Skip to content

Commit 644ae1a

Browse files
ATmobicaATmobica
authored and
ATmobica
committed
[OIS] Add Open IoT SDK unit-tests
Adaptation changes: Exclude LwIP initialization for Open IoT SDK platform in unit tests implementation. Skip read/write chunking tests in controller component. Skip CommissionerDUTVectors test in credentials component. Skip ControllerTests - #23747 issue Skip CHIP stack initialization in FailSafeContext test. Add Open IoT SDK platform unit-tests application in src/test_driver/openiotsdk/unit-tests directory. Add unit tests to Open IoT SDK example script, CI workflow and VScode tasks. Add unit-tests application documentation. Signed-off-by: ATmobica <artur.tynecki@arm.com>
1 parent d516e76 commit 644ae1a

File tree

21 files changed

+988
-17
lines changed

21 files changed

+988
-17
lines changed

.github/workflows/examples-openiotsdk.yaml

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ concurrency:
2626
jobs:
2727
openiotsdk:
2828
name: Open IoT SDK examples building
29-
timeout-minutes: 90
29+
timeout-minutes: 140
3030

3131
env:
3232
TEST_NETWORK_NAME: OIStest
@@ -87,6 +87,12 @@ jobs:
8787
examples/lock-app/openiotsdk/build/chip-openiotsdk-lock-app-example.elf \
8888
/tmp/bloat_reports/
8989
90+
- name: Build unit tests
91+
id: build_unit_tests
92+
timeout-minutes: 10
93+
run: |
94+
scripts/examples/openiotsdk_example.sh unit-tests
95+
9096
- name: Test shell example
9197
if: steps.build_shell.outcome == 'success'
9298
timeout-minutes: 5
@@ -100,3 +106,9 @@ jobs:
100106
scripts/setup/openiotsdk/network_setup.sh -n $TEST_NETWORK_NAME up
101107
scripts/run_in_ns.sh ${TEST_NETWORK_NAME}ns scripts/examples/openiotsdk_example.sh -C test -n ${TEST_NETWORK_NAME}tap lock-app
102108
scripts/setup/openiotsdk/network_setup.sh -n $TEST_NETWORK_NAME down
109+
110+
- name: Run unit tests
111+
if: steps.build_unit_tests.outcome == 'success' && github.event_name == 'pull_request'
112+
timeout-minutes: 90
113+
run: |
114+
scripts/examples/openiotsdk_example.sh -C run unit-tests

.vscode/launch.json

+47
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,20 @@
439439
"runToEntryPoint": "main",
440440
"preLaunchTask": "Debug Open IoT SDK example",
441441
"showDevDebugOutput": "parsed"
442+
},
443+
{
444+
"name": "Debug Open IoT SDK unit-tests application",
445+
"type": "cortex-debug",
446+
"request": "launch",
447+
"cwd": "${workspaceRoot}/src/test_driver/openiotsdk/unit-tests",
448+
"executable": "./build/${input:openiotsdkUnittest}.elf",
449+
"armToolchainPath": "${env:ARM_GCC_TOOLCHAIN_PATH}/bin",
450+
"servertype": "external",
451+
"gdbTarget": ":31627", //GDBserver port on FVP
452+
"overrideLaunchCommands": ["-enable-pretty-printing"],
453+
"runToEntryPoint": "main",
454+
"preLaunchTask": "Debug Open IoT SDK unit-tests",
455+
"showDevDebugOutput": "parsed"
442456
}
443457
],
444458
"inputs": [
@@ -507,6 +521,39 @@
507521
"id": "openiotsdkRemoteHost",
508522
"description": "Type the hostname/IP address of external GDB target that you want to connect to. Leave blank for internal GDB server",
509523
"default": ""
524+
},
525+
{
526+
"type": "pickString",
527+
"id": "openiotsdkUnittest",
528+
"description": "What Open IoT SDK unit test do you want to use?",
529+
"options": [
530+
"accesstest",
531+
"AppTests",
532+
"ASN1Tests",
533+
"BDXTests",
534+
"ChipCryptoTests",
535+
"ControllerTests",
536+
"CoreTests",
537+
"CredentialsTest",
538+
"DataModelTests",
539+
"InetLayerTests",
540+
"MdnsTests",
541+
"MessagingLayerTests",
542+
"MinimalMdnsCoreTests",
543+
"MinimalMdnsRecordsTests",
544+
"MinimalMdnsRespondersTests",
545+
"PlatformTests",
546+
"RawTransportTests",
547+
"RetransmitTests",
548+
"SecureChannelTests",
549+
"SetupPayloadTests",
550+
"SupportTests",
551+
"SystemLayerTests",
552+
"TestShell",
553+
"TransportLayerTests",
554+
"UserDirectedCommissioningTests"
555+
],
556+
"default": "accesstest"
510557
}
511558
]
512559
}

.vscode/tasks.json

+90
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@
262262
}
263263
}
264264
},
265+
{
266+
"label": "Build Open IoT SDK unit-tests",
267+
"type": "shell",
268+
"command": "scripts/examples/openiotsdk_example.sh",
269+
"args": ["-Cbuild", "-d${input:openiotsdkDebugMode}", "unit-tests"],
270+
"group": "build",
271+
"problemMatcher": {
272+
"pattern": {
273+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
274+
"file": 1,
275+
"line": 2,
276+
"message": 5
277+
}
278+
}
279+
},
265280
{
266281
"label": "Run Open IoT SDK example",
267282
"type": "shell",
@@ -283,6 +298,21 @@
283298
}
284299
}
285300
},
301+
{
302+
"label": "Run Open IoT SDK unit-tests",
303+
"type": "shell",
304+
"command": "scripts/examples/openiotsdk_example.sh",
305+
"args": ["-Crun", "unit-tests", "${input:openiotsdkUnitTest}"],
306+
"group": "test",
307+
"problemMatcher": {
308+
"pattern": {
309+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
310+
"file": 1,
311+
"line": 2,
312+
"message": 5
313+
}
314+
}
315+
},
286316
{
287317
"label": "Test Open IoT SDK example",
288318
"type": "shell",
@@ -331,6 +361,32 @@
331361
"endsPattern": "^.*Connected to localhost*"
332362
}
333363
}
364+
},
365+
{
366+
"label": "Debug Open IoT SDK unit-tests",
367+
"type": "shell",
368+
"command": "scripts/examples/openiotsdk_example.sh",
369+
"args": [
370+
"-Crun",
371+
"-dtrue",
372+
"unit-tests",
373+
"${input:openiotsdkUnitTest}"
374+
],
375+
"group": "none",
376+
"isBackground": true,
377+
"problemMatcher": {
378+
"pattern": {
379+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
380+
"file": 1,
381+
"line": 2,
382+
"message": 5
383+
},
384+
"background": {
385+
"activeOnStart": true,
386+
"beginsPattern": "^.*Trying*",
387+
"endsPattern": "^.*Connected to localhost*"
388+
}
389+
}
334390
}
335391
],
336392
"inputs": [
@@ -390,6 +446,40 @@
390446
"options": ["shell", "lock-app"],
391447
"default": "shell"
392448
},
449+
{
450+
"type": "pickString",
451+
"id": "openiotsdkUnitTest",
452+
"description": "What unit test do you want to use?",
453+
"options": [
454+
"all",
455+
"accesstest",
456+
"AppTests",
457+
"ASN1Tests",
458+
"BDXTests",
459+
"ChipCryptoTests",
460+
"ControllerTests",
461+
"CoreTests",
462+
"CredentialsTest",
463+
"DataModelTests",
464+
"InetLayerTests",
465+
"MdnsTests",
466+
"MessagingLayerTests",
467+
"MinimalMdnsCoreTests",
468+
"MinimalMdnsRecordsTests",
469+
"MinimalMdnsRespondersTests",
470+
"PlatformTests",
471+
"RawTransportTests",
472+
"RetransmitTests",
473+
"SecureChannelTests",
474+
"SetupPayloadTests",
475+
"SupportTests",
476+
"SystemLayerTests",
477+
"TestShell",
478+
"TransportLayerTests",
479+
"UserDirectedCommissioningTests"
480+
],
481+
"default": "all"
482+
},
393483
{
394484
"type": "promptString",
395485
"id": "openiotsdkNetworkNamespace",

scripts/examples/openiotsdk_example.sh

+102-9
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ TELNET_TERMINAL_PORT=5000
4040
FAILED_TESTS=0
4141
FVP_NETWORK="user"
4242

43+
readarray -t TEST_NAMES <"$CHIP_ROOT"/src/test_driver/openiotsdk/unit-tests/testnames.txt
44+
4345
function show_usage() {
4446
cat <<EOF
45-
Usage: $0 [options] example
47+
Usage: $0 [options] example [test_name]
4648
47-
Build, run or test the Open IoT SDK example.
49+
Build, run or test the Open IoT SDK examples and unit-tests.
4850
4951
Options:
5052
-h,--help Show this help
@@ -58,6 +60,18 @@ Options:
5860
Examples:
5961
shell
6062
lock-app
63+
unit-tests
64+
65+
You can run individual test suites of unit tests by using their names [test_name] with the run command:
66+
67+
EOF
68+
cat "$CHIP_ROOT"/src/test_driver/openiotsdk/unit-tests/testnames.txt
69+
echo ""
70+
cat <<EOF
71+
Or you can use all tests suites with <all> parameter as [test_name]
72+
73+
The "test" command can be used for all supported examples expect the unit-tests.
74+
6175
EOF
6276
}
6377

@@ -112,7 +126,11 @@ function run_fvp() {
112126
exit 1
113127
fi
114128

115-
EXAMPLE_EXE_PATH="$BUILD_PATH/chip-openiotsdk-$EXAMPLE-example.elf"
129+
if [[ $IS_TEST -eq 0 ]]; then
130+
EXAMPLE_EXE_PATH="$BUILD_PATH/chip-openiotsdk-$EXAMPLE-example.elf"
131+
else
132+
EXAMPLE_EXE_PATH="$BUILD_PATH/$EXAMPLE.elf"
133+
fi
116134

117135
# Check if executable file exists
118136
if ! [ -f "$EXAMPLE_EXE_PATH" ]; then
@@ -138,10 +156,30 @@ function run_fvp() {
138156
"$FVP_BIN" "${RUN_OPTIONS[@]}" -f "$FVP_CONFIG_FILE" --application "$EXAMPLE_EXE_PATH" >/dev/null 2>&1 &
139157
FVP_PID=$!
140158
sleep 1
141-
telnet localhost "$TELNET_TERMINAL_PORT"
159+
160+
if [[ $IS_TEST -eq 1 ]]; then
161+
set +e
162+
expect <<EOF
163+
set timeout 1800
164+
set retcode -1
165+
spawn telnet localhost ${TELNET_TERMINAL_PORT}
166+
expect -re {Test status: (-?\d+)} {
167+
set retcode \$expect_out(1,string)
168+
}
169+
expect "Open IoT SDK unit-tests completed"
170+
set retcode [expr -1*\$retcode]
171+
exit \$retcode
172+
EOF
173+
RETCODE=$?
174+
FAILED_TESTS=$(expr "$FAILED_TESTS" + "$RETCODE")
175+
echo "$(jq '. += {($testname): {failed: $result}}' --arg testname "$EXAMPLE" --arg result "$RETCODE" "$EXAMPLE_PATH"/test_report.json)" >"$EXAMPLE_PATH"/test_report.json
176+
else
177+
telnet localhost "$TELNET_TERMINAL_PORT"
178+
fi
142179

143180
# stop the fvp
144181
kill -9 "$FVP_PID" || true
182+
set -e
145183
sleep 1
146184
}
147185

@@ -246,7 +284,7 @@ if [[ $# -lt 1 ]]; then
246284
fi
247285

248286
case "$1" in
249-
shell | lock-app)
287+
shell | unit-tests | lock-app)
250288
EXAMPLE=$1
251289
;;
252290
*)
@@ -256,6 +294,29 @@ case "$1" in
256294
;;
257295
esac
258296

297+
if [[ "$EXAMPLE" == "unit-tests" ]]; then
298+
if [ ! -z "$2" ]; then
299+
if [[ " ${TEST_NAMES[*]} " =~ " $2 " ]]; then
300+
if [[ "$COMMAND" != *"run"* ]]; then
301+
echo "Test suites can only accept --command run"
302+
show_usage
303+
exit 2
304+
fi
305+
EXAMPLE=$2
306+
echo "Run specific unit test $EXAMPLE"
307+
elif [[ "$2" == "all" ]]; then
308+
echo "Use all unit tests"
309+
else
310+
echo " Wrong unit test name"
311+
show_usage
312+
exit 2
313+
fi
314+
else
315+
echo "Use all unit tests"
316+
fi
317+
IS_TEST=1
318+
fi
319+
259320
case "$COMMAND" in
260321
build | run | test | build-run) ;;
261322
*)
@@ -266,7 +327,16 @@ case "$COMMAND" in
266327
esac
267328

268329
TOOLCHAIN_PATH="toolchains/toolchain-$TOOLCHAIN.cmake"
269-
EXAMPLE_PATH="$CHIP_ROOT/examples/$EXAMPLE/openiotsdk"
330+
331+
if [[ $IS_TEST -eq 0 ]]; then
332+
EXAMPLE_PATH="$CHIP_ROOT/examples/$EXAMPLE/openiotsdk"
333+
else
334+
EXAMPLE_PATH="$CHIP_ROOT/src/test_driver/openiotsdk/unit-tests"
335+
if [[ -f $EXAMPLE_PATH/test_report.json ]]; then
336+
rm -rf "$EXAMPLE_PATH"/test_report.json
337+
fi
338+
echo "{}" >"$EXAMPLE_PATH"/test_report.json
339+
fi
270340

271341
if [ -z "$BUILD_PATH" ]; then
272342
BUILD_PATH="$EXAMPLE_PATH/build"
@@ -277,12 +347,35 @@ if [[ "$COMMAND" == *"build"* ]]; then
277347
fi
278348

279349
if [[ "$COMMAND" == *"run"* ]]; then
280-
run_fvp
350+
# If user wants to run unit-tests we need to loop through all test names
351+
if [[ "$EXAMPLE" == "unit-tests" ]]; then
352+
if "$DEBUG"; then
353+
echo "You have to specify the test suites to run in debug mode"
354+
show_usage
355+
exit 2
356+
else
357+
for NAME in "${TEST_NAMES[@]}"; do
358+
EXAMPLE=$NAME
359+
echo "$EXAMPLE_PATH"
360+
echo "Run specific unit test $EXAMPLE"
361+
run_fvp
362+
done
363+
echo "Failed tests total: $FAILED_TESTS"
364+
fi
365+
else
366+
run_fvp
367+
fi
281368
fi
282369

283370
if [[ "$COMMAND" == *"test"* ]]; then
284-
IS_TEST=1
285-
run_test
371+
if [[ "$EXAMPLE" == "unit-tests" ]]; then
372+
echo "The test command can not be applied to the unit-tests example"
373+
show_usage
374+
exit 2
375+
else
376+
IS_TEST=1
377+
run_test
378+
fi
286379
fi
287380

288381
if [[ $IS_TEST -eq 1 ]]; then

0 commit comments

Comments
 (0)