@@ -32,6 +32,44 @@ printer::KleePrinter::KleePrinter(const types::TypesHandler *typesHandler,
3232    : Printer(srcLanguage), typesHandler(typesHandler), buildDatabase(std::move(buildDatabase)) {
3333}
3434
35+ void  KleePrinter::writePosixWrapper (const  Tests &tests,
36+                                     const  tests::Tests::MethodDescription &testMethod) {
37+     declTestEntryPoint (tests, testMethod, false );
38+     strFunctionCall (PrinterUtils::POSIX_INIT, {" &" " &" 
39+     std::string entryPoint = KleeUtils::entryPointFunction (tests, testMethod.name ) + PrinterUtils::WRAPPED_SUFFIX;
40+     strDeclareVar (" int" 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::writeMain (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+ 
3573fs::path KleePrinter::writeTmpKleeFile (
3674    const  Tests &tests,
3775    const  std::string &buildDir,
@@ -92,22 +130,12 @@ fs::path KleePrinter::writeTmpKleeFile(
92130            continue ;
93131        }
94132        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+                 writeMain (tests, testMethod, predicateInfo, testedMethod, onlyForOneEntity, true );
135+                 writePosixWrapper (tests, testMethod);
103136            } else  {
104-                 genNonVoidFunctionAssumes (testMethod, predicateInfo, testedMethod,
105-                                           onlyForOneEntity);
137+                 writeMain (tests, testMethod, predicateInfo, testedMethod, onlyForOneEntity, false );
106138            }
107-             genGlobalsKleeAssumes (testMethod);
108-             genPostParamsKleeAssumes (testMethod);
109-             strReturn (" 0" 
110-             closeBrackets (1 );
111139        } catch  (const  UnImplementedException &e) {
112140            std::string message =
113141                " Could not generate klee code for method \' " " \' , skipping it. " 
@@ -121,11 +149,16 @@ fs::path KleePrinter::writeTmpKleeFile(
121149}
122150
123151void  KleePrinter::declTestEntryPoint (const  Tests &tests,
124-                                      const  Tests::MethodDescription &testMethod) {
152+                                      const  Tests::MethodDescription &testMethod,
153+                                      bool  isWrapped) {
125154    std::string entryPoint = KleeUtils::entryPointFunction (tests, testMethod.name );
155+     if  (isWrapped) {
156+         entryPoint += PrinterUtils::WRAPPED_SUFFIX;
157+     }
126158    auto  argvType = types::Type::createSimpleTypeFromName (" char" 2 );
127159    //  if change args in next line also change cpp mangledPath in kleeUtils.cpp
128-     strFunctionDecl (" int" types::Type::intType (), argvType, argvType}, {" utbot_argc" " utbot_argv" " utbot_envp" " " LB ();
160+     strFunctionDecl (" int" types::Type::intType (), argvType, argvType},
161+                     {PrinterUtils::UTBOT_ARGC, PrinterUtils::UTBOT_ARGV, PrinterUtils::UTBOT_ENVP}, " " LB ();
129162}
130163
131164Tests::MethodParam KleePrinter::getKleeMethodParam (tests::Tests::MethodParam const  ¶m) {
0 commit comments