2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-02 19:14:39 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-16 02:19:30 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
|
|
|
#include "shared/source/helpers/product_config_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_library.h"
|
2023-04-18 19:17:54 +08:00
|
|
|
#include "shared/source/utilities/logger.h"
|
2021-09-17 23:06:15 +08:00
|
|
|
#include "shared/test/common/helpers/custom_event_listener.h"
|
2023-04-18 19:17:54 +08:00
|
|
|
#include "shared/test/common/helpers/gtest_helpers.h"
|
|
|
|
#include "shared/test/common/helpers/memory_leak_listener.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/test_files.h"
|
2022-11-10 20:58:43 +08:00
|
|
|
#include "shared/test/common/helpers/virtual_file_system_listener.h"
|
2022-01-14 21:51:20 +08:00
|
|
|
#include "shared/test/common/libult/signal_utils.h"
|
2022-08-17 18:17:02 +08:00
|
|
|
#include "shared/test/common/test_stats.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "environment.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "limits.h"
|
2022-05-19 09:52:41 +08:00
|
|
|
#include "test_files_setup.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-02-16 02:19:30 +08:00
|
|
|
#include <fstream>
|
|
|
|
#include <igfxfmid.h>
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#ifdef WIN32
|
|
|
|
const char *fSeparator = "\\";
|
|
|
|
#elif defined(__linux__)
|
|
|
|
const char *fSeparator = "/";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Environment *gEnvironment;
|
2021-12-29 06:17:46 +08:00
|
|
|
extern PRODUCT_FAMILY productFamily;
|
2021-10-26 23:25:20 +08:00
|
|
|
extern GFXCORE_FAMILY renderCoreFamily;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-03-06 17:54:29 +08:00
|
|
|
std::string getRunPath() {
|
2020-05-21 05:01:05 +08:00
|
|
|
char *cwd;
|
2018-02-21 21:42:23 +08:00
|
|
|
#if defined(__linux__)
|
2020-05-21 05:01:05 +08:00
|
|
|
cwd = getcwd(nullptr, 0);
|
2018-02-21 21:42:23 +08:00
|
|
|
#else
|
2020-05-21 05:01:05 +08:00
|
|
|
cwd = _getcwd(nullptr, 0);
|
2018-02-21 21:42:23 +08:00
|
|
|
#endif
|
2020-05-21 05:01:05 +08:00
|
|
|
std::string res{cwd};
|
|
|
|
free(cwd);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-04-07 00:08:51 +08:00
|
|
|
void applyWorkarounds() {
|
|
|
|
{
|
|
|
|
std::ofstream f;
|
|
|
|
const std::string fileName("_tmp_");
|
|
|
|
f.open(fileName, std::ofstream::binary);
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::mutex mtx;
|
|
|
|
std::unique_lock<std::mutex> stateLock(mtx);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::stringstream ss("1");
|
|
|
|
int val;
|
|
|
|
ss >> val;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string res("abc");
|
|
|
|
res = res.substr(0, 2);
|
2023-04-18 19:17:54 +08:00
|
|
|
res += "abc";
|
|
|
|
}
|
|
|
|
// Create FileLogger to prevent false memory leaks
|
|
|
|
{
|
|
|
|
NEO::fileLoggerInstance();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
[[maybe_unused]] auto ret = std::regex_search("str", std::regex(std::string(".")));
|
2023-04-07 00:08:51 +08:00
|
|
|
}
|
|
|
|
// intialize rand
|
|
|
|
srand(static_cast<unsigned int>(time(nullptr)));
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int retVal = 0;
|
|
|
|
bool useDefaultListener = false;
|
2022-07-19 05:24:13 +08:00
|
|
|
bool enableAbrt = true;
|
2022-01-14 21:51:20 +08:00
|
|
|
bool enableAlarm = true;
|
2022-07-19 05:24:13 +08:00
|
|
|
bool enableSegv = true;
|
2021-11-05 22:10:48 +08:00
|
|
|
bool showTestStats = false;
|
2022-05-05 10:32:45 +08:00
|
|
|
bool dumpTestStats = false;
|
|
|
|
std::string dumpTestStatsFileName = "";
|
2021-11-05 22:10:48 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string devicePrefix("skl");
|
2020-09-24 23:09:02 +08:00
|
|
|
std::string revId("0");
|
2022-11-15 23:24:52 +08:00
|
|
|
std::string productConfig("");
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-04-07 00:08:51 +08:00
|
|
|
applyWorkarounds();
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#if defined(__linux__)
|
|
|
|
if (getenv("CLOC_SELFTEST") == nullptr) {
|
|
|
|
setenv("CLOC_SELFTEST", "YES", 1);
|
|
|
|
|
|
|
|
char *ldLibraryPath = getenv("LD_LIBRARY_PATH");
|
|
|
|
|
|
|
|
if (ldLibraryPath == nullptr) {
|
2018-03-06 17:54:29 +08:00
|
|
|
setenv("LD_LIBRARY_PATH", getRunPath().c_str(), 1);
|
2017-12-21 07:45:38 +08:00
|
|
|
} else {
|
2018-03-06 17:54:29 +08:00
|
|
|
std::string ldLibraryPathConcat = getRunPath() + ":" + std::string(ldLibraryPath);
|
2017-12-21 07:45:38 +08:00
|
|
|
setenv("LD_LIBRARY_PATH", ldLibraryPathConcat.c_str(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
execv(argv[0], argv);
|
2022-11-15 23:24:52 +08:00
|
|
|
// execv failed, we return with error
|
2017-12-21 07:45:38 +08:00
|
|
|
printf("FATAL ERROR: cannot self-exec test!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
if (argc > 0) {
|
|
|
|
// parse remaining args assuming they're mine
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
if (strcmp("--use_default_listener", argv[i]) == 0) {
|
|
|
|
useDefaultListener = true;
|
2022-01-14 21:51:20 +08:00
|
|
|
} else if (!strcmp("--disable_alarm", argv[i])) {
|
|
|
|
enableAlarm = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
} else if (strcmp("--device", argv[i]) == 0) {
|
|
|
|
++i;
|
|
|
|
devicePrefix = argv[i];
|
2020-09-24 23:09:02 +08:00
|
|
|
} else if (strcmp("--rev_id", argv[i]) == 0) {
|
|
|
|
++i;
|
|
|
|
revId = argv[i];
|
2021-11-05 22:10:48 +08:00
|
|
|
} else if (!strcmp("--show_test_stats", argv[i])) {
|
|
|
|
showTestStats = true;
|
2022-05-05 10:32:45 +08:00
|
|
|
} else if (!strcmp("--dump_test_stats", argv[i])) {
|
|
|
|
dumpTestStats = true;
|
|
|
|
++i;
|
|
|
|
dumpTestStatsFileName = std::string(argv[i]);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 23:25:20 +08:00
|
|
|
for (unsigned int productId = 0; productId < IGFX_MAX_PRODUCT; ++productId) {
|
|
|
|
if (NEO::hardwarePrefix[productId] && (0 == strcmp(devicePrefix.c_str(), NEO::hardwarePrefix[productId]))) {
|
|
|
|
if (NEO::hardwareInfoTable[productId]) {
|
|
|
|
renderCoreFamily = NEO::hardwareInfoTable[productId]->platform.eRenderCoreFamily;
|
2021-12-29 06:17:46 +08:00
|
|
|
productFamily = NEO::hardwareInfoTable[productId]->platform.eProductFamily;
|
2021-10-26 23:25:20 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 23:24:52 +08:00
|
|
|
auto productConfigHelper = new ProductConfigHelper();
|
|
|
|
auto allEnabledDeviceConfigs = productConfigHelper->getDeviceAotInfo();
|
|
|
|
|
|
|
|
for (const auto &device : allEnabledDeviceConfigs) {
|
|
|
|
if (device.hwInfo->platform.eProductFamily == productFamily) {
|
|
|
|
productConfig = ProductConfigHelper::parseMajorMinorRevisionValue(device.aotConfig);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
// we look for test files always relative to binary location
|
|
|
|
// this simplifies multi-process execution and using different
|
|
|
|
// working directories
|
2018-03-06 17:54:29 +08:00
|
|
|
std::string nTestFiles = getRunPath();
|
2017-12-21 07:45:38 +08:00
|
|
|
nTestFiles.append("/");
|
2023-01-03 19:46:57 +08:00
|
|
|
nTestFiles.append(devicePrefix);
|
2017-12-21 07:45:38 +08:00
|
|
|
nTestFiles.append("/");
|
2020-09-24 23:09:02 +08:00
|
|
|
nTestFiles.append(revId);
|
|
|
|
nTestFiles.append("/");
|
2017-12-21 07:45:38 +08:00
|
|
|
nTestFiles.append(testFiles);
|
|
|
|
testFiles = nTestFiles;
|
2023-01-03 19:46:57 +08:00
|
|
|
binaryNameSuffix.append(devicePrefix);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-19 09:52:41 +08:00
|
|
|
std::string nClFiles = NEO_OPENCL_TEST_FILES_DIR;
|
|
|
|
nClFiles.append("/");
|
|
|
|
clFiles = nClFiles;
|
|
|
|
|
2018-02-21 21:42:23 +08:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <direct.h>
|
2023-01-03 19:46:57 +08:00
|
|
|
if (_chdir(devicePrefix.c_str())) {
|
|
|
|
std::cout << "chdir into " << devicePrefix << " directory failed.\nThis might cause test failures." << std::endl;
|
2018-02-21 21:42:23 +08:00
|
|
|
}
|
|
|
|
#elif defined(__linux__)
|
|
|
|
#include <unistd.h>
|
2023-01-03 19:46:57 +08:00
|
|
|
if (chdir(devicePrefix.c_str()) != 0) {
|
|
|
|
std::cout << "chdir into " << devicePrefix << " directory failed.\nThis might cause test failures." << std::endl;
|
2018-02-21 21:42:23 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-10 20:58:43 +08:00
|
|
|
auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
|
2017-12-21 07:45:38 +08:00
|
|
|
if (useDefaultListener == false) {
|
2022-11-10 20:58:43 +08:00
|
|
|
auto defaultListener = listeners.default_result_printer();
|
2017-12-21 07:45:38 +08:00
|
|
|
auto customEventListener = new CCustomEventListener(defaultListener);
|
|
|
|
|
2022-11-10 20:58:43 +08:00
|
|
|
listeners.Release(defaultListener);
|
2017-12-21 07:45:38 +08:00
|
|
|
listeners.Append(customEventListener);
|
|
|
|
}
|
2023-04-18 19:17:54 +08:00
|
|
|
listeners.Append(new NEO::MemoryLeakListener);
|
2022-11-10 20:58:43 +08:00
|
|
|
listeners.Append(new NEO::VirtualFileSystemListener);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-01-03 19:46:57 +08:00
|
|
|
gEnvironment = reinterpret_cast<Environment *>(::testing::AddGlobalTestEnvironment(new Environment(devicePrefix, productConfig)));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-11-30 21:05:49 +08:00
|
|
|
int sigOut = setSegv(enableSegv);
|
2022-07-19 05:24:13 +08:00
|
|
|
if (sigOut != 0) {
|
2022-01-14 21:51:20 +08:00
|
|
|
return sigOut;
|
2022-07-19 05:24:13 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 21:05:49 +08:00
|
|
|
sigOut = setAbrt(enableAbrt);
|
2022-07-19 05:24:13 +08:00
|
|
|
if (sigOut != 0) {
|
|
|
|
return sigOut;
|
|
|
|
}
|
|
|
|
|
2023-11-30 21:05:49 +08:00
|
|
|
sigOut = setAlarm(enableAlarm);
|
2022-07-19 05:24:13 +08:00
|
|
|
if (sigOut != 0) {
|
|
|
|
return sigOut;
|
|
|
|
}
|
2022-01-14 21:51:20 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
retVal = RUN_ALL_TESTS();
|
2023-11-27 17:59:46 +08:00
|
|
|
cleanupSignals();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-05 10:32:45 +08:00
|
|
|
if (showTestStats) {
|
|
|
|
std::cout << getTestStats() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dumpTestStats) {
|
|
|
|
std::ofstream dumpTestStatsFile;
|
|
|
|
dumpTestStatsFile.open(dumpTestStatsFileName);
|
|
|
|
dumpTestStatsFile << getTestStatsJson();
|
|
|
|
dumpTestStatsFile.close();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
return retVal;
|
|
|
|
}
|