@@ -18,7 +18,7 @@ def nice_opcode(o):
1818 return o [:3 ] + "_" + o [3 :8 ] + "_" + o [8 :]
1919
2020
21- class TestNop (unittest .TestCase ):
21+ class AssembleChecks (unittest .TestCase ):
2222 def assertAssemblesTo (self , source , expected ):
2323 actual = adafruit_pioasm .assemble (source )
2424 expected_bin = [nice_opcode (x ) for x in expected ]
@@ -29,13 +29,18 @@ def assertAssemblesTo(self, source, expected):
2929 f"Assembling { source !r} : Expected { expected_bin } , got { actual_bin } " ,
3030 )
3131
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 )
3437
3538 def assertPioKwargs (self , source , ** kw ):
3639 program = adafruit_pioasm .Program (source )
3740 self .assertEqual (kw , program .pio_kwargs )
3841
42+
43+ class TestNop (AssembleChecks ):
3944 def testNonsense (self ):
4045 self .assertAssemblyFails ("nope" )
4146
@@ -64,6 +69,12 @@ def testSidesetOpt(self):
6469 ".side_set 1 opt\n nop side 0 [7]" , [0b101_10111_010_00_010 ]
6570 )
6671
72+ def testSet (self ):
73+ # non happy path
74+ self .assertAssemblyFails (
75+ "set isr, 1" , match = "Invalid set destination 'isr'" , errtype = ValueError
76+ )
77+
6778 def testJmp (self ):
6879 self .assertAssemblesTo ("l:\n jmp l" , [0b000_00000_000_00000 ])
6980 self .assertAssemblesTo ("l:\n jmp 7" , [0b000_00000_000_00111 ])
@@ -75,6 +86,10 @@ def testJmp(self):
7586 self .assertAssemblesTo ("jmp x!=y, l\n l:" , [0b000_00000_101_00001 ])
7687 self .assertAssemblesTo ("jmp pin, l\n l:" , [0b000_00000_110_00001 ])
7788 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+ )
7893
7994 def testWait (self ):
8095 self .assertAssemblesTo ("wait 0 gpio 0" , [0b001_00000_0_00_00000 ])
@@ -99,3 +114,23 @@ def testCls(self):
99114 self .assertPioKwargs ("" , sideset_count = 0 , sideset_enable = False )
100115 self .assertPioKwargs (".side_set 1" , sideset_count = 1 , sideset_enable = False )
101116 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