Skip to content

Commit 29d06ab

Browse files
trantanentmon-nordic
authored andcommitted
tests: lib: lte_lc_api: Add coverage for edrx
Adding test coverage for edrx related tests. Also cleaning up dead code, i.e., conditions that cannot be met have been changed from if-statements to asserts. Signed-off-by: Tommi Rantanen <[email protected]>
1 parent 3914dcb commit 29d06ab

File tree

3 files changed

+96
-39
lines changed

3 files changed

+96
-39
lines changed

lib/lte_link_control/lte_lc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,19 @@ int lte_lc_edrx_req(bool enable)
10231023
int err = 0;
10241024
int actt[] = {AT_CEDRXS_ACTT_WB, AT_CEDRXS_ACTT_NB};
10251025

1026+
LOG_DBG("enable=%d, "
1027+
"requested_edrx_value_ltem=%s, edrx_value_ltem=%s, "
1028+
"requested_ptw_value_ltem=%s, ptw_value_ltem=%s, ",
1029+
enable,
1030+
requested_edrx_value_ltem, edrx_value_ltem,
1031+
requested_ptw_value_ltem, ptw_value_ltem);
1032+
LOG_DBG("enable=%d, "
1033+
"requested_edrx_value_nbiot=%s, edrx_value_nbiot=%s, "
1034+
"requested_ptw_value_nbiot=%s, ptw_value_nbiot=%s",
1035+
enable,
1036+
requested_edrx_value_nbiot, edrx_value_nbiot,
1037+
requested_ptw_value_nbiot, ptw_value_nbiot);
1038+
10261039
requested_edrx_enable = enable;
10271040

10281041
if (!enable) {

lib/lte_link_control/lte_lc_helpers.c

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ static void get_ptw_multiplier(enum lte_lc_lte_mode lte_mode, float *ptw_multipl
165165
if (lte_mode == LTE_LC_LTE_MODE_NBIOT) {
166166
*ptw_multiplier = 2.56;
167167
} else {
168+
__ASSERT_NO_MSG(lte_mode == LTE_LC_LTE_MODE_LTEM);
168169
*ptw_multiplier = 1.28;
169170
}
170171
}
171172

172-
static int get_edrx_value(enum lte_lc_lte_mode lte_mode, uint8_t idx, float *edrx_value)
173+
static void get_edrx_value(enum lte_lc_lte_mode lte_mode, uint8_t idx, float *edrx_value)
173174
{
174175
uint16_t multiplier = 0;
175176

@@ -186,25 +187,17 @@ static int get_edrx_value(enum lte_lc_lte_mode lte_mode, uint8_t idx, float *edr
186187
};
187188

188189
__ASSERT_NO_MSG(edrx_value != NULL);
190+
/* idx is parsed from 4 character bit field string so it cannot be more than 15 */
191+
__ASSERT_NO_MSG(idx < ARRAY_SIZE(edrx_lookup_ltem));
189192

190-
if (idx > ARRAY_SIZE(edrx_lookup_ltem) - 1) {
191-
return -EINVAL;
192-
}
193-
194-
switch (lte_mode) {
195-
case LTE_LC_LTE_MODE_LTEM:
193+
if (lte_mode == LTE_LC_LTE_MODE_LTEM) {
196194
multiplier = edrx_lookup_ltem[idx];
197-
break;
198-
case LTE_LC_LTE_MODE_NBIOT:
195+
} else {
196+
__ASSERT_NO_MSG(lte_mode == LTE_LC_LTE_MODE_NBIOT);
199197
multiplier = edrx_lookup_nbiot[idx];
200-
break;
201-
default:
202-
return -ENOTCONN;
203198
}
204199

205200
*edrx_value = multiplier == 0 ? 5.12 : multiplier * 10.24;
206-
207-
return 0;
208201
}
209202

210203
/* Counts the frequency of a character in a null-terminated string. */
@@ -327,11 +320,7 @@ int parse_edrx(const char *at_response, struct lte_lc_edrx_cfg *cfg, char *edrx_
327320
*/
328321
get_ptw_multiplier(cfg->mode, &ptw_multiplier);
329322

330-
err = get_edrx_value(cfg->mode, idx, &cfg->edrx);
331-
if (err) {
332-
LOG_ERR("Failed to get eDRX value, error; %d", err);
333-
goto clean_exit;
334-
}
323+
get_edrx_value(cfg->mode, idx, &cfg->edrx);
335324

336325
len = sizeof(tmp_buf);
337326

@@ -342,18 +331,15 @@ int parse_edrx(const char *at_response, struct lte_lc_edrx_cfg *cfg, char *edrx_
342331
goto clean_exit;
343332
}
344333

345-
__ASSERT_NO_MSG(ptw_str != NULL);
346334
strcpy(ptw_str, tmp_buf);
347335

348336
/* Value can be a maximum of 15, as there are 16 entries in the table
349337
* for paging time window (both for LTE-M and NB1).
338+
* We can use assert as only 4 bits can be received and if there would be more,
339+
* the previous at_parser_string_get would fail.
350340
*/
351341
idx = strtoul(tmp_buf, NULL, 2);
352-
if (idx > 15) {
353-
LOG_ERR("Invalid PTW lookup index: %d", idx);
354-
err = -EINVAL;
355-
goto clean_exit;
356-
}
342+
__ASSERT_NO_MSG(idx <= 15);
357343

358344
/* The Paging Time Window is different for LTE-M and NB-IoT:
359345
* - LTE-M: (idx + 1) * 1.28 s
@@ -538,10 +524,7 @@ int parse_psm(const char *active_time_str, const char *tau_ext_str,
538524
memcpy(unit_str, tau_ext_str, unit_str_len);
539525

540526
lut_idx = strtoul(unit_str, NULL, 2);
541-
if (lut_idx > (ARRAY_SIZE(t3412_ext_lookup) - 1)) {
542-
LOG_ERR("Unable to parse periodic TAU string (T3412 extended)");
543-
return -EINVAL;
544-
}
527+
__ASSERT_NO_MSG(lut_idx < ARRAY_SIZE(t3412_ext_lookup));
545528

546529
timer_unit = t3412_ext_lookup[lut_idx];
547530
timer_value = strtoul(tau_ext_str + unit_str_len, NULL, 2);
@@ -554,10 +537,7 @@ int parse_psm(const char *active_time_str, const char *tau_ext_str,
554537
memcpy(unit_str, tau_legacy_str, unit_str_len);
555538

556539
lut_idx = strtoul(unit_str, NULL, 2);
557-
if (lut_idx > (ARRAY_SIZE(t3412_lookup) - 1)) {
558-
LOG_ERR("Unable to parse periodic TAU string (T3412)");
559-
return -EINVAL;
560-
}
540+
__ASSERT_NO_MSG(lut_idx < ARRAY_SIZE(t3412_lookup));
561541

562542
timer_unit = t3412_lookup[lut_idx];
563543
if (timer_unit == 0) {
@@ -575,10 +555,7 @@ int parse_psm(const char *active_time_str, const char *tau_ext_str,
575555
memcpy(unit_str, active_time_str, unit_str_len);
576556

577557
lut_idx = strtoul(unit_str, NULL, 2);
578-
if (lut_idx > (ARRAY_SIZE(t3324_lookup) - 1)) {
579-
LOG_ERR("Unable to parse active time string");
580-
return -EINVAL;
581-
}
558+
__ASSERT_NO_MSG(lut_idx < ARRAY_SIZE(t3324_lookup));
582559

583560
timer_unit = t3324_lookup[lut_idx];
584561
timer_value = strtoul(active_time_str + unit_str_len, NULL, 2);

tests/lib/lte_lc_api/src/lte_lc_api_test.c

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ void test_lte_lc_edrx_get_ltem2_success(void)
13051305
{
13061306
int ret;
13071307
struct lte_lc_edrx_cfg edrx_cfg;
1308-
static const char cedrxrdp_resp[] = "+CEDRXRDP: 4,\"1000\",\"0010\",\"1110\"";
1308+
static const char cedrxrdp_resp[] = "+CEDRXRDP: 4,\"1000\",\"0000\",\"1110\"";
13091309

13101310
__cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CEDRXRDP", 0);
13111311
__cmock_nrf_modem_at_cmd_IgnoreArg_buf();
@@ -1316,7 +1316,7 @@ void test_lte_lc_edrx_get_ltem2_success(void)
13161316
ret = lte_lc_edrx_get(&edrx_cfg);
13171317
TEST_ASSERT_EQUAL(EXIT_SUCCESS, ret);
13181318
TEST_ASSERT_EQUAL(LTE_LC_LTE_MODE_LTEM, edrx_cfg.mode);
1319-
TEST_ASSERT_EQUAL_FLOAT(20.48, edrx_cfg.edrx);
1319+
TEST_ASSERT_EQUAL_FLOAT(5.12, edrx_cfg.edrx);
13201320
TEST_ASSERT_EQUAL_FLOAT(19.2, edrx_cfg.ptw);
13211321
}
13221322

@@ -1374,6 +1374,73 @@ void test_lte_lc_edrx_get_invalid_mode_fail(void)
13741374
TEST_ASSERT_EQUAL(-EBADMSG, ret);
13751375
}
13761376

1377+
void test_lte_lc_edrx_get_invalid_nw_edrx_value_fail(void)
1378+
{
1379+
int ret;
1380+
struct lte_lc_edrx_cfg edrx_cfg;
1381+
static const char cedrxrdp_resp[] = "+CEDRXRDP: 4,\"1000\",0101,\"1011\"";
1382+
1383+
__cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CEDRXRDP", 0);
1384+
__cmock_nrf_modem_at_cmd_IgnoreArg_buf();
1385+
__cmock_nrf_modem_at_cmd_IgnoreArg_len();
1386+
__cmock_nrf_modem_at_cmd_ReturnArrayThruPtr_buf(
1387+
(char *)cedrxrdp_resp, sizeof(cedrxrdp_resp));
1388+
1389+
ret = lte_lc_edrx_get(&edrx_cfg);
1390+
TEST_ASSERT_EQUAL(-EBADMSG, ret);
1391+
}
1392+
1393+
void test_lte_lc_edrx_get_invalid_nw_edrx_value_empty(void)
1394+
{
1395+
int ret;
1396+
struct lte_lc_edrx_cfg edrx_cfg;
1397+
static const char cedrxrdp_resp[] = "+CEDRXRDP: 4,\"1000\",\"\",\"1011\"";
1398+
1399+
__cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CEDRXRDP", 0);
1400+
__cmock_nrf_modem_at_cmd_IgnoreArg_buf();
1401+
__cmock_nrf_modem_at_cmd_IgnoreArg_len();
1402+
__cmock_nrf_modem_at_cmd_ReturnArrayThruPtr_buf(
1403+
(char *)cedrxrdp_resp, sizeof(cedrxrdp_resp));
1404+
1405+
ret = lte_lc_edrx_get(&edrx_cfg);
1406+
TEST_ASSERT_EQUAL(0, ret);
1407+
TEST_ASSERT_EQUAL(LTE_LC_LTE_MODE_NONE, edrx_cfg.mode);
1408+
TEST_ASSERT_EQUAL_FLOAT(0, edrx_cfg.edrx);
1409+
TEST_ASSERT_EQUAL_FLOAT(0, edrx_cfg.ptw);
1410+
}
1411+
1412+
void test_lte_lc_edrx_get_missing_nw_edrx_value(void)
1413+
{
1414+
int ret;
1415+
struct lte_lc_edrx_cfg edrx_cfg;
1416+
static const char cedrxrdp_resp[] = "+CEDRXRDP: 4,\"1000\"";
1417+
1418+
__cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CEDRXRDP", 0);
1419+
__cmock_nrf_modem_at_cmd_IgnoreArg_buf();
1420+
__cmock_nrf_modem_at_cmd_IgnoreArg_len();
1421+
__cmock_nrf_modem_at_cmd_ReturnArrayThruPtr_buf(
1422+
(char *)cedrxrdp_resp, sizeof(cedrxrdp_resp));
1423+
1424+
ret = lte_lc_edrx_get(&edrx_cfg);
1425+
TEST_ASSERT_EQUAL(-EBADMSG, ret);
1426+
}
1427+
1428+
void test_lte_lc_edrx_get_missing_ptw_value_fail(void)
1429+
{
1430+
int ret;
1431+
struct lte_lc_edrx_cfg edrx_cfg;
1432+
static const char cedrxrdp_resp[] = "+CEDRXRDP: 4,\"1000\",\"0101\"";
1433+
1434+
__cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CEDRXRDP", 0);
1435+
__cmock_nrf_modem_at_cmd_IgnoreArg_buf();
1436+
__cmock_nrf_modem_at_cmd_IgnoreArg_len();
1437+
__cmock_nrf_modem_at_cmd_ReturnArrayThruPtr_buf(
1438+
(char *)cedrxrdp_resp, sizeof(cedrxrdp_resp));
1439+
1440+
ret = lte_lc_edrx_get(&edrx_cfg);
1441+
TEST_ASSERT_EQUAL(-EBADMSG, ret);
1442+
}
1443+
13771444
void test_lte_lc_edrx_get_null_fail(void)
13781445
{
13791446
int ret;

0 commit comments

Comments
 (0)