From 5c9d907769ee890c5f5f0d27c0f70c71b9387f18 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sun, 30 Jun 2024 14:35:04 +0300 Subject: [PATCH] test: uart driver tests --- .github/workflows/test.yml | 24 ++++++++++++++++++++++++ test/test_uart.py | 25 +++++++++++++++++++++++++ test/test_uart.scenario.yaml | 22 ++++++++++++++++++++++ test/uart/diagram.esp32.json | 17 +++++++++++++++++ test/uart/diagram.esp32c3.json | 16 ++++++++++++++++ test/uart/diagram.esp32c6.json | 16 ++++++++++++++++ test/uart/diagram.esp32h2.json | 24 ++++++++++++++++++++++++ test/uart/diagram.esp32s2.json | 16 ++++++++++++++++ test/uart/diagram.esp32s3.json | 16 ++++++++++++++++ 9 files changed, 176 insertions(+) create mode 100644 test/test_uart.py create mode 100644 test/test_uart.scenario.yaml create mode 100644 test/uart/diagram.esp32.json create mode 100644 test/uart/diagram.esp32c3.json create mode 100644 test/uart/diagram.esp32c6.json create mode 100644 test/uart/diagram.esp32h2.json create mode 100644 test/uart/diagram.esp32s2.json create mode 100644 test/uart/diagram.esp32s3.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 144f05e8..7cb4bbff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -232,3 +232,27 @@ jobs: run: pytest test_i2c.py env: WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }} + + test-uart: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' + - run: pip install -r test/requirements.txt + + - name: Run a Wokwi CI server + uses: wokwi/wokwi-ci-server-action@v1 + + - name: Install Wokwi CLI + run: curl -L https://wokwi.com/ci/install.sh | sh + + - name: Test on Wokwi + working-directory: test + run: pytest test_uart.py + env: + WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }} diff --git a/test/test_uart.py b/test/test_uart.py new file mode 100644 index 00000000..52fe0581 --- /dev/null +++ b/test/test_uart.py @@ -0,0 +1,25 @@ +import subprocess + +import pytest + + +@pytest.mark.parametrize( + "chip", ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"] +) +def test_uart(chip: str): + + # Run the Wokwi CLI + result = subprocess.run( + [ + "wokwi-cli", + "--elf", + f"../bin/{chip}/idf/latest/components/esp_driver_uart/test_apps/uart/firmware.uf2", + "--timeout", + "30000", + "--scenario", + "test_uart.scenario.yaml", + "--diagram-file", + f"uart/diagram.{chip}.json", + ] + ) + assert result.returncode == 0 diff --git a/test/test_uart.scenario.yaml b/test/test_uart.scenario.yaml new file mode 100644 index 00000000..a5e8399c --- /dev/null +++ b/test/test_uart.scenario.yaml @@ -0,0 +1,22 @@ +name: UART Unity Tests +version: 1 +author: Uri Shaked + +steps: + - wait-serial: "Press ENTER to see the list of tests" + - write-serial: "*\n" + - wait-serial: "Waiting for signal: [select to test 'uart' or 'lp_uart' port]!" + - write-serial: "uart\n" + - wait-serial: "Waiting for signal: [select to test 'uart' or 'lp_uart' port]!" + - write-serial: "uart\n" + - wait-serial: "Waiting for signal: [select to test 'uart' or 'lp_uart' port]!" + - write-serial: "uart\n" + - wait-serial: "Waiting for signal: [select to test 'uart' or 'lp_uart' port]!" + - write-serial: "uart\n" + - wait-serial: "Waiting for signal: [select to test 'uart' or 'lp_uart' port]!" + - write-serial: "uart\n" + - wait-serial: "Waiting for signal: [select to test 'uart' or 'lp_uart' port]!" + - write-serial: "uart\n" + - wait-serial: "Waiting for signal: [select to test 'uart' or 'lp_uart' port]!" + - write-serial: "uart\n" + - wait-serial: "7 Tests 0 Failures 0 Ignored" diff --git a/test/uart/diagram.esp32.json b/test/uart/diagram.esp32.json new file mode 100644 index 00000000..ee413f99 --- /dev/null +++ b/test/uart/diagram.esp32.json @@ -0,0 +1,17 @@ +{ + "version": 1, + "author": "Uri Shaked", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-devkit-c-v4", + "id": "esp", + "top": 0, + "left": 0, + "attrs": { "__timingOptimizations": "disable" } + } + ], + "connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ], + "serialMonitor": { "display": "terminal" }, + "dependencies": {} +} \ No newline at end of file diff --git a/test/uart/diagram.esp32c3.json b/test/uart/diagram.esp32c3.json new file mode 100644 index 00000000..7632d0dd --- /dev/null +++ b/test/uart/diagram.esp32c3.json @@ -0,0 +1,16 @@ +{ + "version": 1, + "author": "Uri Shaked", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c3-devkitm-1", + "id": "esp", + "top": -0.3, + "left": -42.18, + "attrs": { "__timingOptimizations": "disable" } + } + ], + "connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ], + "dependencies": {} +} \ No newline at end of file diff --git a/test/uart/diagram.esp32c6.json b/test/uart/diagram.esp32c6.json new file mode 100644 index 00000000..be9c340a --- /dev/null +++ b/test/uart/diagram.esp32c6.json @@ -0,0 +1,16 @@ +{ + "version": 1, + "author": "Uri Shaked", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c6-devkitc-1", + "id": "esp", + "top": 5.29, + "left": 4.12, + "attrs": { "__timingOptimizations": "disable" } + } + ], + "connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ], + "dependencies": {} +} \ No newline at end of file diff --git a/test/uart/diagram.esp32h2.json b/test/uart/diagram.esp32h2.json new file mode 100644 index 00000000..54f649de --- /dev/null +++ b/test/uart/diagram.esp32h2.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "author": "Uri Shaked", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-h2-devkitm-1", "id": "esp", "top": 2.23, "left": -5.1, "attrs": {"__timingOptimizations": "disable"} }, + { + "type": "wokwi-slide-potentiometer", + "id": "pot1", + "top": 57.8, + "left": -235.8, + "rotate": 180, + "attrs": { "travelLength": "30", "value": "512" } + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "esp:GND.2", "pot1:GND", "black", [ "h0" ] ], + [ "esp:3V3", "pot1:VCC", "red", [ "v0", "h-19.2", "v105.6" ] ], + [ "esp:4", "pot1:SIG", "green", [ "h0" ] ] + ], + "dependencies": {} +} \ No newline at end of file diff --git a/test/uart/diagram.esp32s2.json b/test/uart/diagram.esp32s2.json new file mode 100644 index 00000000..04cc9ffa --- /dev/null +++ b/test/uart/diagram.esp32s2.json @@ -0,0 +1,16 @@ +{ + "version": 1, + "author": "Uri Shaked", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-s2-devkitm-1", + "id": "esp", + "top": -13.91, + "left": 4.57, + "attrs": { "__timingOptimizations": "disable" } + } + ], + "connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ], + "dependencies": {} +} \ No newline at end of file diff --git a/test/uart/diagram.esp32s3.json b/test/uart/diagram.esp32s3.json new file mode 100644 index 00000000..ab7afdf7 --- /dev/null +++ b/test/uart/diagram.esp32s3.json @@ -0,0 +1,16 @@ +{ + "version": 1, + "author": "Uri Shaked", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-s3-devkitc-1", + "id": "esp", + "top": -0.18, + "left": 4.57, + "attrs": { "__timingOptimizations": "disable", "psramSize": "16" } + } + ], + "connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ], + "dependencies": {} +} \ No newline at end of file