@@ -345,20 +345,6 @@ def optimize_function(self) -> Result[BestOptimization, str]:
345345 original_helper_code ,
346346 self .function_to_optimize .file_path ,
347347 )
348- for generated_test_path in generated_test_paths :
349- generated_test_path .unlink (missing_ok = True )
350- for generated_perf_test_path in generated_perf_test_paths :
351- generated_perf_test_path .unlink (missing_ok = True )
352- for test_paths in instrumented_unittests_created_for_function :
353- test_paths .unlink (missing_ok = True )
354- for fn in function_to_concolic_tests :
355- for test in function_to_concolic_tests [fn ]:
356- if not test .tests_in_file .test_file .parent .exists ():
357- logger .warning (
358- f"Concolic test directory { test .tests_in_file .test_file .parent } does not exist so could not be deleted."
359- )
360- shutil .rmtree (test .tests_in_file .test_file .parent , ignore_errors = True )
361- break # need to delete only one test directory
362348
363349 if not best_optimization :
364350 return Failure (f"No best optimizations found for function { self .function_to_optimize .qualified_name } " )
@@ -1242,3 +1228,25 @@ def generate_and_instrument_tests(
12421228 zip (generated_test_paths , generated_perf_test_paths )
12431229 )
12441230 ]
1231+
1232+ def cleanup_generated_files (self ) -> None :
1233+ paths_to_cleanup = (
1234+ [
1235+ test_file .instrumented_behavior_file_path
1236+ for test_type in [
1237+ TestType .GENERATED_REGRESSION ,
1238+ TestType .EXISTING_UNIT_TEST ,
1239+ TestType .CONCOLIC_COVERAGE_TEST ,
1240+ ]
1241+ for test_file in self .test_files .get_by_type (test_type ).test_files
1242+ ]
1243+ + [
1244+ test_file .benchmarking_file_path
1245+ for test_type in [TestType .GENERATED_REGRESSION , TestType .EXISTING_UNIT_TEST ]
1246+ for test_file in self .test_files .get_by_type (test_type ).test_files
1247+ ]
1248+ + [self .test_cfg .concolic_test_root_dir ]
1249+ )
1250+ cleanup_paths (paths_to_cleanup )
1251+ if hasattr (get_run_tmp_file , "tmpdir" ):
1252+ get_run_tmp_file .tmpdir .cleanup ()
0 commit comments