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