Skip to content

Commit d1ead3c

Browse files
authored
[BUG] Cannot run generated test for 32 bits projects #442 (#445)
- propagates `-m32` to linker and for compilation GT files
1 parent a4f9ebf commit d1ead3c

File tree

5 files changed

+60
-38
lines changed

5 files changed

+60
-38
lines changed

server/src/building/BuildDatabase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <unordered_map>
1919
#include <utility>
2020

21+
const std::string BuildDatabase::BITS_32_FLAG = "-m32";
22+
2123
BuildDatabase::BuildDatabase(
2224
fs::path serverBuildDir,
2325
fs::path buildCommandsJsonPath,
@@ -426,7 +428,7 @@ void BuildDatabase::BaseFileInfo::addFile(fs::path file) {
426428
}
427429

428430
bool BuildDatabase::ObjectFileInfo::is32bits() const {
429-
return CollectionUtils::contains(command.getCommandLine(), "-m32");
431+
return CollectionUtils::contains(command.getCommandLine(), BITS_32_FLAG);
430432
}
431433

432434
fs::path BuildDatabase::TargetInfo::getOutput() const {

server/src/building/BuildDatabase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
class BuildDatabase {
2020
public:
21+
static const std::string BITS_32_FLAG;
22+
2123
struct KleeFilesInfo {
2224
explicit KleeFilesInfo(fs::path kleeFile);
2325

server/src/building/Linker.cpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ std::vector<tests::TestMethod> Linker::getTestMethods() {
254254
continue;
255255
}
256256
isAnyOneLinked = true;
257+
auto compilationUnitInfo =
258+
testGen.getClientCompilationUnitInfo(fileName);
257259
for (const auto &[methodName, _] : tests.methods) {
258-
auto compilationUnitInfo =
259-
testGen.getClientCompilationUnitInfo(fileName);
260260
if (compilationUnitInfo->kleeFilesInfo->isCorrectMethod(methodName)) {
261261
testMethods.emplace_back(methodName,
262262
bitcodePath,
@@ -266,37 +266,40 @@ std::vector<tests::TestMethod> Linker::getTestMethods() {
266266
}
267267
}
268268
} else {
269-
[&] {
270-
for (auto &[fileName, tests] : testGen.tests) {
271-
if (CollectionUtils::contains(brokenLinkFiles, bitcodeFileName.at(fileName))) {
272-
LOG_S(ERROR) << "Couldn't link bitcode file for current source file: "
273-
<< fileName;
274-
continue;
275-
}
276-
isAnyOneLinked = true;
277-
if (fileName != lineInfo->filePath) {
278-
continue;
279-
}
280-
for (const auto &[methodName, method] : tests.methods) {
281-
if (methodName == lineInfo->methodName ||
282-
(lineInfo->forClass &&
283-
method.classObj.has_value() &&
284-
method.classObj->type.typeName() == lineInfo->scopeName)) {
285-
auto compilationUnitInfo =
286-
testGen.getClientCompilationUnitInfo(fileName);
287-
if (compilationUnitInfo->kleeFilesInfo->isCorrectMethod(methodName)) {
288-
tests::TestMethod testMethod{ methodName,
289-
bitcodeFileName.at(lineInfo->filePath),
290-
fileName,
291-
compilationUnitInfo->is32bits()};
292-
testMethods.emplace_back(testMethod);
293-
}
294-
if (!lineInfo->forClass)
295-
return;
269+
bool needBreak = false;
270+
for (auto &[fileName, tests] : testGen.tests) {
271+
if (CollectionUtils::contains(brokenLinkFiles, bitcodeFileName.at(fileName))) {
272+
LOG_S(ERROR) << "Couldn't link bitcode file for current source file: "
273+
<< fileName;
274+
continue;
275+
}
276+
isAnyOneLinked = true;
277+
if (fileName != lineInfo->filePath) {
278+
continue;
279+
}
280+
for (const auto &[methodName, method] : tests.methods) {
281+
if (methodName == lineInfo->methodName ||
282+
(lineInfo->forClass &&
283+
method.classObj.has_value() &&
284+
method.classObj->type.typeName() == lineInfo->scopeName)) {
285+
auto compilationUnitInfo =
286+
testGen.getClientCompilationUnitInfo(fileName);
287+
if (compilationUnitInfo->kleeFilesInfo->isCorrectMethod(methodName)) {
288+
testMethods.emplace_back(methodName,
289+
bitcodeFileName.at(lineInfo->filePath),
290+
fileName,
291+
compilationUnitInfo->is32bits());
292+
}
293+
if (!lineInfo->forClass) {
294+
needBreak = true;
295+
break;
296296
}
297297
}
298298
}
299-
}();
299+
if (needBreak) {
300+
break;
301+
}
302+
}
300303
}
301304
if (!isAnyOneLinked) {
302305
throw CompilationDatabaseException("Couldn't link any files");
@@ -317,7 +320,7 @@ Linker::Linker(BaseTestGen &testGen,
317320

318321
Result<Linker::LinkResult> Linker::link(const CollectionUtils::MapFileTo<fs::path> &bitcodeFiles,
319322
const fs::path &target,
320-
std::string const &suffixForParentOfStubs,
323+
const std::string &suffixForParentOfStubs,
321324
const std::optional<fs::path> &testedFilePath,
322325
const CollectionUtils::FileSet &stubSources,
323326
bool errorOnMissingBitcode) {

server/src/printers/NativeMakefilePrinter.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,36 @@ namespace printer {
144144
}
145145

146146
void NativeMakefilePrinter::init() {
147-
147+
bits32Flag = "";
148+
for (auto &[fileName, _] : testGen->tests) {
149+
const auto &ptr = testGen->getClientCompilationUnitInfo(fileName);
150+
if (ptr && ptr->is32bits()) {
151+
bits32Flag = BuildDatabase::BITS_32_FLAG;
152+
break;
153+
}
154+
}
155+
148156
declareAction(stringFormat("$(shell mkdir -p %s >/dev/null)", getRelativePath(buildDirectory)));
149157
declareAction(stringFormat("$(shell mkdir -p %s >/dev/null)",
150158
getRelativePath(dependencyDirectory)));
151159
declareTarget(FORCE, {}, {});
152160

153-
comment("gtest");
161+
comment("{ gtest");
154162

155163
fs::path gtestBuildDirectory = getRelativePath(buildDirectory / "googletest");
156164
fs::path defaultPath = "default.c";
157-
std::vector<std::string> defaultGtestCompileCommandLine{ getRelativePathForLinker(primaryCxxCompiler), "-c", "-std=c++11",
158-
FPIC_FLAG, defaultPath };
165+
std::vector<std::string> defaultGtestCompileCommandLine{
166+
getRelativePathForLinker(primaryCxxCompiler),
167+
bits32Flag,
168+
"-c",
169+
"-std=c++11",
170+
FPIC_FLAG,
171+
defaultPath };
159172
utbot::CompileCommand defaultGtestCompileCommand{ defaultGtestCompileCommandLine,
160173
getRelativePath(buildDirectory), defaultPath };
161174
gtestAllTargets(defaultGtestCompileCommand, gtestBuildDirectory);
162175
gtestMainTargets(defaultGtestCompileCommand, gtestBuildDirectory);
163-
comment("/gtest");
176+
comment("} gtest");
164177
}
165178

166179
fs::path NativeMakefilePrinter::getTemporaryDependencyFile(fs::path const &file) {
@@ -340,6 +353,7 @@ namespace printer {
340353
sharedOutput.value()) };
341354
if (rootLinkUnitInfo->commands.front().isArchiveCommand()) {
342355
std::vector<std::string> dynamicLinkCommandLine{ getRelativePathForLinker(cxxLinker), "$(LDFLAGS)",
356+
bits32Flag,
343357
pthreadFlag, coverageLinkFlags,
344358
sanitizerLinkFlags, "-o",
345359
getRelativePath(
@@ -367,7 +381,7 @@ namespace printer {
367381
}
368382
dynamicLinkCommand.setOptimizationLevel(OPTIMIZATION_FLAG);
369383
dynamicLinkCommand.addFlagsToBegin(
370-
{ pthreadFlag, coverageLinkFlags, sanitizerLinkFlags });
384+
{ bits32Flag, pthreadFlag, coverageLinkFlags, sanitizerLinkFlags });
371385
std::copy_if(rootLinkUnitInfo->files.begin(), rootLinkUnitInfo->files.end(), std::back_inserter(filesToLink),
372386
[](const fs::path& path) {return Paths::isLibraryFile(path);});
373387
for(std::string& file : filesToLink) {

server/src/printers/NativeMakefilePrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace printer {
2424
CompilationUtils::CompilerName primaryCxxCompilerName;
2525
fs::path cxxLinker;
2626

27+
std::string bits32Flag;
2728
std::string pthreadFlag;
2829
std::string coverageLinkFlags;
2930
std::string sanitizerLinkFlags;

0 commit comments

Comments
 (0)