diff --git a/server/proto/testgen.proto b/server/proto/testgen.proto index 6fdd82c5c..24a044c1a 100644 --- a/server/proto/testgen.proto +++ b/server/proto/testgen.proto @@ -106,6 +106,7 @@ message SettingsContext { bool useStubs = 6; ErrorMode errorMode = 7; bool differentVariablesOfTheSameType = 8; + bool skipObjectWithoutSource = 9; } message SnippetRequest { diff --git a/server/src/Server.cpp b/server/src/Server.cpp index 848a7f326..39d3c03a4 100644 --- a/server/src/Server.cpp +++ b/server/src/Server.cpp @@ -588,7 +588,8 @@ Status Server::TestsGenServiceImpl::PrintModulesContent(ServerContext *context, utbot::ProjectContext projectContext{*request}; fs::path serverBuildDir = Paths::getUTBotBuildDir(projectContext); - std::shared_ptr buildDatabase = std::make_shared(projectContext); + std::shared_ptr buildDatabase = + std::make_shared(projectContext, true); StubSourcesFinder(buildDatabase).printAllModules(); return Status::OK; } @@ -663,7 +664,7 @@ Status Server::TestsGenServiceImpl::GetProjectTargets(ServerContext *context, try { utbot::ProjectContext projectContext{request->projectcontext()}; - auto buildDatabase = std::make_shared(projectContext); + auto buildDatabase = std::make_shared(projectContext, true); std::vector targets = buildDatabase->getAllTargetPaths(); ProjectTargetsWriter targetsWriter(response); targetsWriter.writeResponse(projectContext, targets); @@ -690,7 +691,7 @@ Status Server::TestsGenServiceImpl::GetFileTargets(ServerContext *context, try { utbot::ProjectContext projectContext{request->projectcontext()}; - auto buildDatabase = std::make_shared(projectContext); + auto buildDatabase = std::make_shared(projectContext, true); fs::path path = request->path(); auto targetPaths = buildDatabase->getTargetPathsForSourceFile(path); FileTargetsWriter targetsWriter{response}; diff --git a/server/src/SettingsContext.cpp b/server/src/SettingsContext.cpp index 746075602..022cc1784 100644 --- a/server/src/SettingsContext.cpp +++ b/server/src/SettingsContext.cpp @@ -10,27 +10,31 @@ namespace utbot { bool useDeterministicSearcher, bool useStubs, testsgen::ErrorMode errorMode, - bool differentVariablesOfTheSameType) - : generateForStaticFunctions(generateForStaticFunctions), - verbose(verbose), - timeoutPerFunction(timeoutPerFunction > 0 - ? std::make_optional(std::chrono::seconds{ timeoutPerFunction }) + bool differentVariablesOfTheSameType, + bool skipObjectWithoutSource) + : generateForStaticFunctions(generateForStaticFunctions), + verbose(verbose), + timeoutPerFunction(timeoutPerFunction > 0 + ? std::make_optional(std::chrono::seconds{timeoutPerFunction}) : std::nullopt), - timeoutPerTest(timeoutPerTest > 0 - ? std::make_optional(std::chrono::seconds{ timeoutPerTest }) - : std::nullopt), - useDeterministicSearcher(useDeterministicSearcher), useStubs(useStubs), - errorMode(errorMode), - differentVariablesOfTheSameType (differentVariablesOfTheSameType) { + timeoutPerTest(timeoutPerTest > 0 + ? std::make_optional(std::chrono::seconds{timeoutPerTest}) + : std::nullopt), + useDeterministicSearcher(useDeterministicSearcher), useStubs(useStubs), + errorMode(errorMode), + differentVariablesOfTheSameType(differentVariablesOfTheSameType), + skipObjectWithoutSource(skipObjectWithoutSource) { } + SettingsContext::SettingsContext(const testsgen::SettingsContext &settingsContext) - : SettingsContext(settingsContext.generateforstaticfunctions(), + : SettingsContext(settingsContext.generateforstaticfunctions(), settingsContext.verbose(), settingsContext.timeoutperfunction(), settingsContext.timeoutpertest(), settingsContext.usedeterministicsearcher(), settingsContext.usestubs(), settingsContext.errormode(), - settingsContext.differentvariablesofthesametype()) { + settingsContext.differentvariablesofthesametype(), + settingsContext.skipobjectwithoutsource()) { } } diff --git a/server/src/SettingsContext.h b/server/src/SettingsContext.h index 9acb075c9..86eb86af8 100644 --- a/server/src/SettingsContext.h +++ b/server/src/SettingsContext.h @@ -21,7 +21,8 @@ namespace utbot { bool useDeterministicSearcher, bool useStubs, testsgen::ErrorMode errorMode, - bool differentVariablesOfTheSameType); + bool differentVariablesOfTheSameType, + bool skipObjectWithoutSource); const bool generateForStaticFunctions; const bool verbose; @@ -30,6 +31,7 @@ namespace utbot { const bool useStubs; testsgen::ErrorMode errorMode; const bool differentVariablesOfTheSameType; + const bool skipObjectWithoutSource; }; } diff --git a/server/src/building/ProjectBuildDatabase.h b/server/src/building/ProjectBuildDatabase.h index 2808a0684..856e13706 100644 --- a/server/src/building/ProjectBuildDatabase.h +++ b/server/src/building/ProjectBuildDatabase.h @@ -7,7 +7,7 @@ class ProjectBuildDatabase : public BuildDatabase { private: void initObjects(const nlohmann::json &compileCommandsJson); - void initInfo(const nlohmann::json &linkCommandsJson); + void initInfo(const nlohmann::json &linkCommandsJson, bool skipObjectWithoutSource); void filterInstalledFiles(); @@ -17,9 +17,9 @@ class ProjectBuildDatabase : public BuildDatabase { public: ProjectBuildDatabase(fs::path buildCommandsJsonPath, fs::path serverBuildDir, - utbot::ProjectContext projectContext); + utbot::ProjectContext projectContext, bool skipObjectWithoutSource); - explicit ProjectBuildDatabase(utbot::ProjectContext projectContext); + explicit ProjectBuildDatabase(utbot::ProjectContext projectContext, bool skipObjectWithoutSource); }; diff --git a/server/src/building/ProjectBuildDatabse.cpp b/server/src/building/ProjectBuildDatabse.cpp index 84ac3db1e..39d711f32 100644 --- a/server/src/building/ProjectBuildDatabse.cpp +++ b/server/src/building/ProjectBuildDatabse.cpp @@ -31,7 +31,8 @@ static std::string tryConvertOptionToPath(const std::string &possibleFilePath, c ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath, fs::path _serverBuildDir, - utbot::ProjectContext _projectContext) : + utbot::ProjectContext _projectContext, + bool skipObjectWithoutSource) : BuildDatabase(_serverBuildDir, _buildCommandsJsonPath, fs::canonical(_buildCommandsJsonPath / "link_commands.json"), @@ -47,7 +48,7 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath, auto linkCommandsJson = JsonUtils::getJsonFromFile(linkCommandsJsonPath); auto compileCommandsJson = JsonUtils::getJsonFromFile(compileCommandsJsonPath); initObjects(compileCommandsJson); - initInfo(linkCommandsJson); + initInfo(linkCommandsJson, skipObjectWithoutSource); filterInstalledFiles(); addLocalSharedLibraries(); fillTargetInfoParents(); @@ -58,9 +59,10 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath, } } -ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext) : ProjectBuildDatabase( +ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext, bool skipObjectWithoutSource) + : ProjectBuildDatabase( CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext), - Paths::getUTBotBuildDir(projectContext), std::move(projectContext)) { + Paths::getUTBotBuildDir(projectContext), std::move(projectContext), skipObjectWithoutSource) { } @@ -154,7 +156,7 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson } } -void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) { +void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool skipObjectWithoutSource) { for (nlohmann::json const &linkCommand: linkCommandsJson) { fs::path directory = linkCommand.at("directory").get(); std::vector jsonArguments; @@ -189,7 +191,6 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) { if (ignoredOutput.count(currentFile)) { continue; } - targetInfo->addFile(currentFile); if (Paths::isObjectFile(currentFile)) { if (!CollectionUtils::containsKey(objectFileInfos, currentFile) && !CollectionUtils::containsKey(objectFileInfos, @@ -197,6 +198,10 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) { std::string message = "compile_commands.json doesn't contain a command for object file " + currentFile.string(); + if (skipObjectWithoutSource) { + LOG_S(WARNING) << message; + continue; + } LOG_S(ERROR) << message; throw CompilationDatabaseException(message); } @@ -207,6 +212,7 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) { objectFileInfos[relative(currentFile, directory)]->linkUnit = output; } } + targetInfo->addFile(currentFile); } targetInfo->commands.emplace_back(command); } diff --git a/server/src/commands/Commands.cpp b/server/src/commands/Commands.cpp index a85cab399..77be39ec3 100644 --- a/server/src/commands/Commands.cpp +++ b/server/src/commands/Commands.cpp @@ -416,6 +416,10 @@ bool Commands::SettingsContextOptionGroup::doDifferentVariablesOfTheSameType() c return differentVariablesOfTheSameType; } +bool Commands::SettingsContextOptionGroup::getSkipObjectWithoutSource() const { + return skipObjectWithoutSource; +} + Commands::RunTestsCommands::RunTestsCommands(Commands::MainCommands &commands) { runCommand = commands.getRunTestsCommand(); diff --git a/server/src/commands/Commands.h b/server/src/commands/Commands.h index 2ee83d436..10c801edb 100644 --- a/server/src/commands/Commands.h +++ b/server/src/commands/Commands.h @@ -246,6 +246,7 @@ namespace Commands { [[nodiscard]] ErrorMode getErrorMode() const; [[nodiscard]] bool doDifferentVariablesOfTheSameType() const; + [[nodiscard]] bool getSkipObjectWithoutSource() const; private: CLI::Option_group *settingsContextOptions; @@ -257,6 +258,7 @@ namespace Commands { bool noStubs = false; ErrorMode errorMode = ErrorMode::FAILING; bool differentVariablesOfTheSameType = false; + bool skipObjectWithoutSource = false; }; }; diff --git a/server/src/testgens/ProjectTestGen.cpp b/server/src/testgens/ProjectTestGen.cpp index 4495d164d..627a74645 100644 --- a/server/src/testgens/ProjectTestGen.cpp +++ b/server/src/testgens/ProjectTestGen.cpp @@ -16,9 +16,11 @@ ProjectTestGen::ProjectTestGen(const testsgen::ProjectRequest &request, testMode), request(&request) { fs::create_directories(projectContext.testDirPath); compileCommandsJsonPath = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext); - projectBuildDatabase = std::make_shared(compileCommandsJsonPath, serverBuildDir, projectContext); + projectBuildDatabase = std::make_shared(compileCommandsJsonPath, serverBuildDir, + projectContext, + settingsContext.skipObjectWithoutSource); if (sourceFile.has_value() && Paths::isSourceFile(sourceFile.value()) && - (request.targetpath() == GrpcUtils::UTBOT_AUTO_TARGET_PATH || request.targetpath().empty())) { + (request.targetpath() == GrpcUtils::UTBOT_AUTO_TARGET_PATH || request.targetpath().empty())) { targetBuildDatabase = std::make_shared(projectBuildDatabase.get(), sourceFile.value()); } else { targetBuildDatabase = std::make_shared(projectBuildDatabase.get(), request.targetpath()); diff --git a/server/src/testgens/SnippetTestGen.cpp b/server/src/testgens/SnippetTestGen.cpp index 600521db3..752afebe7 100644 --- a/server/src/testgens/SnippetTestGen.cpp +++ b/server/src/testgens/SnippetTestGen.cpp @@ -18,8 +18,11 @@ SnippetTestGen::SnippetTestGen(const testsgen::SnippetRequest &request, printer::CCJsonPrinter::createDummyBuildDB(sourcePaths, serverBuildDir); compileCommandsJsonPath = serverBuildDir; utbot::ProjectContext projectContext{request, serverBuildDir}; - projectBuildDatabase = std::make_shared(compileCommandsJsonPath, serverBuildDir, projectContext); - targetBuildDatabase = std::make_shared(projectBuildDatabase.get(), serverBuildDir / SNIPPET_TARGET); + projectBuildDatabase = std::make_shared(compileCommandsJsonPath, serverBuildDir, + projectContext, + settingsContext.skipObjectWithoutSource); + targetBuildDatabase = std::make_shared(projectBuildDatabase.get(), + serverBuildDir / SNIPPET_TARGET); setTargetForSource(filePath); setInitializedTestsMap(); } diff --git a/server/src/utils/CLIUtils.cpp b/server/src/utils/CLIUtils.cpp index 93447cddb..27d6089c8 100644 --- a/server/src/utils/CLIUtils.cpp +++ b/server/src/utils/CLIUtils.cpp @@ -63,7 +63,8 @@ createSettingsContextByOptions(const SettingsContextOptionGroup &settingsContext settingsContextOptionGroup.isDeterministicSearcherUsed(), settingsContextOptionGroup.withStubs(), settingsContextOptionGroup.getErrorMode(), - settingsContextOptionGroup.doDifferentVariablesOfTheSameType()); + settingsContextOptionGroup.doDifferentVariablesOfTheSameType(), + settingsContextOptionGroup.getSkipObjectWithoutSource()); } std::vector getSourcePaths(const ProjectContextOptionGroup &projectContextOptions, diff --git a/server/src/utils/GrpcUtils.cpp b/server/src/utils/GrpcUtils.cpp index d0cf0e403..c862856eb 100644 --- a/server/src/utils/GrpcUtils.cpp +++ b/server/src/utils/GrpcUtils.cpp @@ -37,7 +37,8 @@ namespace GrpcUtils { bool useDeterministicSearcher, bool useStubs, ErrorMode errorMode, - bool differentVariablesOfTheSameType) { + bool differentVariablesOfTheSameType, + bool skipObjectWithoutSource) { auto result = std::make_unique(); result->set_generateforstaticfunctions(generateForStaticFunctions); result->set_verbose(verbose); @@ -47,6 +48,7 @@ namespace GrpcUtils { result->set_usestubs(useStubs); result->set_errormode(errorMode); result->set_differentvariablesofthesametype(differentVariablesOfTheSameType); + result->set_skipobjectwithoutsource(skipObjectWithoutSource); return result; } diff --git a/server/src/utils/GrpcUtils.h b/server/src/utils/GrpcUtils.h index e8378232c..0f22a62f4 100644 --- a/server/src/utils/GrpcUtils.h +++ b/server/src/utils/GrpcUtils.h @@ -29,7 +29,8 @@ namespace GrpcUtils { bool useDeterministicSearcher, bool useStubs, ErrorMode errorMode, - bool differentVariablesOfTheSameType); + bool differentVariablesOfTheSameType, + bool skipObjectWithoutSource); std::unique_ptr createSnippetRequest(std::unique_ptr projectContext, diff --git a/server/test/framework/Server_Tests.cpp b/server/test/framework/Server_Tests.cpp index a430ae853..789d94ca0 100644 --- a/server/test/framework/Server_Tests.cpp +++ b/server/test/framework/Server_Tests.cpp @@ -62,7 +62,8 @@ namespace { auto projectContext = GrpcUtils::createProjectContext( projectName, suitePath, testsDirPath, buildDirRelativePath); - auto settingsContext = GrpcUtils::createSettingsContext(true, false, 30, 0, false, false, ErrorMode::PASSING, false); + auto settingsContext = GrpcUtils::createSettingsContext(true, false, 30, 0, false, false, + ErrorMode::PASSING, false, false); auto request = GrpcUtils::createProjectRequest(std::move(projectContext), std::move(settingsContext), @@ -1312,8 +1313,8 @@ namespace { projectName, suitePath, testDirPath, buildDirRelativePath, std::move(testFilter)); static auto coverageAndResultsWriter = std::make_unique(nullptr); - CoverageAndResultsGenerator coverageGenerator{ request.get(), coverageAndResultsWriter.get() }; - utbot::SettingsContext settingsContext{ true, true, 30, 0, true, false, errorMode, false}; + CoverageAndResultsGenerator coverageGenerator{request.get(), coverageAndResultsWriter.get()}; + utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, errorMode, false, false}; coverageGenerator.generate(withCoverage, settingsContext); EXPECT_FALSE(coverageGenerator.hasExceptions()); return coverageGenerator; @@ -1545,8 +1546,8 @@ namespace { 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}; + CoverageAndResultsGenerator coverageGenerator{runRequest.get(), coverageAndResultsWriter.get()}; + utbot::SettingsContext settingsContext{true, true, 45, 0, true, false, ErrorMode::FAILING, false, false}; coverageGenerator.generate(false, settingsContext); ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); @@ -1563,6 +1564,28 @@ namespace { testUtils::checkStatusesCount(resultMap, tests, expectedStatusCountMap); } + TEST_F(Server_Test, precompiled_obj) { + std::string suite = "precompiled"; + setSuite(suite); + static const std::string source_c = getTestFilePath("source.c"); + auto projectRequest = createProjectRequest(projectName, suitePath, buildDirRelativePath, srcPaths, + GrpcUtils::UTBOT_AUTO_TARGET_PATH, false, false, 30, + ErrorMode::FAILING, false, false); + auto request = GrpcUtils::createFileRequest(std::move(projectRequest), source_c); + EXPECT_THROW(FileTestGen(*request, writer.get(), TESTMODE), CompilationDatabaseException); + + projectRequest = createProjectRequest(projectName, suitePath, buildDirRelativePath, srcPaths, + GrpcUtils::UTBOT_AUTO_TARGET_PATH, false, false, 30, + ErrorMode::FAILING, false, true); + request = GrpcUtils::createFileRequest(std::move(projectRequest), source_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, 1); + } + TEST_F(Server_Test, Linkage_LD) { std::string suite = "linkage-ld"; setSuite(suite); @@ -1583,7 +1606,7 @@ namespace { 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}; + utbot::SettingsContext settingsContext{ true, true, 45, 0, true, false, ErrorMode::FAILING, false, false}; coverageGenerator.generate(false, settingsContext); ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); @@ -1629,7 +1652,7 @@ namespace { buildDirRelativePath, std::move(testFilter)); auto coverageAndResultsWriter = std::make_unique(nullptr); CoverageAndResultsGenerator coverageGenerator{runRequest.get(), coverageAndResultsWriter.get()}; - utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::FAILING, false}; + utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::FAILING, false, false}; coverageGenerator.generate(false, settingsContext); ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); @@ -1677,7 +1700,7 @@ namespace { buildDirRelativePath, std::move(testFilter)); auto coverageAndResultsWriter = std::make_unique(nullptr); CoverageAndResultsGenerator coverageGenerator{runRequest.get(), coverageAndResultsWriter.get()}; - utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::PASSING, false}; + utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::PASSING, false, false}; coverageGenerator.generate(false, settingsContext); ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); @@ -1723,7 +1746,7 @@ namespace { buildDirRelativePath, std::move(testFilter)); auto coverageAndResultsWriter = std::make_unique(nullptr); CoverageAndResultsGenerator coverageGenerator{runRequest.get(), coverageAndResultsWriter.get()}; - utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::FAILING, false}; + utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::FAILING, false, false}; coverageGenerator.generate(false, settingsContext); ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); @@ -1769,7 +1792,7 @@ namespace { buildDirRelativePath, std::move(testFilter)); auto coverageAndResultsWriter = std::make_unique(nullptr); CoverageAndResultsGenerator coverageGenerator{runRequest.get(), coverageAndResultsWriter.get()}; - utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::PASSING, false}; + utbot::SettingsContext settingsContext{true, true, 30, 0, true, false, ErrorMode::PASSING, false, false}; coverageGenerator.generate(false, settingsContext); ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); @@ -1838,11 +1861,11 @@ namespace { auto testFilter = GrpcUtils::createTestFilterForProject(); auto request = createCoverageAndResultsRequest( - projectName, suitePath, testsDirPath, - buildDirRelativePath, std::move(testFilter)); + projectName, suitePath, testsDirPath, + buildDirRelativePath, std::move(testFilter)); auto coverageAndResultsWriter = std::make_unique(nullptr); - CoverageAndResultsGenerator coverageGenerator{ request.get(), coverageAndResultsWriter.get() }; - utbot::SettingsContext settingsContext{ true, true, 15, timeout, true, false, ErrorMode::FAILING, false}; + CoverageAndResultsGenerator coverageGenerator{request.get(), coverageAndResultsWriter.get()}; + utbot::SettingsContext settingsContext{true, true, 15, timeout, true, false, ErrorMode::FAILING, false, false}; coverageGenerator.generate(false, settingsContext); ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); @@ -1929,7 +1952,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -1967,7 +1990,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 15, 0, false, false, ErrorMode::FAILING, false + true, false, 15, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2007,7 +2030,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2060,7 +2083,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 45, 30, false, false, ErrorMode::FAILING, false + true, false, 45, 30, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2098,7 +2121,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2136,7 +2159,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2174,7 +2197,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2212,7 +2235,7 @@ namespace { CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2247,10 +2270,10 @@ namespace { static auto coverageAndResultsWriter = std::make_unique(nullptr); - CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), - coverageAndResultsWriter.get() }; + CoverageAndResultsGenerator coverageGenerator{runRequest.get(), + coverageAndResultsWriter.get()}; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); @@ -2284,11 +2307,11 @@ namespace { projectName, suitePath, testsDirPath, buildDirRelativePath, std::move(testFilter)); static auto coverageAndResultsWriter = - std::make_unique(nullptr); - CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), - coverageAndResultsWriter.get() }; + std::make_unique(nullptr); + CoverageAndResultsGenerator coverageGenerator{runRequest.get(), + coverageAndResultsWriter.get()}; utbot::SettingsContext settingsContext{ - true, false, 45, 0, false, false, ErrorMode::FAILING, false + true, false, 45, 0, false, false, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); diff --git a/server/test/framework/Stub_Tests.cpp b/server/test/framework/Stub_Tests.cpp index de8c4e9df..d815025da 100644 --- a/server/test/framework/Stub_Tests.cpp +++ b/server/test/framework/Stub_Tests.cpp @@ -197,7 +197,7 @@ namespace { static auto coverageAndResultsWriter = std::make_unique(nullptr); CoverageAndResultsGenerator coverageGenerator{runRequest.get(), coverageAndResultsWriter.get()}; - utbot::SettingsContext settingsContext{true, true, 15, 0, true, true, ErrorMode::FAILING, false}; + utbot::SettingsContext settingsContext{true, true, 15, 0, true, true, ErrorMode::FAILING, false, false}; coverageGenerator.generate(true, settingsContext); EXPECT_FALSE(coverageGenerator.hasExceptions()); } @@ -251,7 +251,7 @@ namespace { static auto coverageAndResultsWriter = std::make_unique(nullptr); CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() }; - utbot::SettingsContext settingsContext{ true, true, 15, 0, true, true, ErrorMode::FAILING, false }; + utbot::SettingsContext settingsContext{ true, true, 15, 0, true, true, ErrorMode::FAILING, false, false}; coverageGenerator.generate(true, settingsContext); EXPECT_FALSE(coverageGenerator.hasExceptions()); } @@ -350,10 +350,10 @@ namespace { static auto coverageAndResultsWriter = std::make_unique(nullptr); - CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), - coverageAndResultsWriter.get() }; + CoverageAndResultsGenerator coverageGenerator{runRequest.get(), + coverageAndResultsWriter.get()}; utbot::SettingsContext settingsContext{ - true, false, 45, 30, false, true, ErrorMode::FAILING, false + true, false, 45, 30, false, true, ErrorMode::FAILING, false, false }; coverageGenerator.generate(false, settingsContext); diff --git a/server/test/framework/TestUtils.cpp b/server/test/framework/TestUtils.cpp index 931524c50..439a82c69 100644 --- a/server/test/framework/TestUtils.cpp +++ b/server/test/framework/TestUtils.cpp @@ -229,11 +229,13 @@ namespace testUtils { bool verbose, int kleeTimeout, ErrorMode errorMode, - bool differentVariables) { + bool differentVariables, + bool skipPrecompiled) { auto projectContext = GrpcUtils::createProjectContext( projectName, projectPath, projectPath / "tests", buildDirRelativePath); auto settingsContext = - GrpcUtils::createSettingsContext(true, verbose, kleeTimeout, 0, false, useStubs, errorMode, differentVariables); + GrpcUtils::createSettingsContext(true, verbose, kleeTimeout, 0, false, useStubs, errorMode, + differentVariables, skipPrecompiled); return GrpcUtils::createProjectRequest(std::move(projectContext), std::move(settingsContext), srcPaths, @@ -293,9 +295,10 @@ namespace testUtils { const fs::path &filePath, ErrorMode errorMode) { auto projectContext = - GrpcUtils::createProjectContext(projectName, projectPath, projectPath / "tests", ""); + GrpcUtils::createProjectContext(projectName, projectPath, projectPath / "tests", ""); // we actually don't pass all parameters except test directory and project name on client - auto settingsContext = GrpcUtils::createSettingsContext(true, true, 10, 0, true, false, errorMode, false); + auto settingsContext = GrpcUtils::createSettingsContext(true, true, 10, 0, true, false, errorMode, false, + false); return GrpcUtils::createSnippetRequest(std::move(projectContext), std::move(settingsContext), filePath); } diff --git a/server/test/framework/TestUtils.h b/server/test/framework/TestUtils.h index 66a79e4ee..bbbf925c1 100644 --- a/server/test/framework/TestUtils.h +++ b/server/test/framework/TestUtils.h @@ -78,7 +78,8 @@ namespace testUtils { bool verbose = true, int kleeTimeout = 60, ErrorMode errorMode = ErrorMode::FAILING, - bool differentVariables = false); + bool differentVariables = false, + bool skipPrecompiled = false); std::unique_ptr createFileRequest(const std::string &projectName, const fs::path &projectPath, diff --git a/server/test/framework/main.cpp b/server/test/framework/main.cpp index a567632f2..74281f527 100644 --- a/server/test/framework/main.cpp +++ b/server/test/framework/main.cpp @@ -74,6 +74,9 @@ int main(int argc, char **argv) { testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("linkage-ld"), clang, testUtils::MAKE_BUILD_COMMANDS_TOOL); + testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("precompiled"), clang, + testUtils::MAKE_BUILD_COMMANDS_TOOL); + testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("small-project"), gcc); testUtils::tryExecGetBuildCommands(testUtils::getRelativeTestSuitePath("small-project"), clang); diff --git a/server/test/suites/object-file/Makefile b/server/test/suites/object-file/Makefile index dcdda2e78..0fd345f81 100644 --- a/server/test/suites/object-file/Makefile +++ b/server/test/suites/object-file/Makefile @@ -15,4 +15,4 @@ lib.a: lib1.o lib2.o ar crs -o lib.a lib1.o lib2.o exe: source1.c source2.c lib.a - clang -o exe source1.c source2.c lib.a \ No newline at end of file + clang -o exe source1.c source2.c lib.a diff --git a/server/test/suites/object-file/source2.c b/server/test/suites/object-file/source2.c index 2a280cc72..496fb6016 100644 --- a/server/test/suites/object-file/source2.c +++ b/server/test/suites/object-file/source2.c @@ -1,6 +1,6 @@ #include -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { if (f(argc) < 5) { return 0; } else { diff --git a/server/test/suites/precompiled/Makefile b/server/test/suites/precompiled/Makefile new file mode 100644 index 000000000..c1e1d0374 --- /dev/null +++ b/server/test/suites/precompiled/Makefile @@ -0,0 +1,12 @@ +.PHONY: all clean + +all: exe + +clean: + rm source.o exe + +source.o: source.c + clang -c -o source.o source.c + +exe: source.o + clang -o exe ../linkage-ld/issue-638.o source.o diff --git a/server/test/suites/precompiled/source.c b/server/test/suites/precompiled/source.c new file mode 100644 index 000000000..c062b1279 --- /dev/null +++ b/server/test/suites/precompiled/source.c @@ -0,0 +1,13 @@ +#include + +int g() { + return 15; +} + +int main(int argc, char *argv[]) { + if (abs(argc) < 5) { + return 0; + } else { + return atoi(argv[0]); + } +} diff --git a/vscode-plugin/package.json b/vscode-plugin/package.json index 24a344348..32121399e 100644 --- a/vscode-plugin/package.json +++ b/vscode-plugin/package.json @@ -513,6 +513,11 @@ "default": false, "markdownDescription": "%unittestbot.testsGeneration.differentVariablesOfTheSameType.description%" }, + "unittestbot.testsGeneration.skipObjectWithoutSource": { + "type": "boolean", + "default": false, + "markdownDescription": "%unittestbot.testsGeneration.skipObjectWithoutSource.description%" + }, "unittestbot.testsGeneration.errorMode": { "type": "string", "enum": [ diff --git a/vscode-plugin/package.nls.json b/vscode-plugin/package.nls.json index 880c7c2ff..f873fa05c 100644 --- a/vscode-plugin/package.nls.json +++ b/vscode-plugin/package.nls.json @@ -10,6 +10,7 @@ "unittestbot.testsGeneration.generateForStaticFunctions.description": "True, if you want UTBot to generate tests for static functions. [Learn more](https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#generate-for-static-functions)", "unittestbot.testsGeneration.errorMode.description": "Choose the option: \"Failing\" means that error tests have runtime error, \"Passing\" means that no tests have runtime error.", "unittestbot.testsGeneration.differentVariablesOfTheSameType.description": "True, if you want signature variables of the same type to have different value in generated tests.", + "unittestbot.testsGeneration.skipObjectWithoutSource.description": "True, if you don't want get error for object files that not has compile info.", "unittestbot.visual.showTestResults.description": "True, if you want UTBot to display whether test passed/failed. [Learn more](https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#show-test-results)", "unittestbot.stubs.useStubs.description": "True, if you want UTBot to use generated stubs from /stubs folder instead real files. [Learn more](https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#use-stubs)", "unittestbot.advanced.enableDeveloperMode.description": "Enables hidden commands for debug. [Learn more](https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#enable-developer-mode)", diff --git a/vscode-plugin/src/config/prefs.ts b/vscode-plugin/src/config/prefs.ts index e4bbdeaac..d0d344132 100644 --- a/vscode-plugin/src/config/prefs.ts +++ b/vscode-plugin/src/config/prefs.ts @@ -48,6 +48,8 @@ export class Prefs { public static DIFF_VARS_PREF = 'unittestbot.testsGeneration.differentVariablesOfTheSameType'; + public static SKIP_OBJECT_PREF = 'unittestbot.testsGeneration.skipObjectWithoutSource'; + public static isLocalHost(): boolean { const host = Prefs.getAsset(Prefs.HOST_PREF); @@ -86,7 +88,8 @@ export class Prefs { .setUsedeterministicsearcher(Prefs.useDeterministicSearcher()) .setUsestubs(Prefs.useStubs()) .setErrormode(Prefs.errorMode()) - .setDifferentvariablesofthesametype(Prefs.differentVariablesOfTheSameType()); + .setDifferentvariablesofthesametype(Prefs.differentVariablesOfTheSameType()) + .setSkipobjectwithoutsource(Prefs.skipObjectWithoutSource()); return settingsContext; } @@ -404,4 +407,8 @@ export class Prefs { public static differentVariablesOfTheSameType(): boolean { return this.getAssetBase(Prefs.DIFF_VARS_PREF, true); } + + public static skipObjectWithoutSource(): boolean { + return this.getAssetBase(Prefs.SKIP_OBJECT_PREF, true); + } }