summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAmit Purwar <amit.purwar@samsung.com>2020-09-04 19:44:49 +0530
committerAmit Purwar <amit.purwar@samsung.com>2020-09-04 20:25:38 +0530
commitba8c7450c49692ed522bec273cd3e76b8ad9ae9b (patch)
tree2c99c055a0be96d59f96abc54775eac94f4a2a5b /tests
parent64e72236129e09e61fa8ff3ab00244f3b2141a46 (diff)
downloadbluetooth-ba8c7450c49692ed522bec273cd3e76b8ad9ae9b.tar.gz
bluetooth-ba8c7450c49692ed522bec273cd3e76b8ad9ae9b.tar.bz2
bluetooth-ba8c7450c49692ed522bec273cd3e76b8ad9ae9b.zip
Add the testcase for node reset, mesh network destroy, model, group send msg and get primary address Change-Id: I3e43ec7f81819ec7d7815f204efe25997aa9798b Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest/mock/bluetooth-mock.c24
-rw-r--r--tests/unittest/tct-bluetooth-core_mobile.h11
-rw-r--r--tests/unittest/utc_bluetooth_mesh_network_positive.c171
3 files changed, 205 insertions, 1 deletions
diff --git a/tests/unittest/mock/bluetooth-mock.c b/tests/unittest/mock/bluetooth-mock.c
index 7c4d1ef..ae51fae 100644
--- a/tests/unittest/mock/bluetooth-mock.c
+++ b/tests/unittest/mock/bluetooth-mock.c
@@ -1161,3 +1161,27 @@ API int bluetooth_mesh_model_get_publication(bluetooth_mesh_model_configure_t *r
g_timeout_add(500, __mesh_event_cb, bt_event);
return BLUETOOTH_ERROR_NONE;
}
+
+API int bluetooth_mesh_model_send_msg(bluetooth_mesh_model_msg_t *req)
+{
+ bluetooth_event_param_t *bt_event = NULL;
+ bluetooth_mesh_model_msg_t *model_msg = NULL;
+
+ model_msg = g_malloc0(sizeof(bluetooth_mesh_model_msg_t));
+ g_strlcpy(model_msg->net_uuid, req->net_uuid, BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH +1);
+ model_msg->opcode = req->opcode;
+ model_msg->primary_unicast = req->primary_unicast;
+ model_msg->elem_index = req->elem_index;
+ model_msg->appkey_idx = req->appkey_idx;
+ model_msg->msg_len = req->msg_len;
+ if (model_msg->msg_len > 0)
+ memcpy(model_msg->msg, req->msg, req->msg_len + 1);
+
+ bt_event = g_malloc0(sizeof(bluetooth_event_param_t));
+ bt_event->event = BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED;
+ bt_event->result = BLUETOOTH_ERROR_NONE;
+ bt_event->param_data = model_msg;
+
+ g_timeout_add(500, __mesh_event_cb, bt_event);
+ return BLUETOOTH_ERROR_NONE;
+}
diff --git a/tests/unittest/tct-bluetooth-core_mobile.h b/tests/unittest/tct-bluetooth-core_mobile.h
index 7b7f7e6..d2dc15f 100644
--- a/tests/unittest/tct-bluetooth-core_mobile.h
+++ b/tests/unittest/tct-bluetooth-core_mobile.h
@@ -567,6 +567,11 @@ extern int utc_bluetooth_bt_mesh_model_configure_virtual_group_subscription_p(vo
extern int utc_bluetooth_bt_mesh_model_get_subscription_list_p(void);
extern int utc_bluetooth_bt_mesh_model_set_publication_p(void);
extern int utc_bluetooth_bt_mesh_model_get_publication_p(void);
+extern int utc_bluetooth_bt_mesh_node_reset_p(void);
+extern int utc_bluetooth_bt_mesh_network_destroy_p(void);
+extern int utc_bluetooth_bt_mesh_node_get_primary_address_p(void);
+extern int utc_bluetooth_bt_mesh_model_send_msg_p(void);
+extern int utc_bluetooth_bt_mesh_group_send_msg_p(void);
extern int utc_bluetooth_bt_mesh_model_send_msg_n(void);
extern int utc_bluetooth_bt_mesh_appkey_get_netkey_p(void);
extern int utc_bluetooth_bt_mesh_group_send_msg_n(void);
@@ -1121,6 +1126,12 @@ testcase tc_array[] = {
{"utc_bluetooth_bt_mesh_model_get_subscription_list_p",utc_bluetooth_bt_mesh_model_get_subscription_list_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
{"utc_bluetooth_bt_mesh_model_set_publication_p",utc_bluetooth_bt_mesh_model_set_publication_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
{"utc_bluetooth_bt_mesh_model_get_publication_p",utc_bluetooth_bt_mesh_model_get_publication_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
+ {"utc_bluetooth_bt_mesh_network_destroy_p",utc_bluetooth_bt_mesh_network_destroy_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
+ {"utc_bluetooth_bt_mesh_node_get_primary_address_p",utc_bluetooth_bt_mesh_node_get_primary_address_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
+ {"utc_bluetooth_bt_mesh_model_send_msg_p",utc_bluetooth_bt_mesh_model_send_msg_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
+ {"utc_bluetooth_bt_mesh_group_send_msg_p",utc_bluetooth_bt_mesh_group_send_msg_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
+ {"utc_bluetooth_bt_mesh_node_reset_p",utc_bluetooth_bt_mesh_node_reset_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
+ {"utc_bluetooth_bt_mesh_node_reset_p",utc_bluetooth_bt_mesh_node_reset_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
{"utc_bluetooth_bt_mesh_appkey_get_netkey_p",utc_bluetooth_bt_mesh_appkey_get_netkey_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup},
{"utc_bluetooth_bt_mesh_deinitialize_n",utc_bluetooth_bt_mesh_deinitialize_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup},
{"utc_bluetooth_bt_mesh_create_node_n",utc_bluetooth_bt_mesh_create_node_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup},
diff --git a/tests/unittest/utc_bluetooth_mesh_network_positive.c b/tests/unittest/utc_bluetooth_mesh_network_positive.c
index 96942d5..c5a7f46 100644
--- a/tests/unittest/utc_bluetooth_mesh_network_positive.c
+++ b/tests/unittest/utc_bluetooth_mesh_network_positive.c
@@ -37,6 +37,10 @@ static bt_mesh_element_h elem_h = NULL;
static bt_mesh_model_h model_h = NULL;
static bt_mesh_netkey_h netkey_h = NULL;
static bt_mesh_appkey_h appkey_h = NULL;
+static bt_mesh_node_h g_remote_node = NULL;
+static bt_mesh_group_h group_h = NULL;
+
+#define MESH_OPCODE_MODEL_GENERIC_ONOFF_GET 0x8201
static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total,
bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data)
@@ -98,6 +102,8 @@ static void __bt_mesh_authentication_request_cb(int result, bt_mesh_authenticati
static void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network,
bt_mesh_node_h node_param, void *user_data)
{
+ g_remote_node = node_param;
+
if (mainloop)
g_main_loop_quit(mainloop);
}
@@ -193,6 +199,13 @@ static void __bt_mesh_model_publication_status_cb(int result, bt_mesh_model_h mo
g_main_loop_quit(mainloop);
}
+void __bt_mesh_model_msg_cb(int result, bt_mesh_element_h element, bt_mesh_appkey_h appkey,
+ bt_mesh_model_msg_params_s *msg, void *user_data)
+{
+ if (mainloop)
+ g_main_loop_quit(mainloop);
+}
+
static void wait_for_async()
{
mainloop = g_main_loop_new(NULL, FALSE);
@@ -1432,7 +1445,6 @@ int utc_bluetooth_bt_mesh_model_set_publication_p(void)
{
int ret = BT_ERROR_NONE;
bt_mesh_model_pub_params_s param;
- bt_mesh_group_h group_h = NULL;
uint16_t group_addr = 0xc001;
bt_mesh_node_key_configuration_e config = 0;
@@ -1503,3 +1515,160 @@ int utc_bluetooth_bt_mesh_appkey_get_netkey_p(void)
return 0;
}
+
+int utc_bluetooth_bt_mesh_node_reset_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_h node_local = 0;
+ bt_mesh_node_features_s features;
+ bt_mesh_model_id_s mod_id;
+ bt_mesh_model_h model_local = NULL;
+ bt_mesh_element_h elem_local = NULL;
+ bt_mesh_network_h network_local = NULL;
+ char *network_name_local = "local-mesh";
+ static char *token_local = NULL;
+ bt_mesh_scan_params_s scan_params;
+ char *dev_uuid = "abababababababababababababababab";
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_local);
+ ret = bt_mesh_node_create_element(node_local, &elem_local);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_local, &mod_id, &model_local);
+ ret = bt_mesh_network_create(node_local, (const char*)network_name_local, &network_local, &token_local);
+ ret = bt_mesh_network_unprovisioned_device_scan(network_local, &scan_params,
+ __bt_mesh_network_scan_unprovisioned_device_result_cb_p, NULL);
+ wait_for_async();
+
+ ret = bt_mesh_network_provision_device(network_local, dev_uuid,
+ __bt_mesh_network_device_provision_cb, NULL);
+ wait_for_async();
+
+ ret = bt_mesh_network_discover_node(network_local, (const char*)dev_uuid,
+ __bt_mesh_node_discover_status_cb, NULL);
+ wait_for_async();
+ ret = bt_mesh_node_reset(g_remote_node);
+ assert_eq(ret, BT_ERROR_NONE);
+
+ /*cleanup */
+ bt_mesh_network_destroy(network_local);
+ g_remote_node = NULL;
+ } else {
+ ret = bt_mesh_node_reset(node_local);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_destroy_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_h node_local = 0;
+ bt_mesh_node_features_s features;
+ bt_mesh_model_id_s mod_id;
+ bt_mesh_model_h model_local = NULL;
+ bt_mesh_element_h elem_local = NULL;
+ bt_mesh_network_h network_local = NULL;
+ char *network_name_local = "local-mesh";
+ static char *token_local = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_local);
+ ret = bt_mesh_node_create_element(node_local, &elem_local);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_local, &mod_id, &model_local);
+ ret = bt_mesh_network_create(node_local, (const char*)network_name_local, &network_local, &token_local);
+
+ bt_mesh_network_destroy(network_local);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ bt_mesh_network_destroy(network_local);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_node_get_primary_address_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ uint16_t primary_address;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ ret = bt_mesh_node_get_primary_address(node_h, &primary_address);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_node_get_primary_address(node_h, &primary_address);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_group_send_msg_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_model_msg_params_s *msg_params = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
+ msg_params->opcode = MESH_OPCODE_MODEL_GENERIC_ONOFF_GET;
+ msg_params->data = "0101010101010101010101010100101010";
+
+ ret = bt_mesh_group_send_msg(group_h, appkey_h, msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ wait_for_async();
+ } else {
+ ret = bt_mesh_group_send_msg(group_h, appkey_h, msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_model_send_msg_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_model_msg_params_s *msg_params = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
+ msg_params->opcode = MESH_OPCODE_MODEL_GENERIC_ONOFF_GET;
+ msg_params->data = "0101010101010101010101010100101010";
+
+ ret = bt_mesh_model_send_msg(model_h, appkey_h, msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ wait_for_async();
+ } else {
+ ret = bt_mesh_model_send_msg(model_h, appkey_h, msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}