Skip to content

Commit c90e724

Browse files
committed
generator: more vm interp tests
1 parent 0b40548 commit c90e724

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

generators/vm_interp.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,31 @@ def validate():
169169
0x71e3cf81, # magic - always SIGSTACK (ignore call_whitelist)
170170
0x12345678, # invalid
171171
0x0b00c380, # inverse of magic - just invalid
172+
0x3770fb22, # syscall: sol_memset_
173+
1, # success without relocation. works in v3+
174+
0,
175+
2,
176+
3,
177+
4,
178+
0xffffffff, # overflow ok because of negative offsets
172179
]:
173180
test_vectors_all_ix.append({
174181
"op": f"{op:02x}",
175182
"cu_avail": 100,
176-
# hashmap containing vaild pc: 0, 1, 2 (higher are trimmed)
183+
# hashmap containing valid function
184+
"call_whitelist": [0x04],
185+
"rodata":
186+
bytes([op, ((sreg << 4) + dreg) % 0xFF, 0, 0]) + imm.to_bytes(4, "little") + \
187+
bytes([0x95, 0, 0, 0, 0, 0, 0, 0]) + \
188+
bytes([0x95, 0, 0, 0, 0, 0, 0, 0])
189+
})
190+
# TODO: the following generates invalid functions to test validate()
191+
# it's ok in v0-v2, it should return -2 in v3+
192+
test_vectors_all_ix.append({
193+
"op": f"{op:02x}",
194+
"cu_avail": 100,
195+
# hashmap containing valid pc: 0, 1, 2 (higher are trimmed)
196+
# these are invalid fn in v3+
177197
"call_whitelist": [0xff],
178198
"rodata":
179199
bytes([op, ((sreg << 4) + dreg) % 0xFF, 0, 0]) + imm.to_bytes(4, "little") + \
@@ -248,6 +268,22 @@ def validate():
248268
bytes([op, ((sreg << 4) + dreg) % 0xFF]) + offset.to_bytes(2, "little") + imm.to_bytes(4, "little") + \
249269
bytes([0x95, 0, 0, 0, 0, 0, 0, 0])
250270
})
271+
272+
# syscall (v3)
273+
if op == 0x95:
274+
sreg = 0
275+
dreg = 0
276+
for imm in [
277+
3, # sol_memset_
278+
100, # invalid
279+
]:
280+
test_vectors_all_ix.append({
281+
"op": f"{op:02x}",
282+
"cu_avail": 100,
283+
"rodata":
284+
bytes([ op, 0, 0, 0]) + imm.to_bytes(4, "little") + \
285+
bytes([0x9d, 0, 0, 0, 0, 0, 0, 0])
286+
})
251287
# fmt: on
252288

253289

@@ -310,14 +346,22 @@ def _into_key_data(key_prefix, test_vectors):
310346
with open(f"{OUTPUT_DIR}/{testname}/v0/{filename}.bin", "wb") as f:
311347
f.write(serialized_instr)
312348

313-
syscall_ctx.vm_ctx.sbpf_version = 1
314-
serialized_instr = syscall_ctx.SerializeToString(deterministic=True)
315-
with open(f"{OUTPUT_DIR}/{testname}/v1/{filename}.bin", "wb") as f:
316-
f.write(serialized_instr)
349+
# syscall_ctx.vm_ctx.sbpf_version = 1
350+
# serialized_instr = syscall_ctx.SerializeToString(deterministic=True)
351+
# with open(f"{OUTPUT_DIR}/{testname}/v1/{filename}.bin", "wb") as f:
352+
# f.write(serialized_instr)
317353

318354
syscall_ctx.vm_ctx.sbpf_version = 2
319355
serialized_instr = syscall_ctx.SerializeToString(deterministic=True)
320356
with open(f"{OUTPUT_DIR}/{testname}/v2/{filename}.bin", "wb") as f:
321357
f.write(serialized_instr)
322358

359+
syscall_ctx.vm_ctx.sbpf_version = 3
360+
syscall_ctx.vm_ctx.rodata = bytes(
361+
[x if x != 0x95 else 0x9D for x in syscall_ctx.vm_ctx.rodata]
362+
)
363+
serialized_instr = syscall_ctx.SerializeToString(deterministic=True)
364+
with open(f"{OUTPUT_DIR}/{testname}/v3/{filename}.bin", "wb") as f:
365+
f.write(serialized_instr)
366+
323367
print("done!")

0 commit comments

Comments
 (0)