summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorHenrik Sölver <henrik.solver@gmail.com>2014-10-30 23:13:26 +0100
committerDamien George <damien.p.george@gmail.com>2014-10-30 23:16:01 +0000
commit6a15ac80dcc41dd950a9177b044ff8876d59710b (patch)
tree1c104f747a70d7cb036ff7c8e53237c41b5b02f0
parent504636815e764ade9a725ba2067ddffbf170b76d (diff)
downloadmicropython-6a15ac80dcc41dd950a9177b044ff8876d59710b.tar.gz
micropython-6a15ac80dcc41dd950a9177b044ff8876d59710b.zip
tests: Added and adapted CAN tests for extended messages
-rw-r--r--tests/pyb/can.py37
-rw-r--r--tests/pyb/can.py.exp8
2 files changed, 42 insertions, 3 deletions
diff --git a/tests/pyb/can.py b/tests/pyb/can.py
index e116955682..931578bc53 100644
--- a/tests/pyb/can.py
+++ b/tests/pyb/can.py
@@ -1,9 +1,42 @@
from pyb import CAN
-can = CAN(1)
+can = CAN(1, CAN.LOOPBACK)
print(can)
-can.init(CAN.LOOPBACK)
print(can.any(0))
can.send('abcd', 123)
print(can.any(0))
print(can.recv(0))
+
+can.send('abcd', -1)
+print(can.recv(0))
+
+can.send('abcd', 0x7FF + 1)
+print(can.recv(0))
+
+#Test too long message
+try:
+ can.send('abcdefghi', 0x7FF)
+except ValueError:
+ print('passed')
+else:
+ print('failed')
+
+del can
+
+#Testing extended IDs
+can = CAN(1, CAN.LOOPBACK, extframe = True)
+print(can)
+
+try:
+ can.send('abcde', 0x7FF + 1)
+except ValueError:
+ print('failed')
+else:
+ r = can.recv(0)
+ if r[0] == 0x7FF+1 and r[3] == b'abcde':
+ print('passed')
+ else:
+ print('failed, wrong data received')
+
+
+print('end') \ No newline at end of file
diff --git a/tests/pyb/can.py.exp b/tests/pyb/can.py.exp
index e5c420dd06..d12643a5fb 100644
--- a/tests/pyb/can.py.exp
+++ b/tests/pyb/can.py.exp
@@ -1,4 +1,10 @@
-CAN(1)
+CAN(1, LOOPBACK, False)
False
True
(123, 0, 0, b'abcd')
+(2047, 0, 0, b'abcd')
+(0, 0, 0, b'abcd')
+passed
+CAN(1, LOOPBACK, True)
+passed
+end