From 0e89328be334c8eb32ba40c030115534b4f0806f Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Tue, 14 May 2024 19:16:45 +0300 Subject: [PATCH 1/6] Fix run tests --- server/src/Paths.cpp | 19 +++++++++++++++++-- server/src/Paths.h | 3 +++ server/src/coverage/TestRunner.cpp | 17 ++++++++--------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/server/src/Paths.cpp b/server/src/Paths.cpp index d77e9e54..ab3a81cf 100644 --- a/server/src/Paths.cpp +++ b/server/src/Paths.cpp @@ -375,8 +375,9 @@ namespace Paths { fs::path sourcePathToStubPath(const utbot::ProjectContext &projectContext, const fs::path &source) { - return normalizedTrimmed((projectContext.getTestDirAbsPath() / "stubs" / getRelativeDirPath(projectContext, source) / - sourcePathToStubName(source))); + return normalizedTrimmed( + (projectContext.getTestDirAbsPath() / "stubs" / getRelativeDirPath(projectContext, source) / + sourcePathToStubName(source))); } fs::path testPathToSourcePath(const utbot::ProjectContext &projectContext, @@ -386,6 +387,20 @@ namespace Paths { return projectContext.projectPath / relative / filename; } + std::pair getSourceAndTestPath(const utbot::ProjectContext &projectContext, + const fs::path &filePath) { + fs::path sourcePath; + fs::path testPath; + if (isSubPathOf(projectContext.getTestDirAbsPath(), filePath)) { + testPath = filePath; + sourcePath = testPathToSourcePath(projectContext, filePath); + } else { + testPath = sourcePathToTestPath(projectContext, filePath); + sourcePath = filePath; + } + return {sourcePath, testPath}; + } + fs::path getMakefilePathFromSourceFilePath(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath, const std::string &suffix) { diff --git a/server/src/Paths.h b/server/src/Paths.h index a6e66da3..e1491c89 100644 --- a/server/src/Paths.h +++ b/server/src/Paths.h @@ -404,6 +404,9 @@ namespace Paths { fs::path testPathToSourcePath(const utbot::ProjectContext &projectContext, const fs::path &testFilePath); + std::pair getSourceAndTestPath(const utbot::ProjectContext &projectContext, + const fs::path &filePath); + fs::path getRelativeDirPath(const utbot::ProjectContext &projectContext, const fs::path &source); std::optional getRelativePathWithShellVariable(const fs::path &shellVariableForBase, diff --git a/server/src/coverage/TestRunner.cpp b/server/src/coverage/TestRunner.cpp index 18cab6da..509d30f5 100644 --- a/server/src/coverage/TestRunner.cpp +++ b/server/src/coverage/TestRunner.cpp @@ -127,29 +127,28 @@ std::vector TestRunner::getTestsToLaunch() { } return result; } + auto [sourcePath, testPath] = Paths::getSourceAndTestPath(projectContext, + projectContext.projectPath / testFilePath.value()); + fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath); if (testName.empty() && functionName.empty()) { //for file - fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath.value()); - fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath); - return getTestsFromMakefile(makefile, testFilePath.value()); + return getTestsFromMakefile(makefile, testPath); } if (testName.empty()) { //for function - fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath.value()); - fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath); - std::string renamedMethodDescription = KleeUtils::getRenamedOperator(functionName); StringUtils::replaceColon(renamedMethodDescription); - std::string filter = "*." + renamedMethodDescription + Paths::TEST_SUFFIX + "*"; + std::string filter = "*." + renamedMethodDescription + Paths::TEST_SUFFIX + "*"; - return getTestsFromMakefile(makefile, testFilePath.value(), filter); + return getTestsFromMakefile(makefile, testPath, filter); } + //for single test - return {UnitTest{testFilePath.value(), testSuite, testName}}; + return {UnitTest{testPath, testSuite, testName}}; } grpc::Status TestRunner::runTests(bool withCoverage, const std::optional &testTimeout) { From e262a31261c9769cca86ecc109327fb2129b8e07 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Wed, 15 May 2024 16:01:29 +0300 Subject: [PATCH 2/6] Add compile only tests in makefiles --- server/src/printers/NativeMakefilePrinter.cpp | 5 ++++- server/src/printers/TestMakefilesPrinter.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/printers/NativeMakefilePrinter.cpp b/server/src/printers/NativeMakefilePrinter.cpp index 2fb99a74..805aad27 100644 --- a/server/src/printers/NativeMakefilePrinter.cpp +++ b/server/src/printers/NativeMakefilePrinter.cpp @@ -152,7 +152,7 @@ namespace printer { break; } } - + declareAction(stringFormat("$(shell mkdir -p %s >/dev/null)", getRelativePath(buildDirectory))); declareAction(stringFormat("$(shell mkdir -p %s >/dev/null)", getRelativePath(dependencyDirectory))); @@ -345,6 +345,9 @@ namespace printer { { testCompilationCommand.toStringWithChangingDirectoryToNew( getRelativePath(testCompilationCommand.getDirectory())) }); + + declareTarget("compile_test", {testCompilationCommand.getOutput()}, {}); + artifacts.push_back(testCompilationCommand.getOutput()); auto rootLinkUnitInfo = testGen->getTargetBuildDatabase()->getClientLinkUnitInfo(rootPath); diff --git a/server/src/printers/TestMakefilesPrinter.cpp b/server/src/printers/TestMakefilesPrinter.cpp index 28f5adfb..8fdc0a0c 100644 --- a/server/src/printers/TestMakefilesPrinter.cpp +++ b/server/src/printers/TestMakefilesPrinter.cpp @@ -88,6 +88,13 @@ namespace printer { MakefileUtils::getMakeCommand(sharedMakefilePathRelative, "bin", true), " ") }); + + generalMakefilePrinter.declareTarget("compile_test", {TARGET_FORCE}, { + StringUtils::joinWith( + MakefileUtils::getMakeCommand(sharedMakefilePathRelative, "compile_test", true), + " ") + }); + generalMakefilePrinter.declareTarget(TARGET_BUILD, {TARGET_FORCE}, { StringUtils::stringFormat("%s || %s", StringUtils::joinWith(MakefileUtils::getMakeCommand( From fcf557301d10a41d1f3912f9fb2660044fa2a345 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Fri, 17 May 2024 13:26:13 +0300 Subject: [PATCH 3/6] Fix extern --- server/src/Synchronizer.h | 2 +- server/src/coverage/LlvmCoverageTool.cpp | 3 +-- .../GlobalVariableUsageMatchCallback.cpp | 2 +- server/src/printers/KleePrinter.cpp | 2 +- server/src/printers/Printer.cpp | 25 ++++++++++++++++--- server/src/printers/Printer.h | 17 +++++++------ server/src/printers/TestsPrinter.cpp | 2 +- 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/server/src/Synchronizer.h b/server/src/Synchronizer.h index 2449bfdd..398242f6 100644 --- a/server/src/Synchronizer.h +++ b/server/src/Synchronizer.h @@ -33,7 +33,7 @@ class Synchronizer { [[nodiscard]] bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const; - [[nodiscard]] bool removeStubIfSourceAbsent(const StubOperator &stub) const; + bool removeStubIfSourceAbsent(const StubOperator &stub) const; void synchronizeStubs(std::unordered_set &outdatedStubs, const types::TypesHandler &typesHandler); diff --git a/server/src/coverage/LlvmCoverageTool.cpp b/server/src/coverage/LlvmCoverageTool.cpp index d17adcdc..ac0571ed 100644 --- a/server/src/coverage/LlvmCoverageTool.cpp +++ b/server/src/coverage/LlvmCoverageTool.cpp @@ -112,8 +112,7 @@ LlvmCoverageTool::getCoverageCommands(const std::vector &testsToLaunch for (const std::string &objectFile : objectFiles) { if (firstBIN) { firstBIN = false; - } - else { + } else { exportArguments.emplace_back("-object"); } exportArguments.emplace_back(objectFile); diff --git a/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp b/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp index 34053b6c..b02902ff 100644 --- a/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp +++ b/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp @@ -67,7 +67,7 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu const std::string usedParamTypeString = varDecl->getType().getAsString(); types::Type paramType = types::Type(realParamType, usedParamTypeString, sourceManager); method.globalParams.emplace_back(paramType, usage.variableName, AlignmentFetcher::fetch(varDecl)); - if (varDecl->isExternC() && !varDecl->isKnownToBeDefined()) { + if (varDecl->isExternC() && !varDecl->hasDefinition()) { tests.externVariables.insert({paramType, usage.variableName}); } } diff --git a/server/src/printers/KleePrinter.cpp b/server/src/printers/KleePrinter.cpp index 70c3b32e..c2fd66f3 100644 --- a/server/src/printers/KleePrinter.cpp +++ b/server/src/printers/KleePrinter.cpp @@ -158,7 +158,7 @@ fs::path KleePrinter::writeTmpKleeFile( return filter && forThisFunction && forThisClass; }); - strDeclareSetOfVars(tests.externVariables); + strDeclareSetOfExternVars(tests.externVariables); ss << printer::NL; for (const auto &[methodName, testMethod]: tests.methods) { diff --git a/server/src/printers/Printer.cpp b/server/src/printers/Printer.cpp index e254e059..719846e8 100644 --- a/server/src/printers/Printer.cpp +++ b/server/src/printers/Printer.cpp @@ -88,8 +88,23 @@ namespace printer { std::optional initValue, std::optional alignment, bool complete, - size_t additionalPointersCount) { + size_t additionalPointersCount, + ExternType externType) { ss << LINE_INDENT(); + + switch (externType) { + case ExternType::C : + if (getLanguage() == utbot::Language::CXX) { + ss << "extern \"C\" "; + break; + } + case ExternType::SAME_LANGUAGE : + ss << "extern "; + break; + case ExternType::NONE : + break; + } + printAlignmentIfExists(alignment); auto additionalPointers = StringUtils::repeat("*", additionalPointersCount); if (needDecorate()) { @@ -685,12 +700,14 @@ namespace printer { ss << Copyright::GENERATED_C_CPP_FILE_HEADER << printer::NL; } - Printer::Stream Printer::strDeclareSetOfVars(const std::set &vars) { + Printer::Stream Printer::strDeclareSetOfExternVars(const std::set &vars) { for (const auto &var: vars) { if (var.type.isArray()) { - strDeclareArrayVar(var.type, var.varName, types::PointerUsage::KNOWN_SIZE); + strDeclareArrayVar(var.type, var.varName, types::PointerUsage::KNOWN_SIZE, std::nullopt, + std::nullopt, true, ExternType::C); } else { - strDeclareVar(var.type.mTypeName(), var.varName); + strDeclareVar(var.type.mTypeName(), var.varName, std::nullopt, + std::nullopt, true, 0, ExternType::C); } } return ss; diff --git a/server/src/printers/Printer.h b/server/src/printers/Printer.h index 73795d86..b72fbbe1 100644 --- a/server/src/printers/Printer.h +++ b/server/src/printers/Printer.h @@ -73,21 +73,22 @@ namespace printer { Stream strIfBound(SRef condition); + enum ExternType { + NONE, + SAME_LANGUAGE, + C + }; + Stream strDeclareVar(std::string_view type, std::string_view name, std::optional initValue = std::nullopt, std::optional alignment = std::nullopt, bool complete = true, - size_t additionalPointersCount = 0); + size_t additionalPointersCount = 0, + ExternType externType = ExternType::NONE); Stream strDeclareAbsError(SRef name); - enum ExternType { - NONE, - SAME_LANGUAGE, - C - }; - Stream strDeclareArrayVar(const types::Type &type, std::string_view name, types::PointerUsage usage, @@ -96,7 +97,7 @@ namespace printer { bool complete = true, ExternType externType = ExternType::NONE); - Stream strDeclareSetOfVars(const std::set &vars); + Stream strDeclareSetOfExternVars(const std::set &vars); Stream strAssignVar(std::string_view name, std::string_view value); diff --git a/server/src/printers/TestsPrinter.cpp b/server/src/printers/TestsPrinter.cpp index 7248ee51..67700282 100644 --- a/server/src/printers/TestsPrinter.cpp +++ b/server/src/printers/TestsPrinter.cpp @@ -64,7 +64,7 @@ void TestsPrinter::joinToFinalCode(Tests &tests, const fs::path& generatedHeader genHeaders(tests, generatedHeaderPath); ss << printer::NL; - strDeclareSetOfVars(tests.externVariables); + strDeclareSetOfExternVars(tests.externVariables); ss << "namespace " << PrinterUtils::TEST_NAMESPACE << " {\n"; From 3f70bad4d3614410b8a7a3fe0b48d59b1566790b Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Thu, 23 May 2024 14:00:16 +0300 Subject: [PATCH 4/6] Ignore extern pointers to functions --- server/src/fetchers/GlobalVariableUsageMatchCallback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp b/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp index b02902ff..8d1211a5 100644 --- a/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp +++ b/server/src/fetchers/GlobalVariableUsageMatchCallback.cpp @@ -67,7 +67,7 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu const std::string usedParamTypeString = varDecl->getType().getAsString(); types::Type paramType = types::Type(realParamType, usedParamTypeString, sourceManager); method.globalParams.emplace_back(paramType, usage.variableName, AlignmentFetcher::fetch(varDecl)); - if (varDecl->isExternC() && !varDecl->hasDefinition()) { + if (!paramType.isPointerToFunction() && varDecl->isExternC() && !varDecl->hasDefinition()) { tests.externVariables.insert({paramType, usage.variableName}); } } From 5b3f34041379e04043bf183b0e578deff81f1b2a Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Thu, 23 May 2024 16:52:10 +0300 Subject: [PATCH 5/6] place "calloc" under ifdef --- server/src/building/IRParser.cpp | 6 +- server/src/printers/KleePrinter.cpp | 110 +++++++++++++++------------- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/server/src/building/IRParser.cpp b/server/src/building/IRParser.cpp index 35fd9fdc..f9fe9627 100644 --- a/server/src/building/IRParser.cpp +++ b/server/src/building/IRParser.cpp @@ -25,13 +25,13 @@ bool IRParser::parseModule(const fs::path &rootBitcode, tests::TestsMap &tests) fs::path const &sourceFile = it.key(); tests::Tests &test = it.value(); test.isFilePresentedInArtifact = true; - for (const auto &[methodName, methodDescription] : test.methods) { + for (const auto &[methodName, methodDescription]: test.methods) { std::string entryPointFunction = KleeUtils::entryPointFunction(test, methodName, true); - std::string methodDebugInfo = - StringUtils::stringFormat("Method: '%s', file: '%s'", methodName, sourceFile); if (llvm::Function *pFunction = module->getFunction(entryPointFunction)) { continue; } else { + std::string methodDebugInfo = + StringUtils::stringFormat("Method: '%s', file: '%s'", methodName, sourceFile); LOG_S(DEBUG) << "llvm::Function is null: " << methodDebugInfo; test.isFilePresentedInArtifact = false; } diff --git a/server/src/printers/KleePrinter.cpp b/server/src/printers/KleePrinter.cpp index c2fd66f3..ea0ff3e2 100644 --- a/server/src/printers/KleePrinter.cpp +++ b/server/src/printers/KleePrinter.cpp @@ -22,17 +22,19 @@ using namespace types; using printer::KleePrinter; static const std::string KLEE_GLOBAL_VAR_H = "klee_global_var.h"; -static const std::string CALLOC_DECLARATION = "extern\n" +static const std::string CALLOC_DECLARATION = "#ifndef calloc\n" + "extern\n" "#ifdef __cplusplus\n" "\"C\"\n" "#endif\n" - "void* calloc(size_t num, size_t size);\n"; + "void* calloc(size_t num, size_t size);\n" + "#endif\n"; printer::KleePrinter::KleePrinter(const types::TypesHandler *typesHandler, std::shared_ptr buildDatabase, utbot::Language srcLanguage, const BaseTestGen *testGen) - : Printer(srcLanguage), typesHandler(typesHandler), buildDatabase(std::move(buildDatabase)), testGen(testGen) { + : Printer(srcLanguage), typesHandler(typesHandler), buildDatabase(std::move(buildDatabase)), testGen(testGen) { } void KleePrinter::writePosixWrapper(const Tests &tests, @@ -41,8 +43,10 @@ void KleePrinter::writePosixWrapper(const Tests &tests, strFunctionCall(PrinterUtils::POSIX_INIT, {"&" + PrinterUtils::UTBOT_ARGC, "&" + PrinterUtils::UTBOT_ARGV}); std::string entryPoint = KleeUtils::entryPointFunction(tests, testMethod.name, false, true); strDeclareVar("int", KleeUtils::RESULT_VARIABLE_NAME, constrFunctionCall(entryPoint, - {PrinterUtils::UTBOT_ARGC, PrinterUtils::UTBOT_ARGV, PrinterUtils::UTBOT_ENVP}, - "", std::nullopt, false)); + {PrinterUtils::UTBOT_ARGC, + PrinterUtils::UTBOT_ARGV, + PrinterUtils::UTBOT_ENVP}, + "", std::nullopt, false)); strFunctionCall(PrinterUtils::POSIX_CHECK_STDIN_READ, {}); strReturn(KleeUtils::RESULT_VARIABLE_NAME); closeBrackets(1); @@ -128,7 +132,7 @@ fs::path KleePrinter::writeTmpKleeFile( } auto headers = getIncludePaths(tests, pathSubstitution); - for (const auto &header : headers) { + for (const auto &header: headers) { LOG_S(MAX) << "Header is included in tmpKleeFile: " << header; strInclude(header); } @@ -180,7 +184,7 @@ fs::path KleePrinter::writeTmpKleeFile( } } catch (const UnImplementedException &e) { std::string message = - "Could not generate klee code for method \'" + methodName + "\', skipping it. "; + "Could not generate klee code for method \'" + methodName + "\', skipping it. "; LOG_S(WARNING) << message << e.what(); } } @@ -202,7 +206,7 @@ void KleePrinter::declTestEntryPoint(const Tests &tests, Tests::MethodParam KleePrinter::getKleeMethodParam(tests::Tests::MethodParam const ¶m) { if (param.type.isTwoDimensionalPointer()) { - return { param.type, param.underscoredName(), param.alignment }; + return {param.type, param.underscoredName(), param.alignment}; } else { return param; } @@ -210,12 +214,12 @@ Tests::MethodParam KleePrinter::getKleeMethodParam(tests::Tests::MethodParam con Tests::MethodParam KleePrinter::getKleePostParam(const Tests::MethodParam ¶m) { auto postVariable = KleeUtils::postSymbolicVariable(param.name); - return { param.type, postVariable, param.alignment }; + return {param.type, postVariable, param.alignment}; } Tests::MethodParam KleePrinter::getKleeGlobalParam(tests::Tests::MethodParam const ¶m) { if (param.type.isObjectPointer()) { - return { param.type, param.underscoredName(), param.alignment }; + return {param.type, param.underscoredName(), param.alignment}; } else { return param; } @@ -224,25 +228,25 @@ Tests::MethodParam KleePrinter::getKleeGlobalParam(tests::Tests::MethodParam con Tests::MethodParam KleePrinter::getKleeGlobalPostParam(const Tests::MethodParam &globalParam) { auto postVariable = KleeUtils::postSymbolicVariable(globalParam.name); if (globalParam.type.isObjectPointer()) { - return { globalParam.type.baseTypeObj(), postVariable, globalParam.alignment }; + return {globalParam.type.baseTypeObj(), postVariable, globalParam.alignment}; } else { - return { globalParam.type, postVariable, globalParam.alignment }; + return {globalParam.type, postVariable, globalParam.alignment}; } } void KleePrinter::genPostGlobalSymbolicVariables(const Tests::MethodDescription &testMethod) { - for (const auto &globalParam : testMethod.globalParams) { + for (const auto &globalParam: testMethod.globalParams) { genPostSymbolicVariable(testMethod, getKleeGlobalPostParam(globalParam)); } } void KleePrinter::genPostParamsSymbolicVariables( - const Tests::MethodDescription &testMethod, - std::function filter) { + const Tests::MethodDescription &testMethod, + std::function filter) { if (testMethod.isClassMethod()) { genPostSymbolicVariable(testMethod, getKleePostParam(testMethod.classObj.value())); } - for (const auto ¶m : testMethod.params) { + for (const auto ¶m: testMethod.params) { if (!filter(param)) { continue; } @@ -252,24 +256,25 @@ void KleePrinter::genPostParamsSymbolicVariables( } } -void KleePrinter::genPostSymbolicVariable(const Tests::MethodDescription &testMethod, const Tests::MethodParam &kleeParam) { +void +KleePrinter::genPostSymbolicVariable(const Tests::MethodDescription &testMethod, const Tests::MethodParam &kleeParam) { bool isArray = genParamDeclaration(testMethod, kleeParam); strKleeMakeSymbolic(kleeParam.type, kleeParam.name, !isArray); } void KleePrinter::genGlobalsKleeAssumes(const Tests::MethodDescription &testMethod) { - for (const auto &globalParam : testMethod.globalParams) { + for (const auto &globalParam: testMethod.globalParams) { genPostAssumes(globalParam, true); } } void KleePrinter::genPostParamsKleeAssumes( - const Tests::MethodDescription &testMethod, - std::function filter) { + const Tests::MethodDescription &testMethod, + std::function filter) { if (testMethod.isClassMethod()) { genPostAssumes(testMethod.classObj.value()); } - for (auto ¶m : testMethod.params) { + for (auto ¶m: testMethod.params) { if (!filter(param)) { continue; } @@ -328,7 +333,8 @@ std::string KleePrinter::addTestLineFlag(const std::shared_ptr &lineIn fs::path flagFileFolder = Paths::getFlagsDir(projectContext); fs::path globalFlagFilePath = flagFileFolder / KLEE_GLOBAL_VAR_H; - FileSystemUtils::writeToFile(globalFlagFilePath, StringUtils::stringFormat("extern int %s;", PrinterUtils::KLEE_PATH_FLAG)); + FileSystemUtils::writeToFile(globalFlagFilePath, + StringUtils::stringFormat("extern int %s;", PrinterUtils::KLEE_PATH_FLAG)); fs::path flagFilePath = flagFileFolder / lineInfo->filePath.filename(); FileSystemUtils::writeToFile(flagFilePath, ss.str()); @@ -355,11 +361,11 @@ void KleePrinter::genNonVoidFunctionAssumes(const Tests::MethodDescription &test std::vector KleePrinter::getIncludePaths(const Tests &tests, const PathSubstitution &substitution) const { - return { substitution.substituteLineFlag(tests.sourceFilePath) }; + return {substitution.substituteLineFlag(tests.sourceFilePath)}; } void KleePrinter::genGlobalParamsDeclarations(const Tests::MethodDescription &testMethod) { - for (const auto ¶m : testMethod.globalParams) { + for (const auto ¶m: testMethod.globalParams) { tests::Tests::MethodParam kleeParam = getKleeGlobalParam(param); bool isArray = TypesHandler::isArrayType(param.type); if (param.type.isObjectPointer()) { @@ -378,8 +384,8 @@ void KleePrinter::genGlobalParamsDeclarations(const Tests::MethodDescription &te } void KleePrinter::genParamsDeclarations( - const Tests::MethodDescription &testMethod, - std::function filter) { + const Tests::MethodDescription &testMethod, + std::function filter) { if (testMethod.isClassMethod()) { strDeclareVar(testMethod.classObj->type.typeName(), testMethod.classObj->name); strKleeMakeSymbolic(testMethod.classObj->type, testMethod.classObj->name, @@ -388,13 +394,13 @@ void KleePrinter::genParamsDeclarations( KleeConstraintsPrinter constraintsPrinter(typesHandler, srcLanguage); constraintsPrinter.setTabsDepth(tabsDepth); const auto constraintsBlock = - constraintsPrinter.genConstraints(testMethod.classObj->name, testMethod.classObj->type) - .str(); + constraintsPrinter.genConstraints(testMethod.classObj->name, testMethod.classObj->type) + .str(); ss << constraintsBlock; } - std::unordered_map>typesToNames; - for (const auto ¶m : testMethod.params) { - if(testGen->settingsContext.differentVariablesOfTheSameType){ + std::unordered_map> typesToNames; + for (const auto ¶m: testMethod.params) { + if (testGen->settingsContext.differentVariablesOfTheSameType) { typesToNames[param.type.typeName()].push_back(param.name); } if (!filter(param)) { @@ -450,7 +456,7 @@ bool KleePrinter::genPointerParamDeclaration(const Tests::MethodParam ¶m) { isArray = true; } else if (!param.type.maybeJustPointer()) { size_t size = types::TypesHandler::getElementsNumberInPointerOneDim( - types::PointerUsage::PARAMETER); + types::PointerUsage::PARAMETER); element = constrIndex(element, size); isArray = true; } @@ -470,17 +476,18 @@ void KleePrinter::makeBracketsForStrPredicate(const std::optional &inf } -void KleePrinter::genReturnDeclaration(const Tests::MethodDescription &testMethod, const std::optional &predicateInfo) { +void KleePrinter::genReturnDeclaration(const Tests::MethodDescription &testMethod, + const std::optional &predicateInfo) { // If return type is a pointer, we compare values that are stored at these pointers, // not the pointers themselves Type returnType = types::TypesHandler::isVoid(testMethod.returnType.baseTypeObj()) - ? Type::minimalScalarType() - : testMethod.returnType; + ? Type::minimalScalarType() + : testMethod.returnType; bool maybeArray = returnType.maybeReturnArray(); bool isPointer = testMethod.returnType.isObjectPointer(); std::string type = typesHandler->isAnonymousEnum(returnType) - ? "int" - : returnType.baseType(); + ? "int" + : returnType.baseType(); strDeclareVar(type, KleeUtils::RESULT_VARIABLE_NAME, std::nullopt, std::nullopt, false); makeBracketsForStrPredicate(predicateInfo); if (maybeArray) { @@ -503,13 +510,14 @@ void KleePrinter::genParamsKleeAssumes( bool onlyForOneEntity) { visitor::KleeAssumeReturnValueVisitor(typesHandler, this).visit(testMethod, predicateInfo); if (!onlyForOneEntity && !testedMethod.empty() && !predicateInfo.has_value()) { - std::string assumption = concat("(", PrinterUtils::KLEE_PATH_FLAG, PrinterUtils::EQ_OPERATOR, PrinterUtils::KLEE_PATH_FLAG_SYMBOLIC, ") & (", - PrinterUtils::KLEE_PATH_FLAG_SYMBOLIC, PrinterUtils::EQ_OPERATOR, "1)"); - strFunctionCall(PrinterUtils::KLEE_ASSUME, { assumption }); + std::string assumption = concat("(", PrinterUtils::KLEE_PATH_FLAG, PrinterUtils::EQ_OPERATOR, + PrinterUtils::KLEE_PATH_FLAG_SYMBOLIC, ") & (", + PrinterUtils::KLEE_PATH_FLAG_SYMBOLIC, PrinterUtils::EQ_OPERATOR, "1)"); + strFunctionCall(PrinterUtils::KLEE_ASSUME, {assumption}); } } -void KleePrinter::genConstraints(const Tests::MethodParam ¶m, const std::vector& names) { +void KleePrinter::genConstraints(const Tests::MethodParam ¶m, const std::vector &names) { KleeConstraintsPrinter constraintsPrinter(typesHandler, srcLanguage); constraintsPrinter.setTabsDepth(tabsDepth); const auto constraintsBlock = constraintsPrinter.genConstraints(param, names).str(); @@ -517,9 +525,9 @@ void KleePrinter::genConstraints(const Tests::MethodParam ¶m, const std::vec } void KleePrinter::genKleePathSymbolicIfNeeded( - const std::optional &predicateInfo, - const std::string &testedMethod, - bool onlyForOneEntity) { + const std::optional &predicateInfo, + const std::string &testedMethod, + bool onlyForOneEntity) { if (!predicateInfo.has_value() && !onlyForOneEntity && !testedMethod.empty()) { strDeclareVar("int", PrinterUtils::KLEE_PATH_FLAG_SYMBOLIC); strKleeMakeSymbolic(PrinterUtils::KLEE_PATH_FLAG_SYMBOLIC, true); @@ -565,13 +573,13 @@ void KleePrinter::genKleePathSymbolicAssumeIfNeeded(const std::optional Date: Tue, 11 Jun 2024 18:34:11 +0300 Subject: [PATCH 6/6] Disable test --- server/test/framework/Regression_Tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/test/framework/Regression_Tests.cpp b/server/test/framework/Regression_Tests.cpp index 6b4be2df..c3c49604 100644 --- a/server/test/framework/Regression_Tests.cpp +++ b/server/test/framework/Regression_Tests.cpp @@ -368,7 +368,7 @@ namespace { testUtils::checkMinNumberOfTests(testGen.tests, 1); } - TEST_F(Regression_Test, Extern_Variables) { + TEST_F(Regression_Test, DISABLED_Extern_Variables) { fs::path source = getTestFilePath("issue-514.c"); auto [testGen, status] = createTestForFunction(source, 5); ASSERT_TRUE(status.ok()) << status.error_message();