Skip to content

Commit 8dd9be8

Browse files
authored
Add native_sim subsys functional test for bacnet_storage.c module. #59
2 parents 3d1c8ce + 97db31e commit 8dd9be8

12 files changed

Lines changed: 268 additions & 12 deletions

File tree

.github/dependabot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
version: 2
44
updates:
5-
- package-ecosystem: "" # See documentation for possible values
6-
directory: "/" # Location of package manifests
5+
- package-ecosystem: "github-actions"
6+
directory: "/"
77
schedule:
8-
interval: "weekly"
8+
interval: "daily"

.github/workflows/zephyr.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- uses: actions/checkout@v3
3737
- name: Run Docker image from GHCR
3838
env:
39-
DOCKER_RUN_TARGET: "/workspace/bacnet/west-ci.sh && /workspace/bacnet/samples.sh && /workspace/bacnet/unittest.sh"
39+
DOCKER_RUN_TARGET: "/workspace/bacnet/west-ci.sh && /workspace/bacnet/samples.sh && /workspace/bacnet/unittest.sh && /workspace/bacnet/subsys.sh"
4040
ZEPHYR_CONTAINER: "ghcr.io/zephyrproject-rtos/ci:v0.26-branch"
4141
run: |
4242
ls -alh
@@ -56,10 +56,10 @@ jobs:
5656
name: twister-out.unit_testing
5757
path: twister-out.unit_testing
5858
if-no-files-found: warn
59-
- name: Upload native_sim Twister results
59+
- name: Upload subsys Twister results
6060
if: ${{ always() }}
6161
uses: actions/upload-artifact@v4
6262
with:
63-
name: twister-out.native_sim
64-
path: twister-out.native_sim
63+
name: twister-out.subsys
64+
path: twister-out.subsys
6565
if-no-files-found: warn

samples.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rm -rf "$OUTPUT_DIR"
2525

2626
# Run twister with the specified test cases and output directory
2727
"$TWISTER_EXE" -O "$OUTPUT_DIR" -T "$TEST_CASES_DIR"
28+
TWISTER_RC=$?
2829

2930
# twister output directory cleanup files we do not archive
3031
find "$OUTPUT_DIR" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
@@ -56,7 +57,7 @@ find "$OUTPUT_DIR" -name 'app' -exec rm -rf '{}' \; 2>/dev/null
5657
echo "Twister samples output cleanup completed successfully."
5758

5859
# Check if twister ran successfully
59-
if [ $? -eq 0 ]; then
60+
if [ $TWISTER_RC -eq 0 ]; then
6061
echo "Twister samples testing completed successfully."
6162
else
6263
echo "Twister samples testing failed."

subsys.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
# Set the path to the twister executable
3+
TWISTER_EXE=""
4+
5+
# Set workspace virtual environment if available
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
WORKSPACE_VENV="$SCRIPT_DIR/../.venv"
8+
WORKSPACE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
9+
TWISTER_EXE="$WORKSPACE_DIR/zephyr/scripts/twister"
10+
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+
17+
# Set the path to the test cases directory
18+
TEST_CASES_DIR="$SCRIPT_DIR/zephyr/tests/subsys"
19+
20+
# Set the output directory for test results
21+
OUTPUT_DIR="$SCRIPT_DIR/twister-out.subsys"
22+
23+
# Set platform to native_sim to run specific simulation tests
24+
TWISTER_PLATFORM="native_sim"
25+
26+
cleanup_twister_output_dir() {
27+
local output_dir="$1"
28+
29+
find "$output_dir" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
30+
find "$output_dir" -name 'modules' -exec rm -rf {} \; 2>/dev/null
31+
find "$output_dir" -name 'app' -exec rm -rf \
32+
'{}/../zephyr/arch
33+
{}/../zephyr/boards
34+
{}/../zephyr/cmake
35+
{}/../zephyr/CMakeFiles
36+
{}/../zephyr/dev_graph.dot
37+
{}/../zephyr/drivers
38+
{}/../zephyr/dts.cmake
39+
{}/../zephyr/edt.pickle
40+
{}/../zephyr/include
41+
{}/../zephyr/isrList.bin
42+
{}/../zephyr/kconfig
43+
{}/../zephyr/kernel
44+
{}/../zephyr/lib
45+
{}/../zephyr/libzephyr.a
46+
{}/../zephyr/misc
47+
{}/../zephyr/modules
48+
{}/../zephyr/soc
49+
{}/../zephyr/subsys
50+
{}/../Makefile
51+
{}/../Kconfig
52+
{}/../cmake_install.cmake
53+
{}/../CMakeCache.txt' \; 2>/dev/null
54+
find "$output_dir" -name 'app' -exec rm -rf '{}' \; 2>/dev/null
55+
}
56+
57+
# Remove the output directory
58+
rm -rf "$OUTPUT_DIR"
59+
60+
# Run twister for native_sim-only functional subsys tests
61+
"$TWISTER_EXE" -O "$OUTPUT_DIR" -p "$TWISTER_PLATFORM" -T "$TEST_CASES_DIR"
62+
TWISTER_RC=$?
63+
64+
# twister output directory cleanup files we do not archive
65+
find "$OUTPUT_DIR" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
66+
find "$OUTPUT_DIR" -name 'modules' -exec rm -rf {} \; 2>/dev/null
67+
find "$OUTPUT_DIR" -name 'app' -exec rm -rf \
68+
'{}/../zephyr/arch
69+
{}/../zephyr/boards
70+
{}/../zephyr/cmake
71+
{}/../zephyr/CMakeFiles
72+
{}/../zephyr/dev_graph.dot
73+
{}/../zephyr/drivers
74+
{}/../zephyr/dts.cmake
75+
{}/../zephyr/edt.pickle
76+
{}/../zephyr/include
77+
{}/../zephyr/isrList.bin
78+
{}/../zephyr/kconfig
79+
{}/../zephyr/kernel
80+
{}/../zephyr/lib
81+
{}/../zephyr/libzephyr.a
82+
{}/../zephyr/misc
83+
{}/../zephyr/modules
84+
{}/../zephyr/soc
85+
{}/../zephyr/subsys
86+
{}/../Makefile
87+
{}/../Kconfig
88+
{}/../cmake_install.cmake
89+
{}/../CMakeCache.txt' \; 2>/dev/null
90+
find "$OUTPUT_DIR" -name 'app' -exec rm -rf '{}' \; 2>/dev/null
91+
echo "Twister native_sim output cleanup completed successfully."
92+
93+
# Check if twister ran successfully
94+
if [ $TWISTER_RC -eq 0 ]; then
95+
echo "Twister native_sim completed successfully."
96+
else
97+
echo "Twister native_sim failed."
98+
exit 1
99+
fi

unittest.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rm -rf "$OUTPUT_DIR"
2828

2929
# Run twister with the specified test cases and output directory
3030
"$TWISTER_EXE" -O "$OUTPUT_DIR" -p "$TWISTER_PLATFORM" -T "$TEST_CASES_DIR"
31+
TWISTER_RC=$?
3132

3233
# twister output directory cleanup files we do not archive
3334
find "$OUTPUT_DIR" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
@@ -59,7 +60,7 @@ find "$OUTPUT_DIR" -name 'app' -exec rm -rf '{}' \; 2>/dev/null
5960
echo "Twister unit_testing output cleanup completed successfully."
6061

6162
# Check if twister ran successfully
62-
if [ $? -eq 0 ]; then
63+
if [ $TWISTER_RC -eq 0 ]; then
6364
echo "Twister unit_testing completed successfully."
6465
else
6566
echo "Twister unit_testing failed."

west-ci.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
33
WORKSPACE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
44

5+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6+
WORKSPACE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
7+
58
# setup our build environment
69
cd "$WORKSPACE_DIR"
710

zephyr/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
7070
#
7171
# sources
7272
#
73-
set(BACNETSTACK_SRC ../stack/src)
73+
set(BACNETSTACK_ROOT ${CMAKE_CURRENT_LIST_DIR}/../stack)
74+
set(BACNETSTACK_SRC ${BACNETSTACK_ROOT}/src)
75+
set(BACNETSTACK_POSIX ${BACNETSTACK_ROOT}/ports/posix)
7476

7577
set(BACNETSTACK_SRCS
7678
${BACNETSTACK_SRC}/bacnet/abort.c
@@ -544,12 +546,16 @@ set(BACNETSTACK_BASIC_SRCS
544546
#
545547
# add ports
546548
#
549+
set(BACNETSTACK_PORT_SRCS
550+
$<$<BOOL:${CONFIG_BOARD_NATIVE_SIM}>:${BACNETSTACK_POSIX}/bacfile-posix.c>
551+
)
547552

548553
message(STATUS "BACNETSTACK: building for Zephyr")
549554

550555
list(
551556
APPEND BACNETSTACK_SRCS
552557
${BACNETSTACK_BASIC_SRCS}
558+
${BACNETSTACK_PORT_SRCS}
553559
)
554560

555561
zephyr_include_directories(include)
@@ -572,10 +578,11 @@ zephyr_library_sources(
572578
zephyr_include_directories(
573579
${BACNETSTACK_PORT}
574580
${BACNETSTACK_SRC}
581+
$<$<BOOL:${CONFIG_BOARD_NATIVE_SIM}>:${BACNETSTACK_POSIX}>
575582
)
576583

577584
zephyr_compile_definitions(
578-
BACNET_CONFIG_H=1 # Use ports/zephyr/bacnet-config.h
585+
BACNET_CONFIG_H=1
579586
BACNET_VENDOR_ID=${CONFIG_BACNET_VENDOR_IDENTIFIER}
580587
BACNET_VENDOR_NAME="${CONFIG_BACNET_VENDOR_NAME}"
581588
BACNET_PROTOCOL_REVISION=${CONFIG_BACNET_PROTOCOL_REVISION}

zephyr/samples/hello_bacnet_stack/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ common:
1111
- "Hello BACnet-Stack! (.*)"
1212
tests:
1313
bacnet-stack.sample.basic.hello_bacnet_stack:
14-
platform_allow: native_posix
14+
platform_allow: native_sim
1515
tags: introduction
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.20.0)
2+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
3+
project(bacnet_settings)
4+
5+
string(REGEX REPLACE
6+
"/zephyr/tests/[0-9a-zA-Z_/-]*$"
7+
"/zephyr"
8+
SRC_DIR
9+
${CMAKE_CURRENT_SOURCE_DIR})
10+
11+
target_include_directories(app PRIVATE
12+
${SRC_DIR}/include
13+
)
14+
15+
target_sources(app PRIVATE
16+
src/main.c
17+
${SRC_DIR}/subsys/bacnet_settings/bacnet_storage.c
18+
)
19+
20+
add_compile_definitions(
21+
CONFIG_ZTEST_NEW_API
22+
CONFIG_BACNET_STORAGE_BASE_NAME=\"bacnet\"
23+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_SETTINGS=y
3+
CONFIG_LOG=n

0 commit comments

Comments
 (0)