Skip to content

Commit b1967ea

Browse files
committed
tests: Improve coverage of emitinlinerv32.c.
Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent ccec4a2 commit b1967ea

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

tests/ports/unix/mpy_coverage.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ def run_one_arch(arch, inlineasm=None):
7171
run_dir(f"inlineasm/{inlineasm}", emit_arch=arch, emit_opt="EMIT_OPT_NATIVE_PYTHON")
7272

7373

74+
def run_extra_cases(emit_arch, cases):
75+
arch_support_check(emit_arch)
76+
77+
for content in cases:
78+
try:
79+
compiled = mpycross.compile(content, "<expect-error>", emit_arch=emit_arch)
80+
print(f"OK")
81+
except SyntaxError as e:
82+
print(e)
83+
84+
7485
if __name__ == "__main__":
7586
arch_support_check("host")
7687
run_dir(f"basics", emit_opt="EMIT_OPT_BYTECODE")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
11
import mpy_coverage
22

33
mpy_coverage.run_one_arch("rv32imc", "rv32")
4+
5+
print("Expected to compile")
6+
mpy_coverage.run_extra_cases(
7+
"rv32imc",
8+
[
9+
"@micropython.asm_rv32\ndef f(): ebreak()",
10+
],
11+
)
12+
13+
print("Expected to fail")
14+
mpy_coverage.run_extra_cases(
15+
"rv32imc",
16+
[
17+
"@micropython.asm_rv32\ndef f(a0, a1, a2, a3, a4): ac_li(a0, 1)",
18+
"@micropython.asm_rv32\ndef f(a0, a4): ac_li(a0, 1)",
19+
"@micropython.asm_rv32\ndef f(a0): csrrc()",
20+
"@micropython.asm_rv32\ndef f(a0): csrrc(s0, s0, s0)",
21+
"@micropython.asm_rv32\ndef f(a0): csrrc(s0, s0, 0xffffff)",
22+
"@micropython.asm_rv32\ndef f(a0): csrrc(s0, 0, s0)",
23+
"@micropython.asm_rv32\ndef f(a0): moo()",
24+
"@micropython.asm_rv32\ndef f(a0): beq(a0,a0,0)",
25+
"@micropython.asm_rv32\ndef f(a0): beq(a0,a0,3.14)",
26+
"@micropython.asm_rv32\ndef f(a0): beq(a0,a0,y)",
27+
"@micropython.asm_rv32\ndef f(): lw(a3, 99999(a3))",
28+
"@micropython.asm_rv32\ndef f(): lw()",
29+
"@micropython.asm_rv32\ndef f(): a=di(a2, a2, -1)",
30+
],
31+
)

tests/ports/unix/mpy_coverage_rv32imc.py.exp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,19 @@ Compiling asmsanity.py with rv32imc EMIT_OPT_NATIVE_PYTHON
595595
Compiling asmshift.py with rv32imc EMIT_OPT_NATIVE_PYTHON
596596
Compiling asmstack.py with rv32imc EMIT_OPT_NATIVE_PYTHON
597597
Compiling asmsum.py with rv32imc EMIT_OPT_NATIVE_PYTHON
598+
Expected to compile
599+
OK
600+
Expected to fail
601+
can only have up to 4 parameters for RV32 assembly
602+
parameters must be registers in sequence a0 to a3
603+
opcode 'csrrc': expecting 3 arguments
604+
opcode 'csrrc' argument 3: expecting integer
605+
opcode 'csrrc' argument 3: out of range
606+
opcode 'csrrc' argument 2: expecting register
607+
unknown RV32 instruction 'moo'
608+
opcode 'beq' argument 3: expecting label
609+
opcode 'beq' argument 3: expecting label
610+
opcode 'beq' argument 3: undefined label 'y'
611+
opcode 'lw' argument 2: out of range
612+
opcode 'lw': expecting 2 arguments
613+
expecting an assembler instruction

0 commit comments

Comments
 (0)