-
Notifications
You must be signed in to change notification settings - Fork 294
[rocsparse] add OutputRedirectListener #769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cd9e3e6
add OutputRedirectListener
kliegeois d44f1cd
address some of Yvan's comments
kliegeois 8d3420b
move both listeners to a new header file and inside the rocsparse_cli…
kliegeois 63c2b68
address Yvan's comments
kliegeois e9f2e23
Merge branch 'develop' into redirected_logs
kliegeois File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
272 changes: 272 additions & 0 deletions
272
projects/rocsparse/clients/tests/rocsparse_test_listeners.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,272 @@ | ||
| /*! \file */ | ||
| /* ************************************************************************ | ||
| * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| * ************************************************************************ */ | ||
| #include "rocsparse_test_listeners.hpp" | ||
|
|
||
| rocsparse_clients::configurable_event_listener::configurable_event_listener( | ||
| testing::TestEventListener* theEventListener) | ||
| : eventListener(theEventListener) | ||
| , showTestCases(true) | ||
| , showTestNames(true) | ||
| , showSuccesses(true) | ||
| , showInlineFailures(true) | ||
| , showEnvironment(true) | ||
| { | ||
| } | ||
|
|
||
| rocsparse_clients::configurable_event_listener::~configurable_event_listener() | ||
| { | ||
| delete eventListener; | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestProgramStart( | ||
| const testing::UnitTest& unit_test) | ||
| { | ||
| eventListener->OnTestProgramStart(unit_test); | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestIterationStart( | ||
| const testing::UnitTest& unit_test, int iteration) | ||
| { | ||
| eventListener->OnTestIterationStart(unit_test, iteration); | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnEnvironmentsSetUpStart( | ||
| const testing::UnitTest& unit_test) | ||
| { | ||
| if(showEnvironment) | ||
| { | ||
| eventListener->OnEnvironmentsSetUpStart(unit_test); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnEnvironmentsSetUpEnd( | ||
| const testing::UnitTest& unit_test) | ||
| { | ||
| if(showEnvironment) | ||
| { | ||
| eventListener->OnEnvironmentsSetUpEnd(unit_test); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestCaseStart( | ||
| const testing::TestCase& test_case) | ||
| { | ||
| if(showTestCases) | ||
| { | ||
| eventListener->OnTestCaseStart(test_case); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestStart(const testing::TestInfo& test_info) | ||
| { | ||
| if(showTestNames) | ||
| { | ||
| eventListener->OnTestStart(test_info); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestPartResult( | ||
| const testing::TestPartResult& result) | ||
| { | ||
| eventListener->OnTestPartResult(result); | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestEnd(const testing::TestInfo& test_info) | ||
| { | ||
| if(test_info.result()->Failed() ? showInlineFailures : showSuccesses) | ||
| { | ||
| eventListener->OnTestEnd(test_info); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestCaseEnd( | ||
| const testing::TestCase& test_case) | ||
| { | ||
| if(showTestCases) | ||
| { | ||
| eventListener->OnTestCaseEnd(test_case); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnEnvironmentsTearDownStart( | ||
| const testing::UnitTest& unit_test) | ||
| { | ||
| if(showEnvironment) | ||
| { | ||
| eventListener->OnEnvironmentsTearDownStart(unit_test); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnEnvironmentsTearDownEnd( | ||
| const testing::UnitTest& unit_test) | ||
| { | ||
| if(showEnvironment) | ||
| { | ||
| eventListener->OnEnvironmentsTearDownEnd(unit_test); | ||
| } | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestIterationEnd( | ||
| const testing::UnitTest& unit_test, int iteration) | ||
| { | ||
| eventListener->OnTestIterationEnd(unit_test, iteration); | ||
| } | ||
|
|
||
| void rocsparse_clients::configurable_event_listener::OnTestProgramEnd( | ||
| const testing::UnitTest& unit_test) | ||
| { | ||
| eventListener->OnTestProgramEnd(unit_test); | ||
| } | ||
|
|
||
| void rocsparse_clients::stream_redirector::redirect() | ||
| { | ||
| // Save original buffers | ||
| this->m_old_cout_buf = std::cout.rdbuf(); | ||
| this->m_old_cerr_buf = std::cerr.rdbuf(); | ||
|
|
||
| // Redirect to our ostringstream | ||
| std::cout.rdbuf(this->m_stream.rdbuf()); | ||
| std::cerr.rdbuf(this->m_stream.rdbuf()); | ||
| } | ||
|
|
||
| void rocsparse_clients::stream_redirector::restore() | ||
| { | ||
| // Restore original buffers | ||
| std::cout.rdbuf(this->m_old_cout_buf); | ||
| std::cerr.rdbuf(this->m_old_cerr_buf); | ||
| } | ||
|
|
||
| std::ostringstream& rocsparse_clients::stream_redirector::get_stream() | ||
| { | ||
| return this->m_stream; | ||
| } | ||
|
|
||
| void rocsparse_clients::stream_redirector::clear() | ||
| { | ||
| this->m_stream.clear(); | ||
| } | ||
|
|
||
| rocsparse_clients::output_redirect_listener::output_redirect_listener( | ||
| ::testing::TestEventListener* listener) | ||
| : m_default_listener(listener) | ||
| { | ||
| } | ||
|
|
||
| rocsparse_clients::output_redirect_listener::~output_redirect_listener() | ||
| { | ||
| delete this->m_default_listener; | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestProgramStart( | ||
| const ::testing::UnitTest& unit_test) | ||
| { | ||
| this->m_default_listener->OnTestProgramStart(unit_test); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestIterationStart( | ||
| const ::testing::UnitTest& unit_test, int iteration) | ||
| { | ||
| this->m_default_listener->OnTestIterationStart(unit_test, iteration); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnEnvironmentsSetUpStart( | ||
| const ::testing::UnitTest& unit_test) | ||
| { | ||
| this->m_default_listener->OnEnvironmentsSetUpStart(unit_test); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnEnvironmentsSetUpEnd( | ||
| const ::testing::UnitTest& unit_test) | ||
| { | ||
| this->m_default_listener->OnEnvironmentsSetUpEnd(unit_test); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestCaseStart( | ||
| const ::testing::TestCase& test_case) | ||
| { | ||
| this->m_default_listener->OnTestCaseStart(test_case); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestStart(const ::testing::TestInfo& test_info) | ||
| { | ||
| // Clear and redirect streams before each test | ||
| this->m_redirector.clear(); | ||
| this->m_redirector.redirect(); | ||
| this->m_default_listener->OnTestStart(test_info); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestPartResult( | ||
| const ::testing::TestPartResult& test_part_result) | ||
| { | ||
| this->m_default_listener->OnTestPartResult(test_part_result); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestEnd(const ::testing::TestInfo& test_info) | ||
| { | ||
| // Restore streams after test | ||
| this->m_redirector.restore(); | ||
|
|
||
| // Check if test failed | ||
| if(test_info.result()->Failed()) | ||
| { | ||
| const std::string content = this->m_redirector.get_stream().str(); | ||
|
|
||
| if(!content.empty()) | ||
| { | ||
| std::cerr << content << std::endl; | ||
| } | ||
| } | ||
|
|
||
| this->m_default_listener->OnTestEnd(test_info); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestCaseEnd( | ||
| const ::testing::TestCase& test_case) | ||
| { | ||
| this->m_default_listener->OnTestCaseEnd(test_case); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnEnvironmentsTearDownStart( | ||
| const ::testing::UnitTest& unit_test) | ||
| { | ||
| this->m_default_listener->OnEnvironmentsTearDownStart(unit_test); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnEnvironmentsTearDownEnd( | ||
| const ::testing::UnitTest& unit_test) | ||
| { | ||
| this->m_default_listener->OnEnvironmentsTearDownEnd(unit_test); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestIterationEnd( | ||
| const ::testing::UnitTest& unit_test, int iteration) | ||
| { | ||
| this->m_default_listener->OnTestIterationEnd(unit_test, iteration); | ||
| } | ||
|
|
||
| void rocsparse_clients::output_redirect_listener::OnTestProgramEnd( | ||
| const ::testing::UnitTest& unit_test) | ||
| { | ||
| this->m_default_listener->OnTestProgramEnd(unit_test); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.