Skip to content
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

Add skip duplicate commands #660

Merged
merged 1 commit into from
Dec 9, 2023
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
31 changes: 17 additions & 14 deletions server/src/KleeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ KleeGenerator::getCompileCommandForKlee(const fs::path &hintPath,
}
command.setSourcePath(srcFilePath);

auto outFilePath = (forStub ? testGen->getProjectBuildDatabase()->getBitcodeFile(compilationUnitInfo->getOutputFile())
: testGen->getTargetBuildDatabase()->getBitcodeFile(compilationUnitInfo->getOutputFile()));
auto outFilePath = (forStub ? testGen->getProjectBuildDatabase()->getBitcodeFile(
compilationUnitInfo->getOutputFile())
: testGen->getTargetBuildDatabase()->getBitcodeFile(
compilationUnitInfo->getOutputFile()));
fs::create_directories(outFilePath.parent_path());
command.setOutput(outFilePath);
command.setOptimizationLevel("-O0");
Expand Down Expand Up @@ -227,7 +229,7 @@ Result<fs::path> KleeGenerator::defaultBuild(const fs::path &hintPath,

auto makefileCommand = MakefileUtils::MakefileCommand(testGen->projectContext, makefile,
printer::DefaultMakefilePrinter::TARGET_BUILD);
auto[out, status, _] = makefileCommand.run();
auto [out, status, _] = makefileCommand.run();
if (status != 0) {
LOG_S(ERROR) << "Compilation for " << sourceFilePath << " failed.\n"
<< "Command: \"" << commandWithChangingDirectory.toString() << "\"\n"
Expand Down Expand Up @@ -264,7 +266,8 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
const std::shared_ptr<LineInfo> &lineInfo) {
std::vector<fs::path> outFiles;
LOG_S(DEBUG) << "Building generated klee files...";
printer::KleePrinter kleePrinter(&typesHandler, testGen->getTargetBuildDatabase(), utbot::Language::UNKNOWN, testGen);
printer::KleePrinter kleePrinter(&typesHandler, testGen->getTargetBuildDatabase(), utbot::Language::UNKNOWN,
testGen);
ExecUtils::doWorkWithProgress(
testsMap, testGen->progressWriter, "Building generated klee files",
[&](auto const &it) {
Expand Down Expand Up @@ -344,14 +347,14 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
}

void KleeGenerator::parseKTestsToFinalCode(
const utbot::ProjectContext &projectContext,
tests::Tests &tests,
const std::unordered_map<std::string, types::Type> &methodNameToReturnTypeMap,
const std::vector<MethodKtests> &kleeOutput,
const std::shared_ptr<LineInfo> &lineInfo,
bool verbose,
ErrorMode errorMode) {
for (const auto &batch : kleeOutput) {
const utbot::ProjectContext &projectContext,
tests::Tests &tests,
const std::unordered_map<std::string, types::Type> &methodNameToReturnTypeMap,
const std::vector<MethodKtests> &kleeOutput,
const std::shared_ptr<LineInfo> &lineInfo,
bool verbose,
ErrorMode errorMode) {
for (const auto &batch: kleeOutput) {
bool filterByFlag = (lineInfo != nullptr && !lineInfo->forMethod && !lineInfo->forClass &&
!lineInfo->predicateInfo.has_value());
tests::KTestObjectParser KTestObjectParser(typesHandler);
Expand All @@ -375,12 +378,12 @@ void KleeGenerator::parseKTestsToFinalCode(
continue;
}
auto predicate =
lineInfo ? lineInfo->predicateInfo : std::optional<LineInfo::PredicateInfo>{};
lineInfo ? lineInfo->predicateInfo : std::optional<LineInfo::PredicateInfo>{};
testsPrinter.genCode(methodDescription, predicate, verbose, errorMode);
}

printer::HeaderPrinter(Paths::getSourceLanguage(tests.sourceFilePath))
.print(tests.testHeaderFilePath, tests.sourceFilePath, tests.headerCode);
.print(tests.testHeaderFilePath, tests.sourceFilePath, tests.headerCode);
testsPrinter.joinToFinalCode(tests, tests.testHeaderFilePath);
LOG_S(DEBUG) << "Generated code for " << tests.methods.size() << " tests";
}
Expand Down
13 changes: 12 additions & 1 deletion server/src/building/ProjectBuildDatabse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,23 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
LOG_S(WARNING)
<< "Source file " << sourceFile << " outside of project root " << projectContext.projectPath;
kleeFilePathTemplate = Paths::createNewDirForFile(sourceFile, fs::path("/"),
Paths::getUTBotFiles(projectContext) / "outside_of_project");
Paths::getUTBotFiles(projectContext) /
"outside_of_project");
}

fs::path kleeFile = Paths::addSuffix(kleeFilePathTemplate, "_klee");
objectInfo->kleeFilesInfo = std::make_shared<KleeFilesInfo>(kleeFile);

if (CollectionUtils::containsKey(objectFileInfos, outputFile) && Paths::isObjectFile(outputFile)) {
auto previusInfo = objectFileInfos[outputFile];
if (previusInfo->command.getCommandLine() == objectInfo->command.getCommandLine()) {
LOG_S(WARNING) << "Skip duplicate compile command for object file: " << outputFile;
} else {
LOG_S(WARNING) << "Skip second compile command for object file: " << outputFile;
}
continue;
}

if (CollectionUtils::containsKey(objectFileInfos, outputFile) ||
CollectionUtils::containsKey(targetInfos, outputFile)) {
/*
Expand Down
12 changes: 6 additions & 6 deletions server/src/fetchers/GlobalVariableUsageMatchCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void GlobalVariableUsageMatchCallback::run(const MatchFinder::MatchResult &Resul
checkUsage(Result);
}

static std::unordered_set<std::string> BLACK_LIST = { "stdin", "stdout", "stderr" };
static std::unordered_set<std::string> BLACK_LIST = {"stdin", "stdout", "stderr"};

void GlobalVariableUsageMatchCallback::checkUsage(const MatchFinder::MatchResult &Result) {
if (const auto *pVarDecl =
Expand Down Expand Up @@ -50,7 +50,7 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu
clang::SourceManager &sourceManager = functionDecl->getASTContext().getSourceManager();
fs::path sourceFilePath = ClangUtils::getSourceFilePath(sourceManager);
auto const &[iterator, inserted] =
usages.emplace(varDecl->getNameAsString(), functionDecl->getNameAsString());
usages.emplace(varDecl->getNameAsString(), functionDecl->getNameAsString());
auto const &usage = *iterator;

LOG_S(MAX) << "Found usage of global variable \'" << usage.variableName << "\' in function \'"
Expand All @@ -73,21 +73,21 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu
}

GlobalVariableUsageMatchCallback::Usage::Usage(std::string variableName, std::string functionName)
: variableName(std::move(variableName)), functionName(std::move(functionName)) {
: variableName(std::move(variableName)), functionName(std::move(functionName)) {
}

bool GlobalVariableUsageMatchCallback::Usage::operator==(
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
return variableName == rhs.variableName && functionName == rhs.functionName;
}

bool GlobalVariableUsageMatchCallback::Usage::operator!=(
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
return !(rhs == *this);
}

std::size_t GlobalVariableUsageMatchCallback::UsageHash::operator()(
const GlobalVariableUsageMatchCallback::Usage &usage) const {
const GlobalVariableUsageMatchCallback::Usage &usage) const {
size_t seed = 0;
HashUtils::hashCombine(seed, usage.variableName, usage.functionName);
return seed;
Expand Down
2 changes: 1 addition & 1 deletion server/src/printers/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace printer {
typedef const std::vector<std::string> &VSRef;
typedef std::stringstream &Stream;

std::stringstream ss;
std::stringstream ss{};
int tabsDepth = 0;
int commentDepth = 0;
utbot::Language srcLanguage = utbot::Language::UNKNOWN;
Expand Down