tests: bsim: Add HAS test for reading of preset list

This adds Read Presets operation bsim test.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2022-04-22 14:43:55 +02:00 committed by Marti Bolivar
parent bc42cbd174
commit b86355b2e6
2 changed files with 78 additions and 0 deletions

View File

@ -11,9 +11,17 @@
extern enum bst_result_t bst_result;
extern const char *test_preset_name_1;
extern const char *test_preset_name_5;
extern const uint8_t test_preset_index_1;
extern const uint8_t test_preset_index_5;
extern const enum bt_has_properties test_preset_properties;
CREATE_FLAG(g_is_connected);
CREATE_FLAG(g_service_discovered);
CREATE_FLAG(g_preset_switched);
CREATE_FLAG(g_preset_1_found);
CREATE_FLAG(g_preset_5_found);
static struct bt_conn *g_conn;
static struct bt_has *g_has;
@ -39,9 +47,41 @@ static void preset_switch_cb(struct bt_has *has, uint8_t index)
SET_FLAG(g_preset_switched);
}
static void check_preset_record(const struct bt_has_preset_record *record,
enum bt_has_properties expected_properties,
const char *expected_name)
{
if (record->properties != expected_properties || strcmp(record->name, expected_name)) {
FAIL("mismatch 0x%02x %s vs 0x%02x %s expected\n",
record->properties, record->name, expected_properties, expected_name);
}
}
static void preset_read_rsp_cb(struct bt_has *has, int err,
const struct bt_has_preset_record *record, bool is_last)
{
if (err) {
FAIL("%s: err %d\n", __func__, err);
return;
}
if (record->index == test_preset_index_1) {
SET_FLAG(g_preset_1_found);
check_preset_record(record, test_preset_properties, test_preset_name_1);
} else if (record->index == test_preset_index_5) {
SET_FLAG(g_preset_5_found);
check_preset_record(record, test_preset_properties, test_preset_name_5);
} else {
FAIL("unexpected index 0x%02x", record->index);
}
}
static const struct bt_has_client_cb has_cb = {
.discover = discover_cb,
.preset_switch = preset_switch_cb,
.preset_read_rsp = preset_read_rsp_cb,
};
static void connected(struct bt_conn *conn, uint8_t err)
@ -101,6 +141,15 @@ static void test_main(void)
WAIT_FOR_COND(g_service_discovered);
WAIT_FOR_COND(g_preset_switched);
err = bt_has_client_presets_read(g_has, BT_HAS_PRESET_INDEX_FIRST, 255);
if (err < 0) {
FAIL("Failed to read presets (err %d)\n", err);
return;
}
WAIT_FOR_COND(g_preset_1_found);
WAIT_FOR_COND(g_preset_5_found);
PASS("HAS main PASS\n");
}

View File

@ -12,8 +12,15 @@
extern enum bst_result_t bst_result;
const uint8_t test_preset_index_1 = 0x01;
const uint8_t test_preset_index_5 = 0x05;
const char *test_preset_name_1 = "test_preset_name_1";
const char *test_preset_name_5 = "test_preset_name_5";
const enum bt_has_properties test_preset_properties = BT_HAS_PROP_AVAILABLE;
static void test_main(void)
{
struct bt_has_preset_register_param param;
int err;
err = bt_enable(NULL);
@ -32,6 +39,28 @@ static void test_main(void)
printk("Advertising successfully started\n");
param.index = test_preset_index_5;
param.properties = test_preset_properties;
param.name = test_preset_name_5;
err = bt_has_preset_register(&param);
if (err) {
FAIL("Preset register failed (err %d)\n", err);
return;
}
param.index = test_preset_index_1;
param.properties = test_preset_properties;
param.name = test_preset_name_1;
err = bt_has_preset_register(&param);
if (err) {
FAIL("Preset register failed (err %d)\n", err);
return;
}
printk("Presets registered\n");
PASS("HAS passed\n");
}