Repository navigation
buffer_bounds_probe: validate and write --json through the shared helpers - #5406
liang-kai-shui wants to merge 8 commits into
Conversation
|
An existing read-only report still costs a complete probe before the tool detects the output error. I tested head
The read-only attribute was set before the call and stayed set throughout. The old report survived. To avoid wasting the hardware measurement, check that attribute for an existing output file before opening the oracle. Keep the write-time check for failures that occur later. To repeat, run this script from the repository root with import contextlib,io,stat,sys,tempfile
from pathlib import Path
from unittest.mock import patch
sys.path.insert(0, "tests")
import test_buffer_bounds_probe as t
with tempfile.TemporaryDirectory() as d:
target=Path(d)/"report.json"
target.write_text("previous report")
try:
for mode in (stat.S_IREAD,stat.S_IREAD|stat.S_IWRITE):
target.chmod(mode)
err=io.StringIO()
with patch.object(t.hw_runner,"open_oracle",return_value=t.fake_oracle()) as opened, patch.object(t.bbp,"probe",return_value=t.FAKE_REPORT) as measured, contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(err):
rc=t.bbp.main(["--json",str(target)])
print(rc,opened.call_count,measured.call_count,err.getvalue().strip(),target.read_text()[:15])
finally:
target.chmod(stat.S_IREAD|stat.S_IWRITE)All eight existing tests and the tool's self-test pass. This is a remaining early-validation case. AI-assisted. |
|
Fixed in
AI-assisted. |
kacper-serewis
left a comment
There was a problem hiding this comment.
AI-assisted Windows CPU review at ab22cd1. All nine focused tests passed. A read-only existing report survived and the oracle was never opened. A valid nested destination produced the expected JSON. Two limits reproduced with a recording harness through main: bad?.json reached both open_oracle and probe before the write failed, and injecting OSError after the writer emitted its first byte replaced an existing report with just {. Both returned 2. The existing open-failure test cannot catch data loss after truncation. A temporary sibling followed by replacement after successful close would preserve an existing report on a late failure.
Kam471
left a comment
There was a problem hiding this comment.
Head deff92f60b48804e7501ca5e6860f6eff880935c (base main 3faac557b).
python -m pytest -q tests/test_buffer_bounds_probe.py-> 8 passed, 7 subtests.python -I tools/buffer_bounds_probe.py --self-test-> self-test OK.- Negative control:
git checkout main -- tools/buffer_bounds_probe.py, same pytest command -> 11 failed, 4 passed. git diff --check mainclean
validate_json_path runs before from hw_oracle import ...; runner.open_oracle(), and the tests assert open_oracle was not called for every bad path. The broken-LEONIDA_AMD_CLANG subprocess expects 2, where reaching the oracle would exit 77, so ordering is proven, not assumed. write_json_report creates parents and returns one error line.
Overlap: the PR itself notes #4785 for the write-failure path (outside this range); this one also validates before hardware.
Verdict: pass.
|
Reviewed 591879b (code read + CPU tests on Linux, Python 3.14): pass, with one small mismatch.
AI-assisted (Claude Code). |
|
Fixed in AI-assisted. |
|
Tested c8aa33a merged with main 561b65a on Linux (WSL2) / Python 3.12.16 and Windows 11 / Python 3.13.1: pass tests/test_buffer_bounds_probe.py: 10 run, 10 passed, 0 failed on both (Linux and a native Windows worktree of the merged tree). Negative control: with tools/buffer_bounds_probe.py restored from upstream/main the new tests fail (10 run, 1 failure and 12 errors, since main has no main(argv), validate_json_path or write_json_report); fix restored afterwards. |
Claimed in the coordination issue as: claim in #5256
What and why
tools/buffer_bounds_probe.py --jsonwrote its report with a bareopen(), and the path was only looked at after the hardware oracle had been opened. So an empty path, a NUL byte, a directory, or a file used as a parent component either cost a GPU session first or raised a traceback, and a missing parent directory was not created.It now uses the same two helpers as
tools/f16_trans_sweep.py(validate_json_pathandwrite_json_report, copied in the shape the other probes use):--jsonis validated beforeopen_oracle(). A bad path prints exactly oneERROR: <message>line and returns 2. The report goes throughwrite_json_report, which creates missing parents and writes LF JSON; an OSError there is oneERROR:line and exit 2, not a traceback.--self-test,--waves, the kernels and the stdout output are unchanged.LEONIDA_AMD_CLANG, so reaching the oracle would have exited 77),open_oracleis asserted not called for every bad path, missing parents are created and the JSON round-trips, a file parent gives a clean error, and a write failure is exactly oneERROR:line.Overlaps #4785 on the write-failure path; this also validates before hardware is opened. First to land wins, as usual.
Tests
CPU only, Windows 11, Python 3.13.15:
python -I tests/test_buffer_bounds_probe.py: 8 tests, OK.python -m compileall -q .: clean.git diff --check: clean.python -I tools/buffer_bounds_probe.py --self-test: self-test OK.--json <directory>and--json <file>/out.jsonwith a broken clang print oneERROR:line and exit 2 (77 if the oracle had been reached).No game data: every kernel, buffer and pattern is built in the tool, and the new tests use synthetic probe results and temporary directories only.
AI-assisted (DeepSeek coding agent); I reviewed the diff and ran the commands above.