Skip to content

Commit cf90882

Browse files
committed
UTOF support
1 parent 5a53589 commit cf90882

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

.gitlab/build/bazel/test.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
variables:
1616
EXTERNAL_LINKS_PATH: external_links_$CI_JOB_ID.json
1717
BEP_FILE: $CI_PROJECT_DIR/bazel-bep.json
18-
RESULT_JSON: output.json
18+
RESULT_JSON: test_output.json
1919
after_script:
2020
- dda inv -- -e bazel.process-test-results --bep-file=$BEP_FILE --junit-tar=junit-${CI_JOB_NAME}.tgz --result-json=$RESULT_JSON
2121
- !reference [.upload_junit_source]
2222
artifacts:
2323
expire_in: 2 weeks
2424
when: always
2525
paths:
26+
- $RESULT_JSON
27+
- test_output_unified.json
2628
- junit-*.tgz
27-
- bazel-bep-*.json
29+
- bazel-bep.json
2830
reports:
2931
annotations:
3032
- $EXTERNAL_LINKS_PATH
@@ -65,8 +67,10 @@ bazel:test:macos-arm64:
6567
- !reference [.bazel:test:reporting, after_script]
6668
artifacts:
6769
paths:
70+
- $RESULT_JSON
71+
- test_output_unified.json
6872
- junit-*.tgz
69-
- bazel-bep-*.json
73+
- bazel-bep.json
7074
- bazel-exec.log
7175

7276
# Windows splits the build from the Go tests, unlike the other platforms: the

tasks/bazel.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ def ensure_test_parity(ctx, bep, flavor_name, verbose=False, emit_metrics=False)
319319

320320
class BepTestArtifacts(TypedDict):
321321
cached: bool
322-
xml_paths: list[Path]
323-
log_paths: list[Path]
322+
xml_paths: list[Path] # noqa: F841 - TypedDict field, not a local variable
323+
log_paths: list[Path] # noqa: F841 - TypedDict field, not a local variable
324324

325325

326326
def _resolve_test_output_path(
@@ -488,8 +488,10 @@ def _collect_test2json(ctx, test_artifacts, output_path):
488488
with tempfile.TemporaryDirectory() as tmpdir:
489489
manifest_path = os.path.join(tmpdir, "manifest.tsv")
490490
with open(manifest_path, "w") as manifest:
491-
for entry in sorted(test_artifacts.keys()):
492-
manifest.writelines(f'{entry}\t{log_path}\n' for log_path in test_artifacts[entry]["log_paths"])
491+
for import_path in sorted(test_artifacts.keys()):
492+
manifest.writelines(
493+
f'{import_path}\t{log_path}\n' for log_path in test_artifacts[import_path]["log_paths"]
494+
)
493495

494496
bazel(
495497
ctx,
@@ -506,23 +508,31 @@ def _collect_test2json(ctx, test_artifacts, output_path):
506508
@task(
507509
help={
508510
"bep_file": "Path to a Bazel BEP JSON file (--build_event_json_file) used to gather all necessary data.",
511+
"result_json": "Path to write test2json JSONL output.",
512+
"junit_tar": "Path to write the JUnit tgz.",
509513
},
510514
)
511-
def process_test_results(ctx, bep_file, result_json, junit_tar):
515+
def process_test_results(ctx, bep_file, result_json="test_output.json", junit_tar=""):
512516
"""Collect results from Bazel-run tests and produce various artifacts.
513517
514518
This task:
515519
- Produces a tgz JUnit XML file compatible with our existing upload machinery.
516520
- Produces a test2json file with test results and a UTOF json file created from it.
517521
- Displays test results in a human-friendly way (based on UTOF).
518522
"""
519-
# BEP is the authoritative source: it lists exactly the test.xml and test.out files
523+
# BEP is the authoritative source: it lists exactly the test.xml and test.log files
520524
# produced by this invocation, avoiding stale results from previous runs
521525
# with a different Bazel configuration.
522526
test_artifacts = _parse_bep(Path(bep_file))
523527

524-
# Produce the junit tar
525-
_collect_junit(test_artifacts, junit_tar)
526-
527528
# Produce the test2json result file
528529
_collect_test2json(ctx, test_artifacts, result_json)
530+
531+
# Produce UTOF and associated terminal output
532+
from tasks.libs.testing.utof.go.generate import generate_unified_output
533+
534+
generate_unified_output(ctx, result_json, "bazel", "")
535+
536+
# Produce the junit tar
537+
if junit_tar:
538+
_collect_junit(test_artifacts, junit_tar)

tasks/unit_tests/bazel_tests.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
_is_gotestsum_shaped,
1313
_label_to_import_path,
1414
_parse_bep,
15-
_test_xml_candidates,
15+
_test_output_candidates,
1616
_test_xml_funcs,
1717
)
1818

@@ -30,26 +30,28 @@ def test_root_package(self):
3030

3131
class TestTestXmlCandidates(unittest.TestCase):
3232
def test_file_uri_only(self):
33-
paths = _test_xml_candidates("//pkg/foo:bar_test", "file:///tmp/test.xml", "cfg1", None, {})
33+
paths = _test_output_candidates("//pkg/foo:bar_test", "file:///tmp/test.xml", "cfg1", None, {}, "test.xml")
3434
self.assertEqual(paths, [Path("/tmp/test.xml")])
3535

3636
def test_bytestream_uri_reconstructed_from_testlogs(self):
37-
paths = _test_xml_candidates(
37+
paths = _test_output_candidates(
3838
"//pkg/foo:bar_test",
3939
"bytestream://example/blobs/abc/123",
4040
"cfg1",
4141
"/exec/root",
4242
{"cfg1": Path("bazel-out/k8-fastbuild/testlogs")},
43+
"test.xml",
4344
)
4445
self.assertEqual(paths, [Path("/exec/root/bazel-out/k8-fastbuild/testlogs/pkg/foo/bar_test/test.xml")])
4546

4647
def test_both_candidates_in_priority_order(self):
47-
paths = _test_xml_candidates(
48+
paths = _test_output_candidates(
4849
"//pkg/foo:bar_test",
4950
"file:///tmp/test.xml",
5051
"cfg1",
5152
"/exec/root",
5253
{"cfg1": Path("bazel-out/k8-fastbuild/testlogs")},
54+
"test.xml",
5355
)
5456
self.assertEqual(
5557
paths,
@@ -60,8 +62,8 @@ def test_both_candidates_in_priority_order(self):
6062
)
6163

6264
def test_no_candidates_when_config_unknown(self):
63-
paths = _test_xml_candidates(
64-
"//pkg/foo:bar_test", "bytestream://example/blobs/abc/123", "cfg1", "/exec/root", {}
65+
paths = _test_output_candidates(
66+
"//pkg/foo:bar_test", "bytestream://example/blobs/abc/123", "cfg1", "/exec/root", {}, "test.xml"
6567
)
6668
self.assertEqual(paths, [])
6769

0 commit comments

Comments
 (0)