From 56bbd54b8fc857f869a0eb076d6120e97b55b8c0 Mon Sep 17 00:00:00 2001 From: Vladislav Kalugin Date: Thu, 14 Sep 2023 18:32:56 +0300 Subject: [PATCH] Add ld to `isArchiveCommand` (#642) * Add ld to linker --- server/src/building/LinkCommand.cpp | 6 ++- server/src/printers/NativeMakefilePrinter.cpp | 4 +- server/test/framework/Regression_Tests.cpp | 1 - server/test/framework/Server_Tests.cpp | 37 +++++++++++++++++++ server/test/framework/main.cpp | 6 ++- server/test/suites/linkage-ld/Makefile | 12 ++++++ server/test/suites/linkage-ld/issue-638.c | 6 +++ submodules/Bear | 2 +- 8 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 server/test/suites/linkage-ld/Makefile create mode 100644 server/test/suites/linkage-ld/issue-638.c 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"; diff --git a/server/test/framework/Regression_Tests.cpp b/server/test/framework/Regression_Tests.cpp index 7bb7cc5ae..0a13f8bbf 100644 --- a/server/test/framework/Regression_Tests.cpp +++ b/server/test/framework/Regression_Tests.cpp @@ -400,5 +400,4 @@ namespace { "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/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/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; +} 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