CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
270 lines
8.2 KiB
C++
270 lines
8.2 KiB
C++
/*******************************************************************************
|
|
*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2022-2025 Advanced Micro Devices, Inc.
|
|
*
|
|
* 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 "hipsparselt_data.hpp"
|
|
#include "hipsparselt_parse_data.hpp"
|
|
#include "hipsparselt_test.hpp"
|
|
#include "test_cleanup.hpp"
|
|
#include "utility.hpp"
|
|
#include <string>
|
|
|
|
using namespace testing;
|
|
|
|
class ConfigurableEventListener : public TestEventListener
|
|
{
|
|
TestEventListener* const eventListener;
|
|
std::atomic_size_t skipped_tests{0}; // Number of skipped tests.
|
|
|
|
public:
|
|
bool showTestCases = true; // Show the names of each test case.
|
|
bool showTestNames = true; // Show the names of each test.
|
|
bool showSuccesses = true; // Show each success.
|
|
bool showInlineFailures = true; // Show each failure as it occurs.
|
|
bool showEnvironment = true; // Show the setup of the global environment.
|
|
bool showInlineSkips = true; // Show when we skip a test.
|
|
|
|
explicit ConfigurableEventListener(TestEventListener* theEventListener)
|
|
: eventListener(theEventListener)
|
|
{
|
|
}
|
|
|
|
~ConfigurableEventListener() override
|
|
{
|
|
delete eventListener;
|
|
}
|
|
|
|
void OnTestProgramStart(const UnitTest& unit_test) override
|
|
{
|
|
eventListener->OnTestProgramStart(unit_test);
|
|
}
|
|
|
|
void OnTestIterationStart(const UnitTest& unit_test, int iteration) override
|
|
{
|
|
eventListener->OnTestIterationStart(unit_test, iteration);
|
|
}
|
|
|
|
void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override
|
|
{
|
|
if(showEnvironment)
|
|
eventListener->OnEnvironmentsSetUpStart(unit_test);
|
|
}
|
|
|
|
void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override
|
|
{
|
|
if(showEnvironment)
|
|
eventListener->OnEnvironmentsSetUpEnd(unit_test);
|
|
}
|
|
|
|
void OnTestCaseStart(const TestCase& test_case) override
|
|
{
|
|
if(showTestCases)
|
|
eventListener->OnTestCaseStart(test_case);
|
|
}
|
|
|
|
void OnTestStart(const TestInfo& test_info) override
|
|
{
|
|
if(showTestNames)
|
|
eventListener->OnTestStart(test_info);
|
|
}
|
|
|
|
void OnTestPartResult(const TestPartResult& result) override
|
|
{
|
|
if(!strcmp(result.message(), LIMITED_MEMORY_STRING_GTEST))
|
|
{
|
|
if(showInlineSkips)
|
|
hipsparselt_cout << "Skipped test due to limited memory environment." << std::endl;
|
|
++skipped_tests;
|
|
}
|
|
else if(!strcmp(result.message(), TOO_MANY_DEVICES_STRING_GTEST))
|
|
{
|
|
if(showInlineSkips)
|
|
hipsparselt_cout << "Skipped test due to too few GPUs." << std::endl;
|
|
++skipped_tests;
|
|
}
|
|
eventListener->OnTestPartResult(result);
|
|
}
|
|
|
|
void OnTestEnd(const TestInfo& test_info) override
|
|
{
|
|
if(test_info.result()->Failed() ? showInlineFailures : showSuccesses)
|
|
eventListener->OnTestEnd(test_info);
|
|
}
|
|
|
|
void OnTestCaseEnd(const TestCase& test_case) override
|
|
{
|
|
if(showTestCases)
|
|
eventListener->OnTestCaseEnd(test_case);
|
|
}
|
|
|
|
void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override
|
|
{
|
|
if(showEnvironment)
|
|
eventListener->OnEnvironmentsTearDownStart(unit_test);
|
|
}
|
|
|
|
void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override
|
|
{
|
|
if(showEnvironment)
|
|
eventListener->OnEnvironmentsTearDownEnd(unit_test);
|
|
}
|
|
|
|
void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override
|
|
{
|
|
eventListener->OnTestIterationEnd(unit_test, iteration);
|
|
}
|
|
|
|
void OnTestProgramEnd(const UnitTest& unit_test) override
|
|
{
|
|
if(skipped_tests)
|
|
hipsparselt_cout << "[ SKIPPED ] " << skipped_tests << " tests." << std::endl;
|
|
eventListener->OnTestProgramEnd(unit_test);
|
|
}
|
|
};
|
|
|
|
// Set the listener for Google Tests
|
|
static void hipsparselt_set_listener()
|
|
{
|
|
// remove the default listener
|
|
auto& listeners = testing::UnitTest::GetInstance()->listeners();
|
|
auto default_printer = listeners.Release(listeners.default_result_printer());
|
|
|
|
// add our listener, by default everything is on (the same as using the default listener)
|
|
// here I am turning everything off so I only see the 3 lines for the result
|
|
// (plus any failures at the end), like:
|
|
|
|
// [==========] Running 149 tests from 53 test cases.
|
|
// [==========] 149 tests from 53 test cases ran. (1 ms total)
|
|
// [ PASSED ] 149 tests.
|
|
//
|
|
auto* listener = new ConfigurableEventListener(default_printer);
|
|
auto* gtest_listener = getenv("GTEST_LISTENER");
|
|
|
|
if(gtest_listener && !strcmp(gtest_listener, "NO_PASS_LINE_IN_LOG"))
|
|
{
|
|
listener->showTestNames = false;
|
|
listener->showSuccesses = false;
|
|
listener->showInlineFailures = false;
|
|
listener->showInlineSkips = false;
|
|
}
|
|
|
|
listeners.Append(listener);
|
|
}
|
|
|
|
// Print Version
|
|
static void hipsparselt_print_version()
|
|
{
|
|
static int version;
|
|
hipsparselt_local_handle handle;
|
|
hipsparseLtGetVersion(handle, &version);
|
|
|
|
char rev[128];
|
|
hipsparseLtGetGitRevision(handle, &rev[0]);
|
|
hipsparselt_cout << "hipSPARSELt version: " << version << " revision: " << rev << "\n" << std::endl;
|
|
}
|
|
|
|
static void hipsparselt_print_usage_warning()
|
|
{
|
|
std::string warning(
|
|
"parsing of test data may take a couple minutes before any test output appears...");
|
|
|
|
hipsparselt_cout << "info: " << warning << "\n" << std::endl;
|
|
}
|
|
|
|
static std::string hipsparselt_capture_args(int argc, char** argv)
|
|
{
|
|
std::ostringstream cmdLine;
|
|
cmdLine << "command line: ";
|
|
for(int i = 0; i < argc; i++)
|
|
{
|
|
if(argv[i])
|
|
cmdLine << std::string(argv[i]) << " ";
|
|
}
|
|
return cmdLine.str();
|
|
}
|
|
|
|
static void hipsparselt_print_args(const std::string& args)
|
|
{
|
|
hipsparselt_cout << args << std::endl;
|
|
hipsparselt_cout.flush();
|
|
}
|
|
|
|
// Device Query
|
|
static void hipsparselt_set_test_device()
|
|
{
|
|
int device_id = 0;
|
|
int device_count = query_device_property();
|
|
if(device_count <= device_id)
|
|
{
|
|
hipsparselt_cerr << "Error: invalid device ID. There may not be such device ID."
|
|
<< std::endl;
|
|
exit(-1);
|
|
}
|
|
set_device(device_id);
|
|
}
|
|
|
|
/*****************
|
|
* Main function *
|
|
*****************/
|
|
int main(int argc, char** argv)
|
|
{
|
|
std::string args = hipsparselt_capture_args(argc, argv);
|
|
|
|
// Set signal handler
|
|
hipsparselt_test_sigaction();
|
|
|
|
hipsparselt_print_version();
|
|
|
|
// Set test device
|
|
hipsparselt_set_test_device();
|
|
|
|
hipsparselt_print_usage_warning();
|
|
|
|
// Set data file path
|
|
hipsparselt_parse_data(argc, argv, hipsparselt_exepath() + "hipsparselt_gtest.data");
|
|
|
|
// Initialize Google Tests
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
// Free up all temporary data generated during test creation
|
|
test_cleanup::cleanup();
|
|
|
|
// Set Google Test listener
|
|
hipsparselt_set_listener();
|
|
|
|
// Run the tests
|
|
int status = RUN_ALL_TESTS();
|
|
|
|
// Failures printed at end for reporting so repeat version info
|
|
hipsparselt_print_version();
|
|
|
|
// end test results with command line
|
|
hipsparselt_print_args(args);
|
|
|
|
//hipsparselt_shutdown();
|
|
|
|
return status;
|
|
}
|