Skip to content

Commit 6f70155

Browse files
committed
[green] allocate valid IDs for every host PUT command
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent 19c4677 commit 6f70155

5 files changed

Lines changed: 34 additions & 28 deletions

File tree

‎tests/firmware_tests/hil/_pble_bench.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ async def put_file(
19571957
accounting.note_send(next_offset, len(piece))
19581958
await central.send_cmd_no_rsp(
19591959
wire.OP_FILE_PUT_DATA,
1960-
0,
1960+
next_id(),
19611961
_u32(next_offset) + piece,
19621962
)
19631963
next_offset += len(piece)

‎tests/firmware_tests/hil/f11_reliability_bench.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def _upload_one(c, path, data, window, chunk, next_id,
198198
piece = data[next_off:next_off + chunk]
199199
await c.send_cmd_no_rsp(
200200
wire.OP_FILE_PUT_DATA,
201-
0, # DATA is no-RSP; id irrelevant
201+
next_id(), # No RSP, but every CMD still needs a nonzero ID.
202202
next_off.to_bytes(4, "little") + piece)
203203
next_off += len(piece)
204204

‎tests/firmware_tests/hil/file_roundtrip_bench.py‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import _pble_wire as wire
3333
from _pble_central import PbleCentral, rsp_status, status_name
34-
from _pble_bench import DownloadVerifier
34+
from _pble_bench import CommandIds, DownloadVerifier
3535

3636
DEST = "/bench_roundtrip.bin"
3737
GET_STALL_S = 10.0 # bench-side inactivity ceiling per chunk (diagnostic bound)
@@ -70,7 +70,7 @@ async def _hello(c, id_):
7070
return caps
7171

7272

73-
async def _put(c, data, chunk, window):
73+
async def _put(c, data, chunk, window, next_id):
7474
"""Windowed FILE_PUT sender honoring the ADVERTISED caps window (FR-FS-4).
7575
7676
Keeps up to `window` unacknowledged chunks in flight past the cumulative
@@ -84,7 +84,7 @@ async def _put(c, data, chunk, window):
8484
reporting ack/want on a true stall (the dropped-chunk diagnostic)."""
8585
t0 = time.monotonic()
8686
rsp = await c.send_cmd(
87-
wire.OP_FILE_PUT_BEGIN, 2,
87+
wire.OP_FILE_PUT_BEGIN, next_id(),
8888
_u32(len(data)) + _u32(zlib.crc32(data)) + _path_field(DEST))
8989
if rsp_status(rsp) != wire.ST_OK:
9090
raise SystemExit("PUT_BEGIN: %s" % status_name(rsp_status(rsp)))
@@ -101,7 +101,7 @@ async def _put(c, data, chunk, window):
101101
# never more than `window` unacknowledged chunks in flight (AC-1).
102102
while next_off < total and (next_off - c.last_ack) < win_bytes:
103103
piece = data[next_off:next_off + chunk]
104-
await c.send_cmd_no_rsp(wire.OP_FILE_PUT_DATA, 0, _u32(next_off) + piece)
104+
await c.send_cmd_no_rsp(wire.OP_FILE_PUT_DATA, next_id(), _u32(next_off) + piece)
105105
next_off += len(piece)
106106
now = time.monotonic()
107107
if c.last_ack > seen_ack:
@@ -117,20 +117,20 @@ async def _put(c, data, chunk, window):
117117
next_off = c.last_ack
118118
last_rewind = now
119119
await asyncio.sleep(0.002)
120-
rsp = await c.send_cmd(wire.OP_FILE_PUT_END, 3, _u32(zlib.crc32(data)))
120+
rsp = await c.send_cmd(wire.OP_FILE_PUT_END, next_id(), _u32(zlib.crc32(data)))
121121
if rsp_status(rsp) != wire.ST_OK:
122122
raise SystemExit("PUT_END: %s" % status_name(rsp_status(rsp)))
123123
return time.monotonic() - t0
124124

125125

126-
async def _get(c, expected):
126+
async def _get(c, expected, next_id):
127127
"""GET_BEGIN then drain GET_DATA events until GET_END. Deadline-bounded."""
128128
expected = bytes(expected)
129129
expect_len = len(expected)
130130
verifier = DownloadVerifier(expected)
131131
c.events.clear()
132132
t0 = time.monotonic()
133-
rsp = await c.send_cmd(wire.OP_FILE_GET_BEGIN, 4, _u32(0) + _path_field(DEST))
133+
rsp = await c.send_cmd(wire.OP_FILE_GET_BEGIN, next_id(), _u32(0) + _path_field(DEST))
134134
if rsp_status(rsp) != wire.ST_OK:
135135
raise SystemExit("GET_BEGIN: %s" % status_name(rsp_status(rsp)))
136136
total = int.from_bytes(rsp.payload[1:5], "little")
@@ -178,7 +178,8 @@ async def run(args):
178178

179179
c = await PbleCentral.connect(args.address)
180180
try:
181-
caps = await _hello(c, 1)
181+
ids = CommandIds()
182+
caps = await _hello(c, ids.next())
182183
chip = caps.get("chip", "?")
183184
caps_mtu = int(caps.get("mtu", "0") or 0)
184185
if caps_mtu:
@@ -195,17 +196,17 @@ async def run(args):
195196
raise SystemExit("wrong board: chip=%s (expected %s)" % (chip, args.expect_chip))
196197

197198
data = os.urandom(args.size)
198-
up_s = await _put(c, data, chunk, window)
199+
up_s = await _put(c, data, chunk, window, ids.next)
199200
print("PUT %6d B in %5.2f s (%6.0f B/s)" % (len(data), up_s, len(data) / up_s))
200201

201-
got, end_crc, dn_s = await _get(c, data)
202+
got, end_crc, dn_s = await _get(c, data, ids.next)
202203
print("GET %6d B in %5.2f s (%6.0f B/s)" % (len(got), dn_s, len(got) / dn_s))
203204

204205
ok = got == data and end_crc == zlib.crc32(data)
205206
print("END crc=0x%08x match=%s bytes-equal=%s"
206207
% (end_crc, end_crc == zlib.crc32(data), got == data))
207208
# Cleanup: remove the bench artifact from the board.
208-
await c.send_cmd(wire.OP_FILE_DELETE, 5, _path_field(DEST))
209+
await c.send_cmd(wire.OP_FILE_DELETE, ids.next(), _path_field(DEST))
209210
# Record the negotiated ATT MTU on the final line: it is the link fact the
210211
# OI-1 throughput numbers are read against (chunk = mtu - PBLE_CHUNK_OVERHEAD),
211212
# so the owner's measurement log captures the MTU the run actually saw.

‎tests/firmware_tests/hil/rp2_run_stop.py‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import _pble_wire as wire
3232
from _pble_central import PbleCentral, rsp_status, status_name
33+
from _pble_bench import CommandIds
3334

3435
STOP_DEADLINE_S = 0.5 # H6: STOP must land inside this bound
3536
STATE_WAIT_S = 5.0 # bench-side ceiling for an expected RUN_STATE
@@ -140,23 +141,23 @@ async def run_and_stop(c, central, log, id_, source, hold_s, desc):
140141
late_done is None and late_err is None)
141142

142143

143-
async def put_small_file(central, path, data, first_id):
144+
async def put_small_file(central, path, data, next_id):
144145
"""Minimal single-chunk windowed PUT for a bench fixture file."""
145146
rsp = await central.send_cmd(
146-
wire.OP_FILE_PUT_BEGIN, first_id,
147+
wire.OP_FILE_PUT_BEGIN, next_id(),
147148
len(data).to_bytes(4, "little") + (zlib.crc32(data) & 0xFFFFFFFF).to_bytes(4, "little")
148149
+ len(path.encode()).to_bytes(2, "little") + path.encode())
149150
if rsp_status(rsp) != wire.ST_OK:
150151
raise SystemExit("PUT_BEGIN %s: %s" % (path, status_name(rsp_status(rsp))))
151152
central.last_ack = 0
152-
await central.send_cmd_no_rsp(wire.OP_FILE_PUT_DATA, 0, (0).to_bytes(4, "little") + data)
153+
await central.send_cmd_no_rsp(wire.OP_FILE_PUT_DATA, next_id(), (0).to_bytes(4, "little") + data)
153154
deadline = time.monotonic() + DONE_WAIT_S
154155
while central.last_ack < len(data):
155156
if time.monotonic() > deadline:
156157
raise SystemExit("PUT %s stalled: ack=%d want=%d"
157158
% (path, central.last_ack, len(data)))
158159
await asyncio.sleep(0.01)
159-
rsp = await central.send_cmd(wire.OP_FILE_PUT_END, first_id + 1,
160+
rsp = await central.send_cmd(wire.OP_FILE_PUT_END, next_id(),
160161
(zlib.crc32(data) & 0xFFFFFFFF).to_bytes(4, "little"))
161162
if rsp_status(rsp) != wire.ST_OK:
162163
raise SystemExit("PUT_END %s: %s" % (path, status_name(rsp_status(rsp))))
@@ -216,22 +217,24 @@ async def run(args):
216217
"got %d RUN_STATE event(s)" % len(stray))
217218

218219
# D) file-mode RUN of /main.py: same lifecycle, finite script -> done.
219-
await put_small_file(central, MAIN_PATH, MAIN_SOURCE, 40)
220+
file_ids = CommandIds()
221+
await put_small_file(central, MAIN_PATH, MAIN_SOURCE, file_ids.next)
220222
cursor = len(log)
221-
rsp = await central.send_cmd(wire.OP_RUN, 42, bytes((0,)) + MAIN_PATH.encode())
223+
file_run_id = file_ids.next()
224+
rsp = await central.send_cmd(wire.OP_RUN, file_run_id, bytes((0,)) + MAIN_PATH.encode())
222225
c.check("file-mode: RUN %s RSP status is OK" % MAIN_PATH,
223226
rsp_status(rsp) == wire.ST_OK, status_name(rsp_status(rsp)))
224227
run_i = await wait_run_state(log, cursor, ST_RUNNING, STATE_WAIT_S)
225228
if c.check("file-mode: RUN_STATE(running) arrives", run_i is not None):
226-
rsp_i = find_rsp(log, cursor, wire.OP_RUN, 42)
229+
rsp_i = find_rsp(log, cursor, wire.OP_RUN, file_run_id)
227230
c.check("file-mode: RSP precedes RUN_STATE(running) on the wire",
228231
rsp_i is not None and rsp_i < run_i,
229232
"rsp_index=%s running_index=%s" % (rsp_i, run_i))
230233
done_i = await wait_run_state(log, run_i + 1, ST_DONE, DONE_WAIT_S)
231234
c.check("file-mode: finite %s terminates as done" % MAIN_PATH,
232235
done_i is not None)
233236
# Cleanup the bench fixture so autorun cannot pick it up later.
234-
await central.send_cmd(wire.OP_FILE_DELETE, 43,
237+
await central.send_cmd(wire.OP_FILE_DELETE, file_ids.next(),
235238
len(MAIN_PATH.encode()).to_bytes(2, "little")
236239
+ MAIN_PATH.encode())
237240

‎tests/firmware_tests/hil/target_run_stop.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import _pble_wire as wire
1717
from _pble_central import PbleCentral, rsp_status, status_name
18+
from _pble_bench import CommandIds
1819
import target_smoke
1920

2021

@@ -346,12 +347,12 @@ async def run_and_stop(checks, central, log, request_id, source, description):
346347
)
347348

348349

349-
async def put_small_file(central, path, data, first_id):
350+
async def put_small_file(central, path, data, next_id):
350351
encoded_path = path.encode("utf-8")
351352
checksum = zlib.crc32(data) & 0xFFFFFFFF
352353
response = await central.send_cmd(
353354
wire.OP_FILE_PUT_BEGIN,
354-
first_id,
355+
next_id(),
355356
len(data).to_bytes(4, "little")
356357
+ checksum.to_bytes(4, "little")
357358
+ len(encoded_path).to_bytes(2, "little")
@@ -364,15 +365,15 @@ async def put_small_file(central, path, data, first_id):
364365
)
365366
central.last_ack = 0
366367
await central.send_cmd_no_rsp(
367-
wire.OP_FILE_PUT_DATA, 0, (0).to_bytes(4, "little") + data
368+
wire.OP_FILE_PUT_DATA, next_id(), (0).to_bytes(4, "little") + data
368369
)
369370
deadline = time.monotonic() + DONE_WAIT_S
370371
while central.last_ack < len(data):
371372
if time.monotonic() >= deadline:
372373
raise ValueError("fixture upload stalled")
373374
await asyncio.sleep(0.01)
374375
response = await central.send_cmd(
375-
wire.OP_FILE_PUT_END, first_id + 1, checksum.to_bytes(4, "little")
376+
wire.OP_FILE_PUT_END, next_id(), checksum.to_bytes(4, "little")
376377
)
377378
if rsp_status(response) != wire.ST_OK:
378379
raise ValueError("fixture PUT_END failed")
@@ -439,10 +440,11 @@ async def run(args):
439440
]
440441
checks.check("idle STOP emits no RUN_STATE", not stray)
441442

442-
await put_small_file(central, FIXTURE_PATH, FIXTURE_SOURCE, 40)
443+
file_ids = CommandIds()
444+
await put_small_file(central, FIXTURE_PATH, FIXTURE_SOURCE, file_ids.next)
443445
cursor = len(log)
444446
response = await central.send_cmd(
445-
wire.OP_RUN, 42, bytes((0,)) + FIXTURE_PATH.encode("utf-8")
447+
wire.OP_RUN, file_ids.next(), bytes((0,)) + FIXTURE_PATH.encode("utf-8")
446448
)
447449
checks.check(
448450
"file-mode RUN RSP is OK",
@@ -461,7 +463,7 @@ async def run(args):
461463
encoded_path = FIXTURE_PATH.encode("utf-8")
462464
await central.send_cmd(
463465
wire.OP_FILE_DELETE,
464-
43,
466+
file_ids.next(),
465467
len(encoded_path).to_bytes(2, "little") + encoded_path,
466468
)
467469

0 commit comments

Comments
 (0)