Skip to content

Commit eac9e37

Browse files
committed
GNU/CI: use the aggregated-result.json files and move to python
1 parent e646126 commit eac9e37

File tree

2 files changed

+216
-123
lines changed

2 files changed

+216
-123
lines changed

.github/workflows/GnuTests.yml

Lines changed: 21 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -349,137 +349,35 @@ jobs:
349349
- name: Compare test failures VS reference
350350
shell: bash
351351
run: |
352-
## Compare test failures VS reference
353-
have_new_failures=""
354-
REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/test-suite.log'
355-
ROOT_REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/test-suite-root.log'
356-
SELINUX_REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/selinux-test-suite.log'
357-
SELINUX_ROOT_REF_LOG_FILE='${{ steps.vars.outputs.path_reference }}/test-logs/selinux-test-suite-root.log'
358-
REF_SUMMARY_FILE='${{ steps.vars.outputs.path_reference }}/test-summary/gnu-result.json'
359-
360-
352+
## Compare test failures VS reference using JSON files
353+
REF_SUMMARY_FILE='${{ steps.vars.outputs.path_reference }}/aggregated-result.json'
354+
CURRENT_SUMMARY_FILE='${{ steps.vars.outputs.AGGREGATED_SUMMARY_FILE }}'
361355
REPO_DEFAULT_BRANCH='${{ steps.vars.outputs.repo_default_branch }}'
362356
path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}'
363-
# https://github.com/uutils/coreutils/issues/4294
364-
# https://github.com/uutils/coreutils/issues/4295
357+
358+
# Path to ignore file for intermittent issues
365359
IGNORE_INTERMITTENT="${path_UUTILS}/.github/workflows/ignore-intermittent.txt"
366360
367-
mkdir -p ${{ steps.vars.outputs.path_reference }}
368-
369-
COMMENT_DIR="${{ steps.vars.outputs.path_reference }}/comment"
370-
mkdir -p ${COMMENT_DIR}
371-
echo ${{ github.event.number }} > ${COMMENT_DIR}/NR
372-
COMMENT_LOG="${COMMENT_DIR}/result.txt"
373-
374-
# The comment log might be downloaded from a previous run
375-
# We only want the new changes, so remove it if it exists.
376-
rm -f ${COMMENT_LOG}
377-
touch ${COMMENT_LOG}
378-
379-
compare_tests() {
380-
local new_log_file=$1
381-
local ref_log_file=$2
382-
local test_type=$3 # "standard" or "root"
383-
384-
if test -f "${ref_log_file}"; then
385-
echo "Reference ${test_type} test log SHA1/ID: $(sha1sum -- "${ref_log_file}") - ${test_type}"
386-
REF_ERROR=$(sed -n "s/^ERROR: \([[:print:]]\+\).*/\1/p" "${ref_log_file}"| sort)
387-
CURRENT_RUN_ERROR=$(sed -n "s/^ERROR: \([[:print:]]\+\).*/\1/p" "${new_log_file}" | sort)
388-
REF_FAILING=$(sed -n "s/^FAIL: \([[:print:]]\+\).*/\1/p" "${ref_log_file}"| sort)
389-
CURRENT_RUN_FAILING=$(sed -n "s/^FAIL: \([[:print:]]\+\).*/\1/p" "${new_log_file}" | sort)
390-
REF_SKIP=$(sed -n "s/^SKIP: \([[:print:]]\+\).*/\1/p" "${ref_log_file}"| sort)
391-
CURRENT_RUN_SKIP=$(sed -n "s/^SKIP: \([[:print:]]\+\).*/\1/p" "${new_log_file}" | sort)
392-
393-
echo "Detailed information:"
394-
echo "REF_ERROR = ${REF_ERROR}"
395-
echo "CURRENT_RUN_ERROR = ${CURRENT_RUN_ERROR}"
396-
echo "REF_FAILING = ${REF_FAILING}"
397-
echo "CURRENT_RUN_FAILING = ${CURRENT_RUN_FAILING}"
398-
echo "REF_SKIP_PASS = ${REF_SKIP}"
399-
echo "CURRENT_RUN_SKIP = ${CURRENT_RUN_SKIP}"
400-
401-
# Compare failing and error tests
402-
for LINE in ${CURRENT_RUN_FAILING}
403-
do
404-
if ! grep -Fxq ${LINE}<<<"${REF_FAILING}"
405-
then
406-
if ! grep ${LINE} ${IGNORE_INTERMITTENT}
407-
then
408-
MSG="GNU test failed: ${LINE}. ${LINE} is passing on '${REPO_DEFAULT_BRANCH}'. Maybe you have to rebase?"
409-
echo "::error ::$MSG"
410-
echo $MSG >> ${COMMENT_LOG}
411-
have_new_failures="true"
412-
else
413-
MSG="Skip an intermittent issue ${LINE} (fails in this run but passes in the 'main' branch)"
414-
echo "::notice ::$MSG"
415-
echo $MSG >> ${COMMENT_LOG}
416-
echo ""
417-
fi
418-
fi
419-
done
420-
421-
for LINE in ${REF_FAILING}
422-
do
423-
if ! grep -Fxq ${LINE}<<<"${CURRENT_RUN_FAILING}"
424-
then
425-
if ! grep ${LINE} ${IGNORE_INTERMITTENT}
426-
then
427-
MSG="Congrats! The gnu test ${LINE} is no longer failing!"
428-
echo "::notice ::$MSG"
429-
echo $MSG >> ${COMMENT_LOG}
430-
else
431-
MSG="Skipping an intermittent issue ${LINE} (passes in this run but fails in the 'main' branch)"
432-
echo "::notice ::$MSG"
433-
echo $MSG >> ${COMMENT_LOG}
434-
echo ""
435-
fi
436-
fi
437-
done
438-
439-
for LINE in ${CURRENT_RUN_ERROR}
440-
do
441-
if ! grep -Fxq ${LINE}<<<"${REF_ERROR}"
442-
then
443-
MSG="GNU test error: ${LINE}. ${LINE} is passing on '${REPO_DEFAULT_BRANCH}'. Maybe you have to rebase?"
444-
echo "::error ::$MSG"
445-
echo $MSG >> ${COMMENT_LOG}
446-
have_new_failures="true"
447-
fi
448-
done
449-
450-
for LINE in ${REF_ERROR}
451-
do
452-
if ! grep -Fxq ${LINE}<<<"${CURRENT_RUN_ERROR}"
453-
then
454-
MSG="Congrats! The gnu test ${LINE} is no longer ERROR! (might be PASS or FAIL)"
455-
echo "::warning ::$MSG"
456-
echo $MSG >> ${COMMENT_LOG}
457-
fi
458-
done
459-
460-
for LINE in ${REF_SKIP}
461-
do
462-
if ! grep -Fxq ${LINE}<<<"${CURRENT_RUN_SKIP}"
463-
then
464-
MSG="Congrats! The gnu test ${LINE} is no longer SKIP! (might be PASS, ERROR or FAIL)"
465-
echo "::warning ::$MSG"
466-
echo $MSG >> ${COMMENT_LOG}
467-
fi
468-
done
361+
COMPARISON_RESULT=0
362+
if test -f "${CURRENT_SUMMARY_FILE}"; then
363+
if test -f "${REF_SUMMARY_FILE}"; then
364+
echo "Reference summary SHA1/ID: $(sha1sum -- "${REF_SUMMARY_FILE}")"
365+
echo "Current summary SHA1/ID: $(sha1sum -- "${CURRENT_SUMMARY_FILE}")"
366+
367+
python3 util/compare_test_results.py \
368+
--ignore-file "${IGNORE_INTERMITTENT}" \
369+
"${CURRENT_SUMMARY_FILE}" "${REF_SUMMARY_FILE}"
469370
371+
COMPARISON_RESULT=$?
470372
else
471-
echo "::warning ::Skipping ${test_type} test failure comparison; no prior reference test logs are available."
373+
echo "::warning ::Skipping test comparison; no prior reference summary is available at '${REF_SUMMARY_FILE}'."
472374
fi
473-
}
474-
475-
# Compare standard tests
476-
compare_tests '${{ steps.vars.outputs.path_GNU_tests }}/test-suite.log' "${REF_LOG_FILE}" "standard"
477-
478-
# Compare root tests
479-
compare_tests '${{ steps.vars.outputs.path_GNU_tests }}/test-suite-root.log' "${ROOT_REF_LOG_FILE}" "root"
375+
else
376+
echo "::error ::Failed to find summary of test results (missing '${CURRENT_SUMMARY_FILE}'); failing early"
377+
exit 1
378+
fi
480379
481-
# Set environment variable to indicate whether all failures are intermittent
482-
if [ -n "${have_new_failures}" ]; then
380+
if [ ${COMPARISON_RESULT} -eq 1 ]; then
483381
echo "ONLY_INTERMITTENT=false" >> $GITHUB_ENV
484382
echo "::error ::Found new non-intermittent test failures"
485383
exit 1

util/compare_test_results.py

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Compare GNU test results between current run and reference to identify
4+
regressions and fixes.
5+
6+
7+
Arguments:
8+
CURRENT_JSON Path to the current run's aggregated results JSON file
9+
REFERENCE_JSON Path to the reference (main branch) aggregated
10+
results JSON file
11+
--ignore-file Path to file containing list of tests to ignore
12+
(for intermittent issues)
13+
"""
14+
15+
import argparse
16+
import json
17+
import os
18+
import sys
19+
20+
21+
def flatten_test_results(results):
22+
"""Convert nested JSON test results to a flat dictionary of test paths to statuses."""
23+
flattened = {}
24+
for util, tests in results.items():
25+
for test_name, status in tests.items():
26+
test_path = f"{util}/{test_name}"
27+
flattened[test_path] = status
28+
return flattened
29+
30+
31+
def load_ignore_list(ignore_file):
32+
"""Load list of tests to ignore from file."""
33+
if not os.path.exists(ignore_file):
34+
return set()
35+
36+
with open(ignore_file, "r") as f:
37+
return {line.strip() for line in f if line.strip() and not line.startswith("#")}
38+
39+
40+
def identify_test_changes(current_flat, reference_flat):
41+
"""
42+
Identify different categories of test changes between current and reference results.
43+
44+
Args:
45+
current_flat (dict): Flattened dictionary of current test results
46+
reference_flat (dict): Flattened dictionary of reference test results
47+
48+
Returns:
49+
tuple: Four lists containing regressions, fixes, newly_skipped, and newly_passing tests
50+
"""
51+
# Find regressions (tests that were passing but now failing)
52+
regressions = []
53+
for test_path, status in current_flat.items():
54+
if status == "FAIL" or status == "ERROR":
55+
if test_path in reference_flat:
56+
if (
57+
reference_flat[test_path] == "PASS"
58+
or reference_flat[test_path] == "SKIP"
59+
):
60+
regressions.append(test_path)
61+
62+
# Find fixes (tests that were failing but now passing)
63+
fixes = []
64+
for test_path, status in reference_flat.items():
65+
if status == "FAIL" or status == "ERROR":
66+
if test_path in current_flat:
67+
if current_flat[test_path] == "PASS":
68+
fixes.append(test_path)
69+
70+
# Find newly skipped tests (were passing, now skipped)
71+
newly_skipped = []
72+
for test_path, status in current_flat.items():
73+
if (
74+
status == "SKIP"
75+
and test_path in reference_flat
76+
and reference_flat[test_path] == "PASS"
77+
):
78+
newly_skipped.append(test_path)
79+
80+
# Find newly passing tests (were skipped, now passing)
81+
newly_passing = []
82+
for test_path, status in current_flat.items():
83+
if (
84+
status == "PASS"
85+
and test_path in reference_flat
86+
and reference_flat[test_path] == "SKIP"
87+
):
88+
newly_passing.append(test_path)
89+
90+
return regressions, fixes, newly_skipped, newly_passing
91+
92+
93+
def main():
94+
parser = argparse.ArgumentParser(
95+
description="Compare GNU test results and identify regressions and fixes"
96+
)
97+
parser.add_argument("current_json", help="Path to current run JSON results")
98+
parser.add_argument("reference_json", help="Path to reference JSON results")
99+
parser.add_argument(
100+
"--ignore-file",
101+
required=True,
102+
help="Path to file with tests to ignore (for intermittent issues)",
103+
)
104+
105+
args = parser.parse_args()
106+
107+
# Load test results
108+
try:
109+
with open(args.current_json, "r") as f:
110+
current_results = json.load(f)
111+
except (FileNotFoundError, json.JSONDecodeError) as e:
112+
sys.stderr.write(f"Error loading current results: {e}\n")
113+
return 1
114+
115+
try:
116+
with open(args.reference_json, "r") as f:
117+
reference_results = json.load(f)
118+
except (FileNotFoundError, json.JSONDecodeError) as e:
119+
sys.stderr.write(f"Error loading reference results: {e}\n")
120+
sys.stderr.write("Skipping comparison as reference is not available.\n")
121+
return 0
122+
123+
# Load ignore list (required)
124+
if not os.path.exists(args.ignore_file):
125+
sys.stderr.write(f"Error: Ignore file {args.ignore_file} does not exist\n")
126+
print(f"::error ::Ignore file {args.ignore_file} does not exist")
127+
return 1
128+
129+
ignore_list = load_ignore_list(args.ignore_file)
130+
print(f"Loaded {len(ignore_list)} tests to ignore from {args.ignore_file}")
131+
132+
# Flatten result structures for easier comparison
133+
current_flat = flatten_test_results(current_results)
134+
reference_flat = flatten_test_results(reference_results)
135+
136+
# Identify different categories of test changes
137+
regressions, fixes, newly_skipped, newly_passing = identify_test_changes(
138+
current_flat, reference_flat
139+
)
140+
141+
# Filter out intermittent issues from regressions
142+
real_regressions = [r for r in regressions if r not in ignore_list]
143+
intermittent_regressions = [r for r in regressions if r in ignore_list]
144+
145+
have_new_failures = len(real_regressions) > 0
146+
147+
# Print summary stats
148+
print(f"Total tests in current run: {len(current_flat)}")
149+
print(f"Total tests in reference: {len(reference_flat)}")
150+
print(f"New regressions: {len(real_regressions)}")
151+
print(f"Intermittent regressions: {len(intermittent_regressions)}")
152+
print(f"Fixed tests: {len(fixes)}")
153+
print(f"Newly skipped tests: {len(newly_skipped)}")
154+
print(f"Newly passing tests (previously skipped): {len(newly_passing)}")
155+
156+
# Report regressions
157+
if real_regressions:
158+
print("\nREGRESSIONS (non-intermittent failures):", file=sys.stderr)
159+
for test in sorted(real_regressions):
160+
msg = f"GNU test failed: {test}. {test} is passing on 'main'. Maybe you have to rebase?"
161+
print(f"::error ::{msg}", file=sys.stderr)
162+
163+
# Report intermittent issues
164+
if intermittent_regressions:
165+
print("\nINTERMITTENT ISSUES (ignored):", file=sys.stderr)
166+
for test in sorted(intermittent_regressions):
167+
msg = f"Skip an intermittent issue {test} (fails in this run but passes in the 'main' branch)"
168+
print(f"::notice ::{msg}", file=sys.stderr)
169+
170+
# Report fixes
171+
if fixes:
172+
print("\nFIXED TESTS:", file=sys.stderr)
173+
for test in sorted(fixes):
174+
msg = f"Congrats! The gnu test {test} is no longer failing!"
175+
print(f"::notice ::{msg}", file=sys.stderr)
176+
177+
# Report newly skipped and passing tests
178+
if newly_skipped:
179+
print("\nNEWLY SKIPPED TESTS:", file=sys.stderr)
180+
for test in sorted(newly_skipped):
181+
msg = f"Note: The gnu test {test} is now being skipped but was previously passing."
182+
print(f"::warning ::{msg}", file=sys.stderr)
183+
184+
if newly_passing:
185+
print("\nNEWLY PASSING TESTS (previously skipped):", file=sys.stderr)
186+
for test in sorted(newly_passing):
187+
msg = f"Congrats! The gnu test {test} is now passing!"
188+
print(f"::notice ::{msg}", file=sys.stderr)
189+
190+
# Return exit code based on whether we found regressions
191+
return 1 if have_new_failures else 0
192+
193+
194+
if __name__ == "__main__":
195+
sys.exit(main())

0 commit comments

Comments
 (0)