Skip to content

Commit 725df26

Browse files
committed
[Temp] refactoring
1 parent 368e00d commit 725df26

File tree

14 files changed

+55
-96
lines changed

14 files changed

+55
-96
lines changed

server/src/Synchronizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Synchronizer::createStubsCompilationDatabase(StubSet &stubFiles,
227227
void Synchronizer::synchronizeWrappers(const CollectionUtils::FileSet &outdatedSourcePaths,
228228
const types::TypesHandler &typesHandler) const {
229229
auto sourceFilesNeedToRegenerateWrappers = outdatedSourcePaths;
230-
for (fs::path const &sourceFilePath : testGen->getTargetSourceFiles()) {
230+
for (fs::path const &sourceFilePath: testGen->getTargetSourceFiles()) {
231231
if (!CollectionUtils::contains(sourceFilesNeedToRegenerateWrappers, sourceFilePath)) {
232232
auto wrapperFilePath =
233233
Paths::getWrapperFilePath(testGen->projectContext, sourceFilePath);

server/src/Tests.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const Tests::MethodParam &tests::Tests::getStdinMethodParam() {
2828
}
2929

3030
Tests::MethodDescription::MethodDescription()
31-
: suiteTestCases{{ Tests::DEFAULT_SUITE_NAME, std::vector<int>() },
32-
{ Tests::ERROR_SUITE_NAME, std::vector<int>() }},
33-
codeText{{ Tests::DEFAULT_SUITE_NAME, std::string() },
34-
{ Tests::ERROR_SUITE_NAME, std::string() }},
31+
: suiteTestCases{{Tests::DEFAULT_SUITE_NAME, std::vector<int>()},
32+
{Tests::ERROR_SUITE_NAME, std::vector<int>()}},
33+
codeText{{Tests::DEFAULT_SUITE_NAME, std::string()},
34+
{Tests::ERROR_SUITE_NAME, std::string()}},
3535
modifiers{} {
3636
stubsParamStorage = std::make_shared<StubsStorage>();
3737
stubsStorage = std::make_shared<StubsStorage>();
@@ -211,7 +211,7 @@ std::shared_ptr<ArrayValueView> KTestObjectParser::multiArrayView(const std::vec
211211
}
212212

213213
std::shared_ptr<FunctionPointerView> KTestObjectParser::functionPointerView(
214-
const std::optional <std::string> &scopeName,
214+
const std::optional<std::string> &scopeName,
215215
const std::string &methodName, const std::string &paramName) {
216216
std::string value =
217217
StubsUtils::getFunctionPointerStubName(scopeName, methodName, paramName, false).substr(1);
@@ -747,16 +747,15 @@ size_t KTestObjectParser::getOffsetInStruct(Tests::TypeAndVarName &objTypeAndNam
747747

748748
void KTestObjectParser::assignTypeStubVar(Tests::MethodTestCase &testCase,
749749
const Tests::MethodDescription &methodDescription) {
750-
for (auto const &obj : testCase.objects) {
750+
for (auto const &obj: testCase.objects) {
751751
std::optional<std::shared_ptr<FunctionInfo>>
752752
maybeFunctionInfo = methodDescription.stubsParamStorage->getFunctionInfoByKTestObjectName(obj.name);
753-
// maybeFunctionInfo = methodDescription.stubsStorage->getFunctionPointerByKTestObjectName(obj.name);
754753
if (maybeFunctionInfo.has_value()) {
755754
types::Type stubType = types::Type::createArray(maybeFunctionInfo.value()->returnType);
756755
std::shared_ptr<AbstractValueView> stubView =
757-
testParameterView({ obj.name, obj.bytes, obj.pointers }, { stubType, obj.name },
758-
PointerUsage::PARAMETER, testCase.objects,
759-
testCase.lazyReferences, methodDescription);
756+
testParameterView({obj.name, obj.bytes, obj.pointers}, {stubType, obj.name},
757+
PointerUsage::PARAMETER, testCase.objects,
758+
testCase.lazyReferences, methodDescription);
760759
testCase.stubParamValues.emplace_back(obj.name, 0, stubView);
761760
testCase.stubParamTypes.emplace_back(stubType, obj.name, std::nullopt);
762761
}
@@ -990,19 +989,19 @@ Tests::TestCaseDescription KTestObjectParser::parseTestCaseParams(
990989
const auto kleeResParam =
991990
getKleeParamOrThrow(rawKleeParams, KleeUtils::RESULT_VARIABLE_NAME);
992991
auto paramType = methodDescription.returnType.maybeReturnArray()
993-
? methodDescription.returnType
994-
: methodDescription.returnType.baseTypeObj();
995-
const Tests::TypeAndVarName returnParam = { paramType, KleeUtils::RESULT_VARIABLE_NAME };
992+
? methodDescription.returnType
993+
: methodDescription.returnType.baseTypeObj();
994+
const Tests::TypeAndVarName returnParam = {paramType, KleeUtils::RESULT_VARIABLE_NAME};
996995
const auto testReturnView = testParameterView(
997-
kleeResParam, returnParam, PointerUsage::RETURN, testCaseDescription.objects,
998-
testCaseDescription.lazyReferences, methodDescription);
996+
kleeResParam, returnParam, PointerUsage::RETURN, testCaseDescription.objects,
997+
testCaseDescription.lazyReferences, methodDescription);
999998
testCaseDescription.returnValue = {
1000-
KleeUtils::RESULT_VARIABLE_NAME,
1001-
types::TypesHandler::isObjectPointerType(methodDescription.returnType), testReturnView
999+
KleeUtils::RESULT_VARIABLE_NAME,
1000+
types::TypesHandler::isObjectPointerType(methodDescription.returnType), testReturnView
10021001
};
10031002
} else {
1004-
testCaseDescription.returnValue = { KleeUtils::RESULT_VARIABLE_NAME, false,
1005-
std::make_shared<VoidValueView>() };
1003+
testCaseDescription.returnValue = {KleeUtils::RESULT_VARIABLE_NAME, false,
1004+
std::make_shared<VoidValueView>()};
10061005
}
10071006

10081007
const auto kleePathFlagIterator = getKleeParam(rawKleeParams, KLEE_PATH_FLAG);
@@ -1182,13 +1181,13 @@ void KTestObjectParser::processStubParamValue(
11821181
}
11831182
}
11841183

1185-
std::shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
1186-
const KTestObjectParser::RawKleeParam &kleeParam,
1187-
const Tests::TypeAndVarName &param,
1188-
PointerUsage usage,
1189-
const std::vector<UTBotKTestObject> &objects,
1190-
std::vector<InitReference> &initReferences,
1191-
const std::optional<const Tests::MethodDescription> &testingMethod) {
1184+
std::shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
1185+
const KTestObjectParser::RawKleeParam &kleeParam,
1186+
const Tests::TypeAndVarName &param,
1187+
PointerUsage usage,
1188+
const std::vector<UTBotKTestObject> &objects,
1189+
std::vector<InitReference> &initReferences,
1190+
const std::optional<const Tests::MethodDescription> &testingMethod) {
11921191
const auto &rawData = kleeParam.rawData;
11931192
const auto &paramType = param.type;
11941193
switch (typesHandler.getTypeKind(paramType)) {

server/src/clang-utils/SourceToHeaderRewriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ std::string SourceToHeaderRewriter::generateStubHeader(const tests::Tests &tests
118118
<< "Stubs feature for C++ sources has not been tested thoroughly; some problems may occur";
119119
auto sourceDeclarations = generateSourceDeclarations(sourceFilePath, true, false);
120120
long long creationTime = TimeUtils::convertFileToSystemClock(fs::file_time_type::clock::now())
121-
.time_since_epoch()
122-
.count();
121+
.time_since_epoch().count();
123122
printer::StubsPrinter stubsPrinter(Paths::getSourceLanguage(sourceFilePath));
124123
stubsPrinter.ss << StringUtils::stringFormat(
125124
"//%s\n"
@@ -129,7 +128,7 @@ std::string SourceToHeaderRewriter::generateStubHeader(const tests::Tests &tests
129128
"%s\n",
130129
std::to_string(creationTime), Copyright::GENERATED_C_CPP_FILE_HEADER,
131130
sourceDeclarations.externalDeclarations);
132-
for (const auto &[methodName, methodDescription] : tests.methods) {
131+
for (const auto &[methodName, methodDescription]: tests.methods) {
133132
std::string stubSymbolicVarName = StubsUtils::getStubSymbolicVarName(methodName, "");
134133
if (!types::TypesHandler::omitMakeSymbolic(methodDescription.returnType)) {
135134
stubsPrinter.strDeclareArrayVar(types::Type::createArray(methodDescription.returnType), stubSymbolicVarName,

server/src/fetchers/Fetcher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Fetcher {
8282
std::shared_ptr<FileToStringSet> structsDeclared = std::make_shared<FileToStringSet>();
8383
public:
8484
[[nodiscard]] std::shared_ptr<FileToStringSet> getStructsToDeclare() const;
85+
8586
private:
8687
// For functions
8788
bool fetchFunctionBodies;

server/src/printers/KleeConstraintsPrinter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,22 @@ void KleeConstraintsPrinter::genConstraintsForPointerInStruct(const ConstraintsS
119119
void KleeConstraintsPrinter::genConstraintsForStruct(const ConstraintsState &state) {
120120
StructInfo curStruct = typesHandler->getStructInfo(state.curType);
121121
bool isStruct = curStruct.subType == SubType::Struct;
122-
for (const auto &field : curStruct.fields) {
122+
for (const auto &field: curStruct.fields) {
123123
auto access = PrinterUtils::getFieldAccess(state.curElement, field);
124-
ConstraintsState newState = { state.paramName,
125-
access,
126-
field.type,
127-
isStruct ? state.endString : false,
128-
state.depth + 1};
124+
ConstraintsState newState = {state.paramName,
125+
access,
126+
field.type,
127+
isStruct ? state.endString : false,
128+
state.depth + 1};
129129
std::string stubFunctionName = StubsUtils::getFunctionPointerAsStructFieldStubName(curStruct.name, field.name,
130130
false);
131131
switch (typesHandler->getTypeKind(field.type)) {
132132
case TypeKind::STRUCT_LIKE:
133133
genConstraintsForStruct(newState);
134-
break;
135-
case TypeKind::ENUM:
136-
genConstraintsForEnum(newState);
137-
break;
134+
break;
135+
case TypeKind::ENUM:
136+
genConstraintsForEnum(newState);
137+
break;
138138
case TypeKind::PRIMITIVE:
139139
genConstraintsForPrimitive(newState);
140140
break;

server/src/printers/Printer.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,6 @@ namespace printer {
394394
methodCopy.name = method.name;
395395

396396
std::string stubSymbolicVarName = StubsUtils::getStubSymbolicVarName(methodCopy.name, parentMethodName);
397-
// if (methodCopy.name != StubsUtils::tryGetMethodNameFromStubSymbolic(stubSymbolicVarName)) {
398-
// LOG_S(WARNING) << "Can't generate symbolic value for \"" << stubSymbolicVarName << "\" function";
399-
// return ss;
400-
// }
401-
402397
if (!types::TypesHandler::omitMakeSymbolic(method.returnType)) {
403398
strDeclareArrayVar(types::Type::createArray(method.returnType), stubSymbolicVarName,
404399
types::PointerUsage::PARAMETER);
@@ -536,27 +531,14 @@ namespace printer {
536531
bool forKlee) {
537532
std::string scopeName = (forKlee ? testMethod.getClassName().value_or("") : "");
538533
std::string prefix = PrinterUtils::getKleePrefix(forKlee);
539-
for (const auto &[name, pointerFunctionStub] : testMethod.functionPointers) {
534+
for (const auto &[name, pointerFunctionStub]: testMethod.functionPointers) {
540535
std::string stubName = StubsUtils::getFunctionPointerStubName(scopeName, testMethod.name, name, true);
541536
testMethod.stubsParamStorage->registerStub(testMethod.name, pointerFunctionStub, std::nullopt);
542537
writeStubForParam(typesHandler, pointerFunctionStub, testMethod.name, stubName, true,
543538
forKlee);
544539
}
545540
}
546541

547-
// void printer::Printer::writeExternForSymbolicStubs(const Tests::MethodDescription &testMethod) {
548-
// std::unordered_map<std::string, std::string> symbolicNamesToTypesMap;
549-
// for (const auto &testCase: testMethod.testCases) {
550-
// for (size_t i = 0; i < testCase.stubValues.size(); i++) {
551-
// std::string utype = testCase.stubValuesTypes[i].type.usedType();
552-
// symbolicNamesToTypesMap[testCase.stubValues[i].name + "[]"] = utype.substr(0, utype.size() - 1);
553-
// }
554-
// }
555-
// for (const auto &[name, type]: symbolicNamesToTypesMap) {
556-
// strDeclareVar("extern \"C\" " + type, name);
557-
// }
558-
// }
559-
560542
void printer::Printer::writeStubForParam(const types::TypesHandler *typesHandler,
561543
const std::shared_ptr<types::FunctionInfo> &fInfo,
562544
const std::string &methodName,

server/src/printers/Printer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ namespace printer {
202202
const Tests::MethodDescription& testMethod,
203203
bool forKlee);
204204

205-
// void writeExternForSymbolicStubs(const Tests::MethodDescription& testMethod);
206-
207205
void writeStubsForStructureFields(const Tests &tests);
208206

209207
void writeStubsForParameters(const Tests &tests);

server/src/printers/TestsPrinter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void TestsPrinter::joinToFinalCode(Tests &tests, const fs::path& generatedHeader
6565
ss << NL;
6666

6767
if (!tests.methods.empty()) {
68-
for (const auto &stubsHeader : tests.methods.begin()->second.stubsStorage->getStubsHeaders()) {
68+
for (const auto &stubsHeader: tests.methods.begin()->second.stubsStorage->getStubsHeaders()) {
6969
strInclude(stubsHeader) << NL;
7070
}
7171
}
@@ -177,7 +177,6 @@ void TestsPrinter::genCode(Tests::MethodDescription &methodDescription,
177177
int testNum = 0;
178178

179179
writeStubsForFunctionParams(typesHandler, methodDescription, false);
180-
// writeExternForSymbolicStubs(methodDescription);
181180

182181
methodDescription.stubsText = ss.str();
183182
resetStream();

server/src/stubs/StubGen.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ StubGen::findStubFilesBySignatures(const std::vector<tests::Tests::MethodDescrip
4747
fetcher.fetchWithProgress(testGen.progressWriter, "Finding stub files", true);
4848
CollectionUtils::FileSet stubFilesSet;
4949
auto signatureNamesSet = CollectionUtils::transformTo<std::unordered_set<std::string>>(
50-
signatures,
51-
[&](const tests::Tests::MethodDescription &signature) { return signature.name; });
52-
for (const auto &[filePath, stub] : stubFilesMap) {
53-
for (const auto &[methodName, methodDescription] : stub.methods) {
50+
signatures,
51+
[&](const tests::Tests::MethodDescription &signature) { return signature.name; });
52+
for (const auto &[filePath, stub]: stubFilesMap) {
53+
for (const auto &[methodName, methodDescription]: stub.methods) {
5454
if (CollectionUtils::contains(signatureNamesSet, methodName)) {
5555
stubFilesSet.insert(filePath);
5656
auto stubInfo = std::make_shared<types::FunctionInfo>(methodDescription.toFunctionInfo());
57-
for (auto &[_, tests] : testGen.tests) {
58-
for (auto &[_, method] : tests.methods) {
59-
method.stubsStorage->registerStub("", stubInfo, ((fs::path)filePath).replace_extension(".h"));
57+
for (auto &[_, tests]: testGen.tests) {
58+
for (auto &[_, method]: tests.methods) {
59+
method.stubsStorage->registerStub("", stubInfo, ((fs::path) filePath).replace_extension(".h"));
6060
}
6161
}
6262
}

server/src/stubs/StubsStorage.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
#include <utility>
44
#include "utils/StubsUtils.h"
55

6-
//void StubsStorage::registerFunctionPointerStub(const std::string &methodName,
7-
// std::shared_ptr<types::FunctionInfo> functionInfo) {
8-
// _functionPointers[StubsUtils::getStubSymbolicVarName(functionInfo->name, methodName)] = std::move(
9-
// functionInfo);
10-
//}
11-
//
12-
//std::optional<std::shared_ptr<types::FunctionInfo>>
13-
//StubsStorage::getFunctionPointerByKTestObjectName(const std::string &objectName) {
14-
// return CollectionUtils::getOptionalValue(_functionPointers, objectName);
15-
//}
16-
176
void StubsStorage::registerStub(const std::string &methodName, std::shared_ptr<types::FunctionInfo> functionInfo,
187
std::optional<fs::path> stubsHeaderPath) {
198
if (stubsHeaderPath.has_value()) {

server/src/stubs/StubsStorage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class StubsStorage {
1111
public:
1212
void registerStub(const std::string &methodName, std::shared_ptr<types::FunctionInfo>,
1313
std::optional<fs::path> stubsHeaderPath = std::nullopt);
14+
1415
std::optional<std::shared_ptr<types::FunctionInfo>>
1516
getFunctionInfoByKTestObjectName(const std::string &objectName) const;
1617

server/src/utils/StubsUtils.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ namespace StubsUtils {
3535
stubName = parentMethodName + "_";
3636
}
3737
stubName += methodName + PrinterUtils::KLEE_SYMBOLIC_SUFFIX;
38-
StringUtils::replaceColon(stubName); //TODO has problem for stubs
38+
StringUtils::replaceColon(stubName);
3939
return stubName;
4040
}
41-
42-
std::string tryGetMethodNameFromStubSymbolic(const std::string &symbolicName) {
43-
std::string methodName = symbolicName.substr(
44-
0, symbolicName.size() - PrinterUtils::KLEE_SYMBOLIC_SUFFIX.size());
45-
return methodName;
46-
}
4741
}

server/src/utils/StubsUtils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ namespace StubsUtils {
1515
bool omitSuffix);
1616

1717
std::string getStubSymbolicVarName(const std::string &methodName, const std::string &parentMethodName);
18-
19-
std::string tryGetMethodNameFromStubSymbolic(const std::string &symbolicName);
20-
2118
}
2219

2320
#endif //UTBOTCPP_STUBUTILS_H

server/test/framework/Stub_Tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ namespace {
3636
fs::path sum_stub_c = getTestFilePath(testDirName + "/stubs/lib/calc/sum_stub.c");
3737

3838
fs::path testsDirPath = getTestFilePath("tests");
39-
utbot::ProjectContext projectContext{ projectName, suitePath, testsDirPath,
40-
buildDirRelativePath, clientProjectPath };
39+
utbot::ProjectContext projectContext{projectName, suitePath, testsDirPath,
40+
buildDirRelativePath, clientProjectPath};
4141
fs::path sum_test_cpp =
4242
Paths::sourcePathToTestPath(projectContext, calc_sum_c);
4343
fs::path foreign_bar_test_cpp =
4444
Paths::sourcePathToTestPath(projectContext, foreign_bar_c);
4545

46-
std::vector<fs::path> modifiedSourceFiles = { literals_foo_c, calc_sum_h, calc_sum_c };
46+
std::vector<fs::path> modifiedSourceFiles = {literals_foo_c, calc_sum_h, calc_sum_c};
4747

4848
void SetUp() override {
4949
clearTestDirectory();
@@ -196,8 +196,8 @@ namespace {
196196

197197
static auto coverageAndResultsWriter =
198198
std::make_unique<ServerCoverageAndResultsWriter>(nullptr);
199-
CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), coverageAndResultsWriter.get() };
200-
utbot::SettingsContext settingsContext{ true, true, 15, 0, true, true, ErrorMode::FAILING, false };
199+
CoverageAndResultsGenerator coverageGenerator{runRequest.get(), coverageAndResultsWriter.get()};
200+
utbot::SettingsContext settingsContext{true, true, 15, 0, true, true, ErrorMode::FAILING, false};
201201
coverageGenerator.generate(true, settingsContext);
202202
EXPECT_FALSE(coverageGenerator.hasExceptions());
203203
}

0 commit comments

Comments
 (0)