changes for R412M test cases
TESTS/unit_tests/default/main.cpp@22:63b1a3c02fb8, 2019-05-13 (annotated)
- Committer:
- mudassar0121
- Date:
- Mon May 13 13:30:24 2019 +0500
- Revision:
- 22:63b1a3c02fb8
- Parent:
- 12:ff6fac481487
- Child:
- 23:9098a541452b
RAT and MNO profile tests
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mudassar0121 |
22:63b1a3c02fb8 | 1 | |
rob.meades@u-blox.com | 1:bc228becc45d | 2 | #include "UbloxATCellularInterface.h" |
RobMeades | 0:7ccf0e7e8a83 | 3 | #include "greentea-client/test_env.h" |
RobMeades | 0:7ccf0e7e8a83 | 4 | #include "unity.h" |
RobMeades | 0:7ccf0e7e8a83 | 5 | #include "utest.h" |
RobMeades | 0:7ccf0e7e8a83 | 6 | #include "UDPSocket.h" |
RobMeades | 0:7ccf0e7e8a83 | 7 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:7ccf0e7e8a83 | 8 | #include "mbed_trace.h" |
RobMeades | 0:7ccf0e7e8a83 | 9 | #define TRACE_GROUP "TEST" |
RobMeades | 0:7ccf0e7e8a83 | 10 | #else |
rob.meades@u-blox.com | 1:bc228becc45d | 11 | #define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 1:bc228becc45d | 12 | #define tr_info(format, ...) debug(format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 1:bc228becc45d | 13 | #define tr_warn(format, ...) debug(format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 1:bc228becc45d | 14 | #define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__) |
RobMeades | 0:7ccf0e7e8a83 | 15 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 16 | |
RobMeades | 0:7ccf0e7e8a83 | 17 | using namespace utest::v1; |
RobMeades | 0:7ccf0e7e8a83 | 18 | |
RobMeades | 0:7ccf0e7e8a83 | 19 | // IMPORTANT!!! if you make a change to the tests here you should |
RobMeades | 0:7ccf0e7e8a83 | 20 | // check whether the same change should be made to the tests under |
rob.meades@u-blox.com | 6:63dad754c267 | 21 | // the PPP interface. |
rob.meades@u-blox.com | 6:63dad754c267 | 22 | |
rob.meades@u-blox.com | 6:63dad754c267 | 23 | // NOTE: these test are only as reliable as UDP across the internet |
rob.meades@u-blox.com | 6:63dad754c267 | 24 | // over a radio link. The tests expect an NTP server to respond |
rob.meades@u-blox.com | 6:63dad754c267 | 25 | // to UDP packets and, if configured, an echo server to respond |
rob.meades@u-blox.com | 6:63dad754c267 | 26 | // to UDP packets. This simply may not happen. Please be patient. |
RobMeades | 0:7ccf0e7e8a83 | 27 | |
RobMeades | 0:7ccf0e7e8a83 | 28 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 29 | // COMPILE-TIME MACROS |
RobMeades | 0:7ccf0e7e8a83 | 30 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 31 | |
RobMeades | 0:7ccf0e7e8a83 | 32 | // These macros can be overridden with an mbed_app.json file and |
RobMeades | 0:7ccf0e7e8a83 | 33 | // contents of the following form: |
RobMeades | 0:7ccf0e7e8a83 | 34 | // |
RobMeades | 0:7ccf0e7e8a83 | 35 | //{ |
RobMeades | 0:7ccf0e7e8a83 | 36 | // "config": { |
RobMeades | 0:7ccf0e7e8a83 | 37 | // "default-pin": { |
RobMeades | 0:7ccf0e7e8a83 | 38 | // "value": "\"1234\"" |
RobMeades | 0:7ccf0e7e8a83 | 39 | // } |
RobMeades | 0:7ccf0e7e8a83 | 40 | //} |
RobMeades | 0:7ccf0e7e8a83 | 41 | // |
RobMeades | 0:7ccf0e7e8a83 | 42 | // See the template_mbed_app.txt in this directory for a fuller example. |
RobMeades | 0:7ccf0e7e8a83 | 43 | |
RobMeades | 0:7ccf0e7e8a83 | 44 | // Whether debug trace is on |
RobMeades | 0:7ccf0e7e8a83 | 45 | #ifndef MBED_CONF_APP_DEBUG_ON |
RobMeades | 0:7ccf0e7e8a83 | 46 | # define MBED_CONF_APP_DEBUG_ON false |
RobMeades | 0:7ccf0e7e8a83 | 47 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 48 | |
RobMeades | 0:7ccf0e7e8a83 | 49 | // Run the SIM change tests, which require the DEFAULT_PIN |
RobMeades | 0:7ccf0e7e8a83 | 50 | // above to be correct for the board on which the test |
RobMeades | 0:7ccf0e7e8a83 | 51 | // is being run (and the SIM PIN to be disabled before tests run). |
RobMeades | 0:7ccf0e7e8a83 | 52 | #ifndef MBED_CONF_APP_RUN_SIM_PIN_CHANGE_TESTS |
RobMeades | 0:7ccf0e7e8a83 | 53 | # define MBED_CONF_APP_RUN_SIM_PIN_CHANGE_TESTS 0 |
RobMeades | 0:7ccf0e7e8a83 | 54 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 55 | |
RobMeades | 0:7ccf0e7e8a83 | 56 | #if MBED_CONF_APP_RUN_SIM_PIN_CHANGE_TESTS |
RobMeades | 0:7ccf0e7e8a83 | 57 | # ifndef MBED_CONF_APP_DEFAULT_PIN |
RobMeades | 0:7ccf0e7e8a83 | 58 | # error "MBED_CONF_APP_DEFAULT_PIN must be defined to run the SIM tests" |
RobMeades | 0:7ccf0e7e8a83 | 59 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 60 | # ifndef MBED_CONF_APP_ALT_PIN |
RobMeades | 0:7ccf0e7e8a83 | 61 | # error "MBED_CONF_APP_ALT_PIN must be defined to run the SIM tests" |
RobMeades | 0:7ccf0e7e8a83 | 62 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 63 | # ifndef MBED_CONF_APP_INCORRECT_PIN |
RobMeades | 0:7ccf0e7e8a83 | 64 | # error "MBED_CONF_APP_INCORRECT_PIN must be defined to run the SIM tests" |
RobMeades | 0:7ccf0e7e8a83 | 65 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 66 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 67 | |
RobMeades | 0:7ccf0e7e8a83 | 68 | // The credentials of the SIM in the board. |
RobMeades | 0:7ccf0e7e8a83 | 69 | #ifndef MBED_CONF_APP_DEFAULT_PIN |
RobMeades | 0:7ccf0e7e8a83 | 70 | // Note: if PIN is enabled on your SIM, or you wish to run the SIM PIN change |
RobMeades | 0:7ccf0e7e8a83 | 71 | // tests, you must define the PIN for your SIM (see note above on using |
RobMeades | 0:7ccf0e7e8a83 | 72 | // mbed_app.json to do so). |
RobMeades | 0:7ccf0e7e8a83 | 73 | # define MBED_CONF_APP_DEFAULT_PIN "0000" |
RobMeades | 0:7ccf0e7e8a83 | 74 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 75 | #ifndef MBED_CONF_APP_APN |
RobMeades | 0:7ccf0e7e8a83 | 76 | # define MBED_CONF_APP_APN NULL |
RobMeades | 0:7ccf0e7e8a83 | 77 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 78 | #ifndef MBED_CONF_APP_USERNAME |
RobMeades | 0:7ccf0e7e8a83 | 79 | # define MBED_CONF_APP_USERNAME NULL |
RobMeades | 0:7ccf0e7e8a83 | 80 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 81 | #ifndef MBED_CONF_APP_PASSWORD |
RobMeades | 0:7ccf0e7e8a83 | 82 | # define MBED_CONF_APP_PASSWORD NULL |
RobMeades | 0:7ccf0e7e8a83 | 83 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 84 | |
RobMeades | 0:7ccf0e7e8a83 | 85 | // Alternate PIN to use during pin change testing |
RobMeades | 0:7ccf0e7e8a83 | 86 | #ifndef MBED_CONF_APP_ALT_PIN |
RobMeades | 0:7ccf0e7e8a83 | 87 | # define MBED_CONF_APP_ALT_PIN "9876" |
RobMeades | 0:7ccf0e7e8a83 | 88 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 89 | |
RobMeades | 0:7ccf0e7e8a83 | 90 | // A PIN that is definitely incorrect |
RobMeades | 0:7ccf0e7e8a83 | 91 | #ifndef MBED_CONF_APP_INCORRECT_PIN |
RobMeades | 0:7ccf0e7e8a83 | 92 | # define MBED_CONF_APP_INCORRECT_PIN "1530" |
RobMeades | 0:7ccf0e7e8a83 | 93 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 94 | |
RobMeades | 0:7ccf0e7e8a83 | 95 | // Servers and ports |
RobMeades | 0:7ccf0e7e8a83 | 96 | #ifdef MBED_CONF_APP_ECHO_SERVER |
RobMeades | 0:7ccf0e7e8a83 | 97 | # ifndef MBED_CONF_APP_ECHO_UDP_PORT |
RobMeades | 0:7ccf0e7e8a83 | 98 | # error "MBED_CONF_APP_ECHO_UDP_PORT (the port on which your echo server echoes UDP packets) must be defined" |
RobMeades | 0:7ccf0e7e8a83 | 99 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 100 | # ifndef MBED_CONF_APP_ECHO_TCP_PORT |
RobMeades | 0:7ccf0e7e8a83 | 101 | # error "MBED_CONF_APP_ECHO_TCP_PORT (the port on which your echo server echoes TCP packets) must be defined" |
RobMeades | 0:7ccf0e7e8a83 | 102 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 103 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 104 | |
RobMeades | 0:7ccf0e7e8a83 | 105 | #ifndef MBED_CONF_APP_NTP_SERVER |
RobMeades | 0:7ccf0e7e8a83 | 106 | # define MBED_CONF_APP_NTP_SERVER "2.pool.ntp.org" |
RobMeades | 0:7ccf0e7e8a83 | 107 | #else |
RobMeades | 0:7ccf0e7e8a83 | 108 | # ifndef MBED_CONF_APP_NTP_PORT |
RobMeades | 0:7ccf0e7e8a83 | 109 | # error "MBED_CONF_APP_NTP_PORT must be defined if MBED_CONF_APP_NTP_SERVER is defined" |
RobMeades | 0:7ccf0e7e8a83 | 110 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 111 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 112 | #ifndef MBED_CONF_APP_NTP_PORT |
RobMeades | 0:7ccf0e7e8a83 | 113 | # define MBED_CONF_APP_NTP_PORT 123 |
RobMeades | 0:7ccf0e7e8a83 | 114 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 115 | |
RobMeades | 0:7ccf0e7e8a83 | 116 | #ifndef MBED_CONF_APP_LOCAL_PORT |
RobMeades | 0:7ccf0e7e8a83 | 117 | # define MBED_CONF_APP_LOCAL_PORT 15 |
RobMeades | 0:7ccf0e7e8a83 | 118 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 119 | |
RobMeades | 0:7ccf0e7e8a83 | 120 | // UDP packet size limit for testing |
RobMeades | 0:7ccf0e7e8a83 | 121 | #ifndef MBED_CONF_APP_UDP_MAX_PACKET_SIZE |
RobMeades | 0:7ccf0e7e8a83 | 122 | # define MBED_CONF_APP_UDP_MAX_PACKET_SIZE 1024 |
RobMeades | 0:7ccf0e7e8a83 | 123 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 124 | |
RobMeades | 0:7ccf0e7e8a83 | 125 | // The maximum size of UDP data fragmented across |
RobMeades | 0:7ccf0e7e8a83 | 126 | // multiple packets |
RobMeades | 0:7ccf0e7e8a83 | 127 | #ifndef MBED_CONF_APP_UDP_MAX_FRAG_PACKET_SIZE |
RobMeades | 0:7ccf0e7e8a83 | 128 | # define MBED_CONF_APP_UDP_MAX_FRAG_PACKET_SIZE 1500 |
RobMeades | 0:7ccf0e7e8a83 | 129 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 130 | |
RobMeades | 0:7ccf0e7e8a83 | 131 | // TCP packet size limit for testing |
RobMeades | 0:7ccf0e7e8a83 | 132 | #ifndef MBED_CONF_APP_MBED_CONF_APP_TCP_MAX_PACKET_SIZE |
RobMeades | 0:7ccf0e7e8a83 | 133 | # define MBED_CONF_APP_TCP_MAX_PACKET_SIZE 1500 |
RobMeades | 0:7ccf0e7e8a83 | 134 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 135 | |
RobMeades | 0:7ccf0e7e8a83 | 136 | // The number of retries for UDP exchanges |
RobMeades | 0:7ccf0e7e8a83 | 137 | #define NUM_UDP_RETRIES 5 |
RobMeades | 0:7ccf0e7e8a83 | 138 | |
RobMeades | 0:7ccf0e7e8a83 | 139 | // How long to wait for stuff to travel in the async echo tests |
RobMeades | 0:7ccf0e7e8a83 | 140 | #define ASYNC_TEST_WAIT_TIME 10000 |
RobMeades | 0:7ccf0e7e8a83 | 141 | |
RobMeades | 0:7ccf0e7e8a83 | 142 | // The maximum number of sockets that can be open at one time |
RobMeades | 0:7ccf0e7e8a83 | 143 | #define MAX_NUM_SOCKETS 7 |
RobMeades | 0:7ccf0e7e8a83 | 144 | |
mudassar0121 |
22:63b1a3c02fb8 | 145 | int previousSelectedRat = -1, previousPreferredRat = -1, previousSecondPreferredRat = -1; |
mudassar0121 |
22:63b1a3c02fb8 | 146 | |
RobMeades | 0:7ccf0e7e8a83 | 147 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 148 | // PRIVATE VARIABLES |
RobMeades | 0:7ccf0e7e8a83 | 149 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 150 | |
RobMeades | 0:7ccf0e7e8a83 | 151 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:7ccf0e7e8a83 | 152 | // Lock for debug prints |
RobMeades | 0:7ccf0e7e8a83 | 153 | static Mutex mtx; |
RobMeades | 0:7ccf0e7e8a83 | 154 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 155 | |
rob.meades@u-blox.com | 6:63dad754c267 | 156 | // An instance of the cellular interface |
rob.meades@u-blox.com | 6:63dad754c267 | 157 | static UbloxATCellularInterface *interface = |
RobMeades | 0:7ccf0e7e8a83 | 158 | new UbloxATCellularInterface(MDMTXD, MDMRXD, |
RobMeades | 0:7ccf0e7e8a83 | 159 | MBED_CONF_UBLOX_CELL_BAUD_RATE, |
RobMeades | 0:7ccf0e7e8a83 | 160 | MBED_CONF_APP_DEBUG_ON); |
RobMeades | 0:7ccf0e7e8a83 | 161 | |
RobMeades | 0:7ccf0e7e8a83 | 162 | // Connection flag |
RobMeades | 0:7ccf0e7e8a83 | 163 | static bool connection_has_gone_down = false; |
RobMeades | 0:7ccf0e7e8a83 | 164 | |
RobMeades | 0:7ccf0e7e8a83 | 165 | // Data to exchange |
RobMeades | 0:7ccf0e7e8a83 | 166 | static const char send_data[] = "_____0000:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 167 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 168 | "_____0100:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 169 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 170 | "_____0200:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 171 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 172 | "_____0300:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 173 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 174 | "_____0400:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 175 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 176 | "_____0500:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 177 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 178 | "_____0600:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 179 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 180 | "_____0700:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 181 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 182 | "_____0800:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 183 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 184 | "_____0900:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 185 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 186 | "_____1000:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 187 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 188 | "_____1100:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 189 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 190 | "_____1200:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 191 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 192 | "_____1300:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 193 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 194 | "_____1400:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 195 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 196 | "_____1500:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 197 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 198 | "_____1600:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 199 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 200 | "_____1700:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 201 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 202 | "_____1800:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 203 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 204 | "_____1900:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 205 | "01234567890123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 206 | "_____2000:0123456789012345678901234567890123456789" |
RobMeades | 0:7ccf0e7e8a83 | 207 | "01234567890123456789012345678901234567890123456789"; |
RobMeades | 0:7ccf0e7e8a83 | 208 | |
RobMeades | 0:7ccf0e7e8a83 | 209 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 210 | // PRIVATE FUNCTIONS |
RobMeades | 0:7ccf0e7e8a83 | 211 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 212 | |
RobMeades | 0:7ccf0e7e8a83 | 213 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:7ccf0e7e8a83 | 214 | // Locks for debug prints |
RobMeades | 0:7ccf0e7e8a83 | 215 | static void lock() |
RobMeades | 0:7ccf0e7e8a83 | 216 | { |
RobMeades | 0:7ccf0e7e8a83 | 217 | mtx.lock(); |
RobMeades | 0:7ccf0e7e8a83 | 218 | } |
RobMeades | 0:7ccf0e7e8a83 | 219 | |
RobMeades | 0:7ccf0e7e8a83 | 220 | static void unlock() |
RobMeades | 0:7ccf0e7e8a83 | 221 | { |
RobMeades | 0:7ccf0e7e8a83 | 222 | mtx.unlock(); |
RobMeades | 0:7ccf0e7e8a83 | 223 | } |
RobMeades | 0:7ccf0e7e8a83 | 224 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 225 | |
RobMeades | 0:7ccf0e7e8a83 | 226 | // Callback in case the connection goes down |
RobMeades | 0:7ccf0e7e8a83 | 227 | static void connection_down_cb(nsapi_error_t err) |
RobMeades | 0:7ccf0e7e8a83 | 228 | { |
RobMeades | 0:7ccf0e7e8a83 | 229 | connection_has_gone_down = true; |
RobMeades | 0:7ccf0e7e8a83 | 230 | } |
RobMeades | 0:7ccf0e7e8a83 | 231 | |
RobMeades | 0:7ccf0e7e8a83 | 232 | #ifdef MBED_CONF_APP_ECHO_SERVER |
RobMeades | 0:7ccf0e7e8a83 | 233 | // Make sure that size is greater than 0 and no more than limit, |
RobMeades | 0:7ccf0e7e8a83 | 234 | // useful since, when moduloing a very large number number, |
RobMeades | 0:7ccf0e7e8a83 | 235 | // compilers sometimes screw up and produce a small *negative* |
RobMeades | 0:7ccf0e7e8a83 | 236 | // number. Who knew? For example, GCC decided that |
RobMeades | 0:7ccf0e7e8a83 | 237 | // 492318453 (0x1d582ef5) modulo 508 was -47 (0xffffffd1). |
RobMeades | 0:7ccf0e7e8a83 | 238 | static int fix (int size, int limit) |
RobMeades | 0:7ccf0e7e8a83 | 239 | { |
RobMeades | 0:7ccf0e7e8a83 | 240 | if (size <= 0) { |
RobMeades | 0:7ccf0e7e8a83 | 241 | size = limit / 2; // better than 1 |
RobMeades | 0:7ccf0e7e8a83 | 242 | } else if (size > limit) { |
RobMeades | 0:7ccf0e7e8a83 | 243 | size = limit; |
RobMeades | 0:7ccf0e7e8a83 | 244 | } |
RobMeades | 0:7ccf0e7e8a83 | 245 | |
RobMeades | 0:7ccf0e7e8a83 | 246 | return size; |
RobMeades | 0:7ccf0e7e8a83 | 247 | } |
RobMeades | 0:7ccf0e7e8a83 | 248 | |
RobMeades | 0:7ccf0e7e8a83 | 249 | // Do a UDP socket echo test to a given host of a given packet size |
RobMeades | 0:7ccf0e7e8a83 | 250 | static void do_udp_echo(UDPSocket *sock, SocketAddress *host_address, int size) |
RobMeades | 0:7ccf0e7e8a83 | 251 | { |
RobMeades | 0:7ccf0e7e8a83 | 252 | bool success = false; |
RobMeades | 0:7ccf0e7e8a83 | 253 | void * recv_data = malloc (size); |
RobMeades | 0:7ccf0e7e8a83 | 254 | SocketAddress sender_address; |
RobMeades | 0:7ccf0e7e8a83 | 255 | TEST_ASSERT(recv_data != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 256 | |
RobMeades | 0:7ccf0e7e8a83 | 257 | // Retry this a few times, don't want to fail due to a flaky link |
RobMeades | 0:7ccf0e7e8a83 | 258 | for (int x = 0; !success && (x < NUM_UDP_RETRIES); x++) { |
RobMeades | 0:7ccf0e7e8a83 | 259 | tr_debug("Echo testing UDP packet size %d byte(s), try %d.", size, x + 1); |
RobMeades | 0:7ccf0e7e8a83 | 260 | if ((sock->sendto(*host_address, (void*) send_data, size) == size) && |
RobMeades | 0:7ccf0e7e8a83 | 261 | (sock->recvfrom(&sender_address, recv_data, size) == size)) { |
RobMeades | 0:7ccf0e7e8a83 | 262 | TEST_ASSERT (memcmp(send_data, recv_data, size) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 263 | TEST_ASSERT (strcmp(sender_address.get_ip_address(), host_address->get_ip_address()) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 264 | TEST_ASSERT (sender_address.get_port() == host_address->get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 265 | success = true; |
RobMeades | 0:7ccf0e7e8a83 | 266 | } |
RobMeades | 0:7ccf0e7e8a83 | 267 | } |
RobMeades | 0:7ccf0e7e8a83 | 268 | TEST_ASSERT (success); |
RobMeades | 0:7ccf0e7e8a83 | 269 | TEST_ASSERT(!connection_has_gone_down); |
RobMeades | 0:7ccf0e7e8a83 | 270 | |
RobMeades | 0:7ccf0e7e8a83 | 271 | free (recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 272 | } |
RobMeades | 0:7ccf0e7e8a83 | 273 | |
RobMeades | 0:7ccf0e7e8a83 | 274 | // The asynchronous callback |
RobMeades | 0:7ccf0e7e8a83 | 275 | static void async_cb(bool *callback_triggered) |
RobMeades | 0:7ccf0e7e8a83 | 276 | { |
RobMeades | 0:7ccf0e7e8a83 | 277 | |
RobMeades | 0:7ccf0e7e8a83 | 278 | TEST_ASSERT (callback_triggered != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 279 | *callback_triggered = true; |
RobMeades | 0:7ccf0e7e8a83 | 280 | } |
RobMeades | 0:7ccf0e7e8a83 | 281 | |
rob.meades@u-blox.com | 6:63dad754c267 | 282 | // Do a UDP echo but using the asynchronous interface; we can exchange |
RobMeades | 0:7ccf0e7e8a83 | 283 | // packets longer in size than one UDP packet this way |
RobMeades | 0:7ccf0e7e8a83 | 284 | static void do_udp_echo_async(UDPSocket *sock, SocketAddress *host_address, |
RobMeades | 0:7ccf0e7e8a83 | 285 | int size, bool *callback_triggered) |
RobMeades | 0:7ccf0e7e8a83 | 286 | { |
RobMeades | 0:7ccf0e7e8a83 | 287 | void * recv_data = malloc (size); |
RobMeades | 0:7ccf0e7e8a83 | 288 | int recv_size = 0; |
RobMeades | 0:7ccf0e7e8a83 | 289 | SocketAddress sender_address; |
RobMeades | 0:7ccf0e7e8a83 | 290 | Timer timer; |
RobMeades | 0:7ccf0e7e8a83 | 291 | int x, y, z; |
RobMeades | 0:7ccf0e7e8a83 | 292 | TEST_ASSERT(recv_data != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 293 | |
RobMeades | 0:7ccf0e7e8a83 | 294 | *callback_triggered = false; |
RobMeades | 0:7ccf0e7e8a83 | 295 | for (y = 0; (recv_size < size) && (y < NUM_UDP_RETRIES); y++) { |
RobMeades | 0:7ccf0e7e8a83 | 296 | tr_debug("Echo testing UDP packet size %d byte(s) async, try %d.", size, y + 1); |
RobMeades | 0:7ccf0e7e8a83 | 297 | recv_size = 0; |
RobMeades | 0:7ccf0e7e8a83 | 298 | // Retry this a few times, don't want to fail due to a flaky link |
RobMeades | 0:7ccf0e7e8a83 | 299 | if (sock->sendto(*host_address, (void *) send_data, size) == size) { |
RobMeades | 0:7ccf0e7e8a83 | 300 | // Wait for all the echoed data to arrive |
RobMeades | 0:7ccf0e7e8a83 | 301 | timer.start(); |
RobMeades | 0:7ccf0e7e8a83 | 302 | while ((recv_size < size) && (timer.read_ms() < ASYNC_TEST_WAIT_TIME)) { |
RobMeades | 0:7ccf0e7e8a83 | 303 | if (*callback_triggered) { |
RobMeades | 0:7ccf0e7e8a83 | 304 | *callback_triggered = false; |
RobMeades | 0:7ccf0e7e8a83 | 305 | x = sock->recvfrom(&sender_address, (char *) recv_data + recv_size, size); |
RobMeades | 0:7ccf0e7e8a83 | 306 | if (x > 0) { |
RobMeades | 0:7ccf0e7e8a83 | 307 | recv_size += x; |
RobMeades | 0:7ccf0e7e8a83 | 308 | } |
RobMeades | 0:7ccf0e7e8a83 | 309 | tr_debug("%d byte(s) echoed back so far, %d to go.", recv_size, size - recv_size); |
RobMeades | 0:7ccf0e7e8a83 | 310 | TEST_ASSERT(strcmp(sender_address.get_ip_address(), host_address->get_ip_address()) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 311 | TEST_ASSERT(sender_address.get_port() == host_address->get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 312 | } |
RobMeades | 0:7ccf0e7e8a83 | 313 | wait_ms(10); |
RobMeades | 0:7ccf0e7e8a83 | 314 | } |
RobMeades | 0:7ccf0e7e8a83 | 315 | timer.stop(); |
RobMeades | 0:7ccf0e7e8a83 | 316 | timer.reset(); |
RobMeades | 0:7ccf0e7e8a83 | 317 | |
RobMeades | 0:7ccf0e7e8a83 | 318 | // If everything arrived back, check it's the same as we sent |
RobMeades | 0:7ccf0e7e8a83 | 319 | if (recv_size == size) { |
RobMeades | 0:7ccf0e7e8a83 | 320 | z = memcmp(send_data, recv_data, size); |
RobMeades | 0:7ccf0e7e8a83 | 321 | if (z != 0) { |
RobMeades | 0:7ccf0e7e8a83 | 322 | tr_debug("WARNING: mismatch, retrying"); |
RobMeades | 0:7ccf0e7e8a83 | 323 | tr_debug("Sent %d, |%*.*s|", size, size, size, send_data); |
RobMeades | 0:7ccf0e7e8a83 | 324 | tr_debug("Rcvd %d, |%*.*s|", size, size, size, (char *) recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 325 | // If things don't match, it could be due to data loss (this is UDP |
RobMeades | 0:7ccf0e7e8a83 | 326 | // you know...), so set recv_size to 0 to cause another try |
RobMeades | 0:7ccf0e7e8a83 | 327 | recv_size = 0; |
RobMeades | 0:7ccf0e7e8a83 | 328 | } |
RobMeades | 0:7ccf0e7e8a83 | 329 | } |
RobMeades | 0:7ccf0e7e8a83 | 330 | } |
RobMeades | 0:7ccf0e7e8a83 | 331 | } |
RobMeades | 0:7ccf0e7e8a83 | 332 | |
RobMeades | 0:7ccf0e7e8a83 | 333 | TEST_ASSERT(recv_size == size); |
RobMeades | 0:7ccf0e7e8a83 | 334 | TEST_ASSERT(!connection_has_gone_down); |
RobMeades | 0:7ccf0e7e8a83 | 335 | |
RobMeades | 0:7ccf0e7e8a83 | 336 | free (recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 337 | } |
RobMeades | 0:7ccf0e7e8a83 | 338 | |
RobMeades | 0:7ccf0e7e8a83 | 339 | // Send an entire TCP data buffer until done |
RobMeades | 0:7ccf0e7e8a83 | 340 | static int sendAll(TCPSocket *sock, const char *data, int size) |
RobMeades | 0:7ccf0e7e8a83 | 341 | { |
RobMeades | 0:7ccf0e7e8a83 | 342 | int x; |
RobMeades | 0:7ccf0e7e8a83 | 343 | int count = 0; |
RobMeades | 0:7ccf0e7e8a83 | 344 | Timer timer; |
RobMeades | 0:7ccf0e7e8a83 | 345 | |
RobMeades | 0:7ccf0e7e8a83 | 346 | timer.start(); |
RobMeades | 0:7ccf0e7e8a83 | 347 | while ((count < size) && (timer.read_ms() < 10000)) { |
RobMeades | 0:7ccf0e7e8a83 | 348 | x = sock->send(data + count, size - count); |
RobMeades | 0:7ccf0e7e8a83 | 349 | if (x > 0) { |
RobMeades | 0:7ccf0e7e8a83 | 350 | count += x; |
RobMeades | 0:7ccf0e7e8a83 | 351 | tr_debug("%d byte(s) sent, %d left to send.", count, size - count); |
RobMeades | 0:7ccf0e7e8a83 | 352 | } |
RobMeades | 0:7ccf0e7e8a83 | 353 | wait_ms(10); |
RobMeades | 0:7ccf0e7e8a83 | 354 | } |
RobMeades | 0:7ccf0e7e8a83 | 355 | timer.stop(); |
RobMeades | 0:7ccf0e7e8a83 | 356 | |
RobMeades | 0:7ccf0e7e8a83 | 357 | return count; |
RobMeades | 0:7ccf0e7e8a83 | 358 | } |
RobMeades | 0:7ccf0e7e8a83 | 359 | |
rob.meades@u-blox.com | 6:63dad754c267 | 360 | // Do a TCP echo but using the asynchronous interface |
RobMeades | 0:7ccf0e7e8a83 | 361 | static void do_tcp_echo_async(TCPSocket *sock, int size, bool *callback_triggered) |
RobMeades | 0:7ccf0e7e8a83 | 362 | { |
RobMeades | 0:7ccf0e7e8a83 | 363 | void * recv_data = malloc (size); |
RobMeades | 0:7ccf0e7e8a83 | 364 | int recv_size = 0; |
RobMeades | 0:7ccf0e7e8a83 | 365 | int x, y; |
RobMeades | 0:7ccf0e7e8a83 | 366 | Timer timer; |
RobMeades | 0:7ccf0e7e8a83 | 367 | TEST_ASSERT(recv_data != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 368 | |
RobMeades | 0:7ccf0e7e8a83 | 369 | *callback_triggered = false; |
RobMeades | 0:7ccf0e7e8a83 | 370 | tr_debug("Echo testing TCP packet size %d byte(s) async.", size); |
RobMeades | 0:7ccf0e7e8a83 | 371 | TEST_ASSERT (sendAll(sock, send_data, size) == size); |
RobMeades | 0:7ccf0e7e8a83 | 372 | |
RobMeades | 0:7ccf0e7e8a83 | 373 | // Wait for all the echoed data to arrive |
RobMeades | 0:7ccf0e7e8a83 | 374 | timer.start(); |
RobMeades | 0:7ccf0e7e8a83 | 375 | while ((recv_size < size) && (timer.read_ms() < ASYNC_TEST_WAIT_TIME)) { |
RobMeades | 0:7ccf0e7e8a83 | 376 | if (*callback_triggered) { |
RobMeades | 0:7ccf0e7e8a83 | 377 | *callback_triggered = false; |
RobMeades | 0:7ccf0e7e8a83 | 378 | x = sock->recv((char *) recv_data + recv_size, size); |
RobMeades | 0:7ccf0e7e8a83 | 379 | TEST_ASSERT(x > 0); |
RobMeades | 0:7ccf0e7e8a83 | 380 | recv_size += x; |
RobMeades | 0:7ccf0e7e8a83 | 381 | tr_debug("%d byte(s) echoed back so far, %d to go.", recv_size, size - recv_size); |
RobMeades | 0:7ccf0e7e8a83 | 382 | } |
RobMeades | 0:7ccf0e7e8a83 | 383 | wait_ms(10); |
RobMeades | 0:7ccf0e7e8a83 | 384 | } |
RobMeades | 0:7ccf0e7e8a83 | 385 | TEST_ASSERT(recv_size == size); |
RobMeades | 0:7ccf0e7e8a83 | 386 | y = memcmp(send_data, recv_data, size); |
RobMeades | 0:7ccf0e7e8a83 | 387 | if (y != 0) { |
RobMeades | 0:7ccf0e7e8a83 | 388 | tr_debug("Sent %d, |%*.*s|", size, size, size, send_data); |
RobMeades | 0:7ccf0e7e8a83 | 389 | tr_debug("Rcvd %d, |%*.*s|", size, size, size, (char *) recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 390 | TEST_ASSERT(false); |
RobMeades | 0:7ccf0e7e8a83 | 391 | } |
RobMeades | 0:7ccf0e7e8a83 | 392 | timer.stop(); |
RobMeades | 0:7ccf0e7e8a83 | 393 | |
RobMeades | 0:7ccf0e7e8a83 | 394 | TEST_ASSERT(!connection_has_gone_down); |
RobMeades | 0:7ccf0e7e8a83 | 395 | |
RobMeades | 0:7ccf0e7e8a83 | 396 | free (recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 397 | } |
RobMeades | 0:7ccf0e7e8a83 | 398 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 399 | |
RobMeades | 0:7ccf0e7e8a83 | 400 | // Get NTP time from a socket |
RobMeades | 0:7ccf0e7e8a83 | 401 | static void do_ntp_sock (UDPSocket *sock, SocketAddress ntp_address) |
RobMeades | 0:7ccf0e7e8a83 | 402 | { |
RobMeades | 0:7ccf0e7e8a83 | 403 | char ntp_values[48] = { 0 }; |
RobMeades | 0:7ccf0e7e8a83 | 404 | time_t timestamp = 0; |
RobMeades | 0:7ccf0e7e8a83 | 405 | struct tm *localTime; |
RobMeades | 0:7ccf0e7e8a83 | 406 | char timeString[25]; |
RobMeades | 0:7ccf0e7e8a83 | 407 | time_t TIME1970 = 2208988800U; |
RobMeades | 0:7ccf0e7e8a83 | 408 | int len; |
RobMeades | 0:7ccf0e7e8a83 | 409 | bool comms_done = false; |
RobMeades | 0:7ccf0e7e8a83 | 410 | |
RobMeades | 0:7ccf0e7e8a83 | 411 | ntp_values[0] = '\x1b'; |
RobMeades | 0:7ccf0e7e8a83 | 412 | |
RobMeades | 0:7ccf0e7e8a83 | 413 | // Retry this a few times, don't want to fail due to a flaky link |
RobMeades | 0:7ccf0e7e8a83 | 414 | for (unsigned int x = 0; !comms_done && (x < NUM_UDP_RETRIES); x++) { |
RobMeades | 0:7ccf0e7e8a83 | 415 | sock->sendto(ntp_address, (void*) ntp_values, sizeof(ntp_values)); |
RobMeades | 0:7ccf0e7e8a83 | 416 | len = sock->recvfrom(&ntp_address, (void*) ntp_values, sizeof(ntp_values)); |
RobMeades | 0:7ccf0e7e8a83 | 417 | if (len > 0) { |
RobMeades | 0:7ccf0e7e8a83 | 418 | comms_done = true; |
RobMeades | 0:7ccf0e7e8a83 | 419 | } |
RobMeades | 0:7ccf0e7e8a83 | 420 | } |
RobMeades | 0:7ccf0e7e8a83 | 421 | TEST_ASSERT (comms_done); |
RobMeades | 0:7ccf0e7e8a83 | 422 | |
RobMeades | 0:7ccf0e7e8a83 | 423 | tr_debug("UDP: %d byte(s) returned by NTP server.", len); |
RobMeades | 0:7ccf0e7e8a83 | 424 | if (len >= 43) { |
RobMeades | 0:7ccf0e7e8a83 | 425 | timestamp |= ((int) *(ntp_values + 40)) << 24; |
RobMeades | 0:7ccf0e7e8a83 | 426 | timestamp |= ((int) *(ntp_values + 41)) << 16; |
RobMeades | 0:7ccf0e7e8a83 | 427 | timestamp |= ((int) *(ntp_values + 42)) << 8; |
RobMeades | 0:7ccf0e7e8a83 | 428 | timestamp |= ((int) *(ntp_values + 43)); |
RobMeades | 0:7ccf0e7e8a83 | 429 | timestamp -= TIME1970; |
RobMeades | 0:7ccf0e7e8a83 | 430 | srand (timestamp); |
RobMeades | 0:7ccf0e7e8a83 | 431 | tr_debug("srand() called"); |
RobMeades | 0:7ccf0e7e8a83 | 432 | localTime = localtime(×tamp); |
RobMeades | 0:7ccf0e7e8a83 | 433 | if (localTime) { |
RobMeades | 0:7ccf0e7e8a83 | 434 | if (strftime(timeString, sizeof(timeString), "%a %b %d %H:%M:%S %Y", localTime) > 0) { |
RobMeades | 0:7ccf0e7e8a83 | 435 | printf("NTP timestamp is %s.\n", timeString); |
RobMeades | 0:7ccf0e7e8a83 | 436 | } |
RobMeades | 0:7ccf0e7e8a83 | 437 | } |
RobMeades | 0:7ccf0e7e8a83 | 438 | } |
RobMeades | 0:7ccf0e7e8a83 | 439 | } |
RobMeades | 0:7ccf0e7e8a83 | 440 | |
RobMeades | 0:7ccf0e7e8a83 | 441 | // Get NTP time |
rob.meades@u-blox.com | 6:63dad754c267 | 442 | static void do_ntp(UbloxATCellularInterface *interface) |
RobMeades | 0:7ccf0e7e8a83 | 443 | { |
RobMeades | 0:7ccf0e7e8a83 | 444 | UDPSocket sock; |
RobMeades | 0:7ccf0e7e8a83 | 445 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 446 | |
rob.meades@u-blox.com | 6:63dad754c267 | 447 | TEST_ASSERT(sock.open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 448 | |
rob.meades@u-blox.com | 6:63dad754c267 | 449 | TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_NTP_SERVER, &host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 450 | host_address.set_port(MBED_CONF_APP_NTP_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 451 | |
RobMeades | 0:7ccf0e7e8a83 | 452 | tr_debug("UDP: NIST server %s address: %s on port %d.", MBED_CONF_APP_NTP_SERVER, |
RobMeades | 0:7ccf0e7e8a83 | 453 | host_address.get_ip_address(), host_address.get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 454 | |
RobMeades | 0:7ccf0e7e8a83 | 455 | sock.set_timeout(10000); |
RobMeades | 0:7ccf0e7e8a83 | 456 | |
RobMeades | 0:7ccf0e7e8a83 | 457 | do_ntp_sock(&sock, host_address); |
RobMeades | 0:7ccf0e7e8a83 | 458 | |
RobMeades | 0:7ccf0e7e8a83 | 459 | sock.close(); |
RobMeades | 0:7ccf0e7e8a83 | 460 | } |
RobMeades | 0:7ccf0e7e8a83 | 461 | |
RobMeades | 0:7ccf0e7e8a83 | 462 | // Use a connection, checking that it is good |
rob.meades@u-blox.com | 6:63dad754c267 | 463 | static void use_connection(UbloxATCellularInterface *interface) |
RobMeades | 0:7ccf0e7e8a83 | 464 | { |
rob.meades@u-blox.com | 6:63dad754c267 | 465 | const char * ip_address = interface->get_ip_address(); |
rob.meades@u-blox.com | 6:63dad754c267 | 466 | const char * net_mask = interface->get_netmask(); |
rob.meades@u-blox.com | 6:63dad754c267 | 467 | const char * gateway = interface->get_gateway(); |
RobMeades | 0:7ccf0e7e8a83 | 468 | |
rob.meades@u-blox.com | 6:63dad754c267 | 469 | TEST_ASSERT(interface->is_connected()); |
RobMeades | 0:7ccf0e7e8a83 | 470 | |
RobMeades | 0:7ccf0e7e8a83 | 471 | TEST_ASSERT(ip_address != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 472 | tr_debug ("IP address %s.", ip_address); |
RobMeades | 0:7ccf0e7e8a83 | 473 | TEST_ASSERT(net_mask == NULL); |
RobMeades | 0:7ccf0e7e8a83 | 474 | tr_debug ("Net mask %s.", net_mask); |
RobMeades | 0:7ccf0e7e8a83 | 475 | TEST_ASSERT(gateway != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 476 | tr_debug ("Gateway %s.", gateway); |
RobMeades | 0:7ccf0e7e8a83 | 477 | |
rob.meades@u-blox.com | 6:63dad754c267 | 478 | do_ntp(interface); |
RobMeades | 0:7ccf0e7e8a83 | 479 | TEST_ASSERT(!connection_has_gone_down); |
RobMeades | 0:7ccf0e7e8a83 | 480 | } |
RobMeades | 0:7ccf0e7e8a83 | 481 | |
RobMeades | 0:7ccf0e7e8a83 | 482 | // Drop a connection and check that it has dropped |
rob.meades@u-blox.com | 6:63dad754c267 | 483 | static void drop_connection(UbloxATCellularInterface *interface) |
RobMeades | 0:7ccf0e7e8a83 | 484 | { |
rob.meades@u-blox.com | 6:63dad754c267 | 485 | TEST_ASSERT(interface->disconnect() == 0); |
RobMeades | 0:7ccf0e7e8a83 | 486 | TEST_ASSERT(connection_has_gone_down); |
RobMeades | 0:7ccf0e7e8a83 | 487 | connection_has_gone_down = false; |
rob.meades@u-blox.com | 6:63dad754c267 | 488 | TEST_ASSERT(!interface->is_connected()); |
RobMeades | 0:7ccf0e7e8a83 | 489 | } |
RobMeades | 0:7ccf0e7e8a83 | 490 | |
RobMeades | 0:7ccf0e7e8a83 | 491 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 492 | // TESTS |
RobMeades | 0:7ccf0e7e8a83 | 493 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 494 | |
RobMeades | 12:ff6fac481487 | 495 | // Tests of stuff in the base class |
RobMeades | 12:ff6fac481487 | 496 | void test_base_class() { |
RobMeades | 12:ff6fac481487 | 497 | const char *imei; |
RobMeades | 12:ff6fac481487 | 498 | const char *meid; |
RobMeades | 12:ff6fac481487 | 499 | const char *imsi; |
RobMeades | 12:ff6fac481487 | 500 | const char *iccid; |
RobMeades | 12:ff6fac481487 | 501 | int rssi; |
mudassar0121 |
22:63b1a3c02fb8 | 502 | |
RobMeades | 12:ff6fac481487 | 503 | // Power-up the modem |
RobMeades | 12:ff6fac481487 | 504 | interface->init(); |
mudassar0121 |
22:63b1a3c02fb8 | 505 | |
RobMeades | 12:ff6fac481487 | 506 | // Check all of the IMEI, MEID, IMSI and ICCID calls |
RobMeades | 12:ff6fac481487 | 507 | imei = interface->imei(); |
RobMeades | 12:ff6fac481487 | 508 | if (imei != NULL) { |
RobMeades | 12:ff6fac481487 | 509 | tr_debug("IMEI is %s.", imei); |
RobMeades | 12:ff6fac481487 | 510 | } else { |
RobMeades | 12:ff6fac481487 | 511 | TEST_ASSERT(false); |
RobMeades | 12:ff6fac481487 | 512 | } |
mudassar0121 |
22:63b1a3c02fb8 | 513 | |
RobMeades | 12:ff6fac481487 | 514 | meid = interface->meid(); |
RobMeades | 12:ff6fac481487 | 515 | if (meid != NULL) { |
RobMeades | 12:ff6fac481487 | 516 | tr_debug("MEID is %s.", meid); |
RobMeades | 12:ff6fac481487 | 517 | } else { |
RobMeades | 12:ff6fac481487 | 518 | TEST_ASSERT(false); |
RobMeades | 12:ff6fac481487 | 519 | } |
mudassar0121 |
22:63b1a3c02fb8 | 520 | |
RobMeades | 12:ff6fac481487 | 521 | imsi = interface->imsi(); |
RobMeades | 12:ff6fac481487 | 522 | if (imsi != NULL) { |
RobMeades | 12:ff6fac481487 | 523 | tr_debug("IMSI is %s.", imsi); |
RobMeades | 12:ff6fac481487 | 524 | } else { |
RobMeades | 12:ff6fac481487 | 525 | TEST_ASSERT(false); |
RobMeades | 12:ff6fac481487 | 526 | } |
mudassar0121 |
22:63b1a3c02fb8 | 527 | |
RobMeades | 12:ff6fac481487 | 528 | iccid = interface->iccid(); |
RobMeades | 12:ff6fac481487 | 529 | if (iccid != NULL) { |
RobMeades | 12:ff6fac481487 | 530 | tr_debug("ICCID is %s.", iccid); |
RobMeades | 12:ff6fac481487 | 531 | } else { |
RobMeades | 12:ff6fac481487 | 532 | TEST_ASSERT(false); |
RobMeades | 12:ff6fac481487 | 533 | } |
mudassar0121 |
22:63b1a3c02fb8 | 534 | |
RobMeades | 12:ff6fac481487 | 535 | // Check the RSSI call at least doesn't assert |
RobMeades | 12:ff6fac481487 | 536 | rssi = interface->rssi(); |
RobMeades | 12:ff6fac481487 | 537 | tr_debug("RSSI is %d dBm.", rssi); |
mudassar0121 |
22:63b1a3c02fb8 | 538 | |
RobMeades | 12:ff6fac481487 | 539 | // Now connect and check that the answers for the |
RobMeades | 12:ff6fac481487 | 540 | // static fields are the same while connected |
RobMeades | 12:ff6fac481487 | 541 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
RobMeades | 12:ff6fac481487 | 542 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
mudassar0121 |
22:63b1a3c02fb8 | 543 | |
RobMeades | 12:ff6fac481487 | 544 | TEST_ASSERT(strcmp(imei, interface->imei()) == 0); |
RobMeades | 12:ff6fac481487 | 545 | TEST_ASSERT(strcmp(meid, interface->meid()) == 0); |
RobMeades | 12:ff6fac481487 | 546 | TEST_ASSERT(strcmp(imsi, interface->imsi()) == 0); |
RobMeades | 12:ff6fac481487 | 547 | TEST_ASSERT(strcmp(iccid, interface->iccid()) == 0); |
RobMeades | 12:ff6fac481487 | 548 | |
RobMeades | 12:ff6fac481487 | 549 | // Check that the RSSI call still doesn't assert |
RobMeades | 12:ff6fac481487 | 550 | rssi = interface->rssi(); |
RobMeades | 12:ff6fac481487 | 551 | tr_debug("RSSI is %d dBm.", rssi); |
RobMeades | 12:ff6fac481487 | 552 | } |
RobMeades | 12:ff6fac481487 | 553 | |
RobMeades | 0:7ccf0e7e8a83 | 554 | // Call srand() using the NTP server |
RobMeades | 0:7ccf0e7e8a83 | 555 | void test_set_randomise() { |
RobMeades | 0:7ccf0e7e8a83 | 556 | UDPSocket sock; |
RobMeades | 0:7ccf0e7e8a83 | 557 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 558 | |
rob.meades@u-blox.com | 6:63dad754c267 | 559 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 560 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 561 | do_ntp(interface); |
RobMeades | 0:7ccf0e7e8a83 | 562 | TEST_ASSERT(!connection_has_gone_down); |
rob.meades@u-blox.com | 6:63dad754c267 | 563 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 564 | } |
RobMeades | 0:7ccf0e7e8a83 | 565 | |
RobMeades | 0:7ccf0e7e8a83 | 566 | #ifdef MBED_CONF_APP_ECHO_SERVER |
RobMeades | 0:7ccf0e7e8a83 | 567 | |
RobMeades | 0:7ccf0e7e8a83 | 568 | // Test UDP data exchange |
RobMeades | 0:7ccf0e7e8a83 | 569 | void test_udp_echo() { |
RobMeades | 0:7ccf0e7e8a83 | 570 | UDPSocket sock; |
RobMeades | 0:7ccf0e7e8a83 | 571 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 572 | SocketAddress local_address; |
RobMeades | 0:7ccf0e7e8a83 | 573 | int x; |
RobMeades | 0:7ccf0e7e8a83 | 574 | int size; |
RobMeades | 0:7ccf0e7e8a83 | 575 | |
rob.meades@u-blox.com | 6:63dad754c267 | 576 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 577 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 578 | |
rob.meades@u-blox.com | 6:63dad754c267 | 579 | TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 580 | host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 581 | |
RobMeades | 0:7ccf0e7e8a83 | 582 | tr_debug("UDP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, |
RobMeades | 0:7ccf0e7e8a83 | 583 | host_address.get_ip_address(), host_address.get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 584 | |
rob.meades@u-blox.com | 6:63dad754c267 | 585 | TEST_ASSERT(sock.open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 586 | |
RobMeades | 0:7ccf0e7e8a83 | 587 | // Do a bind, just for the helluvit |
RobMeades | 0:7ccf0e7e8a83 | 588 | local_address.set_port(MBED_CONF_APP_LOCAL_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 589 | TEST_ASSERT(sock.bind(local_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 590 | |
RobMeades | 0:7ccf0e7e8a83 | 591 | sock.set_timeout(10000); |
RobMeades | 0:7ccf0e7e8a83 | 592 | |
RobMeades | 0:7ccf0e7e8a83 | 593 | // Test min, max, and some random sizes in-between |
RobMeades | 0:7ccf0e7e8a83 | 594 | do_udp_echo(&sock, &host_address, 1); |
RobMeades | 0:7ccf0e7e8a83 | 595 | do_udp_echo(&sock, &host_address, MBED_CONF_APP_UDP_MAX_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 596 | for (x = 0; x < 10; x++) { |
RobMeades | 0:7ccf0e7e8a83 | 597 | size = (rand() % MBED_CONF_APP_UDP_MAX_PACKET_SIZE) + 1; |
RobMeades | 0:7ccf0e7e8a83 | 598 | size = fix(size, MBED_CONF_APP_UDP_MAX_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 599 | do_udp_echo(&sock, &host_address, size); |
RobMeades | 0:7ccf0e7e8a83 | 600 | } |
RobMeades | 0:7ccf0e7e8a83 | 601 | |
RobMeades | 0:7ccf0e7e8a83 | 602 | sock.close(); |
rob.meades@u-blox.com | 6:63dad754c267 | 603 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 604 | tr_debug("%d UDP packets of size up to %d byte(s) echoed successfully.", |
RobMeades | 0:7ccf0e7e8a83 | 605 | x, MBED_CONF_APP_UDP_MAX_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 606 | } |
RobMeades | 0:7ccf0e7e8a83 | 607 | |
RobMeades | 0:7ccf0e7e8a83 | 608 | // Test many different sizes of UDP data arriving at once |
RobMeades | 0:7ccf0e7e8a83 | 609 | void test_udp_echo_recv_sizes() { |
RobMeades | 0:7ccf0e7e8a83 | 610 | UDPSocket sock; |
RobMeades | 0:7ccf0e7e8a83 | 611 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 612 | int x, y, z; |
RobMeades | 0:7ccf0e7e8a83 | 613 | int size; |
RobMeades | 0:7ccf0e7e8a83 | 614 | int tries = 0; |
RobMeades | 0:7ccf0e7e8a83 | 615 | unsigned int offset; |
RobMeades | 0:7ccf0e7e8a83 | 616 | char * recv_data; |
RobMeades | 0:7ccf0e7e8a83 | 617 | bool packetLoss; |
RobMeades | 0:7ccf0e7e8a83 | 618 | bool sendSuccess; |
RobMeades | 0:7ccf0e7e8a83 | 619 | Timer timer; |
RobMeades | 0:7ccf0e7e8a83 | 620 | |
rob.meades@u-blox.com | 6:63dad754c267 | 621 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 622 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 623 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 624 | |
rob.meades@u-blox.com | 6:63dad754c267 | 625 | TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 626 | host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 627 | |
RobMeades | 0:7ccf0e7e8a83 | 628 | tr_debug("UDP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, |
RobMeades | 0:7ccf0e7e8a83 | 629 | host_address.get_ip_address(), host_address.get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 630 | |
rob.meades@u-blox.com | 6:63dad754c267 | 631 | TEST_ASSERT(sock.open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 632 | |
RobMeades | 0:7ccf0e7e8a83 | 633 | do { |
RobMeades | 0:7ccf0e7e8a83 | 634 | tr_debug("--- UDP packet size test, test try %d, flushing input buffers", tries + 1); |
RobMeades | 0:7ccf0e7e8a83 | 635 | // First of all, clear any junk from the socket |
RobMeades | 0:7ccf0e7e8a83 | 636 | sock.set_timeout(1000); |
RobMeades | 0:7ccf0e7e8a83 | 637 | recv_data = (char *) malloc (MBED_CONF_APP_UDP_MAX_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 638 | TEST_ASSERT(recv_data != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 639 | while (sock.recvfrom(&host_address, (void *) recv_data, MBED_CONF_APP_UDP_MAX_PACKET_SIZE) > 0) { |
RobMeades | 0:7ccf0e7e8a83 | 640 | // Throw it away |
RobMeades | 0:7ccf0e7e8a83 | 641 | } |
RobMeades | 0:7ccf0e7e8a83 | 642 | free (recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 643 | |
RobMeades | 0:7ccf0e7e8a83 | 644 | sock.set_timeout(10000); |
RobMeades | 0:7ccf0e7e8a83 | 645 | |
RobMeades | 0:7ccf0e7e8a83 | 646 | // Throw random sized UDP packets up... |
RobMeades | 0:7ccf0e7e8a83 | 647 | x = 0; |
RobMeades | 0:7ccf0e7e8a83 | 648 | offset = 0; |
RobMeades | 0:7ccf0e7e8a83 | 649 | while (offset < sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 650 | size = (rand() % (MBED_CONF_APP_UDP_MAX_PACKET_SIZE / 2)) + 1; |
RobMeades | 0:7ccf0e7e8a83 | 651 | size = fix(size, MBED_CONF_APP_UDP_MAX_PACKET_SIZE / 2); |
RobMeades | 0:7ccf0e7e8a83 | 652 | if (offset + size > sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 653 | size = sizeof (send_data) - offset; |
RobMeades | 0:7ccf0e7e8a83 | 654 | } |
RobMeades | 0:7ccf0e7e8a83 | 655 | sendSuccess = false; |
RobMeades | 0:7ccf0e7e8a83 | 656 | for (y = 0; !sendSuccess && (y < NUM_UDP_RETRIES); y++) { |
RobMeades | 0:7ccf0e7e8a83 | 657 | tr_debug("Sending UDP packet number %d, size %d byte(s), send try %d.", x + 1, size, y + 1); |
RobMeades | 0:7ccf0e7e8a83 | 658 | if (sock.sendto(host_address, (void *) (send_data + offset), size) == size) { |
RobMeades | 0:7ccf0e7e8a83 | 659 | sendSuccess = true; |
RobMeades | 0:7ccf0e7e8a83 | 660 | offset += size; |
RobMeades | 0:7ccf0e7e8a83 | 661 | } |
RobMeades | 0:7ccf0e7e8a83 | 662 | } |
RobMeades | 0:7ccf0e7e8a83 | 663 | TEST_ASSERT(sendSuccess); |
RobMeades | 0:7ccf0e7e8a83 | 664 | x++; |
RobMeades | 0:7ccf0e7e8a83 | 665 | } |
RobMeades | 0:7ccf0e7e8a83 | 666 | tr_debug("--- All UDP packets sent"); |
RobMeades | 0:7ccf0e7e8a83 | 667 | |
RobMeades | 0:7ccf0e7e8a83 | 668 | // ...and capture them all again afterwards |
RobMeades | 0:7ccf0e7e8a83 | 669 | recv_data = (char *) malloc (sizeof (send_data)); |
RobMeades | 0:7ccf0e7e8a83 | 670 | TEST_ASSERT(recv_data != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 671 | memset (recv_data, 0, sizeof (send_data)); |
RobMeades | 0:7ccf0e7e8a83 | 672 | size = 0; |
RobMeades | 0:7ccf0e7e8a83 | 673 | y = 0; |
RobMeades | 0:7ccf0e7e8a83 | 674 | packetLoss = false; |
RobMeades | 0:7ccf0e7e8a83 | 675 | timer.start(); |
RobMeades | 0:7ccf0e7e8a83 | 676 | while ((size < (int) sizeof (send_data)) && (timer.read_ms() < 10000)) { |
RobMeades | 0:7ccf0e7e8a83 | 677 | y = sock.recvfrom(&host_address, (void *) (recv_data + size), sizeof (send_data) - size); |
RobMeades | 0:7ccf0e7e8a83 | 678 | if (y > 0) { |
RobMeades | 0:7ccf0e7e8a83 | 679 | size += y; |
RobMeades | 0:7ccf0e7e8a83 | 680 | } |
RobMeades | 0:7ccf0e7e8a83 | 681 | } |
RobMeades | 0:7ccf0e7e8a83 | 682 | timer.stop(); |
RobMeades | 0:7ccf0e7e8a83 | 683 | timer.reset(); |
RobMeades | 0:7ccf0e7e8a83 | 684 | tr_debug( "--- Either received everything back or timed out waiting"); |
RobMeades | 0:7ccf0e7e8a83 | 685 | |
RobMeades | 0:7ccf0e7e8a83 | 686 | // Check that we reassembled everything correctly |
RobMeades | 0:7ccf0e7e8a83 | 687 | if (size == sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 688 | for (x = 0; ((*(recv_data + x) == *(send_data + x))) && (x < (int) sizeof (send_data)); x++) { |
RobMeades | 0:7ccf0e7e8a83 | 689 | } |
RobMeades | 0:7ccf0e7e8a83 | 690 | if (x != sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 691 | y = x - 5; |
RobMeades | 0:7ccf0e7e8a83 | 692 | if (y < 0) { |
RobMeades | 0:7ccf0e7e8a83 | 693 | y = 0; |
RobMeades | 0:7ccf0e7e8a83 | 694 | } |
RobMeades | 0:7ccf0e7e8a83 | 695 | z = 10; |
RobMeades | 0:7ccf0e7e8a83 | 696 | if (y + z > (int) sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 697 | z = sizeof(send_data) - y; |
RobMeades | 0:7ccf0e7e8a83 | 698 | } |
RobMeades | 0:7ccf0e7e8a83 | 699 | tr_debug(" --- Difference at character %d (send \"%*.*s\", recv \"%*.*s\")", |
RobMeades | 0:7ccf0e7e8a83 | 700 | x + 1, z, z, send_data + y, z, z, recv_data + y); |
RobMeades | 0:7ccf0e7e8a83 | 701 | packetLoss = true; |
RobMeades | 0:7ccf0e7e8a83 | 702 | } |
RobMeades | 0:7ccf0e7e8a83 | 703 | } else { |
RobMeades | 0:7ccf0e7e8a83 | 704 | tr_debug(" --- %d bytes missing (%d bytes received when %d were expected))", |
RobMeades | 0:7ccf0e7e8a83 | 705 | sizeof (send_data) - size, size, sizeof (send_data)); |
RobMeades | 0:7ccf0e7e8a83 | 706 | packetLoss = true; |
RobMeades | 0:7ccf0e7e8a83 | 707 | } |
RobMeades | 0:7ccf0e7e8a83 | 708 | free (recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 709 | tries++; |
RobMeades | 0:7ccf0e7e8a83 | 710 | } while (packetLoss && (tries < NUM_UDP_RETRIES)); |
RobMeades | 0:7ccf0e7e8a83 | 711 | |
RobMeades | 0:7ccf0e7e8a83 | 712 | TEST_ASSERT(!packetLoss); |
RobMeades | 0:7ccf0e7e8a83 | 713 | TEST_ASSERT(!connection_has_gone_down); |
RobMeades | 0:7ccf0e7e8a83 | 714 | sock.close(); |
rob.meades@u-blox.com | 6:63dad754c267 | 715 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 716 | } |
RobMeades | 0:7ccf0e7e8a83 | 717 | |
RobMeades | 0:7ccf0e7e8a83 | 718 | // Test UDP data exchange via the asynchronous sigio() mechanism |
RobMeades | 0:7ccf0e7e8a83 | 719 | void test_udp_echo_async() { |
RobMeades | 0:7ccf0e7e8a83 | 720 | UDPSocket sock; |
RobMeades | 0:7ccf0e7e8a83 | 721 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 722 | SocketAddress local_address; |
RobMeades | 0:7ccf0e7e8a83 | 723 | bool callback_triggered = false; |
RobMeades | 0:7ccf0e7e8a83 | 724 | int x; |
RobMeades | 0:7ccf0e7e8a83 | 725 | int size; |
RobMeades | 0:7ccf0e7e8a83 | 726 | |
rob.meades@u-blox.com | 6:63dad754c267 | 727 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 728 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 729 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 730 | |
rob.meades@u-blox.com | 6:63dad754c267 | 731 | TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 732 | host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 733 | |
RobMeades | 0:7ccf0e7e8a83 | 734 | tr_debug("UDP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, |
RobMeades | 0:7ccf0e7e8a83 | 735 | host_address.get_ip_address(), host_address.get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 736 | |
rob.meades@u-blox.com | 6:63dad754c267 | 737 | TEST_ASSERT(sock.open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 738 | |
RobMeades | 0:7ccf0e7e8a83 | 739 | // Set up the async callback and set the timeout to zero |
RobMeades | 0:7ccf0e7e8a83 | 740 | sock.sigio(callback(async_cb, &callback_triggered)); |
RobMeades | 0:7ccf0e7e8a83 | 741 | sock.set_timeout(0); |
RobMeades | 0:7ccf0e7e8a83 | 742 | |
RobMeades | 0:7ccf0e7e8a83 | 743 | // Test min, max, and some random sizes in-between |
RobMeades | 0:7ccf0e7e8a83 | 744 | // and this time allow the UDP packets to be fragmented |
RobMeades | 0:7ccf0e7e8a83 | 745 | do_udp_echo_async(&sock, &host_address, 1, &callback_triggered); |
RobMeades | 0:7ccf0e7e8a83 | 746 | do_udp_echo_async(&sock, &host_address, MBED_CONF_APP_UDP_MAX_FRAG_PACKET_SIZE, |
RobMeades | 0:7ccf0e7e8a83 | 747 | &callback_triggered); |
RobMeades | 0:7ccf0e7e8a83 | 748 | for (x = 0; x < 10; x++) { |
RobMeades | 0:7ccf0e7e8a83 | 749 | size = (rand() % MBED_CONF_APP_UDP_MAX_FRAG_PACKET_SIZE) + 1; |
RobMeades | 0:7ccf0e7e8a83 | 750 | size = fix(size, MBED_CONF_APP_UDP_MAX_FRAG_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 751 | do_udp_echo_async(&sock, &host_address, size, &callback_triggered); |
RobMeades | 0:7ccf0e7e8a83 | 752 | } |
RobMeades | 0:7ccf0e7e8a83 | 753 | |
RobMeades | 0:7ccf0e7e8a83 | 754 | sock.close(); |
RobMeades | 0:7ccf0e7e8a83 | 755 | |
rob.meades@u-blox.com | 6:63dad754c267 | 756 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 757 | |
RobMeades | 0:7ccf0e7e8a83 | 758 | tr_debug("%d UDP packets of size up to %d byte(s) echoed asynchronously and successfully.", |
RobMeades | 0:7ccf0e7e8a83 | 759 | x, MBED_CONF_APP_UDP_MAX_FRAG_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 760 | } |
RobMeades | 0:7ccf0e7e8a83 | 761 | |
RobMeades | 0:7ccf0e7e8a83 | 762 | // Test many different sizes of TCP data arriving at once |
RobMeades | 0:7ccf0e7e8a83 | 763 | void test_tcp_echo_recv_sizes() { |
RobMeades | 0:7ccf0e7e8a83 | 764 | TCPSocket sock; |
RobMeades | 0:7ccf0e7e8a83 | 765 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 766 | int x, y, z; |
RobMeades | 0:7ccf0e7e8a83 | 767 | int size; |
RobMeades | 0:7ccf0e7e8a83 | 768 | unsigned int offset; |
RobMeades | 0:7ccf0e7e8a83 | 769 | char * recv_data; |
RobMeades | 0:7ccf0e7e8a83 | 770 | Timer timer; |
RobMeades | 0:7ccf0e7e8a83 | 771 | |
rob.meades@u-blox.com | 6:63dad754c267 | 772 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 773 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 774 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 775 | |
rob.meades@u-blox.com | 6:63dad754c267 | 776 | TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 777 | host_address.set_port(MBED_CONF_APP_ECHO_TCP_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 778 | |
RobMeades | 0:7ccf0e7e8a83 | 779 | tr_debug("TCP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, |
RobMeades | 0:7ccf0e7e8a83 | 780 | host_address.get_ip_address(), host_address.get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 781 | |
rob.meades@u-blox.com | 6:63dad754c267 | 782 | TEST_ASSERT(sock.open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 783 | |
RobMeades | 0:7ccf0e7e8a83 | 784 | TEST_ASSERT(sock.connect(host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 785 | |
RobMeades | 0:7ccf0e7e8a83 | 786 | sock.set_timeout(10000); |
RobMeades | 0:7ccf0e7e8a83 | 787 | |
RobMeades | 0:7ccf0e7e8a83 | 788 | // Throw random sized TCP packets up... |
RobMeades | 0:7ccf0e7e8a83 | 789 | x = 0; |
RobMeades | 0:7ccf0e7e8a83 | 790 | offset = 0; |
RobMeades | 0:7ccf0e7e8a83 | 791 | while (offset < sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 792 | size = (rand() % (MBED_CONF_APP_UDP_MAX_PACKET_SIZE / 2)) + 1; |
RobMeades | 0:7ccf0e7e8a83 | 793 | size = fix(size, MBED_CONF_APP_UDP_MAX_PACKET_SIZE / 2); |
RobMeades | 0:7ccf0e7e8a83 | 794 | if (offset + size > sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 795 | size = sizeof (send_data) - offset; |
RobMeades | 0:7ccf0e7e8a83 | 796 | } |
RobMeades | 0:7ccf0e7e8a83 | 797 | tr_debug("Sending TCP packet number %d, size %d byte(s).", x + 1, size); |
RobMeades | 0:7ccf0e7e8a83 | 798 | TEST_ASSERT(sendAll(&sock, (send_data + offset), size) == size); |
RobMeades | 0:7ccf0e7e8a83 | 799 | offset += size; |
RobMeades | 0:7ccf0e7e8a83 | 800 | x++; |
RobMeades | 0:7ccf0e7e8a83 | 801 | } |
RobMeades | 0:7ccf0e7e8a83 | 802 | |
RobMeades | 0:7ccf0e7e8a83 | 803 | // ...and capture them all again afterwards |
RobMeades | 0:7ccf0e7e8a83 | 804 | recv_data = (char *) malloc (sizeof (send_data)); |
RobMeades | 0:7ccf0e7e8a83 | 805 | TEST_ASSERT(recv_data != NULL); |
RobMeades | 0:7ccf0e7e8a83 | 806 | memset (recv_data, 0, sizeof (send_data)); |
RobMeades | 0:7ccf0e7e8a83 | 807 | size = 0; |
RobMeades | 0:7ccf0e7e8a83 | 808 | x = 0; |
RobMeades | 0:7ccf0e7e8a83 | 809 | timer.start(); |
RobMeades | 0:7ccf0e7e8a83 | 810 | while ((size < (int) sizeof (send_data)) && (timer.read_ms() < 30000)) { |
RobMeades | 0:7ccf0e7e8a83 | 811 | y = sock.recv((void *) (recv_data + size), sizeof (send_data) - size); |
RobMeades | 0:7ccf0e7e8a83 | 812 | tr_debug("Received TCP packet number %d, size %d byte(s).", x, y); |
RobMeades | 0:7ccf0e7e8a83 | 813 | size += y; |
RobMeades | 0:7ccf0e7e8a83 | 814 | x++; |
RobMeades | 0:7ccf0e7e8a83 | 815 | } |
RobMeades | 0:7ccf0e7e8a83 | 816 | timer.stop(); |
RobMeades | 0:7ccf0e7e8a83 | 817 | timer.reset(); |
RobMeades | 0:7ccf0e7e8a83 | 818 | |
RobMeades | 0:7ccf0e7e8a83 | 819 | // Check that we reassembled everything correctly |
RobMeades | 0:7ccf0e7e8a83 | 820 | for (x = 0; ((*(recv_data + x) == *(send_data + x))) && (x < (int) sizeof (send_data)); x++) { |
RobMeades | 0:7ccf0e7e8a83 | 821 | } |
RobMeades | 0:7ccf0e7e8a83 | 822 | if (x != sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 823 | y = x - 5; |
RobMeades | 0:7ccf0e7e8a83 | 824 | if (y < 0) { |
RobMeades | 0:7ccf0e7e8a83 | 825 | y = 0; |
RobMeades | 0:7ccf0e7e8a83 | 826 | } |
RobMeades | 0:7ccf0e7e8a83 | 827 | z = 10; |
RobMeades | 0:7ccf0e7e8a83 | 828 | if (y + z > (int) sizeof (send_data)) { |
RobMeades | 0:7ccf0e7e8a83 | 829 | z = sizeof(send_data) - y; |
RobMeades | 0:7ccf0e7e8a83 | 830 | } |
RobMeades | 0:7ccf0e7e8a83 | 831 | tr_debug("Difference at character %d (send \"%*.*s\", recv \"%*.*s\")", |
RobMeades | 0:7ccf0e7e8a83 | 832 | x + 1, z, z, send_data + y, z, z, recv_data + y); |
RobMeades | 0:7ccf0e7e8a83 | 833 | TEST_ASSERT(false); |
RobMeades | 0:7ccf0e7e8a83 | 834 | } |
RobMeades | 0:7ccf0e7e8a83 | 835 | free (recv_data); |
RobMeades | 0:7ccf0e7e8a83 | 836 | |
RobMeades | 0:7ccf0e7e8a83 | 837 | TEST_ASSERT(!connection_has_gone_down); |
RobMeades | 0:7ccf0e7e8a83 | 838 | sock.close(); |
rob.meades@u-blox.com | 6:63dad754c267 | 839 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 840 | } |
RobMeades | 0:7ccf0e7e8a83 | 841 | |
RobMeades | 0:7ccf0e7e8a83 | 842 | // Test TCP data exchange via the asynchronous sigio() mechanism |
RobMeades | 0:7ccf0e7e8a83 | 843 | void test_tcp_echo_async() { |
RobMeades | 0:7ccf0e7e8a83 | 844 | TCPSocket sock; |
RobMeades | 0:7ccf0e7e8a83 | 845 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 846 | bool callback_triggered = false; |
RobMeades | 0:7ccf0e7e8a83 | 847 | int x; |
RobMeades | 0:7ccf0e7e8a83 | 848 | int size; |
RobMeades | 0:7ccf0e7e8a83 | 849 | |
rob.meades@u-blox.com | 6:63dad754c267 | 850 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 851 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 852 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 853 | |
rob.meades@u-blox.com | 6:63dad754c267 | 854 | TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 855 | host_address.set_port(MBED_CONF_APP_ECHO_TCP_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 856 | |
RobMeades | 0:7ccf0e7e8a83 | 857 | tr_debug("TCP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, |
RobMeades | 0:7ccf0e7e8a83 | 858 | host_address.get_ip_address(), host_address.get_port()); |
RobMeades | 0:7ccf0e7e8a83 | 859 | |
rob.meades@u-blox.com | 6:63dad754c267 | 860 | TEST_ASSERT(sock.open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 861 | |
RobMeades | 0:7ccf0e7e8a83 | 862 | // Set up the async callback and set the timeout to zero |
RobMeades | 0:7ccf0e7e8a83 | 863 | sock.sigio(callback(async_cb, &callback_triggered)); |
RobMeades | 0:7ccf0e7e8a83 | 864 | sock.set_timeout(0); |
RobMeades | 0:7ccf0e7e8a83 | 865 | |
RobMeades | 0:7ccf0e7e8a83 | 866 | TEST_ASSERT(sock.connect(host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 867 | // Test min, max, and some random sizes in-between |
RobMeades | 0:7ccf0e7e8a83 | 868 | do_tcp_echo_async(&sock, 1, &callback_triggered); |
RobMeades | 0:7ccf0e7e8a83 | 869 | do_tcp_echo_async(&sock, MBED_CONF_APP_TCP_MAX_PACKET_SIZE, &callback_triggered); |
RobMeades | 0:7ccf0e7e8a83 | 870 | for (x = 0; x < 10; x++) { |
RobMeades | 0:7ccf0e7e8a83 | 871 | size = (rand() % MBED_CONF_APP_TCP_MAX_PACKET_SIZE) + 1; |
RobMeades | 0:7ccf0e7e8a83 | 872 | size = fix(size, MBED_CONF_APP_TCP_MAX_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 873 | do_tcp_echo_async(&sock, size, &callback_triggered); |
RobMeades | 0:7ccf0e7e8a83 | 874 | } |
RobMeades | 0:7ccf0e7e8a83 | 875 | |
RobMeades | 0:7ccf0e7e8a83 | 876 | sock.close(); |
RobMeades | 0:7ccf0e7e8a83 | 877 | |
rob.meades@u-blox.com | 6:63dad754c267 | 878 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 879 | |
RobMeades | 0:7ccf0e7e8a83 | 880 | tr_debug("%d TCP packets of size up to %d byte(s) echoed asynchronously and successfully.", |
RobMeades | 0:7ccf0e7e8a83 | 881 | x, MBED_CONF_APP_TCP_MAX_PACKET_SIZE); |
RobMeades | 0:7ccf0e7e8a83 | 882 | } |
RobMeades | 0:7ccf0e7e8a83 | 883 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 884 | |
RobMeades | 0:7ccf0e7e8a83 | 885 | // Allocate max sockets |
RobMeades | 0:7ccf0e7e8a83 | 886 | void test_max_sockets() { |
RobMeades | 0:7ccf0e7e8a83 | 887 | UDPSocket sock[MAX_NUM_SOCKETS]; |
RobMeades | 0:7ccf0e7e8a83 | 888 | UDPSocket sockNone; |
RobMeades | 0:7ccf0e7e8a83 | 889 | SocketAddress host_address; |
RobMeades | 0:7ccf0e7e8a83 | 890 | |
rob.meades@u-blox.com | 6:63dad754c267 | 891 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 892 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 893 | |
rob.meades@u-blox.com | 6:63dad754c267 | 894 | TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_NTP_SERVER, &host_address) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 895 | host_address.set_port(MBED_CONF_APP_NTP_PORT); |
RobMeades | 0:7ccf0e7e8a83 | 896 | |
RobMeades | 0:7ccf0e7e8a83 | 897 | // Open the first socket and use it |
rob.meades@u-blox.com | 6:63dad754c267 | 898 | TEST_ASSERT(sock[0].open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 899 | sock[0].set_timeout(10000); |
RobMeades | 0:7ccf0e7e8a83 | 900 | do_ntp_sock(&sock[0], host_address); |
RobMeades | 0:7ccf0e7e8a83 | 901 | |
RobMeades | 0:7ccf0e7e8a83 | 902 | // Check that we stop being able to get sockets at the max number |
RobMeades | 0:7ccf0e7e8a83 | 903 | for (int x = 1; x < (int) (sizeof (sock) / sizeof (sock[0])); x++) { |
rob.meades@u-blox.com | 6:63dad754c267 | 904 | TEST_ASSERT(sock[x].open(interface) == 0) |
RobMeades | 0:7ccf0e7e8a83 | 905 | } |
rob.meades@u-blox.com | 6:63dad754c267 | 906 | TEST_ASSERT(sockNone.open(interface) < 0); |
RobMeades | 0:7ccf0e7e8a83 | 907 | |
RobMeades | 0:7ccf0e7e8a83 | 908 | // Now use the last one |
RobMeades | 0:7ccf0e7e8a83 | 909 | sock[sizeof (sock) / sizeof (sock[0]) - 1].set_timeout(10000); |
RobMeades | 0:7ccf0e7e8a83 | 910 | do_ntp_sock(&sock[sizeof (sock) / sizeof (sock[0]) - 1], host_address); |
RobMeades | 0:7ccf0e7e8a83 | 911 | |
RobMeades | 0:7ccf0e7e8a83 | 912 | // Close all of the sockets |
RobMeades | 0:7ccf0e7e8a83 | 913 | for (int x = 0; x < (int) (sizeof (sock) / sizeof (sock[0])); x++) { |
RobMeades | 0:7ccf0e7e8a83 | 914 | TEST_ASSERT(sock[x].close() == 0); |
RobMeades | 0:7ccf0e7e8a83 | 915 | } |
RobMeades | 0:7ccf0e7e8a83 | 916 | |
rob.meades@u-blox.com | 6:63dad754c267 | 917 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 918 | } |
RobMeades | 0:7ccf0e7e8a83 | 919 | |
RobMeades | 0:7ccf0e7e8a83 | 920 | // Connect with credentials included in the connect request |
RobMeades | 0:7ccf0e7e8a83 | 921 | void test_connect_credentials() { |
RobMeades | 0:7ccf0e7e8a83 | 922 | |
rob.meades@u-blox.com | 6:63dad754c267 | 923 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 924 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 925 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 926 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 927 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 928 | } |
RobMeades | 0:7ccf0e7e8a83 | 929 | |
RobMeades | 0:7ccf0e7e8a83 | 930 | // Test with credentials preset |
RobMeades | 0:7ccf0e7e8a83 | 931 | void test_connect_preset_credentials() { |
RobMeades | 0:7ccf0e7e8a83 | 932 | |
rob.meades@u-blox.com | 6:63dad754c267 | 933 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 934 | TEST_ASSERT(interface->init(MBED_CONF_APP_DEFAULT_PIN)); |
rob.meades@u-blox.com | 6:63dad754c267 | 935 | interface->set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, |
rob.meades@u-blox.com | 6:63dad754c267 | 936 | MBED_CONF_APP_PASSWORD); |
rob.meades@u-blox.com | 6:63dad754c267 | 937 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 938 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 939 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 940 | } |
RobMeades | 0:7ccf0e7e8a83 | 941 | |
RobMeades | 0:7ccf0e7e8a83 | 942 | // Test adding and using a SIM pin, then removing it, using the pending |
RobMeades | 0:7ccf0e7e8a83 | 943 | // mechanism where the change doesn't occur until connect() is called |
RobMeades | 0:7ccf0e7e8a83 | 944 | void test_check_sim_pin_pending() { |
RobMeades | 0:7ccf0e7e8a83 | 945 | |
rob.meades@u-blox.com | 6:63dad754c267 | 946 | interface->deinit(); |
RobMeades | 0:7ccf0e7e8a83 | 947 | |
RobMeades | 0:7ccf0e7e8a83 | 948 | // Enable PIN checking (which will use the current PIN) |
RobMeades | 0:7ccf0e7e8a83 | 949 | // and also flag that the PIN should be changed to MBED_CONF_APP_ALT_PIN, |
RobMeades | 0:7ccf0e7e8a83 | 950 | // then try connecting |
rob.meades@u-blox.com | 6:63dad754c267 | 951 | interface->set_sim_pin_check(true); |
rob.meades@u-blox.com | 6:63dad754c267 | 952 | interface->set_new_sim_pin(MBED_CONF_APP_ALT_PIN); |
rob.meades@u-blox.com | 6:63dad754c267 | 953 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 954 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 955 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 956 | drop_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 957 | interface->deinit(); |
RobMeades | 0:7ccf0e7e8a83 | 958 | |
RobMeades | 0:7ccf0e7e8a83 | 959 | // Now change the PIN back to what it was before |
rob.meades@u-blox.com | 6:63dad754c267 | 960 | interface->set_new_sim_pin(MBED_CONF_APP_DEFAULT_PIN); |
rob.meades@u-blox.com | 6:63dad754c267 | 961 | TEST_ASSERT(interface->connect(MBED_CONF_APP_ALT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 962 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 963 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 964 | drop_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 965 | interface->deinit(); |
RobMeades | 0:7ccf0e7e8a83 | 966 | |
RobMeades | 0:7ccf0e7e8a83 | 967 | // Check that it was changed back, and this time |
RobMeades | 0:7ccf0e7e8a83 | 968 | // use the other way of entering the PIN |
rob.meades@u-blox.com | 6:63dad754c267 | 969 | interface->set_sim_pin(MBED_CONF_APP_DEFAULT_PIN); |
rob.meades@u-blox.com | 6:63dad754c267 | 970 | TEST_ASSERT(interface->connect(NULL, MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, |
rob.meades@u-blox.com | 6:63dad754c267 | 971 | MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 972 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 973 | drop_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 974 | interface->deinit(); |
RobMeades | 0:7ccf0e7e8a83 | 975 | |
RobMeades | 0:7ccf0e7e8a83 | 976 | // Remove PIN checking again and check that it no |
RobMeades | 0:7ccf0e7e8a83 | 977 | // longer matters what the PIN is |
rob.meades@u-blox.com | 6:63dad754c267 | 978 | interface->set_sim_pin_check(false); |
rob.meades@u-blox.com | 6:63dad754c267 | 979 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 980 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 981 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 982 | drop_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 983 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 984 | TEST_ASSERT(interface->init(NULL)); |
rob.meades@u-blox.com | 6:63dad754c267 | 985 | TEST_ASSERT(interface->connect(MBED_CONF_APP_INCORRECT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 986 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 987 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 988 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 989 | |
RobMeades | 0:7ccf0e7e8a83 | 990 | // Put the SIM pin back to the correct value for any subsequent tests |
rob.meades@u-blox.com | 6:63dad754c267 | 991 | interface->set_sim_pin(MBED_CONF_APP_DEFAULT_PIN); |
RobMeades | 0:7ccf0e7e8a83 | 992 | } |
RobMeades | 0:7ccf0e7e8a83 | 993 | |
RobMeades | 0:7ccf0e7e8a83 | 994 | // Test adding and using a SIM pin, then removing it, using the immediate |
RobMeades | 0:7ccf0e7e8a83 | 995 | // mechanism |
RobMeades | 0:7ccf0e7e8a83 | 996 | void test_check_sim_pin_immediate() { |
RobMeades | 0:7ccf0e7e8a83 | 997 | |
rob.meades@u-blox.com | 6:63dad754c267 | 998 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 999 | interface->connection_status_cb(connection_down_cb); |
RobMeades | 0:7ccf0e7e8a83 | 1000 | |
RobMeades | 0:7ccf0e7e8a83 | 1001 | // Enable PIN checking (which will use the current PIN), change |
RobMeades | 0:7ccf0e7e8a83 | 1002 | // the PIN to MBED_CONF_APP_ALT_PIN, then try connecting after powering on and |
RobMeades | 0:7ccf0e7e8a83 | 1003 | // off the modem |
rob.meades@u-blox.com | 6:63dad754c267 | 1004 | interface->set_sim_pin_check(true, true, MBED_CONF_APP_DEFAULT_PIN); |
rob.meades@u-blox.com | 6:63dad754c267 | 1005 | interface->set_new_sim_pin(MBED_CONF_APP_ALT_PIN, true); |
rob.meades@u-blox.com | 6:63dad754c267 | 1006 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 1007 | TEST_ASSERT(interface->init(NULL)); |
rob.meades@u-blox.com | 6:63dad754c267 | 1008 | TEST_ASSERT(interface->connect(MBED_CONF_APP_ALT_PIN, MBED_CONF_APP_APN, |
rob.meades@u-blox.com | 6:63dad754c267 | 1009 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 1010 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 1011 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 1012 | |
rob.meades@u-blox.com | 6:63dad754c267 | 1013 | interface->connection_status_cb(connection_down_cb); |
RobMeades | 0:7ccf0e7e8a83 | 1014 | |
RobMeades | 0:7ccf0e7e8a83 | 1015 | // Now change the PIN back to what it was before |
rob.meades@u-blox.com | 6:63dad754c267 | 1016 | interface->set_new_sim_pin(MBED_CONF_APP_DEFAULT_PIN, true); |
rob.meades@u-blox.com | 6:63dad754c267 | 1017 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 1018 | interface->set_sim_pin(MBED_CONF_APP_DEFAULT_PIN); |
rob.meades@u-blox.com | 6:63dad754c267 | 1019 | TEST_ASSERT(interface->init(NULL)); |
rob.meades@u-blox.com | 6:63dad754c267 | 1020 | TEST_ASSERT(interface->connect(NULL, MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, |
rob.meades@u-blox.com | 6:63dad754c267 | 1021 | MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 1022 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 1023 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 1024 | |
rob.meades@u-blox.com | 6:63dad754c267 | 1025 | interface->connection_status_cb(connection_down_cb); |
RobMeades | 0:7ccf0e7e8a83 | 1026 | |
RobMeades | 0:7ccf0e7e8a83 | 1027 | // Remove PIN checking again and check that it no |
RobMeades | 0:7ccf0e7e8a83 | 1028 | // longer matters what the PIN is |
rob.meades@u-blox.com | 6:63dad754c267 | 1029 | interface->set_sim_pin_check(false, true); |
rob.meades@u-blox.com | 6:63dad754c267 | 1030 | interface->deinit(); |
rob.meades@u-blox.com | 6:63dad754c267 | 1031 | TEST_ASSERT(interface->init(MBED_CONF_APP_INCORRECT_PIN)); |
rob.meades@u-blox.com | 6:63dad754c267 | 1032 | TEST_ASSERT(interface->connect(NULL, MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, |
rob.meades@u-blox.com | 6:63dad754c267 | 1033 | MBED_CONF_APP_PASSWORD) == 0); |
rob.meades@u-blox.com | 6:63dad754c267 | 1034 | use_connection(interface); |
rob.meades@u-blox.com | 6:63dad754c267 | 1035 | drop_connection(interface); |
RobMeades | 0:7ccf0e7e8a83 | 1036 | |
RobMeades | 0:7ccf0e7e8a83 | 1037 | // Put the SIM pin back to the correct value for any subsequent tests |
rob.meades@u-blox.com | 6:63dad754c267 | 1038 | interface->set_sim_pin(MBED_CONF_APP_DEFAULT_PIN); |
RobMeades | 0:7ccf0e7e8a83 | 1039 | } |
RobMeades | 0:7ccf0e7e8a83 | 1040 | |
rob.meades@u-blox.com | 6:63dad754c267 | 1041 | // Test being able to connect with a local instance of the interface |
RobMeades | 0:7ccf0e7e8a83 | 1042 | // NOTE: since this local instance will fiddle with bits of HW that the |
RobMeades | 0:7ccf0e7e8a83 | 1043 | // static instance thought it owned, the static instance will no longer |
RobMeades | 0:7ccf0e7e8a83 | 1044 | // work afterwards, hence this must be run as the last test in the list |
RobMeades | 0:7ccf0e7e8a83 | 1045 | void test_connect_local_instance_last_test() { |
RobMeades | 0:7ccf0e7e8a83 | 1046 | |
RobMeades | 0:7ccf0e7e8a83 | 1047 | UbloxATCellularInterface *pLocalInterface = NULL; |
RobMeades | 0:7ccf0e7e8a83 | 1048 | |
RobMeades | 0:7ccf0e7e8a83 | 1049 | pLocalInterface = new UbloxATCellularInterface(MDMTXD, MDMRXD, |
RobMeades | 0:7ccf0e7e8a83 | 1050 | MBED_CONF_UBLOX_CELL_BAUD_RATE, |
RobMeades | 0:7ccf0e7e8a83 | 1051 | MBED_CONF_APP_DEBUG_ON); |
RobMeades | 0:7ccf0e7e8a83 | 1052 | pLocalInterface->connection_status_cb(connection_down_cb); |
RobMeades | 0:7ccf0e7e8a83 | 1053 | |
RobMeades | 0:7ccf0e7e8a83 | 1054 | TEST_ASSERT(pLocalInterface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
RobMeades | 0:7ccf0e7e8a83 | 1055 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 1056 | use_connection(pLocalInterface); |
RobMeades | 0:7ccf0e7e8a83 | 1057 | drop_connection(pLocalInterface); |
RobMeades | 0:7ccf0e7e8a83 | 1058 | delete pLocalInterface; |
RobMeades | 0:7ccf0e7e8a83 | 1059 | |
RobMeades | 0:7ccf0e7e8a83 | 1060 | pLocalInterface = new UbloxATCellularInterface(MDMTXD, MDMRXD, |
RobMeades | 0:7ccf0e7e8a83 | 1061 | MBED_CONF_UBLOX_CELL_BAUD_RATE, |
RobMeades | 0:7ccf0e7e8a83 | 1062 | MBED_CONF_APP_DEBUG_ON); |
RobMeades | 0:7ccf0e7e8a83 | 1063 | pLocalInterface->connection_status_cb(connection_down_cb); |
RobMeades | 0:7ccf0e7e8a83 | 1064 | |
RobMeades | 0:7ccf0e7e8a83 | 1065 | TEST_ASSERT(pLocalInterface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
RobMeades | 0:7ccf0e7e8a83 | 1066 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:7ccf0e7e8a83 | 1067 | use_connection(pLocalInterface); |
RobMeades | 0:7ccf0e7e8a83 | 1068 | drop_connection(pLocalInterface); |
RobMeades | 0:7ccf0e7e8a83 | 1069 | delete pLocalInterface; |
RobMeades | 0:7ccf0e7e8a83 | 1070 | } |
RobMeades | 0:7ccf0e7e8a83 | 1071 | |
mudassar0121 |
22:63b1a3c02fb8 | 1072 | void test_set_new_rat() { |
mudassar0121 |
22:63b1a3c02fb8 | 1073 | |
mudassar0121 |
22:63b1a3c02fb8 | 1074 | int currentSelectedRat = -1, currentPreferredRat = -1, currentSecondPreferredRat = -1; |
mudassar0121 |
22:63b1a3c02fb8 | 1075 | |
mudassar0121 |
22:63b1a3c02fb8 | 1076 | // Power-up the modem |
mudassar0121 |
22:63b1a3c02fb8 | 1077 | TEST_ASSERT(interface->init()); |
mudassar0121 |
22:63b1a3c02fb8 | 1078 | |
mudassar0121 |
22:63b1a3c02fb8 | 1079 | // Check if modem is registered with network |
mudassar0121 |
22:63b1a3c02fb8 | 1080 | if (interface->is_registered_csd() || interface->is_registered_psd() || interface->is_registered_eps()) { |
mudassar0121 |
22:63b1a3c02fb8 | 1081 | tr_error("RAT should only be set in detached state"); |
mudassar0121 |
22:63b1a3c02fb8 | 1082 | // Deregister from Network |
mudassar0121 |
22:63b1a3c02fb8 | 1083 | TEST_ASSERT(interface->nwk_deregistration()); |
mudassar0121 |
22:63b1a3c02fb8 | 1084 | } |
mudassar0121 |
22:63b1a3c02fb8 | 1085 | |
mudassar0121 |
22:63b1a3c02fb8 | 1086 | // Get and store initial RAT set on modem |
mudassar0121 |
22:63b1a3c02fb8 | 1087 | TEST_ASSERT(interface->get_modem_rat(&previousSelectedRat, &previousPreferredRat, &previousSecondPreferredRat)); |
mudassar0121 |
22:63b1a3c02fb8 | 1088 | tr_debug("previous selected RAT: %d\nprevious preferred RAT: %d\nprevious second preferred RAT: %d\n", previousSelectedRat, previousPreferredRat, previousSecondPreferredRat); |
mudassar0121 |
22:63b1a3c02fb8 | 1089 | |
mudassar0121 |
22:63b1a3c02fb8 | 1090 | #ifdef TARGET_UBLOX_C030_U201 |
mudassar0121 |
22:63b1a3c02fb8 | 1091 | // Set new RAT |
mudassar0121 |
22:63b1a3c02fb8 | 1092 | TEST_ASSERT(interface->set_modem_rat(UbloxATCellularInterface::GSM_UMTS, UbloxATCellularInterface::UMTS)); |
mudassar0121 |
22:63b1a3c02fb8 | 1093 | tr_debug("RAT configured\n"); |
mudassar0121 |
22:63b1a3c02fb8 | 1094 | |
mudassar0121 |
22:63b1a3c02fb8 | 1095 | // Get latest set RAT on modem |
mudassar0121 |
22:63b1a3c02fb8 | 1096 | TEST_ASSERT(interface->get_modem_rat(¤tSelectedRat, ¤tPreferredRat, ¤tSecondPreferredRat)); |
mudassar0121 |
22:63b1a3c02fb8 | 1097 | tr_debug("new selected RAT: %d\nnew preferred RAT: %d\nnew second preferred RAT: %d\n", currentSelectedRat, currentPreferredRat, currentSecondPreferredRat); |
mudassar0121 |
22:63b1a3c02fb8 | 1098 | |
mudassar0121 |
22:63b1a3c02fb8 | 1099 | // Check RAT configured correctly |
mudassar0121 |
22:63b1a3c02fb8 | 1100 | TEST_ASSERT((currentSelectedRat == UbloxATCellularInterface::GSM_UMTS) && (currentPreferredRat == UbloxATCellularInterface::UMTS)); |
mudassar0121 |
22:63b1a3c02fb8 | 1101 | #endif |
mudassar0121 |
22:63b1a3c02fb8 | 1102 | |
mudassar0121 |
22:63b1a3c02fb8 | 1103 | #ifdef TARGET_UBLOX_C030_R412M |
mudassar0121 |
22:63b1a3c02fb8 | 1104 | // Set new RAT |
mudassar0121 |
22:63b1a3c02fb8 | 1105 | TEST_ASSERT(interface->set_modem_rat(UbloxATCellularInterface::LTE_CATM1, UbloxATCellularInterface::LTE_CATNB1)); |
mudassar0121 |
22:63b1a3c02fb8 | 1106 | tr_debug("RAT configured\n"); |
mudassar0121 |
22:63b1a3c02fb8 | 1107 | |
mudassar0121 |
22:63b1a3c02fb8 | 1108 | // Get latest set RAT on modem |
mudassar0121 |
22:63b1a3c02fb8 | 1109 | TEST_ASSERT(interface->get_modem_rat(¤tSelectedRat, ¤tPreferredRat, ¤tSecondPreferredRat)); |
mudassar0121 |
22:63b1a3c02fb8 | 1110 | tr_debug("new selected RAT: %d\nnew preferred RAT: %d\nnew second preferred RAT: %d\n", currentSelectedRat, currentPreferredRat, currentSecondPreferredRat); |
mudassar0121 |
22:63b1a3c02fb8 | 1111 | |
mudassar0121 |
22:63b1a3c02fb8 | 1112 | // Check RAT configured correctly |
mudassar0121 |
22:63b1a3c02fb8 | 1113 | TEST_ASSERT((currentSelectedRat == UbloxATCellularInterface::LTE_CATM1) && (currentPreferredRat == UbloxATCellularInterface::LTE_CATNB1)); |
mudassar0121 |
22:63b1a3c02fb8 | 1114 | #endif |
mudassar0121 |
22:63b1a3c02fb8 | 1115 | } |
mudassar0121 |
22:63b1a3c02fb8 | 1116 | |
mudassar0121 |
22:63b1a3c02fb8 | 1117 | void test_reboot() { |
mudassar0121 |
22:63b1a3c02fb8 | 1118 | |
mudassar0121 |
22:63b1a3c02fb8 | 1119 | // Rebooting modem for settings to take effect |
mudassar0121 |
22:63b1a3c02fb8 | 1120 | TEST_ASSERT(interface->reboot_modem()); |
mudassar0121 |
22:63b1a3c02fb8 | 1121 | } |
mudassar0121 |
22:63b1a3c02fb8 | 1122 | |
mudassar0121 |
22:63b1a3c02fb8 | 1123 | void test_registration() { |
mudassar0121 |
22:63b1a3c02fb8 | 1124 | |
mudassar0121 |
22:63b1a3c02fb8 | 1125 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
mudassar0121 |
22:63b1a3c02fb8 | 1126 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
mudassar0121 |
22:63b1a3c02fb8 | 1127 | |
mudassar0121 |
22:63b1a3c02fb8 | 1128 | TEST_ASSERT(interface->nwk_deregistration()); |
mudassar0121 |
22:63b1a3c02fb8 | 1129 | } |
mudassar0121 |
22:63b1a3c02fb8 | 1130 | |
mudassar0121 |
22:63b1a3c02fb8 | 1131 | |
mudassar0121 |
22:63b1a3c02fb8 | 1132 | void test_set_previous_rat() { |
mudassar0121 |
22:63b1a3c02fb8 | 1133 | |
mudassar0121 |
22:63b1a3c02fb8 | 1134 | int currentSelectedRat = -1, currentPreferredRat = -1, currentSecondPreferredRat = -1; |
mudassar0121 |
22:63b1a3c02fb8 | 1135 | |
mudassar0121 |
22:63b1a3c02fb8 | 1136 | // Restore RAT to previous settings |
mudassar0121 |
22:63b1a3c02fb8 | 1137 | TEST_ASSERT(interface->set_modem_rat((UbloxATCellularInterface::RAT)previousSelectedRat, (UbloxATCellularInterface::RAT)previousPreferredRat, (UbloxATCellularInterface::RAT)previousSecondPreferredRat)); |
mudassar0121 |
22:63b1a3c02fb8 | 1138 | tr_debug("RAT configured\n"); |
mudassar0121 |
22:63b1a3c02fb8 | 1139 | |
mudassar0121 |
22:63b1a3c02fb8 | 1140 | TEST_ASSERT(interface->get_modem_rat(¤tSelectedRat, ¤tPreferredRat, ¤tSecondPreferredRat)); |
mudassar0121 |
22:63b1a3c02fb8 | 1141 | tr_debug("current selected RAT: %d\ncurrent preferred RAT: %d\ncurrent second preferred RAT: %d\n", currentSelectedRat, currentPreferredRat, currentSecondPreferredRat); |
mudassar0121 |
22:63b1a3c02fb8 | 1142 | |
mudassar0121 |
22:63b1a3c02fb8 | 1143 | // Check RAT configured correctly |
mudassar0121 |
22:63b1a3c02fb8 | 1144 | TEST_ASSERT((currentSelectedRat == previousSelectedRat) && (currentPreferredRat == previousPreferredRat)); |
mudassar0121 |
22:63b1a3c02fb8 | 1145 | |
mudassar0121 |
22:63b1a3c02fb8 | 1146 | // Rebooting modem for settings to take effect |
mudassar0121 |
22:63b1a3c02fb8 | 1147 | TEST_ASSERT(interface->reboot_modem()); |
mudassar0121 |
22:63b1a3c02fb8 | 1148 | } |
mudassar0121 |
22:63b1a3c02fb8 | 1149 | |
mudassar0121 |
22:63b1a3c02fb8 | 1150 | #ifdef TARGET_UBLOX_C030_R41XM |
mudassar0121 |
22:63b1a3c02fb8 | 1151 | void test_mno_profile() { |
mudassar0121 |
22:63b1a3c02fb8 | 1152 | |
mudassar0121 |
22:63b1a3c02fb8 | 1153 | int previous_profile, current_profile; |
mudassar0121 |
22:63b1a3c02fb8 | 1154 | |
mudassar0121 |
22:63b1a3c02fb8 | 1155 | // Power-up the modem |
mudassar0121 |
22:63b1a3c02fb8 | 1156 | TEST_ASSERT(interface->init()); |
mudassar0121 |
22:63b1a3c02fb8 | 1157 | |
mudassar0121 |
22:63b1a3c02fb8 | 1158 | // Check if modem is registered with network |
mudassar0121 |
22:63b1a3c02fb8 | 1159 | if (interface->is_registered_csd() || interface->is_registered_psd() || interface->is_registered_eps()) { |
mudassar0121 |
22:63b1a3c02fb8 | 1160 | tr_error("MNO profile should only be set in detached state"); |
mudassar0121 |
22:63b1a3c02fb8 | 1161 | // Deregister from Network |
mudassar0121 |
22:63b1a3c02fb8 | 1162 | TEST_ASSERT(interface->nwk_deregistration()); |
mudassar0121 |
22:63b1a3c02fb8 | 1163 | } |
mudassar0121 |
22:63b1a3c02fb8 | 1164 | |
mudassar0121 |
22:63b1a3c02fb8 | 1165 | // Getting current mno profile |
mudassar0121 |
22:63b1a3c02fb8 | 1166 | TEST_ASSERT(interface->get_mno_profile(&previous_profile)); |
mudassar0121 |
22:63b1a3c02fb8 | 1167 | tr_debug("Previous MNO profile is: %d\n\n", previous_profile); |
mudassar0121 |
22:63b1a3c02fb8 | 1168 | |
mudassar0121 |
22:63b1a3c02fb8 | 1169 | // Set MNO profile |
mudassar0121 |
22:63b1a3c02fb8 | 1170 | TEST_ASSERT(interface->set_mno_profile((UbloxATCellularInterface::MNOProfile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE)); |
mudassar0121 |
22:63b1a3c02fb8 | 1171 | tr_debug("MNO configured\n"); |
mudassar0121 |
22:63b1a3c02fb8 | 1172 | |
mudassar0121 |
22:63b1a3c02fb8 | 1173 | // Rebooting modem for settings to take effect |
mudassar0121 |
22:63b1a3c02fb8 | 1174 | TEST_ASSERT(interface->reboot_modem()); |
mudassar0121 |
22:63b1a3c02fb8 | 1175 | tr_debug("Reboot successful\n"); |
mudassar0121 |
22:63b1a3c02fb8 | 1176 | wait_ms(5000); |
mudassar0121 |
22:63b1a3c02fb8 | 1177 | |
mudassar0121 |
22:63b1a3c02fb8 | 1178 | // Check MNO profile configured correctly |
mudassar0121 |
22:63b1a3c02fb8 | 1179 | TEST_ASSERT(interface->get_mno_profile(¤t_profile)); |
mudassar0121 |
22:63b1a3c02fb8 | 1180 | tr_debug("New MNO profile is: %d\n\n", current_profile); |
mudassar0121 |
22:63b1a3c02fb8 | 1181 | |
mudassar0121 |
22:63b1a3c02fb8 | 1182 | TEST_ASSERT((UbloxATCellularInterface::MNOProfile)current_profile == (UbloxATCellularInterface::MNOProfile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE); |
mudassar0121 |
22:63b1a3c02fb8 | 1183 | |
mudassar0121 |
22:63b1a3c02fb8 | 1184 | TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
mudassar0121 |
22:63b1a3c02fb8 | 1185 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
mudassar0121 |
22:63b1a3c02fb8 | 1186 | |
mudassar0121 |
22:63b1a3c02fb8 | 1187 | TEST_ASSERT(interface->nwk_deregistration()); |
mudassar0121 |
22:63b1a3c02fb8 | 1188 | |
mudassar0121 |
22:63b1a3c02fb8 | 1189 | // Restore MNO profile to previous settings |
mudassar0121 |
22:63b1a3c02fb8 | 1190 | TEST_ASSERT(interface->set_mno_profile((UbloxATCellularInterface::MNOProfile)previous_profile)); |
mudassar0121 |
22:63b1a3c02fb8 | 1191 | tr_debug("Previous MNO configured\n"); |
mudassar0121 |
22:63b1a3c02fb8 | 1192 | |
mudassar0121 |
22:63b1a3c02fb8 | 1193 | // Rebooting modem for settings to take effect |
mudassar0121 |
22:63b1a3c02fb8 | 1194 | TEST_ASSERT(interface->reboot_modem()); |
mudassar0121 |
22:63b1a3c02fb8 | 1195 | tr_debug("Reboot successful\n"); |
mudassar0121 |
22:63b1a3c02fb8 | 1196 | wait_ms(5000); |
mudassar0121 |
22:63b1a3c02fb8 | 1197 | |
mudassar0121 |
22:63b1a3c02fb8 | 1198 | // Check MNO profile configured correctly |
mudassar0121 |
22:63b1a3c02fb8 | 1199 | TEST_ASSERT(interface->get_mno_profile(¤t_profile)); |
mudassar0121 |
22:63b1a3c02fb8 | 1200 | TEST_ASSERT((current_profile == previous_profile)); |
mudassar0121 |
22:63b1a3c02fb8 | 1201 | } |
mudassar0121 |
22:63b1a3c02fb8 | 1202 | #endif |
mudassar0121 |
22:63b1a3c02fb8 | 1203 | |
RobMeades | 0:7ccf0e7e8a83 | 1204 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 1205 | // TEST ENVIRONMENT |
RobMeades | 0:7ccf0e7e8a83 | 1206 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 1207 | |
RobMeades | 0:7ccf0e7e8a83 | 1208 | // Setup the test environment |
RobMeades | 0:7ccf0e7e8a83 | 1209 | utest::v1::status_t test_setup(const size_t number_of_cases) { |
RobMeades | 0:7ccf0e7e8a83 | 1210 | // Setup Greentea with a timeout |
RobMeades | 0:7ccf0e7e8a83 | 1211 | GREENTEA_SETUP(960, "default_auto"); |
RobMeades | 0:7ccf0e7e8a83 | 1212 | return verbose_test_setup_handler(number_of_cases); |
RobMeades | 0:7ccf0e7e8a83 | 1213 | } |
RobMeades | 0:7ccf0e7e8a83 | 1214 | |
RobMeades | 0:7ccf0e7e8a83 | 1215 | // IMPORTANT!!! if you make a change to the tests here you should |
RobMeades | 0:7ccf0e7e8a83 | 1216 | // check whether the same change should be made to the tests under |
rob.meades@u-blox.com | 6:63dad754c267 | 1217 | // the PPP interface. |
RobMeades | 0:7ccf0e7e8a83 | 1218 | |
RobMeades | 0:7ccf0e7e8a83 | 1219 | // Test cases |
RobMeades | 0:7ccf0e7e8a83 | 1220 | Case cases[] = { |
RobMeades | 12:ff6fac481487 | 1221 | Case("Base class tests", test_base_class), |
RobMeades | 0:7ccf0e7e8a83 | 1222 | Case("Set randomise", test_set_randomise), |
RobMeades | 0:7ccf0e7e8a83 | 1223 | #ifdef MBED_CONF_APP_ECHO_SERVER |
RobMeades | 0:7ccf0e7e8a83 | 1224 | Case("UDP echo test", test_udp_echo), |
RobMeades | 0:7ccf0e7e8a83 | 1225 | # ifndef TARGET_UBLOX_C027 // Not enough RAM on little 'ole C027 to run this test |
RobMeades | 0:7ccf0e7e8a83 | 1226 | Case("UDP recv sizes", test_udp_echo_recv_sizes), |
RobMeades | 0:7ccf0e7e8a83 | 1227 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 1228 | Case("UDP async echo test", test_udp_echo_async), |
RobMeades | 0:7ccf0e7e8a83 | 1229 | # ifndef TARGET_UBLOX_C027 // Not enough RAM on little 'ole C027 to run this test |
RobMeades | 0:7ccf0e7e8a83 | 1230 | Case("TCP recv sizes", test_tcp_echo_recv_sizes), |
RobMeades | 0:7ccf0e7e8a83 | 1231 | # endif |
RobMeades | 0:7ccf0e7e8a83 | 1232 | Case("TCP async echo test", test_tcp_echo_async), |
RobMeades | 0:7ccf0e7e8a83 | 1233 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 1234 | #ifndef TARGET_UBLOX_C027 // Not enough RAM on little 'ole C027 to run this test |
RobMeades | 0:7ccf0e7e8a83 | 1235 | Case("Alloc max sockets", test_max_sockets), |
RobMeades | 0:7ccf0e7e8a83 | 1236 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 1237 | Case("Connect with credentials", test_connect_credentials), |
RobMeades | 0:7ccf0e7e8a83 | 1238 | Case("Connect with preset credentials", test_connect_preset_credentials), |
RobMeades | 0:7ccf0e7e8a83 | 1239 | #if MBED_CONF_APP_RUN_SIM_PIN_CHANGE_TESTS |
RobMeades | 0:7ccf0e7e8a83 | 1240 | Case("Check SIM pin, pending", test_check_sim_pin_pending), |
RobMeades | 0:7ccf0e7e8a83 | 1241 | Case("Check SIM pin, immediate", test_check_sim_pin_immediate), |
RobMeades | 0:7ccf0e7e8a83 | 1242 | #endif |
mudassar0121 |
22:63b1a3c02fb8 | 1243 | #if defined (TARGET_UBLOX_C030_U201) || defined (TARGET_UBLOX_C030_R412M) |
mudassar0121 |
22:63b1a3c02fb8 | 1244 | Case("Set RAT test", test_set_new_rat), |
mudassar0121 |
22:63b1a3c02fb8 | 1245 | Case("Reboot test", test_reboot), |
mudassar0121 |
22:63b1a3c02fb8 | 1246 | Case("Register with network test", test_registration), |
mudassar0121 |
22:63b1a3c02fb8 | 1247 | Case("Set previous RAT test", test_set_previous_rat), |
mudassar0121 |
22:63b1a3c02fb8 | 1248 | #endif |
mudassar0121 |
22:63b1a3c02fb8 | 1249 | #ifdef TARGET_UBLOX_C030_R41XM |
mudassar0121 |
22:63b1a3c02fb8 | 1250 | Case("MNO profile test", test_mno_profile), |
mudassar0121 |
22:63b1a3c02fb8 | 1251 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 1252 | #ifndef TARGET_UBLOX_C027 // Not enough RAM on little 'ole C027 for this |
RobMeades | 0:7ccf0e7e8a83 | 1253 | Case("Connect using local instance, must be last test", test_connect_local_instance_last_test) |
RobMeades | 0:7ccf0e7e8a83 | 1254 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 1255 | }; |
RobMeades | 0:7ccf0e7e8a83 | 1256 | |
RobMeades | 0:7ccf0e7e8a83 | 1257 | Specification specification(test_setup, cases); |
RobMeades | 0:7ccf0e7e8a83 | 1258 | |
RobMeades | 0:7ccf0e7e8a83 | 1259 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 1260 | // MAIN |
RobMeades | 0:7ccf0e7e8a83 | 1261 | // ---------------------------------------------------------------- |
RobMeades | 0:7ccf0e7e8a83 | 1262 | |
RobMeades | 0:7ccf0e7e8a83 | 1263 | int main() { |
RobMeades | 0:7ccf0e7e8a83 | 1264 | |
RobMeades | 0:7ccf0e7e8a83 | 1265 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:7ccf0e7e8a83 | 1266 | mbed_trace_init(); |
RobMeades | 0:7ccf0e7e8a83 | 1267 | |
RobMeades | 0:7ccf0e7e8a83 | 1268 | mbed_trace_mutex_wait_function_set(lock); |
RobMeades | 0:7ccf0e7e8a83 | 1269 | mbed_trace_mutex_release_function_set(unlock); |
RobMeades | 0:7ccf0e7e8a83 | 1270 | #endif |
RobMeades | 0:7ccf0e7e8a83 | 1271 | |
rob.meades@u-blox.com | 6:63dad754c267 | 1272 | interface->connection_status_cb(connection_down_cb); |
RobMeades | 0:7ccf0e7e8a83 | 1273 | |
RobMeades | 0:7ccf0e7e8a83 | 1274 | // Run tests |
RobMeades | 0:7ccf0e7e8a83 | 1275 | return !Harness::run(specification); |
RobMeades | 0:7ccf0e7e8a83 | 1276 | } |
RobMeades | 0:7ccf0e7e8a83 | 1277 | |
RobMeades | 0:7ccf0e7e8a83 | 1278 | // End Of File |