Skip to content

Commit 3e790cc

Browse files
authored
Merge pull request #12065 from AriParkkila/cell-fea-nidd
Non-IP socket implementation for NIDD over CP
2 parents d07d7ca + 7899fea commit 3e790cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1332
-91
lines changed

TESTS/netsocket/nidd/main.cpp

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) 2019, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* 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, WITHOUT
13+
* 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+
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \
19+
(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != CELLULAR) || \
20+
!MBED_CONF_CELLULAR_CONTROL_PLANE_OPT
21+
#error [NOT_SUPPORTED] No network configuration found for this target.
22+
#else
23+
24+
#include "mbed.h"
25+
#include "mbed_trace.h"
26+
#include "greentea-client/test_env.h"
27+
#include "unity/unity.h"
28+
#include "utest.h"
29+
#include "utest/utest_stack_trace.h"
30+
#include "nidd_tests.h"
31+
32+
using namespace utest::v1;
33+
34+
namespace {
35+
Timer tc_bucket; // Timer to limit a test cases run time
36+
}
37+
38+
void drop_bad_packets(CellularNonIPSocket &sock, int orig_timeout)
39+
{
40+
nsapi_error_t err;
41+
sock.set_timeout(0);
42+
while (true) {
43+
err = sock.recv(NULL, 0);
44+
if (err == NSAPI_ERROR_WOULD_BLOCK) {
45+
break;
46+
}
47+
}
48+
sock.set_timeout(orig_timeout);
49+
}
50+
51+
bool check_oversized_packets(nsapi_error_t error, int &size)
52+
{
53+
if (error == NSAPI_ERROR_PARAMETER) {
54+
#if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT
55+
size = 100; // see BG96 driver
56+
#else
57+
size = 1280; // see TS 23.060 for MTU recommendations
58+
#endif
59+
return true;
60+
}
61+
return false;
62+
}
63+
64+
void fill_tx_buffer_ascii(char *buff, size_t len)
65+
{
66+
for (size_t i = 0; i < len; ++i) {
67+
buff[i] = (rand() % 43) + '0';
68+
}
69+
}
70+
71+
void poll_pending_messages(CellularNonIPSocket &sock, int count)
72+
{
73+
uint8_t buf[100] = {0};
74+
sock.set_timeout(1000);
75+
for (int i = 0; i < count; i++) {
76+
if (i == 0 || i == 2) {
77+
(void) sock.send("", 0); // poll to clear any remaining MT messages
78+
}
79+
while (sock.recv(buf, sizeof(buf)) > 0) {
80+
}
81+
}
82+
}
83+
84+
int split2half_rmng_nidd_test_time()
85+
{
86+
return (nidd_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
87+
}
88+
89+
// Test setup
90+
utest::v1::status_t greentea_setup(const size_t number_of_cases)
91+
{
92+
GREENTEA_SETUP(nidd_global::TESTS_TIMEOUT, "default_auto");
93+
tc_bucket.start();
94+
return greentea_test_setup_handler(number_of_cases);
95+
}
96+
97+
void greentea_teardown(const size_t passed, const size_t failed, const failure_t failure)
98+
{
99+
tc_bucket.stop();
100+
return greentea_test_teardown_handler(passed, failed, failure);
101+
}
102+
103+
utest::v1::status_t greentea_case_setup_handler_nidd(const Case *const source, const size_t index_of_case)
104+
{
105+
return greentea_case_setup_handler(source, index_of_case);
106+
}
107+
108+
utest::v1::status_t greentea_case_teardown_handler_nidd(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
109+
{
110+
return greentea_case_teardown_handler(source, passed, failed, failure);
111+
}
112+
113+
static void test_failure_handler(const failure_t failure)
114+
{
115+
UTEST_LOG_FUNCTION();
116+
if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) {
117+
verbose_test_failure_handler(failure);
118+
GREENTEA_TESTSUITE_RESULT(false);
119+
while (1) ;
120+
}
121+
}
122+
123+
Case cases[] = {
124+
Case("NIDDSOCKET_CONNECT", NIDDSOCKET_CONNECT),
125+
Case("NIDDSOCKET_ECHOTEST_NONBLOCK", NIDDSOCKET_ECHOTEST_NONBLOCK),
126+
Case("NIDDSOCKET_OPEN_CLOSE_REPEAT", NIDDSOCKET_OPEN_CLOSE_REPEAT),
127+
Case("NIDDSOCKET_OPEN_LIMIT", NIDDSOCKET_OPEN_LIMIT),
128+
Case("NIDDSOCKET_OPEN_DESTRUCT", NIDDSOCKET_OPEN_DESTRUCT),
129+
Case("NIDDSOCKET_OPEN_TWICE", NIDDSOCKET_OPEN_TWICE),
130+
Case("NIDDSOCKET_RECV_TIMEOUT", NIDDSOCKET_RECV_TIMEOUT),
131+
Case("NIDDSOCKET_SEND_TIMEOUT", NIDDSOCKET_SEND_TIMEOUT),
132+
Case("NIDDSOCKET_SEND_INVALID", NIDDSOCKET_SEND_INVALID),
133+
Case("NIDDSOCKET_SEND_REPEAT", NIDDSOCKET_SEND_REPEAT),
134+
Case("NIDDSOCKET_DISCONNECT", NIDDSOCKET_DISCONNECT),
135+
};
136+
137+
handlers_t nidd_test_case_handlers = {
138+
default_greentea_test_setup_handler,
139+
greentea_test_teardown_handler,
140+
test_failure_handler,
141+
greentea_case_setup_handler_nidd,
142+
greentea_case_teardown_handler_nidd,
143+
greentea_case_failure_continue_handler
144+
};
145+
146+
Specification specification(greentea_setup, cases, greentea_teardown, nidd_test_case_handlers);
147+
148+
int main()
149+
{
150+
int err = Harness::run(specification);
151+
return !err;
152+
}
153+
154+
#endif // !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE)
155+

TESTS/netsocket/nidd/nidd_tests.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2019, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* 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, WITHOUT
13+
* 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+
#ifndef NIDD_TESTS_H
19+
#define NIDD_TESTS_H
20+
21+
#include "CellularNonIPSocket.h"
22+
#include "CellularLog.h"
23+
#include "../test_params.h"
24+
25+
NetworkInterface *get_interface();
26+
void drop_bad_packets(CellularNonIPSocket &sock, int orig_timeout);
27+
bool check_oversized_packets(nsapi_error_t error, int &size);
28+
void fill_tx_buffer_ascii(char *buff, size_t len);
29+
void poll_pending_messages(CellularNonIPSocket &sock, int count);
30+
31+
/**
32+
* Single testcase might take only half of the remaining execution time
33+
*/
34+
int split2half_rmng_nidd_test_time(); // [s]
35+
36+
namespace nidd_global {
37+
#ifdef MBED_GREENTEA_TEST_NIDDSOCKET_TIMEOUT_S
38+
static const int TESTS_TIMEOUT = MBED_GREENTEA_TEST_NIDDSOCKET_TIMEOUT_S;
39+
#else
40+
static const int TESTS_TIMEOUT = (3 * 60);
41+
#endif
42+
static const int SOCKET_SEND_COUNT = 4;
43+
}
44+
45+
/*
46+
* Test cases
47+
*/
48+
void NIDDSOCKET_CONNECT();
49+
void NIDDSOCKET_DISCONNECT();
50+
void NIDDSOCKET_OPEN_CLOSE_REPEAT();
51+
void NIDDSOCKET_OPEN_LIMIT();
52+
void NIDDSOCKET_RECV_TIMEOUT();
53+
void NIDDSOCKET_SEND_TIMEOUT();
54+
void NIDDSOCKET_OPEN_DESTRUCT();
55+
void NIDDSOCKET_OPEN_TWICE();
56+
void NIDDSOCKET_SEND_INVALID();
57+
void NIDDSOCKET_ECHOTEST_NONBLOCK();
58+
void NIDDSOCKET_SEND_REPEAT();
59+
60+
#endif //NIDD_TESTS_H
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2019, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* 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, WITHOUT
13+
* 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+
#include "greentea-client/test_env.h"
19+
#include "mbed.h"
20+
#include "nidd_tests.h"
21+
#include "unity/unity.h"
22+
#include "utest.h"
23+
24+
using namespace utest::v1;
25+
26+
void NIDDSOCKET_CONNECT()
27+
{
28+
// power off modem for an initial state
29+
CellularDevice *dev = CellularDevice::get_default_instance();
30+
(void) dev->shutdown(); // modem may not be powered or ready yet
31+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, dev->soft_power_off());
32+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, dev->hard_power_off());
33+
34+
CellularContext *ctx = CellularContext::get_default_nonip_instance();
35+
ctx->set_default_parameters();
36+
nsapi_error_t err = ctx->connect();
37+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2019, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* 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, WITHOUT
13+
* 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+
#include "greentea-client/test_env.h"
19+
#include "mbed.h"
20+
#include "nidd_tests.h"
21+
#include "unity/unity.h"
22+
#include "utest.h"
23+
24+
using namespace utest::v1;
25+
26+
void NIDDSOCKET_DISCONNECT()
27+
{
28+
nsapi_error_t err = CellularContext::get_default_nonip_instance()->disconnect();
29+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
30+
}

0 commit comments

Comments
 (0)