From cd72fb374a11a28d0043293f302d15d28301dfe1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 14 Jun 2024 11:40:29 +1000 Subject: [PATCH] github/workflows: Add workflow to run package tests. All of the runable package tests are run together in the new `ci.sh` function. This is added to a new GitHub workflow to test the packages as part of CI. Eventually it would be good to unify all the package tests to use `unittest`. Signed-off-by: Damien George --- .github/workflows/package_tests.yml | 14 ++++++ tools/ci.sh | 70 +++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 .github/workflows/package_tests.yml diff --git a/.github/workflows/package_tests.yml b/.github/workflows/package_tests.yml new file mode 100644 index 000000000..6f1355926 --- /dev/null +++ b/.github/workflows/package_tests.yml @@ -0,0 +1,14 @@ +name: Package tests + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - name: Setup environment + run: source tools/ci.sh && ci_package_tests_setup + - name: Run tests + run: source tools/ci.sh && ci_package_tests_run diff --git a/tools/ci.sh b/tools/ci.sh index 761491c6e..c5706faa7 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -12,6 +12,76 @@ function ci_commit_formatting_run { tools/verifygitlog.py -v upstream/master..HEAD --no-merges } +######################################################################################## +# package tests + +MICROPYTHON=/tmp/micropython/ports/unix/build-standard/micropython + +function ci_package_tests_setup { + git clone https://github.com/micropython/micropython.git /tmp/micropython + + # build mpy-cross and micropython (use -O0 to speed up the build) + make -C /tmp/micropython/mpy-cross -j CFLAGS_EXTRA=-O0 + make -C /tmp/micropython/ports/unix submodules + make -C /tmp/micropython/ports/unix -j CFLAGS_EXTRA=-O0 + + # install unittest + mkdir -p ~/.micropython/lib + cp python-stdlib/shutil/shutil.py ~/.micropython/lib/ + cp -r python-stdlib/unittest/unittest ~/.micropython-lib + tree ~/.micropython +} + +function ci_package_tests_run { + for test in \ + micropython/drivers/storage/sdcard/sdtest.py \ + micropython/xmltok/test_xmltok.py \ + python-ecosys/requests/test_requests.py \ + python-stdlib/argparse/test_argparse.py \ + python-stdlib/base64/test_base64.py \ + python-stdlib/binascii/test_binascii.py \ + python-stdlib/collections-defaultdict/test_defaultdict.py \ + python-stdlib/functools/test_partial.py \ + python-stdlib/functools/test_reduce.py \ + python-stdlib/heapq/test_heapq.py \ + python-stdlib/hmac/test_hmac.py \ + python-stdlib/itertools/test_itertools.py \ + python-stdlib/operator/test_operator.py \ + python-stdlib/os-path/test_path.py \ + python-stdlib/pickle/test_pickle.py \ + python-stdlib/string/test_translate.py \ + python-stdlib/tempfile/test_tempfile.py \ + python-stdlib/time/test_time.py \ + unix-ffi/gettext/test_gettext.py \ + unix-ffi/pwd/test_getpwnam.py \ + unix-ffi/re/test_re.py \ + unix-ffi/time/test_strftime.py \ + ; do + echo "Running test $test" + (cd `dirname $test` && $MICROPYTHON `basename $test`) + if [ $? -ne 0 ]; then + false # make this function return an error code + return + fi + done + + for path in \ + micropython/ucontextlib \ + python-stdlib/pathlib \ + python-stdlib/shutil \ + python-stdlib/unittest-discover/tests \ + ; do + (cd $path && $MICROPYTHON -m unittest) + if [ $? -ne 0 ]; then false; return; fi + done + + (cd micropython/usb/usb-device && $MICROPYTHON -m tests.test_core_buffer) + if [ $? -ne 0 ]; then false; return; fi + + (cd python-ecosys/cbor2 && $MICROPYTHON -m examples.cbor_test) + if [ $? -ne 0 ]; then false; return; fi +} + ######################################################################################## # build packages