Skip to content

Commit d4ca616

Browse files
committed
issue_423_fix
1 parent 93401ae commit d4ca616

20 files changed

+90
-45
lines changed

server/proto/testgen.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ message SettingsContext {
105105
bool useDeterministicSearcher = 5;
106106
bool useStubs = 6;
107107
ErrorMode errorMode = 7;
108+
bool differentVariablesOfTheSameType = 8;
108109
}
109110

110111
message SnippetRequest {

server/src/KleeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
244244
const std::shared_ptr<LineInfo> &lineInfo) {
245245
std::vector<fs::path> outFiles;
246246
LOG_S(DEBUG) << "Building generated klee files...";
247-
printer::KleePrinter kleePrinter(&typesHandler, testGen->getTargetBuildDatabase(), utbot::Language::UNKNOWN);
247+
printer::KleePrinter kleePrinter(&typesHandler, testGen->getTargetBuildDatabase(), utbot::Language::UNKNOWN, testGen);
248248
ExecUtils::doWorkWithProgress(
249249
testsMap, testGen->progressWriter, "Building generated klee files",
250250
[&](auto const &it) {

server/src/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
249249
if (lineTestGen->needToAddPathFlag()) {
250250
LOG_S(DEBUG) << "Added test line flag for file " << lineInfo->filePath;
251251
fs::path flagFilePath =
252-
printer::KleePrinter(&typesHandler, nullptr, Paths::getSourceLanguage(lineInfo->filePath))
252+
printer::KleePrinter(&typesHandler, nullptr, Paths::getSourceLanguage(lineInfo->filePath), &testGen)
253253
.addTestLineFlag(lineInfo, lineInfo->forAssert, testGen.projectContext);
254254
pathSubstitution = {lineTestGen->filePath, flagFilePath};
255255
}

server/src/SettingsContext.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace utbot {
99
int32_t timeoutPerTest,
1010
bool useDeterministicSearcher,
1111
bool useStubs,
12-
testsgen::ErrorMode errorMode)
12+
testsgen::ErrorMode errorMode,
13+
bool differentVariablesOfTheSameType)
1314
: generateForStaticFunctions(generateForStaticFunctions),
1415
verbose(verbose),
1516
timeoutPerFunction(timeoutPerFunction > 0
@@ -19,7 +20,8 @@ namespace utbot {
1920
? std::make_optional(std::chrono::seconds{ timeoutPerTest })
2021
: std::nullopt),
2122
useDeterministicSearcher(useDeterministicSearcher), useStubs(useStubs),
22-
errorMode(errorMode) {
23+
errorMode(errorMode),
24+
differentVariablesOfTheSameType (differentVariablesOfTheSameType) {
2325
}
2426
SettingsContext::SettingsContext(const testsgen::SettingsContext &settingsContext)
2527
: SettingsContext(settingsContext.generateforstaticfunctions(),
@@ -28,6 +30,7 @@ namespace utbot {
2830
settingsContext.timeoutpertest(),
2931
settingsContext.usedeterministicsearcher(),
3032
settingsContext.usestubs(),
31-
settingsContext.errormode()) {
33+
settingsContext.errormode(),
34+
settingsContext.differentvariablesofthesametype()) {
3235
}
3336
}

server/src/SettingsContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ namespace utbot {
2020
int32_t timeoutPerTest,
2121
bool useDeterministicSearcher,
2222
bool useStubs,
23-
testsgen::ErrorMode errorMode);
23+
testsgen::ErrorMode errorMode,
24+
bool differentVariablesOfTheSameType);
2425

2526
const bool generateForStaticFunctions;
2627
const bool verbose;
2728
const std::optional<std::chrono::seconds> timeoutPerFunction, timeoutPerTest;
2829
const bool useDeterministicSearcher;
2930
const bool useStubs;
3031
testsgen::ErrorMode errorMode;
32+
const bool differentVariablesOfTheSameType;
3133
};
3234
}
3335

server/src/commands/Commands.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ ErrorMode Commands::SettingsContextOptionGroup::getErrorMode() const {
412412
return errorMode;
413413
}
414414

415+
bool Commands::SettingsContextOptionGroup::doDifferentVariablesOfTheSameType() const {
416+
return differentVariablesOfTheSameType;
417+
}
418+
415419
Commands::RunTestsCommands::RunTestsCommands(Commands::MainCommands &commands) {
416420
runCommand = commands.getRunTestsCommand();
417421

server/src/commands/Commands.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ namespace Commands {
245245

246246
[[nodiscard]] ErrorMode getErrorMode() const;
247247

248+
[[nodiscard]] bool doDifferentVariablesOfTheSameType() const;
249+
248250
private:
249251
CLI::Option_group *settingsContextOptions;
250252
bool generateForStaticFunctions = true;
@@ -254,6 +256,7 @@ namespace Commands {
254256
bool noDeterministicSearcher = false;
255257
bool noStubs = false;
256258
ErrorMode errorMode = ErrorMode::FAILING;
259+
bool differentVariablesOfTheSameType = false;
257260
};
258261
};
259262

server/src/printers/KleeConstraintsPrinter.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ printer::KleeConstraintsPrinter::KleeConstraintsPrinter(const types::TypesHandle
1515
: Printer(srcLanguage), typesHandler(typesHandler) {}
1616

1717
printer::KleeConstraintsPrinter::Stream
18-
KleeConstraintsPrinter::genConstraints(const std::string &name, const types::Type& type) {
18+
KleeConstraintsPrinter::genConstraints(const std::string &name, const types::Type& type, const std::vector<std::string>& names) {
1919
ConstraintsState state = { "&" + name, name, type, true };
2020
auto paramType = type;
2121
if (type.maybeJustPointer()) {
@@ -34,19 +34,19 @@ KleeConstraintsPrinter::genConstraints(const std::string &name, const types::Typ
3434
genConstraintsForEnum(state);
3535
break;
3636
default:
37-
genConstraintsForPrimitive(state);
37+
genConstraintsForPrimitive(state, names);
3838
}
3939

4040
return ss;
4141
}
4242

4343
printer::KleeConstraintsPrinter::Stream
44-
KleeConstraintsPrinter::genConstraints(const Tests::MethodParam &param) {
45-
return genConstraints(param.name, param.type);
44+
KleeConstraintsPrinter::genConstraints(const Tests::MethodParam &param, const std::vector<std::string>& names) {
45+
return genConstraints(param.name, param.type, names);
4646
}
4747

48-
void KleeConstraintsPrinter::genConstraintsForPrimitive(const ConstraintsState &state) {
49-
const auto &cons = cexConstraints(state.curElement, state.curType);
48+
void KleeConstraintsPrinter::genConstraintsForPrimitive(const ConstraintsState &state, const std::vector<std::string>& names) {
49+
const auto &cons = cexConstraints(state.curElement, state.curType, names);
5050
if (!cons.empty()) {
5151
strFunctionCall(PrinterUtils::KLEE_PREFER_CEX, { state.paramName, cons });
5252
} else {
@@ -164,7 +164,7 @@ void KleeConstraintsPrinter::genConstraintsForStruct(const ConstraintsState &sta
164164
}
165165
}
166166

167-
std::string KleeConstraintsPrinter::cexConstraints(const std::string &name, const types::Type &type) {
167+
std::string KleeConstraintsPrinter::cexConstraints(const std::string &name, const types::Type &type, const std::vector<std::string>& names) {
168168
if (!CollectionUtils::containsKey(TypesHandler::preferredConstraints(), type.baseType())) {
169169
return "";
170170
}
@@ -176,6 +176,11 @@ std::string KleeConstraintsPrinter::cexConstraints(const std::string &name, cons
176176
ssCex << " & ";
177177
}
178178
}
179+
for (const std::string& currentName: names){
180+
if(name != currentName){
181+
ssCex << " & " << name << " != " << currentName;
182+
}
183+
}
179184
return ssCex.str();
180185
}
181186

server/src/printers/KleeConstraintsPrinter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace printer {
1212

1313
utbot::Language getLanguage() const override;
1414

15-
Stream genConstraints(const std::string &name, const types::Type& type);
15+
Stream genConstraints(const std::string &name, const types::Type& type, const std::vector<std::string>& names={});
1616

17-
Stream genConstraints(const Tests::MethodParam &param);
17+
Stream genConstraints(const Tests::MethodParam &param, const std::vector<std::string>& names={});
1818

1919
void setTabsDepth(const size_t depth) {
2020
tabsDepth = depth;
@@ -31,7 +31,7 @@ namespace printer {
3131
int depth = 0;
3232
};
3333

34-
void genConstraintsForPrimitive(const ConstraintsState &state);
34+
void genConstraintsForPrimitive(const ConstraintsState &state, const std::vector<std::string>& names={});
3535

3636
void genConstraintsForPointerOrArray(const ConstraintsState &state);
3737

@@ -44,7 +44,7 @@ namespace printer {
4444

4545
void genConstraintsForPointerInStruct(const ConstraintsState &state);
4646

47-
static std::string cexConstraints(const std::string &name, const types::Type &type);
47+
static std::string cexConstraints(const std::string &name, const types::Type &type, const std::vector<std::string>& names={});
4848

4949
void noConstraints(const std::string &cause);
5050
};

server/src/printers/KleePrinter.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Paths.h"
66
#include "exceptions/NoSuchTypeException.h"
77
#include "exceptions/UnImplementedException.h"
8+
#include "testgens/BaseTestGen.h"
89
#include "utils/CollectionUtils.h"
910
#include "utils/FileSystemUtils.h"
1011
#include "utils/KleeUtils.h"
@@ -29,8 +30,9 @@ static const std::string CALLOC_DECLARATION = "extern\n"
2930

3031
printer::KleePrinter::KleePrinter(const types::TypesHandler *typesHandler,
3132
std::shared_ptr<BuildDatabase> buildDatabase,
32-
utbot::Language srcLanguage)
33-
: Printer(srcLanguage), typesHandler(typesHandler), buildDatabase(std::move(buildDatabase)) {
33+
utbot::Language srcLanguage,
34+
const BaseTestGen *testGen)
35+
: Printer(srcLanguage), typesHandler(typesHandler), buildDatabase(std::move(buildDatabase)), testGen(testGen) {
3436
}
3537

3638
void KleePrinter::writePosixWrapper(const Tests &tests,
@@ -376,7 +378,11 @@ void KleePrinter::genParamsDeclarations(
376378
.str();
377379
ss << constraintsBlock;
378380
}
381+
std::unordered_map<std::string , std::vector<std::string>>typesToNames;
379382
for (const auto &param : testMethod.params) {
383+
if(testGen->settingsContext.differentVariablesOfTheSameType){
384+
typesToNames[param.type.typeName()].push_back(param.name);
385+
}
380386
if (!filter(param)) {
381387
continue;
382388
}
@@ -388,7 +394,9 @@ void KleePrinter::genParamsDeclarations(
388394
auto paramType =
389395
kleeParam.type.maybeJustPointer() ? kleeParam.type.baseTypeObj() : kleeParam.type;
390396
strKleeMakeSymbolic(paramType, kleeParam.name, param.name, !isArray);
391-
genConstraints(kleeParam, testMethod.name);
397+
if(testGen->settingsContext.differentVariablesOfTheSameType && typesToNames[param.type.typeName()].size() <= 10){
398+
genConstraints(kleeParam, testMethod.name, typesToNames[param.type.typeName()]);}
399+
else {genConstraints(kleeParam, testMethod.name);}
392400
genTwoDimPointers(param, true);
393401
commentBlockSeparator();
394402
}
@@ -479,10 +487,10 @@ void KleePrinter::genParamsKleeAssumes(
479487
}
480488
}
481489

482-
void KleePrinter::genConstraints(const Tests::MethodParam &param, const std::string &methodName) {
490+
void KleePrinter::genConstraints(const Tests::MethodParam &param, const std::string &methodName, const std::vector<std::string>& names) {
483491
KleeConstraintsPrinter constraintsPrinter(typesHandler, srcLanguage);
484492
constraintsPrinter.setTabsDepth(tabsDepth);
485-
const auto constraintsBlock = constraintsPrinter.genConstraints(param).str();
493+
const auto constraintsBlock = constraintsPrinter.genConstraints(param, names).str();
486494
ss << constraintsBlock;
487495
}
488496

server/src/printers/KleePrinter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "LineInfo.h"
99
#include "building/BuildDatabase.h"
1010
#include "types/Types.h"
11+
#include "testgens/BaseTestGen.h"
1112
#include "utils/path/FileSystemPath.h"
1213

1314
#include <cstdio>
@@ -24,7 +25,7 @@ namespace printer {
2425
public:
2526
KleePrinter(const types::TypesHandler *typesHandler,
2627
std::shared_ptr<BuildDatabase> buildDatabase,
27-
utbot::Language srcLanguage);
28+
utbot::Language srcLanguage, const BaseTestGen *testGen);
2829

2930
utbot::Language getLanguage() const override;
3031

@@ -46,6 +47,7 @@ namespace printer {
4647
[[nodiscard]] std::vector<std::string> getIncludePaths(const Tests &tests, const PathSubstitution &substitution) const;
4748
private:
4849
types::TypesHandler const *typesHandler;
50+
BaseTestGen const *testGen;
4951
std::shared_ptr<BuildDatabase> buildDatabase;
5052

5153
using PredInfo = LineInfo::PredicateInfo;
@@ -85,7 +87,7 @@ namespace printer {
8587
/*
8688
* Functions for constraints generation.
8789
*/
88-
void genConstraints(const Tests::MethodParam &param, const std::string& methodName = "");
90+
void genConstraints(const Tests::MethodParam &param, const std::string& methodName = "", const std::vector<std::string>& names = {});
8991

9092
void genTwoDimPointers(const Tests::MethodParam &param, bool needDeclare);
9193

server/src/utils/CLIUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ createSettingsContextByOptions(const SettingsContextOptionGroup &settingsContext
6262
settingsContextOptionGroup.getTimeoutPerTest(),
6363
settingsContextOptionGroup.isDeterministicSearcherUsed(),
6464
settingsContextOptionGroup.withStubs(),
65-
settingsContextOptionGroup.getErrorMode());
65+
settingsContextOptionGroup.getErrorMode(),
66+
settingsContextOptionGroup.doDifferentVariablesOfTheSameType());
6667
}
6768

6869
std::vector<fs::path> getSourcePaths(const ProjectContextOptionGroup &projectContextOptions,

server/src/utils/GrpcUtils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace GrpcUtils {
3636
int32_t timeoutPerTest,
3737
bool useDeterministicSearcher,
3838
bool useStubs,
39-
ErrorMode errorMode) {
39+
ErrorMode errorMode,
40+
bool differentVariablesOfTheSameType) {
4041
auto result = std::make_unique<testsgen::SettingsContext>();
4142
result->set_generateforstaticfunctions(generateForStaticFunctions);
4243
result->set_verbose(verbose);
@@ -45,6 +46,7 @@ namespace GrpcUtils {
4546
result->set_usedeterministicsearcher(useDeterministicSearcher);
4647
result->set_usestubs(useStubs);
4748
result->set_errormode(errorMode);
49+
result->set_differentvariablesofthesametype(differentVariablesOfTheSameType);
4850
return result;
4951
}
5052

server/src/utils/GrpcUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace GrpcUtils {
2828
int32_t timeoutPerTest,
2929
bool useDeterministicSearcher,
3030
bool useStubs,
31-
ErrorMode errorMode);
31+
ErrorMode errorMode,
32+
bool differentVariablesOfTheSameType);
3233

3334
std::unique_ptr<testsgen::SnippetRequest>
3435
createSnippetRequest(std::unique_ptr<testsgen::ProjectContext> projectContext,

0 commit comments

Comments
 (0)