mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
Review of the first version of the suite found four holes. - The conversion sites returned the converted value, which shows its bits but not the type it was stored as. The untyped_local site passed over a real bug that way. Each site now reads the value back through an expression whose result depends on its sign and width. - With the type drawn at random, 25 examples per site left a single type with about 3. A deliberately broken c_bool conversion went undetected under some seeds. The conversion property is now parametrized by destination type and the operator property by left operand type, a sixteenth of the profile's examples each. - The global_init site was a strict xfail. Hypothesis shrank its expected failures, which took 115 of the property's 187 seconds. Its two bugs are now pinned in test_known_gaps.py, and the site steps around them. - Gaps are now stepped around by drawing only inputs that avoid them, not by assume(). Filtering tripped Hypothesis's filter_too_much health check. untyped-copy-keeps-narrow-type is renamed untyped-copy-keeps-source-type. `t = a` keeps a's type for any source that is not 64-bit, c_uint32 and c_int32 included, not only narrow ones. Under the ci profile, each of these deliberate compiler bugs fails a property: - >> always logical - % always unsigned - / always unsigned - equal-width mixed signs going signed - promotion keeping an unsigned sign - widening always by zero-extension - c_bool conversion by truncation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""
|
|
Each known gap's smallest program, as a strict xfail: when a fix lands it
|
|
XPASSes and fails the run, as a reminder to delete the gap from
|
|
tests/property/known_gaps.py so the properties cover that ground again.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from tests.property.cints import C_BOOL, C_INT64, convert
|
|
from tests.property.harness import CLANG, check_against_clang
|
|
from tests.property.known_gaps import GAPS
|
|
from tests.property.programs import Program
|
|
|
|
pytestmark = pytest.mark.skipif(CLANG is None, reason="clang is not installed")
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"gap",
|
|
[
|
|
pytest.param(
|
|
g,
|
|
id=g.name,
|
|
marks=pytest.mark.xfail(
|
|
strict=True, raises=AssertionError, reason=g.reason
|
|
),
|
|
)
|
|
for g in GAPS
|
|
],
|
|
)
|
|
def test_known_gap_still_diverges(gap):
|
|
assert gap.hits(gap.example), "the pinned program must hit its own gap"
|
|
check_against_clang(gap.example.program(), gap.example.expected)
|
|
|
|
|
|
@pytest.mark.xfail(
|
|
strict=True,
|
|
raises=AssertionError,
|
|
reason="shift-result-type, in augmented assignment: `x >>= a` with x a "
|
|
"c_int32 and a a c_uint32 shifts logically in u32; C shifts x's own int",
|
|
)
|
|
def test_known_gap_augassign_shift():
|
|
program = Program(
|
|
["a0 = c_uint32(1)", "x = c_int32(-2147483648)", "x >>= a0", "return x"],
|
|
["unsigned int a0 = 1;", "int x = -2147483648;", "x >>= a0;", "return x;"],
|
|
)
|
|
check_against_clang(program, lambda: convert(-(2**31) >> 1, C_INT64))
|
|
|
|
|
|
GLOBAL_INIT_REASON = (
|
|
"global-initialiser: a @bpfglobal initialiser that is not a bare constant "
|
|
"(c_int64(-5) is not: -5 is a UnaryOp) is emitted as 0, and a constant is "
|
|
"not converted to the type, so c_bool(2) keeps the low bit, 0, where C "
|
|
"gives 1 (pythonbpf/globals_pass.py, _emit_global). "
|
|
"test_int_conversions' global_init site steps around both."
|
|
)
|
|
|
|
|
|
@pytest.mark.xfail(strict=True, raises=AssertionError, reason=GLOBAL_INIT_REASON)
|
|
@pytest.mark.parametrize(
|
|
"ty, literal", [(C_INT64, -5), (C_BOOL, 2)], ids=["negative", "c_bool"]
|
|
)
|
|
def test_known_gap_global_initialiser(ty, literal):
|
|
program = Program(["return g"], ["return g;"], globals=[("g", ty, literal)])
|
|
check_against_clang(program, lambda: convert(convert(literal, ty), C_INT64))
|