Skip to content

[BUG] Cannot run generated test for 32 bits projects #442 #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion server/src/building/BuildDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <unordered_map>
#include <utility>

const std::string BuildDatabase::BITS_32_FLAG = "-m32";

BuildDatabase::BuildDatabase(
fs::path serverBuildDir,
fs::path buildCommandsJsonPath,
Expand Down Expand Up @@ -426,7 +428,7 @@ void BuildDatabase::BaseFileInfo::addFile(fs::path file) {
}

bool BuildDatabase::ObjectFileInfo::is32bits() const {
return CollectionUtils::contains(command.getCommandLine(), "-m32");
return CollectionUtils::contains(command.getCommandLine(), BITS_32_FLAG);
}

fs::path BuildDatabase::TargetInfo::getOutput() const {
Expand Down
2 changes: 2 additions & 0 deletions server/src/building/BuildDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

class BuildDatabase {
public:
static const std::string BITS_32_FLAG;

struct KleeFilesInfo {
explicit KleeFilesInfo(fs::path kleeFile);

Expand Down
65 changes: 34 additions & 31 deletions server/src/building/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ std::vector<tests::TestMethod> Linker::getTestMethods() {
continue;
}
isAnyOneLinked = true;
auto compilationUnitInfo =
testGen.getClientCompilationUnitInfo(fileName);
for (const auto &[methodName, _] : tests.methods) {
auto compilationUnitInfo =
testGen.getClientCompilationUnitInfo(fileName);
if (compilationUnitInfo->kleeFilesInfo->isCorrectMethod(methodName)) {
testMethods.emplace_back(methodName,
bitcodePath,
Expand All @@ -266,37 +266,40 @@ std::vector<tests::TestMethod> Linker::getTestMethods() {
}
}
} else {
[&] {
for (auto &[fileName, tests] : testGen.tests) {
if (CollectionUtils::contains(brokenLinkFiles, bitcodeFileName.at(fileName))) {
LOG_S(ERROR) << "Couldn't link bitcode file for current source file: "
<< fileName;
continue;
}
isAnyOneLinked = true;
if (fileName != lineInfo->filePath) {
continue;
}
for (const auto &[methodName, method] : tests.methods) {
if (methodName == lineInfo->methodName ||
(lineInfo->forClass &&
method.classObj.has_value() &&
method.classObj->type.typeName() == lineInfo->scopeName)) {
auto compilationUnitInfo =
testGen.getClientCompilationUnitInfo(fileName);
if (compilationUnitInfo->kleeFilesInfo->isCorrectMethod(methodName)) {
tests::TestMethod testMethod{ methodName,
bitcodeFileName.at(lineInfo->filePath),
fileName,
compilationUnitInfo->is32bits()};
testMethods.emplace_back(testMethod);
}
if (!lineInfo->forClass)
return;
bool needBreak = false;
for (auto &[fileName, tests] : testGen.tests) {
if (CollectionUtils::contains(brokenLinkFiles, bitcodeFileName.at(fileName))) {
LOG_S(ERROR) << "Couldn't link bitcode file for current source file: "
<< fileName;
continue;
}
isAnyOneLinked = true;
if (fileName != lineInfo->filePath) {
continue;
}
for (const auto &[methodName, method] : tests.methods) {
if (methodName == lineInfo->methodName ||
(lineInfo->forClass &&
method.classObj.has_value() &&
method.classObj->type.typeName() == lineInfo->scopeName)) {
auto compilationUnitInfo =
testGen.getClientCompilationUnitInfo(fileName);
if (compilationUnitInfo->kleeFilesInfo->isCorrectMethod(methodName)) {
testMethods.emplace_back(methodName,
bitcodeFileName.at(lineInfo->filePath),
fileName,
compilationUnitInfo->is32bits());
}
if (!lineInfo->forClass) {
needBreak = true;
break;
}
}
}
}();
if (needBreak) {
break;
}
}
}
if (!isAnyOneLinked) {
throw CompilationDatabaseException("Couldn't link any files");
Expand All @@ -317,7 +320,7 @@ Linker::Linker(BaseTestGen &testGen,

Result<Linker::LinkResult> Linker::link(const CollectionUtils::MapFileTo<fs::path> &bitcodeFiles,
const fs::path &target,
std::string const &suffixForParentOfStubs,
const std::string &suffixForParentOfStubs,
const std::optional<fs::path> &testedFilePath,
const CollectionUtils::FileSet &stubSources,
bool errorOnMissingBitcode) {
Expand Down
26 changes: 20 additions & 6 deletions server/src/printers/NativeMakefilePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,36 @@ namespace printer {
}

void NativeMakefilePrinter::init() {

bits32Flag = "";
for (auto &[fileName, _] : testGen->tests) {
const auto &ptr = testGen->getClientCompilationUnitInfo(fileName);
if (ptr && ptr->is32bits()) {
bits32Flag = BuildDatabase::BITS_32_FLAG;
break;
}
}

declareAction(stringFormat("$(shell mkdir -p %s >/dev/null)", getRelativePath(buildDirectory)));
declareAction(stringFormat("$(shell mkdir -p %s >/dev/null)",
getRelativePath(dependencyDirectory)));
declareTarget(FORCE, {}, {});

comment("gtest");
comment("{ gtest");

fs::path gtestBuildDirectory = getRelativePath(buildDirectory / "googletest");
fs::path defaultPath = "default.c";
std::vector<std::string> defaultGtestCompileCommandLine{ getRelativePathForLinker(primaryCxxCompiler), "-c", "-std=c++11",
FPIC_FLAG, defaultPath };
std::vector<std::string> defaultGtestCompileCommandLine{
getRelativePathForLinker(primaryCxxCompiler),
bits32Flag,
"-c",
"-std=c++11",
FPIC_FLAG,
defaultPath };
utbot::CompileCommand defaultGtestCompileCommand{ defaultGtestCompileCommandLine,
getRelativePath(buildDirectory), defaultPath };
gtestAllTargets(defaultGtestCompileCommand, gtestBuildDirectory);
gtestMainTargets(defaultGtestCompileCommand, gtestBuildDirectory);
comment("/gtest");
comment("} gtest");
}

fs::path NativeMakefilePrinter::getTemporaryDependencyFile(fs::path const &file) {
Expand Down Expand Up @@ -340,6 +353,7 @@ namespace printer {
sharedOutput.value()) };
if (rootLinkUnitInfo->commands.front().isArchiveCommand()) {
std::vector<std::string> dynamicLinkCommandLine{ getRelativePathForLinker(cxxLinker), "$(LDFLAGS)",
bits32Flag,
pthreadFlag, coverageLinkFlags,
sanitizerLinkFlags, "-o",
getRelativePath(
Expand Down Expand Up @@ -367,7 +381,7 @@ namespace printer {
}
dynamicLinkCommand.setOptimizationLevel(OPTIMIZATION_FLAG);
dynamicLinkCommand.addFlagsToBegin(
{ pthreadFlag, coverageLinkFlags, sanitizerLinkFlags });
{ bits32Flag, pthreadFlag, coverageLinkFlags, sanitizerLinkFlags });
std::copy_if(rootLinkUnitInfo->files.begin(), rootLinkUnitInfo->files.end(), std::back_inserter(filesToLink),
[](const fs::path& path) {return Paths::isLibraryFile(path);});
for(std::string& file : filesToLink) {
Expand Down
1 change: 1 addition & 0 deletions server/src/printers/NativeMakefilePrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace printer {
CompilationUtils::CompilerName primaryCxxCompilerName;
fs::path cxxLinker;

std::string bits32Flag;
std::string pthreadFlag;
std::string coverageLinkFlags;
std::string sanitizerLinkFlags;
Expand Down