Skip to content

Commit ed0dce6

Browse files
committed
fix code review comments
1 parent 3a8f934 commit ed0dce6

30 files changed

+203
-254
lines changed

server/proto/testgen.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ message ProjectContext {
8888
string projectPath = 2;
8989
string testDirPath = 3;
9090
string buildDirRelativePath = 4;
91-
string resultsDirRelativePath = 5;
9291
}
9392

9493
message SettingsContext {

server/src/KleeRunner.cpp

Lines changed: 43 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#include "utils/KleeUtils.h"
1212
#include "utils/LogUtils.h"
1313
#include "utils/stats/CSVReader.h"
14+
#include "utils/stats/TestsGenerationStats.h"
1415

1516
#include "loguru.h"
1617

1718
#include <fstream>
1819
#include <utility>
19-
#include <utils/stats/TestsGenerationStats.h>
2020

2121
using namespace tests;
2222

@@ -26,23 +26,6 @@ namespace {
2626
fs::remove(kleeDir / "run.istats");
2727
}
2828

29-
StatsUtils::KleeStats parseKleeStatsReport(const std::string &kleeStatsReport) {
30-
std::stringstream ss(kleeStatsReport);
31-
StatsUtils::CSVTable parsedCSV = StatsUtils::readCSV(ss, ',');
32-
std::map<std::string, std::chrono::milliseconds> timeStats;
33-
std::vector<std::string> keys = {"Time(s)", "TSolver(s)", "TResolve(s)"};
34-
std::vector<std::chrono::milliseconds> timeValues;
35-
for (const auto &key: keys) {
36-
if (!CollectionUtils::containsKey(parsedCSV, key)) {
37-
LOG_S(WARNING) << StringUtils::stringFormat("Key %s not found in klee-stats report", key);
38-
return {};
39-
}
40-
std::chrono::milliseconds totalTime((int)(1000 * std::stof(parsedCSV[key].back())));
41-
timeValues.emplace_back(totalTime);
42-
}
43-
return { timeValues[0], timeValues[1], timeValues[2] };
44-
}
45-
4629
StatsUtils::KleeStats writeKleeStats(const fs::path &kleeOut) {
4730
ShellExecTask::ExecutionParameters kleeStatsParams("klee-stats",
4831
{"--utbot-config", kleeOut.string(),
@@ -53,10 +36,10 @@ namespace {
5336
LOG_S(ERROR) << out;
5437
return {};
5538
} else {
56-
LOG_S(DEBUG) << "klee-stats report:";
57-
LOG_S(DEBUG) << '\n' << out;
39+
LOG_S(DEBUG) << "klee-stats report:" << '\n' << out;
5840
}
59-
return parseKleeStatsReport(out);
41+
std::stringstream ss(out);
42+
return StatsUtils::KleeStats(ss);
6043
}
6144
}
6245

@@ -181,50 +164,49 @@ static void processMethod(MethodKtests &ktestChunk,
181164
std::vector<ConcretizedObject> kTestObjects(
182165
ktestData->objects, ktestData->objects + ktestData->n_objects);
183166

184-
std::vector<UTBotKTestObject> objects = CollectionUtils::transform(
185-
kTestObjects, [](const ConcretizedObject &kTestObject) {
186-
return UTBotKTestObject{ kTestObject };
187-
});
167+
std::vector<UTBotKTestObject> objects = CollectionUtils::transform(
168+
kTestObjects, [](const ConcretizedObject &kTestObject) {
169+
return UTBotKTestObject{ kTestObject };
170+
});
188171

189172
std::vector<std::string> errorDescriptors = CollectionUtils::transform(
190-
errorDescriptorFiles, [](const fs::path &errorFile) {
191-
std::ifstream fileWithError(errorFile.c_str(), std::ios_base::in);
192-
std::string content((std::istreambuf_iterator<char>(fileWithError)),
193-
std::istreambuf_iterator<char>());
194-
195-
const std::string &errorId = errorFile.stem().extension().string();
196-
if (!errorId.empty()) {
197-
// skip leading dot
198-
content += "\n" + sarif::ERROR_ID_KEY + ":" + errorId.substr(1);
199-
}
200-
return content;
201-
});
202-
173+
errorDescriptorFiles, [](const fs::path &errorFile) {
174+
std::ifstream fileWithError(errorFile.c_str(), std::ios_base::in);
175+
std::string content((std::istreambuf_iterator<char>(fileWithError)),
176+
std::istreambuf_iterator<char>());
177+
178+
const std::string &errorId = errorFile.stem().extension().string();
179+
if (!errorId.empty()) {
180+
// skip leading dot
181+
content += "\n" + sarif::ERROR_ID_KEY + ":" + errorId.substr(1);
182+
}
183+
return content;
184+
});
203185

204186
ktestChunk[method].emplace_back(objects, status, errorDescriptors);
205-
}
206187
}
207188
}
208-
if (hasTimeout) {
209-
std::string message = StringUtils::stringFormat(
210-
"Some tests for function '%s' were skipped, as execution of function is "
211-
"out of timeout.",
212-
method.methodName);
213-
tests.commentBlocks.emplace_back(std::move(message));
214-
}
215-
if (hasError) {
216-
std::string message = StringUtils::stringFormat(
217-
"Some tests for function '%s' were skipped, as execution of function leads "
218-
"KLEE to the internal error. See console log for more details.",
219-
method.methodName);
220-
tests.commentBlocks.emplace_back(std::move(message));
221-
}
189+
}
190+
if (hasTimeout) {
191+
std::string message = StringUtils::stringFormat(
192+
"Some tests for function '%s' were skipped, as execution of function is "
193+
"out of timeout.",
194+
method.methodName);
195+
tests.commentBlocks.emplace_back(std::move(message));
196+
}
197+
if (hasError) {
198+
std::string message = StringUtils::stringFormat(
199+
"Some tests for function '%s' were skipped, as execution of function leads "
200+
"KLEE to the internal error. See console log for more details.",
201+
method.methodName);
202+
tests.commentBlocks.emplace_back(std::move(message));
203+
}
222204

223-
if (!CollectionUtils::containsKey(ktestChunk, method) || ktestChunk.at(method).empty()) {
224-
tests.commentBlocks.emplace_back(StringUtils::stringFormat(
225-
"Tests for %s were not generated. Maybe the function is too complex.",
226-
method.methodName));
227-
}
205+
if (!CollectionUtils::containsKey(ktestChunk, method) || ktestChunk.at(method).empty()) {
206+
tests.commentBlocks.emplace_back(StringUtils::stringFormat(
207+
"Tests for %s were not generated. Maybe the function is too complex.",
208+
method.methodName));
209+
}
228210
}
229211

230212
void KleeRunner::processBatchWithoutInteractive(const std::vector<tests::TestMethod> &testMethods,
@@ -237,9 +219,9 @@ void KleeRunner::processBatchWithoutInteractive(const std::vector<tests::TestMet
237219
for (const auto &testMethod : testMethods) {
238220
if (testMethod.sourceFilePath != tests.sourceFilePath) {
239221
std::string message = StringUtils::stringFormat(
240-
"While generating tests for source file: %s tried to generate tests for method %s "
241-
"from another source file: %s. This can cause invalid generation.\n",
242-
tests.sourceFilePath, testMethod.methodName, testMethod.sourceFilePath);
222+
"While generating tests for source file: %s tried to generate tests for method %s "
223+
"from another source file: %s. This can cause invalid generation.\n",
224+
tests.sourceFilePath, testMethod.methodName, testMethod.sourceFilePath);
243225
LOG_S(WARNING) << message;
244226
}
245227

server/src/KleeRunner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#include "Tests.h"
88
#include "streams/tests/TestsWriter.h"
99
#include "utils/stats/KleeStats.h"
10+
#include "utils/stats/TestsGenerationStats.h"
1011

1112
#include <grpcpp/grpcpp.h>
1213

1314
#include <vector>
14-
#include <utils/stats/TestsGenerationStats.h>
1515

1616
class KleeRunner {
1717
public:

server/src/Paths.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,16 @@ namespace Paths {
164164
fs::path kleeOutDirForFilePath(const utbot::ProjectContext &projectContext, const fs::path &projectTmpPath,
165165
const fs::path &filePath) {
166166
fs::path kleeOutDir = getKleeOutDir(projectTmpPath);
167-
fs::path relative = (fs::relative(addOrigExtensionAsSuffixAndAddNew(filePath, ""), projectContext.projectPath));
167+
fs::path relative = fs::relative(addOrigExtensionAsSuffixAndAddNew(filePath, ""), projectContext.projectPath);
168168
return kleeOutDir / relative;
169169
}
170170

171171
fs::path kleeOutDirForEntrypoints(const utbot::ProjectContext &projectContext, const fs::path &projectTmpPath,
172172
const fs::path &srcFilePath, const std::string &methodName) {
173-
if (!methodName.empty()) {
174-
return kleeOutDirForFilePath(projectContext, projectTmpPath, srcFilePath) / ("klee_out_" + methodName);
175-
}
176-
return kleeOutDirForFilePath(projectContext, projectTmpPath, srcFilePath) /
177-
("klee_out_" + srcFilePath.filename().stem().string());
173+
auto kleeOutDirForFile = kleeOutDirForFilePath(projectContext, projectTmpPath, srcFilePath);
174+
std::string suffix = methodName.empty() ?
175+
addOrigExtensionAsSuffixAndAddNew(srcFilePath, "").filename().string() : methodName;
176+
return kleeOutDirForFile / ("klee_out_" + suffix);
178177
}
179178

180179
//endregion
@@ -204,7 +203,7 @@ namespace Paths {
204203
}
205204

206205
fs::path getArtifactsRootDir(const utbot::ProjectContext &projectContext) {
207-
return projectContext.buildDir / "utbot";
206+
return projectContext.buildDir() / "utbot";
208207
}
209208
fs::path getGTestResultsJsonPath(const utbot::ProjectContext &projectContext) {
210209
return getArtifactsRootDir(projectContext) / "gtest-results.json";
@@ -256,7 +255,7 @@ namespace Paths {
256255
newFilename = fs::relative(filePath, projectContext.projectPath);
257256
newFilename = addExtension(newFilename, ".o");
258257
} else {
259-
newFilename = fs::relative(filePath, projectContext.buildDir);
258+
newFilename = fs::relative(filePath, projectContext.buildDir());
260259
}
261260
return getRecompiledDir(projectContext) / newFilename;
262261
}
@@ -409,7 +408,7 @@ namespace Paths {
409408
return removeSuffix(srcPath, STUB_SUFFIX).stem() == headerPath.stem();
410409
}
411410
fs::path getUtbotBuildDir(const utbot::ProjectContext &projectContext) {
412-
return projectContext.buildDir / CompilationUtils::UTBOT_BUILD_DIR_NAME;
411+
return projectContext.buildDir() / CompilationUtils::UTBOT_BUILD_DIR_NAME;
413412
}
414413

415414
//endregion

server/src/Paths.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,19 @@ namespace Paths {
415415

416416
//endregion
417417

418-
//region stats
418+
//region utbot-report
419+
420+
inline fs::path getUTBotReportDir(const utbot::ProjectContext &projectContext) {
421+
return projectContext.projectPath / "utbot-report";
422+
}
423+
419424
inline fs::path getGenerationStatsCSVPath(const utbot::ProjectContext &projectContext) {
420-
return projectContext.resultsDirPath / "generation-stats.csv";
425+
return getUTBotReportDir(projectContext) / "generation-stats.csv";
421426
}
422427
inline fs::path getExecutionStatsCSVPath(const utbot::ProjectContext &projectContext) {
423-
return projectContext.resultsDirPath / "execution-stats.csv";
428+
return getUTBotReportDir(projectContext) / "execution-stats.csv";
424429
}
430+
425431
//endregion
426432

427433
bool isHeadersEqual(const fs::path &srcPath, const fs::path &headerPath);

server/src/ProjectContext.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,27 @@
55
#include <utility>
66

77
namespace utbot {
8-
ProjectContext::ProjectContext(std::string projectName,
9-
fs::path projectPath,
10-
fs::path testDirPath,
11-
fs::path buildDirRelativePath,
12-
fs::path resultsDirRelativePath)
13-
: projectName(std::move(projectName)),
14-
projectPath(std::move(projectPath)),
15-
testDirPath(std::move(testDirPath)),
16-
buildDirRelativePath(std::move(buildDirRelativePath)),
17-
buildDir(this->projectPath / this->buildDirRelativePath),
18-
resultsDirRelativePath(std::move(resultsDirRelativePath)),
19-
resultsDirPath(this->projectPath / this->resultsDirRelativePath) { }
20-
218
ProjectContext::ProjectContext(std::string projectName,
229
fs::path projectPath,
2310
fs::path testDirPath,
2411
fs::path buildDirRelativePath)
25-
: ProjectContext(projectName, projectPath, testDirPath, buildDirRelativePath, "utbot-results") { }
12+
: projectName(std::move(projectName)), projectPath(std::move(projectPath)),
13+
testDirPath(std::move(testDirPath)),
14+
buildDirRelativePath(std::move(buildDirRelativePath)) {}
2615

2716
ProjectContext::ProjectContext(const testsgen::ProjectContext &projectContext)
2817
: ProjectContext(projectContext.projectname(),
2918
projectContext.projectpath(),
3019
projectContext.testdirpath(),
31-
projectContext.builddirrelativepath(),
32-
!projectContext.resultsdirrelativepath().empty() ?
33-
projectContext.resultsdirrelativepath() :
34-
"utbot-results") {}
20+
projectContext.builddirrelativepath()) {}
3521

3622
ProjectContext::ProjectContext(const testsgen::SnippetRequest &request, fs::path serverBuildDir)
3723
: projectName(request.projectcontext().projectname()),
3824
projectPath(request.projectcontext().projectpath()),
3925
testDirPath(request.projectcontext().testdirpath()),
40-
buildDirRelativePath(request.projectcontext().builddirrelativepath()),
41-
buildDir(std::move(serverBuildDir)) { }
26+
buildDirRelativePath(request.projectcontext().builddirrelativepath()) { }
27+
28+
fs::path ProjectContext::buildDir() const {
29+
return projectPath / buildDirRelativePath;
30+
}
4231
}

server/src/ProjectContext.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,16 @@ class ProjectContext {
1818
fs::path testDirPath,
1919
fs::path buildDirRelativePath);
2020

21-
ProjectContext(std::string projectName,
22-
fs::path projectPath,
23-
fs::path testDirPath,
24-
fs::path buildDirRelativePath,
25-
fs::path resultDirRelativePath);
26-
2721
explicit ProjectContext(const testsgen::ProjectContext &projectContext);
2822

2923
ProjectContext(const testsgen::SnippetRequest &request, fs::path serverBuildDir);
3024

25+
[[nodiscard]] fs::path buildDir() const;
26+
3127
const std::string projectName;
3228
const fs::path projectPath;
3329
const fs::path testDirPath;
3430
const fs::path buildDirRelativePath;
35-
const fs::path buildDir;
36-
const fs::path resultsDirRelativePath;
37-
const fs::path resultsDirPath;
3831
};
3932
}
4033

server/src/SARIFGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace sarif {
7676
const fs::path &srcPath = fs::path(stack_match[3]);
7777
const fs::path &relPathInProject = getInProjectPath(projectContext.projectPath, srcPath);
7878
const fs::path &fullPathInProject = projectContext.projectPath / relPathInProject;
79-
if (Paths::isSubPathOf(projectContext.buildDir, fullPathInProject)) {
79+
if (Paths::isSubPathOf(projectContext.buildDir(), fullPathInProject)) {
8080
continue;
8181
}
8282
if (!relPathInProject.empty() && fs::exists(fullPathInProject)) {

server/src/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
#include "utils/LogUtils.h"
3131
#include "utils/ServerUtils.h"
3232
#include "utils/stats/TestsGenerationStats.h"
33+
#include "utils/stats/TestsExecutionStats.h"
3334
#include "utils/TypeUtils.h"
3435

3536
#include <thread>
3637
#include <fstream>
37-
#include <utils/stats/TestsExecutionStats.h>
3838

3939
using TypeUtils::isSameType;
4040

server/src/building/BuildDatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void BuildDatabase::createClangCompileCommandsJson(const fs::path &buildCommands
103103
objectInfo->command.removeWerror();
104104
fs::path outputFile = objectInfo->getOutputFile();
105105
fs::path kleeFilePathTemplate =
106-
Paths::createNewDirForFile(sourceFile, projectContext.buildDir, serverBuildDir);
106+
Paths::createNewDirForFile(sourceFile, projectContext.buildDir(), serverBuildDir);
107107
fs::path kleeFile = Paths::addSuffix(kleeFilePathTemplate, "_klee");
108108
objectInfo->kleeFilesInfo = std::make_shared<KleeFilesInfo>(kleeFile);
109109

@@ -676,7 +676,7 @@ std::shared_ptr<BuildDatabase::TargetInfo> BuildDatabase::getPriorityTarget() co
676676
return *it;
677677
}
678678
fs::path BuildDatabase::newDirForFile(const fs::path &file) const {
679-
fs::path base = Paths::longestCommonPrefixPath(this->projectContext.buildDir,
679+
fs::path base = Paths::longestCommonPrefixPath(this->projectContext.buildDir(),
680680
this->projectContext.projectPath);
681681
return Paths::createNewDirForFile(file, base, this->serverBuildDir);
682682
}

0 commit comments

Comments
 (0)