|
| 1 | +/* |
| 2 | + * Copyright (c) 2017, 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 | +#include "CellularTests.h" |
| 19 | + |
| 20 | +#if !defined(MBED_CONF_NSAPI_PRESENT) |
| 21 | +#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. |
| 22 | +#endif |
| 23 | + |
| 24 | +#ifndef CELLULAR_DEVICE |
| 25 | +#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined for this test |
| 26 | +#endif |
| 27 | + |
| 28 | +EventQueue queue(32 * EVENTS_EVENT_SIZE); |
| 29 | +Thread t; |
| 30 | +CELLULAR_DEVICE cellularDevice(queue); |
| 31 | + |
| 32 | +UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); |
| 33 | +CellularNetwork *network = NULL; |
| 34 | +CellularPower *pwr = NULL; |
| 35 | +CellularSIM *sim = NULL; |
| 36 | +CellularSMS *sms = NULL; |
| 37 | + |
| 38 | +using namespace utest::v1; |
| 39 | + |
| 40 | +// using namespace mbed; |
| 41 | +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) |
| 42 | +{ |
| 43 | + greentea_case_failure_abort_handler(source, reason); |
| 44 | + return STATUS_CONTINUE; |
| 45 | +} |
| 46 | + |
| 47 | +Case cases[] = { |
| 48 | + // power test |
| 49 | + Case("Create power", test_create_power, greentea_failure_handler), |
| 50 | +#ifdef MBED_CONF_APP_CELLULAR_SIM_PIN |
| 51 | + // sim test |
| 52 | + Case("test get SIM state", test_get_sim_state, greentea_failure_handler), |
| 53 | + Case("SIM set pin", test_set_pin, greentea_failure_handler), |
| 54 | + Case("SIM change pin", test_change_pin, greentea_failure_handler), |
| 55 | +#endif |
| 56 | + // network tests |
| 57 | + Case("attach", test_attach, greentea_failure_handler), |
| 58 | + // SMS tests |
| 59 | + Case("SMS init", test_sms_init, greentea_failure_handler), |
| 60 | + // network tests |
| 61 | + Case("connect", test_connect, greentea_failure_handler), |
| 62 | + Case("get_ip_address", test_get_ip_address, greentea_failure_handler), |
| 63 | + // stack tests |
| 64 | + Case("open", test_socket_open, greentea_failure_handler), |
| 65 | + Case("bind", test_socket_bind, greentea_failure_handler), |
| 66 | +// Case("set socket blocking", test_socket_set_blocking, greentea_failure_handler), |
| 67 | +// Case("socket send receive in blocking mode", test_socket_send_receive_blocking, greentea_failure_handler), |
| 68 | + Case("set socket non blocking", test_socket_set_non_blocking, greentea_failure_handler), |
| 69 | + Case("socket send receive in non blocking mode", test_socket_send_receive_non_blocking, greentea_failure_handler), |
| 70 | + Case("close", test_socket_close, greentea_failure_handler), |
| 71 | + // network tests |
| 72 | + Case("disconnect", test_disconnect, greentea_failure_handler), |
| 73 | + |
| 74 | + // test closing of all interface, must be the last test case |
| 75 | + Case("Close all Interfaces", test_close_interfaces, greentea_failure_handler) |
| 76 | +}; |
| 77 | + |
| 78 | +utest::v1::status_t test_setup(const size_t number_of_cases) |
| 79 | +{ |
| 80 | + GREENTEA_SETUP(300, "default_auto"); |
| 81 | + |
| 82 | + return verbose_test_setup_handler(number_of_cases); |
| 83 | +} |
| 84 | + |
| 85 | +Specification specification(test_setup, cases); |
| 86 | + |
| 87 | +void test_close_interfaces() |
| 88 | +{ |
| 89 | + // SMS is already closed in it's test |
| 90 | + cellularDevice.close_network(); |
| 91 | + cellularDevice.close_sim(); |
| 92 | + cellularDevice.close_power(); |
| 93 | +} |
| 94 | + |
| 95 | +int main() |
| 96 | +{ |
| 97 | +#if defined (MDMRTS) && defined (MDMCTS) |
| 98 | + serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); |
| 99 | +#endif |
| 100 | + pwr = cellularDevice.open_power(&serial); |
| 101 | + sim = cellularDevice.open_sim(&serial); |
| 102 | + sms = cellularDevice.open_sms(&serial); |
| 103 | + network = cellularDevice.open_network(&serial); |
| 104 | + |
| 105 | + t.start(callback(&queue, &EventQueue::dispatch_forever)); |
| 106 | + return Harness::run(specification); |
| 107 | +} |
0 commit comments