1
0
Fork 0

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 <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-12-04 19:33:05 +00:00 committed by Daniel Thompson
parent 3fb1faceab
commit f1f5cc9e0c
5 changed files with 131 additions and 7 deletions

44
.github/workflows/sim.yml vendored Normal file
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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')

8
wasp/requirements.txt Normal file
View file

@ -0,0 +1,8 @@
cbor
click
numpy
pexpect
Pillow
pyserial
pysdl2
pytest