From 7089ffc3a691a637270dad767b2f23ed1ab1d977 Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Mon, 24 Apr 2023 15:34:17 +0200 Subject: [PATCH] tests: Added PSoC6 port specific tests. Signed-off-by: jaenrig-ifx --- tests/psoc6/README | 339 +++++++++++++++++++++++++++++++++ tests/psoc6/flash.py | 59 ++++++ tests/psoc6/flash.py.exp | 2 + tests/psoc6/i2c_hard.py | 7 + tests/psoc6/i2c_hard.py.exp | 2 + tests/psoc6/i2c_soft.py | 7 + tests/psoc6/i2c_soft.py.exp | 2 + tests/psoc6/modtime.py | 62 ++++++ tests/psoc6/modtime.py.exp | 17 ++ tests/psoc6/pin.py | 26 +++ tests/psoc6/pin.py.exp | 6 + tests/psoc6/rtc.py | 54 ++++++ tests/psoc6/rtc.py.exp | 33 ++++ tests/psoc6/run_psoc6_tests.sh | 295 ++++++++++++++++++++++++++++ tests/psoc6/time.py | 78 ++++++++ tests/psoc6/time.py.exp | 25 +++ 16 files changed, 1014 insertions(+) create mode 100644 tests/psoc6/README create mode 100644 tests/psoc6/flash.py create mode 100644 tests/psoc6/flash.py.exp create mode 100644 tests/psoc6/i2c_hard.py create mode 100644 tests/psoc6/i2c_hard.py.exp create mode 100644 tests/psoc6/i2c_soft.py create mode 100644 tests/psoc6/i2c_soft.py.exp create mode 100644 tests/psoc6/modtime.py create mode 100644 tests/psoc6/modtime.py.exp create mode 100644 tests/psoc6/pin.py create mode 100644 tests/psoc6/pin.py.exp create mode 100644 tests/psoc6/rtc.py create mode 100644 tests/psoc6/rtc.py.exp create mode 100755 tests/psoc6/run_psoc6_tests.sh create mode 100644 tests/psoc6/time.py create mode 100644 tests/psoc6/time.py.exp diff --git a/tests/psoc6/README b/tests/psoc6/README new file mode 100644 index 0000000000000..223602cf0a17a --- /dev/null +++ b/tests/psoc6/README @@ -0,0 +1,339 @@ + +Micropython is based on a certain version of Python (currently 3.4), so certain Python features may not be present at all, depending on the version used as reference. +Other features may simply yield different results as compared to CPython, depending on the version CPyton is based on. And then there are certain features that are simply +implemented differently in order to gain speed or smaller memory footprint. Please refer to : + + https://docs.micropython.org/en/latest/genrst/index.html + + + +A description of limitations and differences of builtin features wrt CPython can be found here : + + https://docs.micropython.org/en/latest/genrst/builtin_types.html + + +########################################################################### +### the following test directories and files are currently available + +# generic tests for all tools +basics +cmdline : Only works with command line Python, e.g. Unix +cpydiff : tests with known discrepancies to CPython, therefore to be omitted +extmod +feature_check +float +frozen +import : many tests require files on the board filesystem, but these are not copied by default. All those tests have been manually tested and verified to work as expected +inlineasm +internal_bench : run by run-internalbench.py; some need “ticks” function or will fail; also require module bench.py which must be on the local flash +io : need files in local flash (io/data/*), but those are not copied by default +jni : tests to be run in environment with JAVA available, ie Unix, Windows, ... +micropython +misc +multi_bluetooth +multi_net +net_hosted +net_inet +perf_bench : used with run-perfbench.py for benchmarking +stress +thread +unicode +unix : exclude mod_os.py, but use time.py for psoc6; in general to be run only on Unix platform ! + + +########################################################################### +# tool specific tests +esp32 +psoc6 +pyb +qemu-arm +renesas-ra +unix +wipy + + +########################################################################### +### tests excluded in psoc6 test suite because they must fail with the current run-tests.py functionality +# tests with known discrepancies to CPython, therefore to be omitted +cpydiff + + +########################################################################### +# Many tests require files on the board filesystem, but these are not copied by default. Also, the sys.path must be adapted to reflect the mount point of the board FS. +# All these excluded tests have been manually tested and verified to work as expected +- import : + - gen_context.py + - import1a.py + - import2a.py + - import3a.py + - import_file.py + - import_long_dyn.py + - import_override.py + - import_pkg1.py + - import_pkg2.py + - import_pkg3.py + - import_pkg4.py + - import_pkg5.py + - import_pkg6.py + - import_pkg7.py + - import_pkg8.py + - module_dict.py + - try_module.py + + +########################################################################### +# Many tests require files on the board filesystem, but these are not copied by default. Also, the sys.path must be adapted to reflect the mount point of the board FS. +# All these excluded tests have been manually tested and verified to work as expected +-io : + - file_readinto.py + - file_readline.py + - file_iter.py + - file_long_read.py + - file_long_read2.py + - file_long_read3.py + - file_readinto.py + - file_readinto_len.py + - file_seek.py + - file_with.py + - open_append.py + - open_plus.py + + # The following io tests do fail : + - argv.py : no command line parameters passed at board level, therefore argv is empty, but not so in python + - file1.py : !!!! writes to a file opened in read mode, therefore file is changed and all further tests based on this file will fail !!!! + - file_stdio.py : attribute fileno not available, therefore tests fail + + +########################################################################### +# tests to be run in environment with JAVA available, ie Unix, Windows, ... +jni + + +########################################################################### +# test which cannot be compared to Python because MPY specific features are used +- perf_bench : + - core_import_mpy_multi.py + - core_import_mpy_single.py + - viper_call*.py + + +########################################################################### +# Many tests require files on the board filesystem, but these are not copied by default. Also, the sys.path must be adapted to reflect the mount point of the board FS. +# All these excluded tests have been manually tested and verified to work as expected +- unicode : + - file1.py + - file2.py + - file_invalid.py + + +########################################################################### +### TODO: clarify how to solve these +# strange error in time module (only sometimes) +- extmod : + - utime_res.py + + # this test fails at times as 1 check is not timing safe + - vfs_lfs_mtime.py + + +# only differ in standard output message by MPY, code is MPY code and seems to work fine +- feature_check : + - async_check.py + - bytearray.py + - byteorder.py + - complex.py + - const.py + - coverage.py + - native_check.py + + +# emacs features not enabled in port config +- feature_check : + - repl_emacs_check.py + - repl_words_move_check.py + - set_check.py + - slice.py + - uio_module.py + + +# tests that require double precision (64 bits), ie double, to be set in mpconfigport.h for macro "MICROPY_FLOAT_IMPL" +# clashes with misc/rge_sm.py +- feature_check : + - float.py + + +# +- float + - math_domain_special.py + + +# strange error in output of message not consistent with text in source code => wrong mapping of internal qstrings ? +- micropython : + - import_mpy_invalid.py + - import_mpy_native.py + - viper_error.py + + +# tests that require single precision (32 bits), ie float, to be set in mpconfigport.h for macro "MICROPY_FLOAT_IMPL" +# clashes with feature_check/float.py +misc/rge_sm.py + + +# in order to enable code tracing the following switches must be set. All tests are run to completion, but output differs. Instead of file names is printed. +# other features (uasyncio*) need MICROPY_STACKLESS=0 in order to be testable ! +#define MICROPY_PY_SYS_SETTRACE (1) +#define MICROPY_PERSISTENT_CODE_SAVE (1) +#define MICROPY_COMP_CONST (0) + +# to be set in order to increase recursion depth +#define MICROPY_STACKLESS (1) +//#define MICROPY_STACKLESS_STRICT (1) + + +########################################################################### +### directory filled with test results for failling tests +results + + +########################################################################### +# test executables and other files +README.md + +run-internalbench.py : run internal benchmarks + +run-multitests.py : run tests between 2 MCU instances + +run-natmodtests.py + +run-perfbench.py : run tests in perfbench +./run-perfbench.py --pyboard 100 256 + +run-tests-exp.py : run tests in MCU session + +run-tests-exp.sh + +run-tests.py : run tests from host platform + + +########################################################################### +### Test results +840 tests performed (23903 individual testcases) +837 tests passed +59 tests skipped +3 tests failed + + +########################################################################### +### failing tests +# unclear why +FAIL extmod/ussl_basic.py +FAIL extmod/ussl_keycert.py +FAIL extmod/utime_res.py + + +### tests that fail sometimes +extmod/uasyncio_lock.py => crash +extmod/utime_res.py => crash +psoc6/time.py => test_ticks_ms due to latencies greater than tested range +stress/bytecode_limit.py + +########################################################################### +### skipped tests +### tests skipped by run-tests.py and potentially to be enabled in "mpconfigport.h" +# unclear why skipped +skip basics/builtin_next_arg2.py +skip basics/builtin_range_binop.py + +# excluded in run-tests.py because known to differ from Python +skip basics/class_inplace_op2.py +skip basics/exception_chain.py + +# unclear why skipped +skip basics/io_buffered_writer.py +skip basics/memoryview_itemsize.py +skip basics/namedtuple_asdict.py +skip basics/nanbox_smallint.py + +# excluded in run-tests.py because known to differ from Python +skip basics/subclass_native_call.py + +# not enabled +skip basics/sys_getsizeof.py + +# not enabled +skip basics/sys_path.py +skip basics/sys_tracebacklimit.py + +# not enabled +skip extmod/btree1.py +skip extmod/btree_error.py +skip extmod/btree_gc.py +skip extmod/machine1.py +skip extmod/machine_i2s_rate.py +skip extmod/machine_pinbase.py +skip extmod/machine_pulse.py +skip extmod/machine_signal.py +skip extmod/machine_timer.py +skip extmod/urandom_seed_default.py + +# enabled, but skipped, unclear why +skip extmod/uselect_poll_basic.py +skip extmod/uselect_poll_udp.py + +# not enabled +skip extmod/usocket_tcp_basic.py +skip extmod/usocket_udp_nonblock.py + +# enabled, but skipped +skip extmod/ussl_poll.py + +# not enabled +skip extmod/utimeq1.py +skip extmod/utimeq_stable.py + +# FAT not enabled +skip extmod/vfs_blockdev.py +skip extmod/vfs_fat_fileio1.py +skip extmod/vfs_fat_fileio2.py +skip extmod/vfs_fat_finaliser.py +skip extmod/vfs_fat_ilistdir_del.py +skip extmod/vfs_fat_more.py +skip extmod/vfs_fat_mtime.py +skip extmod/vfs_fat_oldproto.py +skip extmod/vfs_fat_ramdisk.py +skip extmod/vfs_fat_ramdisklarge.py + +# skipped because lfs1 not enabled +skip extmod/vfs_lfs.py +skip extmod/vfs_lfs_corrupt.py +skip extmod/vfs_lfs_error.py +skip extmod/vfs_lfs_file.py +skip extmod/vfs_lfs_mount.py + +# not enabled +skip extmod/vfs_posix.py +skip extmod/vfs_posix_ilistdir_del.py + +# not enabled +skip extmod/websocket_basic.py + +# skipped, see run-tests.py +skip float/float2int_doubleprec_intbig.py +skip float/float_divmod.py +skip float/float_format_ints_doubleprec.py +skip float/float_parse_doubleprec.py + +# not enabled +skip micropython/heap_locked.py + +# unclear why skipped +skip micropython/heapalloc_bytesio2.py +skip micropython/meminfo.py + +# not enabled +skip micropython/memstats.py + +# not enabled +skip misc/sys_settrace_features.py +skip misc/sys_settrace_generator.py +skip misc/sys_settrace_loop.py diff --git a/tests/psoc6/flash.py b/tests/psoc6/flash.py new file mode 100644 index 0000000000000..fdac69bb855bd --- /dev/null +++ b/tests/psoc6/flash.py @@ -0,0 +1,59 @@ +import os, psoc6 + +# Try to mount the filesystem, and format the flash if it doesn't exist. +# create block device object based on whichever flash is active +bdev = psoc6.QSPI_Flash() if "QSPI_Flash" in dir(psoc6) else psoc6.Flash() +# unmount the filesystem in case its already mounted +os.umount("/") + +test_string = "This is a test string." +print(test_string) + +# first priority is always LFS2 filesystem as it is the default +if "VfsLfs2" in dir(os): + # sector size 4 KB for external flash + # sector size 512 B for internal flash + read_size = 0x1000 if "QSPI_Flash" in dir(psoc6) else 0x200 + # page size 512 B for both flashes + write_size = 0x200 + + # create a LFS2 fs and mount it, else format and mount it + try: + vfs = os.VfsLfs2(bdev, progsize=write_size, readsize=read_size) + os.mount(vfs, "/flash") + except: + os.VfsLfs2.mkfs(bdev, progsize=write_size, readsize=read_size) + vfs = os.VfsLfs2(bdev, progsize=write_size, readsize=read_size) + os.mount(vfs, "/flash") + + # open a file and do some operation + f = open("/flash/test_lfs2.txt", "w") + f.write(test_string) + f.close() + + # read back the contents + f = open("/flash/test_lfs2.txt", "r") + if f.read() == test_string: + print("Test successful") + f.close() + +if "VfsFat" in dir(os): + # create a FAT fs and mount it, else format and mount it + try: + vfs = os.VfsFat(bdev) + os.mount(vfs, "/flash") + except: + os.VfsFat.mkfs(bdev) + vfs = os.VfsFat(bdev) + os.mount(vfs, "/flash") + + # open a file and do some operation + f = open("/flash/test_fat.txt", "w") + f.write(test_string) + f.close() + + # read back the contents + f = open("/flash/test_fat.txt", "r") + if f.read() == test_string: + print("Test successful") + f.close() diff --git a/tests/psoc6/flash.py.exp b/tests/psoc6/flash.py.exp new file mode 100644 index 0000000000000..ebf73f8bf0104 --- /dev/null +++ b/tests/psoc6/flash.py.exp @@ -0,0 +1,2 @@ +This is a test string. +Test successful diff --git a/tests/psoc6/i2c_hard.py b/tests/psoc6/i2c_hard.py new file mode 100644 index 0000000000000..07219fbb7bda9 --- /dev/null +++ b/tests/psoc6/i2c_hard.py @@ -0,0 +1,7 @@ +### I2C +from machine import I2C + +i2c = I2C(id=0, scl="P6_0", sda="P6_1", freq=400000) +print(i2c) + +print(i2c.scan()) diff --git a/tests/psoc6/i2c_hard.py.exp b/tests/psoc6/i2c_hard.py.exp new file mode 100644 index 0000000000000..8d60f88ee6851 --- /dev/null +++ b/tests/psoc6/i2c_hard.py.exp @@ -0,0 +1,2 @@ +I2C(0, freq=400000, scl=48, sda=49) +[] diff --git a/tests/psoc6/i2c_soft.py b/tests/psoc6/i2c_soft.py new file mode 100644 index 0000000000000..d36fb499458ee --- /dev/null +++ b/tests/psoc6/i2c_soft.py @@ -0,0 +1,7 @@ +#### SoftI2C +from machine import SoftI2C + +si2c = SoftI2C(scl="P6_0", sda="P6_1", freq=400000) +print(si2c) + +print(si2c.scan()) diff --git a/tests/psoc6/i2c_soft.py.exp b/tests/psoc6/i2c_soft.py.exp new file mode 100644 index 0000000000000..49bfede5efe0e --- /dev/null +++ b/tests/psoc6/i2c_soft.py.exp @@ -0,0 +1,2 @@ +SoftI2C(scl=48, sda=49, freq=500000) +[] diff --git a/tests/psoc6/modtime.py b/tests/psoc6/modtime.py new file mode 100644 index 0000000000000..f8f2992750442 --- /dev/null +++ b/tests/psoc6/modtime.py @@ -0,0 +1,62 @@ +import time + +wday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] + + +def get_default_date_time(): + seconds = 0 + default_dtime = time.gmtime(0) + print( + "\ngmtime() at default returned [Year/Month/Day - WeekDay - HH:MM:SS] : %d/%02d/%02d - %s - %02d:%02d:%02d " + % ( + default_dtime[0], + default_dtime[1], + default_dtime[2], + wday[default_dtime[6]], + default_dtime[3], + default_dtime[4], + default_dtime[5], + ) + ) + + if time.mktime(default_dtime) != seconds: + print("\nmktime() FAILED to create right dtime from secs\n") + else: + print("\nmktime() SUCCESSFULLY created right dtime from secs\n") + + +def get_dtime_from_secs(secs): + return time.localtime(secs) + + +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, + "(Test : FAILED)", + ) + return + print("time.localtime(", seconds, ") returned", actual_time, "(Test : PASSED)") + + +get_default_date_time() + +spot_test(0, (1970, 1, 1, 0, 0, 0, 3, 1)) +spot_test(1, (1970, 1, 1, 0, 0, 1, 3, 1)) +spot_test(59, (1970, 1, 1, 0, 0, 59, 3, 1)) +spot_test(60, (1970, 1, 1, 0, 1, 0, 3, 1)) +spot_test(3599, (1970, 1, 1, 0, 59, 59, 3, 1)) +spot_test(3600, (1970, 1, 1, 1, 0, 0, 3, 1)) +spot_test(-1, (1969, 12, 31, 23, 59, 59, 2, 365)) +spot_test(447549467, (1984, 3, 7, 23, 17, 47, 2, 67)) +spot_test(-940984933, (1940, 3, 7, 23, 17, 47, 3, 67)) +spot_test(-1072915199, (1936, 1, 2, 0, 0, 1, 3, 2)) +spot_test(-1072915200, (1936, 1, 2, 0, 0, 0, 3, 2)) +spot_test(-1072915201, (1936, 1, 1, 23, 59, 59, 2, 1)) diff --git a/tests/psoc6/modtime.py.exp b/tests/psoc6/modtime.py.exp new file mode 100644 index 0000000000000..0b5b07bd9776d --- /dev/null +++ b/tests/psoc6/modtime.py.exp @@ -0,0 +1,17 @@ + +gmtime() at default returned [Year/Month/Day - WeekDay - HH:MM:SS] : 1970/01/01 - Thu - 00:00:00 + +mktime() SUCCESSFULLY created right dtime from secs + +time.localtime( 0 ) returned (1970, 1, 1, 0, 0, 0, 3, 1) (Test : PASSED) +time.localtime( 1 ) returned (1970, 1, 1, 0, 0, 1, 3, 1) (Test : PASSED) +time.localtime( 59 ) returned (1970, 1, 1, 0, 0, 59, 3, 1) (Test : PASSED) +time.localtime( 60 ) returned (1970, 1, 1, 0, 1, 0, 3, 1) (Test : PASSED) +time.localtime( 3599 ) returned (1970, 1, 1, 0, 59, 59, 3, 1) (Test : PASSED) +time.localtime( 3600 ) returned (1970, 1, 1, 1, 0, 0, 3, 1) (Test : PASSED) +time.localtime( -1 ) returned (1969, 12, 31, 23, 59, 59, 2, 365) (Test : PASSED) +time.localtime( 447549467 ) returned (1984, 3, 7, 23, 17, 47, 2, 67) (Test : PASSED) +time.localtime( -940984933 ) returned (1940, 3, 7, 23, 17, 47, 3, 67) (Test : PASSED) +time.localtime( -1072915199 ) returned (1936, 1, 2, 0, 0, 1, 3, 2) (Test : PASSED) +time.localtime( -1072915200 ) returned (1936, 1, 2, 0, 0, 0, 3, 2) (Test : PASSED) +time.localtime( -1072915201 ) returned (1936, 1, 1, 23, 59, 59, 2, 1) (Test : PASSED) diff --git a/tests/psoc6/pin.py b/tests/psoc6/pin.py new file mode 100644 index 0000000000000..3e1812d80645c --- /dev/null +++ b/tests/psoc6/pin.py @@ -0,0 +1,26 @@ +from machine import Pin +import time +import machine + +# Tests for Output pin +# Instantiate output pin for led operation +# Constr +p1 = Pin("P13_7") +p1.init(Pin.OUT) +print(p1) # Pin:111 or P13_7, Mode=OUT, Pull=None, Value=1 + +p1.value(0) # Led glows +print(p1.value()) # None + +p1.off() # Switches off led +print(p1.off()) # None + +p1.value(False) # Led glows +print(p1.value()) # None + +# Tests for Input pin +# Instantiate input pin for button operation +p2 = Pin("P0_4", Pin.IN) +print(p2) # Pin:4 or P0_4, Mode=IN, Pull=None, Value=1 +p2.value() +print(p2.value()) # 1 - button is released diff --git a/tests/psoc6/pin.py.exp b/tests/psoc6/pin.py.exp new file mode 100644 index 0000000000000..f6e070bbd7fa8 --- /dev/null +++ b/tests/psoc6/pin.py.exp @@ -0,0 +1,6 @@ +Pin:111 or P13_7, Mode=OUT, Pull=None, Value=1 +None +None +None +Pin:4 or P0_4, Mode=IN, Pull=None, Value=1 +1 diff --git a/tests/psoc6/rtc.py b/tests/psoc6/rtc.py new file mode 100644 index 0000000000000..24cf1a64bb10c --- /dev/null +++ b/tests/psoc6/rtc.py @@ -0,0 +1,54 @@ +# import machine +from machine import RTC +import time + +rtc = RTC() +print(rtc) +# Tuple format: Year, Month, Sec, WDay*, Hour, Min, Sec, Subsec=0 +# *Note: User cannot set a wrong week day value here. PSoC always calculates the right weekday using rest of the fields. +rtc.init((2023, 1, 1, 0, 0, 0, 0, 0)) +print(rtc.datetime()) + +# Make sure that 1 second passes correctly +rtc.datetime((2023, 1, 1, 0, 0, 0, 0, 0)) +print(rtc.datetime()) +time.sleep_ms(1008) +print(rtc.datetime()) + + +def set_and_print(datetime): + rtc.datetime(datetime) + current_datetime = rtc.now() + print(current_datetime) + if current_datetime == datetime: + print("PASS") + else: + print("FAIL") + + +set_and_print((2000, 1, 1, 6, 0, 0, 0, 0)) +set_and_print((2000, 1, 31, 1, 0, 0, 0, 0)) +set_and_print((2000, 12, 31, 0, 0, 0, 0, 0)) +set_and_print((2016, 12, 31, 6, 0, 0, 0, 0)) +set_and_print((2016, 12, 31, 6, 0, 0, 0, 0)) +set_and_print((2016, 12, 31, 6, 1, 0, 0, 0)) +set_and_print((2016, 12, 31, 6, 12, 0, 0, 0)) +set_and_print((2016, 12, 31, 6, 13, 0, 0, 0)) +set_and_print((2016, 12, 31, 6, 23, 0, 0, 0)) +set_and_print((2016, 12, 31, 6, 23, 1, 0, 0)) +set_and_print((2016, 12, 31, 6, 23, 59, 0, 0)) +set_and_print((2016, 12, 31, 6, 23, 59, 1, 0)) +set_and_print((2016, 12, 31, 6, 23, 59, 59, 0)) +set_and_print((2099, 12, 31, 4, 23, 59, 59, 0)) + + +def reset_rtc(): + rtc.deinit() + default_datetime = (2015, 1, 1, 4, 0, 0, 0, 0) + if default_datetime == rtc.now(): + print("RESET SUCCESSFUL") + else: + print("RESET FAILED") + + +reset_rtc() diff --git a/tests/psoc6/rtc.py.exp b/tests/psoc6/rtc.py.exp new file mode 100644 index 0000000000000..ab948ac05ca45 --- /dev/null +++ b/tests/psoc6/rtc.py.exp @@ -0,0 +1,33 @@ + +(2023, 1, 1, 0, 0, 0, 0, 0) +(2023, 1, 1, 0, 0, 0, 0, 0) +(2023, 1, 1, 0, 0, 0, 1, 0) +(2000, 1, 1, 6, 0, 0, 0, 0) +PASS +(2000, 1, 31, 1, 0, 0, 0, 0) +PASS +(2000, 12, 31, 0, 0, 0, 0, 0) +PASS +(2016, 12, 31, 6, 0, 0, 0, 0) +PASS +(2016, 12, 31, 6, 0, 0, 0, 0) +PASS +(2016, 12, 31, 6, 1, 0, 0, 0) +PASS +(2016, 12, 31, 6, 12, 0, 0, 0) +PASS +(2016, 12, 31, 6, 13, 0, 0, 0) +PASS +(2016, 12, 31, 6, 23, 0, 0, 0) +PASS +(2016, 12, 31, 6, 23, 1, 0, 0) +PASS +(2016, 12, 31, 6, 23, 59, 0, 0) +PASS +(2016, 12, 31, 6, 23, 59, 1, 0) +PASS +(2016, 12, 31, 6, 23, 59, 59, 0) +PASS +(2099, 12, 31, 4, 23, 59, 59, 0) +PASS +RESET SUCCESSFUL diff --git a/tests/psoc6/run_psoc6_tests.sh b/tests/psoc6/run_psoc6_tests.sh new file mode 100755 index 0000000000000..8bf562eb4f163 --- /dev/null +++ b/tests/psoc6/run_psoc6_tests.sh @@ -0,0 +1,295 @@ +#!/usr/bin/sh + +# +# psoc6/run_psoc6_tests.sh -ci +# + + +echo "executing $0 $* ..." + +usage() { + echo "Usage: $0 -a -c -d -f -i -n " 1>&2; + exit 1; +} + + +while getopts "acd:fhin" o; do + case "${o}" in + a) + all=1 + ;; + c) + cleanResultsDirectoryFirst=1 + ;; + d) + device=${OPTARG} + ;; + f) + failing=1 + ;; + h) + usage + ;; + i) + implemented=1 + ;; + n) + notYetImplemented=1 + ;; + *) + usage + ;; + esac +done + + +if [ -z "${all}" ]; then + all=0 +fi + + +if [ -z "${cleanResultsDirectoryFirst}" ]; then + cleanResultsDirectoryFirst=0 +fi + + +if [ -z "${device}" ]; then + device="/dev/ttyACM0" +fi + + +if [ -z "${failing}" ]; then + failing=0 +fi + + +if [ -z "${implemented}" ]; then + implemented=0 +fi + + +if [ -z "${notYetImplemented}" ]; then + notYetImplemented=0 +fi + + +resultsFile="psoc6_test_results.log" +passResultsFile="psoc6_test_passed.log" +skipResultsFile="psoc6_test_skipped.log" +failResultsFile="psoc6_test_failed.log" + + +echo +echo " device : ${device}" +echo +echo " results file : ${resultsFile}" +echo " pass results file : ${passResultsFile}" +echo " skip results file : ${skipResultsFile}" +echo " fail results file : ${failResultsFile}" +echo + + +if [ ${cleanResultsDirectoryFirst} -eq 1 ]; then + + echo + echo " removing results directory and file if existent ..." + + if [ -e results ]; then + + rm -rf results ${resultsFile} + + fi + + echo " done." + echo + +fi + + +if [ ${all} -eq 1 ]; then + + echo " running all tests ..." + echo + + ./run-tests.py --target psoc6 --device ${device} \ + -d \ + basics \ + extmod \ + feature_check \ + float \ + frozen \ + import \ + inlineasm \ + micropython \ + misc \ + multi_bluetooth \ + multi_net \ + net_hosted \ + net_inet \ + perf_bench \ + psoc6 \ + stress \ + thread \ + unicode \ + | tee -a ${resultsFile} + + echo + echo " done." + echo + +fi + + +if [ ${implemented} -eq 1 ]; then + + echo " running implemented tests ..." + echo + + ./run-tests.py --target psoc6 --device ${device} \ + io/builtin_print_file.py \ + unix/time.py \ + | tee -a ${resultsFile} + + echo + + ./run-tests.py --target psoc6 --device ${device} \ + -d \ + basics \ + extmod \ + feature_check \ + float \ + frozen \ + import \ + inlineasm \ + micropython \ + misc \ + perf_bench \ + psoc6 \ + stress \ + unicode \ + \ + -e extmod/vfs_lfs_mtime.py \ + \ + -e feature_check/async_check.py \ + -e feature_check/bytearray.py \ + -e feature_check/byteorder.py \ + -e feature_check/complex.py \ + -e feature_check/const.py \ + -e feature_check/coverage.py \ + -e feature_check/float.py \ + -e feature_check/native_check.py \ + -e feature_check/repl_emacs_check.py \ + -e feature_check/repl_words_move_check.py \ + -e feature_check/set_check.py \ + -e feature_check/slice.py \ + -e feature_check/uio_module.py \ + \ + -e float/math_domain_special.py \ + \ + -e import/gen_context.py \ + -e import/import1a.py \ + -e import/import2a.py \ + -e import/import3a.py \ + -e import/import_file.py \ + -e import/import_long_dyn.py \ + -e import/import_override.py \ + -e import/import_pkg1.py \ + -e import/import_pkg2.py \ + -e import/import_pkg3.py \ + -e import/import_pkg4.py \ + -e import/import_pkg5.py \ + -e import/import_pkg6.py \ + -e import/import_pkg7.py \ + -e import/import_pkg8.py \ + -e import/module_dict.py \ + -e import/try_module.py \ + \ + -e micropython/import_mpy_invalid.py \ + -e micropython/import_mpy_native.py \ + -e micropython/viper_error.py \ + \ + -e perf_bench/core_import_mpy_multi.py \ + -e perf_bench/core_import_mpy_single.py \ + -e 'perf_bench/viper_call.*.py' \ + \ + -e unicode/file1.py \ + -e unicode/file2.py \ + -e unicode/file_invalid.py \ + | tee -a ${resultsFile} + + echo + echo " done." + echo + +fi + + +### not yet enabled/implemented, therefore failing +if [ ${notYetImplemented} -eq 1 ]; then + + echo " running not yet implemented tests ..." + echo + + ./run-tests.py --target psoc6 --device ${device} -d \ + multi_bluetooth \ + multi_net \ + net_hosted \ + net_inet \ + thread \ + | tee -a ${resultsFile} + + echo + echo " done." + echo + +fi + + +### all excluded because it is know that these tests fail. In case of folder +# +# - cpydiff : please refer to documentetion within tests +# - cmdline : tests are for command line Python execution and not for embedded MPY +# - internal_bench : used for measuring run time of certain operations. Will always fail because runtime of Python and MPY will differ. +# - io : tests required data files on board flash and a change in the file paths to match the flash mount point +# - jni : tests to be run in environment with JAVA available, ie Unix, Windows, ... + +# +### therefore have been placed in this category +### +if [ ${failing} -eq 1 ]; then + + echo " running failing tests ..." + echo + + + # prepare execution of tests by uploading required files to on-board flash + ../tools/mpremote/mpremote.py cp internal_bench/bench.py :/flash/bench.py + + + ./run-tests.py --target psoc6 --device ${device} -d \ + cmdline \ + cpydiff \ + internal_bench \ + io \ + jni \ + | tee -a ${resultsFile} + + echo + echo " done." + echo + +fi + + +echo +echo "generating pass, skip and fail files ..." + +grep -i 'pass ' ${resultsFile} > ${passResultsFile} +grep -i 'skip ' ${resultsFile} > ${skipResultsFile} +grep -i 'FAIL ' ${resultsFile} > ${failResultsFile} + +echo "generating pass, skip and fail files done." + + +echo +echo "executing $0 $* done." diff --git a/tests/psoc6/time.py b/tests/psoc6/time.py new file mode 100644 index 0000000000000..573d799fbc93e --- /dev/null +++ b/tests/psoc6/time.py @@ -0,0 +1,78 @@ +import time + + +def test_ticks_ms(): + print("\n***** Test 1: ticks_ms() *****\n") + t0 = time.ticks_ms() + time.sleep_ms(1) + t1 = time.ticks_ms() + diff = time.ticks_diff(t1, t0) + tick_val = [t0, t1, diff, 0 <= diff <= 1] + if tick_val[3]: + print("Status: PASS") + else: + print("Status: FAIL") + + +def test_ticks_us(): + print("\n***** Test 2: ticks_us() *****\n") + t0 = time.ticks_us() + time.sleep_us(1) + t1 = time.ticks_us() + diff = time.ticks_diff(t1, t0) + tick_val = [t0, t1, diff, 0 <= diff <= 500] + if tick_val[3]: + print("Status: PASS") + else: + print("Status: FAIL") + + +def test_ticks_cpu(): + # ticks_cpu may not be implemented, at least make sure it doesn't decrease''' + print("\n***** Test 3: ticks_cpu() *****\n") + t0 = time.ticks_cpu() + time.sleep_us(1) + t1 = time.ticks_cpu() + diff = time.ticks_diff(t1, t0) + tick_val = [t0, t1, diff, 0 <= diff <= 500] + if tick_val[3]: + print("Status: PASS") + else: + print("Status: FAIL") + + +def test_boundary_us_cond(): + print("\n***** Test 4: Checking boundary conditions *****\n") + max_tick = 15000000 + tick_var = [] + for i in range(1, 11): + t0 = time.ticks_us() + time.sleep_us(max_tick - t0) + t1 = time.ticks_us() + diff = time.ticks_diff(t1, t0) + tick_val = [t0, t1, diff, diff >= 0] + tick_var.append(tick_val) + + for i in range(0, 10): + if tick_var[i][3]: + print("PASS") + else: + print("FAIL") + break + + +def test_us_deviation(): + print("\n***** Test 5: Checking wrap around condition *****\n") + for i in range(150): + t0 = time.ticks_us() + time.sleep_us(i) + t1 = time.ticks_us() + print("[instant, t0, t1, diff] : [", i, t0, t1, time.ticks_diff(t1, t0), "]") + + +test_ticks_ms() +test_ticks_us() +test_ticks_cpu() +test_boundary_us_cond() +# Enable this test only if needed for advanced checking +# test_us_deviation() diff --git a/tests/psoc6/time.py.exp b/tests/psoc6/time.py.exp new file mode 100644 index 0000000000000..84305c19c8980 --- /dev/null +++ b/tests/psoc6/time.py.exp @@ -0,0 +1,25 @@ + +***** Test 1: ticks_ms() ***** + +Status: PASS + +***** Test 2: ticks_us() ***** + +Status: PASS + +***** Test 3: ticks_cpu() ***** + +Status: PASS + +***** Test 4: Checking boundary conditions ***** + +PASS +PASS +PASS +PASS +PASS +PASS +PASS +PASS +PASS +PASS