From a7f648c79377b2367bae7b61c0df6cb51c541d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 18 Oct 2023 17:48:11 +0200 Subject: [PATCH] tests: Bluetooth: Mesh: Add op_agg coex test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- tests/bsim/bluetooth/mesh/src/test_op_agg.c | 93 +++++++++++++------ .../mesh/tests_scripts/op_agg/model_coex.sh | 31 +++++++ 2 files changed, 98 insertions(+), 26 deletions(-) create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh diff --git a/tests/bsim/bluetooth/mesh/src/test_op_agg.c b/tests/bsim/bluetooth/mesh/src/test_op_agg.c index 9f091491e00ebce..edc79c2b545144c 100644 --- a/tests/bsim/bluetooth/mesh/src/test_op_agg.c +++ b/tests/bsim/bluetooth/mesh/src/test_op_agg.c @@ -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; @@ -168,25 +161,41 @@ 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)); - - 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)); + 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) { + 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++) { + 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", @@ -196,22 +205,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(); } @@ -228,8 +267,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}; diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh new file mode 100755 index 000000000000000..68c95eff2b66f93 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Copyright 2022 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