Skip to content

Commit

Permalink
tests: update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Konrad Derda <[email protected]>
  • Loading branch information
konradderda committed Sep 18, 2024
1 parent f9fabab commit a06d443
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
6 changes: 6 additions & 0 deletions tests/unit_tests/pal_ble_adapter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ config SIDEWALK_LOG_LEVEL
config SIDEWALK_BLE_ADAPTER_LOG_LEVEL
default 0

config SIDEWALK_BLE_ID
default 1

config BT_ID_MAX
default 2

source "Kconfig.zephyr"
6 changes: 5 additions & 1 deletion tests/unit_tests/pal_ble_adapter/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ FAKE_VALUE_FUNC(ssize_t, bt_gatt_attr_read_ccc, struct bt_conn *, const struct b
void *, uint16_t, uint16_t);
FAKE_VALUE_FUNC(ssize_t, bt_gatt_attr_write_ccc, struct bt_conn *, const struct bt_gatt_attr *,
const void *, uint16_t, uint16_t, uint8_t);
FAKE_VOID_FUNC(bt_id_get, bt_addr_le_t *, size_t *);
FAKE_VALUE_FUNC(int, bt_id_create, bt_addr_le_t *, uint8_t *);

#define FFF_FAKES_LIST(FAKE) \
FAKE(bt_enable) \
Expand All @@ -51,10 +53,12 @@ FAKE_VALUE_FUNC(ssize_t, bt_gatt_attr_write_ccc, struct bt_conn *, const struct
FAKE(bt_conn_ref) \
FAKE(bt_conn_unref) \
FAKE(bt_conn_get_dst) \
FAKE(bt_id_get) \
FAKE(bt_id_create) \
FAKE(bt_gatt_attr_read_service) \
FAKE(bt_gatt_attr_read_chrc) \
FAKE(bt_gatt_attr_read_ccc) \
FAKE(bt_gatt_attr_write_ccc)
FAKE(bt_gatt_attr_write_ccc) \

#define ESUCCESS (0)
#define FAKE_SERVICE (9)
Expand Down
6 changes: 5 additions & 1 deletion tests/unit_tests/sid_ble_advert/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config SIDEWALK_BLE_ADV_INT_PRECISION
config SIDEWALK_BLE_ADV_INT_FAST
int "test value for Sidewalk configuration macro"
default 160

config SIDEWALK_BLE_ADV_INT_SLOW
int "test value for Sidewalk configuration macro"
default 1000
Expand All @@ -29,4 +29,8 @@ config SIDEWALK_BLE_ADV_INT_TRANSITION
int "test value for Sidewalk configuration macro"
default 30

config SIDEWALK_BLE_ID
int "test value for Sidewalk configuration"
default 1

source "Kconfig.zephyr"
69 changes: 35 additions & 34 deletions tests/unit_tests/sid_ble_advert/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

DEFINE_FFF_GLOBALS;

FAKE_VALUE_FUNC(int, bt_le_adv_start, const struct bt_le_adv_param *, const struct bt_data *,
size_t, const struct bt_data *, size_t);
FAKE_VALUE_FUNC(int, bt_le_adv_stop);
FAKE_VALUE_FUNC(int, bt_le_adv_update_data, const struct bt_data *, size_t, const struct bt_data *,
size_t);
FAKE_VALUE_FUNC(int, bt_le_ext_adv_start, struct bt_le_ext_adv *,
const struct bt_le_ext_adv_start_param *);
FAKE_VALUE_FUNC(int, bt_le_ext_adv_stop, struct bt_le_ext_adv *);
FAKE_VALUE_FUNC(int, bt_le_ext_adv_set_data, struct bt_le_ext_adv *, const struct bt_data *, size_t,
const struct bt_data *, size_t);

#define FFF_FAKES_LIST(FAKE) \
FAKE(bt_le_adv_start) \
FAKE(bt_le_adv_stop) \
FAKE(bt_le_adv_update_data)
FAKE(bt_le_ext_adv_start) \
FAKE(bt_le_ext_adv_stop) \
FAKE(bt_le_ext_adv_set_data)

#define ESUCCESS (0)
#define TEST_BUFFER_LEN (100)
Expand All @@ -40,50 +40,51 @@ void test_sid_ble_advert_start(void)
{
size_t adv_start_call_count = 0;

bt_le_adv_start_fake.return_val = ESUCCESS;
bt_le_ext_adv_start_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_start());
adv_start_call_count++;
TEST_ASSERT_EQUAL(adv_start_call_count, bt_le_adv_start_fake.call_count);
TEST_ASSERT_EQUAL(adv_start_call_count, bt_le_ext_adv_start_fake.call_count);

bt_le_adv_start_fake.return_val = -ENOENT;
bt_le_ext_adv_start_fake.return_val = -ENOENT;
TEST_ASSERT_EQUAL(-ENOENT, sid_ble_advert_start());
adv_start_call_count++;
TEST_ASSERT_EQUAL(adv_start_call_count, bt_le_adv_start_fake.call_count);
TEST_ASSERT_EQUAL(adv_start_call_count, bt_le_ext_adv_start_fake.call_count);
}

void test_sid_ble_advert_stop(void)
{
size_t adv_stop_call_count = 0;

bt_le_adv_stop_fake.return_val = ESUCCESS;
bt_le_ext_adv_stop_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_stop());
adv_stop_call_count++;
TEST_ASSERT_EQUAL(adv_stop_call_count, bt_le_adv_stop_fake.call_count);
TEST_ASSERT_EQUAL(adv_stop_call_count, bt_le_ext_adv_stop_fake.call_count);

bt_le_adv_stop_fake.return_val = -ENOENT;
bt_le_ext_adv_stop_fake.return_val = -ENOENT;
TEST_ASSERT_EQUAL(-ENOENT, sid_ble_advert_stop());
adv_stop_call_count++;
TEST_ASSERT_EQUAL(adv_stop_call_count, bt_le_adv_stop_fake.call_count);
TEST_ASSERT_EQUAL(adv_stop_call_count, bt_le_ext_adv_stop_fake.call_count);
}

void test_sid_ble_advert_update(void)
{
uint8_t test_data[] = "Lorem ipsum.";
size_t adv_update_call_count = 0;

bt_le_adv_start_fake.return_val = ESUCCESS;
bt_le_adv_update_data_fake.return_val = ESUCCESS;
bt_le_ext_adv_start_fake.return_val = ESUCCESS;
bt_le_ext_adv_set_data_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_start());
adv_update_call_count++;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_update(test_data, sizeof(test_data)));
adv_update_call_count++;
TEST_ASSERT_EQUAL(adv_update_call_count, bt_le_adv_update_data_fake.call_count);
TEST_ASSERT_EQUAL(adv_update_call_count, bt_le_ext_adv_set_data_fake.call_count);

bt_le_adv_update_data_fake.return_val = -ENOENT;
bt_le_ext_adv_set_data_fake.return_val = -ENOENT;
TEST_ASSERT_EQUAL(-ENOENT, sid_ble_advert_update(test_data, sizeof(test_data)));
adv_update_call_count++;
TEST_ASSERT_EQUAL(adv_update_call_count, bt_le_adv_update_data_fake.call_count);
TEST_ASSERT_EQUAL(adv_update_call_count, bt_le_ext_adv_set_data_fake.call_count);

bt_le_adv_update_data_fake.return_val = ESUCCESS;
bt_le_ext_adv_set_data_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(-EINVAL, sid_ble_advert_update(NULL, sizeof(test_data)));
TEST_ASSERT_EQUAL(-EINVAL, sid_ble_advert_update(test_data, 0));
}
Expand All @@ -94,12 +95,12 @@ void test_sid_ble_advert_update_in_every_state(void)

TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_update(test_data, sizeof(test_data)));

bt_le_adv_start_fake.return_val = ESUCCESS;
bt_le_adv_update_data_fake.return_val = ESUCCESS;
bt_le_ext_adv_start_fake.return_val = ESUCCESS;
bt_le_ext_adv_set_data_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_start());
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_update(test_data, sizeof(test_data)));

bt_le_adv_stop_fake.return_val = ESUCCESS;
bt_le_ext_adv_stop_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_stop());
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_update(test_data, sizeof(test_data)));
}
Expand Down Expand Up @@ -130,17 +131,17 @@ void test_sid_ble_advert_update_before_start(void)
size_t advert_data_size;
bool found;

bt_le_adv_stop_fake.return_val = ESUCCESS;
bt_le_ext_adv_stop_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_stop());

bt_le_adv_update_data_fake.return_val = ESUCCESS;
bt_le_ext_adv_set_data_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_update(test_data, sizeof(test_data)));

bt_le_adv_start_fake.return_val = ESUCCESS;
bt_le_ext_adv_start_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_start());

advert_data = bt_le_adv_start_fake.arg1_val;
advert_data_size = bt_le_adv_start_fake.arg2_val;
advert_data = bt_le_ext_adv_set_data_fake.arg1_val;
advert_data_size = bt_le_ext_adv_set_data_fake.arg2_val;
TEST_ASSERT_NOT_NULL(advert_data);
TEST_ASSERT_GREATER_THAN_size_t(0, advert_data_size);

Expand All @@ -159,13 +160,13 @@ void check_sid_ble_advert_update(uint8_t *data, uint8_t data_len)
size_t advert_data_size;
bool found;

bt_le_adv_start_fake.return_val = ESUCCESS;
bt_le_adv_update_data_fake.return_val = ESUCCESS;
bt_le_ext_adv_start_fake.return_val = ESUCCESS;
bt_le_ext_adv_set_data_fake.return_val = ESUCCESS;
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_start());
TEST_ASSERT_EQUAL(ESUCCESS, sid_ble_advert_update(data, data_len));

advert_data = bt_le_adv_update_data_fake.arg0_val;
advert_data_size = bt_le_adv_update_data_fake.arg1_val;
advert_data = bt_le_ext_adv_set_data_fake.arg1_val;
advert_data_size = bt_le_ext_adv_set_data_fake.arg2_val;
TEST_ASSERT_NOT_NULL(advert_data);
TEST_ASSERT_GREATER_THAN_size_t(0, advert_data_size);

Expand Down

0 comments on commit a06d443

Please sign in to comment.