diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index fec8d96ba..099bbe180 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -21,7 +21,7 @@ concurrency: cancel-in-progress: true jobs: - codecov: + twister: runs-on: self-hosted container: image: ghcr.io/zephyrproject-rtos/ci:v0.26.13 @@ -114,9 +114,117 @@ jobs: path: coverage/reports/${{ matrix.normalized }}.json retention-days: 1 + babblesim: + runs-on: self-hosted + container: + image: ghcr.io/zephyrproject-rtos/ci:v0.26.13 + options: '--entrypoint /bin/bash' + volumes: + - /repo-cache/embeint:/github/cache/embeint + env: + BASE_REF: ${{ github.base_ref }} + ZEPHYR_TOOLCHAIN_VARIANT: zephyr + BSIM_OUT_PATH: /github/cache/embeint/tools/bsim + BSIM_COMPONENTS_PATH: /github/cache/embeint/tools/bsim/components/ + + steps: + - name: Workspace cleanup + run: | + rm -rf ./{*,.*} + rm -rf infuse-sdk + + - name: Clone cached Embeint SDK repository + continue-on-error: true + run: | + git config --global --add safe.directory '*' + git clone --shared /github/cache/embeint/infuse-sdk infuse-sdk + cd infuse-sdk + git remote set-url origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} + + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: infuse-sdk + fetch-depth: 0 + persist-credentials: false + + - name: Environment Setup + working-directory: infuse-sdk + run: | + if [ "${{github.event_name}}" = "pull_request" ]; then + git config --global user.email "ci@embeint.com" + git config --global user.name "Embeint CI" + rm -fr ".git/rebase-apply" + git rebase origin/${BASE_REF} + git log --pretty=oneline | head -n 10 + fi + + west init -l . || true + west config --global update.narrow true + west config manifest.group-filter -- +babblesim + west update --path-cache /github/cache/embeint 2>&1 1> west.update.log || west update --path-cache /github/cache/embeint 2>&1 1> west.update.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /github/cache/embeint) + west forall -c 'git reset --hard HEAD' + + pip3 install gcovr==6.0 + + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-$( cat SDK_VERSION )" >> $GITHUB_ENV + + - name: nRF Hardware Models patch + working-directory: modules/bsim_hw_models/nrf_hw_models + run: | + # Apply temporary patch until latest upstream can be used + git apply ../../../infuse-sdk/tests/bsim/nrf_hw_models.patch + + - name: BabbleSim build + run: | + cd ${BSIM_OUT_PATH} + make everything -j 8 + + - name: Check Environment + run: | + cmake --version + gcc --version + ls -la /opt/toolchains + ls -la + echo "github.ref: ${{ github.ref }}" + echo "github.base_ref: ${{ github.base_ref }}" + echo "github.ref_name: ${{ github.ref_name }}" + + - name: Run Bluetooth Tests with BabbleSim + run: | + export ZEPHYR_BASE=${PWD}/zephyr + export INFUSE_BASE=${PWD}/infuse-sdk + export WORK_DIR=${PWD}/bsim_out + $INFUSE_BASE/tests/bsim/ci.bt.sh + + - name: Generate coverage report + run: | + export INFUSE_BASE=${PWD}/infuse-sdk + export WORK_DIR=${PWD}/bsim_out + + mkdir -p coverage/reports + gcovr -r $INFUSE_BASE \ + --gcov-ignore-parse-errors=negative_hits.warn_once_per_file \ + --gcov-executable gcov -e tests/* -e .*generated.* -e .*/tests/.* -e .*/samples/.* \ + --exclude-branches-by-pattern "(^\s*LOG_(?:HEXDUMP_)?(?:DBG|INF|WRN|ERR)\(.*)|(^\s*__ASSERT(?:_EVAL|_NO_MSG|_POST_ACTION)?\(.*)" \ + --merge-mode-functions=separate --json \ + -o coverage/reports/nrf52_bsim.json \ + $WORK_DIR + + - name: Upload Coverage Results + uses: actions/upload-artifact@v4 + with: + name: Coverage Data (BabbleSim) + path: coverage/reports/nrf52_bsim.json + if-no-files-found: ignore + retention-days: 1 + codecov-results: name: "Publish Coverage Results" - needs: codecov + needs: + - twister + - babblesim runs-on: ubuntu-22.04 # the codecov job might be skipped, we don't need to run this job then if: success() || failure() diff --git a/.github/workflows/twister.yml b/.github/workflows/twister.yml index d46f59ea8..e97576c45 100644 --- a/.github/workflows/twister.yml +++ b/.github/workflows/twister.yml @@ -39,7 +39,7 @@ jobs: - name: Clone cached Embeint SDK repository continue-on-error: true run: | - git config --global --add safe.directory /github/cache/embeint/infuse-sdk/.git + git config --global --add safe.directory '*' git clone --shared /github/cache/embeint/infuse-sdk infuse-sdk cd infuse-sdk git remote set-url origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} diff --git a/.gitignore b/.gitignore index 1472485ea..dd35db03f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Build folders build +bsim_out doc/_build # Python files diff --git a/Kconfig.defaults.bluetooth b/Kconfig.defaults.bluetooth index b32861701..bca73ed43 100644 --- a/Kconfig.defaults.bluetooth +++ b/Kconfig.defaults.bluetooth @@ -83,6 +83,8 @@ configdefault BT_PERIPHERAL # While extended advertising can support 255 bytes, iOS only supports 124 bytes configdefault BT_CTLR_ADV_DATA_LEN_MAX default 124 +configdefault BT_CTLR_SCAN_DATA_LEN_MAX + default 124 # GATT central options configdefault BT_GATT_CLIENT diff --git a/Kconfig.defaults.core b/Kconfig.defaults.core index 25c49847d..885d44b28 100644 --- a/Kconfig.defaults.core +++ b/Kconfig.defaults.core @@ -211,7 +211,7 @@ configdefault DEBUG_INFO configdefault DEBUG_THREAD_INFO default y configdefault OUTPUT_DISASSEMBLY - default y if !ZTEST + default y if !ZTEST && !SOC_SERIES_BSIM_NRFXX # Memfault options configdefault MEMFAULT_NRF_CONNECT_SDK diff --git a/scripts/bsim_coverage.sh b/scripts/bsim_coverage.sh new file mode 100755 index 000000000..8f0497255 --- /dev/null +++ b/scripts/bsim_coverage.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env sh + +echo "BabbleSim Coverage" + +export ZEPHYR_BASE=`pwd`/zephyr +export INFUSE_BASE=`pwd`/infuse-sdk +export WORK_DIR=`pwd`/bsim_out +# Run BabbleSim tests +$INFUSE_BASE/tests/bsim/ci.bt.sh + +# Disable branch coverage on LOG_ and __ASSERT macros +BRANCH_LOG="(^\s*LOG_(?:HEXDUMP_)?(?:DBG|INF|WRN|ERR)\(.*)" +BRANCH_ASSERT="(^\s*__ASSERT(?:_EVAL|_NO_MSG|_POST_ACTION)?\(.*)" + +# Generate coverage.json +gcovr -r $INFUSE_BASE \ + --gcov-ignore-parse-errors=negative_hits.warn_once_per_file \ + --gcov-executable gcov -e tests/* -e .*generated.* -e .*/tests/.* -e .*/samples/.* \ + --exclude-branches-by-pattern "$BRANCH_LOG|$BRANCH_ASSERT" \ + --merge-mode-functions=separate --json \ + -o $WORK_DIR/coverage.json \ + $WORK_DIR + +# Generate html +mkdir -p $WORK_DIR/html +gcovr -r $INFUSE_BASE --html $WORK_DIR/html/index.html --html-details \ + --add-tracefile $WORK_DIR/coverage.json diff --git a/snippets/infuse/boards/nrf52_bsim.overlay b/snippets/infuse/boards/nrf52_bsim.overlay new file mode 100644 index 000000000..9130cf288 --- /dev/null +++ b/snippets/infuse/boards/nrf52_bsim.overlay @@ -0,0 +1,31 @@ +/ { + chosen { + infuse,kv-partition = &storage_partition; + }; + + epacket_bt_adv: epacket_bt_adv { + compatible = "embeint,epacket-bt-adv"; + }; + + data_logger_bt_adv: data_logger_bt_adv { + compatible = "embeint,data-logger-epacket", "embeint,data-logger"; + epacket = <&epacket_bt_adv>; + + tdf_logger_bt_adv: tdf_logger_bt_adv { + compatible = "embeint,tdf-data-logger"; + }; + }; + + epacket_bt_peripheral: epacket_bt_peripheral { + compatible = "embeint,epacket-bt-peripheral"; + }; + + data_logger_bt_peripheral: data_logger_bt_peripheral { + compatible = "embeint,data-logger-epacket", "embeint,data-logger"; + epacket = <&epacket_bt_peripheral>; + + tdf_logger_bt_peripheral: tdf_logger_bt_peripheral { + compatible = "embeint,tdf-data-logger"; + }; + }; +}; diff --git a/snippets/infuse/snippet.yml b/snippets/infuse/snippet.yml index 8345d67a2..4c99f1e7d 100644 --- a/snippets/infuse/snippet.yml +++ b/snippets/infuse/snippet.yml @@ -5,6 +5,10 @@ boards: append: EXTRA_DTC_OVERLAY_FILE: boards/mps2_an385.overlay EXTRA_CONF_FILE: infuse_snippet.conf + nrf52_bsim/native: + append: + EXTRA_DTC_OVERLAY_FILE: boards/nrf52_bsim.overlay + EXTRA_CONF_FILE: infuse_snippet.conf nrf52840dk/nrf52840: append: EXTRA_DTC_OVERLAY_FILE: boards/nrf52840dk_nrf52840.overlay diff --git a/submanifests/babblesim.yaml b/submanifests/babblesim.yaml new file mode 100644 index 000000000..21836524d --- /dev/null +++ b/submanifests/babblesim.yaml @@ -0,0 +1,97 @@ +manifest: + remotes: + - name: zephyrproject + url-base: https://github.com/zephyrproject-rtos + - name: babblesim + url-base: https://github.com/BabbleSim + projects: + - name: bsim + remote: zephyrproject + repo-path: babblesim-manifest + revision: 9351ae1ad44864a49c351f9704f65f43046abeb0 + path: tools/bsim + groups: + - babblesim + - name: nrf_hw_models + remote: zephyrproject + revision: 6c389b9b5fa0a079cd4502e69d375da4c0c289b7 + path: modules/bsim_hw_models/nrf_hw_models + groups: + - babblesim + - name: babblesim_base + remote: babblesim + repo-path: base + path: tools/bsim/components + revision: 4bd907be0b2abec3b31a23fd8ca98db2a07209d2 + groups: + - babblesim + - name: babblesim_ext_2G4_libPhyComv1 + remote: babblesim + repo-path: ext_2G4_libPhyComv1 + path: tools/bsim/components/ext_2G4_libPhyComv1 + revision: 93f5eba512c438b0c9ebc1b1a947517c865b3643 + groups: + - babblesim + - name: babblesim_ext_2G4_phy_v1 + remote: babblesim + repo-path: ext_2G4_phy_v1 + path: tools/bsim/components/ext_2G4_phy_v1 + revision: 04eeb3c3794444122fbeeb3715f4233b0b50cfbb + groups: + - babblesim + - name: babblesim_ext_2G4_channel_NtNcable + remote: babblesim + repo-path: ext_2G4_channel_NtNcable + path: tools/bsim/components/ext_2G4_channel_NtNcable + revision: 20a38c997f507b0aa53817aab3d73a462fff7af1 + groups: + - babblesim + - name: babblesim_ext_2G4_channel_multiatt + remote: babblesim + repo-path: ext_2G4_channel_multiatt + path: tools/bsim/components/ext_2G4_channel_multiatt + revision: bde72a57384dde7a4310bcf3843469401be93074 + groups: + - babblesim + - name: babblesim_ext_2G4_modem_magic + remote: babblesim + repo-path: ext_2G4_modem_magic + path: tools/bsim/components/ext_2G4_modem_magic + revision: edfcda2d3937a74be0a59d6cd47e0f50183453da + groups: + - babblesim + - name: babblesim_ext_2G4_modem_BLE_simple + remote: babblesim + repo-path: ext_2G4_modem_BLE_simple + path: tools/bsim/components/ext_2G4_modem_BLE_simple + revision: a38d2d24b04a6f970a225d1316047256ebf5a539 + groups: + - babblesim + - name: babblesim_ext_2G4_device_burst_interferer + remote: babblesim + repo-path: ext_2G4_device_burst_interferer + path: tools/bsim/components/ext_2G4_device_burst_interferer + revision: 5b5339351d6e6a2368c686c734dc8b2fc65698fc + groups: + - babblesim + - name: babblesim_ext_2G4_device_WLAN_actmod + remote: babblesim + repo-path: ext_2G4_device_WLAN_actmod + path: tools/bsim/components/ext_2G4_device_WLAN_actmod + revision: 9cb6d8e72695f6b785e57443f0629a18069d6ce4 + groups: + - babblesim + - name: babblesim_ext_2G4_device_playback + remote: babblesim + repo-path: ext_2G4_device_playback + path: tools/bsim/components/ext_2G4_device_playback + revision: abb48cd71ddd4e2a9022f4bf49b2712524c483e8 + groups: + - babblesim + - name: babblesim_ext_libCryptov1 + remote: babblesim + repo-path: ext_libCryptov1 + path: tools/bsim/components/ext_libCryptov1 + revision: eed6d7038e839153e340bd333bc43541cb90ba64 + groups: + - babblesim diff --git a/tests/bsim/bluetooth/advertising/compile.sh b/tests/bsim/bluetooth/advertising/compile.sh new file mode 100755 index 000000000..1e10ff83b --- /dev/null +++ b/tests/bsim/bluetooth/advertising/compile.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Copyright 2024 Embeint Inc +# SPDX-License-Identifier: Apache-2.0 + +# Compile all the applications needed by the bsim tests in these subfolders + +# set -x #uncomment this line for debugging +set -ue + +: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root directory}" +: "${INFUSE_BASE:?INFUSE_BASE must be set to point to the Infuse-IoT root directory}" + +source ${ZEPHYR_BASE}/tests/bsim/compile.source + +APP=tests/bsim/bluetooth/advertising/epacket + +app_root=$INFUSE_BASE app=$APP conf_file=prj_advertiser.conf snippet=infuse compile +app_root=$INFUSE_BASE app=$APP conf_file=prj_scanner.conf snippet=infuse compile + +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/advertising/epacket/CMakeLists.txt b/tests/bsim/bluetooth/advertising/epacket/CMakeLists.txt new file mode 100644 index 000000000..fd0b76d4d --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright 2024 Embeint Inc +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(bsim_test_epacket_bt_adv) + +target_sources(app PRIVATE + src/common.c +) + +if(CONFIG_BT_CENTRAL) + target_sources(app PRIVATE + src/ext_adv_scanner.c + ) +else() + target_sources(app PRIVATE + src/ext_adv_advertiser.c + ) +endif() + +zephyr_include_directories( + ${BSIM_COMPONENTS_PATH}/libUtilv1/src/ + ${BSIM_COMPONENTS_PATH}/libPhyComv1/src/ +) diff --git a/tests/bsim/bluetooth/advertising/epacket/prj_advertiser.conf b/tests/bsim/bluetooth/advertising/epacket/prj_advertiser.conf new file mode 100644 index 000000000..d39c2023f --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/prj_advertiser.conf @@ -0,0 +1,3 @@ +CONFIG_INFUSE_SDK=y +CONFIG_TASK_RUNNER=y +CONFIG_BT=y diff --git a/tests/bsim/bluetooth/advertising/epacket/prj_scanner.conf b/tests/bsim/bluetooth/advertising/epacket/prj_scanner.conf new file mode 100644 index 000000000..4acf88575 --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/prj_scanner.conf @@ -0,0 +1,4 @@ +CONFIG_INFUSE_SDK=y +CONFIG_TASK_RUNNER=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y diff --git a/tests/bsim/bluetooth/advertising/epacket/src/common.c b/tests/bsim/bluetooth/advertising/epacket/src/common.c new file mode 100644 index 000000000..6de9aee1d --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/src/common.c @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2024 Croxel, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "bstests.h" +#include "common.h" + +extern enum bst_result_t bst_result; + +void test_tick(bs_time_t HW_device_time) +{ + if (bst_result != Passed) { + FAIL("test failed (not passed after %i seconds)\n", WAIT_SECONDS); + } +} + +void test_init(void) +{ + bst_ticker_set_next_tick_absolute(WAIT_TIME); + bst_result = In_progress; +} diff --git a/tests/bsim/bluetooth/advertising/epacket/src/common.h b/tests/bsim/bluetooth/advertising/epacket/src/common.h new file mode 100644 index 000000000..3ded06629 --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/src/common.h @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2024 Croxel, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_TEST_BSIM_BT_EXT_ADV_TEST_ +#define ZEPHYR_TEST_BSIM_BT_EXT_ADV_TEST_ + +#include + +#include "bs_types.h" +#include "bs_tracing.h" +#include "time_machine.h" +#include "bstests.h" + +#define WAIT_SECONDS 30 /* seconds */ +#define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/ + +#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t) false +#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) +#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t) true) +#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) +#define WAIT_FOR_FLAG(flag) \ + while (!(bool)atomic_get(&flag)) { \ + (void)k_sleep(K_MSEC(1)); \ + } +#define WAIT_FOR_FLAG_UNSET(flag) \ + while ((bool)atomic_get(&flag)) { \ + (void)k_sleep(K_MSEC(1)); \ + } +#define TAKE_FLAG(flag) \ + while (!(bool)atomic_cas(&flag, true, false)) { \ + (void)k_sleep(K_MSEC(1)); \ + } + +#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, "PASSED: " __VA_ARGS__); \ + } while (0) + +void test_tick(bs_time_t HW_device_time); +void test_init(void); + +#endif /* ZEPHYR_TEST_BSIM_BT_EXT_ADV_TEST_ */ diff --git a/tests/bsim/bluetooth/advertising/epacket/src/ext_adv_advertiser.c b/tests/bsim/bluetooth/advertising/epacket/src/ext_adv_advertiser.c new file mode 100644 index 000000000..b01a1edd0 --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/src/ext_adv_advertiser.c @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2024 Embeint Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include "common.h" + +#include "bs_types.h" +#include "bs_tracing.h" +#include "time_machine.h" +#include "bstests.h" + +#include +#include +#include + +extern enum bst_result_t bst_result; + +LOG_MODULE_REGISTER(app, LOG_LEVEL_INF); + +static void main_epacket_bt_adv_tx(void) +{ + struct tdf_announce announce = {0}; + + LOG_INF("Starting send"); + + /* Send 5 packets with spacing */ + for (int i = 0; i < 5; i++) { + k_sleep(K_MSEC(500)); + LOG_INF("TX %d", i); + tdf_data_logger_log(TDF_DATA_LOGGER_BT_ADV | TDF_DATA_LOGGER_BT_PERIPHERAL, + TDF_ANNOUNCE, (sizeof(announce)), 0, &announce); + tdf_data_logger_flush(TDF_DATA_LOGGER_BT_ADV | TDF_DATA_LOGGER_BT_PERIPHERAL); + } + k_sleep(K_MSEC(500)); + + /* Queue 5 packets at once */ + for (int i = 0; i < 5; i++) { + tdf_data_logger_log(TDF_DATA_LOGGER_BT_ADV | TDF_DATA_LOGGER_BT_PERIPHERAL, + TDF_ANNOUNCE, (sizeof(announce)), 0, &announce); + tdf_data_logger_flush(TDF_DATA_LOGGER_BT_ADV | TDF_DATA_LOGGER_BT_PERIPHERAL); + } + k_sleep(K_MSEC(500)); + + PASS("Extended advertiser passed\n"); +} + +static const struct bst_test_instance ext_adv_advertiser[] = { + {.test_id = "ext_adv_advertiser", + .test_descr = "Basic extended advertising test. " + "Will just start extended advertising.", + .test_pre_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = main_epacket_bt_adv_tx}, + BSTEST_END_MARKER}; + +struct bst_test_list *test_ext_adv_advertiser(struct bst_test_list *tests) +{ + return bst_add_tests(tests, ext_adv_advertiser); +} + +bst_test_install_t test_installers[] = {test_ext_adv_advertiser, NULL}; + +int main(void) +{ + bst_main(); + return 0; +} diff --git a/tests/bsim/bluetooth/advertising/epacket/src/ext_adv_scanner.c b/tests/bsim/bluetooth/advertising/epacket/src/ext_adv_scanner.c new file mode 100644 index 000000000..51cb4cbd3 --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/src/ext_adv_scanner.c @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2024 Embeint Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include "common.h" + +#include "bs_types.h" +#include "bs_tracing.h" +#include "time_machine.h" +#include "bstests.h" + +#include +#include + +extern enum bst_result_t bst_result; +static atomic_t received_packets; + +LOG_MODULE_REGISTER(app, LOG_LEVEL_INF); + +static void epacket_bt_adv_receive_handler(struct net_buf *buf) +{ + struct epacket_rx_metadata *meta = net_buf_user_data(buf); + + LOG_INF("RX Type: %02X Flags: %04X Auth: %d Len: %d RSSI: %ddBm", meta->type, meta->flags, + meta->auth, buf->len, meta->rssi); + atomic_inc(&received_packets); + + net_buf_unref(buf); +} + +static void main_ext_adv_scanner(void) +{ + const struct device *epacket_bt_adv = DEVICE_DT_GET(DT_NODELABEL(epacket_bt_adv)); + int rc; + + epacket_set_receive_handler(epacket_bt_adv, epacket_bt_adv_receive_handler); + rc = epacket_receive(epacket_bt_adv, K_FOREVER); + if (rc < 0) { + FAIL("Failed to start ePacket receive (%d)\n", rc); + return; + } + + LOG_INF("Waiting for packets"); + k_sleep(K_SECONDS(6)); + + rc = epacket_receive(epacket_bt_adv, K_NO_WAIT); + if (rc < 0) { + FAIL("Failed to stop ePacket receive (%d)\n", rc); + return; + } + + if (atomic_get(&received_packets) < 10) { + FAIL("Failed to receive expected packets\n"); + } else { + PASS("Received %d packets from advertiser\n", atomic_get(&received_packets)); + } +} + +static const struct bst_test_instance ext_adv_scanner[] = { + {.test_id = "ext_adv_scanner", + .test_descr = "Basic extended advertising scanning test. " + "Will just scan an extended advertiser.", + .test_pre_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = main_ext_adv_scanner}, + BSTEST_END_MARKER}; + +struct bst_test_list *test_ext_adv_scanner(struct bst_test_list *tests) +{ + return bst_add_tests(tests, ext_adv_scanner); +} + +bst_test_install_t test_installers[] = {test_ext_adv_scanner, NULL}; + +int main(void) +{ + bst_main(); + return 0; +} diff --git a/tests/bsim/bluetooth/advertising/epacket/tests_scripts/ext_adv.sh b/tests/bsim/bluetooth/advertising/epacket/tests_scripts/ext_adv.sh new file mode 100755 index 000000000..8b6d01e85 --- /dev/null +++ b/tests/bsim/bluetooth/advertising/epacket/tests_scripts/ext_adv.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Copyright (c) 2024 Embeint Inc +# SPDX-License-Identifier: Apache-2.0 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +simulation_id="ext_adv" +verbosity_level=2 + +cd ${BSIM_OUT_PATH}/bin + +Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_advertising_epacket_prj_advertiser_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ + -testid=ext_adv_advertiser -rs=23 + +Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_advertising_epacket_prj_scanner_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ + -testid=ext_adv_scanner -rs=6 + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ + -D=2 -sim_length=10e6 $@ + +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/compile.sh b/tests/bsim/bluetooth/compile.sh new file mode 100755 index 000000000..55d2bfef1 --- /dev/null +++ b/tests/bsim/bluetooth/compile.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Copyright 2018 Oticon A/S +# SPDX-License-Identifier: Apache-2.0 + +# Compile all the applications needed by the Bluetooth bsim tests + +#set -x #uncomment this line for debugging +set -ue + +: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root directory}" +: "${INFUSE_BASE:?INFUSE_BASE must be set to point to the Infuse-IoT root directory}" + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +run_in_background ${INFUSE_BASE}/tests/bsim/bluetooth/advertising/compile.sh + +wait_for_background_jobs diff --git a/tests/bsim/ci.bt.sh b/tests/bsim/ci.bt.sh new file mode 100755 index 000000000..138d05a30 --- /dev/null +++ b/tests/bsim/ci.bt.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Copyright 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# This script runs the Babblesim CI BT tests. +# It can also be run locally. +# Note it will produce its output in ${INFUSE_BASE}/bsim_bt/ + +export INFUSE_BASE="${INFUSE_BASE:-${PWD}}" +export ZEPHYR_BASE="${ZEPHYR_BASE:-${INFUSE_BASE}/../zephyr}" +cd ${INFUSE_BASE} + +set -uex + +# nrf52_bsim set: +nice tests/bsim/bluetooth/compile.sh + +RESULTS_FILE=${INFUSE_BASE}/bsim_out/bsim_results.bt.52.xml \ +SEARCH_PATH=tests/bsim/bluetooth \ +${ZEPHYR_BASE}/tests/bsim/run_parallel.sh diff --git a/tests/bsim/compile.sh b/tests/bsim/compile.sh new file mode 100755 index 000000000..5d3002afb --- /dev/null +++ b/tests/bsim/compile.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# Compile all the applications needed by all bsim tests + +#set -x #uncomment this line for debugging +set -ue + +: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root directory}" +: "${INFUSE_BASE:?INFUSE_BASE must be set to point to the Infuse-IoT root directory}" + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +run_in_background ${INFUSE_BASE}/tests/bsim/bluetooth/compile.sh + +wait_for_background_jobs diff --git a/tests/bsim/nrf_hw_models.patch b/tests/bsim/nrf_hw_models.patch new file mode 100644 index 000000000..b90a14f0e --- /dev/null +++ b/tests/bsim/nrf_hw_models.patch @@ -0,0 +1,22 @@ +diff --git a/src/HW_models/NHW_NVMC.c b/src/HW_models/NHW_NVMC.c +index ec2c027eba9e..fff661c73c27 100644 +--- a/src/HW_models/NHW_NVMC.c ++++ b/src/HW_models/NHW_NVMC.c +@@ -627,7 +627,7 @@ void nhw_nmvc_read_buffer(void *dest, uint32_t address, size_t size) { + } + } + +- if (offset + size >= backend->size) { ++ if (offset + size > backend->size) { + OUT_OF_FLASH_ERROR(address + size); + } + +diff --git a/zephyr/module.yml b/zephyr/module.yml +index eb317c3ce8a6..4ed35dd2011a 100644 +--- a/zephyr/module.yml ++++ b/zephyr/module.yml +@@ -1,2 +1,4 @@ + build: + cmake: . ++ depends: ++ - hal_nordic diff --git a/west.yml b/west.yml index fd6e21f3b..e7305330f 100644 --- a/west.yml +++ b/west.yml @@ -12,7 +12,7 @@ manifest: projects: - name: zephyr - revision: 92469c601d500ec47817b982cd760494782b139b + revision: 49140202d1fbb9d4a4b555e0350efe601a19ed20 # Limit imported repositories to reduce clone time import: name-allowlist: @@ -30,7 +30,7 @@ manifest: - zcbor - name: sdk-nrf path: modules/nrfconnect/sdk-nrf - revision: cca8709e56cd65561a330ed5b09def75aa4f72ba + revision: 563aa8f03456aeb1583487b4c1969c8a99b594ec import: true - name: memfault-firmware-sdk path: modules/lib/memfault @@ -40,3 +40,4 @@ manifest: self: path: infuse-sdk west-commands: scripts/west-commands.yml + import: submanifests