@@ -18,7 +18,7 @@ def nice_opcode(o):
18
18
return o [:3 ] + "_" + o [3 :8 ] + "_" + o [8 :]
19
19
20
20
21
- class TestNop (unittest .TestCase ):
21
+ class AssembleChecks (unittest .TestCase ):
22
22
def assertAssemblesTo (self , source , expected ):
23
23
actual = adafruit_pioasm .assemble (source )
24
24
expected_bin = [nice_opcode (x ) for x in expected ]
@@ -29,13 +29,18 @@ def assertAssemblesTo(self, source, expected):
29
29
f"Assembling { source !r} : Expected { expected_bin } , got { actual_bin } " ,
30
30
)
31
31
32
- def assertAssemblyFails (self , source ):
33
- self .assertRaises (RuntimeError , adafruit_pioasm .assemble , source )
32
+ def assertAssemblyFails (self , source , match = None , errtype = RuntimeError ):
33
+ if match :
34
+ self .assertRaisesRegex (errtype , match , adafruit_pioasm .assemble , source )
35
+ else :
36
+ self .assertRaises (errtype , adafruit_pioasm .assemble , source )
34
37
35
38
def assertPioKwargs (self , source , ** kw ):
36
39
program = adafruit_pioasm .Program (source )
37
40
self .assertEqual (kw , program .pio_kwargs )
38
41
42
+
43
+ class TestNop (AssembleChecks ):
39
44
def testNonsense (self ):
40
45
self .assertAssemblyFails ("nope" )
41
46
@@ -64,6 +69,12 @@ def testSidesetOpt(self):
64
69
".side_set 1 opt\n nop side 0 [7]" , [0b101_10111_010_00_010 ]
65
70
)
66
71
72
+ def testSet (self ):
73
+ # non happy path
74
+ self .assertAssemblyFails (
75
+ "set isr, 1" , match = "Invalid set destination 'isr'" , errtype = ValueError
76
+ )
77
+
67
78
def testJmp (self ):
68
79
self .assertAssemblesTo ("l:\n jmp l" , [0b000_00000_000_00000 ])
69
80
self .assertAssemblesTo ("l:\n jmp 7" , [0b000_00000_000_00111 ])
@@ -75,6 +86,10 @@ def testJmp(self):
75
86
self .assertAssemblesTo ("jmp x!=y, l\n l:" , [0b000_00000_101_00001 ])
76
87
self .assertAssemblesTo ("jmp pin, l\n l:" , [0b000_00000_110_00001 ])
77
88
self .assertAssemblesTo ("jmp !osre, l\n l:" , [0b000_00000_111_00001 ])
89
+ # non happy path
90
+ self .assertAssemblyFails (
91
+ "jmp x--., l\n l:" , match = "Invalid jmp condition 'x--.'" , errtype = ValueError
92
+ )
78
93
79
94
def testWait (self ):
80
95
self .assertAssemblesTo ("wait 0 gpio 0" , [0b001_00000_0_00_00000 ])
@@ -99,3 +114,23 @@ def testCls(self):
99
114
self .assertPioKwargs ("" , sideset_count = 0 , sideset_enable = False )
100
115
self .assertPioKwargs (".side_set 1" , sideset_count = 1 , sideset_enable = False )
101
116
self .assertPioKwargs (".side_set 3 opt" , sideset_count = 3 , sideset_enable = True )
117
+
118
+
119
+ class TestMov (AssembleChecks ):
120
+ def testMovNonHappy (self ):
121
+ # non happy path
122
+ self .assertAssemblyFails (
123
+ "mov x, blah" , match = "Invalid mov source 'blah'" , errtype = ValueError
124
+ )
125
+
126
+ def testMovInvert (self ):
127
+ # test moving and inverting
128
+ self .assertAssemblesTo ("mov x, ~ x" , [0b101_00000_001_01_001 ])
129
+ self .assertAssemblesTo ("mov x, ~ x" , [0b101_00000_001_01_001 ])
130
+ self .assertAssemblesTo ("mov x, ~x" , [0b101_00000_001_01_001 ])
131
+ self .assertAssemblesTo ("mov x, !x" , [0b101_00000_001_01_001 ])
132
+
133
+ def testMovReverse (self ):
134
+ # test moving and reversing bits
135
+ self .assertAssemblesTo ("mov x, :: x" , [0b101_00000_001_10_001 ])
136
+ self .assertAssemblesTo ("mov x, ::x" , [0b101_00000_001_10_001 ])
0 commit comments