tests bsim/net: Add simple echo test over 802.15.4
Add a simple selfchecking test for the 15.4 stack, based on the echo client / server sample apps. It relies on the bs_tests hooks to register a test timer callback, which after a deadline will check how many packets the echo client has got back as expected, and if over a threshold considers the test passed. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
parent
5a0834f16f
commit
fc3d8a83aa
9 changed files with 277 additions and 0 deletions
|
@ -22,5 +22,6 @@ run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio/compile.sh
|
|||
run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/host/compile.sh
|
||||
run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/ll/compile.sh
|
||||
run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/mesh/compile.sh
|
||||
run_in_background ${ZEPHYR_BASE}/tests/bsim/net/compile.sh
|
||||
|
||||
wait_for_background_jobs
|
||||
|
|
26
tests/bsim/net/compile.sh
Executable file
26
tests/bsim/net/compile.sh
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright 2023 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Compile all the applications needed by the network bsim tests
|
||||
|
||||
#set -x #uncomment this line for debugging
|
||||
set -ue
|
||||
|
||||
: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}"
|
||||
: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}"
|
||||
: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\
|
||||
directory}"
|
||||
|
||||
WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}"
|
||||
BOARD="${BOARD:-nrf52_bsim}"
|
||||
BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}"
|
||||
|
||||
mkdir -p ${WORK_DIR}
|
||||
|
||||
source ${ZEPHYR_BASE}/tests/bsim/compile.source
|
||||
|
||||
app=samples/net/sockets/echo_server conf_overlay=overlay-802154.conf compile
|
||||
app=tests/bsim/net/sockets/echo_test conf_overlay=overlay-802154.conf compile
|
||||
|
||||
wait_for_background_jobs
|
47
tests/bsim/net/sockets/echo_test/CMakeLists.txt
Normal file
47
tests/bsim/net/sockets/echo_test/CMakeLists.txt
Normal file
|
@ -0,0 +1,47 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(sockets_echo_client_self_test)
|
||||
|
||||
if(CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED AND
|
||||
(CONFIG_NET_SAMPLE_PSK_HEADER_FILE STREQUAL "dummy_psk.h"))
|
||||
add_custom_target(development_psk
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "--- WARNING: Using dummy PSK! Only suitable for ---"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "--- development. Set NET_SAMPLE_PSK_HEADER_FILE to use ---"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "--- own pre-shared key. ---"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------"
|
||||
)
|
||||
add_dependencies(app development_psk)
|
||||
endif()
|
||||
|
||||
set(echo_client_path ${ZEPHYR_BASE}/samples/net/sockets/echo_client)
|
||||
|
||||
target_include_directories(app PRIVATE ${echo_client_path}/src/)
|
||||
|
||||
target_sources(app PRIVATE
|
||||
src/echo_test.c
|
||||
src/test_main.c
|
||||
)
|
||||
|
||||
target_sources( app PRIVATE ${echo_client_path}/src/echo-client.c)
|
||||
target_sources_ifdef(CONFIG_NET_UDP app PRIVATE ${echo_client_path}/src/udp.c)
|
||||
target_sources_ifdef(CONFIG_NET_TCP app PRIVATE ${echo_client_path}/src/tcp.c)
|
||||
target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE ${echo_client_path}/src/vlan.c)
|
||||
|
||||
include(${ZEPHYR_BASE}/samples/net/common/common.cmake)
|
||||
|
||||
set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/)
|
||||
|
||||
generate_inc_file_for_target(
|
||||
app
|
||||
${echo_client_path}/src/echo-apps-cert.der
|
||||
${gen_dir}/echo-apps-cert.der.inc
|
||||
)
|
||||
|
||||
zephyr_include_directories(
|
||||
$ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
|
||||
$ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/
|
||||
)
|
4
tests/bsim/net/sockets/echo_test/Kconfig
Normal file
4
tests/bsim/net/sockets/echo_test/Kconfig
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
source "${ZEPHYR_BASE}/samples/net/sockets/echo_client/Kconfig"
|
20
tests/bsim/net/sockets/echo_test/overlay-802154.conf
Normal file
20
tests/bsim/net/sockets/echo_test/overlay-802154.conf
Normal file
|
@ -0,0 +1,20 @@
|
|||
# This file content is just a copy of the echo client overlay-802154.conf
|
||||
|
||||
CONFIG_BT=n
|
||||
|
||||
# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_IPV4=n
|
||||
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
CONFIG_NET_L2_IEEE802154_LOG_LEVEL_INF=y
|
||||
|
||||
CONFIG_NET_CONFIG_IEEE802154_CHANNEL=26
|
51
tests/bsim/net/sockets/echo_test/prj.conf
Normal file
51
tests/bsim/net/sockets/echo_test/prj.conf
Normal file
|
@ -0,0 +1,51 @@
|
|||
# This file content is just a copy of the echo client prj.conf
|
||||
|
||||
# Generic networking options
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_SOCKETS_POLL_MAX=4
|
||||
CONFIG_NET_CONNECTION_MANAGER=y
|
||||
|
||||
# Kernel options
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
CONFIG_ENTROPY_GENERATOR=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
CONFIG_INIT_STACKS=y
|
||||
|
||||
# Logging
|
||||
CONFIG_NET_LOG=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_PRINTK=y
|
||||
|
||||
# Network buffers
|
||||
CONFIG_NET_PKT_RX_COUNT=16
|
||||
CONFIG_NET_PKT_TX_COUNT=16
|
||||
CONFIG_NET_BUF_RX_COUNT=80
|
||||
CONFIG_NET_BUF_TX_COUNT=80
|
||||
CONFIG_NET_CONTEXT_NET_PKT_POOL=y
|
||||
|
||||
# IP address options
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
|
||||
CONFIG_NET_MAX_CONTEXTS=10
|
||||
|
||||
# Network shell
|
||||
CONFIG_NET_SHELL=y
|
||||
|
||||
# The addresses are selected so that qemu<->qemu connectivity works ok.
|
||||
# For linux<->qemu connectivity, create a new conf file and swap the
|
||||
# addresses (so that peer address is ending to 2).
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
|
84
tests/bsim/net/sockets/echo_test/src/echo_test.c
Normal file
84
tests/bsim/net/sockets/echo_test/src/echo_test.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2017-2019 Oticon A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "bs_types.h"
|
||||
#include "bs_tracing.h"
|
||||
#include "time_machine.h"
|
||||
#include "bstests.h"
|
||||
|
||||
#include "common.h" /* From echo_client */
|
||||
|
||||
#define WAIT_TIME 20 /* Seconds */
|
||||
#define PASS_THRESHOLD 100 /* Packets */
|
||||
|
||||
extern enum bst_result_t bst_result;
|
||||
|
||||
#define FAIL(...) \
|
||||
do { \
|
||||
bst_result = Failed; \
|
||||
bs_trace_error_time_line(__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define PASS(...) \
|
||||
do { \
|
||||
bst_result = Passed; \
|
||||
bs_trace_info_time(1, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
static void test_echo_client_init(void)
|
||||
{
|
||||
/* We set an absolute deadline in 30 seconds */
|
||||
bst_ticker_set_next_tick_absolute(WAIT_TIME*1e6);
|
||||
bst_result = In_progress;
|
||||
}
|
||||
|
||||
static void test_echo_client_tick(bs_time_t HW_device_time)
|
||||
{
|
||||
/*
|
||||
* If in WAIT_TIME seconds we did not get enough packets through
|
||||
* we consider the test failed
|
||||
*/
|
||||
|
||||
extern struct configs conf;
|
||||
int packet_count = 0;
|
||||
|
||||
if ((IS_ENABLED(CONFIG_NET_TCP)) && IS_ENABLED(CONFIG_NET_IPV6)) {
|
||||
packet_count = conf.ipv6.tcp.counter;
|
||||
} else if ((IS_ENABLED(CONFIG_NET_UDP)) && IS_ENABLED(CONFIG_NET_IPV6)) {
|
||||
packet_count = conf.ipv6.udp.counter;
|
||||
}
|
||||
|
||||
bs_trace_info_time(2, "%i packets received, expected >= %i\n",
|
||||
packet_count, PASS_THRESHOLD);
|
||||
|
||||
if (packet_count >= PASS_THRESHOLD) {
|
||||
PASS("echo_client PASSED\n");
|
||||
bs_trace_exit("Done, disconnecting from simulation\n");
|
||||
} else {
|
||||
FAIL("echo_client FAILED (Did not pass after %i seconds)\n",
|
||||
WAIT_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
static const struct bst_test_instance test_echo_client[] = {
|
||||
{
|
||||
.test_id = "echo_client",
|
||||
.test_descr = "Test based on the echo client sample. "
|
||||
"It expects to be connected to a compatible echo server, "
|
||||
"waits for 20 seconds, and checks how many packets have been "
|
||||
"exchanged correctly",
|
||||
.test_post_init_f = test_echo_client_init,
|
||||
.test_tick_f = test_echo_client_tick,
|
||||
},
|
||||
BSTEST_END_MARKER
|
||||
};
|
||||
|
||||
struct bst_test_list *test_echo_client_install(struct bst_test_list *tests)
|
||||
{
|
||||
tests = bst_add_tests(tests, test_echo_client);
|
||||
return tests;
|
||||
}
|
14
tests/bsim/net/sockets/echo_test/src/test_main.c
Normal file
14
tests/bsim/net/sockets/echo_test/src/test_main.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "bstests.h"
|
||||
|
||||
extern struct bst_test_list *test_echo_client_install(struct bst_test_list *tests);
|
||||
|
||||
bst_test_install_t test_installers[] = {
|
||||
test_echo_client_install,
|
||||
NULL
|
||||
};
|
30
tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_802154.sh
Executable file
30
tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_802154.sh
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright 2018 Oticon A/S
|
||||
# Copyright 2023 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Simple selfchecking test for the 15.4 stack, based on the echo client / server sample apps
|
||||
# It relies on the bs_tests hooks to register a test timer callback, which after a deadline
|
||||
# will check how many packets the echo client has got back as expected, and if over a threshold
|
||||
# it considers the test passed
|
||||
|
||||
simulation_id="echo_test_154"
|
||||
verbosity_level=2
|
||||
|
||||
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
|
||||
|
||||
EXECUTE_TIMEOUT=100
|
||||
|
||||
cd ${BSIM_OUT_PATH}/bin
|
||||
|
||||
Execute ./bs_${BOARD}_tests_bsim_net_sockets_echo_test_prj_conf_overlay-802154_conf \
|
||||
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 \
|
||||
-testid=echo_client
|
||||
|
||||
Execute ./bs_${BOARD}_samples_net_sockets_echo_server_prj_conf_overlay-802154_conf\
|
||||
-v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \
|
||||
|
||||
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
|
||||
-D=2 -sim_length=60e6 -argschannel -at=40 $@
|
||||
|
||||
wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails
|
Loading…
Add table
Add a link
Reference in a new issue