From 9000c6b2fa153d11ca36e04ef9665904d27387d4 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Thu, 16 Jun 2022 19:09:17 +0300 Subject: [PATCH] Build ByteCode by make instead of shellExec --- server/src/KleeGenerator.cpp | 9 ++- server/test/framework/Regression_Tests.cpp | 60 ++++++++++++++++++++ server/test/suites/regression/CMakeLists.txt | 6 ++ server/test/suites/regression/issue-276.c | 15 +++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 server/test/suites/regression/issue-276.c diff --git a/server/src/KleeGenerator.cpp b/server/src/KleeGenerator.cpp index cd07dea60..81a7d43d5 100644 --- a/server/src/KleeGenerator.cpp +++ b/server/src/KleeGenerator.cpp @@ -177,7 +177,14 @@ Result KleeGenerator::defaultBuild(const fs::path &hintPath, auto &command = optionalCommand.value(); command.setSourcePath(sourceFilePath); command.setOutput(bitcodeFilePath); - auto [out, status, _] = ShellExecTask::executeUtbotCommand(command, buildDirPath, projectContext.projectName); + + printer::DefaultMakefilePrinter makefilePrinter; + makefilePrinter.declareTarget("build", {command.getSourcePath()}, {command.toStringWithChangingDirectory()}); + fs::path makefile = projectTmpPath / "BCForKLEE.mk"; + FileSystemUtils::writeToFile(makefile, makefilePrinter.ss.str()); + + auto makefileCommand = MakefileUtils::makefileCommand(projectContext, makefile, "build"); + auto [out, status, _] = makefileCommand.run(); if (status != 0) { LOG_S(ERROR) << "Compilation for " << sourceFilePath << " failed.\n" << "Command: \"" << command.toString() << "\"\n" diff --git a/server/test/framework/Regression_Tests.cpp b/server/test/framework/Regression_Tests.cpp index 3379134c2..834a230d7 100644 --- a/server/test/framework/Regression_Tests.cpp +++ b/server/test/framework/Regression_Tests.cpp @@ -268,4 +268,64 @@ namespace { } }), "hash"); } + + TEST_F(Regression_Test, Export_Empty) { + fs::path source = getTestFilePath("issue-276.c"); + auto [testGen, status] = createTestForFunction(source, 2); + + ASSERT_TRUE(status.ok()) << status.error_message(); + + checkTestCasePredicates( + testGen.tests.at(source).methods.begin().value().testCases, + std::vector( + { [](const tests::Tests::MethodTestCase &testCase) { + return testCase.returnValue.view->getEntryValue(nullptr) == "0"; + } }), + "f1"); + } + + TEST_F(Regression_Test, Export_Empty_String) { + fs::path source = getTestFilePath("issue-276.c"); + auto [testGen, status] = createTestForFunction(source, 6); + + ASSERT_TRUE(status.ok()) << status.error_message(); + + checkTestCasePredicates( + testGen.tests.at(source).methods.begin().value().testCases, + std::vector( + { [](const tests::Tests::MethodTestCase &testCase) { + return testCase.returnValue.view->getEntryValue(nullptr) == "'\\0'"; + } }), + "f2"); + } + + TEST_F(Regression_Test, Export_Int) { + fs::path source = getTestFilePath("issue-276.c"); + auto [testGen, status] = createTestForFunction(source, 10); + + ASSERT_TRUE(status.ok()) << status.error_message(); + + checkTestCasePredicates( + testGen.tests.at(source).methods.begin().value().testCases, + std::vector( + { [](const tests::Tests::MethodTestCase &testCase) { + return testCase.returnValue.view->getEntryValue(nullptr) == "4"; + } }), + "f3"); + } + + TEST_F(Regression_Test, Export_String_Int) { + fs::path source = getTestFilePath("issue-276.c"); + auto [testGen, status] = createTestForFunction(source, 14); + + ASSERT_TRUE(status.ok()) << status.error_message(); + + checkTestCasePredicates( + testGen.tests.at(source).methods.begin().value().testCases, + std::vector( + { [](const tests::Tests::MethodTestCase &testCase) { + return testCase.returnValue.view->getEntryValue(nullptr) == "'4'"; + } }), + "f4"); + } } diff --git a/server/test/suites/regression/CMakeLists.txt b/server/test/suites/regression/CMakeLists.txt index 48aa5b059..9d051a996 100644 --- a/server/test/suites/regression/CMakeLists.txt +++ b/server/test/suites/regression/CMakeLists.txt @@ -40,4 +40,10 @@ add_library(PR153 PR153.c) add_library(GH215 GH215.c) +add_library(issue-276 issue-276.c) +target_compile_definitions(issue-276 PUBLIC EXPORT1=) +target_compile_definitions(issue-276 PUBLIC EXPORT2="") +target_compile_definitions(issue-276 PUBLIC EXPORT3=4) +target_compile_definitions(issue-276 PUBLIC EXPORT4="4") + set_target_properties(regression PROPERTIES LINK_WHAT_YOU_USE TRUE) diff --git a/server/test/suites/regression/issue-276.c b/server/test/suites/regression/issue-276.c new file mode 100644 index 000000000..d2ceb0aa2 --- /dev/null +++ b/server/test/suites/regression/issue-276.c @@ -0,0 +1,15 @@ +int EXPORT1 f1() { + return 0; +} + +char* f2() { + return EXPORT2; +} + +int f3() { + return EXPORT3; +} + +char* f4() { + return EXPORT4; +}