diff options
Diffstat (limited to 'tests/wipy')
-rw-r--r-- | tests/wipy/i2c.py | 8 | ||||
-rw-r--r-- | tests/wipy/os.py | 155 | ||||
-rw-r--r-- | tests/wipy/os.py.exp | 30 | ||||
-rw-r--r-- | tests/wipy/rtc.py | 100 | ||||
-rw-r--r-- | tests/wipy/rtc.py.exp | 34 | ||||
-rw-r--r-- | tests/wipy/sd.py | 46 | ||||
-rw-r--r-- | tests/wipy/sd.py.exp | 6 | ||||
-rw-r--r-- | tests/wipy/time.py | 78 | ||||
-rw-r--r-- | tests/wipy/time.py.exp | 65 | ||||
-rw-r--r-- | tests/wipy/uart.py | 3 | ||||
-rw-r--r-- | tests/wipy/wdt.py | 7 |
11 files changed, 524 insertions, 8 deletions
diff --git a/tests/wipy/i2c.py b/tests/wipy/i2c.py index 24afc5a082..b5f2a610d7 100644 --- a/tests/wipy/i2c.py +++ b/tests/wipy/i2c.py @@ -5,7 +5,7 @@ A MPU-9150 sensor must be connected to the I2C bus. from pyb import I2C import os -import pyb +import time machine = os.uname().machine if 'LaunchPad' in machine: @@ -39,7 +39,7 @@ reg2_r = bytearray(2) # reset the sensor reg[0] |= 0x80 print(1 == i2c.writeto_mem(addr, 107, reg)) -pyb.delay(100) # wait for the sensor to reset... +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]) @@ -79,7 +79,7 @@ print(0x40 == reg[0]) # reset the sensor reg[0] |= 0x80 print(1 == i2c.writeto_mem(addr, 107, reg)) -pyb.delay(100) # wait for the sensor to reset... +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)) @@ -97,7 +97,7 @@ print(reg2 == reg2_r) # reset the sensor reg[0] = 0x80 print(1 == i2c.writeto_mem(addr, 107, reg)) -pyb.delay(100) # wait for the sensor to reset... +time.sleep_ms(100) # wait for the sensor to reset... # try some raw read and writes reg[0] = 117 # register address diff --git a/tests/wipy/os.py b/tests/wipy/os.py new file mode 100644 index 0000000000..796d4699ef --- /dev/null +++ b/tests/wipy/os.py @@ -0,0 +1,155 @@ +''' +os module test for the CC3200 based boards +''' + +from pyb import SD +import pyb +import os + +machine = os.uname().machine +if 'LaunchPad' in machine: + sd_pins = ('GP16', 'GP17', 'GP15') +elif 'WiPy' in machine: + sd_pins = ('GP10', 'GP11', 'GP15') +else: + raise Exception('Board not supported!') + +sd = SD(pins=sd_pins) + +os.mount(sd, '/sd') +os.mkfs('/sd') +os.chdir('/flash') +print(os.listdir()) + +os.chdir('/sd') +print(os.listdir()) + +# create a test directory in flash +os.mkdir('/flash/test') +os.chdir('/flash/test') +print(os.getcwd()) +os.chdir('..') +print(os.getcwd()) +os.chdir('test') +print(os.getcwd()) +# create a new file +f = open('test.txt', 'w') +test_bytes = os.urandom(1024) +n_w = f.write(test_bytes) +print(n_w == len(test_bytes)) +f.close() +f = open('test.txt', 'r') +r = bytes(f.readall(), 'ascii') +# check that we can write and read it correctly +print(r == test_bytes) +f.close() +os.rename('test.txt', 'newtest.txt') +print(os.listdir()) +os.rename('/flash/test', '/flash/newtest') +print(os.listdir('/flash')) +os.remove('newtest.txt') +os.chdir('..') +os.rmdir('newtest') + +# create a test directory in the sd card +os.mkdir('/sd/test') +os.chdir('/sd/test') +print(os.getcwd()) +os.chdir('..') +print(os.getcwd()) +os.chdir('test') +print(os.getcwd()) +# create a new file +f = open('test.txt', 'w') +test_bytes = os.urandom(1024) +n_w = f.write(test_bytes) +print(n_w == len(test_bytes)) +f.close() +f = open('test.txt', 'r') +r = bytes(f.readall(), 'ascii') +# check that we can write and read it correctly +print(r == test_bytes) +f.close() + +print('CC3200' in os.uname().machine) +print('WiPy' == os.uname().sysname) + +os.sync() +os.stat('/flash') +os.stat('/flash/sys') +os.stat('/flash/boot.py') +os.stat('/sd') +os.stat('/') +os.chdir('/sd/test') +os.remove('test.txt') +os.chdir('/sd') +os.rmdir('test') +os.listdir('/sd') +print(os.listdir('/')) +os.unmount('/sd') +print(os.listdir('/')) +os.mkfs(sd) +os.mount(sd, '/sd') +print(os.listdir('/')) +os.chdir('/flash') + +# next ones must raise +sd.deinit() +try: + os.listdir('/sd') +except: + print('Exception') + +#re-initialization must work +sd.init() +print(os.listdir('/sd')) + +try: + os.mount(sd, '/sd') +except: + print('Exception') + +try: + os.mount(sd, '/sd2') +except: + print('Exception') + +os.unmount('/sd') +try: + os.listdir('/sd') +except: + print('Exception') + +try: + os.unmount('/flash') +except: + print('Exception') + +try: + os.mkfs('flash') # incorrect path format +except: + print('Exception') + +try: + os.remove('/flash/nofile.txt') +except: + print('Exception') + +try: + os.rename('/flash/nofile.txt', '/flash/nofile2.txt') +except: + print('Exception') + +try: + os.chdir('/flash/nodir') +except: + print('Exception') + +try: + os.listdir('/flash/nodir') +except: + print('Exception') + +os.mount(sd, '/sd') +print(os.listdir('/')) +os.unmount('/sd') diff --git a/tests/wipy/os.py.exp b/tests/wipy/os.py.exp new file mode 100644 index 0000000000..55a0879aad --- /dev/null +++ b/tests/wipy/os.py.exp @@ -0,0 +1,30 @@ +['main.py', 'sys', 'lib', 'cert', 'boot.py'] +[] +/flash/test +/flash +/flash/test +True +True +['newtest.txt'] +['main.py', 'sys', 'lib', 'cert', 'boot.py', 'newtest'] +/sd/test +/sd +/sd/test +True +True +True +True +['flash', 'sd'] +['flash'] +['flash', 'sd'] +[] +Exception +Exception +Exception +Exception +Exception +Exception +Exception +Exception +Exception +['flash', 'sd'] diff --git a/tests/wipy/rtc.py b/tests/wipy/rtc.py new file mode 100644 index 0000000000..4114796db1 --- /dev/null +++ b/tests/wipy/rtc.py @@ -0,0 +1,100 @@ +''' +RTC test for the CC3200 based boards. +''' + +from pyb import RTC +import os +import time + +machine = os.uname().machine +if not 'LaunchPad' in machine and not 'WiPy' in machine: + raise Exception('Board not supported!') + +rtc = RTC() +print(rtc) +print(rtc.now()[:6]) + +rtc = RTC(datetime=(2015, 8, 29, 9, 0, 0, 0, None)) +print(rtc.now()[:6]) + +rtc.deinit() +print(rtc.now()[:6]) + +rtc.init((2015, 8, 29, 9, 0, 0, 0, None)) +print(rtc.now()[:6]) +seconds = rtc.now()[5] +time.sleep_ms(1000) +print(rtc.now()[5] - seconds == 1) +seconds = rtc.now()[5] +time.sleep_ms(2000) +print(rtc.now()[5] - seconds == 2) + +# initialization with shorter tuples +rtc.init((2015, 9, 19, 8, 0, 0, 0)) +print(rtc.now()[5]) +rtc.init((2015, 9, 19, 8, 0, 0)) +print(rtc.now()[5]) +rtc.init((2015, 9, 19, 8, 0)) +print(rtc.now()[5]) +rtc.init((2015, 9, 19, 8)) +print(rtc.now()[4]) +rtc.init((2015, 9, 19)) +print(rtc.now()[3]) + +def set_and_print(datetime): + rtc.init(datetime) + print(rtc.now()[:6]) + +# make sure that setting works correctly +set_and_print((2000, 1, 1, 0, 0, 0, 0, None)) +set_and_print((2000, 1, 31, 0, 0, 0, 0, None)) +set_and_print((2000, 12, 31, 0, 0, 0, 0, None)) +set_and_print((2016, 12, 31, 0, 0, 0, 0, None)) +set_and_print((2016, 12, 31, 0, 0, 0, 0, None)) +set_and_print((2016, 12, 31, 1, 0, 0, 0, None)) +set_and_print((2016, 12, 31, 12, 0, 0, 0, None)) +set_and_print((2016, 12, 31, 13, 0, 0, 0, None)) +set_and_print((2016, 12, 31, 23, 0, 0, 0, None)) +set_and_print((2016, 12, 31, 23, 1, 0, 0, None)) +set_and_print((2016, 12, 31, 23, 59, 0, 50, None)) +set_and_print((2016, 12, 31, 23, 59, 1, 900, None)) +set_and_print((2016, 12, 31, 23, 59, 59, 100, None)) +set_and_print((2048, 12, 31, 23, 59, 59, 99999, None)) + +rtc.init((2015, 8, 29, 9, 0, 0, 0, None)) +rtc.alarm(0, 5000) +rtc.alarm(time=2000) +time.sleep_ms(1000) +left = rtc.alarm_left() +print(abs(left-1000) < 20) +time.sleep_ms(1000) +print(rtc.alarm_left() == 0) +time.sleep_ms(100) +print(rtc.alarm_left() == 0) + +rtc.init((2015, 8, 29, 9, 0, 0, 0, None)) +rtc.alarm(time=(2015, 8, 29, 9, 0, 45)) +time.sleep_ms(1000) +left = rtc.alarm_left() +print(abs(left-44000) < 100) + +# next ones must raise +try: + rtc.alarm(5000) +except: + print('Exception') + +try: + rtc.alarm(5000) +except: + print('Exception') + +try: + rtc = RTC(200000000) +except: + print('Exception') + +try: + rtc = RTC((2015, 8, 29, 9, 0, 0, 0, None)) +except: + print('Exception') diff --git a/tests/wipy/rtc.py.exp b/tests/wipy/rtc.py.exp new file mode 100644 index 0000000000..8225f4602f --- /dev/null +++ b/tests/wipy/rtc.py.exp @@ -0,0 +1,34 @@ +<RTC> +(2015, 1, 1, 0, 0, 0) +(2015, 8, 29, 9, 0, 0) +(2015, 1, 1, 0, 0, 0) +(2015, 8, 29, 9, 0, 0) +True +True +0 +0 +0 +0 +0 +(2000, 1, 1, 0, 0, 0) +(2000, 1, 31, 0, 0, 0) +(2000, 12, 31, 0, 0, 0) +(2016, 12, 31, 0, 0, 0) +(2016, 12, 31, 0, 0, 0) +(2016, 12, 31, 1, 0, 0) +(2016, 12, 31, 12, 0, 0) +(2016, 12, 31, 13, 0, 0) +(2016, 12, 31, 23, 0, 0) +(2016, 12, 31, 23, 1, 0) +(2016, 12, 31, 23, 59, 0) +(2016, 12, 31, 23, 59, 1) +(2016, 12, 31, 23, 59, 59) +(2048, 12, 31, 23, 59, 59) +True +True +True +True +Exception +Exception +Exception +Exception diff --git a/tests/wipy/sd.py b/tests/wipy/sd.py new file mode 100644 index 0000000000..2b66af78bb --- /dev/null +++ b/tests/wipy/sd.py @@ -0,0 +1,46 @@ +''' +SD card test for the CC3200 based boards. +''' + +from pyb import SD +import os + +machine = os.uname().machine +if 'LaunchPad' in machine: + sd_pins = ('GP16', 'GP17', 'GP15') +elif 'WiPy' in machine: + sd_pins = ('GP10', 'GP11', 'GP15') +else: + raise Exception('Board not supported!') + +sd = SD(pins=sd_pins) +print(sd) +sd.deinit() +print(sd) +sd.init(sd_pins) +print(sd) + +sd = SD(0, pins=sd_pins) +sd = SD(id=0, pins=sd_pins) +sd = SD(0, sd_pins) + +# check for memory leaks +for i in range(0, 1000): + sd = sd = SD(0, pins=sd_pins) + +# next ones should raise +try: + sd = SD(pins=()) +except Exception: + print("Exception") + +try: + sd = SD(pins=('GP10', 'GP11', 'GP8')) +except Exception: + print("Exception") + +try: + sd = SD(pins=('GP10', 'GP11')) +except Exception: + print("Exception") + diff --git a/tests/wipy/sd.py.exp b/tests/wipy/sd.py.exp new file mode 100644 index 0000000000..eaa5f08efb --- /dev/null +++ b/tests/wipy/sd.py.exp @@ -0,0 +1,6 @@ +<SD> +<SD> +<SD> +Exception +Exception +Exception diff --git a/tests/wipy/time.py b/tests/wipy/time.py new file mode 100644 index 0000000000..d6b4f245d6 --- /dev/null +++ b/tests/wipy/time.py @@ -0,0 +1,78 @@ +import time + +DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + +def is_leap(year): + return (year % 4) == 0 + +def test(): + seconds = 0 + wday = 5 # Jan 1, 2000 was a Saturday + for year in range(2000, 2049): + print("Testing %d" % year) + yday = 1 + for month in range(1, 13): + if month == 2 and is_leap(year): + DAYS_PER_MONTH[2] = 29 + else: + DAYS_PER_MONTH[2] = 28 + for day in range(1, DAYS_PER_MONTH[month] + 1): + secs = time.mktime((year, month, day, 0, 0, 0, 0, 0)) + if secs != seconds: + print("mktime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds)) + tuple = time.localtime(seconds) + secs = time.mktime(tuple) + if secs != seconds: + print("localtime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds)) + return + seconds += 86400 + if yday != tuple[7]: + print("locatime for %d-%02d-%02d got yday %d, expecting %d" % (year, month, day, tuple[7], yday)) + return + if wday != tuple[6]: + print("locatime for %d-%02d-%02d got wday %d, expecting %d" % (year, month, day, tuple[6], wday)) + return + yday += 1 + wday = (wday + 1) % 7 + +def spot_test(seconds, expected_time): + actual_time = time.localtime(seconds) + for i in range(len(actual_time)): + if actual_time[i] != expected_time[i]: + print("time.localtime(", seconds, ") returned", actual_time, "expecting", expected_time) + return + print("time.localtime(", seconds, ") returned", actual_time, "(pass)") + + +test() +spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1)) +spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1)) +spot_test( 59, (2000, 1, 1, 0, 0, 59, 5, 1)) +spot_test( 60, (2000, 1, 1, 0, 1, 0, 5, 1)) +spot_test( 3599, (2000, 1, 1, 0, 59, 59, 5, 1)) +spot_test( 3600, (2000, 1, 1, 1, 0, 0, 5, 1)) +spot_test( -1, (1999, 12, 31, 23, 59, 59, 4, 365)) +spot_test( 447549467, (2014, 3, 7, 23, 17, 47, 4, 66)) +spot_test( -940984933, (1970, 3, 7, 23, 17, 47, 5, 66)) +spot_test(-1072915199, (1966, 1, 1, 0, 0, 1, 5, 1)) +spot_test(-1072915200, (1966, 1, 1, 0, 0, 0, 5, 1)) +spot_test(-1072915201, (1965, 12, 31, 23, 59, 59, 4, 365)) + +t1 = time.time() +time.sleep(2) +t2 = time.time() +print(time.ticks_diff(t1, t2) == 2) + +t1 = time.ticks_ms() +time.sleep_ms(50) +t2 = time.ticks_ms() +print(time.ticks_diff(t1, t2) == 50) + +t1 = time.ticks_us() +time.sleep_us(1000) +t2 = time.ticks_us() +print(time.ticks_diff(t1, t2) < 2000) + +t1 = time.ticks_cpu() +t2 = time.ticks_cpu() +print(time.ticks_diff(t1, t2) < 16384) diff --git a/tests/wipy/time.py.exp b/tests/wipy/time.py.exp new file mode 100644 index 0000000000..24d798f929 --- /dev/null +++ b/tests/wipy/time.py.exp @@ -0,0 +1,65 @@ +Testing 2000 +Testing 2001 +Testing 2002 +Testing 2003 +Testing 2004 +Testing 2005 +Testing 2006 +Testing 2007 +Testing 2008 +Testing 2009 +Testing 2010 +Testing 2011 +Testing 2012 +Testing 2013 +Testing 2014 +Testing 2015 +Testing 2016 +Testing 2017 +Testing 2018 +Testing 2019 +Testing 2020 +Testing 2021 +Testing 2022 +Testing 2023 +Testing 2024 +Testing 2025 +Testing 2026 +Testing 2027 +Testing 2028 +Testing 2029 +Testing 2030 +Testing 2031 +Testing 2032 +Testing 2033 +Testing 2034 +Testing 2035 +Testing 2036 +Testing 2037 +Testing 2038 +Testing 2039 +Testing 2040 +Testing 2041 +Testing 2042 +Testing 2043 +Testing 2044 +Testing 2045 +Testing 2046 +Testing 2047 +Testing 2048 +time.localtime( 0 ) returned (2000, 1, 1, 0, 0, 0, 5, 1) (pass) +time.localtime( 1 ) returned (2000, 1, 1, 0, 0, 1, 5, 1) (pass) +time.localtime( 59 ) returned (2000, 1, 1, 0, 0, 59, 5, 1) (pass) +time.localtime( 60 ) returned (2000, 1, 1, 0, 1, 0, 5, 1) (pass) +time.localtime( 3599 ) returned (2000, 1, 1, 0, 59, 59, 5, 1) (pass) +time.localtime( 3600 ) returned (2000, 1, 1, 1, 0, 0, 5, 1) (pass) +time.localtime( -1 ) returned (1999, 12, 31, 23, 59, 59, 4, 365) (pass) +time.localtime( 447549467 ) returned (2014, 3, 7, 23, 17, 47, 4, 66) (pass) +time.localtime( -940984933 ) returned (1970, 3, 7, 23, 17, 47, 5, 66) (pass) +time.localtime( -1072915199 ) returned (1966, 1, 1, 0, 0, 1, 5, 1) (pass) +time.localtime( -1072915200 ) returned (1966, 1, 1, 0, 0, 0, 5, 1) (pass) +time.localtime( -1072915201 ) returned (1965, 12, 31, 23, 59, 59, 4, 365) (pass) +True +True +True +True diff --git a/tests/wipy/uart.py b/tests/wipy/uart.py index aa2f18b985..d700c29d08 100644 --- a/tests/wipy/uart.py +++ b/tests/wipy/uart.py @@ -7,6 +7,7 @@ from pyb import UART from pyb import Pin import os import pyb +import time machine = os.uname().machine if 'LaunchPad' in machine: @@ -66,7 +67,7 @@ print(buf) # try initializing without the id uart0 = UART(baudrate=1000000, pins=uart_pins[0][0]) uart0.write(b'1234567890') -pyb.delay(2) # because of the fifo interrupt levels +time.sleep_ms(2) # because of the fifo interrupt levels print(uart1.any() == 10) print(uart1.readline() == b'1234567890') print(uart1.any() == 0) diff --git a/tests/wipy/wdt.py b/tests/wipy/wdt.py index 9be6293b08..8e07fd8314 100644 --- a/tests/wipy/wdt.py +++ b/tests/wipy/wdt.py @@ -3,6 +3,7 @@ WDT test for the CC3200 based boards ''' from pyb import WDT +import time # test the invalid cases first try: @@ -28,10 +29,10 @@ try: except Exception: print("Exception") -pyb.delay(500) +time.sleep_ms(500) wdt.feed() print(wdt) -pyb.delay(900) +time.sleep_ms(900) wdt.feed() print(wdt) -pyb.delay(950) +time.sleep_ms(950) |