Skip to content

Commit da6cd74

Browse files
authored
Fix extern (#683)
* Fix extern * Disable test
1 parent b9eb026 commit da6cd74

14 files changed

+137
-85
lines changed

server/src/Paths.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,9 @@ namespace Paths {
375375

376376
fs::path sourcePathToStubPath(const utbot::ProjectContext &projectContext,
377377
const fs::path &source) {
378-
return normalizedTrimmed((projectContext.getTestDirAbsPath() / "stubs" / getRelativeDirPath(projectContext, source) /
379-
sourcePathToStubName(source)));
378+
return normalizedTrimmed(
379+
(projectContext.getTestDirAbsPath() / "stubs" / getRelativeDirPath(projectContext, source) /
380+
sourcePathToStubName(source)));
380381
}
381382

382383
fs::path testPathToSourcePath(const utbot::ProjectContext &projectContext,
@@ -386,6 +387,20 @@ namespace Paths {
386387
return projectContext.projectPath / relative / filename;
387388
}
388389

390+
std::pair<fs::path, fs::path> getSourceAndTestPath(const utbot::ProjectContext &projectContext,
391+
const fs::path &filePath) {
392+
fs::path sourcePath;
393+
fs::path testPath;
394+
if (isSubPathOf(projectContext.getTestDirAbsPath(), filePath)) {
395+
testPath = filePath;
396+
sourcePath = testPathToSourcePath(projectContext, filePath);
397+
} else {
398+
testPath = sourcePathToTestPath(projectContext, filePath);
399+
sourcePath = filePath;
400+
}
401+
return {sourcePath, testPath};
402+
}
403+
389404
fs::path getMakefilePathFromSourceFilePath(const utbot::ProjectContext &projectContext,
390405
const fs::path &sourceFilePath,
391406
const std::string &suffix) {

server/src/Paths.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ namespace Paths {
404404

405405
fs::path testPathToSourcePath(const utbot::ProjectContext &projectContext, const fs::path &testFilePath);
406406

407+
std::pair<fs::path, fs::path> getSourceAndTestPath(const utbot::ProjectContext &projectContext,
408+
const fs::path &filePath);
409+
407410
fs::path getRelativeDirPath(const utbot::ProjectContext &projectContext, const fs::path &source);
408411

409412
std::optional<std::string> getRelativePathWithShellVariable(const fs::path &shellVariableForBase,

server/src/Synchronizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Synchronizer {
3333

3434
[[nodiscard]] bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const;
3535

36-
[[nodiscard]] bool removeStubIfSourceAbsent(const StubOperator &stub) const;
36+
bool removeStubIfSourceAbsent(const StubOperator &stub) const;
3737

3838
void synchronizeStubs(std::unordered_set<StubOperator, HashUtils::StubHash> &outdatedStubs,
3939
const types::TypesHandler &typesHandler);

server/src/building/IRParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ bool IRParser::parseModule(const fs::path &rootBitcode, tests::TestsMap &tests)
2525
fs::path const &sourceFile = it.key();
2626
tests::Tests &test = it.value();
2727
test.isFilePresentedInArtifact = true;
28-
for (const auto &[methodName, methodDescription] : test.methods) {
28+
for (const auto &[methodName, methodDescription]: test.methods) {
2929
std::string entryPointFunction = KleeUtils::entryPointFunction(test, methodName, true);
30-
std::string methodDebugInfo =
31-
StringUtils::stringFormat("Method: '%s', file: '%s'", methodName, sourceFile);
3230
if (llvm::Function *pFunction = module->getFunction(entryPointFunction)) {
3331
continue;
3432
} else {
33+
std::string methodDebugInfo =
34+
StringUtils::stringFormat("Method: '%s', file: '%s'", methodName, sourceFile);
3535
LOG_S(DEBUG) << "llvm::Function is null: " << methodDebugInfo;
3636
test.isFilePresentedInArtifact = false;
3737
}

server/src/coverage/LlvmCoverageTool.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ LlvmCoverageTool::getCoverageCommands(const std::vector<UnitTest> &testsToLaunch
112112
for (const std::string &objectFile : objectFiles) {
113113
if (firstBIN) {
114114
firstBIN = false;
115-
}
116-
else {
115+
} else {
117116
exportArguments.emplace_back("-object");
118117
}
119118
exportArguments.emplace_back(objectFile);

server/src/coverage/TestRunner.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,28 @@ std::vector<UnitTest> TestRunner::getTestsToLaunch() {
127127
}
128128
return result;
129129
}
130+
auto [sourcePath, testPath] = Paths::getSourceAndTestPath(projectContext,
131+
projectContext.projectPath / testFilePath.value());
132+
fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath);
130133

131134
if (testName.empty() && functionName.empty()) {
132135
//for file
133-
fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath.value());
134-
fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath);
135-
return getTestsFromMakefile(makefile, testFilePath.value());
136+
return getTestsFromMakefile(makefile, testPath);
136137
}
137138

138139
if (testName.empty()) {
139140
//for function
140-
fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath.value());
141-
fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath);
142-
143141

144142
std::string renamedMethodDescription = KleeUtils::getRenamedOperator(functionName);
145143
StringUtils::replaceColon(renamedMethodDescription);
146144

147-
std::string filter = "*." + renamedMethodDescription + Paths::TEST_SUFFIX + "*";
145+
std::string filter = "*." + renamedMethodDescription + Paths::TEST_SUFFIX + "*";
148146

149-
return getTestsFromMakefile(makefile, testFilePath.value(), filter);
147+
return getTestsFromMakefile(makefile, testPath, filter);
150148
}
149+
151150
//for single test
152-
return {UnitTest{testFilePath.value(), testSuite, testName}};
151+
return {UnitTest{testPath, testSuite, testName}};
153152
}
154153

155154
grpc::Status TestRunner::runTests(bool withCoverage, const std::optional<std::chrono::seconds> &testTimeout) {

server/src/fetchers/GlobalVariableUsageMatchCallback.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu
6767
const std::string usedParamTypeString = varDecl->getType().getAsString();
6868
types::Type paramType = types::Type(realParamType, usedParamTypeString, sourceManager);
6969
method.globalParams.emplace_back(paramType, usage.variableName, AlignmentFetcher::fetch(varDecl));
70-
if (varDecl->isExternC() && !varDecl->isKnownToBeDefined()) {
70+
if (!paramType.isPointerToFunction() && varDecl->isExternC() && !varDecl->hasDefinition()) {
7171
tests.externVariables.insert({paramType, usage.variableName});
7272
}
7373
}

0 commit comments

Comments
 (0)