Skip to content

Commit 5134e59

Browse files
committed
Refactor twister scripts for improved environment handling and cleanup messages
1 parent d87306c commit 5134e59

2 files changed

Lines changed: 45 additions & 54 deletions

File tree

samples.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/bin/bash
2+
# Set the path to the twister executable
3+
TWISTER_EXE=""
4+
5+
# Set workspace virtual environment if available
26
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
WORKSPACE_VENV="$SCRIPT_DIR/../.venv"
38
WORKSPACE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
4-
5-
# Set the path to the twister executable
69
TWISTER_EXE="$WORKSPACE_DIR/zephyr/scripts/twister"
710

11+
if [ -x "$WORKSPACE_VENV/bin/python3" ]; then
12+
VENV_SITE="$($WORKSPACE_VENV/bin/python3 -c 'import site; print(site.getsitepackages()[0])')"
13+
export PATH="$WORKSPACE_VENV/bin:$PATH"
14+
export PYTHONPATH="$VENV_SITE${PYTHONPATH:+:$PYTHONPATH}"
15+
fi
16+
817
# Set the path to the test cases directory
918
TEST_CASES_DIR="$SCRIPT_DIR/zephyr/samples"
1019

@@ -44,12 +53,12 @@ find "$OUTPUT_DIR" -name 'app' -exec rm -rf \
4453
{}/../cmake_install.cmake
4554
{}/../CMakeCache.txt' \; 2>/dev/null
4655
find "$OUTPUT_DIR" -name 'app' -exec rm -rf '{}' \; 2>/dev/null
47-
echo "Twister output cleanup completed successfully."
56+
echo "Twister samples output cleanup completed successfully."
4857

4958
# Check if twister ran successfully
5059
if [ $? -eq 0 ]; then
51-
echo "Twister testing completed successfully."
60+
echo "Twister samples testing completed successfully."
5261
else
53-
echo "Twister testing failed."
62+
echo "Twister samples testing failed."
5463
exit 1
5564
fi

unittest.sh

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,49 @@ fi
1616

1717
# Set the path to the test cases directory
1818
TEST_CASES_DIR="$SCRIPT_DIR/zephyr/tests"
19-
NATIVE_SIM_TEST_CASES_DIR="$SCRIPT_DIR/zephyr/tests/subsys/bacnet_settings"
2019

2120
# Set the output directory for test results
2221
OUTPUT_DIR="$SCRIPT_DIR/twister-out.unit_testing"
23-
NATIVE_SIM_OUTPUT_DIR="$SCRIPT_DIR/twister-out.native_sim"
24-
25-
TWISTER_PLATFORM="unit_testing"
26-
NATIVE_SIM_PLATFORM="native_sim"
27-
28-
cleanup_twister_output_dir() {
29-
local output_dir="$1"
30-
31-
find "$output_dir" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
32-
find "$output_dir" -name 'modules' -exec rm -rf {} \; 2>/dev/null
33-
find "$output_dir" -name 'app' -exec rm -rf \
34-
'{}/../zephyr/arch
35-
{}/../zephyr/boards
36-
{}/../zephyr/cmake
37-
{}/../zephyr/CMakeFiles
38-
{}/../zephyr/dev_graph.dot
39-
{}/../zephyr/drivers
40-
{}/../zephyr/dts.cmake
41-
{}/../zephyr/edt.pickle
42-
{}/../zephyr/include
43-
{}/../zephyr/isrList.bin
44-
{}/../zephyr/kconfig
45-
{}/../zephyr/kernel
46-
{}/../zephyr/lib
47-
{}/../zephyr/libzephyr.a
48-
{}/../zephyr/misc
49-
{}/../zephyr/modules
50-
{}/../zephyr/soc
51-
{}/../zephyr/subsys
52-
{}/../Makefile
53-
{}/../Kconfig
54-
{}/../cmake_install.cmake
55-
{}/../CMakeCache.txt' \; 2>/dev/null
56-
find "$output_dir" -name 'app' -exec rm -rf '{}' \; 2>/dev/null
57-
}
5822

5923
# Remove the output directory
6024
rm -rf "$OUTPUT_DIR"
61-
rm -rf "$NATIVE_SIM_OUTPUT_DIR"
6225

6326
# Run twister with the specified test cases and output directory
64-
"$TWISTER_EXE" -O "$OUTPUT_DIR" -p "$TWISTER_PLATFORM" -T "$TEST_CASES_DIR"
65-
UNIT_TEST_RC=$?
66-
67-
# Run twister for native_sim-only functional tests
68-
"$TWISTER_EXE" -O "$NATIVE_SIM_OUTPUT_DIR" -p "$NATIVE_SIM_PLATFORM" -T "$NATIVE_SIM_TEST_CASES_DIR"
69-
NATIVE_SIM_RC=$?
27+
"$TWISTER_EXE" -O "$OUTPUT_DIR" -T "$TEST_CASES_DIR"
7028

7129
# twister output directory cleanup files we do not archive
72-
cleanup_twister_output_dir "$OUTPUT_DIR"
73-
cleanup_twister_output_dir "$NATIVE_SIM_OUTPUT_DIR"
74-
echo "Twister output cleanup completed successfully."
30+
find "$OUTPUT_DIR" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
31+
find "$OUTPUT_DIR" -name 'modules' -exec rm -rf {} \; 2>/dev/null
32+
find "$OUTPUT_DIR" -name 'app' -exec rm -rf \
33+
'{}/../zephyr/arch
34+
{}/../zephyr/boards
35+
{}/../zephyr/cmake
36+
{}/../zephyr/CMakeFiles
37+
{}/../zephyr/dev_graph.dot
38+
{}/../zephyr/drivers
39+
{}/../zephyr/dts.cmake
40+
{}/../zephyr/edt.pickle
41+
{}/../zephyr/include
42+
{}/../zephyr/isrList.bin
43+
{}/../zephyr/kconfig
44+
{}/../zephyr/kernel
45+
{}/../zephyr/lib
46+
{}/../zephyr/libzephyr.a
47+
{}/../zephyr/misc
48+
{}/../zephyr/modules
49+
{}/../zephyr/soc
50+
{}/../zephyr/subsys
51+
{}/../Makefile
52+
{}/../Kconfig
53+
{}/../cmake_install.cmake
54+
{}/../CMakeCache.txt' \; 2>/dev/null
55+
find "$OUTPUT_DIR" -name 'app' -exec rm -rf '{}' \; 2>/dev/null
56+
echo "Twister unit_testing output cleanup completed successfully."
7557

7658
# Check if twister ran successfully
77-
if [ $UNIT_TEST_RC -eq 0 ] && [ $NATIVE_SIM_RC -eq 0 ]; then
78-
echo "Twister testing completed successfully."
59+
if [ $? -eq 0 ]; then
60+
echo "Twister unit_testing completed successfully."
7961
else
80-
echo "Twister testing failed."
62+
echo "Twister unit_testing failed."
8163
exit 1
8264
fi

0 commit comments

Comments
 (0)