Skip to content

Commit 2369c12

Browse files
authored
Merge pull request #10269 from TeemuKultala/cellular_valgrind_fix
cellular: valgrind defect fix
2 parents 0066ba9 + 453d7b8 commit 2369c12

File tree

5 files changed

+59
-15
lines changed

5 files changed

+59
-15
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_ready_cb)
417417

418418
dev->set_ready_cb(&device_ready_cb);
419419
dev->set_ready_cb(0);
420+
421+
delete dev;
420422
}

UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,24 @@ TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_get_sms)
140140
ATHandler_stub::int_value = 0;
141141
EXPECT_TRUE(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
142142

143+
//In below we are expecting the stub ATHandler info_resp() to respond
144+
//twice true, then once false, then again twice true so that the
145+
//below message contents would be read in AT_CellularSMS read_sms_from_index().
146+
//This is to avoid comparing empty date strings
143147
ATHandler_stub::resp_info_true_counter = 2;
148+
ATHandler_stub::resp_info_false_counter = 1;
149+
ATHandler_stub::resp_info_true_counter2 = 2;
144150
ATHandler_stub::int_value = 11;
151+
ATHandler_stub::read_string_index = 4;
152+
ATHandler_stub::read_string_table[4] = "";
153+
ATHandler_stub::read_string_table[3] = "REC READ";
154+
ATHandler_stub::read_string_table[2] = "09/01/12,11:15:00+04";
155+
ATHandler_stub::read_string_table[1] = "REC READ";
156+
ATHandler_stub::read_string_table[0] = "24/12/12,11:15:00+04";
157+
145158
EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
146159
//TODO: Should make add_info to happen, before calling get_sms!
160+
ATHandler_stub::read_string_index = kRead_string_table_size;
147161

148162
ATHandler_stub::resp_info_true_counter = 2;
149163
ATHandler_stub::int_value = 11;

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,10 @@ TEST_F(TestATHandler, test_ATHandler_skip_param)
493493
at.resp_start();
494494
at.skip_param();
495495

496-
char table2[] = "sssOK\r\n\0";
497-
filehandle_stub_table = table2;
498-
499496
at.flush();
500497
at.clear_error();
498+
char table2[] = "sssOK\r\n\0";
499+
filehandle_stub_table = table2;
501500
filehandle_stub_short_value_counter = 1;
502501
filehandle_stub_table_pos = 0;
503502
at.resp_start();
@@ -914,13 +913,12 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
914913
filehandle_stub_table_pos = 0;
915914
at.resp_start("ssssaaaassssaaaassss"); //too long prefix
916915

917-
char table3[] = "+CME ERROR: 108\0";
918-
filehandle_stub_table = table3;
919-
filehandle_stub_table_pos = 0;
920-
921916
at.flush();
922917
at.clear_error();
918+
char table3[] = "+CME ERROR: 108\r\n";
919+
filehandle_stub_table = table3;
923920
filehandle_stub_table_pos = 0;
921+
924922
at.resp_start();
925923

926924

@@ -929,7 +927,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
929927
filehandle_stub_table_pos = 0;
930928
at.resp_start();
931929

932-
char table4[] = "+CMS ERROR: 6\0";
930+
char table4[] = "+CMS ERROR: 6\r\n";
933931
filehandle_stub_table = table4;
934932

935933
filehandle_stub_table_pos = 0;
@@ -1055,12 +1053,11 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
10551053
at.set_stop_tag("OK\r\n");
10561054
at.resp_stop();
10571055

1058-
char table3[] = "+CME ERROR: 108\0";
1059-
filehandle_stub_table = table3;
1060-
filehandle_stub_table_pos = 0;
1061-
10621056
at.flush();
10631057
at.clear_error();
1058+
1059+
char table3[] = "+CME ERROR: 108\r\n";
1060+
filehandle_stub_table = table3;
10641061
filehandle_stub_table_pos = 0;
10651062
at.resp_start();
10661063

UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ FileHandle_stub *ATHandler_stub::fh_value = NULL;
4545
device_err_t ATHandler_stub::device_err_value;
4646
bool ATHandler_stub::call_immediately = false;
4747
uint8_t ATHandler_stub::resp_info_true_counter = false;
48+
uint8_t ATHandler_stub::resp_info_true_counter2 = false;
49+
uint8_t ATHandler_stub::resp_info_false_counter = false;
4850
uint8_t ATHandler_stub::info_elem_true_counter = false;
4951
int ATHandler_stub::int_valid_count_table[kRead_int_table_size];
5052
int ATHandler_stub::int_count = kRead_int_table_size;
@@ -55,7 +57,7 @@ const char *ATHandler_stub::read_string_table[kRead_string_table_size] = {'\0'};
5557
int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
5658
int ATHandler_stub::urc_amount = 0;
5759
mbed::Callback<void()> ATHandler_stub::callback[kATHandler_urc_table_max_size];
58-
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {'\0'};
60+
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {NULL};
5961

6062
bool ATHandler_stub::get_debug_flag = false;
6163
uint8_t ATHandler_stub::set_debug_call_count = 0;
@@ -156,8 +158,9 @@ void ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
156158
{
157159
if (ATHandler_stub::urc_amount < kATHandler_urc_table_max_size) {
158160
ATHandler_stub::callback[ATHandler_stub::urc_amount] = cb;
159-
ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount] = new char[kATHandler_urc_string_max_size];
160161
if (urc) {
162+
ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount] = new char[kATHandler_urc_string_max_size];
163+
memset(ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount], 0, sizeof(ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount]));
161164
int bytes_to_copy = strlen(urc) < kATHandler_urc_string_max_size ? strlen(urc) : kATHandler_urc_string_max_size;
162165
memcpy(ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount], urc, bytes_to_copy);
163166
}
@@ -213,9 +216,13 @@ void ATHandler::process_oob()
213216
int i = 0;
214217
while (i < ATHandler_stub::urc_amount) {
215218
if (ATHandler_stub::read_string_index >= 0) {
219+
int len = 0;
220+
if (ATHandler_stub::urc_string_table[i]) {
221+
len = strlen(ATHandler_stub::urc_string_table[i]);
222+
}
216223
if (!memcmp(ATHandler_stub::urc_string_table[i],
217224
ATHandler_stub::read_string_table[ATHandler_stub::read_string_index],
218-
strlen(ATHandler_stub::urc_string_table[i]))) {
225+
len)) {
219226
ATHandler_stub::callback[i]();
220227
break;
221228
}
@@ -311,10 +318,32 @@ void ATHandler::resp_start(const char *prefix, bool stop)
311318

312319
bool ATHandler::info_resp()
313320
{
321+
//3 counter variables available here now so that in a test
322+
//case it is possible to have at least two while loops checking
323+
//specified amount of info_resps.
324+
//
325+
//For example:
326+
//while(athandler.info_resp())
327+
//{
328+
// resp_info_true_counter responses handled in this loop
329+
//}
330+
// resp_info_false_counter set to 1 to break out from the 1st loop
331+
//while(athandler.info_resp())
332+
//{
333+
// resp_info_true_counter2 responses handled in this loop
334+
//}
314335
if (ATHandler_stub::resp_info_true_counter) {
315336
ATHandler_stub::resp_info_true_counter--;
316337
return true;
317338
}
339+
if (ATHandler_stub::resp_info_false_counter) {
340+
ATHandler_stub::resp_info_false_counter--;
341+
return false;
342+
}
343+
if (ATHandler_stub::resp_info_true_counter2) {
344+
ATHandler_stub::resp_info_true_counter2--;
345+
return true;
346+
}
318347
return ATHandler_stub::bool_value;
319348
}
320349

UNITTESTS/stubs/ATHandler_stub.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ extern size_t size_value;
5050
extern size_t return_given_size;
5151
extern bool bool_value;
5252
extern uint8_t resp_info_true_counter;
53+
extern uint8_t resp_info_true_counter2;
54+
extern uint8_t resp_info_false_counter;
5355
extern uint8_t info_elem_true_counter;
5456
extern uint8_t uint8_value;
5557
extern mbed::FileHandle_stub *fh_value;

0 commit comments

Comments
 (0)