trace_processor: make diff test more Win-friendly
This doesn't solve all problems.
Problems fixed:
- Reorder cmdline arguments to be POSIX-getopt friendly.
- Don't pass an auto-closing temporary file for perf test as
NamedTemporaryFile() are exclusive-access by default on Windows.
- Ignore \r in comparisons.
Problems still open:
The proto_utils.create_message_factory() method fails because
message_types_by_name ends up being empty. This seems somehow
related with the fact that the python protobuf library on Windows
still uses the pure python implementation (unlike the 'cpp' one
in Linux). This needs further research
Change-Id: I22176287a430e44db2b116447c86ccd02cf9c5b2
Bug: 174454879
diff --git a/tools/diff_test_trace_processor.py b/tools/diff_test_trace_processor.py
index ade516e..f7a5dd6 100755
--- a/tools/diff_test_trace_processor.py
+++ b/tools/diff_test_trace_processor.py
@@ -96,9 +96,9 @@
'--run-metrics',
metric,
'--metrics-output=%s' % ('json' if json_output else 'binary'),
- gen_trace_path,
'--perf-file',
perf_path,
+ gen_trace_path,
]
tp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = tp.communicate()
@@ -134,9 +134,9 @@
trace_processor_path,
'-q',
query_path,
- gen_trace_path,
'--perf-file',
perf_path,
+ gen_trace_path,
]
tp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -177,30 +177,36 @@
gen_trace_file = None
gen_trace_path = trace_path
- with tempfile.NamedTemporaryFile() as tmp_perf_file:
- sys.stderr.write('[ RUN ] {} {}\n'.format(
- os.path.basename(test.query_path_or_metric),
- os.path.basename(trace_path)))
+ # We can't use delete=True here. When using that on Windwows, the resulting
+ # file is opened in exclusive mode (in turn that's a subtle side-effect of
+ # the underlying CreateFile(FILE_ATTRIBUTE_TEMPORARY)) and TP fails to open
+ # the passed path.
+ tmp_perf_file = tempfile.NamedTemporaryFile(delete=False)
+ sys.stderr.write('[ RUN ] {} {}\n'.format(
+ os.path.basename(test.query_path_or_metric),
+ os.path.basename(trace_path)))
- tmp_perf_path = tmp_perf_file.name
- if test.type == 'queries':
- query_path = test.query_path_or_metric
+ tmp_perf_path = tmp_perf_file.name
+ if test.type == 'queries':
+ query_path = test.query_path_or_metric
- if not os.path.exists(test.query_path_or_metric):
- print('Query file not found {}'.format(query_path))
- test_failure += 1
- continue
+ if not os.path.exists(test.query_path_or_metric):
+ print('Query file not found {}'.format(query_path))
+ test_failure += 1
+ continue
- result = run_query_test(trace_processor, gen_trace_path, query_path,
- expected_path, tmp_perf_path)
- elif test.type == 'metrics':
- result = run_metrics_test(trace_processor, gen_trace_path,
- test.query_path_or_metric, expected_path,
- tmp_perf_path, metrics_message_factory)
- else:
- assert False
+ result = run_query_test(trace_processor, gen_trace_path, query_path,
+ expected_path, tmp_perf_path)
+ elif test.type == 'metrics':
+ result = run_metrics_test(trace_processor, gen_trace_path,
+ test.query_path_or_metric, expected_path,
+ tmp_perf_path, metrics_message_factory)
+ else:
+ assert False
- perf_lines = [line.decode('utf8') for line in tmp_perf_file.readlines()]
+ perf_lines = [line.decode('utf8') for line in tmp_perf_file.readlines()]
+ tmp_perf_file.close()
+ os.remove(tmp_perf_file.name)
if gen_trace_file:
if keep_input:
@@ -220,7 +226,10 @@
os.path.relpath(gen_trace_path, ROOT_DIR)))
sys.stderr.write('Command line:\n{}\n'.format(' '.join(result.cmd)))
- if result.exit_code != 0 or result.expected != result.actual:
+ contents_equal = (
+ result.expected.replace('\r\n',
+ '\n') == result.actual.replace('\r\n', '\n'))
+ if result.exit_code != 0 or not contents_equal:
sys.stderr.write(result.stderr)
if result.exit_code == 0: