Skip to content

Commit

Permalink
Fix extern (#683)
Browse files Browse the repository at this point in the history
* Fix extern

* Disable test
  • Loading branch information
ladisgin committed Jun 13, 2024
1 parent b9eb026 commit da6cd74
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 85 deletions.
19 changes: 17 additions & 2 deletions server/src/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ namespace Paths {

fs::path sourcePathToStubPath(const utbot::ProjectContext &projectContext,
const fs::path &source) {
return normalizedTrimmed((projectContext.getTestDirAbsPath() / "stubs" / getRelativeDirPath(projectContext, source) /
sourcePathToStubName(source)));
return normalizedTrimmed(
(projectContext.getTestDirAbsPath() / "stubs" / getRelativeDirPath(projectContext, source) /
sourcePathToStubName(source)));
}

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

std::pair<fs::path, fs::path> getSourceAndTestPath(const utbot::ProjectContext &projectContext,
const fs::path &filePath) {
fs::path sourcePath;
fs::path testPath;
if (isSubPathOf(projectContext.getTestDirAbsPath(), filePath)) {
testPath = filePath;
sourcePath = testPathToSourcePath(projectContext, filePath);
} else {
testPath = sourcePathToTestPath(projectContext, filePath);
sourcePath = filePath;
}
return {sourcePath, testPath};
}

fs::path getMakefilePathFromSourceFilePath(const utbot::ProjectContext &projectContext,
const fs::path &sourceFilePath,
const std::string &suffix) {
Expand Down
3 changes: 3 additions & 0 deletions server/src/Paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ namespace Paths {

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

std::pair<fs::path, fs::path> getSourceAndTestPath(const utbot::ProjectContext &projectContext,
const fs::path &filePath);

fs::path getRelativeDirPath(const utbot::ProjectContext &projectContext, const fs::path &source);

std::optional<std::string> getRelativePathWithShellVariable(const fs::path &shellVariableForBase,
Expand Down
2 changes: 1 addition & 1 deletion server/src/Synchronizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Synchronizer {

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

[[nodiscard]] bool removeStubIfSourceAbsent(const StubOperator &stub) const;
bool removeStubIfSourceAbsent(const StubOperator &stub) const;

void synchronizeStubs(std::unordered_set<StubOperator, HashUtils::StubHash> &outdatedStubs,
const types::TypesHandler &typesHandler);
Expand Down
6 changes: 3 additions & 3 deletions server/src/building/IRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ bool IRParser::parseModule(const fs::path &rootBitcode, tests::TestsMap &tests)
fs::path const &sourceFile = it.key();
tests::Tests &test = it.value();
test.isFilePresentedInArtifact = true;
for (const auto &[methodName, methodDescription] : test.methods) {
for (const auto &[methodName, methodDescription]: test.methods) {
std::string entryPointFunction = KleeUtils::entryPointFunction(test, methodName, true);
std::string methodDebugInfo =
StringUtils::stringFormat("Method: '%s', file: '%s'", methodName, sourceFile);
if (llvm::Function *pFunction = module->getFunction(entryPointFunction)) {
continue;
} else {
std::string methodDebugInfo =
StringUtils::stringFormat("Method: '%s', file: '%s'", methodName, sourceFile);
LOG_S(DEBUG) << "llvm::Function is null: " << methodDebugInfo;
test.isFilePresentedInArtifact = false;
}
Expand Down
3 changes: 1 addition & 2 deletions server/src/coverage/LlvmCoverageTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ LlvmCoverageTool::getCoverageCommands(const std::vector<UnitTest> &testsToLaunch
for (const std::string &objectFile : objectFiles) {
if (firstBIN) {
firstBIN = false;
}
else {
} else {
exportArguments.emplace_back("-object");
}
exportArguments.emplace_back(objectFile);
Expand Down
17 changes: 8 additions & 9 deletions server/src/coverage/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,28 @@ std::vector<UnitTest> TestRunner::getTestsToLaunch() {
}
return result;
}
auto [sourcePath, testPath] = Paths::getSourceAndTestPath(projectContext,
projectContext.projectPath / testFilePath.value());
fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath);

if (testName.empty() && functionName.empty()) {
//for file
fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath.value());
fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath);
return getTestsFromMakefile(makefile, testFilePath.value());
return getTestsFromMakefile(makefile, testPath);
}

if (testName.empty()) {
//for function
fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath.value());
fs::path makefile = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath);


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

std::string filter = "*." + renamedMethodDescription + Paths::TEST_SUFFIX + "*";
std::string filter = "*." + renamedMethodDescription + Paths::TEST_SUFFIX + "*";

return getTestsFromMakefile(makefile, testFilePath.value(), filter);
return getTestsFromMakefile(makefile, testPath, filter);
}

//for single test
return {UnitTest{testFilePath.value(), testSuite, testName}};
return {UnitTest{testPath, testSuite, testName}};
}

grpc::Status TestRunner::runTests(bool withCoverage, const std::optional<std::chrono::seconds> &testTimeout) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/fetchers/GlobalVariableUsageMatchCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu
const std::string usedParamTypeString = varDecl->getType().getAsString();
types::Type paramType = types::Type(realParamType, usedParamTypeString, sourceManager);
method.globalParams.emplace_back(paramType, usage.variableName, AlignmentFetcher::fetch(varDecl));
if (varDecl->isExternC() && !varDecl->isKnownToBeDefined()) {
if (!paramType.isPointerToFunction() && varDecl->isExternC() && !varDecl->hasDefinition()) {
tests.externVariables.insert({paramType, usage.variableName});
}
}
Expand Down
Loading

0 comments on commit da6cd74

Please sign in to comment.