Skip to content

Build ByteCode by make instead of shellExec #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion server/src/KleeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ Result<fs::path> 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"
Expand Down
60 changes: 60 additions & 0 deletions server/test/framework/Regression_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestCasePredicate>(
{ [](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<TestCasePredicate>(
{ [](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<TestCasePredicate>(
{ [](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<TestCasePredicate>(
{ [](const tests::Tests::MethodTestCase &testCase) {
return testCase.returnValue.view->getEntryValue(nullptr) == "'4'";
} }),
"f4");
}
}
6 changes: 6 additions & 0 deletions server/test/suites/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions server/test/suites/regression/issue-276.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
int EXPORT1 f1() {
return 0;
}

char* f2() {
return EXPORT2;
}

int f3() {
return EXPORT3;
}

char* f4() {
return EXPORT4;
}