Skip to content

Commit 5c09ff1

Browse files
authored
Merge pull request #11220 from jarvte/fix_cellular_dns_test
Fix cellular dns test with IAR compiled binary
2 parents 6812869 + 65bf17e commit 5c09ff1

File tree

13 files changed

+57
-31
lines changed

13 files changed

+57
-31
lines changed

TESTS/netsocket/dns/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static void net_bringup()
160160
net = NetworkInterface::get_default_instance();
161161
nsapi_error_t err = net->connect();
162162
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
163-
printf("MBED: IP address is '%s'\n", net->get_ip_address());
163+
printf("MBED: IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
164164
}
165165

166166
static void net_bringdown()

TESTS/netsocket/tcp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void _ifup()
7272
NetworkInterface *net = NetworkInterface::get_default_instance();
7373
nsapi_error_t err = net->connect();
7474
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
75-
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
75+
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
7676
}
7777

7878
static void _ifdown()

TESTS/netsocket/tls/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void _ifup()
9494
NetworkInterface *net = NetworkInterface::get_default_instance();
9595
nsapi_error_t err = net->connect();
9696
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
97-
printf("MBED: TLSClient IP address is '%s'\n", net->get_ip_address());
97+
printf("MBED: TLSClient IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
9898
}
9999

100100
static void _ifdown()

TESTS/netsocket/udp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void _ifup()
5959
NetworkInterface *net = NetworkInterface::get_default_instance();
6060
nsapi_error_t err = net->connect();
6161
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
62-
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
62+
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
6363
}
6464

6565
static void _ifdown()

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
537537
ATHandler_stub::read_string_index = 2;
538538
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
539539

540-
ASSERT_EQ(network_cb_count, 5);
540+
ASSERT_EQ(network_cb_count, 4);
541541

542542
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
543543
ATHandler_stub::resp_info_true_counter = 1;
@@ -704,7 +704,7 @@ TEST_F(TestAT_CellularContext, connect_disconnect_async)
704704
data.status_data = CellularNetwork::Attached;
705705
ctx1.cellular_callback((nsapi_event_t)CellularAttachNetwork, (intptr_t)&data);
706706

707-
ASSERT_EQ(network_cb_count, 5);
707+
ASSERT_EQ(network_cb_count, 4);
708708
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_IS_CONNECTED);
709709
EXPECT_TRUE(ctx1.is_connected() == true);
710710
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_NO_MEMORY);

UNITTESTS/features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_get_ip_address)
175175
ATHandler at(&fh1, que, 0, ",");
176176

177177
MyStack st(at, 0, IPV6_STACK);
178-
EXPECT_EQ(strlen(st.get_ip_address()), 0);
178+
EXPECT_TRUE(st.get_ip_address() == NULL);
179179

180180
char table[] = "1.2.3.4.5.65.7.8.9.10.11\0";
181181
ATHandler_stub::ssize_value = -1;

UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ set(unittest-test-sources
2828
stubs/NetworkStack_stub.cpp
2929
stubs/SocketAddress_stub.cpp
3030
stubs/mbed_assert_stub.c
31+
stubs/ThisThread_stub.cpp
3132
)

UNITTESTS/stubs/AT_CellularContext_stub.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace mbed;
2121

2222
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
2323
AT_CellularBase(at), _is_connected(false),
24-
_current_op(OP_INVALID), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
24+
_current_op(OP_INVALID), _fh(0), _cp_req(cp_req)
2525
{
2626
_stack = NULL;
2727
_pdp_type = DEFAULT_PDP_TYPE;
@@ -43,6 +43,8 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
4343
_is_blocking = true;
4444
_device = device;
4545
_nw = NULL;
46+
_nonip_req = nonip_req;
47+
_cp_in_use = false;
4648
}
4749

4850
AT_CellularContext::~AT_CellularContext()

features/cellular/framework/API/CellularContext.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ class CellularContext : public CellularInterface {
337337
*/
338338
virtual void do_connect();
339339

340+
/** After we have connected successfully we must check that we have a valid IP address.
341+
* Some modems/networks don't give IP address right after connect so we must poll it for a while.
342+
*/
343+
void validate_ip_address();
344+
340345
// member variables needed in target override methods
341346
NetworkStack *_stack; // must be pointer because of PPP
342347
pdp_type_t _pdp_type;
@@ -361,6 +366,10 @@ class CellularContext : public CellularInterface {
361366
CellularDevice *_device;
362367
CellularNetwork *_nw;
363368
bool _is_blocking;
369+
// flag indicating if Non-IP context was requested to be setup
370+
bool _nonip_req;
371+
// tells if CCIOTOPTI received green from network for CP optimization use
372+
bool _cp_in_use;
364373
};
365374

366375
/**

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ using namespace mbed;
4747
using namespace rtos;
4848

4949
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
50-
AT_CellularBase(at), _is_connected(false), _current_op(OP_INVALID), _fh(0), _cp_req(cp_req),
51-
_nonip_req(nonip_req), _cp_in_use(false)
50+
AT_CellularBase(at), _is_connected(false), _current_op(OP_INVALID), _fh(0), _cp_req(cp_req)
5251
{
5352
tr_info("New CellularContext %s (%p)", apn ? apn : "", this);
53+
_nonip_req = nonip_req;
5454
_apn = apn;
5555
_device = device;
5656
}
@@ -570,7 +570,6 @@ void AT_CellularContext::do_connect()
570570
}
571571
#else
572572
_is_connected = true;
573-
call_network_cb(NSAPI_STATUS_GLOBAL_UP);
574573
#endif
575574
}
576575

0 commit comments

Comments
 (0)