Bluetooth: Test: Add long AD test
Test that the Host give back the correct error when we try to set too big advertising data. And ensure that long advertising data are correctly transmitted. Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
This commit is contained in:
parent
a0198fe420
commit
8ba0ebab12
9 changed files with 478 additions and 0 deletions
|
@ -22,5 +22,6 @@ app=tests/bsim/bluetooth/host/adv/periodic compile
|
|||
app=tests/bsim/bluetooth/host/adv/periodic conf_file=prj_long_data.conf compile
|
||||
app=tests/bsim/bluetooth/host/adv/encrypted/css_sample_data compile
|
||||
app=tests/bsim/bluetooth/host/adv/encrypted/ead_sample compile
|
||||
app=tests/bsim/bluetooth/host/adv/long_ad compile
|
||||
|
||||
wait_for_background_jobs
|
||||
|
|
22
tests/bsim/bluetooth/host/adv/long_ad/CMakeLists.txt
Normal file
22
tests/bsim/bluetooth/host/adv/long_ad/CMakeLists.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(long_ad)
|
||||
|
||||
# This contains babblesim-specific helpers, e.g. device synchronization.
|
||||
add_subdirectory(${ZEPHYR_BASE}/tests/bsim/babblekit babblekit)
|
||||
target_link_libraries(app PRIVATE babblekit)
|
||||
|
||||
zephyr_include_directories(
|
||||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
|
||||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
|
||||
)
|
||||
|
||||
target_sources(app PRIVATE
|
||||
src/main.c
|
||||
src/advertiser.c
|
||||
src/scanner.c
|
||||
)
|
26
tests/bsim/bluetooth/host/adv/long_ad/prj.conf
Normal file
26
tests/bsim/bluetooth/host/adv/long_ad/prj.conf
Normal file
|
@ -0,0 +1,26 @@
|
|||
CONFIG_BT=y
|
||||
CONFIG_BT_DEVICE_NAME="long-ad"
|
||||
|
||||
CONFIG_BT_BROADCASTER=y
|
||||
CONFIG_BT_OBSERVER=y
|
||||
|
||||
CONFIG_BT_EXT_ADV=y
|
||||
|
||||
CONFIG_BT_CTLR_ADV_DATA_CHAIN=y
|
||||
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
|
||||
|
||||
CONFIG_BT_EXT_SCAN_BUF_SIZE=266
|
||||
CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2
|
||||
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=266
|
||||
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=266
|
||||
|
||||
CONFIG_BT_EXT_ADV_MAX_ADV_SET=1
|
||||
|
||||
CONFIG_ASSERT=y
|
||||
|
||||
CONFIG_LOG=y
|
||||
|
||||
# Will call `raise(SIGTRAP)` on fatal error.
|
||||
# If a debugger is connected to the app, it will automatically be stopped.
|
||||
# Makes retrieving an exception stacktrace very easy.
|
||||
CONFIG_ARCH_POSIX_TRAP_ON_FATAL=y
|
59
tests/bsim/bluetooth/host/adv/long_ad/src/ad.h
Normal file
59
tests/bsim/bluetooth/host/adv/long_ad/src/ad.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t test_ad1[] = {
|
||||
0xe9, 0xff, 0x7c, 0xe8, 0x40, 0x60, 0x3a, 0x10, 0x43, 0xba, 0x2e, 0x75, 0xbd, 0x0a, 0x07,
|
||||
0xe2, 0xf1, 0x61, 0x56, 0xea, 0xc1, 0x70, 0x98, 0x6f, 0x8a, 0xb1, 0x74, 0x52, 0x43, 0x6f,
|
||||
0x47, 0xbf, 0x81, 0x95, 0x60, 0xe7, 0x80, 0x68, 0x9a, 0x16, 0xe9, 0xa8, 0x61, 0x03, 0x3a,
|
||||
0x3e, 0xc1, 0x8e, 0x2a, 0xde, 0x27, 0x9b, 0xaa, 0xe7, 0x7d, 0x79, 0x20, 0x5e, 0xd0, 0x4a,
|
||||
0xb3, 0xd7, 0x5a, 0x3c, 0xfc, 0x1b, 0x6e, 0xd6, 0x19, 0x3b, 0xa7, 0x94, 0xc1, 0xeb, 0x1e,
|
||||
0x6c, 0x94, 0x76, 0x6f, 0x45, 0x0f, 0x72, 0x22, 0xbf, 0x3c, 0x4a, 0xaf, 0x0f, 0xf8, 0x82,
|
||||
0xa6, 0xa6, 0x2a, 0x9f, 0x15, 0x93, 0x38, 0x5b, 0x71, 0xec, 0x0d, 0xed, 0xfe, 0x26, 0x8a,
|
||||
0xca, 0x2b, 0x29, 0x9a, 0x55, 0x9d, 0x14, 0xf1, 0x21, 0x10, 0xa4, 0x05, 0x5f, 0xf8, 0x46,
|
||||
0x73, 0x90, 0xc3, 0x62, 0x46, 0x57, 0x36, 0x65, 0xfc, 0x98, 0xc1, 0xe5, 0xc6, 0xcd, 0x58,
|
||||
0xc0, 0xa9, 0x97, 0x76, 0x43, 0x8c, 0x84, 0xac, 0xa2, 0x84, 0xe3, 0xe0, 0x45, 0x1c, 0xb9,
|
||||
0xc2, 0x44, 0xdc, 0xbc, 0x15, 0x3c, 0x81, 0x0f, 0x65, 0x13, 0xc6, 0xe1, 0x8b, 0x74, 0xb1,
|
||||
0x1f, 0x54, 0x67, 0xfc, 0x1d, 0x72, 0x4d, 0x4f, 0x29, 0x61, 0x4c, 0xf9, 0x3f, 0xfc, 0x98,
|
||||
0xf6, 0x00, 0xbe, 0xfd, 0x17, 0x51, 0x86, 0x21, 0x83, 0x32, 0x87, 0xed, 0xdf, 0xb9, 0xc1,
|
||||
0xc9, 0xe7, 0x3a, 0xe7, 0x12, 0x19, 0x98, 0x2e, 0x9d, 0xcc, 0xa8, 0xa9, 0x94, 0xe9, 0x31,
|
||||
0xb1, 0xa0, 0xf0, 0xd1, 0x72, 0x1c, 0xfe, 0x21, 0xa0, 0xb9, 0xf0, 0x47, 0x15, 0xa1, 0x1a,
|
||||
0x7a, 0x80, 0xac, 0x0d, 0x2b, 0xa7, 0x7a, 0x2f, 0x22, 0x97, 0xff, 0x45, 0x13, 0xaf, 0xb9,
|
||||
0x82, 0x68, 0xfc, 0x52, 0xd1, 0xff, 0xc5, 0x03, 0x01, 0xc1, 0x21, 0xd3, 0xfc, 0xb1, 0xcd,
|
||||
0x65, 0xd5, 0x7e, 0x1b, 0x81, 0x7c, 0x62, 0x7d, 0x24, 0x9e, 0xfa, 0xe7, 0x12, 0x01, 0x9a,
|
||||
0x19, 0x11, 0xa7, 0x50, 0x40, 0x1b, 0x99, 0xb9, 0xf4, 0x17, 0xbe, 0xbe, 0x8d, 0xaa, 0xde,
|
||||
0xdd, 0xba, 0xfe, 0xb2, 0x76, 0x50, 0x99, 0xb4, 0xf4, 0x0e, 0x8e, 0xea, 0x8e, 0x90, 0x2e,
|
||||
0x77, 0xc9, 0xd2, 0xa9, 0xe2, 0xd5, 0xdb, 0x51, 0x77, 0xf4, 0x87, 0xb8, 0xb7, 0xc9, 0x0b,
|
||||
0x8e, 0x3c, 0x7c, 0x8e, 0xf6, 0x0a, 0xb1, 0x26, 0x25, 0xba, 0x73, 0x09, 0x25, 0x14, 0x32,
|
||||
0xd9, 0xba, 0x2c, 0x52, 0xd2, 0x9a, 0xfc, 0xae, 0xd6, 0xcc, 0x9d, 0xc3, 0xf9, 0x4e, 0x1a,
|
||||
0x37, 0x15, 0x3f, 0x1b, 0x86, 0x6a, 0x0a, 0x08, 0xe6, 0x1e, 0xcc, 0xf6, 0xe6, 0xca, 0x19,
|
||||
0x93, 0x61, 0x5f, 0x32, 0x34, 0x4b, 0xc6, 0x3d, 0x3d, 0x21, 0x66, 0x82, 0xaa, 0x68, 0x4d,
|
||||
0x08, 0x4b, 0x6d, 0x34, 0x98, 0x28, 0xdd, 0xa5, 0xae, 0x43, 0xe3,
|
||||
};
|
||||
BUILD_ASSERT(sizeof(test_ad1) > CONFIG_BT_CTLR_ADV_DATA_LEN_MAX);
|
||||
|
||||
static const uint8_t test_ad2[] = {
|
||||
0xff, 0xff, 0x1d, 0x10, 0x11, 0x25, 0x2c, 0x1b, 0x9a, 0x18, 0xb3, 0xea, 0x99, 0x70, 0x93,
|
||||
0x4e, 0x5b, 0x93, 0x27, 0x86, 0xd9, 0x03, 0xf4, 0x22, 0x32, 0x09, 0x37, 0xed, 0x80, 0xe1,
|
||||
0xb2, 0xb8, 0x0d, 0x33, 0x70, 0x1e, 0xf1, 0x22, 0x73, 0xe5, 0xea, 0x33, 0x51, 0x98, 0x72,
|
||||
0x0a, 0xfc, 0x99, 0xbf, 0xe5, 0x28, 0x09, 0x7e, 0x7b, 0xab, 0xbb, 0xad, 0xc9, 0x92, 0x54,
|
||||
0x2d, 0xcd, 0x9c, 0x24, 0xba, 0x06, 0xa4, 0xbc, 0xad, 0x47, 0x7a, 0xa2, 0xac, 0x06, 0xb1,
|
||||
0xa6, 0xc5, 0x9c, 0x46, 0x5c, 0xdf, 0x74, 0x60, 0xa9, 0xa8, 0xe1, 0x7f, 0x48, 0x2e, 0x34,
|
||||
0xcc, 0xd2, 0x20, 0x4e, 0x7a, 0xa1, 0x2c, 0x3a, 0x84, 0x0b, 0x34, 0x39, 0xd5, 0x6f, 0x85,
|
||||
0x44, 0xf3, 0x93, 0xc0, 0xe5, 0x3e, 0xc0, 0x26, 0xa0, 0xe4, 0x21, 0xac, 0xf8, 0xa0, 0x19,
|
||||
0xb6, 0xdd, 0xe7, 0xb7, 0x44, 0x25, 0x42, 0x70, 0xf2, 0xb2, 0x36, 0x75, 0x77, 0xbb, 0x8c,
|
||||
0x86, 0x9f, 0x58, 0x29, 0xa9, 0xcd, 0xa3, 0x2b, 0x40, 0x53, 0x87, 0xd5, 0xe6, 0x14, 0x9f,
|
||||
0xec, 0x71, 0x9a, 0x75, 0x04, 0x50, 0xab, 0x9b, 0x46, 0x53, 0xdf, 0x95, 0xd8, 0xb6, 0x67,
|
||||
0xc9, 0x6b, 0x83, 0x36, 0x94, 0x67, 0x62, 0x98, 0xb8, 0xd8, 0xc1, 0x88, 0xa0, 0x3c, 0x98,
|
||||
0xbb, 0xd1, 0x68, 0x20, 0x26, 0x48, 0x89, 0x94, 0xca, 0x8b, 0xe2, 0x1d, 0xb4, 0xb5, 0xc0,
|
||||
0xef, 0x4f, 0xa7, 0x19, 0xaa, 0xd1, 0x95, 0xb2, 0x23, 0x88, 0xd0, 0x5a, 0x5a, 0x5d, 0xad,
|
||||
0x7e, 0x1e, 0x68, 0xd1, 0xa0, 0x64, 0xd1, 0xf9, 0x59, 0x72, 0xde, 0x00, 0x90, 0x49, 0x97,
|
||||
0xb3, 0x50, 0xdf, 0xb5, 0x15, 0x41, 0x72, 0x8c, 0x32, 0x66, 0xff, 0x4b, 0x2f, 0xd6, 0x89,
|
||||
0x97, 0x52, 0xd8, 0xba, 0xb2, 0xd0, 0x5b, 0x11, 0x8b, 0x38, 0xa2, 0x42, 0xfb, 0x47, 0xfe,
|
||||
0xb5, 0x09, 0x09, 0xf0, 0x9f, 0x94, 0xb5, 0xf0, 0x9f, 0xa6, 0xb7,
|
||||
};
|
||||
BUILD_ASSERT(sizeof(test_ad2) == CONFIG_BT_CTLR_ADV_DATA_LEN_MAX);
|
165
tests/bsim/bluetooth/host/adv/long_ad/src/advertiser.c
Normal file
165
tests/bsim/bluetooth/host/adv/long_ad/src/advertiser.c
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "ad.h"
|
||||
#include "babblekit/testcase.h"
|
||||
|
||||
LOG_MODULE_REGISTER(advertiser, LOG_LEVEL_INF);
|
||||
|
||||
static void create_adv(struct bt_le_ext_adv **adv)
|
||||
{
|
||||
int err;
|
||||
struct bt_le_adv_param params;
|
||||
|
||||
memset(¶ms, 0, sizeof(struct bt_le_adv_param));
|
||||
|
||||
params.options |= BT_LE_ADV_OPT_EXT_ADV;
|
||||
|
||||
params.id = BT_ID_DEFAULT;
|
||||
params.sid = 0;
|
||||
params.interval_min = BT_GAP_ADV_SLOW_INT_MIN;
|
||||
params.interval_max = BT_GAP_ADV_SLOW_INT_MAX;
|
||||
|
||||
err = bt_le_ext_adv_create(¶ms, NULL, adv);
|
||||
if (err) {
|
||||
TEST_FAIL("Failed to create advertiser (%d)\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
static void start_adv(struct bt_le_ext_adv *adv)
|
||||
{
|
||||
int err;
|
||||
int32_t timeout = 0;
|
||||
uint8_t num_events = 0;
|
||||
|
||||
struct bt_le_ext_adv_start_param start_params;
|
||||
|
||||
start_params.timeout = timeout;
|
||||
start_params.num_events = num_events;
|
||||
|
||||
err = bt_le_ext_adv_start(adv, &start_params);
|
||||
if (err) {
|
||||
TEST_FAIL("Failed to start advertiser (%d)\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
static size_t ad_deserialize(const uint8_t *input, size_t input_size, struct bt_data output[])
|
||||
{
|
||||
uint8_t type;
|
||||
uint8_t data_len;
|
||||
const uint8_t *data;
|
||||
|
||||
size_t idx = 0;
|
||||
size_t ad_len = 0;
|
||||
|
||||
while (idx < input_size) {
|
||||
data_len = input[idx] - 1;
|
||||
type = input[idx + 1];
|
||||
data = &input[idx + 2];
|
||||
|
||||
if (data_len + 2 > input_size - idx) {
|
||||
TEST_FAIL("malformed advertising data, expected %d bytes of data but got "
|
||||
"only %d "
|
||||
"bytes",
|
||||
data_len + 1, input_size - idx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
output[ad_len].data = data;
|
||||
output[ad_len].type = type;
|
||||
output[ad_len].data_len = data_len;
|
||||
|
||||
ad_len += 1;
|
||||
idx += data_len + 2;
|
||||
}
|
||||
|
||||
return ad_len;
|
||||
}
|
||||
|
||||
static int set_ad_data(struct bt_le_ext_adv *adv, const uint8_t *serialized_ad,
|
||||
size_t serialized_ad_size)
|
||||
{
|
||||
int err;
|
||||
size_t ad_len = 0;
|
||||
uint8_t max_ad_len = 10;
|
||||
|
||||
struct bt_data ad[max_ad_len];
|
||||
|
||||
ad_len = ad_deserialize(serialized_ad, serialized_ad_size, ad);
|
||||
|
||||
err = bt_le_ext_adv_set_data(adv, ad, ad_len, NULL, 0);
|
||||
if (err != 0 && err != -EDOM) {
|
||||
TEST_FAIL("Failed to set advertising data (%d)\n", err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void entrypoint_advertiser(void)
|
||||
{
|
||||
/* Test purpose:
|
||||
*
|
||||
* Verifies that we can send Advertising Data up to the size set in the
|
||||
* Kconfig. And if we try to set data too large we get the correct
|
||||
* error code.
|
||||
*
|
||||
* Two devices:
|
||||
* - `advertiser`: tries to send the data
|
||||
* - `scanner`: will receive the data and check that they match with the
|
||||
* data sent
|
||||
*
|
||||
* Procedure:
|
||||
* - [advertiser] try to use `test_ad1` as advertising data
|
||||
* - [advertiser] get the expected error (adv or scan resp too large)
|
||||
* - [advertiser] try to use `test_ad2` as advertising data
|
||||
* - [advertiser] get a success
|
||||
* - [advertiser] start advertiser
|
||||
* - [scanner] start scanner
|
||||
* - [scanner] wait until receiving advertising data matching `test_ad2`
|
||||
*
|
||||
* [verdict]
|
||||
* - advertiser receives the correct error code when trying to set
|
||||
* advertising data
|
||||
* - scanner receives the correct data in advertising data
|
||||
*/
|
||||
int err;
|
||||
struct bt_le_ext_adv *adv = NULL;
|
||||
|
||||
TEST_START("advertiser");
|
||||
|
||||
err = bt_enable(NULL);
|
||||
TEST_ASSERT(err == 0, "Can't enable Bluetooth (err %d)", err);
|
||||
|
||||
LOG_DBG("Bluetooth initialized");
|
||||
|
||||
create_adv(&adv);
|
||||
LOG_DBG("Advertiser created");
|
||||
|
||||
err = set_ad_data(adv, test_ad1, ARRAY_SIZE(test_ad1));
|
||||
TEST_ASSERT(err == -EDOM,
|
||||
"Tried to set Advertising Data larger than the controller can accept, "
|
||||
"expected failure with error code %d but got %d",
|
||||
-EDOM, err);
|
||||
|
||||
err = set_ad_data(adv, test_ad2, ARRAY_SIZE(test_ad2));
|
||||
TEST_ASSERT(err == 0,
|
||||
"Tried to set Advertising Data as large as the maximum advertising data size "
|
||||
"the controller can accept, expected success but got error code %d",
|
||||
err);
|
||||
LOG_DBG("AD set");
|
||||
|
||||
start_adv(adv);
|
||||
LOG_DBG("Advertiser started");
|
||||
|
||||
TEST_PASS("advertiser");
|
||||
}
|
53
tests/bsim/bluetooth/host/adv/long_ad/src/main.c
Normal file
53
tests/bsim/bluetooth/host/adv/long_ad/src/main.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#include "bs_tracing.h"
|
||||
#include "bstests.h"
|
||||
#include "babblekit/testcase.h"
|
||||
|
||||
extern void entrypoint_advertiser(void);
|
||||
extern void entrypoint_scanner(void);
|
||||
extern enum bst_result_t bst_result;
|
||||
|
||||
static void test_end_cb(void)
|
||||
{
|
||||
/* This callback will fire right before the executable returns */
|
||||
static const char demo_state[] = "My interesting state";
|
||||
|
||||
if (bst_result != Passed) {
|
||||
TEST_PRINT("Test has not passed. State: %s", demo_state);
|
||||
}
|
||||
}
|
||||
|
||||
static const struct bst_test_instance entrypoints[] = {
|
||||
{
|
||||
.test_id = "advertiser",
|
||||
.test_delete_f = test_end_cb,
|
||||
.test_main_f = entrypoint_advertiser,
|
||||
},
|
||||
{
|
||||
.test_id = "scanner",
|
||||
.test_delete_f = test_end_cb,
|
||||
.test_main_f = entrypoint_scanner,
|
||||
},
|
||||
BSTEST_END_MARKER,
|
||||
};
|
||||
|
||||
static struct bst_test_list *install(struct bst_test_list *tests)
|
||||
{
|
||||
return bst_add_tests(tests, entrypoints);
|
||||
};
|
||||
|
||||
bst_test_install_t test_installers[] = {install, NULL};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bst_main();
|
||||
|
||||
return 0;
|
||||
}
|
113
tests/bsim/bluetooth/host/adv/long_ad/src/scanner.c
Normal file
113
tests/bsim/bluetooth/host/adv/long_ad/src/scanner.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/bluetooth/hci.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "ad.h"
|
||||
|
||||
#include "babblekit/flags.h"
|
||||
#include "babblekit/testcase.h"
|
||||
|
||||
LOG_MODULE_REGISTER(scanner, LOG_LEVEL_INF);
|
||||
|
||||
DEFINE_FLAG(scan_received);
|
||||
|
||||
static bool data_parse_cb(struct bt_data *data, void *user_data)
|
||||
{
|
||||
LOG_DBG("Type: %02x (size: %d)", data->type, data->data_len);
|
||||
LOG_HEXDUMP_DBG(data->data, data->data_len, "Data:");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
|
||||
struct net_buf_simple *ad)
|
||||
{
|
||||
char addr_str[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
|
||||
|
||||
LOG_DBG("Device found: %s (RSSI %d)", addr_str, rssi);
|
||||
|
||||
if (ad->len > 0) {
|
||||
LOG_INF("Received AD of size %d", ad->len);
|
||||
|
||||
TEST_ASSERT(ad->len == ARRAY_SIZE(test_ad2),
|
||||
"Received %d bytes of Advertising Data %d bytes were expected", ad->len,
|
||||
ARRAY_SIZE(test_ad2));
|
||||
|
||||
if (memcmp(ad->data, test_ad2, ad->len) != 0) {
|
||||
LOG_HEXDUMP_ERR(ad->data, ad->len, "Received AD:");
|
||||
LOG_HEXDUMP_ERR(test_ad2, ARRAY_SIZE(test_ad2), "Expected AD:");
|
||||
TEST_FAIL("Received Advertising Data doesn't match expected ones");
|
||||
}
|
||||
}
|
||||
|
||||
bt_data_parse(ad, data_parse_cb, NULL);
|
||||
|
||||
SET_FLAG(scan_received);
|
||||
}
|
||||
|
||||
static void start_scan(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found);
|
||||
if (err) {
|
||||
TEST_FAIL("Scanning failed to start (err %d)\n", err);
|
||||
}
|
||||
|
||||
LOG_DBG("Scanning successfully started");
|
||||
}
|
||||
|
||||
void entrypoint_scanner(void)
|
||||
{
|
||||
/* Test purpose:
|
||||
*
|
||||
* Verifies that we can send Advertising Data up to the size set in the
|
||||
* Kconfig. And if we try to set data too large we get the correct
|
||||
* error code.
|
||||
*
|
||||
* Two devices:
|
||||
* - `advertiser`: tries to send the data
|
||||
* - `scanner`: will receive the data and check that they match with the
|
||||
* data sent
|
||||
*
|
||||
* Procedure:
|
||||
* - [advertiser] try to use `test_ad1` as advertising data
|
||||
* - [advertiser] get the expected error (adv or scan resp too large)
|
||||
* - [advertiser] try to use `test_ad2` as advertising data
|
||||
* - [advertiser] get a success
|
||||
* - [advertiser] start advertiser
|
||||
* - [scanner] start scanner
|
||||
* - [scanner] wait until receiving advertising data matching `test_ad2`
|
||||
*
|
||||
* [verdict]
|
||||
* - advertiser receives the correct error code when trying to set
|
||||
* advertising data
|
||||
* - scanner receives the correct data in advertising data
|
||||
*/
|
||||
int err;
|
||||
|
||||
TEST_START("scanner");
|
||||
|
||||
err = bt_enable(NULL);
|
||||
TEST_ASSERT(err == 0, "Can't enable Bluetooth (err %d)", err);
|
||||
|
||||
LOG_DBG("Bluetooth initialized");
|
||||
|
||||
start_scan();
|
||||
|
||||
LOG_DBG("Wait until we receive at least one AD");
|
||||
WAIT_FOR_FLAG(scan_received);
|
||||
|
||||
TEST_PASS_AND_EXIT("scanner");
|
||||
}
|
13
tests/bsim/bluetooth/host/adv/long_ad/test_scripts/_compile.sh
Executable file
13
tests/bsim/bluetooth/host/adv/long_ad/test_scripts/_compile.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright 2023 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
set -eu
|
||||
: "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}"
|
||||
|
||||
INCR_BUILD=1
|
||||
|
||||
source ${ZEPHYR_BASE}/tests/bsim/compile.source
|
||||
|
||||
app="$(guess_test_relpath)" compile
|
||||
|
||||
wait_for_background_jobs
|
26
tests/bsim/bluetooth/host/adv/long_ad/test_scripts/run.sh
Executable file
26
tests/bsim/bluetooth/host/adv/long_ad/test_scripts/run.sh
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2024 Nordic Semiconductor
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -eu
|
||||
|
||||
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
|
||||
|
||||
test_name="$(guess_test_long_name)"
|
||||
|
||||
simulation_id=${test_name}
|
||||
|
||||
verbosity_level=2
|
||||
|
||||
SIM_LEN_US=$((2 * 1000 * 1000))
|
||||
|
||||
test_exe="${BSIM_OUT_PATH}/bin/bs_${BOARD_TS}_${test_name}_prj_conf"
|
||||
|
||||
cd ${BSIM_OUT_PATH}/bin
|
||||
|
||||
Execute "${test_exe}" -v=${verbosity_level} -s=${simulation_id} -d=0 -rs=420 -testid=advertiser
|
||||
Execute "${test_exe}" -v=${verbosity_level} -s=${simulation_id} -d=1 -rs=69 -testid=scanner
|
||||
|
||||
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=2 -sim_length=${SIM_LEN_US} $@
|
||||
|
||||
wait_for_background_jobs
|
Loading…
Add table
Add a link
Reference in a new issue