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