Skip to content

Commit 547c195

Browse files
author
Vladislav Kalugin
committed
not end
1 parent 131140e commit 547c195

File tree

13 files changed

+173
-135
lines changed

13 files changed

+173
-135
lines changed

server/src/BordersFinder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ BordersFinder::BordersFinder(const fs::path &filePath,
1717
const std::shared_ptr<CompilationDatabase> &compilationDatabase,
1818
const fs::path &compileCommandsJsonPath)
1919
: line(line), classBorder(std::nullopt), clangToolRunner(compilationDatabase) {
20-
buildRootPath = Paths::subtractPath(compileCommandsJsonPath.string(), CompilationUtils::UTBOT_BUILD_DIR_NAME);
20+
// buildRootPath = Paths::subtractPath(compileCommandsJsonPath.string(), CompilationUtils::UTBOT_BUILD_DIR_NAME);
2121
lineInfo.filePath = filePath;
2222
}
2323

server/src/BordersFinder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BordersFinder : public clang::ast_matchers::MatchFinder::MatchCallback {
3131
private:
3232
unsigned line;
3333
LineInfo lineInfo{};
34-
fs::path buildRootPath;
34+
// fs::path buildRootPath;
3535
struct Borders {
3636
struct Position {
3737
unsigned line;

server/src/KleeGenerator.cpp

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,43 @@
1616

1717
using namespace tests;
1818

19-
KleeGenerator::KleeGenerator(
20-
utbot::ProjectContext projectContext,
21-
utbot::SettingsContext settingsContext,
22-
fs::path serverBuildDir,
23-
std::shared_ptr<CompilationDatabase> compilationDatabase,
24-
types::TypesHandler &typesHandler,
25-
PathSubstitution filePathsSubstitution,
26-
std::shared_ptr<BuildDatabase> buildDatabase,
27-
ProgressWriter const *progressWriter)
28-
: projectContext(std::move(projectContext)),
29-
settingsContext(std::move(settingsContext)), projectTmpPath(std::move(serverBuildDir)),
30-
compilationDatabase(std::move(compilationDatabase)),
31-
typesHandler(typesHandler), pathSubstitution(std::move(filePathsSubstitution)),
32-
buildDatabase(std::move(buildDatabase)), progressWriter(progressWriter) {
19+
//KleeGenerator::KleeGenerator(
20+
// utbot::testGen.projectContext testGen.projectContext,
21+
// utbot::SettingsContext settingsContext,
22+
// fs::path serverBuildDir,
23+
// std::shared_ptr<CompilationDatabase> compilationDatabase,
24+
// types::TypesHandler &typesHandler,
25+
// PathSubstitution filePathsSubstitution,
26+
// std::shared_ptr<testGen.buildDatabase> testGen.buildDatabase,
27+
// ProgressWriter const *progressWriter)
28+
// : testGen.projectContext(std::move(testGen.projectContext)),
29+
// settingsContext(std::move(settingsContext)),
30+
// testGen.serverBuildDir(std::move(serverBuildDir)),
31+
// compilationDatabase(std::move(compilationDatabase)),
32+
// typesHandler(typesHandler),
33+
// pathSubstitution(std::move(filePathsSubstitution)),
34+
// testGen.buildDatabase(std::move(testGen.buildDatabase)),
35+
// progressWriter(progressWriter) {
36+
// try {
37+
// fs::create_directories(this->testGen.serverBuildDir);
38+
// fs::create_directories(Paths::getLogDir(this->testGen.projectContext.projectName));
39+
// } catch (const fs::filesystem_error &e) {
40+
// throw FileSystemException("create_directories failed", e);
41+
// }
42+
//}
43+
//
44+
//auto generator = std::make_shared<KleeGenerator>(
45+
// testGen.testGen.projectContext, testGen.settingsContext,
46+
// testGen.serverBuildDir, testGen.testGen.buildDatabase->compilationDatabase, typesHandler,
47+
// pathSubstitution, testGen.testGen.buildDatabase, testGen.progressWriter);
48+
49+
KleeGenerator::KleeGenerator(BaseTestGen &_testGen, types::TypesHandler &typesHandler,
50+
PathSubstitution filePathsSubstitution)
51+
: testGen(_testGen), typesHandler(typesHandler),
52+
pathSubstitution(std::move(filePathsSubstitution)) {
3353
try {
34-
fs::create_directories(this->projectTmpPath);
35-
fs::create_directories(Paths::getLogDir(this->projectContext.projectName));
54+
fs::create_directories(this->testGen.serverBuildDir);
55+
fs::create_directories(Paths::getLogDir(this->testGen.projectContext.projectName));
3656
} catch (const fs::filesystem_error &e) {
3757
throw FileSystemException("create_directories failed", e);
3858
}
@@ -55,10 +75,10 @@ KleeGenerator::buildByCDb(const CollectionUtils::MapFileTo<fs::path> &filesToBui
5575
}
5676

5777
makefilePrinter.declareTarget("all", outfilePaths, {});
58-
fs::path makefile = projectTmpPath / "GenerationCompileMakefile.mk";
78+
fs::path makefile = testGen.serverBuildDir / "GenerationCompileMakefile.mk";
5979
FileSystemUtils::writeToFile(makefile, makefilePrinter.ss.str());
6080

61-
auto command = MakefileUtils::MakefileCommand(projectContext, makefile, "all");
81+
auto command = MakefileUtils::MakefileCommand(testGen.projectContext, makefile, "all");
6282
ExecUtils::ExecutionResult res = command.run();
6383
if (res.status != 0) {
6484
LOG_S(ERROR) << StringUtils::stringFormat("Make for \"%s\" failed.\nCommand: \"%s\"\n%s\n",
@@ -81,7 +101,7 @@ KleeGenerator::buildByCDb(const CollectionUtils::FileSet &filesToBuild,
81101
const CollectionUtils::FileSet &stubSources) {
82102
CollectionUtils::MapFileTo<fs::path> filesMap;
83103
for (fs::path const &file : filesToBuild) {
84-
filesMap[file] = buildDatabase->getBitcodeFile(file);
104+
filesMap[file] = testGen.buildDatabase->getBitcodeFile(file);
85105
}
86106
return buildByCDb(filesMap, stubSources);
87107
}
@@ -127,20 +147,24 @@ static const std::unordered_set<std::string> UNSUPPORTED_FLAGS_AND_OPTIONS_KLEE
127147
std::optional<utbot::CompileCommand>
128148
KleeGenerator::getCompileCommandForKlee(const fs::path &hintPath,
129149
const CollectionUtils::FileSet &stubSources,
130-
const std::vector<std::string> &flags) const {
131-
auto compilationUnitInfo = buildDatabase->getClientCompilationUnitInfo(hintPath);
150+
const std::vector<std::string> &flags,
151+
bool forStub) const {
152+
153+
auto compilationUnitInfo = forStub ? testGen.baseBuildDatabase->getClientCompilationUnitInfo(hintPath)
154+
: testGen.buildDatabase->getClientCompilationUnitInfo(hintPath);
132155
auto command = compilationUnitInfo->command;
133156
auto srcFilePath = compilationUnitInfo->getSourcePath();
134157
std::string newCompilerPath = getUTBotClangCompilerPath(command.getCompiler());
135158
command.setCompiler(newCompilerPath);
136159

137160
srcFilePath = pathSubstitution.substituteLineFlag(srcFilePath);
138161
if (CollectionUtils::contains(stubSources, srcFilePath)) {
139-
srcFilePath = Paths::sourcePathToStubPath(projectContext, srcFilePath);
162+
srcFilePath = Paths::sourcePathToStubPath(testGen.projectContext, srcFilePath);
140163
}
141164
command.setSourcePath(srcFilePath);
142165

143-
auto outFilePath = buildDatabase->getBitcodeFile(compilationUnitInfo->getOutputFile());
166+
auto outFilePath = forStub ? testGen.baseBuildDatabase->getBitcodeFile(compilationUnitInfo->getOutputFile())
167+
: testGen.buildDatabase->getBitcodeFile(compilationUnitInfo->getOutputFile());
144168
fs::create_directories(outFilePath.parent_path());
145169
command.setOutput(outFilePath);
146170
command.setOptimizationLevel("-O0");
@@ -172,7 +196,7 @@ KleeGenerator::getCompileCommandsForKlee(const CollectionUtils::MapFileTo<fs::pa
172196
std::vector<utbot::CompileCommand> compileCommands;
173197
compileCommands.reserve(filesToBuild.size());
174198
for (const auto &[fileToBuild, bitcode] : filesToBuild) {
175-
auto optionalCommand = getCompileCommandForKlee(fileToBuild, stubSources, {});
199+
auto optionalCommand = getCompileCommandForKlee(fileToBuild, stubSources, {}, false);
176200
if (optionalCommand.has_value()) {
177201
auto command = std::move(optionalCommand).value();
178202
command.setOutput(bitcode);
@@ -188,8 +212,8 @@ Result<fs::path> KleeGenerator::defaultBuild(const fs::path &hintPath,
188212
const fs::path &buildDirPath,
189213
const std::vector<std::string> &flags) {
190214
LOG_SCOPE_FUNCTION(DEBUG);
191-
auto bitcodeFilePath = buildDatabase->getBitcodeFile(sourceFilePath);
192-
auto optionalCommand = getCompileCommandForKlee(hintPath, {}, flags);
215+
auto bitcodeFilePath = testGen.buildDatabase->getBitcodeFile(sourceFilePath);
216+
auto optionalCommand = getCompileCommandForKlee(hintPath, {}, flags, false);
193217
if (!optionalCommand.has_value()) {
194218
std::string message = StringUtils::stringFormat(
195219
"Couldn't get command for klee file: %s\n"
@@ -204,10 +228,10 @@ Result<fs::path> KleeGenerator::defaultBuild(const fs::path &hintPath,
204228
printer::DefaultMakefilePrinter makefilePrinter;
205229
auto commandWithChangingDirectory = utbot::CompileCommand(command, true);
206230
makefilePrinter.declareTarget("build", {commandWithChangingDirectory.getSourcePath()}, {commandWithChangingDirectory.toStringWithChangingDirectory()});
207-
fs::path makefile = projectTmpPath / "BCForKLEE.mk";
231+
fs::path makefile = testGen.serverBuildDir / "BCForKLEE.mk";
208232
FileSystemUtils::writeToFile(makefile, makefilePrinter.ss.str());
209233

210-
auto makefileCommand = MakefileUtils::MakefileCommand(projectContext, makefile, "build");
234+
auto makefileCommand = MakefileUtils::MakefileCommand(testGen.projectContext, makefile, "build");
211235
auto [out, status, _] = makefileCommand.run();
212236
if (status != 0) {
213237
LOG_S(ERROR) << "Compilation for " << sourceFilePath << " failed.\n"
@@ -233,10 +257,10 @@ fs::path KleeGenerator::writeKleeFile(
233257
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter) {
234258
if (lineInfo) {
235259
return kleePrinter.writeTmpKleeFile(
236-
tests, projectTmpPath, pathSubstitution, lineInfo->predicateInfo, lineInfo->methodName,
260+
tests, testGen.serverBuildDir, pathSubstitution, lineInfo->predicateInfo, lineInfo->methodName,
237261
lineInfo->scopeName, lineInfo->forMethod, lineInfo->forClass, methodFilter);
238262
} else {
239-
return kleePrinter.writeTmpKleeFile(tests, projectTmpPath, pathSubstitution, std::nullopt,
263+
return kleePrinter.writeTmpKleeFile(tests, testGen.serverBuildDir, pathSubstitution, std::nullopt,
240264
"", "", false, false, methodFilter);
241265
}
242266
}
@@ -245,23 +269,23 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
245269
const std::shared_ptr<LineInfo> &lineInfo) {
246270
std::vector<fs::path> outFiles;
247271
LOG_S(DEBUG) << "Building generated klee files...";
248-
printer::KleePrinter kleePrinter(&typesHandler, buildDatabase, utbot::Language::UNKNOWN);
272+
printer::KleePrinter kleePrinter(&typesHandler, testGen.buildDatabase, utbot::Language::UNKNOWN);
249273
ExecUtils::doWorkWithProgress(
250-
testsMap, progressWriter, "Building generated klee files",
274+
testsMap, testGen.progressWriter, "Building generated klee files",
251275
[&](auto const &it) {
252276
const auto &[filename, tests] = it;
253277
if (lineInfo != nullptr && filename != lineInfo->filePath) {
254278
return;
255279
}
256280
kleePrinter.srcLanguage = Paths::getSourceLanguage(filename);
257281
std::vector<std::string> includeFlags = {
258-
StringUtils::stringFormat("-I%s", Paths::getFlagsDir(projectContext))};
282+
StringUtils::stringFormat("-I%s", Paths::getFlagsDir(testGen.projectContext))};
259283
auto buildDirPath =
260-
buildDatabase->getClientCompilationUnitInfo(filename)->getDirectory();
284+
testGen.buildDatabase->getClientCompilationUnitInfo(filename)->getDirectory();
261285

262286
fs::path kleeFilePath = writeKleeFile(kleePrinter, tests, lineInfo);
263287
auto kleeFilesInfo =
264-
buildDatabase->getClientCompilationUnitInfo(tests.sourceFilePath)->kleeFilesInfo;
288+
testGen.buildDatabase->getClientCompilationUnitInfo(tests.sourceFilePath)->kleeFilesInfo;
265289
auto kleeBitcodeFile = defaultBuild(filename, kleeFilePath, buildDirPath, includeFlags);
266290
if (kleeBitcodeFile.isSuccess()) {
267291
outFiles.emplace_back(kleeBitcodeFile.getOpt().value());
@@ -281,7 +305,7 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
281305
std::unordered_set<std::string> correctMethods;
282306
for (const auto &[methodName, methodDescription] : tests.methods) {
283307
fs::path currentKleeFilePath = kleePrinter.writeTmpKleeFile(
284-
tests, projectTmpPath, pathSubstitution, std::nullopt,
308+
tests, testGen.serverBuildDir, pathSubstitution, std::nullopt,
285309
methodDescription.name,
286310
methodDescription.getClassName(),
287311
true, false);
@@ -358,7 +382,11 @@ void KleeGenerator::parseKTestsToFinalCode(
358382
}
359383

360384
std::shared_ptr<BuildDatabase> KleeGenerator::getBuildDatabase() const {
361-
return buildDatabase;
385+
return testGen.buildDatabase;
386+
}
387+
388+
std::shared_ptr<BuildDatabase> KleeGenerator::getBaseBuildDatabase() const {
389+
return testGen.baseBuildDatabase;
362390
}
363391

364392
void KleeGenerator::handleFailedFunctions(tests::TestsMap &testsMap) {

server/src/KleeGenerator.h

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#include "streams/tests/TestsWriter.h"
1616
#include "types/Types.h"
1717
#include "utils/ExecUtils.h"
18-
1918
#include "utils/path/FileSystemPath.h"
19+
#include "testgens/BaseTestGen.h"
20+
2021
#include <optional>
2122
#include <sstream>
2223
#include <string>
2324

25+
2426
using json = nlohmann::json;
2527

2628
/**
@@ -31,30 +33,33 @@ class KleeGenerator {
3133
using TestsMap = tests::TestsMap;
3234

3335
public:
34-
/**
35-
* @brief Also creates tmp directories for build files.
36-
* @param projectContext contains context about current project.
37-
* @param settingsContext contains context about settings applied for current request.
38-
* @param serverBuildDir Path to folder on server machine where project build dirs are located.
39-
* @param sourcesFilePaths Paths to project files. Files which are listed in
40-
* [compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html), filtered
41-
* by them.
42-
* @param compilationDatabase Pointer to compile_commands.json object.
43-
* @param typesHandler provides additional information about types.
44-
* @param filePathsSubstitution Mapping from source file path to modified file. Required for
45-
* line test generation requests.
46-
* @param buildDatabase Instance of BuildDatabase which handles link and compile commands
47-
* @throws fs::filesystem_error Thrown if it can't create tmp folder for some
48-
* reasons.
49-
*/
50-
KleeGenerator(utbot::ProjectContext projectContext,
51-
utbot::SettingsContext settingsContext,
52-
fs::path serverBuildDir,
53-
std::shared_ptr<CompilationDatabase> compilationDatabase,
54-
types::TypesHandler &typesHandler,
55-
PathSubstitution filePathsSubstitution,
56-
std::shared_ptr<BuildDatabase> buildDatabase = nullptr,
57-
const ProgressWriter *progressWriter = DummyStreamWriter::getInstance());
36+
// /**
37+
// * @brief Also creates tmp directories for build files.
38+
// * @param projectContext contains context about current project.
39+
// * @param settingsContext contains context about settings applied for current request.
40+
// * @param serverBuildDir Path to folder on server machine where project build dirs are located.
41+
// * @param sourcesFilePaths Paths to project files. Files which are listed in
42+
// * [compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html), filtered
43+
// * by them.
44+
// * @param compilationDatabase Pointer to compile_commands.json object.
45+
// * @param typesHandler provides additional information about types.
46+
// * @param filePathsSubstitution Mapping from source file path to modified file. Required for
47+
// * line test generation requests.
48+
// * @param buildDatabase Instance of BuildDatabase which handles link and compile commands
49+
// * @throws fs::filesystem_error Thrown if it can't create tmp folder for some
50+
// * reasons.
51+
// */
52+
// KleeGenerator(utbot::ProjectContext projectContext,
53+
// utbot::SettingsContext settingsContext,
54+
// fs::path serverBuildDir,
55+
// std::shared_ptr<CompilationDatabase> compilationDatabase,
56+
// types::TypesHandler &typesHandler,
57+
// PathSubstitution filePathsSubstitution,
58+
// std::shared_ptr<BuildDatabase> buildDatabase = nullptr,
59+
// const ProgressWriter *progressWriter = DummyStreamWriter::getInstance());
60+
61+
KleeGenerator(BaseTestGen &_testGen, types::TypesHandler &typesHandler,
62+
PathSubstitution filePathsSubstitution);
5863

5964
struct BuildFileInfo {
6065
fs::path outFilePath;
@@ -130,6 +135,8 @@ class KleeGenerator {
130135

131136
[[nodiscard]] std::shared_ptr<BuildDatabase> getBuildDatabase() const;
132137

138+
[[nodiscard]] std::shared_ptr<BuildDatabase> getBaseBuildDatabase() const;
139+
133140
void handleFailedFunctions(tests::TestsMap &testsMap);
134141

135142
/**
@@ -146,21 +153,23 @@ class KleeGenerator {
146153
std::optional<utbot::CompileCommand>
147154
getCompileCommandForKlee(const fs::path &hintPath,
148155
const CollectionUtils::FileSet &stubSources,
149-
const std::vector<std::string> &flags) const;
156+
const std::vector<std::string> &flags,
157+
bool forStub) const;
150158

151159
std::vector<utbot::CompileCommand>
152160
getCompileCommandsForKlee(const CollectionUtils::MapFileTo<fs::path> &filesToBuild,
153161
const CollectionUtils::FileSet &stubSources) const;
154162

155163
private:
156-
const utbot::ProjectContext projectContext;
157-
const utbot::SettingsContext settingsContext;
158-
fs::path projectTmpPath;
159-
std::shared_ptr<CompilationDatabase> compilationDatabase;
164+
// const utbot::ProjectContext projectContext;
165+
// const utbot::SettingsContext settingsContext;
166+
BaseTestGen &testGen;;
167+
// fs::path projectTmpPath;
168+
// std::shared_ptr<CompilationDatabase> compilationDatabase;
160169
types::TypesHandler typesHandler;
161170
PathSubstitution pathSubstitution;
162-
std::shared_ptr<BuildDatabase> buildDatabase;
163-
const ProgressWriter *progressWriter;
171+
// std::shared_ptr<BuildDatabase> buildDatabase;
172+
// const ProgressWriter *progressWriter;
164173

165174
CollectionUtils::MapFileTo<std::vector<std::string>> failedFunctions;
166175

server/src/Server.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,7 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
253253
pathSubstitution = { lineTestGen->filePath, flagFilePath };
254254
}
255255
}
256-
auto generator = std::make_shared<KleeGenerator>(
257-
testGen.projectContext, testGen.settingsContext,
258-
testGen.serverBuildDir, testGen.buildDatabase->compilationDatabase, typesHandler,
259-
pathSubstitution, testGen.buildDatabase, testGen.progressWriter);
256+
auto generator = std::make_shared<KleeGenerator>(testGen, typesHandler, pathSubstitution);
260257

261258
ReturnTypesFetcher returnTypesFetcher{ &testGen };
262259
returnTypesFetcher.fetch(testGen.progressWriter, synchronizer.getAllFiles());

0 commit comments

Comments
 (0)