From 69a206b310b3ae4e8987625341cfc3a382e896c7 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Tue, 12 Sep 2023 19:24:01 +0300 Subject: [PATCH 1/4] Simple implementation --- server/src/building/LinkCommand.cpp | 6 ++++-- server/src/printers/NativeMakefilePrinter.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/src/building/LinkCommand.cpp b/server/src/building/LinkCommand.cpp index bc2f88a2a..ca084d861 100644 --- a/server/src/building/LinkCommand.cpp +++ b/server/src/building/LinkCommand.cpp @@ -62,11 +62,13 @@ namespace utbot { } bool LinkCommand::isArchiveCommand() const { - return StringUtils::contains(getBuildTool().filename().c_str(), "ar"); + return StringUtils::contains(getBuildTool().filename().c_str(), "ld") || + StringUtils::contains(getBuildTool().filename().c_str(), "ar"); } bool LinkCommand::isSharedLibraryCommand() const { - return CollectionUtils::contains(commandLine, "-shared"); + return StringUtils::contains(getBuildTool().filename().c_str(), "ld") || + CollectionUtils::contains(commandLine, "-shared"); } void LinkCommand::initOutput() { diff --git a/server/src/printers/NativeMakefilePrinter.cpp b/server/src/printers/NativeMakefilePrinter.cpp index 0e178e678..fc120bebd 100644 --- a/server/src/printers/NativeMakefilePrinter.cpp +++ b/server/src/printers/NativeMakefilePrinter.cpp @@ -20,11 +20,11 @@ namespace printer { using StringUtils::stringFormat; static const std::string STUB_OBJECT_FILES_NAME = "STUB_OBJECT_FILES"; - static const std::string STUB_OBJECT_FILES = "$(STUB_OBJECT_FILES)"; + static const std::string STUB_OBJECT_FILES = "$(" + STUB_OBJECT_FILES_NAME + ")"; static const std::string FPIC_FLAG = "-fPIC"; static const std::vector SANITIZER_NEEDED_FLAGS = { - "-g", "-fno-omit-frame-pointer", "-fno-optimize-sibling-calls" + "-g", "-fno-omit-frame-pointer", "-fno-optimize-sibling-calls" }; static const std::string STATIC_FLAG = "-static"; static const std::string SHARED_FLAG = "-shared"; From 8ec25ef35799517b196d0e01ab385fcd3cfc5d48 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Thu, 14 Sep 2023 13:33:43 +0300 Subject: [PATCH 2/4] Add test for ld linker --- server/test/framework/Regression_Tests.cpp | 26 +++++++++++++++ server/test/framework/Server_Tests.cpp | 37 ++++++++++++++++++++++ server/test/framework/main.cpp | 6 +++- server/test/suites/linkage-ld/issue-638.c | 6 ++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 server/test/suites/linkage-ld/issue-638.c diff --git a/server/test/framework/Regression_Tests.cpp b/server/test/framework/Regression_Tests.cpp index 7bb7cc5ae..2c4211c53 100644 --- a/server/test/framework/Regression_Tests.cpp +++ b/server/test/framework/Regression_Tests.cpp @@ -401,4 +401,30 @@ namespace { ); } + TEST_F(Regression_Test, LD_linker) { + fs::path source = getTestFilePath("ISSUE-680/issue-680.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) == "-2"; + }, + [](const tests::Tests::MethodTestCase &testCase) { + return testCase.returnValue.view->getEntryValue(nullptr) == "-1"; + }, + [](const tests::Tests::MethodTestCase &testCase) { + return testCase.returnValue.view->getEntryValue(nullptr) == "0"; + }, + [](const tests::Tests::MethodTestCase &testCase) { + return testCase.returnValue.view->getEntryValue(nullptr) == "1"; + } + }), + "isCorrectPointerStruct" + ); + } + } diff --git a/server/test/framework/Server_Tests.cpp b/server/test/framework/Server_Tests.cpp index dd738b3d7..2ae7f7177 100644 --- a/server/test/framework/Server_Tests.cpp +++ b/server/test/framework/Server_Tests.cpp @@ -1574,6 +1574,43 @@ namespace { testUtils::checkStatusesCount(resultMap, tests, expectedStatusCountMap); } + TEST_F(Server_Test, Linkage_LD) { + std::string suite = "linkage-ld"; + setSuite(suite); + static const std::string issue_c = getTestFilePath("issue-638.c"); + auto projectRequest = createProjectRequest(projectName, suitePath, buildDirRelativePath, srcPaths, + GrpcUtils::UTBOT_AUTO_TARGET_PATH, false, false, 30, ErrorMode::FAILING); + auto request = GrpcUtils::createFileRequest(std::move(projectRequest), issue_c); + auto testGen = FileTestGen(*request, writer.get(), TESTMODE); + + Status status = Server::TestsGenServiceImpl::ProcessBaseTestRequest(testGen, writer.get()); + ASSERT_TRUE(status.ok()) << status.error_message(); + + testUtils::checkMinNumberOfTests(testGen.tests, 2); + + auto testFilter = GrpcUtils::createTestFilterForProject(); + auto runRequest = createCoverageAndResultsRequest( + projectName, suitePath, suitePath / "tests", + buildDirRelativePath, std::move(testFilter)); + auto coverageAndResultsWriter = std::make_unique(nullptr); + CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; + utbot::SettingsContext settingsContext{ true, true, 45, 0, true, false, ErrorMode::FAILING, false}; + coverageGenerator.generate(false, settingsContext); + + ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); + + auto resultMap = coverageGenerator.getTestResultMap(); + auto tests = coverageGenerator.getTestsToLaunch(); + + ASSERT_FALSE(resultMap.empty()); + EXPECT_EQ(resultMap.getNumberOfTests(), 2); + + testUtils::checkStatuses(resultMap, tests); + + StatusCountMap expectedStatusCountMap{{testsgen::TEST_PASSED, 2}}; + testUtils::checkStatusesCount(resultMap, tests, expectedStatusCountMap); + } + TEST_F(Server_Test, Assert_Fail) { std::string suite = "error"; setSuite(suite); diff --git a/server/test/framework/main.cpp b/server/test/framework/main.cpp index 6e900c9e0..a567632f2 100644 --- a/server/test/framework/main.cpp +++ b/server/test/framework/main.cpp @@ -68,7 +68,11 @@ int main(int argc, char **argv) { testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("targets"), clang); - testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("object-file"), clang, testUtils::MAKE_BUILD_COMMANDS_TOOL); + testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("object-file"), clang, + testUtils::MAKE_BUILD_COMMANDS_TOOL); + + testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("linkage-ld"), clang, + testUtils::MAKE_BUILD_COMMANDS_TOOL); testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("small-project"), gcc); diff --git a/server/test/suites/linkage-ld/issue-638.c b/server/test/suites/linkage-ld/issue-638.c new file mode 100644 index 000000000..c62ce3db4 --- /dev/null +++ b/server/test/suites/linkage-ld/issue-638.c @@ -0,0 +1,6 @@ +int abs(int i) { + if (i < 0) { + return -1 * i; + } + return i; +} From bbb497ecb3b5e0560f5fc05f9e1ab5b17826f373 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Thu, 14 Sep 2023 14:04:13 +0300 Subject: [PATCH 3/4] Add makefile for test and new Bear version --- server/test/suites/linkage-ld/Makefile | 12 ++++++++++++ submodules/Bear | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 server/test/suites/linkage-ld/Makefile diff --git a/server/test/suites/linkage-ld/Makefile b/server/test/suites/linkage-ld/Makefile new file mode 100644 index 000000000..7b5385e73 --- /dev/null +++ b/server/test/suites/linkage-ld/Makefile @@ -0,0 +1,12 @@ +.PHONY: all clean + +all: issue-638.so + +clean: + rm issue-638.o issue-638.so + +issue-638.o: issue-638.c + clang -c -o issue-638.o issue-638.c + +issue-638.so: issue-638.o + ld --shared -o issue-638.so issue-638.o diff --git a/submodules/Bear b/submodules/Bear index d9da503e7..e9fe74c53 160000 --- a/submodules/Bear +++ b/submodules/Bear @@ -1 +1 @@ -Subproject commit d9da503e73e06d30a72b416d6dd8be4612e96c09 +Subproject commit e9fe74c5341b43d945acb16b1a9d277a52159330 From e1eed8444c67d4851332594cf2f8823d364557e2 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Thu, 14 Sep 2023 15:37:50 +0300 Subject: [PATCH 4/4] remove useless --- server/test/framework/Regression_Tests.cpp | 27 ---------------------- 1 file changed, 27 deletions(-) diff --git a/server/test/framework/Regression_Tests.cpp b/server/test/framework/Regression_Tests.cpp index 2c4211c53..0a13f8bbf 100644 --- a/server/test/framework/Regression_Tests.cpp +++ b/server/test/framework/Regression_Tests.cpp @@ -400,31 +400,4 @@ namespace { "isCorrectPointerStruct" ); } - - TEST_F(Regression_Test, LD_linker) { - fs::path source = getTestFilePath("ISSUE-680/issue-680.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) == "-2"; - }, - [](const tests::Tests::MethodTestCase &testCase) { - return testCase.returnValue.view->getEntryValue(nullptr) == "-1"; - }, - [](const tests::Tests::MethodTestCase &testCase) { - return testCase.returnValue.view->getEntryValue(nullptr) == "0"; - }, - [](const tests::Tests::MethodTestCase &testCase) { - return testCase.returnValue.view->getEntryValue(nullptr) == "1"; - } - }), - "isCorrectPointerStruct" - ); - } - }