Skip to content

Commit 3bfef7f

Browse files
author
Hasnain Virk
committed
Unit Test Fixes for LoRaWAN
Missing methods are added. Logic was broken at various places which needed to be fixed.
1 parent 0a94172 commit 3bfef7f

File tree

7 files changed

+50
-19
lines changed

7 files changed

+50
-19
lines changed

UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,12 @@ TEST_F(Test_LoRaMac, get_current_slot)
558558
object->get_current_slot();
559559
}
560560

561+
TEST_F(Test_LoRaMac, get_QOS_level)
562+
{
563+
EXPECT_EQ(1, object->get_QOS_level());
564+
}
565+
566+
TEST_F(Test_LoRaMac, get_prev_QOS_level)
567+
{
568+
EXPECT_EQ(1, object->get_prev_QOS_level());
569+
}

UNITTESTS/features/lorawan/loraphy/Test_LoRaPHY.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ TEST_F(Test_LoRaPHY, link_ADR_request)
430430
//verify adr with p.adr_enabled = false
431431
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
432432

433-
p.current_nb_rep = 0;
433+
p.current_nb_trans = 0;
434434
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
435435

436436
p.adr_enabled = true;

UNITTESTS/features/lorawan/lorawaninterface/Test_LoRaWANInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ TEST_F(Test_LoRaWANInterface, add_app_callbacks)
201201

202202
TEST_F(Test_LoRaWANInterface, set_device_class)
203203
{
204-
object->set_device_class(CLASS_A);
204+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_device_class(CLASS_A));
205205
}
206206

207207
TEST_F(Test_LoRaWANInterface, get_tx_metadata)

UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ TEST_F(Test_LoRaWANStack, handle_tx)
350350
cb.events = events_cb;
351351
cb.link_check_resp = lc_resp;
352352
cb.battery_level = batt_lvl;
353+
struct equeue_event ptr;
354+
equeue_stub.void_ptr = &ptr;
355+
equeue_stub.call_cb_immediately = true;
353356
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
354357
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_link_check_request());
355358

@@ -394,6 +397,10 @@ TEST_F(Test_LoRaWANStack, handle_rx)
394397
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
395398
EXPECT_TRUE(LORAWAN_STATUS_NO_ACTIVE_SESSIONS == object->handle_rx(NULL, 0, port, flags, false));
396399

400+
struct equeue_event ptr;
401+
equeue_stub.void_ptr = &ptr;
402+
equeue_stub.call_cb_immediately = true;
403+
397404
lorawan_connect_t conn;
398405
conn.connect_type = LORAWAN_CONNECTION_ABP;
399406
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
@@ -410,14 +417,13 @@ TEST_F(Test_LoRaWANStack, handle_rx)
410417
my_LoRaPHY phy;
411418
object->bind_phy_and_radio_driver(radio, phy);
412419

413-
struct equeue_event ptr;
414-
equeue_stub.void_ptr = &ptr;
415-
equeue_stub.call_cb_immediately = true;
416420
loramac_mcps_confirm_t conf;
421+
conf.status = LORAMAC_EVENT_INFO_STATUS_OK;
417422
LoRaMac_stub::mcps_conf_ptr = &conf;
418423
radio._ev->tx_done();
419424

420425
loramac_mcps_indication_t ind;
426+
ind.status = LORAMAC_EVENT_INFO_STATUS_OK;
421427
LoRaMac_stub::mcps_ind_ptr = &ind;
422428

423429
loramac_mlme_confirm_t mlme;
@@ -429,7 +435,7 @@ TEST_F(Test_LoRaWANStack, handle_rx)
429435
conf.req_type = MCPS_PROPRIETARY;
430436

431437
ind.pending = true;
432-
LoRaMac_stub::dev_class_value = CLASS_C;
438+
LoRaMac_stub::dev_class_value = CLASS_A;
433439

434440
loramac_mlme_indication_t mlme_ind;
435441
mlme_ind.pending = false;
@@ -546,11 +552,6 @@ TEST_F(Test_LoRaWANStack, set_device_class)
546552
EXPECT_TRUE(LORAWAN_STATUS_UNSUPPORTED == object->set_device_class(CLASS_B));
547553

548554
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_device_class(CLASS_A));
549-
550-
//Visit callback
551-
if (LoRaMac_stub::_ack_expiry_handler_for_class_c) {
552-
LoRaMac_stub::_ack_expiry_handler_for_class_c.call();
553-
}
554555
}
555556

556557
TEST_F(Test_LoRaWANStack, acquire_tx_metadata)
@@ -574,9 +575,13 @@ TEST_F(Test_LoRaWANStack, acquire_tx_metadata)
574575
equeue_stub.void_ptr = &ptr;
575576
equeue_stub.call_cb_immediately = true;
576577
loramac_mcps_confirm_t conf;
578+
conf.status = LORAMAC_EVENT_INFO_STATUS_OK;
577579
LoRaMac_stub::mcps_conf_ptr = &conf;
578580
radio._ev->tx_done();
579581

582+
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
583+
radio._ev->rx_timeout();
584+
580585
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_tx_metadata(data));
581586
}
582587

@@ -601,13 +606,16 @@ TEST_F(Test_LoRaWANStack, acquire_rx_metadata)
601606
equeue_stub.void_ptr = &ptr;
602607
equeue_stub.call_cb_immediately = true;
603608
loramac_mcps_confirm_t conf;
609+
conf.status = LORAMAC_EVENT_INFO_STATUS_OK;
604610
LoRaMac_stub::mcps_conf_ptr = &conf;
605611
radio._ev->tx_done();
606612

607613
loramac_mcps_indication_t ind;
614+
ind.status = LORAMAC_EVENT_INFO_STATUS_OK;
608615
LoRaMac_stub::mcps_ind_ptr = &ind;
609616

610617
loramac_mlme_confirm_t mlme;
618+
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
611619
LoRaMac_stub::mlme_conf_ptr = &mlme;
612620
mlme.pending = true;
613621
mlme.req_type = MLME_JOIN;
@@ -631,6 +639,7 @@ TEST_F(Test_LoRaWANStack, acquire_rx_metadata)
631639
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
632640
mlme.req_type = MLME_LINK_CHECK;
633641
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
642+
LoRaMac_stub::bool_true_counter = true;
634643
radio._ev->rx_done(NULL, 0, 0, 0);
635644

636645
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_rx_metadata(data));
@@ -851,7 +860,7 @@ TEST_F(Test_LoRaWANStack, process_reception)
851860

852861
conf.req_type = MCPS_UNCONFIRMED;
853862
LoRaMac_stub::dev_class_value = CLASS_A;
854-
LoRaMac_stub::bool_value = true;
863+
LoRaMac_stub::bool_true_counter++;
855864
mlme_ind.pending = true;
856865
mlme_ind.indication_type = MLME_SCHEDULE_UPLINK;
857866
conf.status = LORAMAC_EVENT_INFO_STATUS_ERROR;

UNITTESTS/stubs/LoRaMac_stub.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@ int LoRaMac_stub::bool_false_counter = 0;
2626
int LoRaMac_stub::bool_true_counter = 0;
2727
bool LoRaMac_stub::bool_value = false;
2828
int LoRaMac_stub::int_value = 0;
29+
uint8_t LoRaMac_stub::uint8_value = 1;
2930
rx_slot_t LoRaMac_stub::slot_value = RX_SLOT_WIN_1;
3031
lorawan_status_t LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
3132
loramac_mcps_confirm_t *LoRaMac_stub::mcps_conf_ptr = NULL;
3233
loramac_mcps_indication_t *LoRaMac_stub::mcps_ind_ptr = NULL;
3334
loramac_mlme_confirm_t *LoRaMac_stub::mlme_conf_ptr = NULL;
3435
loramac_mlme_indication_t *LoRaMac_stub::mlme_ind_ptr = NULL;
3536
device_class_t LoRaMac_stub::dev_class_value = CLASS_A;
36-
mbed::Callback<void(void)> LoRaMac_stub::_ack_expiry_handler_for_class_c = NULL;
3737
mbed::Callback<void(void)> LoRaMac_stub::_scheduling_failure_handler = NULL;
3838

39-
4039
LoRaMac::LoRaMac()
4140
: _lora_time(),
4241
_lora_phy(NULL),
@@ -334,9 +333,8 @@ device_class_t LoRaMac::get_device_class() const
334333
}
335334

336335
void LoRaMac::set_device_class(const device_class_t &device_class,
337-
mbed::Callback<void(void)>ack_expiry_handler)
336+
mbed::Callback<void(void)>rx2_would_be_closure_handler)
338337
{
339-
LoRaMac_stub::_ack_expiry_handler_for_class_c = ack_expiry_handler;
340338
}
341339

342340
void LoRaMac::setup_link_check_request()
@@ -456,3 +454,13 @@ lorawan_status_t LoRaMac::multicast_channel_unlink(multicast_params_t *channel_p
456454
void LoRaMac::bind_phy(LoRaPHY &phy)
457455
{
458456
}
457+
458+
uint8_t LoRaMac::get_QOS_level(void)
459+
{
460+
return LoRaMac_stub::uint8_value;
461+
}
462+
463+
uint8_t LoRaMac::get_prev_QOS_level(void)
464+
{
465+
return LoRaMac_stub::uint8_value;
466+
}

UNITTESTS/stubs/LoRaMac_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ extern bool bool_value;
2828
extern int bool_false_counter;
2929
extern int bool_true_counter;
3030
extern int int_value;
31+
extern uint8_t uint8_value;
3132
extern rx_slot_t slot_value;
3233
extern lorawan_status_t status_value;
3334
extern loramac_mcps_confirm_t *mcps_conf_ptr;
3435
extern loramac_mcps_indication_t *mcps_ind_ptr;
3536
extern loramac_mlme_confirm_t *mlme_conf_ptr;
3637
extern loramac_mlme_indication_t *mlme_ind_ptr;
3738
extern device_class_t dev_class_value;
38-
extern mbed::Callback<void(void)> _ack_expiry_handler_for_class_c;
3939
extern mbed::Callback<void(void)> _scheduling_failure_handler;
4040
}

UNITTESTS/stubs/LoRaWANStack_stub.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,14 @@ void LoRaWANStack::process_transmission(void)
186186
{
187187
}
188188

189-
void LoRaWANStack::handle_ack_expiry_for_class_c(void)
189+
void post_process_tx_with_reception(void)
190190
{
191+
192+
}
193+
194+
void post_process_tx_no_reception(void)
195+
{
196+
191197
}
192198

193199
void LoRaWANStack::handle_scheduling_failure(void)
@@ -295,4 +301,3 @@ void LoRaWANStack::process_idle_state(lorawan_status_t &op_status)
295301
void LoRaWANStack::process_uninitialized_state(lorawan_status_t &op_status)
296302
{
297303
}
298-

0 commit comments

Comments
 (0)