@@ -32,6 +32,45 @@ printer::KleePrinter::KleePrinter(const types::TypesHandler *typesHandler,
32
32
: Printer(srcLanguage), typesHandler(typesHandler), buildDatabase(std::move(buildDatabase)) {
33
33
}
34
34
35
+ void KleePrinter::writePosixWrapper (const Tests &tests,
36
+ const tests::Tests::MethodDescription &testMethod) {
37
+ declTestEntryPoint (tests, testMethod, false );
38
+ strFunctionCall (PrinterUtils::POSIX_INIT, {" &" + PrinterUtils::UTBOT_ARGC, " &" + PrinterUtils::UTBOT_ARGV});
39
+ std::string entryPoint = KleeUtils::entryPointFunction (tests, testMethod.name , false , true );
40
+ strDeclareVar (" int" , KleeUtils::RESULT_VARIABLE_NAME, constrFunctionCall (entryPoint,
41
+ {PrinterUtils::UTBOT_ARGC, PrinterUtils::UTBOT_ARGV, PrinterUtils::UTBOT_ENVP},
42
+ " " , std::nullopt, false ));
43
+ strFunctionCall (PrinterUtils::POSIX_CHECK_STDIN_READ, {});
44
+ strReturn (KleeUtils::RESULT_VARIABLE_NAME);
45
+ closeBrackets (1 );
46
+ ss << NL;
47
+ }
48
+
49
+ void KleePrinter::writeTestedFunction (const Tests &tests,
50
+ const tests::Tests::MethodDescription &testMethod,
51
+ const std::optional<LineInfo::PredicateInfo> &predicateInfo,
52
+ const std::string &testedMethod,
53
+ bool onlyForOneEntity,
54
+ bool isWrapped) {
55
+ writeStubsForFunctionParams (typesHandler, testMethod, true );
56
+ declTestEntryPoint (tests, testMethod, isWrapped);
57
+ genGlobalParamsDeclarations (testMethod);
58
+ genParamsDeclarations (testMethod);
59
+ genPostGlobalSymbolicVariables (testMethod);
60
+ genPostParamsSymbolicVariables (testMethod);
61
+ if (types::TypesHandler::skipTypeInReturn (testMethod.returnType )) {
62
+ genVoidFunctionAssumes (testMethod, predicateInfo, testedMethod, onlyForOneEntity);
63
+ } else {
64
+ genNonVoidFunctionAssumes (testMethod, predicateInfo, testedMethod,
65
+ onlyForOneEntity);
66
+ }
67
+ genGlobalsKleeAssumes (testMethod);
68
+ genPostParamsKleeAssumes (testMethod);
69
+ strReturn (" 0" );
70
+ closeBrackets (1 );
71
+ ss << NL;
72
+ }
73
+
35
74
fs::path KleePrinter::writeTmpKleeFile (
36
75
const Tests &tests,
37
76
const std::string &buildDir,
@@ -92,22 +131,12 @@ fs::path KleePrinter::writeTmpKleeFile(
92
131
continue ;
93
132
}
94
133
try {
95
- writeStubsForFunctionParams (typesHandler, testMethod, true );
96
- declTestEntryPoint (tests, testMethod);
97
- genGlobalParamsDeclarations (testMethod);
98
- genParamsDeclarations (testMethod);
99
- genPostGlobalSymbolicVariables (testMethod);
100
- genPostParamsSymbolicVariables (testMethod);
101
- if (types::TypesHandler::skipTypeInReturn (testMethod.returnType )) {
102
- genVoidFunctionAssumes (testMethod, predicateInfo, testedMethod, onlyForOneEntity);
134
+ if (srcLanguage == utbot::Language::C) {
135
+ writeTestedFunction (tests, testMethod, predicateInfo, testedMethod, onlyForOneEntity, true );
136
+ writePosixWrapper (tests, testMethod);
103
137
} else {
104
- genNonVoidFunctionAssumes (testMethod, predicateInfo, testedMethod,
105
- onlyForOneEntity);
138
+ writeTestedFunction (tests, testMethod, predicateInfo, testedMethod, onlyForOneEntity, false );
106
139
}
107
- genGlobalsKleeAssumes (testMethod);
108
- genPostParamsKleeAssumes (testMethod);
109
- strReturn (" 0" );
110
- closeBrackets (1 );
111
140
} catch (const UnImplementedException &e) {
112
141
std::string message =
113
142
" Could not generate klee code for method \' " + methodName + " \' , skipping it. " ;
@@ -121,11 +150,13 @@ fs::path KleePrinter::writeTmpKleeFile(
121
150
}
122
151
123
152
void KleePrinter::declTestEntryPoint (const Tests &tests,
124
- const Tests::MethodDescription &testMethod) {
125
- std::string entryPoint = KleeUtils::entryPointFunction (tests, testMethod.name );
153
+ const Tests::MethodDescription &testMethod,
154
+ bool isWrapped) {
155
+ std::string entryPoint = KleeUtils::entryPointFunction (tests, testMethod.name , false , isWrapped);
126
156
auto argvType = types::Type::createSimpleTypeFromName (" char" , 2 );
127
157
// if change args in next line also change cpp mangledPath in kleeUtils.cpp
128
- strFunctionDecl (" int" , entryPoint, {types::Type::intType (), argvType, argvType}, {" utbot_argc" , " utbot_argv" , " utbot_envp" }, " " ) << LB ();
158
+ strFunctionDecl (" int" , entryPoint, {types::Type::intType (), argvType, argvType},
159
+ {PrinterUtils::UTBOT_ARGC, PrinterUtils::UTBOT_ARGV, PrinterUtils::UTBOT_ENVP}, " " ) << LB ();
129
160
}
130
161
131
162
Tests::MethodParam KleePrinter::getKleeMethodParam (tests::Tests::MethodParam const ¶m) {
0 commit comments