1 Commits

Author SHA1 Message Date
0294aed3dd buffer_format_fuzz: validate --budget
--budget is a count of random elements per format, and a negative one was
accepted with exit 0 and no message. `for _ in range(budget)` simply does not
run, so -1, -100 and -1000000 produced exactly the run of 0 -- 1026 instead of
1106 elements for 8_8_8_8_UNORM -- and every format still reported "ok".
--self-test was worse: it builds its own patterns with a hardcoded budget of 2
and never reads the option, so `--self-test --budget -100` and `--budget
1000000` both printed the same "self-test: ok" in the same 1.4 s.

Before:
  $ python -I tools/buffer_format_fuzz.py --self-test --budget -1
  self-test: ok                                # exit 0
  $ python -I tools/buffer_format_fuzz.py --oracle hw --budget -3
  hardware oracle unavailable: ...             # exit 77, no GPU needed to know

After, one check next to the other argument guards and before both the
self-test and the oracle, so the value is validated even where it is not used:

  $ python -I tools/buffer_format_fuzz.py --self-test --budget -1
  buffer_format_fuzz.py: error: --budget cannot be negative   # exit 2
  $ python -I tools/buffer_format_fuzz.py --self-test --budget 0
  self-test: ok                                # 0 stays legal: sweeps only

tests/test_buffer_format_fuzz.py (CPU only, hw_oracle stubbed) covers the
negative value on both paths, that it is refused before the oracle is opened,
that 0 stays legal and that -1 is otherwise indistinguishable from 0.
3 of its 7 tests fail without this change, 7 pass with it.
2026-11-25 07:06:02 +01:00