Skip to content

Commit d5a6baf

Browse files
Teppo Järvelinadbridge
authored andcommitted
Cellular: added greentea test for cellular device.
1 parent bf6407e commit d5a6baf

File tree

2 files changed

+153
-2
lines changed

2 files changed

+153
-2
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#if !defined(MBED_CONF_NSAPI_PRESENT)
20+
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
21+
#endif
22+
23+
#include "CellularUtil.h" // for CELLULAR_ helper macros
24+
#include "CellularTargets.h"
25+
26+
#ifndef CELLULAR_DEVICE
27+
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
28+
#endif
29+
30+
#include "greentea-client/test_env.h"
31+
#include "unity.h"
32+
#include "utest.h"
33+
34+
#include "mbed.h"
35+
36+
#include "CellularLog.h"
37+
#include "CellularDevice.h"
38+
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
39+
40+
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
41+
static CellularDevice *device;
42+
static EventQueue queue(8 * EVENTS_EVENT_SIZE);
43+
44+
static void create_device()
45+
{
46+
device = new CELLULAR_DEVICE(queue);
47+
TEST_ASSERT(device != NULL);
48+
}
49+
50+
static void open_close_interfaces()
51+
{
52+
CellularNetwork *nw = device->open_network(&cellular_serial);
53+
TEST_ASSERT(nw != NULL);
54+
device->close_network();
55+
nw = device->open_network(NULL);
56+
TEST_ASSERT(nw == NULL);
57+
58+
CellularSIM* sim = device->open_sim(&cellular_serial);
59+
TEST_ASSERT(sim != NULL);
60+
device->close_sim();
61+
sim = device->open_sim(NULL);
62+
TEST_ASSERT(sim == NULL);
63+
64+
CellularInformation* info = device->open_information(&cellular_serial);
65+
TEST_ASSERT(info != NULL);
66+
device->close_information();
67+
info = device->open_information(NULL);
68+
TEST_ASSERT(info == NULL);
69+
70+
CellularPower* power = device->open_power(&cellular_serial);
71+
TEST_ASSERT(power != NULL);
72+
device->close_power();
73+
power = device->open_power(NULL);
74+
TEST_ASSERT(power == NULL);
75+
76+
CellularSMS* sms = device->open_sms(&cellular_serial);
77+
TEST_ASSERT(sms != NULL);
78+
device->close_sms();
79+
sms = device->open_sms(NULL);
80+
TEST_ASSERT(sms == NULL);
81+
}
82+
83+
static void other_methods()
84+
{
85+
// test first without any open interfaces
86+
device->set_timeout(5000);
87+
device->modem_debug_on(true);
88+
device->modem_debug_on(false);
89+
NetworkStack* stack = device->get_stack();
90+
TEST_ASSERT(stack == NULL);
91+
92+
CellularNetwork *nw = device->open_network(&cellular_serial);
93+
TEST_ASSERT(nw != NULL);
94+
95+
// then test witj open interface which is called
96+
device->set_timeout(5000);
97+
device->modem_debug_on(true);
98+
device->modem_debug_on(false);
99+
stack = device->get_stack();
100+
TEST_ASSERT(stack != NULL);
101+
}
102+
103+
static void delete_device()
104+
{
105+
// delete will close all opened interfaces
106+
delete device;
107+
device = NULL;
108+
}
109+
110+
using namespace utest::v1;
111+
112+
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
113+
{
114+
greentea_case_failure_abort_handler(source, reason);
115+
return STATUS_ABORT;
116+
}
117+
118+
static Case cases[] = {
119+
Case("CellularDevice create device", create_device, greentea_failure_handler),
120+
Case("CellularDevice Open and close interfaces", open_close_interfaces, greentea_failure_handler),
121+
Case("CellularDevice other methods", other_methods, greentea_failure_handler),
122+
Case("CellularDevice delete device", delete_device, greentea_failure_handler)
123+
};
124+
125+
static utest::v1::status_t test_setup(const size_t number_of_cases)
126+
{
127+
GREENTEA_SETUP(10*60, "default_auto");
128+
return verbose_test_setup_handler(number_of_cases);
129+
}
130+
131+
static Specification specification(test_setup, cases);
132+
133+
int main()
134+
{
135+
mbed_trace_init();
136+
137+
return Harness::run(specification);
138+
}
139+

features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,27 @@ UBLOX_PPP::~UBLOX_PPP()
3333
CellularNetwork *UBLOX_PPP::open_network(FileHandle *fh)
3434
{
3535
if (!_network) {
36-
_network = new UBLOX_PPP_CellularNetwork(*get_at_handler(fh));
36+
ATHandler *atHandler = get_at_handler(fh);
37+
if (atHandler) {
38+
_network = new UBLOX_PPP_CellularNetwork(*atHandler);
39+
if (!_network) {
40+
release_at_handler(atHandler);
41+
}
42+
}
3743
}
3844
return _network;
3945
}
4046

4147
CellularPower *UBLOX_PPP::open_power(FileHandle *fh)
4248
{
4349
if (!_power) {
44-
_power = new UBLOX_PPP_CellularPower(*get_at_handler(fh));
50+
ATHandler *atHandler = get_at_handler(fh);
51+
if (atHandler) {
52+
_power = new UBLOX_PPP_CellularPower(*get_at_handler(fh));
53+
if (!_power) {
54+
release_at_handler(atHandler);
55+
}
56+
}
4557
}
4658
return _power;
4759
}

0 commit comments

Comments
 (0)