|
| 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 | + |
0 commit comments