refactor: capability to run multiple targets in unit tests

Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz 2023-10-13 09:31:40 +00:00 committed by Compute-Runtime-Automation
parent a3faf5dacc
commit 71e36f85b4
2 changed files with 163 additions and 104 deletions

View File

@ -172,6 +172,12 @@ int main(int argc, char **argv) {
uint32_t subSlicePerSliceCount = 0;
int32_t revId = -1;
int dieRecovery = 0;
bool productOptionSelected = false;
std::vector<PRODUCT_FAMILY> selectedTestProducts;
auto baseTestFiles = testFiles;
auto baseTestFilesApiSpecific = testFilesApiSpecific;
for (int i = 1; i < argc; ++i) {
if (!strcmp("--disable_default_listener", argv[i])) {
@ -209,16 +215,21 @@ int main(int argc, char **argv) {
productFamily = IGFX_UNKNOWN;
}
} else {
bool selectAllProducts = (strcmp("*", argv[i]) == 0);
productFamily = IGFX_UNKNOWN;
for (int j = 0; j < IGFX_MAX_PRODUCT; j++) {
if (hardwarePrefix[j] == nullptr)
continue;
if (strcmp(hardwarePrefix[j], argv[i]) == 0) {
if ((strcmp(hardwarePrefix[j], argv[i]) == 0) || selectAllProducts) {
productFamily = static_cast<PRODUCT_FAMILY>(j);
selectedTestProducts.push_back(productFamily);
if (!selectAllProducts) {
break;
}
}
}
}
if (productFamily == IGFX_UNKNOWN) {
std::cout << "unknown or unsupported product family has been set: " << argv[i] << std::endl;
return -1;
@ -226,6 +237,7 @@ int main(int argc, char **argv) {
std::cout << "product family: " << hardwarePrefix[productFamily] << " (" << productFamily << ")" << std::endl;
}
hwInfoForTests = *hardwareInfoTable[productFamily];
productOptionSelected = true;
}
} else if (!strcmp("--slices", argv[i])) {
++i;
@ -267,13 +279,33 @@ int main(int argc, char **argv) {
}
}
if (!productOptionSelected) {
selectedTestProducts.push_back(hwInfoForTests.platform.eProductFamily);
}
auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
auto defaultListener = listeners.default_result_printer();
defaultHwInfo = std::make_unique<HardwareInfo>();
CCustomEventListener *customEventListener = nullptr;
bool ultListenersInitialized = false;
bool gmmInitialized = false;
bool sipInitialized = false;
for (auto &selectedProduct : selectedTestProducts) {
hwInfoForTests = *hardwareInfoTable[selectedProduct];
productFamily = hwInfoForTests.platform.eProductFamily;
renderCoreFamily = hwInfoForTests.platform.eRenderCoreFamily;
PLATFORM &platform = hwInfoForTests.platform;
if (revId != -1) {
platform.usRevId = revId;
auto testRevId = revId;
if (testRevId != -1) {
platform.usRevId = testRevId;
} else {
revId = platform.usRevId;
testRevId = platform.usRevId;
}
adjustHwInfoForTests(hwInfoForTests, euPerSubSlice, sliceCount, subSlicePerSliceCount, dieRecovery);
@ -284,15 +316,18 @@ int main(int argc, char **argv) {
return 0;
}
binaryNameSuffix.append(hardwarePrefix[hwInfoForTests.platform.eProductFamily]);
binaryNameSuffix = hardwarePrefix[hwInfoForTests.platform.eProductFamily];
setupTestFiles(getRunPath(argv[0]), revId);
testFiles = baseTestFiles;
testFilesApiSpecific = baseTestFilesApiSpecific;
setupTestFiles(getRunPath(argv[0]), testRevId);
auto executionDirectory = getBaseExecutionDir();
executionDirectory += hardwarePrefix[productFamily];
executionDirectory += NEO::executionDirectorySuffix; // _aub for aub_tests, empty otherwise
executionDirectory += "/";
executionDirectory += std::to_string(revId);
executionDirectory += std::to_string(testRevId);
#ifdef WIN32
#include <direct.h>
@ -310,23 +345,31 @@ int main(int argc, char **argv) {
return -1;
}
defaultHwInfo = std::make_unique<HardwareInfo>();
*defaultHwInfo = hwInfoForTests;
auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
if (useDefaultListener == false) {
auto defaultListener = listeners.default_result_printer();
auto customEventListener = new CCustomEventListener(defaultListener, hardwarePrefix[productFamily]);
if (!useDefaultListener) {
if (!customEventListener) {
customEventListener = new CCustomEventListener(defaultListener);
}
customEventListener->setHwPrefix(hardwarePrefix[productFamily]);
}
if (!ultListenersInitialized) {
if (!useDefaultListener) {
listeners.Release(defaultListener);
listeners.Append(customEventListener);
}
listeners.Append(new MemoryLeakListener);
addUltListener(listeners);
addUltListener(listeners);
ultListenersInitialized = true;
}
if (!gEnvironment) {
gEnvironment = reinterpret_cast<TestEnvironment *>(::testing::AddGlobalTestEnvironment(new TestEnvironment));
}
MockCompilerDebugVars fclDebugVars;
MockCompilerDebugVars igcDebugVars;
@ -358,16 +401,22 @@ int main(int argc, char **argv) {
return sigOut;
}
if (!gmmInitialized) {
if (useMockGmm) {
GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>;
} else {
GmmInterface::initialize(nullptr, nullptr);
}
gmmInitialized = true;
}
if (!sipInitialized) {
MockSipData::mockSipKernel.reset(new MockSipKernel());
if (testMode == TestMode::AubTests || testMode == TestMode::AubTestsWithTbx) {
MockSipData::useMockSip = false;
}
sipInitialized = true;
}
retVal = RUN_ALL_TESTS();
@ -383,5 +432,10 @@ int main(int argc, char **argv) {
}
cleanTestHelpers();
if (retVal != 0) {
break;
}
}
return retVal;
}

View File

@ -25,6 +25,11 @@ class CCustomEventListener : public ::testing::TestEventListener {
CCustomEventListener(::testing::TestEventListener *listener) : listener(listener), hardwarePrefix("---") {}
CCustomEventListener(::testing::TestEventListener *listener, const char *hardwarePrefix) : listener(listener), hardwarePrefix(hardwarePrefix) {
setHwPrefix(hardwarePrefix);
}
void setHwPrefix(const char *hardwarePrefix) {
this->hardwarePrefix = hardwarePrefix;
std::transform(this->hardwarePrefix.begin(), this->hardwarePrefix.end(), this->hardwarePrefix.begin(),
[](unsigned char c) { return std::toupper(c); });
}