HARD: Mynewt FCB media results and SPIFFS append truncate space (batch 28 47298b7, after a top-up); TinyUSB CH34x control completion, TLV320 output gain encoding and ArduinoJSON decimal carry (batch 26 f20f11c); NetX Duo PPP buffered burst (batch 28 7f01d64). MEDIUM: RT-Thread ringbuffer DMA peek (batch 28 7f01d64). Task digests match the measured ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
5.5 KiB
Python
139 lines
5.5 KiB
Python
"""Private behavioral checks. C code reports observations only."""
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
|
|
CANDIDATES = (
|
|
'components/drivers/include/ipc/ringbuffer.h',
|
|
'components/drivers/ipc/ringbuffer.c',
|
|
'components/drivers/serial/dev_serial_v2.c',
|
|
)
|
|
GRADER = Path(__file__).resolve().parent
|
|
|
|
|
|
def raw_case(exe, args):
|
|
result = subprocess.run([str(exe), *args], capture_output=True, text=True, timeout=5)
|
|
sys.stderr.write('RAW {} {}\n'.format(' '.join(args), result.stdout.replace('\n', ' | ')))
|
|
if result.returncode:
|
|
raise AssertionError('program exit={} stdout={!r} stderr={!r}'.format(
|
|
result.returncode, result.stdout[-400:], result.stderr[-400:]))
|
|
lines = result.stdout.splitlines()
|
|
if len(lines) != 2 or lines[0] != 'IDENTITY uid=65534 gid=65534 groups=[]':
|
|
raise AssertionError('candidate identity/output: {!r}'.format(result.stdout[-600:]))
|
|
fields = {}
|
|
for word in lines[1].split()[1:]:
|
|
key, sep, value = word.partition('=')
|
|
if not sep or key in fields:
|
|
raise AssertionError('malformed output {}'.format(word))
|
|
fields[key] = value
|
|
return fields
|
|
|
|
|
|
def intval(fields, key):
|
|
return int(fields[key])
|
|
|
|
|
|
def assert_ring(exe, cap, first, take, second):
|
|
args = ['ring', str(cap), first.hex() or '-', str(take), second.hex() or '-']
|
|
got = raw_case(exe, args)
|
|
initial = first[:cap]
|
|
removed = initial[:take]
|
|
remaining = initial[take:]
|
|
appended = second[:cap - len(remaining)]
|
|
queue = remaining + appended
|
|
read = len(removed) % cap
|
|
contiguous = queue[:min(len(queue), cap - read)]
|
|
assert intval(got, 'put1') == len(initial)
|
|
assert intval(got, 'got') == len(removed)
|
|
assert got['gothex'] == (removed.hex() or '-')
|
|
assert intval(got, 'put2') == len(appended)
|
|
assert intval(got, 'before_read') == read
|
|
assert intval(got, 'before_len') == len(queue)
|
|
for tag in ('p1', 'p2'):
|
|
assert intval(got, tag + '_n') == len(contiguous)
|
|
assert got[tag + '_hex'] == (contiguous.hex() or '-')
|
|
assert intval(got, tag + '_null') == int(not queue)
|
|
assert intval(got, tag + '_read') == read
|
|
assert intval(got, tag + '_rm') == intval(got, 'before_rm')
|
|
assert intval(got, tag + '_len') == len(queue)
|
|
assert intval(got, 'tail') == len(queue)
|
|
assert got['tailhex'] == (queue.hex() or '-')
|
|
|
|
|
|
def assert_dma(exe, cap, start, first, second):
|
|
args = ['dma', str(cap), str(start), first.hex(), second.hex()]
|
|
got = raw_case(exe, args)
|
|
assert intval(got, 'cap') == cap
|
|
assert intval(got, 'start') == start
|
|
total = 0
|
|
for tag, data in (('d1', first), ('d2', second)):
|
|
total += len(data)
|
|
assert intval(got, tag + '_n') == len(data)
|
|
assert got[tag + '_hex'] == data.hex()
|
|
assert intval(got, tag + '_len') == 0
|
|
idx = (start + total) % cap
|
|
mirror = ((start + total) // cap) & 1
|
|
assert intval(got, tag + '_read') == idx
|
|
assert intval(got, tag + '_write') == idx
|
|
assert intval(got, tag + '_rm') == mirror
|
|
assert intval(got, tag + '_wm') == mirror
|
|
|
|
|
|
def main(candidate):
|
|
with tempfile.TemporaryDirectory(prefix='ring-dma-') as name:
|
|
root = Path(name)
|
|
for rel in CANDIDATES:
|
|
target = root / rel
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy2(candidate / rel, target)
|
|
support = root / 'support'
|
|
shutil.copytree(GRADER / 'grade_support', support)
|
|
shutil.copy2(GRADER / 'probe.c', root / 'probe.c')
|
|
for path in (root, *root.rglob('*')):
|
|
os.chown(path, 65534, 65534)
|
|
for strategy in ('drop', 'force'):
|
|
exe = root / ('probe-' + strategy)
|
|
cmd = ['gcc', '-std=gnu11', '-Wno-implicit-function-declaration',
|
|
'-Wno-int-conversion', '-ffunction-sections', '-fdata-sections',
|
|
'-Wl,--gc-sections']
|
|
if strategy == 'drop':
|
|
cmd.append('-DRT_SERIAL_BUF_STRATEGY_DROP')
|
|
cmd += ['-I' + str(root / 'components/drivers/include/ipc'),
|
|
'-I' + str(support),
|
|
str(root / CANDIDATES[1]), str(root / CANDIDATES[2]),
|
|
str(root / 'probe.c'), '-o', str(exe)]
|
|
compiled = subprocess.run(cmd, capture_output=True, text=True, timeout=20)
|
|
if compiled.returncode:
|
|
raise AssertionError('compile {}: {}'.format(strategy, compiled.stderr[-1200:]))
|
|
if strategy == 'drop':
|
|
ring_cases = (
|
|
(8, b'', 0, b''),
|
|
(8, b'ABC', 0, b''),
|
|
(8, b'abcdef', 5, b'WXYZ'),
|
|
(8, b'abcdefgh', 0, b''),
|
|
(8, b'abcdef', 5, b'1234567'),
|
|
(12, b'\x00\x01\x02\xf0\xfe\xff\x10\x20\x30', 8, b'\x99\x88\x77\x66\x55'),
|
|
)
|
|
for case in ring_cases:
|
|
assert_ring(exe, *case)
|
|
dma_cases = (
|
|
(8, 0, b'ABC', b'DE'),
|
|
(8, 6, b'MNOP', b'QR'),
|
|
(16, 7, bytes(range(12, 18)), bytes(range(22, 27))),
|
|
)
|
|
for case in dma_cases:
|
|
assert_dma(exe, *case)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main(Path(sys.argv[1]))
|
|
except (AssertionError, KeyError, ValueError, OSError, subprocess.TimeoutExpired) as exc:
|
|
print('FAIL {}'.format(str(exc)[:250]))
|
|
raise SystemExit(1)
|
|
print('PASS')
|