Skip to content

Commit 01752c6

Browse files
committed
ci(wokwi): Support wokwi
1 parent 140cb2f commit 01752c6

20 files changed

+152
-150
lines changed

.github/workflows/hil.yml

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
name: Run tests
22

33
on:
4-
pull_request_target:
4+
pull_request:
55
types: [opened, reopened, synchronize, labeled]
6-
branches:
7-
- master
86

97
schedule:
108
- cron: '0 2 * * *'
119

1210
env:
1311
MAX_CHUNKS: 15
1412
WOKWI_TIMEOUT: 120000 # Milliseconds
13+
WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }}
1514

1615
concurrency:
1716
group: hil-${{github.event.pull_request.number || github.ref}}
@@ -32,8 +31,6 @@ jobs:
3231
steps:
3332
- name: Checkout Repository
3433
uses: actions/checkout@v4
35-
with:
36-
ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR
3734

3835
- name: Generate Chunks matrix
3936
id: gen-chunks
@@ -87,10 +84,12 @@ jobs:
8784
path: |
8885
~/.build_skipped
8986
~/.arduino/tests/**/build*.tmp/*.bin
87+
~/.arduino/tests/**/build*.tmp/*.elf
9088
~/.arduino/tests/**/build*.tmp/*.json
9189
9290
wokwi-test:
9391
needs: [gen_chunks, build]
92+
if: github.event_name == 'schedule'
9493
name: ${{matrix.chip}}-Wokwi_Test#${{matrix.chunks}}
9594
strategy:
9695
fail-fast: false
@@ -106,8 +105,8 @@ jobs:
106105
uses: actions/download-artifact@v4
107106
with:
108107
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
109-
path: ~/.arduino/tests/
110-
108+
path: ~/
109+
111110
- name: Install Wokwi CLI
112111
run: curl -L https://wokwi.com/ci/install.sh | sh
113112

@@ -123,12 +122,21 @@ jobs:
123122
run: |
124123
bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -w ${{env.WOKWI_TIMEOUT}}
125124
125+
- name: Check if tests were skipped
126+
id: check-test-skipped
127+
run: |
128+
if [ -f ~/.test_skipped ]; then
129+
echo "skipped=true" >> $GITHUB_OUTPUT
130+
else
131+
echo "skipped=false" >> $GITHUB_OUTPUT
132+
fi
133+
126134
- name: Upload test result artifacts
127135
uses: actions/upload-artifact@v4
128-
if: always()
136+
if: ${{ always() && steps.check-test-skipped.outputs.skipped == 'false' }}
129137
with:
130138
name: wokwi_results-${{matrix.chip}}-${{matrix.chunks}}
131-
path: tests/*/*.xml
139+
path: tests/**/*.xml
132140

133141
hardware-test:
134142
needs: [gen_chunks, build]

tests/gpio/test_gpio.py

-2
This file was deleted.
File renamed without changes.
File renamed without changes.

tests/gpio/gpio.ino renamed to tests/validation/gpio/gpio.ino

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ void test_button()
2424
}
2525
delay(10);
2626
}
27-
TEST_ASSERT_EQUAL(3, count);
2827
}
2928

3029
void setup()
3130
{
3231
Serial.begin(115200);
33-
UNITY_BEGIN();
3432
pinMode(BTN, INPUT_PULLUP);
35-
RUN_TEST(test_button);
36-
UNITY_END();
33+
test_button();
3734
}
3835

3936
void loop()

tests/gpio/scenario.yaml renamed to tests/validation/gpio/scenario.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ author: Jan Prochazka ([email protected])
55
steps:
66
- wait-serial: 'Button test'
77

8-
# Delay 1s (to make sure the test is ready to start)
8+
# Need for 1s delay for scenario to run properly
99
- delay: 1000ms
10+
1011
# Press once
1112
- set-control:
1213
part-id: btn1

tests/validation/gpio/test_gpio.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def test_gpio(dut):
2+
dut.expect_exact("Button test")
3+
dut.expect_exact("Button pressed 1 times")
4+
dut.expect_exact("Button pressed 2 times")
5+
dut.expect_exact("Button pressed 3 times")
File renamed without changes.

tests/validation/wifi/.skip.hardware

Whitespace-only changes.

tests/validation/wifi/.skip.qemu

Whitespace-only changes.

tests/validation/wifi/test_wifi.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test_wifi(dut):
2+
dut.expect_exact("WiFi connected")
3+
dut.expect_exact("IP address:")

tests/validation/wifi/wifi.ino

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* This sketch shows the WiFi event usage
3+
*
4+
*/
5+
6+
/*
7+
* WiFi Events
8+
9+
0 ARDUINO_EVENT_WIFI_READY < ESP32 WiFi ready
10+
1 ARDUINO_EVENT_WIFI_SCAN_DONE < ESP32 finish scanning AP
11+
2 ARDUINO_EVENT_WIFI_STA_START < ESP32 station start
12+
3 ARDUINO_EVENT_WIFI_STA_STOP < ESP32 station stop
13+
4 ARDUINO_EVENT_WIFI_STA_CONNECTED < ESP32 station connected to AP
14+
5 ARDUINO_EVENT_WIFI_STA_DISCONNECTED < ESP32 station disconnected from AP
15+
6 ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE < the auth mode of AP connected by ESP32 station changed
16+
7 ARDUINO_EVENT_WIFI_STA_GOT_IP < ESP32 station got IP from connected AP
17+
8 ARDUINO_EVENT_WIFI_STA_LOST_IP < ESP32 station lost IP and the IP is reset to 0
18+
9 ARDUINO_EVENT_WPS_ER_SUCCESS < ESP32 station wps succeeds in enrollee mode
19+
10 ARDUINO_EVENT_WPS_ER_FAILED < ESP32 station wps fails in enrollee mode
20+
11 ARDUINO_EVENT_WPS_ER_TIMEOUT < ESP32 station wps timeout in enrollee mode
21+
12 ARDUINO_EVENT_WPS_ER_PIN < ESP32 station wps pin code in enrollee mode
22+
13 ARDUINO_EVENT_WIFI_AP_START < ESP32 soft-AP start
23+
14 ARDUINO_EVENT_WIFI_AP_STOP < ESP32 soft-AP stop
24+
15 ARDUINO_EVENT_WIFI_AP_STACONNECTED < a station connected to ESP32 soft-AP
25+
16 ARDUINO_EVENT_WIFI_AP_STADISCONNECTED < a station disconnected from ESP32 soft-AP
26+
17 ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED < ESP32 soft-AP assign an IP to a connected station
27+
18 ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED < Receive probe request packet in soft-AP interface
28+
19 ARDUINO_EVENT_WIFI_AP_GOT_IP6 < ESP32 ap interface v6IP addr is preferred
29+
19 ARDUINO_EVENT_WIFI_STA_GOT_IP6 < ESP32 station interface v6IP addr is preferred
30+
20 ARDUINO_EVENT_ETH_START < ESP32 ethernet start
31+
21 ARDUINO_EVENT_ETH_STOP < ESP32 ethernet stop
32+
22 ARDUINO_EVENT_ETH_CONNECTED < ESP32 ethernet phy link up
33+
23 ARDUINO_EVENT_ETH_DISCONNECTED < ESP32 ethernet phy link down
34+
24 ARDUINO_EVENT_ETH_GOT_IP < ESP32 ethernet got IP from connected AP
35+
19 ARDUINO_EVENT_ETH_GOT_IP6 < ESP32 ethernet interface v6IP addr is preferred
36+
25 ARDUINO_EVENT_MAX
37+
*/
38+
39+
#include <WiFi.h>
40+
41+
const char *ssid = "Wokwi-GUEST";
42+
const char *password = "";
43+
44+
// WARNING: This function is called from a separate FreeRTOS task (thread)!
45+
void WiFiEvent(WiFiEvent_t event) {
46+
Serial.printf("[WiFi-event] event: %d\n", event);
47+
48+
switch (event) {
49+
case ARDUINO_EVENT_WIFI_READY: Serial.println("WiFi interface ready"); break;
50+
case ARDUINO_EVENT_WIFI_SCAN_DONE: Serial.println("Completed scan for access points"); break;
51+
case ARDUINO_EVENT_WIFI_STA_START: Serial.println("WiFi client started"); break;
52+
case ARDUINO_EVENT_WIFI_STA_STOP: Serial.println("WiFi clients stopped"); break;
53+
case ARDUINO_EVENT_WIFI_STA_CONNECTED: Serial.println("Connected to access point"); break;
54+
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: Serial.println("Disconnected from WiFi access point"); break;
55+
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE: Serial.println("Authentication mode of access point has changed"); break;
56+
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
57+
Serial.print("Obtained IP address: ");
58+
Serial.println(WiFi.localIP());
59+
break;
60+
case ARDUINO_EVENT_WIFI_STA_LOST_IP: Serial.println("Lost IP address and IP address is reset to 0"); break;
61+
case ARDUINO_EVENT_WPS_ER_SUCCESS: Serial.println("WiFi Protected Setup (WPS): succeeded in enrollee mode"); break;
62+
case ARDUINO_EVENT_WPS_ER_FAILED: Serial.println("WiFi Protected Setup (WPS): failed in enrollee mode"); break;
63+
case ARDUINO_EVENT_WPS_ER_TIMEOUT: Serial.println("WiFi Protected Setup (WPS): timeout in enrollee mode"); break;
64+
case ARDUINO_EVENT_WPS_ER_PIN: Serial.println("WiFi Protected Setup (WPS): pin code in enrollee mode"); break;
65+
case ARDUINO_EVENT_WIFI_AP_START: Serial.println("WiFi access point started"); break;
66+
case ARDUINO_EVENT_WIFI_AP_STOP: Serial.println("WiFi access point stopped"); break;
67+
case ARDUINO_EVENT_WIFI_AP_STACONNECTED: Serial.println("Client connected"); break;
68+
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED: Serial.println("Client disconnected"); break;
69+
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED: Serial.println("Assigned IP address to client"); break;
70+
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED: Serial.println("Received probe request"); break;
71+
case ARDUINO_EVENT_WIFI_AP_GOT_IP6: Serial.println("AP IPv6 is preferred"); break;
72+
case ARDUINO_EVENT_WIFI_STA_GOT_IP6: Serial.println("STA IPv6 is preferred"); break;
73+
case ARDUINO_EVENT_ETH_GOT_IP6: Serial.println("Ethernet IPv6 is preferred"); break;
74+
case ARDUINO_EVENT_ETH_START: Serial.println("Ethernet started"); break;
75+
case ARDUINO_EVENT_ETH_STOP: Serial.println("Ethernet stopped"); break;
76+
case ARDUINO_EVENT_ETH_CONNECTED: Serial.println("Ethernet connected"); break;
77+
case ARDUINO_EVENT_ETH_DISCONNECTED: Serial.println("Ethernet disconnected"); break;
78+
case ARDUINO_EVENT_ETH_GOT_IP: Serial.println("Obtained IP address"); break;
79+
default: break;
80+
}
81+
}
82+
83+
// WARNING: This function is called from a separate FreeRTOS task (thread)!
84+
void WiFiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
85+
Serial.println("WiFi connected");
86+
Serial.println("IP address: ");
87+
Serial.println(IPAddress(info.got_ip.ip_info.ip.addr));
88+
}
89+
90+
void setup() {
91+
Serial.begin(115200);
92+
93+
// delete old config
94+
WiFi.disconnect(true);
95+
96+
delay(1000);
97+
98+
// Examples of different ways to register wifi events;
99+
// these handlers will be called from another thread.
100+
WiFi.onEvent(WiFiEvent);
101+
WiFi.onEvent(WiFiGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
102+
WiFiEventId_t eventID = WiFi.onEvent(
103+
[](WiFiEvent_t event, WiFiEventInfo_t info) {
104+
Serial.print("WiFi lost connection. Reason: ");
105+
Serial.println(info.wifi_sta_disconnected.reason);
106+
},
107+
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED
108+
);
109+
110+
// Remove WiFi event
111+
Serial.print("WiFi Event ID: ");
112+
Serial.println(eventID);
113+
// WiFi.removeEvent(eventID);
114+
115+
WiFi.begin(ssid, password);
116+
117+
Serial.println();
118+
Serial.println();
119+
Serial.println("Wait for WiFi... ");
120+
}
121+
122+
void loop() {
123+
delay(1000);
124+
}

tests/wifi/test_wifi.py

-2
This file was deleted.

tests/wifi/wifi.ino

-132
This file was deleted.

0 commit comments

Comments
 (0)