refactor: Modernize writeDataToFile function

Signed-off-by: Marcel Skierkowski <marcel.skierkowski@intel.com>
This commit is contained in:
Marcel Skierkowski
2025-04-11 11:24:23 +00:00
committed by Compute-Runtime-Automation
parent dd3d294f87
commit e82be94368
18 changed files with 74 additions and 58 deletions

View File

@@ -267,8 +267,7 @@ TEST_F(BuiltInTests, WhenBuildingListOfBuiltinsThenBuiltinsHaveBeenGenerated) {
#define GENERATE_NEW_HASH_FOR_BUILT_INS 0
#if GENERATE_NEW_HASH_FOR_BUILT_INS
std::cout << "writing builtins to file: " << hashName << std::endl;
const char *pData = allBuiltIns.c_str();
writeDataToFile(hashName.c_str(), pData, allBuiltIns.length());
writeDataToFile(hashName.c_str(), allBuiltIns);
#endif
}
}

View File

@@ -54,15 +54,18 @@ class OclocApiTest : public ::testing::Test {
std::string spvFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".spv";
std::string binFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".bin";
std::string dbgFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".dbg";
std::vector<unsigned char> mockByteArray = {0x01, 0x02, 0x03, 0x04};
writeDataToFile(spvFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(binFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(dbgFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(clCopybufferFilename.c_str(), kernelSources.data(), mockByteArray.size());
constexpr unsigned char mockByteArray[] = {0x01, 0x02, 0x03, 0x04};
std::string_view byteArrayView(reinterpret_cast<const char *>(mockByteArray), sizeof(mockByteArray));
writeDataToFile(spvFile.c_str(), byteArrayView);
writeDataToFile(binFile.c_str(), byteArrayView);
writeDataToFile(dbgFile.c_str(), byteArrayView);
writeDataToFile(clCopybufferFilename.c_str(), kernelSources);
}
const std::string clCopybufferFilename = "some_kernel.cl";
std::string kernelSources = "example_kernel(){}";
const std::string_view kernelSources = "example_kernel(){}";
};
TEST_F(OclocApiTest, WhenGoodArgsAreGivenThenSuccessIsReturned) {
VariableBackup<decltype(NEO::IoFunctions::fopenPtr)> mockFopen(&NEO::IoFunctions::fopenPtr, [](const char *filename, const char *mode) -> FILE * {

View File

@@ -27,10 +27,13 @@ class OclocTest : public ::testing::Test {
std::string spvFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".spv";
std::string binFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".bin";
std::string dbgFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".dbg";
std::vector<unsigned char> mockByteArray = {0x01, 0x02, 0x03, 0x04};
writeDataToFile(spvFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(binFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(dbgFile.c_str(), mockByteArray.data(), mockByteArray.size());
constexpr unsigned char mockByteArray[] = {0x01, 0x02, 0x03, 0x04};
std::string_view byteArrayView(reinterpret_cast<const char *>(mockByteArray), sizeof(mockByteArray));
writeDataToFile(spvFile.c_str(), byteArrayView);
writeDataToFile(binFile.c_str(), byteArrayView);
writeDataToFile(dbgFile.c_str(), byteArrayView);
}
protected:

View File

@@ -38,10 +38,13 @@ class OfflineCompilerTests : public ::testing::Test {
std::string spvFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".spv";
std::string binFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".bin";
std::string dbgFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".dbg";
std::vector<unsigned char> mockByteArray = {0x01, 0x02, 0x03, 0x04};
writeDataToFile(spvFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(binFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(dbgFile.c_str(), mockByteArray.data(), mockByteArray.size());
constexpr unsigned char mockByteArray[] = {0x01, 0x02, 0x03, 0x04};
std::string_view byteArrayView(reinterpret_cast<const char *>(mockByteArray), sizeof(mockByteArray));
writeDataToFile(spvFile.c_str(), byteArrayView);
writeDataToFile(binFile.c_str(), byteArrayView);
writeDataToFile(dbgFile.c_str(), byteArrayView);
filesMap[clCopybufferFilename] = OfflineCompilerTests::kernelSources;
oclocArgHelperWithoutInput->setAllCallBase(false);
@@ -67,10 +70,14 @@ class MultiCommandTests : public ::testing::Test {
std::string spvFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".spv";
std::string binFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".bin";
std::string dbgFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".dbg";
std::vector<unsigned char> mockByteArray = {0x01, 0x02, 0x03, 0x04};
writeDataToFile(spvFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(binFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(dbgFile.c_str(), mockByteArray.data(), mockByteArray.size());
constexpr unsigned char mockByteArray[] = {0x01, 0x02, 0x03, 0x04};
std::string_view byteArrayView(reinterpret_cast<const char *>(mockByteArray), sizeof(mockByteArray));
writeDataToFile(spvFile.c_str(), byteArrayView);
writeDataToFile(binFile.c_str(), byteArrayView);
writeDataToFile(dbgFile.c_str(), byteArrayView);
filesMap[clCopybufferFilename] = kernelSources;
oclocArgHelperWithoutInput->setAllCallBase(false);
}

View File

@@ -37,10 +37,14 @@ void OfflineLinkerTest::SetUp() {
std::string spvFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".spv";
std::string binFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".bin";
std::string dbgFile = std::string("copybuffer") + "_" + gEnvironment->devicePrefix + ".dbg";
std::vector<unsigned char> mockByteArray = {0x01, 0x02, 0x03, 0x04};
writeDataToFile(spvFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(binFile.c_str(), mockByteArray.data(), mockByteArray.size());
writeDataToFile(dbgFile.c_str(), mockByteArray.data(), mockByteArray.size());
constexpr unsigned char mockByteArray[] = {0x01, 0x02, 0x03, 0x04};
std::string_view byteArrayView(reinterpret_cast<const char *>(mockByteArray), sizeof(mockByteArray));
writeDataToFile(spvFile.c_str(), byteArrayView);
writeDataToFile(binFile.c_str(), byteArrayView);
writeDataToFile(dbgFile.c_str(), byteArrayView);
MockCompilerDebugVars igcDebugVars{gEnvironment->igcDebugVars};
igcDebugVars.binaryToReturn = binaryToReturn;
igcDebugVars.binaryToReturnSize = sizeof(binaryToReturn);