Skip to content

Commit 41a05e7

Browse files
ppryga-nordiccarlescufi
authored andcommitted
tests: Bluetooth: llcp: Add tests to check instant if no PHY change
There were no unit tests that verify if instant value send in LL_PHY_UPDATE_IND PDU are correct. The commit adds missing tests. Besides that there is a small update to all ull_cp_phy_update calls, to improve readability of the code. Magic number was changed to HOST_INITIATED macro. Signed-off-by: Piotr Pryga <[email protected]>
1 parent c18477a commit 41a05e7

File tree

1 file changed

+295
-7
lines changed
  • tests/bluetooth/controller/ctrl_phy_update/src

1 file changed

+295
-7
lines changed

tests/bluetooth/controller/ctrl_phy_update/src/main.c

Lines changed: 295 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define PREFER_S8_CODING 1
4343
#define PREFER_S2_CODING 0
4444

45+
#define HOST_INITIATED 1U
46+
4547
static struct ll_conn conn;
4648

4749
static void setup(void)
@@ -130,7 +132,7 @@ void test_phy_update_central_loc(void)
130132
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
131133

132134
/* Initiate an PHY Update Procedure */
133-
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, 1);
135+
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED);
134136
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
135137

136138
/* Prepare */
@@ -234,7 +236,7 @@ void test_phy_update_central_loc_invalid(void)
234236
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
235237

236238
/* Initiate an PHY Update Procedure */
237-
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, 1);
239+
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED);
238240
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
239241

240242
/* Prepare */
@@ -285,7 +287,7 @@ void test_phy_update_central_loc_unsupp_feat(void)
285287
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
286288

287289
/* Initiate an PHY Update Procedure */
288-
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, 1);
290+
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED);
289291
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
290292

291293
/* Prepare */
@@ -441,7 +443,7 @@ void test_phy_update_periph_loc(void)
441443
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
442444

443445
/* Initiate an PHY Update Procedure */
444-
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, 1);
446+
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED);
445447
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
446448

447449
/* Prepare */
@@ -706,7 +708,7 @@ void test_phy_update_central_loc_collision(void)
706708
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
707709

708710
/* Initiate an PHY Update Procedure */
709-
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, 1);
711+
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED);
710712
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
711713

712714
/*** ***/
@@ -893,7 +895,7 @@ void test_phy_update_central_rem_collision(void)
893895
/*** ***/
894896

895897
/* Initiate an PHY Update Procedure */
896-
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, 1);
898+
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED);
897899
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
898900

899901
/*** ***/
@@ -1051,7 +1053,7 @@ void test_phy_update_periph_loc_collision(void)
10511053
/*** ***/
10521054

10531055
/* Initiate an PHY Update Procedure */
1054-
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, 1);
1056+
err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED);
10551057
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
10561058

10571059
/* Prepare */
@@ -1147,6 +1149,284 @@ void test_phy_update_periph_loc_collision(void)
11471149
"Free CTX buffers %d", ctx_buffers_free());
11481150
}
11491151

1152+
void test_phy_update_central_loc_no_act_change(void)
1153+
{
1154+
uint8_t err;
1155+
struct node_tx *tx;
1156+
struct node_rx_pdu *ntf;
1157+
struct pdu_data *pdu;
1158+
struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M, .tx_phys = PHY_1M };
1159+
struct pdu_data_llctrl_phy_req rsp = { .rx_phys = PHY_1M | PHY_2M,
1160+
.tx_phys = PHY_1M | PHY_2M };
1161+
struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 0, .c_to_p_phy = 0, .p_to_c_phy = 0 };
1162+
uint16_t instant;
1163+
1164+
struct node_rx_pu pu = { .status = BT_HCI_ERR_SUCCESS };
1165+
1166+
/* Role */
1167+
test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1168+
1169+
/* Connect */
1170+
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1171+
1172+
/* Initiate an PHY Update Procedure */
1173+
err = ull_cp_phy_update(&conn, PHY_1M, PREFER_S8_CODING, PHY_1M, HOST_INITIATED);
1174+
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
1175+
1176+
/* Prepare */
1177+
event_prepare(&conn);
1178+
1179+
/* Tx Queue should have one LL Control PDU */
1180+
lt_rx(LL_PHY_REQ, &conn, &tx, &req);
1181+
lt_rx_q_is_empty(&conn);
1182+
1183+
/* Rx */
1184+
lt_tx(LL_PHY_RSP, &conn, &rsp);
1185+
1186+
/* TX Ack */
1187+
event_tx_ack(&conn, tx);
1188+
1189+
/* Done */
1190+
event_done(&conn);
1191+
1192+
/* Check that data tx was paused */
1193+
zassert_equal(conn.tx_q.pause_data, 1U, "Data tx is not paused");
1194+
1195+
/* Release Tx */
1196+
ull_cp_release_tx(&conn, tx);
1197+
1198+
/* Prepare */
1199+
event_prepare(&conn);
1200+
1201+
/* Tx Queue should have one LL Control PDU */
1202+
lt_rx(LL_PHY_UPDATE_IND, &conn, &tx, &ind);
1203+
lt_rx_q_is_empty(&conn);
1204+
1205+
/* TX Ack */
1206+
event_tx_ack(&conn, tx);
1207+
1208+
/* Check that data tx is no longer paused */
1209+
zassert_equal(conn.tx_q.pause_data, 0U, "Data tx is paused");
1210+
1211+
/* Done */
1212+
event_done(&conn);
1213+
1214+
/* Save Instant */
1215+
pdu = (struct pdu_data *)tx->pdu;
1216+
instant = sys_le16_to_cpu(pdu->llctrl.phy_upd_ind.instant);
1217+
1218+
/* Check if instant is zero, due to no actual PHY change */
1219+
zassert_equal(instant, 0, "Unexpected instant %d", instant);
1220+
1221+
/* Release Tx */
1222+
ull_cp_release_tx(&conn, tx);
1223+
1224+
/* There should be one host notifications, due to host initiated PHY upd */
1225+
ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu);
1226+
ut_rx_q_is_empty();
1227+
1228+
/* Release Ntf */
1229+
ull_cp_release_ntf(ntf);
1230+
1231+
CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_1M);
1232+
CHECK_PREF_PHY_STATE(conn, PHY_1M, PHY_1M);
1233+
1234+
zassert_equal(ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d",
1235+
ctx_buffers_free());
1236+
}
1237+
1238+
void test_phy_update_central_rem_no_actual_change(void)
1239+
{
1240+
struct node_tx *tx;
1241+
struct pdu_data *pdu;
1242+
struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M, .tx_phys = PHY_1M };
1243+
struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 0, .c_to_p_phy = 0, .p_to_c_phy = 0 };
1244+
uint16_t instant;
1245+
1246+
/* Role */
1247+
test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1248+
1249+
/* Connect */
1250+
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1251+
1252+
/* Prepare */
1253+
event_prepare(&conn);
1254+
1255+
/* Rx */
1256+
lt_tx(LL_PHY_REQ, &conn, &req);
1257+
1258+
/* TX Ack */
1259+
event_tx_ack(&conn, tx);
1260+
1261+
/* Done */
1262+
event_done(&conn);
1263+
1264+
/* Check that data tx was paused */
1265+
zassert_equal(conn.tx_q.pause_data, 1U, "Data tx is not paused");
1266+
1267+
/* Prepare */
1268+
event_prepare(&conn);
1269+
1270+
/* Tx Queue should have one LL Control PDU */
1271+
lt_rx(LL_PHY_UPDATE_IND, &conn, &tx, &ind);
1272+
lt_rx_q_is_empty(&conn);
1273+
1274+
/* TX Ack */
1275+
event_tx_ack(&conn, tx);
1276+
1277+
/* Done */
1278+
event_done(&conn);
1279+
1280+
/* Check that data tx is no longer paused */
1281+
zassert_equal(conn.tx_q.pause_data, 0U, "Data tx is paused");
1282+
1283+
/* Save Instant */
1284+
pdu = (struct pdu_data *)tx->pdu;
1285+
instant = sys_le16_to_cpu(pdu->llctrl.phy_upd_ind.instant);
1286+
1287+
/* Check if instant is zero, due to no actual PHY change */
1288+
zassert_equal(instant, 0, "Unexpected instant %d", instant);
1289+
1290+
/* Release Tx */
1291+
ull_cp_release_tx(&conn, tx);
1292+
1293+
/* There is not actual PHY change, so there shouldn't be host notification */
1294+
ut_rx_q_is_empty();
1295+
1296+
CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_1M);
1297+
CHECK_PREF_PHY_STATE(conn, PHY_1M | PHY_2M | PHY_CODED, PHY_1M | PHY_2M | PHY_CODED);
1298+
1299+
zassert_equal(ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d",
1300+
ctx_buffers_free());
1301+
}
1302+
1303+
void test_phy_update_periph_loc_no_actual_change(void)
1304+
{
1305+
uint8_t err;
1306+
struct node_tx *tx;
1307+
struct node_rx_pdu *ntf;
1308+
struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M, .tx_phys = PHY_1M };
1309+
struct node_rx_pu pu = { .status = BT_HCI_ERR_SUCCESS };
1310+
struct pdu_data_llctrl_phy_upd_ind phy_update_ind = { .instant = 0,
1311+
.c_to_p_phy = 0,
1312+
.p_to_c_phy = 0 };
1313+
1314+
/* Role */
1315+
test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
1316+
1317+
/* Connect */
1318+
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1319+
1320+
/* Initiate an PHY Update Procedure */
1321+
err = ull_cp_phy_update(&conn, PHY_1M, PREFER_S8_CODING, PHY_1M, HOST_INITIATED);
1322+
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
1323+
1324+
/* Prepare */
1325+
event_prepare(&conn);
1326+
1327+
/* Tx Queue should have one LL Control PDU */
1328+
lt_rx(LL_PHY_REQ, &conn, &tx, &req);
1329+
lt_rx_q_is_empty(&conn);
1330+
1331+
/* TX Ack */
1332+
event_tx_ack(&conn, tx);
1333+
1334+
/* Done */
1335+
event_done(&conn);
1336+
1337+
/* Release Tx */
1338+
ull_cp_release_tx(&conn, tx);
1339+
1340+
/* Prepare */
1341+
event_prepare(&conn);
1342+
1343+
/* Tx Queue should NOT have a LL Control PDU */
1344+
lt_rx_q_is_empty(&conn);
1345+
1346+
/* Rx */
1347+
lt_tx(LL_PHY_UPDATE_IND, &conn, &phy_update_ind);
1348+
1349+
/* Done */
1350+
event_done(&conn);
1351+
1352+
/* There should be one notification due to Host initiated PHY UPD */
1353+
ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu);
1354+
ut_rx_q_is_empty();
1355+
1356+
/* Release Ntf */
1357+
ull_cp_release_ntf(ntf);
1358+
1359+
CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_1M);
1360+
CHECK_PREF_PHY_STATE(conn, PHY_1M, PHY_1M);
1361+
1362+
zassert_equal(ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d",
1363+
ctx_buffers_free());
1364+
}
1365+
1366+
void test_phy_update_periph_rem_no_actual_change(void)
1367+
{
1368+
struct node_tx *tx;
1369+
struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M, .tx_phys = PHY_1M };
1370+
struct pdu_data_llctrl_phy_req rsp = { .rx_phys = PHY_1M | PHY_2M | PHY_CODED,
1371+
.tx_phys = PHY_1M | PHY_2M | PHY_CODED };
1372+
struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 0, .c_to_p_phy = 0, .p_to_c_phy = 0 };
1373+
1374+
/* Role */
1375+
test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
1376+
1377+
/* Connect */
1378+
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1379+
1380+
/* Prepare */
1381+
event_prepare(&conn);
1382+
1383+
/* Tx Queue should NOT have a LL Control PDU */
1384+
lt_rx_q_is_empty(&conn);
1385+
1386+
/* Rx */
1387+
lt_tx(LL_PHY_REQ, &conn, &req);
1388+
1389+
/* Done */
1390+
event_done(&conn);
1391+
1392+
/* We received a REQ, so data tx should be paused */
1393+
zassert_equal(conn.tx_q.pause_data, 1U, "Data tx is not paused");
1394+
1395+
/* Prepare */
1396+
event_prepare(&conn);
1397+
1398+
/* Tx Queue should have one LL Control PDU */
1399+
lt_rx(LL_PHY_RSP, &conn, &tx, &rsp);
1400+
lt_rx_q_is_empty(&conn);
1401+
1402+
/* Rx */
1403+
lt_tx(LL_PHY_UPDATE_IND, &conn, &ind);
1404+
1405+
/* We are sending RSP, so data tx should be paused until after tx ack */
1406+
zassert_equal(conn.tx_q.pause_data, 1U, "Data tx is not paused");
1407+
1408+
/* TX Ack */
1409+
event_tx_ack(&conn, tx);
1410+
1411+
/* Check that data tx is no longer paused */
1412+
zassert_equal(conn.tx_q.pause_data, 0U, "Data tx is paused");
1413+
1414+
/* Done */
1415+
event_done(&conn);
1416+
1417+
/* Release Tx */
1418+
ull_cp_release_tx(&conn, tx);
1419+
1420+
/* There should be no host notification */
1421+
ut_rx_q_is_empty();
1422+
1423+
CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_1M);
1424+
CHECK_PREF_PHY_STATE(conn, PHY_1M | PHY_2M | PHY_CODED, PHY_1M | PHY_2M | PHY_CODED);
1425+
1426+
zassert_equal(ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d",
1427+
ctx_buffers_free());
1428+
}
1429+
11501430
void test_main(void)
11511431
{
11521432
ztest_test_suite(
@@ -1166,6 +1446,14 @@ void test_main(void)
11661446
ztest_unit_test_setup_teardown(test_phy_update_central_rem_collision, setup,
11671447
unit_test_noop),
11681448
ztest_unit_test_setup_teardown(test_phy_update_periph_loc_collision, setup,
1449+
unit_test_noop),
1450+
ztest_unit_test_setup_teardown(test_phy_update_central_loc_no_act_change, setup,
1451+
unit_test_noop),
1452+
ztest_unit_test_setup_teardown(test_phy_update_central_rem_no_actual_change, setup,
1453+
unit_test_noop),
1454+
ztest_unit_test_setup_teardown(test_phy_update_periph_rem_no_actual_change, setup,
1455+
unit_test_noop),
1456+
ztest_unit_test_setup_teardown(test_phy_update_periph_loc_no_actual_change, setup,
11691457
unit_test_noop));
11701458

11711459
ztest_run_test_suite(phy);

0 commit comments

Comments
 (0)