summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/pyb/halerror.py15
-rw-r--r--tests/pyb/i2c.py32
-rw-r--r--tests/pyb/i2c.py.exp12
-rw-r--r--tests/pyb/i2c_error.py50
-rw-r--r--tests/pyb/spi.py33
-rw-r--r--tests/pyb/spi.py.exp14
-rwxr-xr-xtests/run-tests20
-rw-r--r--tests/wipy/i2c.py175
-rw-r--r--tests/wipy/i2c.py.exp51
-rw-r--r--tests/wipy/spi.py147
-rw-r--r--tests/wipy/spi.py.exp35
11 files changed, 12 insertions, 572 deletions
diff --git a/tests/pyb/halerror.py b/tests/pyb/halerror.py
deleted file mode 100644
index 1a6bce1a7..000000000
--- a/tests/pyb/halerror.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# test hal errors
-
-import pyb
-
-i2c = pyb.I2C(2, pyb.I2C.MASTER)
-try:
- i2c.recv(1, 1)
-except OSError as e:
- print(repr(e))
-
-can = pyb.CAN(1, pyb.CAN.NORMAL)
-try:
- can.send('1', 1, timeout=50)
-except OSError as e:
- print(repr(e))
diff --git a/tests/pyb/i2c.py b/tests/pyb/i2c.py
deleted file mode 100644
index 6875e5a5a..000000000
--- a/tests/pyb/i2c.py
+++ /dev/null
@@ -1,32 +0,0 @@
-import pyb
-from pyb import I2C
-
-# test we can correctly create by id or name
-for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
- try:
- I2C(bus)
- print("I2C", bus)
- except ValueError:
- print("ValueError", bus)
-
-i2c = I2C(1)
-
-i2c.init(I2C.MASTER, baudrate=400000)
-print(i2c.scan())
-i2c.deinit()
-
-# use accelerometer to test i2c bus
-
-accel_addr = 76
-
-pyb.Accel() # this will init the MMA for us
-i2c.init(I2C.MASTER, baudrate=400000)
-
-print(i2c.scan())
-print(i2c.is_ready(accel_addr))
-
-print(i2c.mem_read(1, accel_addr, 7, timeout=500))
-i2c.mem_write(0, accel_addr, 0, timeout=500)
-
-i2c.send(7, addr=accel_addr)
-i2c.recv(1, addr=accel_addr)
diff --git a/tests/pyb/i2c.py.exp b/tests/pyb/i2c.py.exp
deleted file mode 100644
index 709fb412d..000000000
--- a/tests/pyb/i2c.py.exp
+++ /dev/null
@@ -1,12 +0,0 @@
-ValueError -1
-ValueError 0
-I2C 1
-I2C 2
-ValueError 3
-I2C X
-I2C Y
-ValueError Z
-[]
-[76]
-True
-b'\x01'
diff --git a/tests/pyb/i2c_error.py b/tests/pyb/i2c_error.py
deleted file mode 100644
index 3201d6367..000000000
--- a/tests/pyb/i2c_error.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# test I2C errors, with polling (disabled irqs) and DMA
-
-import pyb
-from pyb import I2C
-
-# init accelerometer
-pyb.Accel()
-
-# get I2C bus
-i2c = I2C(1, I2C.MASTER, dma=True)
-
-# test polling mem_read
-pyb.disable_irq()
-i2c.mem_read(1, 76, 0x0a) # should succeed
-pyb.enable_irq()
-try:
- pyb.disable_irq()
- i2c.mem_read(1, 77, 0x0a) # should fail
-except OSError as e:
- pyb.enable_irq()
- print(repr(e))
-i2c.mem_read(1, 76, 0x0a) # should succeed
-
-# test polling mem_write
-pyb.disable_irq()
-i2c.mem_write(1, 76, 0x0a) # should succeed
-pyb.enable_irq()
-try:
- pyb.disable_irq()
- i2c.mem_write(1, 77, 0x0a) # should fail
-except OSError as e:
- pyb.enable_irq()
- print(repr(e))
-i2c.mem_write(1, 76, 0x0a) # should succeed
-
-# test DMA mem_read
-i2c.mem_read(1, 76, 0x0a) # should succeed
-try:
- i2c.mem_read(1, 77, 0x0a) # should fail
-except OSError as e:
- print(repr(e))
-i2c.mem_read(1, 76, 0x0a) # should succeed
-
-# test DMA mem_write
-i2c.mem_write(1, 76, 0x0a) # should succeed
-try:
- i2c.mem_write(1, 77, 0x0a) # should fail
-except OSError as e:
- print(repr(e))
-i2c.mem_write(1, 76, 0x0a) # should succeed
diff --git a/tests/pyb/spi.py b/tests/pyb/spi.py
deleted file mode 100644
index 88cc975bb..000000000
--- a/tests/pyb/spi.py
+++ /dev/null
@@ -1,33 +0,0 @@
-from pyb import SPI
-
-# test we can correctly create by id or name
-for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
- try:
- SPI(bus)
- print("SPI", bus)
- except ValueError:
- print("ValueError", bus)
-
-spi = SPI(1)
-print(spi)
-
-spi = SPI(1, SPI.MASTER)
-spi = SPI(1, SPI.MASTER, baudrate=500000)
-spi = SPI(1, SPI.MASTER, 500000, polarity=1, phase=0, bits=8, firstbit=SPI.MSB, ti=False, crc=None)
-print(spi)
-
-spi.init(SPI.SLAVE, phase=1)
-print(spi)
-try:
- # need to flush input before we get an error (error is what we want to test)
- for i in range(10):
- spi.recv(1, timeout=100)
-except OSError:
- print("OSError")
-
-spi.init(SPI.MASTER)
-spi.send(1, timeout=100)
-print(spi.recv(1, timeout=100))
-print(spi.send_recv(1, timeout=100))
-
-spi.deinit()
diff --git a/tests/pyb/spi.py.exp b/tests/pyb/spi.py.exp
deleted file mode 100644
index a0d835700..000000000
--- a/tests/pyb/spi.py.exp
+++ /dev/null
@@ -1,14 +0,0 @@
-ValueError -1
-ValueError 0
-SPI 1
-SPI 2
-ValueError 3
-SPI X
-SPI Y
-ValueError Z
-SPI(1)
-SPI(1, SPI.MASTER, baudrate=328125, prescaler=256, polarity=1, phase=0, bits=8)
-SPI(1, SPI.SLAVE, polarity=1, phase=1, bits=8)
-OSError
-b'\xff'
-b'\xff'
diff --git a/tests/run-tests b/tests/run-tests
index 6e980f03c..151d48095 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -87,28 +87,32 @@ def run_micropython(pyb, args, test_file, is_special=False):
def get(required=False):
rv = b''
while True:
- ready = select.select([master], [], [], 0.02)
- if ready[0] == [master]:
- rv += os.read(master, 1024)
+ ready = select.select([emulator], [], [], 0.02)
+ if ready[0] == [emulator]:
+ rv += os.read(emulator, 1024)
else:
if not required or rv:
return rv
def send_get(what):
- os.write(master, what)
+ os.write(emulator, what)
return get()
with open(test_file, 'rb') as f:
# instead of: output_mupy = subprocess.check_output(args, stdin=f)
- master, slave = pty.openpty()
- p = subprocess.Popen(args, stdin=slave, stdout=slave,
+ # openpty returns two read/write file descriptors. The first one is
+ # used by the program which provides the virtual
+ # terminal service, and the second one is used by the
+ # subprogram which requires a tty to work.
+ emulator, subterminal = pty.openpty()
+ p = subprocess.Popen(args, stdin=subterminal, stdout=subterminal,
stderr=subprocess.STDOUT, bufsize=0)
banner = get(True)
output_mupy = banner + b''.join(send_get(line) for line in f)
send_get(b'\x04') # exit the REPL, so coverage info is saved
p.kill()
- os.close(master)
- os.close(slave)
+ os.close(emulator)
+ os.close(subterminal)
else:
output_mupy = subprocess.check_output(args + [test_file], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
diff --git a/tests/wipy/i2c.py b/tests/wipy/i2c.py
deleted file mode 100644
index 39dcdc722..000000000
--- a/tests/wipy/i2c.py
+++ /dev/null
@@ -1,175 +0,0 @@
-'''
-I2C test for the CC3200 based boards.
-A MPU-9150 sensor must be connected to the I2C bus.
-'''
-
-from machine import I2C
-import os
-import time
-
-mch = os.uname().machine
-if 'LaunchPad' in mch:
- i2c_pins = ('GP11', 'GP10')
-elif 'WiPy' in mch:
- i2c_pins = ('GP15', 'GP10')
-else:
- raise Exception('Board not supported!')
-
-i2c = I2C(0, I2C.MASTER, baudrate=400000)
-# try initing without the peripheral id
-i2c = I2C()
-print(i2c)
-i2c = I2C(mode=I2C.MASTER, baudrate=50000, pins=i2c_pins)
-print(i2c)
-
-i2c = I2C(0, I2C.MASTER, baudrate=100000)
-print(i2c)
-i2c = I2C(0, mode=I2C.MASTER, baudrate=400000)
-print(i2c)
-i2c = I2C(0, mode=I2C.MASTER, baudrate=400000, pins=i2c_pins)
-print(i2c)
-
-addr = i2c.scan()[0]
-print(addr)
-
-reg = bytearray(1)
-reg2 = bytearray(2)
-reg2_r = bytearray(2)
-
-# reset the sensor
-reg[0] |= 0x80
-print(1 == i2c.writeto_mem(addr, 107, reg))
-time.sleep_ms(100) # wait for the sensor to reset...
-
-print(1 == i2c.readfrom_mem_into(addr, 107, reg)) # read the power management register 1
-print(0x40 == reg[0])
-
-# now just read one byte
-data = i2c.readfrom_mem(addr, 117, 1) # read the "who am I?" register
-print(0x68 == data[0])
-print(len(data) == 1)
-print(1 == i2c.readfrom_mem_into(addr, 117, reg)) # read the "who am I?" register again
-print(0x68 == reg[0])
-
-# now try reading two bytes
-data = i2c.readfrom_mem(addr, 116, 2) # read the "who am I?" register
-print(0x68 == data[1])
-print(data == b'\x00\x68')
-print(len(data) == 2)
-print(2 == i2c.readfrom_mem_into(addr, 116, reg2)) # read the "who am I?" register again
-print(0x68 == reg2[1])
-print(reg2 == b'\x00\x68')
-
-print(1 == i2c.readfrom_mem_into(addr, 107, reg)) # read the power management register 1
-print(0x40 == reg[0])
-# clear the sleep bit
-reg[0] = 0
-print(1 == i2c.writeto_mem(addr, 107, reg))
-# read it back
-i2c.readfrom_mem_into(addr, 107, reg)
-print(0 == reg[0])
-
-# set the sleep bit
-reg[0] = 0x40
-print(1 == i2c.writeto_mem(addr, 107, reg))
-# read it back
-i2c.readfrom_mem_into(addr, 107, reg)
-print(0x40 == reg[0])
-
-# reset the sensor
-reg[0] |= 0x80
-print(1 == i2c.writeto_mem(addr, 107, reg))
-time.sleep_ms(100) # wait for the sensor to reset...
-
-# now read and write two register at a time
-print(2 == i2c.readfrom_mem_into(addr, 107, reg2))
-print(0x40 == reg2[0])
-print(0x00 == reg2[1])
-# clear the sleep bit
-reg2[0] = 0
-# set some other bits
-reg2[1] |= 0x03
-print(2 == i2c.writeto_mem(addr, 107, reg2))
-# read it back
-i2c.readfrom_mem_into(addr, 107, reg2_r)
-print(reg2 == reg2_r)
-
-# reset the sensor
-reg[0] = 0x80
-print(1 == i2c.writeto_mem(addr, 107, reg))
-time.sleep_ms(100) # wait for the sensor to reset...
-
-# try some raw read and writes
-reg[0] = 117 # register address
-print(1 == i2c.writeto(addr, reg, stop=False)) # just write the register address
-# now read
-print(1 == i2c.readfrom_into(addr, reg))
-print(reg[0] == 0x68)
-reg[0] = 117 # register address
-print(1 == i2c.writeto(addr, reg, stop=False)) # just write the register address
-# now read
-print(0x68 == i2c.readfrom(addr, 1)[0])
-
-i2c.readfrom_mem_into(addr, 107, reg2)
-print(0x40 == reg2[0])
-print(0x00 == reg2[1])
-
-reg2[0] = 107 # register address
-reg2[1] = 0
-print(2 == i2c.writeto(addr, reg2, stop=True)) # write the register address and the data
-i2c.readfrom_mem_into(addr, 107, reg) # check it back
-print(reg[0] == 0)
-
-# check for memory leaks...
-for i in range (0, 1000):
- i2c = I2C(0, I2C.MASTER, baudrate=100000)
-
-# test deinit
-i2c = I2C(0, I2C.MASTER, baudrate=100000)
-i2c.deinit()
-print(i2c)
-
-# next ones should raise
-try:
- i2c.scan()
-except Exception:
- print("Exception")
-
-try:
- i2c.readfrom(addr, 1)
-except Exception:
- print("Exception")
-
-try:
- i2c.readfrom_into(addr, reg)
-except Exception:
- print("Exception")
-
-try:
- i2c.readfrom_mem_into(addr, 107, reg)
-except Exception:
- print("Exception")
-
-try:
- i2c.writeto(addr, reg, stop=False)
-except Exception:
- print("Exception")
-
-try:
- i2c.writeto_mem(addr, 107, reg)
-except Exception:
- print("Exception")
-
-try:
- i2c.readfrom_mem(addr, 116, 2)
-except Exception:
- print("Exception")
-
-try:
- I2C(1, I2C.MASTER, baudrate=100000)
-except Exception:
- print("Exception")
-
-# reinitialization must work
-i2c.init(baudrate=400000)
-print(i2c)
diff --git a/tests/wipy/i2c.py.exp b/tests/wipy/i2c.py.exp
deleted file mode 100644
index 083da9be7..000000000
--- a/tests/wipy/i2c.py.exp
+++ /dev/null
@@ -1,51 +0,0 @@
-I2C(0, I2C.MASTER, baudrate=100000)
-I2C(0, I2C.MASTER, baudrate=50000)
-I2C(0, I2C.MASTER, baudrate=100000)
-I2C(0, I2C.MASTER, baudrate=400000)
-I2C(0, I2C.MASTER, baudrate=400000)
-104
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-I2C(0)
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-I2C(0, I2C.MASTER, baudrate=400000)
diff --git a/tests/wipy/spi.py b/tests/wipy/spi.py
deleted file mode 100644
index 6bd7aabce..000000000
--- a/tests/wipy/spi.py
+++ /dev/null
@@ -1,147 +0,0 @@
-'''
-SPI test for the CC3200 based boards.
-'''
-
-from machine import SPI
-import os
-
-mch = os.uname().machine
-if 'LaunchPad' in mch:
- spi_pins = ('GP14', 'GP16', 'GP30')
-elif 'WiPy' in mch:
- spi_pins = ('GP14', 'GP16', 'GP30')
-else:
- raise Exception('Board not supported!')
-
-spi = SPI(0, SPI.MASTER, baudrate=2000000, polarity=0, phase=0, firstbit=SPI.MSB, pins=spi_pins)
-print(spi)
-spi = SPI(baudrate=5000000)
-print(spi)
-spi = SPI(0, SPI.MASTER, baudrate=200000, bits=16, polarity=0, phase=0)
-print(spi)
-spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=0, phase=1)
-print(spi)
-spi = SPI(0, SPI.MASTER, baudrate=5000000, bits=32, polarity=1, phase=0)
-print(spi)
-spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=1, phase=1)
-print(spi)
-spi.init(baudrate=20000000, polarity=0, phase=0)
-print(spi)
-spi=SPI()
-print(spi)
-SPI(mode=SPI.MASTER)
-SPI(mode=SPI.MASTER, pins=spi_pins)
-SPI(id=0, mode=SPI.MASTER, polarity=0, phase=0, pins=('GP14', 'GP16', 'GP15'))
-SPI(0, SPI.MASTER, polarity=0, phase=0, pins=('GP31', 'GP16', 'GP15'))
-
-spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=0, phase=0, pins=spi_pins)
-print(spi.write('123456') == 6)
-buffer_r = bytearray(10)
-print(spi.readinto(buffer_r) == 10)
-print(spi.readinto(buffer_r, write=0x55) == 10)
-read = spi.read(10)
-print(len(read) == 10)
-read = spi.read(10, write=0xFF)
-print(len(read) == 10)
-buffer_w = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
-print(spi.write_readinto(buffer_w, buffer_r) == 10)
-print(buffer_w == buffer_r)
-
-# test all polaritiy and phase combinations
-spi.init(polarity=1, phase=0, pins=None)
-buffer_r = bytearray(10)
-spi.write_readinto(buffer_w, buffer_r)
-print(buffer_w == buffer_r)
-
-spi.init(polarity=1, phase=1, pins=None)
-buffer_r = bytearray(10)
-spi.write_readinto(buffer_w, buffer_r)
-print(buffer_w == buffer_r)
-
-spi.init(polarity=0, phase=1, pins=None)
-buffer_r = bytearray(10)
-spi.write_readinto(buffer_w, buffer_r)
-print(buffer_w == buffer_r)
-
-# test 16 and 32 bit transfers
-buffer_w = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2])
-buffer_r = bytearray(12)
-spi.init(SPI.MASTER, baudrate=10000000, bits=16, polarity=0, phase=0, pins=None)
-print(spi.write_readinto(buffer_w, buffer_r) == 12)
-print(buffer_w == buffer_r)
-
-buffer_r = bytearray(12)
-spi.init(SPI.MASTER, baudrate=10000000, bits=32, polarity=0, phase=0, pins=None)
-print(spi.write_readinto(buffer_w, buffer_r) == 12)
-print(buffer_w == buffer_r)
-
-# check for memory leaks...
-for i in range (0, 1000):
- spi = SPI(0, SPI.MASTER, baudrate=1000000)
-
-# test deinit
-spi = SPI(0, SPI.MASTER, baudrate=1000000)
-spi.deinit()
-print(spi)
-
-spi = SPI(0, SPI.MASTER, baudrate=1000000)
-# next ones must fail
-try:
- spi = SPI(0, 10, baudrate=10000000, polarity=0, phase=0)
-except:
- print("Exception")
-
-try:
- spi = SPI(0, mode=SPI.MASTER, baudrate=10000000, polarity=1, phase=2)
-except:
- print("Exception")
-
-try:
- spi = SPI(1, mode=SPI.MASTER, baudrate=10000000, polarity=1, phase=1)
-except:
- print("Exception")
-
-try:
- spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0)
-except:
- print("Exception")
-
-try:
- spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0, firstbit=2)
-except:
- print("Exception")
-
-try:
- spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0, pins=('GP1', 'GP2'))
-except:
- print("Exception")
-
-try:
- spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=0, phase=0, bits=9)
-except:
- print("Exception")
-
-spi.deinit()
-try:
- spi.read(15)
-except Exception:
- print("Exception")
-
-try:
- spi.spi.readinto(buffer_r)
-except Exception:
- print("Exception")
-
-try:
- spi.spi.write('abc')
-except Exception:
- print("Exception")
-
-try:
- spi.write_readinto(buffer_w, buffer_r)
-except Exception:
- print("Exception")
-
-# reinitialization must work
-spi.init(baudrate=500000)
-print(spi)
diff --git a/tests/wipy/spi.py.exp b/tests/wipy/spi.py.exp
deleted file mode 100644
index cc4ff4022..000000000
--- a/tests/wipy/spi.py.exp
+++ /dev/null
@@ -1,35 +0,0 @@
-SPI(0, SPI.MASTER, baudrate=2000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
-SPI(0, SPI.MASTER, baudrate=5000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
-SPI(0, SPI.MASTER, baudrate=200000, bits=16, polarity=0, phase=0, firstbit=SPI.MSB)
-SPI(0, SPI.MASTER, baudrate=10000000, bits=8, polarity=0, phase=1, firstbit=SPI.MSB)
-SPI(0, SPI.MASTER, baudrate=5000000, bits=32, polarity=1, phase=0, firstbit=SPI.MSB)
-SPI(0, SPI.MASTER, baudrate=10000000, bits=8, polarity=1, phase=1, firstbit=SPI.MSB)
-SPI(0, SPI.MASTER, baudrate=20000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
-SPI(0, SPI.MASTER, baudrate=1000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-True
-SPI(0)
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-Exception
-SPI(0, SPI.MASTER, baudrate=500000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)