1111#include  " utils/KleeUtils.h" 
1212#include  " utils/LogUtils.h" 
1313#include  " utils/stats/CSVReader.h" 
14+ #include  " utils/stats/TestsGenerationStats.h" 
1415
1516#include  " loguru.h" 
1617
1718#include  < fstream> 
1819#include  < utility> 
19- #include  < utils/stats/TestsGenerationStats.h> 
2020
2121using  namespace  tests ; 
2222
@@ -26,23 +26,6 @@ namespace {
2626        fs::remove (kleeDir / " run.istats" 
2727    }
2828
29-     StatsUtils::KleeStats parseKleeStatsReport (const  std::string &kleeStatsReport) {
30-         std::stringstream ss (kleeStatsReport);
31-         StatsUtils::CSVTable parsedCSV = StatsUtils::readCSV (ss, ' ,' 
32-         std::map<std::string, std::chrono::milliseconds> timeStats;
33-         std::vector<std::string> keys = {" Time(s)" " TSolver(s)" " TResolve(s)" 
34-         std::vector<std::chrono::milliseconds> timeValues;
35-         for  (const  auto  &key: keys) {
36-             if  (!CollectionUtils::containsKey (parsedCSV, key)) {
37-                 LOG_S (WARNING) << StringUtils::stringFormat (" Key %s not found in klee-stats report" 
38-                 return  {};
39-             }
40-             std::chrono::milliseconds totalTime ((int )(1000  * std::stof (parsedCSV[key].back ())));
41-             timeValues.emplace_back (totalTime);
42-         }
43-         return  { timeValues[0 ], timeValues[1 ], timeValues[2 ] };
44-     }
45- 
4629    StatsUtils::KleeStats writeKleeStats (const  fs::path &kleeOut) {
4730        ShellExecTask::ExecutionParameters kleeStatsParams (" klee-stats" 
4831                                                           {" --utbot-config" string (),
@@ -53,10 +36,10 @@ namespace {
5336            LOG_S (ERROR) << out;
5437            return  {};
5538        } else  {
56-             LOG_S (DEBUG) << " klee-stats report:" 
57-             LOG_S (DEBUG) << ' \n ' 
39+             LOG_S (DEBUG) << " klee-stats report:" ' \n ' 
5840        }
59-         return  parseKleeStatsReport (out);
41+         std::stringstream ss (out);
42+         return  StatsUtils::KleeStats (ss);
6043    }
6144}
6245
@@ -181,50 +164,49 @@ static void processMethod(MethodKtests &ktestChunk,
181164                std::vector<ConcretizedObject> kTestObjects (
182165                    ktestData->objects , ktestData->objects  + ktestData->n_objects );
183166
184-                      std::vector<UTBotKTestObject> objects = CollectionUtils::transform (
185-                          kTestObjects , [](const  ConcretizedObject &kTestObject ) {
186-                              return  UTBotKTestObject{ kTestObject  };
187-                          });
167+                 std::vector<UTBotKTestObject> objects = CollectionUtils::transform (
168+                     kTestObjects , [](const  ConcretizedObject &kTestObject ) {
169+                         return  UTBotKTestObject{ kTestObject  };
170+                     });
188171
189172                std::vector<std::string> errorDescriptors = CollectionUtils::transform (
190-                         errorDescriptorFiles, [](const  fs::path &errorFile) {
191-                             std::ifstream fileWithError (errorFile.c_str (), std::ios_base::in);
192-                             std::string content ((std::istreambuf_iterator<char >(fileWithError)),
193-                                                 std::istreambuf_iterator<char >());
194- 
195-                             const  std::string &errorId = errorFile.stem ().extension ().string ();
196-                             if  (!errorId.empty ()) {
197-                                 //  skip leading dot
198-                                 content += " \n " " :" substr (1 );
199-                             }
200-                             return  content;
201-                         });
202- 
173+                     errorDescriptorFiles, [](const  fs::path &errorFile) {
174+                         std::ifstream fileWithError (errorFile.c_str (), std::ios_base::in);
175+                         std::string content ((std::istreambuf_iterator<char >(fileWithError)),
176+                                             std::istreambuf_iterator<char >());
177+ 
178+                         const  std::string &errorId = errorFile.stem ().extension ().string ();
179+                         if  (!errorId.empty ()) {
180+                             //  skip leading dot
181+                             content += " \n " " :" substr (1 );
182+                         }
183+                         return  content;
184+                     });
203185
204186                ktestChunk[method].emplace_back (objects, status, errorDescriptors);
205-                 }
206187            }
207188        }
208-         if  (hasTimeout) {
209-             std::string message = StringUtils::stringFormat (
210-                 " Some tests for function '%s' were skipped, as execution of function is " 
211-                 " out of timeout." 
212-                 method.methodName );
213-             tests.commentBlocks .emplace_back (std::move (message));
214-         }
215-         if  (hasError) {
216-             std::string message = StringUtils::stringFormat (
217-                 " Some tests for function '%s' were skipped, as execution of function leads " 
218-                 " KLEE to the internal error. See console log for more details." 
219-                 method.methodName );
220-             tests.commentBlocks .emplace_back (std::move (message));
221-         }
189+     }
190+     if  (hasTimeout) {
191+         std::string message = StringUtils::stringFormat (
192+             " Some tests for function '%s' were skipped, as execution of function is " 
193+             " out of timeout." 
194+             method.methodName );
195+         tests.commentBlocks .emplace_back (std::move (message));
196+     }
197+     if  (hasError) {
198+         std::string message = StringUtils::stringFormat (
199+             " Some tests for function '%s' were skipped, as execution of function leads " 
200+             " KLEE to the internal error. See console log for more details." 
201+             method.methodName );
202+         tests.commentBlocks .emplace_back (std::move (message));
203+     }
222204
223-          if  (!CollectionUtils::containsKey (ktestChunk, method) || ktestChunk.at (method).empty ()) {
224-              tests.commentBlocks .emplace_back (StringUtils::stringFormat (
225-                  " Tests for %s were not generated. Maybe the function is too complex." 
226-                  method.methodName ));
227-          }
205+     if  (!CollectionUtils::containsKey (ktestChunk, method) || ktestChunk.at (method).empty ()) {
206+         tests.commentBlocks .emplace_back (StringUtils::stringFormat (
207+             " Tests for %s were not generated. Maybe the function is too complex." 
208+             method.methodName ));
209+     }
228210}
229211
230212void  KleeRunner::processBatchWithoutInteractive (const  std::vector<tests::TestMethod> &testMethods,
@@ -237,9 +219,9 @@ void KleeRunner::processBatchWithoutInteractive(const std::vector<tests::TestMet
237219    for  (const  auto  &testMethod : testMethods) {
238220        if  (testMethod.sourceFilePath  != tests.sourceFilePath ) {
239221            std::string message = StringUtils::stringFormat (
240-                      " While generating tests for source file: %s tried to generate tests for method %s " 
241-                      " from another source file: %s. This can cause invalid generation.\n " 
242-                      tests.sourceFilePath , testMethod.methodName , testMethod.sourceFilePath );
222+                 " While generating tests for source file: %s tried to generate tests for method %s " 
223+                 " from another source file: %s. This can cause invalid generation.\n " 
224+                 tests.sourceFilePath , testMethod.methodName , testMethod.sourceFilePath );
243225            LOG_S (WARNING) << message;
244226        }
245227
0 commit comments