Skip to content

cellular: valgrind defect fix #10269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_ready_cb)

dev->set_ready_cb(&device_ready_cb);
dev->set_ready_cb(0);

delete dev;
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,24 @@ TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_get_sms)
ATHandler_stub::int_value = 0;
EXPECT_TRUE(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));

//In below we are expecting the stub ATHandler info_resp() to respond
//twice true, then once false, then again twice true so that the
//below message contents would be read in AT_CellularSMS read_sms_from_index().
//This is to avoid comparing empty date strings
ATHandler_stub::resp_info_true_counter = 2;
ATHandler_stub::resp_info_false_counter = 1;
ATHandler_stub::resp_info_true_counter2 = 2;
ATHandler_stub::int_value = 11;
ATHandler_stub::read_string_index = 4;
ATHandler_stub::read_string_table[4] = "";
ATHandler_stub::read_string_table[3] = "REC READ";
ATHandler_stub::read_string_table[2] = "09/01/12,11:15:00+04";
ATHandler_stub::read_string_table[1] = "REC READ";
ATHandler_stub::read_string_table[0] = "24/12/12,11:15:00+04";

EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
//TODO: Should make add_info to happen, before calling get_sms!
ATHandler_stub::read_string_index = kRead_string_table_size;

ATHandler_stub::resp_info_true_counter = 2;
ATHandler_stub::int_value = 11;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,10 @@ TEST_F(TestATHandler, test_ATHandler_skip_param)
at.resp_start();
at.skip_param();

char table2[] = "sssOK\r\n\0";
filehandle_stub_table = table2;

at.flush();
at.clear_error();
char table2[] = "sssOK\r\n\0";
filehandle_stub_table = table2;
filehandle_stub_short_value_counter = 1;
filehandle_stub_table_pos = 0;
at.resp_start();
Expand Down Expand Up @@ -914,13 +913,12 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
filehandle_stub_table_pos = 0;
at.resp_start("ssssaaaassssaaaassss"); //too long prefix

char table3[] = "+CME ERROR: 108\0";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;

at.flush();
at.clear_error();
char table3[] = "+CME ERROR: 108\r\n";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;

at.resp_start();


Expand All @@ -929,7 +927,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
filehandle_stub_table_pos = 0;
at.resp_start();

char table4[] = "+CMS ERROR: 6\0";
char table4[] = "+CMS ERROR: 6\r\n";
filehandle_stub_table = table4;

filehandle_stub_table_pos = 0;
Expand Down Expand Up @@ -1055,12 +1053,11 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
at.set_stop_tag("OK\r\n");
at.resp_stop();

char table3[] = "+CME ERROR: 108\0";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;

at.flush();
at.clear_error();

char table3[] = "+CME ERROR: 108\r\n";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
at.resp_start();

Expand Down
35 changes: 32 additions & 3 deletions UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ FileHandle_stub *ATHandler_stub::fh_value = NULL;
device_err_t ATHandler_stub::device_err_value;
bool ATHandler_stub::call_immediately = false;
uint8_t ATHandler_stub::resp_info_true_counter = false;
uint8_t ATHandler_stub::resp_info_true_counter2 = false;
uint8_t ATHandler_stub::resp_info_false_counter = false;
uint8_t ATHandler_stub::info_elem_true_counter = false;
int ATHandler_stub::int_valid_count_table[kRead_int_table_size];
int ATHandler_stub::int_count = kRead_int_table_size;
Expand All @@ -55,7 +57,7 @@ const char *ATHandler_stub::read_string_table[kRead_string_table_size] = {'\0'};
int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
int ATHandler_stub::urc_amount = 0;
mbed::Callback<void()> ATHandler_stub::callback[kATHandler_urc_table_max_size];
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {'\0'};
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {NULL};

bool ATHandler_stub::get_debug_flag = false;
uint8_t ATHandler_stub::set_debug_call_count = 0;
Expand Down Expand Up @@ -156,8 +158,9 @@ void ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
{
if (ATHandler_stub::urc_amount < kATHandler_urc_table_max_size) {
ATHandler_stub::callback[ATHandler_stub::urc_amount] = cb;
ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount] = new char[kATHandler_urc_string_max_size];
if (urc) {
ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount] = new char[kATHandler_urc_string_max_size];
memset(ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount], 0, sizeof(ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount]));
int bytes_to_copy = strlen(urc) < kATHandler_urc_string_max_size ? strlen(urc) : kATHandler_urc_string_max_size;
memcpy(ATHandler_stub::urc_string_table[ATHandler_stub::urc_amount], urc, bytes_to_copy);
}
Expand Down Expand Up @@ -213,9 +216,13 @@ void ATHandler::process_oob()
int i = 0;
while (i < ATHandler_stub::urc_amount) {
if (ATHandler_stub::read_string_index >= 0) {
int len = 0;
if (ATHandler_stub::urc_string_table[i]) {
len = strlen(ATHandler_stub::urc_string_table[i]);
}
if (!memcmp(ATHandler_stub::urc_string_table[i],
ATHandler_stub::read_string_table[ATHandler_stub::read_string_index],
strlen(ATHandler_stub::urc_string_table[i]))) {
len)) {
ATHandler_stub::callback[i]();
break;
}
Expand Down Expand Up @@ -311,10 +318,32 @@ void ATHandler::resp_start(const char *prefix, bool stop)

bool ATHandler::info_resp()
{
//3 counter variables available here now so that in a test
//case it is possible to have at least two while loops checking
//specified amount of info_resps.
//
//For example:
//while(athandler.info_resp())
//{
// resp_info_true_counter responses handled in this loop
//}
// resp_info_false_counter set to 1 to break out from the 1st loop
//while(athandler.info_resp())
//{
// resp_info_true_counter2 responses handled in this loop
//}
if (ATHandler_stub::resp_info_true_counter) {
ATHandler_stub::resp_info_true_counter--;
return true;
}
if (ATHandler_stub::resp_info_false_counter) {
ATHandler_stub::resp_info_false_counter--;
return false;
}
if (ATHandler_stub::resp_info_true_counter2) {
ATHandler_stub::resp_info_true_counter2--;
return true;
}
return ATHandler_stub::bool_value;
}

Expand Down
2 changes: 2 additions & 0 deletions UNITTESTS/stubs/ATHandler_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extern size_t size_value;
extern size_t return_given_size;
extern bool bool_value;
extern uint8_t resp_info_true_counter;
extern uint8_t resp_info_true_counter2;
extern uint8_t resp_info_false_counter;
extern uint8_t info_elem_true_counter;
extern uint8_t uint8_value;
extern mbed::FileHandle_stub *fh_value;
Expand Down