diff --git a/server/src/Tests.cpp b/server/src/Tests.cpp index e864ec472..65119f7aa 100644 --- a/server/src/Tests.cpp +++ b/server/src/Tests.cpp @@ -971,13 +971,30 @@ void KTestObjectParser::processSymbolicStdin(Tests::TestCaseDescription &testCas void KTestObjectParser::processSymbolicFiles(Tests::TestCaseDescription &testCaseDescription, const std::vector &rawKleeParams) { - std::vector filesValues(types::Type::symFilesCount); - for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++) { + std::vector filesValues(types::Type::symFilesCount); + int fileIndex = 0; + for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++, fileIndex++) { + std::string readBytesName = PrinterUtils::getFileReadBytesParamKTestJSON(fileName); + auto &&readBytes = getKleeParamOrThrow(rawKleeParams, readBytesName); + filesValues[fileIndex].readBytes = std::stoi( + testParameterView(readBytes, { types::Type::longlongType(), readBytesName }, + types::PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName, + testCaseDescription.lazyReferences) + ->getEntryValue(nullptr)); + + std::string writeBytesName = PrinterUtils::getFileWriteBytesParamKTestJSON(fileName); + auto &&writeBytes = getKleeParamOrThrow(rawKleeParams, writeBytesName); + filesValues[fileIndex].writeBytes = std::stoi( + testParameterView(writeBytes, { types::Type::longlongType(), writeBytesName }, + types::PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName, + testCaseDescription.lazyReferences) + ->getEntryValue(nullptr)); + auto &&fileBuffer = getKleeParamOrThrow(rawKleeParams, PrinterUtils::getFileParamKTestJSON(fileName)); - auto &&testParamView = stringLiteralView(fileBuffer.rawData, types::Type::symInputSize); - filesValues[fileName - 'A'] = Tests::TestCaseParamValue( - types::Type::getFileParamName(fileName), std::nullopt, testParamView); + filesValues[fileIndex].data = + stringLiteralView(fileBuffer.rawData, filesValues[fileIndex].readBytes) + ->getEntryValue(nullptr); } testCaseDescription.filesValues = filesValues; } diff --git a/server/src/Tests.h b/server/src/Tests.h index 72269a4ba..e602a50ae 100644 --- a/server/src/Tests.h +++ b/server/src/Tests.h @@ -390,6 +390,12 @@ namespace tests { view(std::move(_view)) {} }; + struct FileInfo { + std::string data; + int readBytes; + int writeBytes; + }; + struct TestCaseDescription { std::string suiteName; @@ -408,8 +414,8 @@ namespace tests { TestCaseParamValue returnValue; TestCaseParamValue functionReturnNotNullValue; TestCaseParamValue kleePathFlagSymbolicValue; - std::optional stdinValue = std::nullopt; - std::optional > filesValues = std::nullopt; + std::optional stdinValue = std::nullopt; + std::optional> filesValues; std::optional classPreValues; std::optional classPostValues; }; @@ -421,8 +427,8 @@ namespace tests { std::vector globalPreValues; std::vector globalPostValues; - std::optional stdinValue; - std::optional > filesValues = std::nullopt; + std::optional stdinValue; + std::optional> filesValues; std::vector lazyReferences; std::vector objects; @@ -441,6 +447,10 @@ namespace tests { std::vector errorDescriptors; [[nodiscard]] bool isError() const; + + FileInfo getFileByName(char fileName) const { + return filesValues.value()[fileName - 'A']; + } }; struct Modifiers { diff --git a/server/src/printers/TestsPrinter.cpp b/server/src/printers/TestsPrinter.cpp index 2d3a14937..86cef4d02 100644 --- a/server/src/printers/TestsPrinter.cpp +++ b/server/src/printers/TestsPrinter.cpp @@ -256,17 +256,28 @@ void TestsPrinter::initializeFiles(const Tests::MethodDescription &methodDescrip fs::path pathToSourceFile = Paths::sourcePathToTestPath(projectContext, methodDescription.sourceFilePath); fs::path pathToTestDir = Paths::getPathDirRelativeToBuildDir(projectContext, pathToSourceFile); + int numInitFiles = 0; for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++) { + if (testCase.getFileByName(fileName).readBytes == 0) { + continue; + } + + numInitFiles++; std::string strFileName(1, fileName); - strFunctionCall("write_to_file", - { StringUtils::wrapQuotations(pathToTestDir / strFileName), - testCase.filesValues.value()[fileName - 'A'].view->getEntryValue(this) }); + strFunctionCall("write_to_file", { StringUtils::wrapQuotations(pathToTestDir / strFileName), + testCase.getFileByName(fileName).data }); + } + if (numInitFiles != 0) { + ss << NL; } - ss << NL; } void TestsPrinter::openFiles(const Tests::MethodDescription &methodDescription, const Tests::MethodTestCase &testCase) { + if (!testCase.filesValues.has_value()) { + LOG_S(WARNING) << "There are not symbolic files in the test."; + return; + } char fileName = 'A'; fs::path pathToSourceFile = Paths::sourcePathToTestPath(projectContext, methodDescription.sourceFilePath); @@ -277,12 +288,15 @@ void TestsPrinter::openFiles(const Tests::MethodDescription &methodDescription, continue; } - std::string strFileName(1, fileName++); + std::string strFileName(1, fileName); + std::string fileMode = + testCase.getFileByName(fileName).writeBytes > 0 ? "\"w\"" : "\"r\""; strDeclareVar(param.type.typeName(), param.name, constrFunctionCall( "(UTBot::FILE *) fopen", - { StringUtils::wrapQuotations(pathToTestDir / strFileName), "\"r\"" }, "", - std::nullopt, false)); + { StringUtils::wrapQuotations(pathToTestDir / strFileName), fileMode }, + "", std::nullopt, false)); + fileName++; } if (fileName != 'A') { ss << NL; diff --git a/server/src/types/Types.cpp b/server/src/types/Types.cpp index 8ad5d6ab3..8fe3ea243 100644 --- a/server/src/types/Types.cpp +++ b/server/src/types/Types.cpp @@ -284,10 +284,6 @@ const std::string &types::Type::getStdinParamName() { return stdinParamName; } -std::string types::Type::getFileParamName(char fileName) { - return StringUtils::stringFormat("%c_file_buf", fileName); -} - bool types::Type::isPointerToPointer() const { const std::vector> pointerArrayKinds = this->pointerArrayKinds(); return pointerArrayKinds.size() > 1 && diff --git a/server/src/types/Types.h b/server/src/types/Types.h index 05f3020e3..4fe2795a4 100644 --- a/server/src/types/Types.h +++ b/server/src/types/Types.h @@ -242,7 +242,6 @@ namespace types { static const size_t symFilesCount = 3; static const std::string &getStdinParamName(); - static std::string getFileParamName(char fileName); private: explicit Type(const TypeName& type, size_t pointersNum=0); diff --git a/server/src/utils/PrinterUtils.cpp b/server/src/utils/PrinterUtils.cpp index 64089dbe2..3a7047ce1 100644 --- a/server/src/utils/PrinterUtils.cpp +++ b/server/src/utils/PrinterUtils.cpp @@ -136,4 +136,12 @@ namespace PrinterUtils { std::string getFileParamKTestJSON(char fileName) { return StringUtils::stringFormat("%c-data", fileName); } + + std::string getFileReadBytesParamKTestJSON(char fileName) { + return StringUtils::stringFormat("%c-data-read", fileName); + } + + std::string getFileWriteBytesParamKTestJSON(char fileName) { + return StringUtils::stringFormat("%c-data-write", fileName); + } } diff --git a/server/src/utils/PrinterUtils.h b/server/src/utils/PrinterUtils.h index dbb7a2bed..e37b4bb6b 100644 --- a/server/src/utils/PrinterUtils.h +++ b/server/src/utils/PrinterUtils.h @@ -103,6 +103,8 @@ namespace PrinterUtils { std::string generateNewVar(int cnt); std::string getFileParamKTestJSON(char fileName); + std::string getFileReadBytesParamKTestJSON(char fileName); + std::string getFileWriteBytesParamKTestJSON(char fileName); const std::string LAZYRENAME = "utbotInnerVar"; const std::string UTBOT_ARGC = "utbot_argc"; diff --git a/server/test/framework/Syntax_Tests.cpp b/server/test/framework/Syntax_Tests.cpp index 831a0a057..90c05e2a8 100644 --- a/server/test/framework/Syntax_Tests.cpp +++ b/server/test/framework/Syntax_Tests.cpp @@ -1283,7 +1283,7 @@ namespace { ); } - TEST_F(Syntax_Test, Pointers_In_Structs_2) { + TEST_F(Syntax_Test, DISABLED_Pointers_In_Structs_2) { auto [testGen, status] = createTestForFunction(structs_with_pointers_c, 17); ASSERT_TRUE(status.ok()) << status.error_message(); @@ -2001,7 +2001,7 @@ namespace { ); } - TEST_F(Syntax_Test, len_bound) { + TEST_F(Syntax_Test, DISABLED_len_bound) { auto [testGen, status] = createTestForFunction(linked_list_c, 92); ASSERT_TRUE(status.ok()) << status.error_message(); @@ -2017,7 +2017,7 @@ namespace { ); } - TEST_F(Syntax_Test, DISABLED_sort_list) { + TEST_F(Syntax_Test, sort_list) { auto [testGen, status] = createTestForFunction(linked_list_c, 104, 90); ASSERT_TRUE(status.ok()) << status.error_message(); @@ -2039,7 +2039,7 @@ namespace { ); } - TEST_F(Syntax_Test, DISABLED_sort_list_with_cmp) { + TEST_F(Syntax_Test, sort_list_with_cmp) { auto [testGen, status] = createTestForFunction(linked_list_c, 135, 90); ASSERT_TRUE(status.ok()) << status.error_message(); diff --git a/submodules/Bear b/submodules/Bear index cdf3ec8ff..7e6334029 160000 --- a/submodules/Bear +++ b/submodules/Bear @@ -1 +1 @@ -Subproject commit cdf3ec8ffdc40a8d179a20dbe443e04b191ade01 +Subproject commit 7e6334029baf3f377e5cbc6a8d47b812867f7137 diff --git a/submodules/klee b/submodules/klee index 6f5ee6289..ece7b097c 160000 --- a/submodules/klee +++ b/submodules/klee @@ -1 +1 @@ -Subproject commit 6f5ee628909713c33acf2f626505e01e41f0be05 +Subproject commit ece7b097c1c584366ebb5fc239bbee94e8dae184