Skip to content

Cellular: Remove support for multiple ATHandlers #12305

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
Feb 7, 2020
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 @@ -44,7 +44,6 @@ class TestAT_CellularContext : public testing::Test {
ATHandler_stub::nsapi_error_value = 0;
ATHandler_stub::nsapi_error_ok_counter = 0;
ATHandler_stub::int_value = -1;
ATHandler_stub::ref_count = 0;
ATHandler_stub::timeout = 0;
ATHandler_stub::default_timeout = 0;
ATHandler_stub::debug_on = 0;
Expand Down Expand Up @@ -514,21 +513,6 @@ TEST_F(TestAT_CellularContext, get_apn_backoff_timer)
ASSERT_EQ(time, 55);
}

TEST_F(TestAT_CellularContext, set_file_handle)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularDevice dev(&fh1);
AT_CellularContext ctx(at, &dev);
ctx.set_file_handle(&fh1);

BufferedSerial ss(NC, NC);

ctx.set_file_handle(&ss, PTC0, true);
ctx.enable_hup(true);
}

TEST_F(TestAT_CellularContext, connect_disconnect_sync)
{
EventQueue que;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,14 @@ class TestAT_CellularDevice : public testing::Test {

void SetUp()
{
EventQueue que;
FileHandle_stub fh1;
filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0;

ATHandler at(&fh1, que, 0, ",");
ATHandler_stub::handler = &at;

ATHandler_stub::read_string_index = kRead_string_table_size;
}

void TearDown()
{
ATHandler_stub::handler = NULL;
}
};

Expand All @@ -55,82 +49,50 @@ TEST_F(TestAT_CellularDevice, Create)

EXPECT_TRUE(dev2 != NULL);
delete dev2;
ATHandler *at = dev.get_at_handler(&fh1);
dev.release_at_handler(at);
dev.release_at_handler(at);
ATHandler *at = dev.get_at_handler();
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
{
FileHandle_stub fh1;
FileHandle_stub fh2;
FileHandle_stub fh3;
AT_CellularDevice dev(&fh1); // AT fh1 ref count 1

EXPECT_TRUE(dev.open_network(&fh1)); // AT fh1 ref count 2
dev.modem_debug_on(true);
EXPECT_TRUE(dev.open_sms(&fh2));
EXPECT_TRUE(dev.open_information(&fh3));
ATHandler_stub::fh_value = &fh1;

ATHandler_stub::fh_value = NULL;

AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5
delete dev2; // AT fh1 2 refs deleted -> ref count 3

AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3
AT_CellularDevice dev(&fh1);
ATHandler *at = dev.get_at_handler();
EXPECT_TRUE(at->get_file_handle() == &fh1);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
{
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

CellularNetwork *nw = dev.open_network(NULL);
CellularNetwork *nw1 = dev.open_network(&fh1);

CellularNetwork *nw = dev.open_network();
EXPECT_TRUE(nw);
EXPECT_TRUE(nw1);
EXPECT_TRUE(nw1 == nw);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
{
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

CellularSMS *sms = dev.open_sms(NULL);
CellularSMS *sms1 = dev.open_sms(&fh1);

CellularSMS *sms = dev.open_sms();
EXPECT_TRUE(sms);
EXPECT_TRUE(sms1);
EXPECT_TRUE(sms1 == sms);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
{
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

CellularInformation *info = dev.open_information(NULL);
CellularInformation *info1 = dev.open_information(&fh1);

CellularInformation *info = dev.open_information();
EXPECT_TRUE(info);
EXPECT_TRUE(info1);
EXPECT_TRUE(info1 == info);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
{
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(dev.open_network(&fh1));
EXPECT_EQ(ATHandler_stub::ref_count, 1);

EXPECT_TRUE(dev.open_network());
dev.close_network();
}

Expand All @@ -139,9 +101,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(dev.open_sms(&fh1));
EXPECT_EQ(ATHandler_stub::ref_count, 1);

EXPECT_TRUE(dev.open_sms());
dev.close_sms();
}

Expand All @@ -151,14 +111,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
AT_CellularDevice dev(&fh1);
ATHandler_stub::int_value = 0;

EXPECT_TRUE(dev.open_information(&fh1));
EXPECT_TRUE(dev.open_information());

ATHandler_stub::fh_value = NULL;
dev.close_information();

ATHandler_stub::fh_value = &fh1;

EXPECT_TRUE(dev.open_information(&fh1));
EXPECT_TRUE(dev.open_information());

dev.close_information();

Expand All @@ -176,8 +136,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
EXPECT_TRUE(ATHandler_stub::default_timeout == true);

EXPECT_TRUE(dev.open_sms(&fh1));
EXPECT_EQ(ATHandler_stub::ref_count, 1);
EXPECT_TRUE(dev.open_sms());

dev.set_timeout(5000);
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
Expand All @@ -195,8 +154,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
dev.modem_debug_on(true);
EXPECT_TRUE(ATHandler_stub::debug_on == true);

EXPECT_TRUE(dev.open_sms(&fh1));
EXPECT_EQ(ATHandler_stub::ref_count, 1);
EXPECT_TRUE(dev.open_sms());

dev.modem_debug_on(true);
EXPECT_TRUE(ATHandler_stub::debug_on == true);
Expand Down Expand Up @@ -263,16 +221,15 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);

ATHandler *at = dev->get_at_handler();
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);

CellularContext *ctx = dev->create_context(NULL);
delete dev;

dev = new AT_CellularDevice(&fh1);
at = dev->get_at_handler();
ctx = dev->create_context(NULL);
CellularContext *ctx1 = dev->create_context(&fh1);
CellularContext *ctx2 = dev->create_context(&fh1);
CellularContext *ctx1 = dev->create_context();
CellularContext *ctx2 = dev->create_context();

EXPECT_TRUE(ctx);
EXPECT_TRUE(ctx1);
Expand All @@ -288,9 +245,9 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
dev->delete_context(ctx2);

ctx = dev->create_context(NULL);
ctx1 = dev->create_context(&fh1);
ctx2 = dev->create_context(&fh1);
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
ctx1 = dev->create_context();
ctx2 = dev->create_context();

EXPECT_TRUE(ctx);
EXPECT_TRUE(ctx1);
EXPECT_TRUE(ctx1 != ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,43 +86,6 @@ TEST_F(TestATHandler, test_ATHandler_get_file_handle)
EXPECT_EQ(&fh1, at.get_file_handle());
}

TEST_F(TestATHandler, test_ATHandler_set_file_handle)
{
EventQueue que;
FileHandle_stub fh1, fh2;

ATHandler at(&fh1, que, 0, ",");

at.set_file_handle(&fh2);
}

TEST_F(TestATHandler, test_ATHandler_list)
{
EventQueue que;
FileHandle_stub fh1;

ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(false);

ATHandler *at1 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);

ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(true);

EXPECT_TRUE(ATHandler::get_instance(NULL, que, 0, ",", 0, 0) == NULL);

ATHandler *at2 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);

ATHandler::set_at_timeout_list(2000, true);
ATHandler::set_debug_list(false);

EXPECT_TRUE(at1->close() == NSAPI_ERROR_OK);
EXPECT_TRUE(at2->close() == NSAPI_ERROR_OK);

ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(false);
}

TEST_F(TestATHandler, test_ATHandler_lock)
{
EventQueue que;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ class testContext : public CellularContext

}
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
virtual void set_file_handle(BufferedSerial *serial, PinName dcd_pin = NC, bool active_high = false)
virtual nsapi_error_t configure_hup(PinName dcd_pin = NC, bool active_high = false)
{

return NSAPI_ERROR_OK;
}
#endif
ControlPlane_netif *get_cp_netif()
Expand Down
49 changes: 0 additions & 49 deletions UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ using namespace events;
const int DEFAULT_AT_TIMEOUT = 1000;
const uint8_t MAX_RESP_LENGTH = 7;

mbed::ATHandler *ATHandler_stub::handler = NULL;

nsapi_error_t ATHandler_stub::nsapi_error_value = 0;
uint8_t ATHandler_stub::nsapi_error_ok_counter = 0;
int ATHandler_stub::int_value = -1;
int ATHandler_stub::ref_count = 0;
int ATHandler_stub::timeout = 0;
bool ATHandler_stub::default_timeout = 0;
bool ATHandler_stub::debug_on = 0;
Expand Down Expand Up @@ -84,7 +81,6 @@ void ATHandler_stub::debug_call_count_clear()
}

ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
_nextATHandler(0),
#if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT
_oobCv(_fileHandleMutex),
#endif
Expand All @@ -111,41 +107,17 @@ bool ATHandler::get_debug() const
return ATHandler_stub::debug_on;
}

void ATHandler::set_debug_list(bool debug_on)
{
ATHandler_stub::debug_on = debug_on;
}

ATHandler::~ATHandler()
{
ATHandler_stub::urc_handlers.clear();
}

void ATHandler::inc_ref_count()
{
ATHandler_stub::ref_count++;
}

void ATHandler::dec_ref_count()
{
ATHandler_stub::ref_count--;
}

int ATHandler::get_ref_count()
{
return ATHandler_stub::ref_count;
}

FileHandle *ATHandler::get_file_handle()
{
ATHandler_stub::fh_value = (FileHandle_stub *)_fileHandle;
return _fileHandle;
}

void ATHandler::set_file_handle(FileHandle *fh)
{
}

bool ATHandler::find_urc_handler(const char *prefix)
{
return ATHandler_stub::bool_value;
Expand Down Expand Up @@ -393,27 +365,6 @@ nsapi_error_t ATHandler::at_cmd_discard(const char *cmd, const char *cmd_chr,
return ATHandler_stub::nsapi_error_value;
}

ATHandler *ATHandler::get_instance(FileHandle *fileHandle, events::EventQueue &queue, uint32_t timeout,
const char *delimiter, uint16_t send_delay, bool debug_on)
{
ATHandler_stub::ref_count++;
int a = ATHandler_stub::ref_count;
a = 0;
return ATHandler_stub::handler;
}

nsapi_error_t ATHandler::close()
{
ATHandler_stub::ref_count--;
return NSAPI_ERROR_OK;
}

void ATHandler::set_at_timeout_list(uint32_t timeout_milliseconds, bool default_timeout)
{
ATHandler_stub::timeout = timeout_milliseconds;
ATHandler_stub::default_timeout = default_timeout;
}

void ATHandler::set_send_delay(uint16_t send_delay)
{
}
Expand Down
2 changes: 0 additions & 2 deletions UNITTESTS/stubs/ATHandler_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ static const int kATHandler_urc_table_max_size = 10;
static const int kATHandler_urc_string_max_size = 16;

namespace ATHandler_stub {
extern mbed::ATHandler *handler;
extern nsapi_error_t nsapi_error_value;
extern uint8_t nsapi_error_ok_counter;
extern int int_value;
extern int ref_count;
extern int timeout;
extern bool default_timeout;
extern bool debug_on;
Expand Down
Loading