Tests: Bluetooth: Mesh: Refactor and cleanup of test_brg
This introduces a global variable controlling the number of remote nodes used in a given test case. This allows removal of the `TEST_TYPE_...` enums and further tests in the future that can use different remote node counts. This also cleans up the test source by extracting common tester initialization to separate functions, avoiding repetition. Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
This commit is contained in:
parent
88f62a1a5e
commit
1453f6e4ea
1 changed files with 108 additions and 158 deletions
|
@ -27,7 +27,6 @@ LOG_MODULE_REGISTER(test_brg, LOG_LEVEL_INF);
|
|||
#define DEVICE_ADDR_START 0x0003
|
||||
#define GROUP_ADDR 0xc000
|
||||
|
||||
#define REMOTE_NODES 2
|
||||
#define REMOTE_NODES_MULTICAST 3
|
||||
|
||||
static const uint8_t prov_dev_key[16] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
|
@ -60,11 +59,11 @@ static uint8_t recvd_msgs_cnt;
|
|||
|
||||
const struct bt_mesh_va *va_entry;
|
||||
|
||||
enum {
|
||||
TEST_TYPE_UNICAST = 0,
|
||||
TEST_TYPE_GROUP = 1,
|
||||
TEST_TYPE_VA = 2,
|
||||
};
|
||||
/*
|
||||
* The number of remote nodes participating in the test. Initialized to 2 because most tests use 2
|
||||
* remote nodes.
|
||||
*/
|
||||
static int remote_nodes = 2;
|
||||
|
||||
BUILD_ASSERT((2 /* opcode */ + 1 /* type */ + 1 /* msgs cnt */ + sizeof(recvd_msgs) +
|
||||
BT_MESH_MIC_SHORT) <= BT_MESH_RX_SDU_MAX,
|
||||
|
@ -160,11 +159,10 @@ static struct bt_mesh_prov bridge_prov = {
|
|||
.complete = prov_complete,
|
||||
};
|
||||
|
||||
static void tester_setup(int test_type)
|
||||
static void tester_setup(void)
|
||||
{
|
||||
uint8_t status;
|
||||
int err;
|
||||
int subnets = (test_type == TEST_TYPE_UNICAST) ? REMOTE_NODES : REMOTE_NODES_MULTICAST;
|
||||
|
||||
ASSERT_OK(bt_mesh_cdb_create(test_net_key));
|
||||
ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, test_ividx, PROV_ADDR, prov_dev_key));
|
||||
|
@ -181,7 +179,7 @@ static void tester_setup(int test_type)
|
|||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < subnets; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
LOG_INF("Creating subnet idx %d", i);
|
||||
|
||||
ASSERT_OK(
|
||||
|
@ -245,14 +243,14 @@ static void bridge_entry_remove(uint16_t src, uint16_t dst, uint16_t net_idx1, u
|
|||
}
|
||||
}
|
||||
|
||||
static void tester_bridge_configure(int subnets)
|
||||
static void tester_bridge_configure(void)
|
||||
{
|
||||
uint8_t status;
|
||||
int err;
|
||||
|
||||
LOG_INF("Configuring bridge...");
|
||||
|
||||
for (int i = 0; i < subnets; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
err = bt_mesh_cfg_cli_net_key_add(0, BRIDGE_ADDR, i + 1, subnet_keys[i], &status);
|
||||
if (err || status) {
|
||||
FAIL("NetKey add failed (err %d, status %u)", err, status);
|
||||
|
@ -279,7 +277,7 @@ static void tester_bridge_configure(int subnets)
|
|||
LOG_INF("Bridge configured");
|
||||
}
|
||||
|
||||
static void tester_device_configure(uint16_t net_key_idx, uint16_t addr, int test_type)
|
||||
static void tester_device_configure(uint16_t net_key_idx, uint16_t addr)
|
||||
{
|
||||
int err;
|
||||
uint8_t status;
|
||||
|
@ -303,25 +301,6 @@ static void tester_device_configure(uint16_t net_key_idx, uint16_t addr, int tes
|
|||
return;
|
||||
}
|
||||
|
||||
if (test_type == TEST_TYPE_GROUP) {
|
||||
err = bt_mesh_cfg_cli_mod_sub_add(net_key_idx, addr, addr, GROUP_ADDR, TEST_MOD_ID,
|
||||
&status);
|
||||
if (err || status) {
|
||||
FAIL("Mod sub add failed (err %d, status %u)", err, status);
|
||||
return;
|
||||
}
|
||||
} else if (test_type == TEST_TYPE_VA) {
|
||||
uint16_t vaddr;
|
||||
|
||||
err = bt_mesh_cfg_cli_mod_sub_va_add(net_key_idx, addr, addr, test_va_uuid,
|
||||
TEST_MOD_ID, &vaddr, &status);
|
||||
if (err || status) {
|
||||
FAIL("Mod sub VA add failed (err %d, status %u)", err, status);
|
||||
return;
|
||||
}
|
||||
ASSERT_EQUAL(vaddr, va_entry->addr);
|
||||
}
|
||||
|
||||
LOG_INF("Device 0x%04x configured", addr);
|
||||
}
|
||||
|
||||
|
@ -444,15 +423,14 @@ static void device_data_cb(uint8_t *data, size_t length)
|
|||
* hit when the devices send STATUS message encrypted with the subnet key known by the tester,
|
||||
* but with different app key pair (app key is the same, but net key <-> app key pair is different).
|
||||
*/
|
||||
static void tester_workaround(int test_type)
|
||||
static void tester_workaround(void)
|
||||
{
|
||||
uint8_t status;
|
||||
int err;
|
||||
int subnets = (test_type == TEST_TYPE_UNICAST) ? REMOTE_NODES : REMOTE_NODES_MULTICAST;
|
||||
|
||||
LOG_INF("Applying subnet's workaround for tester...");
|
||||
|
||||
for (int i = 0; i < subnets; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
err = bt_mesh_cfg_cli_net_key_del(0, PROV_ADDR, i + 1, &status);
|
||||
if (err || status) {
|
||||
FAIL("NetKey del failed (err %d, status %u)", err, status);
|
||||
|
@ -461,13 +439,41 @@ static void tester_workaround(int test_type)
|
|||
}
|
||||
}
|
||||
|
||||
static void tester_init_common(void)
|
||||
{
|
||||
bt_mesh_device_setup(&tester_prov, &comp);
|
||||
tester_setup();
|
||||
|
||||
for (int i = 0; i < 1 /* bridge */ + remote_nodes; i++) {
|
||||
LOG_INF("Waiting for a device to provision...");
|
||||
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
|
||||
}
|
||||
|
||||
tester_bridge_configure();
|
||||
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
tester_device_configure(i + 1, DEVICE_ADDR_START + i);
|
||||
}
|
||||
|
||||
bt_mesh_test_data_cb_setup(tester_data_cb);
|
||||
}
|
||||
|
||||
static void setup_basic_bridge(void)
|
||||
{
|
||||
/* Adding devices to bridge table */
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
bridge_entry_add(PROV_ADDR, DEVICE_ADDR_START + i, 0, i + 1,
|
||||
BT_MESH_BRG_CFG_DIR_TWOWAY);
|
||||
}
|
||||
}
|
||||
|
||||
static void send_and_receive(void)
|
||||
{
|
||||
const int msgs_cnt = 3;
|
||||
|
||||
LOG_INF("Sending data...");
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
uint8_t payload = i | i << 4;
|
||||
|
||||
for (int j = 0; j < msgs_cnt; j++) {
|
||||
|
@ -477,7 +483,7 @@ static void send_and_receive(void)
|
|||
|
||||
LOG_INF("Checking data...");
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
uint8_t payload = i | i << 4;
|
||||
|
||||
ASSERT_OK(send_get(DEVICE_ADDR_START + i, NULL));
|
||||
|
@ -496,30 +502,9 @@ static void test_tester_simple(void)
|
|||
int err;
|
||||
|
||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
||||
bt_mesh_device_setup(&tester_prov, &comp);
|
||||
|
||||
tester_setup(TEST_TYPE_UNICAST);
|
||||
|
||||
for (int i = 0; i < 1 /* bridge */ + REMOTE_NODES; i++) {
|
||||
LOG_INF("Waiting for a device to provision...");
|
||||
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
|
||||
}
|
||||
|
||||
tester_bridge_configure(REMOTE_NODES);
|
||||
|
||||
/* Adding devices to bridge table */
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
bridge_entry_add(PROV_ADDR, DEVICE_ADDR_START + i, 0, i + 1,
|
||||
BT_MESH_BRG_CFG_DIR_TWOWAY);
|
||||
}
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
tester_device_configure(i + 1, DEVICE_ADDR_START + i, TEST_TYPE_UNICAST);
|
||||
}
|
||||
|
||||
tester_workaround(TEST_TYPE_UNICAST);
|
||||
|
||||
bt_mesh_test_data_cb_setup(tester_data_cb);
|
||||
tester_init_common();
|
||||
setup_basic_bridge();
|
||||
tester_workaround();
|
||||
|
||||
LOG_INF("Step 1: Checking bridging table...");
|
||||
|
||||
|
@ -534,7 +519,7 @@ static void test_tester_simple(void)
|
|||
}
|
||||
|
||||
LOG_INF("Sending data...");
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
uint8_t payload = i | i << 4;
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
|
@ -550,7 +535,7 @@ static void test_tester_simple(void)
|
|||
}
|
||||
|
||||
LOG_INF("Checking data...");
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
ASSERT_OK(send_get(DEVICE_ADDR_START + i, NULL));
|
||||
ASSERT_OK(k_sem_take(&status_msg_recvd_sem, K_SECONDS(5)));
|
||||
|
||||
|
@ -560,34 +545,16 @@ static void test_tester_simple(void)
|
|||
PASS();
|
||||
}
|
||||
|
||||
static void tester_simple_multicast(int test_type)
|
||||
static void tester_simple_multicast(uint16_t addr, const uint8_t *uuid)
|
||||
{
|
||||
uint8_t status;
|
||||
int err;
|
||||
const int msgs_cnt = 3;
|
||||
uint16_t addr = (test_type == TEST_TYPE_GROUP) ? GROUP_ADDR : va_entry->addr;
|
||||
const uint8_t *uuid = (test_type == TEST_TYPE_VA) ? va_entry->uuid : NULL;
|
||||
|
||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
||||
bt_mesh_device_setup(&tester_prov, &comp);
|
||||
|
||||
tester_setup(test_type);
|
||||
|
||||
for (int i = 0; i < 1 /* bridge */ + REMOTE_NODES_MULTICAST; i++) {
|
||||
LOG_INF("Waiting for a device to provision...");
|
||||
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
|
||||
}
|
||||
|
||||
tester_bridge_configure(REMOTE_NODES_MULTICAST);
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES_MULTICAST; i++) {
|
||||
tester_device_configure(i + 1, DEVICE_ADDR_START + i, test_type);
|
||||
}
|
||||
|
||||
/* Adding devices to bridge table */
|
||||
for (int i = 0; i < REMOTE_NODES_MULTICAST; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
/* Bridge messages from tester to multicast addr, for each subnet expect the last */
|
||||
if (i != REMOTE_NODES_MULTICAST - 1) {
|
||||
if (i != remote_nodes - 1) {
|
||||
bridge_entry_add(PROV_ADDR, addr, 0, i + 1, BT_MESH_BRG_CFG_DIR_ONEWAY);
|
||||
}
|
||||
|
||||
|
@ -596,7 +563,7 @@ static void tester_simple_multicast(int test_type)
|
|||
BT_MESH_BRG_CFG_DIR_ONEWAY);
|
||||
}
|
||||
|
||||
tester_workaround(test_type);
|
||||
tester_workaround();
|
||||
|
||||
bt_mesh_test_data_cb_setup(tester_data_cb);
|
||||
|
||||
|
@ -611,7 +578,7 @@ static void tester_simple_multicast(int test_type)
|
|||
LOG_INF("Checking data...");
|
||||
|
||||
ASSERT_OK(send_get(addr, uuid));
|
||||
for (int i = 0; i < REMOTE_NODES_MULTICAST - 1; i++) {
|
||||
for (int i = 0; i < remote_nodes - 1; i++) {
|
||||
ASSERT_OK(k_sem_take(&status_msg_recvd_sem, K_SECONDS(5)));
|
||||
|
||||
ASSERT_EQUAL(recvd_msgs_cnt, msgs_cnt);
|
||||
|
@ -642,7 +609,7 @@ static void tester_simple_multicast(int test_type)
|
|||
|
||||
LOG_INF("Checking data...");
|
||||
ASSERT_OK(send_get(addr, uuid));
|
||||
for (int i = 0; i < REMOTE_NODES_MULTICAST - 1; i++) {
|
||||
for (int i = 0; i < remote_nodes - 1; i++) {
|
||||
ASSERT_OK(k_sem_take(&status_msg_recvd_sem, K_SECONDS(5)));
|
||||
ASSERT_EQUAL(recvd_msgs_cnt, 0);
|
||||
}
|
||||
|
@ -650,15 +617,53 @@ static void tester_simple_multicast(int test_type)
|
|||
|
||||
static void test_tester_simple_group(void)
|
||||
{
|
||||
tester_simple_multicast(TEST_TYPE_GROUP);
|
||||
int err;
|
||||
uint8_t status;
|
||||
|
||||
remote_nodes = REMOTE_NODES_MULTICAST;
|
||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
||||
tester_init_common();
|
||||
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
err = bt_mesh_cfg_cli_mod_sub_add(i + 1, DEVICE_ADDR_START + i,
|
||||
DEVICE_ADDR_START + i, GROUP_ADDR, TEST_MOD_ID,
|
||||
&status);
|
||||
if (err || status) {
|
||||
FAIL("Mod sub add failed (err %d, status %u)", err, status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
tester_simple_multicast(GROUP_ADDR, NULL);
|
||||
PASS();
|
||||
}
|
||||
|
||||
static void test_tester_simple_va(void)
|
||||
{
|
||||
int err;
|
||||
uint8_t status;
|
||||
uint16_t vaddr;
|
||||
|
||||
remote_nodes = REMOTE_NODES_MULTICAST;
|
||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
||||
|
||||
ASSERT_OK(bt_mesh_va_add(test_va_uuid, &va_entry));
|
||||
ASSERT_TRUE(va_entry != NULL);
|
||||
tester_simple_multicast(TEST_TYPE_VA);
|
||||
|
||||
tester_init_common();
|
||||
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
err = bt_mesh_cfg_cli_mod_sub_va_add(i + 1, DEVICE_ADDR_START + i,
|
||||
DEVICE_ADDR_START + i, test_va_uuid,
|
||||
TEST_MOD_ID, &vaddr, &status);
|
||||
if (err || status) {
|
||||
FAIL("Mod sub VA add failed (err %d, status %u)", err, status);
|
||||
return;
|
||||
}
|
||||
ASSERT_EQUAL(vaddr, va_entry->addr);
|
||||
}
|
||||
|
||||
tester_simple_multicast(va_entry->addr, va_entry->uuid);
|
||||
PASS();
|
||||
}
|
||||
|
||||
|
@ -667,24 +672,8 @@ static void test_tester_table_state_change(void)
|
|||
int err;
|
||||
|
||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
||||
bt_mesh_device_setup(&tester_prov, &comp);
|
||||
|
||||
tester_setup(TEST_TYPE_UNICAST);
|
||||
|
||||
for (int i = 0; i < 1 /* bridge */ + REMOTE_NODES; i++) {
|
||||
LOG_INF("Waiting for a device to provision...");
|
||||
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
|
||||
}
|
||||
|
||||
tester_bridge_configure(REMOTE_NODES);
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
tester_device_configure(i + 1, DEVICE_ADDR_START + i, TEST_TYPE_UNICAST);
|
||||
}
|
||||
|
||||
tester_workaround(TEST_TYPE_UNICAST);
|
||||
|
||||
bt_mesh_test_data_cb_setup(tester_data_cb);
|
||||
tester_init_common();
|
||||
tester_workaround();
|
||||
|
||||
/* Bridge Table is empty, will not get any message back. */
|
||||
ASSERT_OK(send_get(DEVICE_ADDR_START, NULL));
|
||||
|
@ -764,30 +753,9 @@ static void test_tester_net_key_remove(void)
|
|||
int err;
|
||||
|
||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
||||
bt_mesh_device_setup(&tester_prov, &comp);
|
||||
|
||||
tester_setup(TEST_TYPE_UNICAST);
|
||||
|
||||
for (int i = 0; i < 1 /* bridge */ + REMOTE_NODES; i++) {
|
||||
LOG_INF("Waiting for a device to provision...");
|
||||
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
|
||||
}
|
||||
|
||||
tester_bridge_configure(REMOTE_NODES);
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
tester_device_configure(i + 1, DEVICE_ADDR_START + i, TEST_TYPE_UNICAST);
|
||||
}
|
||||
|
||||
tester_workaround(TEST_TYPE_UNICAST);
|
||||
|
||||
bt_mesh_test_data_cb_setup(tester_data_cb);
|
||||
|
||||
/* Adding devices to bridge table */
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
bridge_entry_add(PROV_ADDR, DEVICE_ADDR_START + i, 0, i + 1,
|
||||
BT_MESH_BRG_CFG_DIR_TWOWAY);
|
||||
}
|
||||
tester_init_common();
|
||||
setup_basic_bridge();
|
||||
tester_workaround();
|
||||
|
||||
ASSERT_OK(send_data(DEVICE_ADDR_START, 0xAA, NULL));
|
||||
ASSERT_OK(send_get(DEVICE_ADDR_START, NULL));
|
||||
|
@ -867,16 +835,16 @@ static void test_tester_persistence(void)
|
|||
},
|
||||
1);
|
||||
} else {
|
||||
tester_setup(TEST_TYPE_UNICAST);
|
||||
tester_setup();
|
||||
|
||||
LOG_INF("Waiting for a bridge to provision...");
|
||||
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
|
||||
|
||||
LOG_INF("Configuring bridge...");
|
||||
tester_bridge_configure(REMOTE_NODES);
|
||||
tester_bridge_configure();
|
||||
|
||||
/* Adding devices to bridge table */
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
bridge_entry_add(PROV_ADDR, DEVICE_ADDR_START + i, 0, i + 1,
|
||||
BT_MESH_BRG_CFG_DIR_TWOWAY);
|
||||
bridge_entry_add(DEVICE_ADDR_START + i, PROV_ADDR, i + 1, 0,
|
||||
|
@ -901,7 +869,7 @@ static void msg_cache_workaround(void)
|
|||
{
|
||||
LOG_INF("Applying Msg Cache workaround...");
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
for (int i = 0; i < remote_nodes; i++) {
|
||||
for (int j = 0; j < CONFIG_BT_MESH_MSG_CACHE_SIZE; j++) {
|
||||
ASSERT_OK(send_get(DEVICE_ADDR_START + i, NULL));
|
||||
/* k_sem_take is needed to not overflow network buffer pool. The result
|
||||
|
@ -958,31 +926,10 @@ static void propagate_ivi_update_state(void)
|
|||
static void test_tester_ivu(void)
|
||||
{
|
||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME_IVU_TEST);
|
||||
bt_mesh_device_setup(&tester_prov, &comp);
|
||||
bt_mesh_iv_update_test(true);
|
||||
|
||||
tester_setup(TEST_TYPE_UNICAST);
|
||||
|
||||
for (int i = 0; i < 1 /* bridge */ + REMOTE_NODES; i++) {
|
||||
LOG_INF("Waiting for a device to provision...");
|
||||
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
|
||||
}
|
||||
|
||||
tester_bridge_configure(REMOTE_NODES);
|
||||
|
||||
/* Adding devices to bridge table */
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
bridge_entry_add(PROV_ADDR, DEVICE_ADDR_START + i, 0, i + 1,
|
||||
BT_MESH_BRG_CFG_DIR_TWOWAY);
|
||||
}
|
||||
|
||||
for (int i = 0; i < REMOTE_NODES; i++) {
|
||||
tester_device_configure(i + 1, DEVICE_ADDR_START + i, TEST_TYPE_UNICAST);
|
||||
}
|
||||
|
||||
tester_workaround(TEST_TYPE_UNICAST);
|
||||
|
||||
bt_mesh_test_data_cb_setup(tester_data_cb);
|
||||
tester_init_common();
|
||||
setup_basic_bridge();
|
||||
tester_workaround();
|
||||
|
||||
ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS));
|
||||
ASSERT_TRUE(bt_mesh.iv_index == test_ividx);
|
||||
|
@ -1021,6 +968,9 @@ static void test_tester_ivu(void)
|
|||
|
||||
propagate_ivi_update_state();
|
||||
|
||||
/* Sleep here to avoid packet collision. */
|
||||
k_sleep(K_MSEC(300));
|
||||
|
||||
send_and_receive();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue