From f1f5cc9e0c113bf44c7ca2ce58ed1c41089a1b7f Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Fri, 4 Dec 2020 19:33:05 +0000 Subject: [PATCH] simulator: Introduce fully automatic testint Currently the tests do little more than fire up the simulator and switch into (and out of) the built in applications. However this is useful and allows us to fully integrate as a CI job. Unfortunately the numpy warning from pysdl2 mean we have been forced to disable all warnings to prevent pytest from collecting and reporting them. Signed-off-by: Daniel Thompson --- .github/workflows/sim.yml | 44 ++++++++++++++++++++ Makefile | 20 ++++++--- docs/install.rst | 2 +- wasp/boards/simulator/test_smoke.py | 64 +++++++++++++++++++++++++++++ wasp/requirements.txt | 8 ++++ 5 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/sim.yml create mode 100644 wasp/boards/simulator/test_smoke.py create mode 100644 wasp/requirements.txt diff --git a/.github/workflows/sim.yml b/.github/workflows/sim.yml new file mode 100644 index 0000000..03c9791 --- /dev/null +++ b/.github/workflows/sim.yml @@ -0,0 +1,44 @@ +name: wasp-os simulator tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout files + id: checkout-files + uses: actions/checkout@v2 + + - name: Check the cached python downloads + id: cache-modules + uses: actions/cache@v2 + env: + cache-name: cache-toolchain + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('wasp/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip-${{ hashFiles('wasp/requirements.txt') }} + + - name: Install packages + id: install-packages + run: | + sudo apt-get update + sudo apt-get install libsdl2-2.0.0 + + - name: Install python modules + id: install-modules + run: | + pip3 install -r wasp/requirements.txt + + - name: Run the simulator tests + id: run-tests + run: | + PYTEST=$HOME/.local/bin/pytest \ + SDL_VIDEODRIVER=dummy \ + make check diff --git a/Makefile b/Makefile index 470de25..0a1a517 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ export PYTHONPATH := $(PWD)/tools/nrfutil:$(PWD)/tools/intelhex:$(PYTHONPATH) +PYTHON ?= python3 +PYTEST ?= pytest-3 + all : bootloader reloader micropython # If BOARD is undefined then set it up so that expanding it issues an @@ -33,13 +36,13 @@ submodules : bootloader: build-$(BOARD_SAFE) $(RM) bootloader/_build-$(BOARD)_nrf52832//$(BOARD)_nrf52832_bootloader-*-nosd.hex $(MAKE) -C bootloader/ BOARD=$(BOARD)_nrf52832 all genhex - python3 tools/hexmerge.py \ + $(PYTHON) tools/hexmerge.py \ bootloader/_build-$(BOARD)_nrf52832/$(BOARD)_nrf52832_bootloader-*-nosd.hex \ bootloader/lib/softdevice/s132_nrf52_6.1.1/s132_nrf52_6.1.1_softdevice.hex \ -o build-$(BOARD)/bootloader.hex - python3 tools/hex2c.py build-$(BOARD)/bootloader.hex > \ + $(PYTHON) tools/hex2c.py build-$(BOARD)/bootloader.hex > \ reloader/src/boards/$(BOARD)/bootloader.h - python3 -m nordicsemi dfu genpkg \ + $(PYTHON) -m nordicsemi dfu genpkg \ --bootloader bootloader/_build-$(BOARD)_nrf52832//$(BOARD)_nrf52832_bootloader-*-nosd.hex \ --softdevice bootloader/lib/softdevice/s132_nrf52_6.1.1/s132_nrf52_6.1.1_softdevice.hex \ build-$(BOARD)/bootloader-daflasher.zip @@ -63,7 +66,7 @@ micropython: build-$(BOARD_SAFE) wasp/boards/$(BOARD_SAFE)/watch.py MICROPY_VFS_LFS2=1 \ FROZEN_MANIFEST=$(PWD)/wasp/boards/$(BOARD)/manifest.py \ USER_C_MODULES=$(PWD)/wasp/modules - python3 -m nordicsemi dfu genpkg \ + $(PYTHON) -m nordicsemi dfu genpkg \ --dev-type 0x0052 \ --application micropython/ports/nrf/build-$(BOARD)-s132/firmware.hex \ build-$(BOARD)/micropython.zip @@ -72,7 +75,7 @@ build-$(BOARD_SAFE): mkdir -p build-$(BOARD) dfu: - python3 -m nordicsemi dfu serial --package micropython.zip --port /dev/ttyACM0 + $(PYTHON) -m nordicsemi dfu serial --package micropython.zip --port /dev/ttyACM0 flash: pyocd erase -t nrf52 --mass @@ -93,7 +96,12 @@ docs: sim: PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=.:wasp/boards/simulator:wasp \ - python3 -i wasp/boards/simulator/main.py + $(PYTHON) -i wasp/boards/simulator/main.py + +check: + PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=.:wasp/boards/simulator:wasp \ + $(PYTEST) -v -W ignore wasp/boards/simulator + .PHONY: bootloader reloader docs micropython diff --git a/docs/install.rst b/docs/install.rst index 4b8b7a4..68fc0f7 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -36,7 +36,7 @@ with pip instead: .. code-block:: sh - pip3 install --user cbor click numpy pexpect Pillow pyserial pysdl2 + pip3 install --user -r wasp/requirements.txt You will also need a toolchain for the Arm Cortex-M4. wasp-os is developed and tested using the `GNU-RM toolchain diff --git a/wasp/boards/simulator/test_smoke.py b/wasp/boards/simulator/test_smoke.py new file mode 100644 index 0000000..6dd2757 --- /dev/null +++ b/wasp/boards/simulator/test_smoke.py @@ -0,0 +1,64 @@ +import pytest +import time +import wasp + +def step(): + wasp.system._tick() + wasp.machine.deepsleep() +wasp.system.step = step + +def play(appname): + system = wasp.system + system.switch(system.apps[appname]) + for i in range(4): + system.step() + time.sleep(0.125) + system.switch(system.quick_ring[0]) +wasp.system.play = play + +wasp.system.apps = {} +for app in wasp.system.quick_ring + wasp.system.launcher_ring: + wasp.system.apps[app.NAME] = app + +@pytest.fixture +def system(): + system = wasp.system + if system.app != system.quick_ring[0]: + system.switch(system.quick_ring[0]) + system.step() + + return system + +def test_step(system): + system.step() + +def test_quick_ring(system): + names = [ x.NAME for x in system.quick_ring ] + assert('Clock' in names) + assert('Steps' in names) + assert('Timer' in names) + assert('Heart' in names) + +def test_launcher_ring(system): + names = [ x.NAME for x in system.launcher_ring ] + assert('Self Test' in names) + assert('Settings' in names) + assert('Torch' in names) + +def test_steps(system): + system.play('Steps') + +def test_timer(system): + system.play('Timer') + +def test_heart(system): + system.play('Heart') + +def test_self_test(system): + system.play('Self Test') + +def test_settings(system): + system.play('Settings') + +def test_torch(system): + system.play('Torch') diff --git a/wasp/requirements.txt b/wasp/requirements.txt new file mode 100644 index 0000000..e64a397 --- /dev/null +++ b/wasp/requirements.txt @@ -0,0 +1,8 @@ +cbor +click +numpy +pexpect +Pillow +pyserial +pysdl2 +pytest