1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
|
/* ************************************************************************
* Copyright (C) 2018-2024 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 cop-
* ies 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 IM-
* PLIED, 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 CONNE-
* CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ************************************************************************ */
#include <string>
#include "rocblas_data.hpp"
#include "rocblas_parse_data.hpp"
#include "rocblas_test.hpp"
#include "test_cleanup.hpp"
#include "client_utility.hpp"
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.
bool showInlineSkipTooFewGPU = false; // Only show in summary
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(result.type() == TestPartResult::kSkip)
{
++skipped_tests;
if(strstr(result.message(), LIMITED_RAM_STRING))
{
if(showInlineSkips)
rocblas_cout << "Skipped test due to limited RAM environment." << std::endl;
}
else if(strstr(result.message(), LIMITED_VRAM_STRING))
{
if(showInlineSkips)
rocblas_cout << "Skipped test due to limited GPU memory environment."
<< std::endl;
}
else if(strstr(result.message(), HMM_NOT_SUPPORTED_STRING))
{
if(showInlineSkips)
rocblas_cout << "Skipped test due to HMM not supported." << std::endl;
}
else if(strstr(result.message(), TOO_FEW_DEVICES_PRESENT_STRING))
{
if(showInlineSkipTooFewGPU) // specific default for gpu
rocblas_cout << "Skipped test due to too few GPUs." << std::endl;
}
else if(showInlineSkips)
{
// this is more output than the simple sentences above
eventListener->OnTestPartResult(result);
}
}
else
{
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)
rocblas_cout << "[ SKIPPED ] " << skipped_tests << " tests." << std::endl;
eventListener->OnTestProgramEnd(unit_test);
}
};
// Set the listener for Google Tests
static void rocblas_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"))
{
rocblas_cout << "environment GTEST_LISTENER=NO_PASS_LINE_IN_LOG is now the default.\n"
"To see pass lines use: GTEST_LISTENER=PASS_LINE_IN_LOG"
<< std::endl;
}
if(gtest_listener && !strcmp(gtest_listener, "PASS_LINE_IN_LOG"))
{
}
else
{
// default is now the same as GTEST_LISTENER=NO_PASS_LINE_IN_LOG
listener->showTestNames = false;
listener->showSuccesses = false;
listener->showInlineFailures = true; // easier reading
listener->showInlineSkips = false;
}
listeners.Append(listener);
}
static std::string rocblas_version_string()
{
size_t size;
rocblas_get_version_string_size(&size);
std::string str(size - 1, '\0');
rocblas_get_version_string(str.data(), size);
return str;
}
// Print Version
static void rocblas_print_version()
{
static std::string blas_version = rocblas_version_string();
rocblas_cout << "rocBLAS version: " << blas_version << "\n" << std::endl;
}
// Print rocBLAS and Tensile commit hashes
static void rocblas_print_commit_hashes()
{
const char* rocblas_tensile_commit_hash[] = {ROCBLAS_TENSILE_COMMIT_ID};
#if BUILD_WITH_TENSILE
rocblas_cout << "rocBLAS-commit-hash: " << rocblas_tensile_commit_hash[0] << std::endl
<< std::endl;
rocblas_cout << "Tensile-commit-hash: " << rocblas_tensile_commit_hash[1] << std::endl
<< std::endl;
#else
rocblas_cout << "rocBLAS-commit-hash: " << rocblas_tensile_commit_hash[0] << std::endl
<< std::endl;
rocblas_cout << "Tensile-commit-hash: N/A, as rocBLAS was built without Tensile" << std::endl
<< std::endl;
#endif
}
static void rocblas_print_usage_warning()
{
std::string warning(
"parsing of test data may take a couple minutes before any test output appears...");
rocblas_cout << "info: " << warning << "\n" << std::endl;
}
static std::string rocblas_capture_args(int argc, char** argv, std::string& filter_str)
{
bool yaml = false;
bool filter = false;
std::ostringstream cmdLine;
cmdLine << "command line: ";
for(int i = 0; i < argc; i++)
{
if(argv[i])
{
if(strstr(argv[i], "--yaml"))
{
yaml = true;
}
if(strstr(argv[i], "--gtest_filter="))
{
std::string argv_str(argv[i]);
filter_str = argv_str.substr(strlen("--gtest_filter="));
filter = true;
}
cmdLine << std::string(argv[i]) << " ";
}
}
// guard against non explicit full test set, stress will be removed by default
if(!yaml)
{
const char* known_bug_pos = strstr(filter_str.c_str(), "*known_bug");
const char* filter_removal_pos = strstr(filter_str.c_str(), "-");
// detect if known_bugs is near beginning of filter and is in removal set
bool only_less_known_bugs = known_bug_pos && (known_bug_pos - filter_str.c_str() < 3)
&& (filter_removal_pos && known_bug_pos > filter_removal_pos);
if(filter_str.empty() || only_less_known_bugs)
{
if(!filter_removal_pos)
filter_str += "-";
filter_str += ":*stress*";
rocblas_client_set_gtest_filter(filter_str.c_str());
std::string warning(
"automatically adding filter to remove stress tests. --gtest_filter=");
rocblas_cout << "info: " << warning << filter_str << "\n" << std::endl;
}
}
return cmdLine.str();
}
static void rocblas_print_args(const std::string& args)
{
rocblas_cout << args << std::endl;
rocblas_cout.flush();
}
// Device Query
static void rocblas_set_test_device()
{
int device_id = 0;
int device_count = query_device_property();
if(device_count <= device_id)
{
rocblas_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)
{
rocblas_client_init();
std::string filter_override;
std::string args = rocblas_capture_args(argc, argv, filter_override);
auto* no_signal_handling = getenv("ROCBLAS_TEST_NO_SIGACTION");
if(no_signal_handling)
{
rocblas_cout << "rocblas-test INFO: sigactions disabled." << std::endl;
}
else
{
// Set signal handler
rocblas_test_sigaction();
}
rocblas_print_version();
// Print rocBLAS and Tensile commit hashes
rocblas_print_commit_hashes();
// Warn users if using older reference library
print_reference_lib_warning();
// Set test device
rocblas_set_test_device();
rocblas_print_usage_warning();
// Set data file path
#ifdef INSTALL_TEST_DATA_DIR
std::string exe_path = INSTALL_TEST_DATA_DIR;
if (exe_path.back() != '/') {
exe_path += '/';
}
#else
std::string exe_path = rocblas_exepath();
#endif
rocblas_parse_data(argc, argv, exe_path + "rocblas_gtest.data");
// Initialize Google Tests
testing::InitGoogleTest(&argc, argv);
if(!filter_override.empty())
rocblas_client_set_gtest_filter(filter_override.c_str());
// Free up all temporary data generated during test creation
test_cleanup::cleanup();
// Set Google Test listener
rocblas_set_listener();
// Run the tests
int status = RUN_ALL_TESTS();
// Failures printed at end for reporting so repeat version info
rocblas_print_version();
// end test results with command line
rocblas_print_args(args);
//rocblas_shutdown();
rocblas_client_shutdown();
return status;
}
|