Skip to content

Commit

Permalink
tests: Bluetooth: Mesh: Add op_agg coex test
Browse files Browse the repository at this point in the history
Adds coexistence Bsim test for Opcode Aggregator models.
The test verifies that the Opcode Aggregator server and client can be
present and functional when operating on the same device.

Signed-off-by: Anders Storrø <[email protected]>
  • Loading branch information
Andrewpini committed Oct 19, 2023
1 parent fa5d18a commit 75a069d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 24 deletions.
91 changes: 67 additions & 24 deletions tests/bsim/bluetooth/mesh/src/test_op_agg.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ static struct k_sem cli_suspend_sem;
static struct k_sem srv_suspend_sem;
static const uint8_t dev_key[16] = {0xaa};
static uint8_t cli_sent_array[TEST_SEND_ITR], cli_rcvd_array[TEST_SEND_ITR];

static struct bt_mesh_msg_ctx test_ctx = {
.net_idx = 0,
.app_idx = 0,
.addr = SRV_ADDR,
};

static struct bt_mesh_prov prov;
static struct bt_mesh_cfg_cli cfg_cli;

Expand Down Expand Up @@ -168,25 +161,43 @@ static void op_agg_test_prov_and_conf(uint16_t addr)
}
}

static void test_cli_max_len_sequence_msg_send(void)
static void common_init(uint16_t own_addr, uint16_t dst_addr, bool agg_cli_fill)
{
struct bt_mesh_model *dummy_vnd_model = &elements[0].vnd_models[0];
uint8_t seq;

bt_mesh_test_cfg_set(NULL, WAIT_TIME);
bt_mesh_device_setup(&prov, &comp);
op_agg_test_prov_and_conf(CLI_ADDR);
op_agg_test_prov_and_conf(own_addr);

ASSERT_OK(k_sem_init(&cli_suspend_sem, 0, 1));
ASSERT_OK(bt_mesh_op_agg_cli_seq_start(0, 0, SRV_ADDR, SRV_ADDR));
ASSERT_OK(k_sem_init(&srv_suspend_sem, 0, 1));
ASSERT_OK(bt_mesh_op_agg_cli_seq_start(0, 0, dst_addr, dst_addr));

if (!agg_cli_fill) {
return;
}

struct bt_mesh_msg_ctx ctx = {
.net_idx = 0,
.app_idx = 0,
.addr = dst_addr,
};

/* Populate the op_agg sequence */
for (int i = 0; i < TEST_SEND_ITR; i++) {
seq = cli_sent_array[i] = i;
ASSERT_OK(dummy_vnd_mod_get(dummy_vnd_model, &test_ctx, seq));
cli_sent_array[i] = i;
ASSERT_OK(dummy_vnd_mod_get(&elements[0].vnd_models[0], &ctx, i));
}
}

ASSERT_OK(bt_mesh_op_agg_cli_seq_send());
static void confirm_agg_seq(void)
{
/* Wait for all expected GET messages to be received */
if (k_sem_take(&srv_suspend_sem, SEM_TIMEOUT)) {
FAIL("Server suspension timed out. Get-messages received: %d", get_rcvd_count);
}
}

static void confirm_agg_status(void)
{
/* Wait for all expected STATUS messages to be received */
if (k_sem_take(&cli_suspend_sem, SEM_TIMEOUT)) {
FAIL("Client suspension timed out. Status-messages received: %d",
Expand All @@ -196,22 +207,52 @@ static void test_cli_max_len_sequence_msg_send(void)
if (memcmp(cli_sent_array, cli_rcvd_array, ARRAY_SIZE(cli_rcvd_array))) {
FAIL("Message arrays (sent / rcvd) are not equal.");
}
}

static void test_cli_max_len_sequence_msg_send(void)
{
common_init(CLI_ADDR, SRV_ADDR, true);
ASSERT_OK(bt_mesh_op_agg_cli_seq_send());
confirm_agg_status();
PASS();
}

static void test_srv_max_len_status_msg_send(void)
{
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
bt_mesh_device_setup(&prov, &comp);
op_agg_test_prov_and_conf(SRV_ADDR);
common_init(SRV_ADDR, CLI_ADDR, false);
confirm_agg_seq();
PASS();
}

ASSERT_OK(k_sem_init(&srv_suspend_sem, 0, 1));
static void test_tester_model_coex(void)
{
common_init(CLI_ADDR, SRV_ADDR, true);

/* Wait for all expected GET messages to be received */
if (k_sem_take(&srv_suspend_sem, SEM_TIMEOUT)) {
FAIL("Server suspension timed out. Get-messages received: %d", get_rcvd_count);
}
/* Immediately send aggregated sequence to srv device */
ASSERT_OK(bt_mesh_op_agg_cli_seq_send());

/* Confirm status messages for sequence */
confirm_agg_status();

/* Confirm incoming sequence messages from server */
confirm_agg_seq();

PASS();
}

static void test_dut_model_coex(void)
{
/* Start an aggregated sequence, but postpone sending it */
common_init(SRV_ADDR, CLI_ADDR, true);

/* Wait and confirm incoming sequence messages from cli device */
confirm_agg_seq();

/* After incoming sequence completes, send aggregated sequence to srv device */
ASSERT_OK(bt_mesh_op_agg_cli_seq_send());

/* Confirm status messages for sequence */
confirm_agg_status();

PASS();
}
Expand All @@ -228,8 +269,10 @@ static const struct bst_test_instance test_op_agg[] = {
TEST_CASE(cli, max_len_sequence_msg_send,
"OpAggCli composes a sequence request list, expecting a 380 Byte status message "
"in return."),
TEST_CASE(tester, model_coex, "Tester: Coexistence of OpAggSrv and OpAggCli."),
TEST_CASE(srv, max_len_status_msg_send,
"OpAggSrv will respond with a 380 Byte status message. "),
TEST_CASE(dut, model_coex, "DUT: Coexistence of OpAggSrv and OpAggCli."),

BSTEST_END_MARKER};

Expand Down
31 changes: 31 additions & 0 deletions tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Copyright 2023 Nordic Semiconductor
# SPDX-License-Identifier: Apache-2.0

source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh

# Test that Opcode aggregator server and client can coexist on the same device.
# In this test scenario, the DUT has a sequence in progress on the Opcode
# Aggregator client model that is interrupted by an incoming sequence to the Opcode
# Aggregator server model. The test verifies that both the incoming and outgoing
# sequence on the DUT completes successfully.
#
# Test procedure:
# 1. Both Tester and DUT device initialize both Opcode aggregator server and client.
# Both devices starts an Opcode aggregator sequence and populates the buffer.
# 2. The Tester device immediately starts sending the sequence.
# 3. The DUT device waits, and verifies that the sequence is correctly received.
# Then it starts sending its own aggregated sequence.
# 4. The Tester device confirms that it received all status messages related to its
# own aggregated sequence from the DUT device, then it verifies that the
# aggregated sequence from the DUT device is correctly received.
# 5. Finally, the DUT device waits and confirms that it received all status messages
# related to its own aggregated sequence from the cli device.
conf=prj_mesh1d1_conf
RunTest mesh_op_agg_model_coex \
op_agg_tester_model_coex op_agg_dut_model_coex

conf=prj_mesh1d1_conf
overlay=overlay_psa_conf
RunTest mesh_op_agg_model_coex \
op_agg_tester_model_coex op_agg_dut_model_coex

0 comments on commit 75a069d

Please sign in to comment.