Skip to content

Commit f0864be

Browse files
author
Antti Kauppila
committed
Fixed lorawan unittests valgrind issues
1 parent d30ae07 commit f0864be

File tree

11 files changed

+96
-29
lines changed

11 files changed

+96
-29
lines changed

UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Test_LoRaMac : public testing::Test {
4040
virtual void SetUp()
4141
{
4242
object = new LoRaMac();
43+
LoRaWANTimer_stub::time_value = 1;
4344
}
4445

4546
virtual void TearDown()
@@ -64,7 +65,9 @@ TEST_F(Test_LoRaMac, initialize)
6465
object->bind_phy(phy);
6566

6667
lorawan_connect_t conn;
68+
memset(&conn, 0, sizeof(conn));
6769
uint8_t key[16];
70+
memset(key, 0, sizeof(key));
6871
conn.connection_u.otaa.app_key = key;
6972
conn.connection_u.otaa.app_eui = key;
7073
conn.connection_u.otaa.dev_eui = key;
@@ -119,6 +122,7 @@ TEST_F(Test_LoRaMac, remove_single_channel)
119122
TEST_F(Test_LoRaMac, multicast_channel_link)
120123
{
121124
multicast_params_t p;
125+
memset(&p, 0, sizeof(p));
122126

123127
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->multicast_channel_link(NULL));
124128

@@ -132,6 +136,7 @@ TEST_F(Test_LoRaMac, multicast_channel_link)
132136
TEST_F(Test_LoRaMac, multicast_channel_unlink)
133137
{
134138
multicast_params_t p;
139+
memset(&p, 0, sizeof(p));
135140

136141
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->multicast_channel_unlink(NULL));
137142

@@ -145,7 +150,9 @@ TEST_F(Test_LoRaMac, multicast_channel_unlink)
145150
TEST_F(Test_LoRaMac, send)
146151
{
147152
loramac_mhdr_t mac_hdr;
153+
memset(&mac_hdr, 0, sizeof(mac_hdr));
148154
uint8_t buf[15];
155+
memset(buf, 0, sizeof(buf));
149156
mac_hdr.bits.mtype = FRAME_TYPE_DATA_CONFIRMED_UP;
150157
object->send(&mac_hdr, 1, buf, 15);
151158
}
@@ -183,6 +190,7 @@ TEST_F(Test_LoRaMac, reset_ongoing_tx)
183190
TEST_F(Test_LoRaMac, prepare_ongoing_tx)
184191
{
185192
uint8_t buf[16];
193+
memset(buf, 0, sizeof(buf));
186194
object->prepare_ongoing_tx(1, buf, 16, 1, 0);
187195
}
188196

@@ -214,6 +222,7 @@ TEST_F(Test_LoRaMac, setup_link_check_request)
214222
TEST_F(Test_LoRaMac, prepare_join)
215223
{
216224
lorawan_connect_t conn;
225+
memset(&conn, 0, sizeof(conn));
217226
object->prepare_join(&conn, false);
218227

219228
my_phy phy;
@@ -293,7 +302,9 @@ TEST_F(Test_LoRaMac, join)
293302
EXPECT_EQ(LORAWAN_STATUS_OK, object->join(false));
294303

295304
lorawan_connect_t conn;
305+
memset(&conn, 0, sizeof(conn));
296306
uint8_t key[16];
307+
memset(key, 0, sizeof(key));
297308
conn.connection_u.otaa.app_key = key;
298309
conn.connection_u.otaa.app_eui = key;
299310
conn.connection_u.otaa.dev_eui = key;
@@ -312,6 +323,7 @@ TEST_F(Test_LoRaMac, on_radio_tx_done)
312323
TEST_F(Test_LoRaMac, on_radio_rx_done)
313324
{
314325
uint8_t buf[16];
326+
memset(buf, 0, sizeof(buf));
315327
object->on_radio_rx_done(buf, 16, 0, 0);
316328
}
317329

@@ -330,7 +342,9 @@ TEST_F(Test_LoRaMac, continue_joining_process)
330342
my_phy phy;
331343
object->bind_phy(phy);
332344
lorawan_connect_t conn;
345+
memset(&conn, 0, sizeof(conn));
333346
uint8_t key[16];
347+
memset(key, 0, sizeof(key));
334348
conn.connection_u.otaa.app_key = key;
335349
conn.connection_u.otaa.app_eui = key;
336350
conn.connection_u.otaa.dev_eui = key;
@@ -369,6 +383,7 @@ TEST_F(Test_LoRaMac, get_mlme_indication)
369383
TEST_F(Test_LoRaMac, post_process_mcps_req)
370384
{
371385
uint8_t data[16];
386+
memset(data, 0, sizeof(data));
372387
LoRaPHY_stub::bool_counter = 0;
373388
LoRaPHY_stub::bool_table[0] = true;
374389

@@ -533,7 +548,9 @@ TEST_F(Test_LoRaMac, clear_tx_pipe)
533548
object->bind_phy(phy);
534549

535550
lorawan_connect_t conn;
551+
memset(&conn, 0, sizeof(conn));
536552
uint8_t key[16];
553+
memset(key, 0, sizeof(key));
537554
conn.connection_u.otaa.app_key = key;
538555
conn.connection_u.otaa.app_eui = key;
539556
conn.connection_u.otaa.dev_eui = key;
@@ -566,7 +583,7 @@ TEST_F(Test_LoRaMac, get_current_slot)
566583

567584
TEST_F(Test_LoRaMac, get_QOS_level)
568585
{
569-
EXPECT_EQ(1, object->get_QOS_level());
586+
EXPECT_EQ(0, object->get_QOS_level());
570587
}
571588

572589
TEST_F(Test_LoRaMac, get_prev_QOS_level)

UNITTESTS/features/lorawan/loramacchannelplan/Test_LoRaMacChannelPlan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ TEST_F(Test_LoRaMacChannelPlan, constructor)
6060
TEST_F(Test_LoRaMacChannelPlan, set_plan)
6161
{
6262
lorawan_channelplan_t plan;
63+
memset(&plan, 0, sizeof(plan));
64+
memset(&LoRaPHY_stub::bool_table, 0, sizeof(LoRaPHY_stub::bool_table));
6365
LoRaPHY_stub::bool_counter = 0;
6466
LoRaPHY_stub::bool_table[0] = false;
6567
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_SERVICE_UNKNOWN);
@@ -74,6 +76,9 @@ TEST_F(Test_LoRaMacChannelPlan, set_plan)
7476
LoRaPHY_stub::bool_table[0] = true;
7577
LoRaPHY_stub::uint8_value = 10;
7678
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_PARAMETER_INVALID;
79+
loramac_channel_t chan;
80+
memset(&chan, 0, sizeof(chan));
81+
plan.channels = &chan;
7782
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_PARAMETER_INVALID);
7883

7984
LoRaPHY_stub::bool_counter = 0;

UNITTESTS/features/lorawan/loraphy/Test_LoRaPHY.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Test_LoRaPHY : public testing::Test {
100100
virtual void SetUp()
101101
{
102102
object = new my_LoRaPHY();
103+
memset(&object->get_phy_params(), 0, sizeof(object->get_phy_params()));
103104
}
104105

105106
virtual void TearDown()
@@ -606,10 +607,12 @@ TEST_F(Test_LoRaPHY, set_next_channel)
606607
p.aggregate_timeoff = 10000;
607608
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
608609

609-
uint16_t list[16];
610-
memset(list, 0, 16);
610+
uint16_t list[129];
611+
memset(list, 0, sizeof(list));
611612
list[4] = 1;
613+
list[128] = 1;
612614
object->get_phy_params().channels.mask = list;
615+
object->get_phy_params().channels.default_mask = list;
613616
object->get_phy_params().channels.mask_size = 1;
614617
p.aggregate_timeoff = 10000;
615618
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
@@ -620,12 +623,18 @@ TEST_F(Test_LoRaPHY, set_next_channel)
620623
p.joined = false;
621624
p.dc_enabled = false;
622625
band_t b[4];
626+
ch = 5;
627+
t1 = 16;
628+
t2 = 32;
623629
memset(b, 0, sizeof(band_t)*4);
624630
object->get_phy_params().bands.size = 2;
625631
object->get_phy_params().bands.table = &b;
626632
b[0].off_time = 0;
627633
b[1].off_time = 9999999;
634+
memset(list, 0, 129);
628635
list[4] = 0;
636+
object->get_phy_params().channels.mask = list;
637+
object->get_phy_params().channels.default_mask = list;
629638
object->get_phy_params().channels.mask_size = 128;
630639
p.current_datarate = DR_1;
631640
object->get_phy_params().max_channel_cnt = 4;
@@ -663,6 +672,8 @@ TEST_F(Test_LoRaPHY, add_channel)
663672
object->get_phy_params().channels.mask = list;
664673
object->get_phy_params().channels.default_mask = list;
665674
channel_params_t p;
675+
p.band = 0;
676+
p.frequency = 0;
666677
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->add_channel(&p, 0));
667678

668679
object->get_phy_params().custom_channelplans_supported = true;
@@ -702,13 +713,17 @@ TEST_F(Test_LoRaPHY, set_tx_cont_mode)
702713
pp.band=0;
703714
object->get_phy_params().channels.channel_list = &pp;
704715
band_t b;
716+
b.max_tx_pwr = 10;
705717
object->get_phy_params().bands.table = &b;
706718
my_radio radio;
707719
object->set_radio_instance(radio);
708720

709721
cw_mode_params_t p;
710722
p.max_eirp = 0;
711723
p.channel=0;
724+
p.tx_power = -1;
725+
p.datarate = 0;
726+
p.antenna_gain = 1;
712727
object->set_tx_cont_mode(&p);
713728

714729
p.max_eirp = 1;

UNITTESTS/features/lorawan/loraphyau915/Test_LoRaPHYAU915.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ TEST_F(Test_LoRaPHYAU915, constructor)
107107
TEST_F(Test_LoRaPHYAU915, rx_config)
108108
{
109109
rx_config_params_t p;
110+
memset(&p, 0, sizeof(p));
110111

111112
radio.uint8_value = 1;
112113
EXPECT_TRUE(!object->rx_config(&p));
@@ -122,7 +123,8 @@ TEST_F(Test_LoRaPHYAU915, rx_config)
122123
TEST_F(Test_LoRaPHYAU915, tx_config)
123124
{
124125
tx_config_params_t p;
125-
int8_t tx;
126+
memset(&p, 0, sizeof(p));
127+
int8_t tx = 0;
126128
lorawan_time_t time;
127129
p.tx_power = 9;
128130
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
@@ -131,10 +133,11 @@ TEST_F(Test_LoRaPHYAU915, tx_config)
131133
TEST_F(Test_LoRaPHYAU915, link_ADR_request)
132134
{
133135
adr_req_params_t params;
134-
int8_t dr_out;
135-
int8_t tx_power_out;
136-
uint8_t nb_rep_out;
137-
uint8_t nb_bytes_parsed;
136+
memset(&params, 0, sizeof(params));
137+
int8_t dr_out = 0;
138+
int8_t tx_power_out = 0;
139+
uint8_t nb_rep_out = 0;
140+
uint8_t nb_bytes_parsed = 0;
138141

139142
LoRaPHY_stub::uint8_value = 1;
140143
LoRaPHY_stub::ch_mask_value = 6;
@@ -159,6 +162,7 @@ TEST_F(Test_LoRaPHYAU915, link_ADR_request)
159162
TEST_F(Test_LoRaPHYAU915, accept_rx_param_setup_req)
160163
{
161164
rx_param_setup_req_t p;
165+
memset(&p, 0, sizeof(p));
162166
radio.bool_value = false;
163167
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
164168

UNITTESTS/features/lorawan/loraphycn470/Test_LoRaPHYCN470.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ TEST_F(Test_LoRaPHYCN470, constructor)
109109
TEST_F(Test_LoRaPHYCN470, set_next_channel)
110110
{
111111
channel_selection_params_t params;
112-
uint8_t channel;
113-
lorawan_time_t time;
114-
lorawan_time_t timeoff;
112+
113+
memset(&params, 0, sizeof(params));
114+
uint8_t channel = 0;
115+
lorawan_time_t time = 0;
116+
lorawan_time_t timeoff = 0;
115117

116118
params.current_datarate = 4;
117119
params.aggregate_timeoff = 0;
@@ -130,6 +132,7 @@ TEST_F(Test_LoRaPHYCN470, set_next_channel)
130132
TEST_F(Test_LoRaPHYCN470, rx_config)
131133
{
132134
rx_config_params_t p;
135+
memset(&p, 0, sizeof(p));
133136

134137
radio.uint8_value = 1;
135138
EXPECT_TRUE(!object->rx_config(&p));
@@ -145,19 +148,20 @@ TEST_F(Test_LoRaPHYCN470, rx_config)
145148
TEST_F(Test_LoRaPHYCN470, tx_config)
146149
{
147150
tx_config_params_t p;
148-
int8_t tx;
149-
lorawan_time_t time;
151+
int8_t tx = 0;
152+
lorawan_time_t time = 0;
150153
p.tx_power = 9;
151154
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
152155
}
153156

154157
TEST_F(Test_LoRaPHYCN470, link_ADR_request)
155158
{
156159
adr_req_params_t params;
157-
int8_t dr_out;
158-
int8_t tx_power_out;
159-
uint8_t nb_rep_out;
160-
uint8_t nb_bytes_parsed;
160+
memset(&params, 0, sizeof(params));
161+
int8_t dr_out = 0;
162+
int8_t tx_power_out = 0;
163+
uint8_t nb_rep_out = 0;
164+
uint8_t nb_bytes_parsed = 0;
161165

162166
LoRaPHY_stub::uint8_value = 1;
163167
LoRaPHY_stub::ch_mask_value = 6;
@@ -182,6 +186,8 @@ TEST_F(Test_LoRaPHYCN470, link_ADR_request)
182186
TEST_F(Test_LoRaPHYCN470, accept_rx_param_setup_req)
183187
{
184188
rx_param_setup_req_t p;
189+
memset(&p, 0, sizeof(p));
190+
radio.bool_value = false;
185191
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
186192

187193
radio.bool_value = true;

UNITTESTS/features/lorawan/loraphykr920/Test_LoRaPHYKR920.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ TEST_F(Test_LoRaPHYKR920, verify_frequency_for_band)
117117
TEST_F(Test_LoRaPHYKR920, tx_config)
118118
{
119119
tx_config_params_t tx_config;
120+
memset(&tx_config, 0, sizeof(tx_config));
120121
int8_t tx_power = 0;
121-
lorawan_time_t time;
122+
lorawan_time_t time = 0;
122123

123124
tx_config.tx_power = 9;
124125
EXPECT_TRUE(true == object->tx_config(&tx_config, &tx_power, &time));
@@ -127,6 +128,7 @@ TEST_F(Test_LoRaPHYKR920, tx_config)
127128
TEST_F(Test_LoRaPHYKR920, set_next_channel)
128129
{
129130
channel_selection_params_t next_channel;
131+
memset(&next_channel, 0, sizeof(next_channel));
130132
lorawan_time_t backoff_time = 0;
131133
lorawan_time_t time = 0;
132134
uint8_t ch = 1;
@@ -150,6 +152,7 @@ TEST_F(Test_LoRaPHYKR920, set_next_channel)
150152
TEST_F(Test_LoRaPHYKR920, set_tx_cont_mode)
151153
{
152154
cw_mode_params_t params;
155+
memset(&params, 0, sizeof(params));
153156
params.tx_power = 9;
154157
object->set_tx_cont_mode(&params, 0);
155158
}

UNITTESTS/features/lorawan/loraphyus915/Test_LoRaPHYUS915.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ TEST_F(Test_LoRaPHYUS915, restore_default_channels)
111111
TEST_F(Test_LoRaPHYUS915, rx_config)
112112
{
113113
rx_config_params_t p;
114+
memset(&p, 0, sizeof(p));
114115

115116
radio.uint8_value = 1;
116117
EXPECT_TRUE(!object->rx_config(&p));
@@ -126,18 +127,20 @@ TEST_F(Test_LoRaPHYUS915, rx_config)
126127
TEST_F(Test_LoRaPHYUS915, tx_config)
127128
{
128129
tx_config_params_t p;
129-
int8_t tx;
130-
lorawan_time_t time;
130+
memset(&p, 0, sizeof(p));
131+
int8_t tx = 0;
132+
lorawan_time_t time = 0;
131133
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
132134
}
133135

134136
TEST_F(Test_LoRaPHYUS915, link_ADR_request)
135137
{
136138
adr_req_params_t params;
137-
int8_t dr_out;
138-
int8_t tx_power_out;
139-
uint8_t nb_rep_out;
140-
uint8_t nb_bytes_parsed;
139+
memset(&params, 0, sizeof(params));
140+
int8_t dr_out = 0;
141+
int8_t tx_power_out = 0;
142+
uint8_t nb_rep_out = 0;
143+
uint8_t nb_bytes_parsed = 0;
141144

142145
EXPECT_TRUE(0 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
143146

@@ -164,6 +167,8 @@ TEST_F(Test_LoRaPHYUS915, link_ADR_request)
164167
TEST_F(Test_LoRaPHYUS915, accept_rx_param_setup_req)
165168
{
166169
rx_param_setup_req_t p;
170+
memset(&p, 0, sizeof(p));
171+
radio.bool_value = false;
167172
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
168173

169174
radio.bool_value = true;
@@ -188,9 +193,10 @@ TEST_F(Test_LoRaPHYUS915, get_alternate_DR)
188193
TEST_F(Test_LoRaPHYUS915, set_next_channel)
189194
{
190195
channel_selection_params_t params;
191-
uint8_t channel;
192-
lorawan_time_t time;
193-
lorawan_time_t timeoff;
196+
memset(&params, 0, sizeof(params));
197+
uint8_t channel = 0;
198+
lorawan_time_t time = 0;
199+
lorawan_time_t timeoff = 0;
194200

195201
params.current_datarate = 4;
196202
params.aggregate_timeoff = 0;
@@ -228,6 +234,7 @@ TEST_F(Test_LoRaPHYUS915, apply_DR_offset)
228234
TEST_F(Test_LoRaPHYUS915, set_tx_cont_mode)
229235
{
230236
cw_mode_params_t p;
237+
memset(&p, 0, sizeof(p));
231238
object->set_tx_cont_mode(&p, 0);
232239

233240
p.datarate = 4;

0 commit comments

Comments
 (0)