Skip to content

Commit

Permalink
TS-534: Fix card.binary HIL testing. (#153)
Browse files Browse the repository at this point in the history
- 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: platformio/platformio-core#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.
  • Loading branch information
haydenroche5 authored Jul 1, 2024
1 parent 2eac09e commit c828782
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
30 changes: 8 additions & 22 deletions .github/workflows/notecard-binary-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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: |
Expand Down Expand Up @@ -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
Expand All @@ -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" \
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/run_tunnelmole.sh → scripts/run_tmole.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 0 additions & 14 deletions scripts/wait_for_file.sh

This file was deleted.

19 changes: 17 additions & 2 deletions test/hitl/card.binary/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/hitl/card.binary/wait_for_test_port.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c828782

Please sign in to comment.