Skip to content

Commit 41f768f

Browse files
committed
tests: Add a suite of tests specifically for the pyboard.
In tests/pyb is now a suite of tests that tests the pyb module on the pyboard. They include expected output files because we can't run CPython on the pyboard to compare against. run-tests script has now been updated to allow pyboard tests to be run. Just pass the option --pyboard. This runs all basic, float and pyb tests. Note that float/math-fun.py currently fails because not all math functions are implemented in stmhal/.
1 parent baa2afb commit 41f768f

30 files changed

+390
-70
lines changed

tests/pyb/accel.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
accel = pyb.Accel()
2+
print(accel)
3+
accel.x()
4+
accel.y()
5+
accel.z()
6+
accel.tilt()
7+
accel.filtered_xyz()

tests/pyb/accel.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Accel>

tests/pyb/adc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pyb import ADC
2+
from pyb import Pin
3+
4+
adc = ADC('X22')
5+
print(adc)
6+
7+
adc.read()
8+
9+
buf = bytearray(100)
10+
adc.read_timed(buf, 500)

tests/pyb/adc.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ADC on X22 channel=13>

tests/pyb/dac.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dac = pyb.DAC(1)
2+
print(dac)
3+
dac.noise(100)
4+
dac.triangle(100)
5+
dac.write(0)
6+
dac.write_timed(bytearray(10), 100, mode=pyb.DAC.NORMAL)
7+
pyb.delay(20)
8+
dac.write(0)

tests/pyb/dac.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<DAC>

tests/pyb/extint.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ext = pyb.ExtInt('X1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
2+
ext.disable()
3+
ext.enable()
4+
print(ext.line())
5+
ext.swint()
6+
ext.disable()

tests/pyb/extint.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0
2+
line: 0

tests/pyb/i2c.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from pyb import I2C
2+
3+
i2c = I2C(1)
4+
i2c2 = I2C(2)
5+
6+
i2c.init(I2C.MASTER, baudrate=400000)
7+
print(i2c.scan())
8+
i2c.deinit()
9+
10+
# use accelerometer to test i2c bus
11+
12+
accel_addr = 76
13+
14+
pyb.Accel() # this will init the bus for us
15+
16+
print(i2c.scan())
17+
print(i2c.is_ready(accel_addr))
18+
19+
print(i2c.mem_read(1, accel_addr, 7, timeout=500))
20+
i2c.mem_write(0, accel_addr, 0, timeout=500)
21+
22+
i2c.send(7, addr=accel_addr)
23+
i2c.recv(1, addr=accel_addr)

tests/pyb/i2c.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[]
2+
[76]
3+
True
4+
b'\x01'

0 commit comments

Comments
 (0)