From c8287823449a263ac11eedd092fe4d7f55878338 Mon Sep 17 00:00:00 2001 From: Hayden Roche Date: Mon, 1 Jul 2024 15:55:31 -0700 Subject: [PATCH] TS-534: Fix card.binary HIL testing. (#153) - Use a single PlatformIO command to build, upload, and test. Previously, we we did this in a few steps because of a problem where the Swan's serial port wasn't ready after uploading and so the test step would fail because it couldn't find the serial port. I was able to reduce this to one step by using the approach described here: https://github.com/platformio/platformio-core/issues/3742 - Fix a Bash typo in the step that cleaned up the Notehub proxy route. - I reinstalled tunnelmole using npm on the Orange Pi, and it's working again. I really don't know what was wrong here. In order for run_tmole.sh to find the tmole executable, I had to add a couple lines to the start of the script so that npm packages are on PATH. - Upgrade the note-arduino version to latest. --- .github/workflows/notecard-binary-tests.yml | 30 ++++++--------------- scripts/{run_tunnelmole.sh => run_tmole.sh} | 3 +++ scripts/wait_for_file.sh | 14 ---------- test/hitl/card.binary/platformio.ini | 19 +++++++++++-- test/hitl/card.binary/wait_for_test_port.py | 14 ++++++++++ 5 files changed, 42 insertions(+), 38 deletions(-) rename scripts/{run_tunnelmole.sh => run_tmole.sh} (96%) delete mode 100755 scripts/wait_for_file.sh create mode 100644 test/hitl/card.binary/wait_for_test_port.py diff --git a/.github/workflows/notecard-binary-tests.yml b/.github/workflows/notecard-binary-tests.yml index a967dcfb..480dd2c9 100644 --- a/.github/workflows/notecard-binary-tests.yml +++ b/.github/workflows/notecard-binary-tests.yml @@ -35,9 +35,6 @@ jobs: DELETE_NOTEHUB_ROUTES: true # CREATE_NOTEHUB_ROUTES set to false to use the already created routes on notehub CREATE_NOTEHUB_ROUTES: true - # FLASH_TEST_FIRMWARE set to false to skip flashing firmware to the Host (Swan). - # Be sure to press reset on Swan before running the workflow unless you deliberately want to skip running the tests. - FLASH_TEST_FIRMWARE: true # START_MD5SRV set to false to skip starting the MD5 server. There should be one # already running locally with MD5SRV_PORT/ADDRESS/TOKEN set correspondingly. START_MD5SRV: true @@ -61,7 +58,6 @@ jobs: echo NOTEHUB_PROXY_ROUTE_ALIAS=$NOTEHUB_PROXY_ROUTE_ALIAS - name: Install PlatformIO dependencies - if: env.FLASH_TEST_FIRMWARE!='false' run: | python3 -m venv venv # python venv is also used by the md5server, so this comes first. source venv/bin/activate @@ -80,21 +76,11 @@ jobs: mkdir md5srv-files ./scripts/run_md5srv.sh - - name: Build and upload test firmware - if: env.FLASH_TEST_FIRMWARE!='false' - run: | - source venv/bin/activate - export PLATFORMIO_BUILD_FLAGS="'-D NOTEHUB_PROXY_ROUTE_ALIAS=\"$NOTEHUB_PROXY_ROUTE_ALIAS\"' '-D PRODUCT_UID=\"$NOTEHUB_PRODUCT_UID\"'" - echo "build flags $PLATFORMIO_BUILD_FLAGS" - timeout 10 ./scripts/wait_for_file.sh "$STLINK_PROGRAMMER_PORT" - platformio test -e debug --without-testing --upload-port "$STLINK_PROGRAMMER_PORT" --project-dir "$PIO_PROJECT_DIR" - timeout 10 ./scripts/wait_for_file.sh "$SWAN_SERIAL" - - name: Start tunnelmole if: env.START_TUNNELMOLE!='false' run: | rm -f tmole.log - ./scripts/run_tunnelmole.sh + ./scripts/run_tmole.sh - name: Check MD5 server is available run: | @@ -155,13 +141,13 @@ jobs: exit 1 fi - - name: Run tests + - name: Build and upload test firmware and run tests run: | source venv/bin/activate + export PLATFORMIO_BUILD_FLAGS="'-D NOTEHUB_PROXY_ROUTE_ALIAS=\"$NOTEHUB_PROXY_ROUTE_ALIAS\"' '-D PRODUCT_UID=\"$NOTEHUB_PRODUCT_UID\"'" + echo "build flags $PLATFORMIO_BUILD_FLAGS" cd $PIO_PROJECT_DIR platformio test -v -e debug \ - --without-building --without-uploading \ - --test-port "$SWAN_SERIAL" \ --json-output-path test.json \ --junit-output-path test.xml @@ -178,7 +164,7 @@ jobs: - name: Cleanup Notehub proxy route if: always() run: | - if [ "$DELETE_NOTEHUB_ROUTES" == "true" && -n "$NOTEHUB_PROXY_ROUTE_UID" ]; then + if [ "$DELETE_NOTEHUB_ROUTES" == "true" ] && [ -n "$NOTEHUB_PROXY_ROUTE_UID" ]; then echo "Deleting Notehub proxy route." curl -f -s -X DELETE \ -L "https://api.notefile.net/v1/projects/$NOTEHUB_PROJECT_UID/routes/$NOTEHUB_PROXY_ROUTE_UID" \ @@ -196,14 +182,14 @@ jobs: fi - - name: Cleanup tunnelmole + - name: Cleanup tmole if: always() run: | if [ -n "$TMOLE_PID" ]; then - echo "Stopping tunnelmole." + echo "Stopping tmole." kill $TMOLE_PID else - echo "Tunnelmole not running (TMOLE_PID is empty)." + echo "tmole not running (TMOLE_PID is empty)." fi - name: Cleanup MD5 server diff --git a/scripts/run_tunnelmole.sh b/scripts/run_tmole.sh similarity index 96% rename from scripts/run_tunnelmole.sh rename to scripts/run_tmole.sh index 5979d9ba..ef33cacf 100755 --- a/scripts/run_tunnelmole.sh +++ b/scripts/run_tmole.sh @@ -1,5 +1,8 @@ #!/bin/bash +export NVM_DIR=~/.nvm +source ~/.nvm/nvm.sh + if [ -n "$MD5SRV_PORT" ]; then echo "INFO: Using MD5 server port $MD5SRV_PORT." >&2 else diff --git a/scripts/wait_for_file.sh b/scripts/wait_for_file.sh deleted file mode 100755 index faf7189b..00000000 --- a/scripts/wait_for_file.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# $1 filename to wait for -set -e - -if [ -z "$1" ]; then - echo "Expected 1 argument: " - exit 1 -else - echo "Waiting for file $1..." -fi - -while ! test -e "$1"; do - sleep 0.5 -done diff --git a/test/hitl/card.binary/platformio.ini b/test/hitl/card.binary/platformio.ini index 00ef65f8..f0948bf9 100644 --- a/test/hitl/card.binary/platformio.ini +++ b/test/hitl/card.binary/platformio.ini @@ -20,10 +20,25 @@ build_flags = -D UNITY_INCLUDE_PRINT_FORMATTED '-D DEFAULT_NOTEHUB_PROXY_ROUTE_ALIAS="cobstest"' '-D DEFAULT_PRODUCT_UID=""' # don't set the product UID -lib_deps = blues/Blues Wireless Notecard@^1.5.1 +lib_deps = blues/Blues Wireless Notecard@^1.6.0 debug_tool = stlink +upload_protocol = stlink test_framework = unity -test_port = /dev/swan +test_port = /dev/note_c_hil_swan + +; The serial port used for streaming test results from the Swan to the host +; computer takes a second to show up after uploading. This script waits for it +; to show up before running the tests. See https://github.com/platformio/platformio-core/issues/3742. +extra_scripts = post:wait_for_test_port.py + +; We need to pass this down to OpenOCD so that it uses the correct ST-LINK. +; In my (Hayden's) HIL setup, there are many ST-LINKs connected to the same +; machine. Simply specifying the serial port corresponding to a given ST-LINK +; via upload_port doesn't work, so we have to use the specific serial number +; of the ST-LINK we're trying to target. +upload_flags = + -c + hla_serial 0029000F3156501420323443 [env:debug] build_type = debug diff --git a/test/hitl/card.binary/wait_for_test_port.py b/test/hitl/card.binary/wait_for_test_port.py new file mode 100644 index 00000000..34497f76 --- /dev/null +++ b/test/hitl/card.binary/wait_for_test_port.py @@ -0,0 +1,14 @@ +Import("env") + +def after_upload(source, target, env): + port = env.GetProjectOption("test_port") + print("waiting for " + port + " ...") + import serial + while True: + try: + s = serial.Serial(port) + break + except: + pass + +env.AddPostAction("upload", after_upload)