From c7be471439a59a8f0a0376fba8d709c21b6de15d Mon Sep 17 00:00:00 2001 From: Hayden Roche Date: Thu, 27 Jun 2024 15:45:05 -0700 Subject: [PATCH] wip --- .github/workflows/notecard-binary-tests.yml | 23 ++------------------- scripts/run_lt.sh | 1 + test/hitl/card.binary/platformio.ini | 19 +++++++++++++++-- test/hitl/card.binary/wait_for_test_port.py | 14 +++++++++++++ 4 files changed, 34 insertions(+), 23 deletions(-) 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 948d36e8..a5e67bd7 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,19 +76,6 @@ 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" - # Build the firmware - platformio run -e debug --project-dir "$PIO_PROJECT_DIR" - timeout 10 ./scripts/wait_for_file.sh "$STLINK_PROGRAMMER_PORT" - # Upload the firmware - 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 lt if: env.START_LT!='false' run: | @@ -158,13 +141,11 @@ jobs: exit 1 fi - - name: Run tests + - name: Build and upload test firmware and run tests run: | source venv/bin/activate 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 @@ -181,7 +162,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" \ diff --git a/scripts/run_lt.sh b/scripts/run_lt.sh index 76e6b7d4..48495ef7 100755 --- a/scripts/run_lt.sh +++ b/scripts/run_lt.sh @@ -13,6 +13,7 @@ if ! which lt > /dev/null 2>&1; then fi echo "INFO: Starting lt..." >&2 +# TODO: When the localtunnel server is under heavy load, this can fail and should just be retried a couple times. lt --port $MD5SRV_PORT > lt.log 2>&1 & LT_PID=$! echo "INFO: lt PID is $LT_PID." >&2 diff --git a/test/hitl/card.binary/platformio.ini b/test/hitl/card.binary/platformio.ini index 00ef65f8..9e585bc4 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)