8000 tests: Add a suite of tests specifically for the pyboard. · hellcoderz/micropython@41f768f · GitHub
[go: up one dir, main page]

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'

tests/pyb/led.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from pyb import LED
2+
3+
for i in range(4):
4+
print(LED(i+1))
5+
6+
for i in range(4):
7+
LED(i+1).on()
8+
pyb.delay(10)
9+
for i in range(4):
10+
LED(i+1).off()
11+
pyb.delay(10)
12+
for i in range(4):
13+
LED(i+1).toggle()
14+
pyb.delay(10)
15+
for i in range(4):
16+
LED(i+1).intensity(0)
17+
18+
for i in range(256):
19+
LED(4).intensity(i)
20+
if LED(4).intensity() != i:
21+
print('fail', i)
22+
pyb.delay(1)
23+
for i in range(256):
24+
LED(4).intensity(255 - i)
25+
pyb.delay(1)
26+
27+
for i in range(4):
28+
LED(i+1).off()

tests/pyb/led.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<LED 1>
2+
<LED 2>
3+
<LED 3>
4+
<LED 4>

tests/pyb/pin.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pyb import Pin
2+
3+
p = Pin('X1')
4+
print(p)
5+
print(p.name())
6+
print(p.pin())
7+
print(p.port())
8+
9+
p = Pin('X1', Pin.IN, Pin.PULL_UP)
10+
#p = Pin('X1', Pin.IN, pull=Pin.PULL_UP)
11+
print(p.value())
12+
13+
p.init(p.IN, p.PULL_DOWN)
14+
#p.init(p.IN, pull=p.PULL_DOWN)
15+
print(p.value())
16+
17+
p.init(p.OUT_PP)
18+
p.low()
19+
print(p.value())
20+
p.high()
21+
print(p.value())
22+
p.value(0)
23+
print(p.value())
24+
p.value(1)
25+
print(p.value())
26+
p.value(False)
27+
print(p.value())
28+
p.value(True)
29+
print(p.value())

tests/pyb/pin.py.exp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Pin A0>
2+
A0
3+
0
4+
0
5+
1
6+
0
7+
0
8+
1
9+
0
10+
1
11+
0
12+
1

tests/pyb/pyb1.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# basic tests of pyb module
2+
3+
import pyb
4+
5+
# test delay
6+
7+
pyb.delay(-1)
8+
pyb.delay(0)
9+
pyb.delay(1)
10+
11+
start = pyb.millis()
12+
pyb.delay(17)
13+
print((pyb.millis() - start) // 5) # should print 3
14+
15+
# test udelay
16+
17+
pyb.udelay(-1)
18+
pyb.udelay(0)
19+
pyb.udelay(1)
20+
21+
start = pyb.millis()
22+
pyb.udelay(17000)
23+
print((pyb.millis() - start) // 5) # should print 3
24+
25+
# other
26+
27+
pyb.disable_irq()
28+
pyb.enable_irq()
29+
30+
print(pyb.freq())
31+
32+
print(pyb.have_cdc())
33+
34+
pyb.hid((0, 0, 0, 0)) # won't do anything
35+
36+
pyb.rng()
37+
38+
pyb.sync()
39+
40+
print(len(pyb.unique_id()))
41+
42+
pyb.wfi()

tests/pyb/pyb1.py.exp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
3
3+
(168000000, 168000000, 42000000, 84000000)
4+
True
5+
12

tests/pyb/rtc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pyb import RTC
2+
rtc = RTC()
3+
print(rtc)
4+
rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
5+
pyb.delay(1000)
6+
print(rtc.datetime()[:7])

tests/pyb/rtc.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<RTC>
2+
(2014, 1, 1, 1, 0, 0, 1)

tests/pyb/servo.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pyb import Servo
2+
3+
servo = Servo(1)
4+
print(servo)
5+
6+
servo.angle(0)
7+
servo.angle(10, 100)
8+
9+
servo.speed(-10)
10+
servo.speed(10, 100)
11+
12+
servo.pulse_width(1500)
13+
print(servo.pulse_width())
14+
15+
servo.calibration(630, 2410, 1490, 2460, 2190)
16+
print(servo.calibration())

tests/pyb/servo.py.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Servo 1 at 1500us>
2+
1500
3+
(630, 2410, 1490, 2460, 2190)

tests/pyb/spi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pyb import SPI
2+
3+
spi = SPI(1)
4+
print(spi)
5+
6+
spi = SPI(1, SPI.MASTER)
7+
spi = SPI(1, SPI.MASTER, baudrate=500000)
8+
spi = SPI(1, SPI.MASTER, 500000, polarity=1, phase=1, bits=8, firstbit=SPI.MSB, ti=False, crc=None)
9+
print(spi)
10+
11+
spi.init(SPI.SLAVE)
12+
print(spi)
13+
14+
spi.init(SPI.MASTER)
15+
spi.send(1, timeout=100)
16+
print(spi.recv(1, timeout=100))
17+
print(spi.send_recv(1, timeout=100))

tests/pyb/spi.py.exp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SPI(1)
2+
SPI(1, SPI.MASTER, baudrate=328125, polarity=1, phase=1, bits=8)
3+
SPI(1, SPI.SLAVE, polarity=1, phase=1, bits=8)
4+
b'\xff'
5+
b'\xff'

tests/pyb/switch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pyb import Switch
2+
3+
sw = pyb.Switch()
4+
print(sw())
5+
sw.callback(print)
6+
sw.callback(None)

tests/pyb/switch.py.exp

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

tests/pyb/timer.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from pyb import Timer
2+
3+
tim = Timer(4)
4+
tim = Timer(4, prescaler=100, period=200)
5+
print(tim.prescaler())
6+
print(tim.period())
7+
tim.prescaler(300)
8+
print(tim.prescaler())
9+
tim.period(400)
10+
print(tim.period())
11+
12+
tim = Timer(4, freq=1)
13+
tim.init(freq=2000)
14+
def f(t):
15+
print(1)
16+
t.callback(None)
17+
tim.callback(f)
18+
pyb.delay(10)
19+
20+
# f3 closes over f2.y
21+
def f2(x):
22+
y = x
23+
def f3(t):
24+
print(2, y)
25+
t.callback(None)
26+
return f3
27+
tim.callback(f2(3))
28+
pyb.delay(10)

tests/pyb/timer.py.exp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
100
2+
200
3+
300
4+
400
5+
1
6+
2 3

tests/pyb/uart.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pyb import UART
2+
3+
uart = UART(1)
4+
uart = UART(1, 9600)
5+
uart = UART(1, 9600, bits=8, stop=1, parity=None)
6+
print(uart)
7+
8+
uart.init(1200)
9+
print(uart)
10+
11+
uart.any()
12+
uart.send(1, timeout=500)

tests/pyb/uart.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UART(1, baudrate=9600, bits=8, stop=1, parity=None)
2+
UART(1, baudrate=1200, bits=8, stop=1, parity=None)

tests/pyboard.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../tools/pyboard.py

0 commit comments

Comments
 (0)
0