Skip to content

Commit 2bd62e0

Browse files
committed
[dexter] Don't generate results files by default
Dexter saves various files to a new results directory each time it is run (including when it's run by lit tests) and there isn't a way to opt-out. This patch reconfigures the behaviour to be opt-in by removing the default `--results-directory` location. Now results are only saved if `--results-directory` is specified. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D119545
1 parent 52fbb78 commit 2bd62e0

File tree

5 files changed

+93
-60
lines changed

5 files changed

+93
-60
lines changed

cross-project-tests/debuginfo-tests/dexter/dex/tools/TestToolBase.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ def add_tool_arguments(self, parser, defaults):
4646
'--results-directory',
4747
type=str,
4848
metavar='<directory>',
49-
default=os.path.abspath(
50-
os.path.join(get_root_directory(), '..', 'results',
51-
datetime.now().strftime('%Y-%m-%d-%H%M-%S'))),
52-
help='directory to save results')
49+
default=None,
50+
help='directory to save results (default: none)')
5351

5452
def handle_options(self, defaults):
5553
options = self.context.options
@@ -86,14 +84,15 @@ def handle_options(self, defaults):
8684
'<d>could not find test path</> <r>"{}"</>'.format(
8785
options.test_path))
8886

89-
options.results_directory = os.path.abspath(options.results_directory)
90-
if not os.path.isdir(options.results_directory):
91-
try:
92-
os.makedirs(options.results_directory, exist_ok=True)
93-
except OSError as e:
94-
raise Error(
95-
'<d>could not create directory</> <r>"{}"</> <y>({})</>'.
96-
format(options.results_directory, e.strerror))
87+
if options.results_directory:
88+
options.results_directory = os.path.abspath(options.results_directory)
89+
if not os.path.isdir(options.results_directory):
90+
try:
91+
os.makedirs(options.results_directory, exist_ok=True)
92+
except OSError as e:
93+
raise Error(
94+
'<d>could not create directory</> <r>"{}"</> <y>({})</>'.
95+
format(options.results_directory, e.strerror))
9796

9897
def go(self) -> ReturnCode: # noqa
9998
options = self.context.options

cross-project-tests/debuginfo-tests/dexter/dex/tools/clang_opt_bisect/Tool.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,12 @@ def _run_test(self, test_name): # noqa
192192
steps_changed = steps_str != prev_steps_str
193193
prev_steps_str = steps_str
194194

195-
# If this is the first pass, or something has changed, write a text
196-
# file containing verbose information on the current status.
197-
if current_limit == 0 or score_difference or steps_changed:
195+
# If a results directory has been specified and this is the first
196+
# pass or something has changed, write a text file containing
197+
# verbose information on the current status.
198+
if options.results_directory and (current_limit == 0 or
199+
score_difference or
200+
steps_changed):
198201
file_name = '-'.join(
199202
str(s) for s in [
200203
'status', test_name, '{{:0>{}}}'.format(
@@ -231,31 +234,33 @@ def _run_test(self, test_name): # noqa
231234
current_bisect_pass_summary[pass_info[1]].append(
232235
score_difference)
233236

234-
per_pass_score_path = os.path.join(
235-
options.results_directory,
236-
'{}-per_pass_score.csv'.format(test_name))
237+
if options.results_directory:
238+
per_pass_score_path = os.path.join(
239+
options.results_directory,
240+
'{}-per_pass_score.csv'.format(test_name))
237241

238-
with open(per_pass_score_path, mode='w', newline='') as fp:
239-
writer = csv.writer(fp, delimiter=',')
240-
writer.writerow(['Source File', 'Pass', 'Score'])
242+
with open(per_pass_score_path, mode='w', newline='') as fp:
243+
writer = csv.writer(fp, delimiter=',')
244+
writer.writerow(['Source File', 'Pass', 'Score'])
241245

242-
for path, pass_, score in per_pass_score:
243-
writer.writerow([path, pass_, score])
244-
self.context.o.blue('wrote "{}"\n'.format(per_pass_score_path))
246+
for path, pass_, score in per_pass_score:
247+
writer.writerow([path, pass_, score])
248+
self.context.o.blue('wrote "{}"\n'.format(per_pass_score_path))
245249

246-
pass_summary_path = os.path.join(
247-
options.results_directory, '{}-pass-summary.csv'.format(test_name))
250+
pass_summary_path = os.path.join(
251+
options.results_directory, '{}-pass-summary.csv'.format(test_name))
248252

249-
self._write_pass_summary(pass_summary_path,
250-
current_bisect_pass_summary)
253+
self._write_pass_summary(pass_summary_path,
254+
current_bisect_pass_summary)
251255

252256
def _handle_results(self) -> ReturnCode:
253257
options = self.context.options
254-
pass_summary_path = os.path.join(options.results_directory,
255-
'overall-pass-summary.csv')
258+
if options.results_directory:
259+
pass_summary_path = os.path.join(options.results_directory,
260+
'overall-pass-summary.csv')
256261

257-
self._write_pass_summary(pass_summary_path,
258-
self._all_bisect_pass_summary)
262+
self._write_pass_summary(pass_summary_path,
263+
self._all_bisect_pass_summary)
259264
return ReturnCode.OK
260265

261266
def _clang_opt_bisect_build(self, opt_bisect_limits):

cross-project-tests/debuginfo-tests/dexter/dex/tools/test/Tool.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def _get_results_path(self, test_name):
176176
"""Returns the path to the test results directory for the test denoted
177177
by test_name.
178178
"""
179+
assert self.context.options.results_directory != None
179180
return os.path.join(self.context.options.results_directory,
180181
self._get_results_basename(test_name))
181182

@@ -193,22 +194,25 @@ def _get_results_pickle_path(self, test_name):
193194

194195
def _record_steps(self, test_name, steps):
195196
"""Write out the set of steps out to the test's .txt and .json
196-
results file.
197+
results file if a results directory has been specified.
197198
"""
198-
output_text_path = self._get_results_text_path(test_name)
199-
with open(output_text_path, 'w') as fp:
200-
self.context.o.auto(str(steps), stream=Stream(fp))
199+
if self.context.options.results_directory:
200+
output_text_path = self._get_results_text_path(test_name)
201+
with open(output_text_path, 'w') as fp:
202+
self.context.o.auto(str(steps), stream=Stream(fp))
201203

202-
output_dextIR_path = self._get_results_pickle_path(test_name)
203-
with open(output_dextIR_path, 'wb') as fp:
204-
pickle.dump(steps, fp, protocol=pickle.HIGHEST_PROTOCOL)
204+
output_dextIR_path = self._get_results_pickle_path(test_name)
205+
with open(output_dextIR_path, 'wb') as fp:
206+
pickle.dump(steps, fp, protocol=pickle.HIGHEST_PROTOCOL)
205207

206208
def _record_score(self, test_name, heuristic):
207-
"""Write out the test's heuristic score to the results .txt file.
209+
"""Write out the test's heuristic score to the results .txt file
210+
if a results directory has been specified.
208211
"""
209-
output_text_path = self._get_results_text_path(test_name)
210-
with open(output_text_path, 'a') as fp:
211-
self.context.o.auto(heuristic.verbose_output, stream=Stream(fp))
212+
if self.context.options.results_directory:
213+
output_text_path = self._get_results_text_path(test_name)
214+
with open(output_text_path, 'a') as fp:
215+
self.context.o.auto(heuristic.verbose_output, stream=Stream(fp))
212216

213217
def _record_test_and_display(self, test_case):
214218
"""Output test case to o stream and record test case internally for
@@ -272,19 +276,20 @@ def _handle_results(self) -> ReturnCode:
272276
if num_tests != 0:
273277
print("@avg: ({:.4f})".format(score_sum/num_tests))
274278

275-
summary_path = os.path.join(options.results_directory, 'summary.csv')
276-
with open(summary_path, mode='w', newline='') as fp:
277-
writer = csv.writer(fp, delimiter=',')
278-
writer.writerow(['Test Case', 'Score', 'Error'])
279-
280-
for test_case in self._test_cases:
281-
if (test_case.score < options.fail_lt or
282-
test_case.error is not None):
283-
return_code = ReturnCode.FAIL
284-
285-
writer.writerow([
286-
test_case.name, '{:.4f}'.format(test_case.score),
287-
test_case.error
288-
])
279+
has_failed = lambda test: test.score < options.fail_lt or test.error
280+
if any(map(has_failed, self._test_cases)):
281+
return_code = ReturnCode.FAIL
282+
283+
if options.results_directory:
284+
summary_path = os.path.join(options.results_directory, 'summary.csv')
285+
with open(summary_path, mode='w', newline='') as fp:
286+
writer = csv.writer(fp, delimiter=',')
287+
writer.writerow(['Test Case', 'Score', 'Error'])
288+
289+
for test_case in self._test_cases:
290+
writer.writerow([
291+
test_case.name, '{:.4f}'.format(test_case.score),
292+
test_case.error
293+
])
289294

290295
return return_code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Purpose:
2+
// Check the `clang-opt-bisect` tool runs with --results-directory.
3+
//
4+
// RUN: true
5+
// RUN: %dexter_base clang-opt-bisect \
6+
// RUN: --debugger %dexter_regression_test_debugger \
7+
// RUN: --builder %dexter_regression_test_builder \
8+
// RUN: --cflags "%dexter_regression_test_cflags" \
9+
// RUN: --ldflags "%dexter_regression_test_ldflags" \
10+
// RUN: --results-directory=%t \
11+
// RUN: -- %s \
12+
// RUN: | FileCheck %s
13+
//// Clean up those results files.
14+
// RUN: rm %t/clang-opt-bisect-results.cpp-pass-summary.csv
15+
// RUN: rm %t/clang-opt-bisect-results.cpp-per_pass_score.csv
16+
// RUN: rm %t/overall-pass-summary.csv
17+
// RUN: rm %t/*.dextIR
18+
// RUN: rm %t/*.txt
19+
// RUN: rmdir %t
20+
// CHECK: running pass 0
21+
// CHECK: wrote{{.*}}per_pass_score
22+
// CHECK: wrote{{.*}}pass-summary
23+
// CHECK: wrote{{.*}}overall-pass-summary
24+
25+
int main() {
26+
return 0;
27+
}

cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/clang-opt-bisect/clang-opt-bisect.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
// RUN: -- %s \
1111
// RUN: | FileCheck %s
1212
// CHECK: running pass 0
13-
// CHECK: wrote{{.*}}per_pass_score
14-
// CHECK: wrote{{.*}}pass-summary
15-
// CHECK: wrote{{.*}}overall-pass-summary
1613

1714
int main() {
1815
return 0;

0 commit comments

Comments
 (0)