Skip to content

Commit 525e9dd

Browse files
mi-acV8-internal LUCI CQ
authored andcommitted
Add merge script for transpile-tests results
This adds a simple script to merge data from multiple sharded calls to transpile_tests.py. We keep the merge script side-by-side with the main script to ease changing details in the data later, e.g. adding additional keys. This also drops two redundant entries from the current format. Bug: 442444727 Change-Id: I774c078455028a01eb97276b90120a0f03c14f7a Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8832116 Reviewed-by: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Michael Achenbach <machenbach@google.com>
1 parent ea68e64 commit 525e9dd

4 files changed

Lines changed: 141 additions & 7 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Script to merge multiple output json files from transpile_tests.py into one.
17+
"""
18+
19+
import argparse
20+
import json
21+
import sys
22+
23+
24+
def merge_test_results(inputs):
25+
num_tests = 0
26+
failures = []
27+
for result in inputs:
28+
num_tests += result["num_tests"]
29+
failures += result["failures"]
30+
31+
return {
32+
'num_tests': num_tests,
33+
'failures': failures,
34+
}
35+
36+
37+
def parse_args(args):
38+
parser = argparse.ArgumentParser()
39+
parser.add_argument(
40+
'--json-input', action='append', required=True,
41+
help='Path to a json results file from transpile_tests.py.')
42+
parser.add_argument(
43+
'--json-output', required=True,
44+
help='Path to the merged json results file.')
45+
return parser.parse_args(args)
46+
47+
48+
def main(args):
49+
options = parse_args(args)
50+
51+
inputs = []
52+
for input_path in options.json_input:
53+
with open(input_path) as f:
54+
inputs.append(json.load(f))
55+
56+
result = merge_test_results(inputs)
57+
with open(options.json_output, 'w') as f:
58+
json.dump(result, f, sort_keys=True, indent=2)
59+
60+
print(f'Merged results for {result["num_tests"]} tests '
61+
f'and {len(result["failures"])} failures.')
62+
63+
64+
if __name__ == '__main__':
65+
main(sys.argv[1:])
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import contextlib
16+
import io
17+
import json
18+
import unittest
19+
20+
from pyfakefs import fake_filesystem_unittest
21+
22+
import merge_json_results
23+
24+
25+
class TestMergeResults(fake_filesystem_unittest.TestCase):
26+
27+
@fake_filesystem_unittest.patchfs(allow_root_user=True)
28+
def test_full_run(self, fs):
29+
with open('/in1.json', 'w') as f:
30+
json.dump({
31+
'num_tests': 2,
32+
'failures': [
33+
{'path': 'path/to/failure1', 'output': 'foo'},
34+
]
35+
}, f)
36+
37+
with open('/in2.json', 'w') as f:
38+
json.dump({
39+
'num_tests': 3,
40+
'failures': [
41+
{'path': 'path/to/failure2', 'output': 'bar 42\nbar 43'},
42+
{'path': 'path/to/failure3', 'output': 'baz'},
43+
]
44+
}, f)
45+
46+
f = io.StringIO()
47+
with contextlib.redirect_stdout(f):
48+
merge_json_results.main([
49+
'--json-input', '/in1.json',
50+
'--json-input', '/in2.json',
51+
'--json-output', '/output.json',
52+
])
53+
54+
# Verify the output.
55+
self.assertEqual(
56+
'Merged results for 5 tests and 3 failures.',
57+
f.getvalue().strip())
58+
59+
# Verify the results written to the json output file.
60+
with open('/output.json') as f:
61+
actual_results = json.load(f)
62+
63+
expected_results = {
64+
'num_tests': 5,
65+
'failures': [
66+
{'path': 'path/to/failure1', 'output': 'foo'},
67+
{'path': 'path/to/failure2', 'output': 'bar 42\nbar 43'},
68+
{'path': 'path/to/failure3', 'output': 'baz'},
69+
],
70+
}
71+
self.assertEqual(expected_results, actual_results)
72+
73+
74+
if __name__ == '__main__':
75+
unittest.main()

Tools/transpile_tests/test_transpile_tests.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ def test_full_run(self, fs):
9898

9999
expected_results = {
100100
'num_tests': 4,
101-
'num_successes': 3,
102-
'percent_successes': 75.0,
103101
'failures': [
104102
{
105103
'output': 'Failed!',
@@ -148,8 +146,6 @@ def test_shard_run(self, fs):
148146

149147
expected_results = {
150148
'num_tests': 2,
151-
'num_successes': 1,
152-
'percent_successes': 50.0,
153149
'failures': [
154150
{
155151
'output': 'Failed!',

Tools/transpile_tests/transpile_tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,13 @@ def test_input_gen():
172172
f'({num_successes} of {num_tests}) test cases.')
173173
return {
174174
'num_tests': num_tests,
175-
'num_successes': num_successes,
176-
'percent_successes': ratio,
177175
'failures': failures,
178176
}
179177

180178

181179
def write_json_output(path, results):
182180
with open(path, 'w') as f:
183-
json.dump(results, f)
181+
json.dump(results, f, sort_keys=True, indent=2)
184182

185183

186184
def parse_args(args):

0 commit comments

Comments
 (0)