Skip to content

Commit 7982012

Browse files
committed
[refactoring] changed klee out directories for interactive mode
1 parent 0e59302 commit 7982012

File tree

4 files changed

+53
-45
lines changed

4 files changed

+53
-45
lines changed

server/src/KleeRunner.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
9393
std::move(writeFunctor));
9494
}
9595

96-
fs::path KleeRunner::getKleeMethodOutFile(const TestMethod &method) {
97-
fs::path kleeOutDir = Paths::getKleeOutDir(projectTmpPath);
98-
fs::path relative =
99-
Paths::removeExtension(fs::relative(method.sourceFilePath, projectContext.projectPath));
100-
return kleeOutDir / relative / ("klee_out_" + method.methodName);
101-
}
102-
10396
namespace {
10497
void clearUnusedData(const fs::path &kleeDir) {
10598
fs::remove(kleeDir / "assembly.ll");
@@ -198,7 +191,8 @@ void KleeRunner::processBatchWithoutInteractive(MethodKtests &ktestChunk,
198191

199192
std::string entryPoint = KleeUtils::entryPointFunction(tests, testMethod.methodName, true);
200193
std::string entryPointFlag = StringUtils::stringFormat("--entry-point=%s", entryPoint);
201-
auto kleeOut = getKleeMethodOutFile(testMethod);
194+
auto kleeOut = Paths::kleeOutDirForEntrypoints(projectContext, projectTmpPath, testMethod.sourceFilePath,
195+
testMethod.methodName);
202196
fs::create_directories(kleeOut.parent_path());
203197
std::string outputDir = "--output-dir=" + kleeOut.string();
204198
std::vector<std::string> argvData = { "klee",
@@ -259,7 +253,7 @@ void KleeRunner::processBatchWithInteractive(const std::vector<tests::TestMethod
259253
TestMethod testMethod = testMethods[0];
260254
std::string entryPoint = KleeUtils::entryPointFunction(tests, testMethod.methodName, true);
261255
std::string entryPointFlag = StringUtils::stringFormat("--entry-point=%s", entryPoint);
262-
auto kleeOut = getKleeMethodOutFile(testMethod);
256+
auto kleeOut = Paths::kleeOutDirForEntrypoints(projectContext, projectTmpPath, tests.sourceFilePath);
263257
fs::create_directories(kleeOut.parent_path());
264258

265259
fs::path entrypoints = kleeOut.parent_path() / "entrypoints.txt";

server/src/KleeRunner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class KleeRunner {
4949
void processBatchWithInteractive(const std::vector<tests::TestMethod> &testMethods,
5050
tests::Tests &tests,
5151
std::vector<tests::MethodKtests> &ktests);
52-
fs::path getKleeMethodOutFile(const tests::TestMethod &method);
5352
};
5453

5554

server/src/Paths.cpp

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ namespace Paths {
153153
[&path](auto const &suffix) { return errorFileExists(path, suffix); });
154154
}
155155

156+
fs::path kleeOutDirForEntrypoints(const utbot::ProjectContext &projectContext, const fs::path &projectTmpPath,
157+
const fs::path &srcFilePath, const std::string &methodName) {
158+
fs::path kleeOutDir = getKleeOutDir(projectTmpPath);
159+
fs::path relative = (fs::relative(addOrigExtensionAsSuffixAndAddNew(srcFilePath, ""),
160+
projectContext.projectPath));
161+
if (!methodName.empty()) {
162+
return kleeOutDir / relative / ("klee_out_" + methodName);
163+
}
164+
return kleeOutDir / relative / ("klee_out_" + srcFilePath.filename().stem().string());
165+
}
166+
156167
//endregion
157168

158169
//region extensions
@@ -281,48 +292,13 @@ namespace Paths {
281292
//endregion
282293

283294
//region transformation
284-
const std::string MAKEFILE_EXTENSION = ".mk";
285-
const std::string TEST_SUFFIX = "_test";
286-
const std::string STUB_SUFFIX = "_stub";
287-
const std::string DOT_SEP = "_dot_";
288-
const std::string MAKE_WRAPPER_SUFFIX = "_wrapper";
289-
const char dot = '.';
290295

291296
fs::path sourcePathToTestPath(const utbot::ProjectContext &projectContext,
292297
const fs::path &sourceFilePath) {
293298
return projectContext.testDirPath / getRelativeDirPath(projectContext, sourceFilePath) /
294299
sourcePathToTestName(sourceFilePath);
295300
}
296301

297-
static inline fs::path addOrigExtensionAsSuffixAndAddNew(const fs::path &path,
298-
const std::string &newExt) {
299-
std::string extensionAsSuffix = path.extension().string();
300-
if (!extensionAsSuffix.empty()) {
301-
std::string fnWithNewExt =
302-
path.stem().string() + DOT_SEP + extensionAsSuffix.substr(1) + newExt;
303-
return path.parent_path() / fnWithNewExt;
304-
}
305-
return replaceExtension(path, newExt);
306-
}
307-
308-
static inline fs::path restoreExtensionFromSuffix(const fs::path &path,
309-
const std::string &defaultExt) {
310-
std::string fnWithoutExt = path.stem();
311-
fs::path fnWithExt;
312-
std::size_t posEncodedExtension = fnWithoutExt.rfind(DOT_SEP);
313-
if (posEncodedExtension == std::string::npos) {
314-
// In `sample_class_test.cpp` the `class` is not an extension
315-
fnWithExt = fnWithoutExt + defaultExt;
316-
}
317-
else {
318-
// In `sample_class_dot_cpp.cpp` the `cpp` is an extension
319-
fnWithExt = fnWithoutExt.substr(0, posEncodedExtension)
320-
+ dot
321-
+ fnWithoutExt.substr(posEncodedExtension + DOT_SEP.length());
322-
}
323-
return path.parent_path() / fs::path(fnWithExt);
324-
}
325-
326302
fs::path sourcePathToTestName(const fs::path &source) {
327303
return addSuffix(addOrigExtensionAsSuffixAndAddNew(source, ".cpp"),
328304
TEST_SUFFIX).filename();

server/src/Paths.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
namespace Paths {
1616
extern fs::path logPath;
17+
const std::string MAKEFILE_EXTENSION = ".mk";
18+
const std::string TEST_SUFFIX = "_test";
19+
const std::string STUB_SUFFIX = "_stub";
20+
const std::string DOT_SEP = "_dot_";
21+
const std::string MAKE_WRAPPER_SUFFIX = "_wrapper";
22+
const char dot = '.';
1723

1824
//region util
1925
static inline bool isValidDir(const std::string &dir) {
@@ -109,6 +115,36 @@ namespace Paths {
109115
std::vector<fs::path> findFilesInFolder(const fs::path &folder, const CollectionUtils::FileSet &sourcePaths);
110116

111117
std::string mangle(const fs::path& path);
118+
119+
static inline fs::path addOrigExtensionAsSuffixAndAddNew(const fs::path &path,
120+
const std::string &newExt) {
121+
std::string extensionAsSuffix = path.extension().string();
122+
if (!extensionAsSuffix.empty()) {
123+
std::string fnWithNewExt =
124+
path.stem().string() + DOT_SEP + extensionAsSuffix.substr(1) + newExt;
125+
return path.parent_path() / fnWithNewExt;
126+
}
127+
return replaceExtension(path, newExt);
128+
}
129+
130+
static inline fs::path restoreExtensionFromSuffix(const fs::path &path,
131+
const std::string &defaultExt) {
132+
std::string fnWithoutExt = path.stem();
133+
fs::path fnWithExt;
134+
std::size_t posEncodedExtension = fnWithoutExt.rfind(DOT_SEP);
135+
if (posEncodedExtension == std::string::npos) {
136+
// In `sample_class_test.cpp` the `class` is not an extension
137+
fnWithExt = fnWithoutExt + defaultExt;
138+
}
139+
else {
140+
// In `sample_class_dot_cpp.cpp` the `cpp` is an extension
141+
fnWithExt = fnWithoutExt.substr(0, posEncodedExtension)
142+
+ dot
143+
+ fnWithoutExt.substr(posEncodedExtension + DOT_SEP.length());
144+
}
145+
return path.parent_path() / fs::path(fnWithExt);
146+
}
147+
112148
//endregion
113149

114150
//region includes
@@ -202,6 +238,9 @@ namespace Paths {
202238

203239
bool hasError(fs::path const &path);
204240

241+
fs::path kleeOutDirForEntrypoints(const utbot::ProjectContext &projectContext, const fs::path &projectTmpPath,
242+
const fs::path &srcFilePath, const std::string &methodName = "");
243+
205244
//endregion
206245

207246
//region extensions

0 commit comments

Comments
 (0)