ublox-at-cellular-interface-ext
Dependencies: ublox-at-cellular-interface
TESTS/unit_tests/http/main.cpp@30:da746bc48735, 2019-10-11 (annotated)
- Committer:
- wajahat.abbas@u-blox.com
- Date:
- Fri Oct 11 15:35:03 2019 +0500
- Revision:
- 30:da746bc48735
- Parent:
- 28:4427f2e6bbab
Updated test cases for C030_R41XM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobMeades | 0:0b75e22c9231 | 1 | #include "mbed.h" |
RobMeades | 0:0b75e22c9231 | 2 | #include "greentea-client/test_env.h" |
RobMeades | 0:0b75e22c9231 | 3 | #include "unity.h" |
RobMeades | 0:0b75e22c9231 | 4 | #include "utest.h" |
RobMeades | 0:0b75e22c9231 | 5 | #include "UbloxATCellularInterfaceExt.h" |
RobMeades | 0:0b75e22c9231 | 6 | #include "UDPSocket.h" |
rob.meades@u-blox.com | 5:9fd89567f769 | 7 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:0b75e22c9231 | 8 | #include "mbed_trace.h" |
RobMeades | 0:0b75e22c9231 | 9 | #define TRACE_GROUP "TEST" |
rob.meades@u-blox.com | 5:9fd89567f769 | 10 | #else |
rob.meades@u-blox.com | 5:9fd89567f769 | 11 | #define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 5:9fd89567f769 | 12 | #define tr_info(format, ...) debug(format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 5:9fd89567f769 | 13 | #define tr_warn(format, ...) debug(format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 5:9fd89567f769 | 14 | #define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 5:9fd89567f769 | 15 | #endif |
RobMeades | 0:0b75e22c9231 | 16 | |
RobMeades | 0:0b75e22c9231 | 17 | using namespace utest::v1; |
RobMeades | 0:0b75e22c9231 | 18 | |
RobMeades | 0:0b75e22c9231 | 19 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 20 | // COMPILE-TIME MACROS |
RobMeades | 0:0b75e22c9231 | 21 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 22 | |
RobMeades | 0:0b75e22c9231 | 23 | // These macros can be overridden with an mbed_app.json file and |
RobMeades | 0:0b75e22c9231 | 24 | // contents of the following form: |
RobMeades | 0:0b75e22c9231 | 25 | // |
RobMeades | 0:0b75e22c9231 | 26 | //{ |
RobMeades | 0:0b75e22c9231 | 27 | // "config": { |
RobMeades | 0:0b75e22c9231 | 28 | // "apn": { |
RobMeades | 0:0b75e22c9231 | 29 | // "value": "\"my_apn\"" |
RobMeades | 0:0b75e22c9231 | 30 | // } |
RobMeades | 0:0b75e22c9231 | 31 | //} |
RobMeades | 0:0b75e22c9231 | 32 | |
rob.meades@u-blox.com | 11:3631f62bb359 | 33 | // Whether debug trace is on |
rob.meades@u-blox.com | 11:3631f62bb359 | 34 | #ifndef MBED_CONF_APP_DEBUG_ON |
rob.meades@u-blox.com | 11:3631f62bb359 | 35 | # define MBED_CONF_APP_DEBUG_ON false |
rob.meades@u-blox.com | 11:3631f62bb359 | 36 | #endif |
rob.meades@u-blox.com | 11:3631f62bb359 | 37 | |
RobMeades | 0:0b75e22c9231 | 38 | // The credentials of the SIM in the board. |
RobMeades | 0:0b75e22c9231 | 39 | #ifndef MBED_CONF_APP_DEFAULT_PIN |
rob.meades@u-blox.com | 11:3631f62bb359 | 40 | // Note: if PIN is enabled on your SIM, you must define the PIN |
rob.meades@u-blox.com | 11:3631f62bb359 | 41 | // for your SIM jere (e.g. using mbed_app.json to do so). |
rob.meades@u-blox.com | 11:3631f62bb359 | 42 | # define MBED_CONF_APP_DEFAULT_PIN "0000" |
RobMeades | 0:0b75e22c9231 | 43 | #endif |
RobMeades | 0:0b75e22c9231 | 44 | |
RobMeades | 0:0b75e22c9231 | 45 | // Network credentials. |
RobMeades | 0:0b75e22c9231 | 46 | #ifndef MBED_CONF_APP_APN |
RobMeades | 0:0b75e22c9231 | 47 | # define MBED_CONF_APP_APN NULL |
RobMeades | 0:0b75e22c9231 | 48 | #endif |
RobMeades | 0:0b75e22c9231 | 49 | #ifndef MBED_CONF_APP_USERNAME |
RobMeades | 0:0b75e22c9231 | 50 | # define MBED_CONF_APP_USERNAME NULL |
RobMeades | 0:0b75e22c9231 | 51 | #endif |
RobMeades | 0:0b75e22c9231 | 52 | #ifndef MBED_CONF_APP_PASSWORD |
RobMeades | 0:0b75e22c9231 | 53 | # define MBED_CONF_APP_PASSWORD NULL |
RobMeades | 0:0b75e22c9231 | 54 | #endif |
RobMeades | 0:0b75e22c9231 | 55 | |
RobMeades | 0:0b75e22c9231 | 56 | // The time to wait for a HTTP command to complete |
fahim.alavi@u-blox.com | 19:ee06f3b2b078 | 57 | #ifndef MBED_CONF_APP_HTTP_TIMEOUT |
fahim.alavi@u-blox.com | 19:ee06f3b2b078 | 58 | #define HTTP_TIMEOUT 10000 |
fahim.alavi@u-blox.com | 19:ee06f3b2b078 | 59 | #else |
fahim.alavi@u-blox.com | 19:ee06f3b2b078 | 60 | #define HTTP_TIMEOUT MBED_CONF_APP_HTTP_TIMEOUT |
fahim.alavi@u-blox.com | 19:ee06f3b2b078 | 61 | #endif |
RobMeades | 0:0b75e22c9231 | 62 | |
RobMeades | 0:0b75e22c9231 | 63 | // The HTTP echo server, as described in the |
RobMeades | 0:0b75e22c9231 | 64 | // first answer here: |
RobMeades | 0:0b75e22c9231 | 65 | // http://stackoverflow.com/questions/5725430/http-test-server-that-accepts-get-post-calls |
RobMeades | 0:0b75e22c9231 | 66 | // !!! IMPORTANT: this test relies on that server behaving in the same way forever !!! |
RobMeades | 0:0b75e22c9231 | 67 | #define HTTP_ECHO_SERVER "httpbin.org" |
RobMeades | 0:0b75e22c9231 | 68 | |
RobMeades | 0:0b75e22c9231 | 69 | // The size of the test file |
RobMeades | 0:0b75e22c9231 | 70 | #define TEST_FILE_SIZE 100 |
RobMeades | 0:0b75e22c9231 | 71 | |
RobMeades | 0:0b75e22c9231 | 72 | // The maximum number of HTTP profiles |
RobMeades | 0:0b75e22c9231 | 73 | #define MAX_PROFILES 4 |
RobMeades | 0:0b75e22c9231 | 74 | |
RobMeades | 0:0b75e22c9231 | 75 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 76 | // PRIVATE VARIABLES |
RobMeades | 0:0b75e22c9231 | 77 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 78 | |
rob.meades@u-blox.com | 5:9fd89567f769 | 79 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:0b75e22c9231 | 80 | // Lock for debug prints |
RobMeades | 0:0b75e22c9231 | 81 | static Mutex mtx; |
rob.meades@u-blox.com | 5:9fd89567f769 | 82 | #endif |
RobMeades | 0:0b75e22c9231 | 83 | |
RobMeades | 0:0b75e22c9231 | 84 | // An instance of the cellular interface |
RobMeades | 0:0b75e22c9231 | 85 | static UbloxATCellularInterfaceExt *pDriver = |
RobMeades | 0:0b75e22c9231 | 86 | new UbloxATCellularInterfaceExt(MDMTXD, MDMRXD, |
RobMeades | 0:0b75e22c9231 | 87 | MBED_CONF_UBLOX_CELL_BAUD_RATE, |
rob.meades@u-blox.com | 11:3631f62bb359 | 88 | MBED_CONF_APP_DEBUG_ON); |
RobMeades | 0:0b75e22c9231 | 89 | // A few buffers for general use |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 90 | static char buf[2048]; |
RobMeades | 0:0b75e22c9231 | 91 | static char buf1[sizeof(buf)]; |
RobMeades | 0:0b75e22c9231 | 92 | |
RobMeades | 0:0b75e22c9231 | 93 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 94 | // PRIVATE FUNCTIONS |
RobMeades | 0:0b75e22c9231 | 95 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 96 | |
rob.meades@u-blox.com | 5:9fd89567f769 | 97 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:0b75e22c9231 | 98 | // Locks for debug prints |
RobMeades | 0:0b75e22c9231 | 99 | static void lock() |
RobMeades | 0:0b75e22c9231 | 100 | { |
RobMeades | 0:0b75e22c9231 | 101 | mtx.lock(); |
RobMeades | 0:0b75e22c9231 | 102 | } |
RobMeades | 0:0b75e22c9231 | 103 | |
RobMeades | 0:0b75e22c9231 | 104 | static void unlock() |
RobMeades | 0:0b75e22c9231 | 105 | { |
RobMeades | 0:0b75e22c9231 | 106 | mtx.unlock(); |
RobMeades | 0:0b75e22c9231 | 107 | } |
rob.meades@u-blox.com | 5:9fd89567f769 | 108 | #endif |
RobMeades | 0:0b75e22c9231 | 109 | |
RobMeades | 0:0b75e22c9231 | 110 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 111 | // TESTS |
RobMeades | 0:0b75e22c9231 | 112 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 113 | |
RobMeades | 0:0b75e22c9231 | 114 | // Test HTTP commands |
RobMeades | 0:0b75e22c9231 | 115 | void test_http_cmd() { |
RobMeades | 0:0b75e22c9231 | 116 | int profile; |
RobMeades | 0:0b75e22c9231 | 117 | char * pData; |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 118 | #ifdef TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 119 | int mno_profile; |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 120 | if (pDriver->init(MBED_CONF_APP_DEFAULT_PIN) == false) //init can return false if profile set is SW_DEFAULT |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 121 | { |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 122 | TEST_ASSERT(pDriver->get_mno_profile(&mno_profile)); |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 123 | if (mno_profile == UbloxATCellularInterface::SW_DEFAULT) { |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 124 | TEST_ASSERT(pDriver->set_mno_profile(UbloxATCellularInterface::STANDARD_EU)); |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 125 | TEST_ASSERT(pDriver->reboot_modem()); |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 126 | tr_debug("Reboot successful\n"); |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 127 | wait_ms(5000); |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 128 | } |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 129 | } |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 130 | TEST_ASSERT(pDriver->init(MBED_CONF_APP_DEFAULT_PIN)); |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 131 | TEST_ASSERT(pDriver->disable_psm()); |
wajahat.abbas@u-blox.com | 30:da746bc48735 | 132 | #endif |
RobMeades | 0:0b75e22c9231 | 133 | TEST_ASSERT(pDriver->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
RobMeades | 0:0b75e22c9231 | 134 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:0b75e22c9231 | 135 | |
RobMeades | 0:0b75e22c9231 | 136 | profile = pDriver->httpAllocProfile(); |
RobMeades | 0:0b75e22c9231 | 137 | TEST_ASSERT(profile >= 0); |
RobMeades | 0:0b75e22c9231 | 138 | |
RobMeades | 0:0b75e22c9231 | 139 | pDriver->httpSetTimeout(profile, HTTP_TIMEOUT); |
RobMeades | 0:0b75e22c9231 | 140 | |
RobMeades | 0:0b75e22c9231 | 141 | // Set up the server to talk to |
RobMeades | 0:0b75e22c9231 | 142 | TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, HTTP_ECHO_SERVER)); |
RobMeades | 0:0b75e22c9231 | 143 | |
RobMeades | 0:0b75e22c9231 | 144 | // Check HTTP head request |
RobMeades | 0:0b75e22c9231 | 145 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 146 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_HEAD, |
RobMeades | 0:0b75e22c9231 | 147 | "/headers", |
RobMeades | 0:0b75e22c9231 | 148 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 149 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 150 | tr_debug("Received: %s", buf); |
RobMeades | 0:0b75e22c9231 | 151 | TEST_ASSERT(strstr(buf, "Content-Length:") != NULL); |
RobMeades | 0:0b75e22c9231 | 152 | |
RobMeades | 0:0b75e22c9231 | 153 | // Check HTTP get request |
RobMeades | 0:0b75e22c9231 | 154 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 155 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_GET, |
RobMeades | 0:0b75e22c9231 | 156 | "/get", |
RobMeades | 0:0b75e22c9231 | 157 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 158 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 159 | tr_debug("Received: %s", buf); |
SanaMasood | 20:737d307fd4d6 | 160 | TEST_ASSERT(strstr(buf, "HTTP/1.1 200 OK") != NULL); |
RobMeades | 0:0b75e22c9231 | 161 | |
RobMeades | 0:0b75e22c9231 | 162 | // Check HTTP delete request |
RobMeades | 0:0b75e22c9231 | 163 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 164 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_DELETE, |
RobMeades | 0:0b75e22c9231 | 165 | "/delete", |
RobMeades | 0:0b75e22c9231 | 166 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 167 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 168 | tr_debug("Received: %s", buf); |
SanaMasood | 20:737d307fd4d6 | 169 | TEST_ASSERT(strstr(buf, "HTTP/1.1 200 OK") != NULL); |
RobMeades | 0:0b75e22c9231 | 170 | |
RobMeades | 0:0b75e22c9231 | 171 | // Check HTTP put request (this will fail as the echo server doesn't support it) |
RobMeades | 0:0b75e22c9231 | 172 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 173 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_PUT, |
RobMeades | 0:0b75e22c9231 | 174 | "/put", |
RobMeades | 0:0b75e22c9231 | 175 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 176 | buf, sizeof (buf)) != NULL); |
RobMeades | 0:0b75e22c9231 | 177 | |
RobMeades | 0:0b75e22c9231 | 178 | // Check HTTP post request with data |
RobMeades | 0:0b75e22c9231 | 179 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 180 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_POST_DATA, |
RobMeades | 0:0b75e22c9231 | 181 | "/post", |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 182 | NULL, "formData=0123456789", 0, NULL, |
RobMeades | 0:0b75e22c9231 | 183 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 184 | tr_debug("Received: %s", buf); |
SanaMasood | 20:737d307fd4d6 | 185 | TEST_ASSERT(strstr(buf, "HTTP/1.1 200 OK") != NULL); |
RobMeades | 0:0b75e22c9231 | 186 | |
RobMeades | 0:0b75e22c9231 | 187 | // Check HTTP post request with a file, also checking that writing the response |
RobMeades | 0:0b75e22c9231 | 188 | // to a named file works |
RobMeades | 0:0b75e22c9231 | 189 | for (int x = 0; x < TEST_FILE_SIZE; x++) { |
RobMeades | 0:0b75e22c9231 | 190 | buf[x] = (x % 10) + 0x30; |
RobMeades | 0:0b75e22c9231 | 191 | } |
RobMeades | 0:0b75e22c9231 | 192 | pDriver->delFile("post_test.txt"); |
RobMeades | 0:0b75e22c9231 | 193 | TEST_ASSERT(pDriver->writeFile("post_test.txt", buf, TEST_FILE_SIZE) == TEST_FILE_SIZE); |
RobMeades | 0:0b75e22c9231 | 194 | |
RobMeades | 0:0b75e22c9231 | 195 | // This may fail if rsp.txt doesn't happen to be sitting around from a previous run |
RobMeades | 0:0b75e22c9231 | 196 | // so don't check the return value |
RobMeades | 0:0b75e22c9231 | 197 | pDriver->delFile("rsp.txt"); |
RobMeades | 0:0b75e22c9231 | 198 | |
RobMeades | 0:0b75e22c9231 | 199 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 200 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_POST_FILE, |
RobMeades | 0:0b75e22c9231 | 201 | "/post", |
RobMeades | 0:0b75e22c9231 | 202 | "rsp.txt", "post_test.txt", |
RobMeades | 0:0b75e22c9231 | 203 | UbloxATCellularInterfaceExt::HTTP_CONTENT_TEXT, NULL, |
RobMeades | 0:0b75e22c9231 | 204 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 205 | tr_debug("Received: %s", buf); |
RobMeades | 0:0b75e22c9231 | 206 | // Find the data in the response and check it |
RobMeades | 0:0b75e22c9231 | 207 | pData = strstr(buf, "\"data\": \""); |
RobMeades | 0:0b75e22c9231 | 208 | TEST_ASSERT(pData != NULL); |
RobMeades | 0:0b75e22c9231 | 209 | pData += 9; |
RobMeades | 0:0b75e22c9231 | 210 | for (int x = 0; x < TEST_FILE_SIZE; x++) { |
RobMeades | 0:0b75e22c9231 | 211 | TEST_ASSERT(*(pData + x) == (x % 10) + 0x30); |
RobMeades | 0:0b75e22c9231 | 212 | } |
RobMeades | 0:0b75e22c9231 | 213 | |
RobMeades | 0:0b75e22c9231 | 214 | // Also check that rsp.txt exists and is the same as buf |
RobMeades | 0:0b75e22c9231 | 215 | pDriver->readFile("rsp.txt", buf1, sizeof (buf1)); |
RobMeades | 0:0b75e22c9231 | 216 | memcmp(buf1, buf, sizeof (buf1)); |
RobMeades | 0:0b75e22c9231 | 217 | TEST_ASSERT(pDriver->delFile("rsp.txt")); |
RobMeades | 0:0b75e22c9231 | 218 | TEST_ASSERT(!pDriver->delFile("rsp.txt")); // Should fail |
RobMeades | 0:0b75e22c9231 | 219 | |
RobMeades | 0:0b75e22c9231 | 220 | TEST_ASSERT(pDriver->httpFreeProfile(profile)); |
RobMeades | 0:0b75e22c9231 | 221 | TEST_ASSERT(pDriver->disconnect() == 0); |
RobMeades | 0:0b75e22c9231 | 222 | // Wait for printfs to leave the building or the test result string gets messed up |
RobMeades | 0:0b75e22c9231 | 223 | wait_ms(500); |
RobMeades | 0:0b75e22c9231 | 224 | } |
RobMeades | 0:0b75e22c9231 | 225 | |
RobMeades | 0:0b75e22c9231 | 226 | // Test HTTP with TLS |
RobMeades | 0:0b75e22c9231 | 227 | void test_http_tls() { |
RobMeades | 0:0b75e22c9231 | 228 | int profile; |
RobMeades | 0:0b75e22c9231 | 229 | SocketAddress address; |
RobMeades | 0:0b75e22c9231 | 230 | |
RobMeades | 0:0b75e22c9231 | 231 | TEST_ASSERT(pDriver->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
RobMeades | 0:0b75e22c9231 | 232 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:0b75e22c9231 | 233 | |
RobMeades | 0:0b75e22c9231 | 234 | profile = pDriver->httpAllocProfile(); |
RobMeades | 0:0b75e22c9231 | 235 | TEST_ASSERT(profile >= 0); |
RobMeades | 0:0b75e22c9231 | 236 | |
RobMeades | 0:0b75e22c9231 | 237 | pDriver->httpSetTimeout(profile, HTTP_TIMEOUT); |
RobMeades | 0:0b75e22c9231 | 238 | |
RobMeades | 0:0b75e22c9231 | 239 | // Set up the server to talk to and TLS, using the IP address this time just for variety |
Bilal Qamar |
28:4427f2e6bbab | 240 | TEST_ASSERT(pDriver->gethostbyname("www.amazon.com", &address) == 0); |
RobMeades | 0:0b75e22c9231 | 241 | TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_IP_ADDRESS, address.get_ip_address())); |
RobMeades | 0:0b75e22c9231 | 242 | TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_SECURE, "1")); |
Bilal Qamar |
28:4427f2e6bbab | 243 | TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_REQ_HEADER, "0:Host:www.amazon.com")); |
RobMeades | 0:0b75e22c9231 | 244 | |
RobMeades | 0:0b75e22c9231 | 245 | // Check HTTP get request |
RobMeades | 0:0b75e22c9231 | 246 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 247 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_GET, |
RobMeades | 0:0b75e22c9231 | 248 | "/", |
RobMeades | 0:0b75e22c9231 | 249 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 250 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 251 | tr_debug("Received: %s", buf); |
RobMeades | 0:0b75e22c9231 | 252 | // This is what amazon.com returns if TLS is set |
Bilal Qamar |
28:4427f2e6bbab | 253 | TEST_ASSERT(strstr(buf, "HTTP/1.1 200 OK") != NULL); |
RobMeades | 0:0b75e22c9231 | 254 | |
RobMeades | 0:0b75e22c9231 | 255 | // Reset the profile and check that this now fails |
RobMeades | 0:0b75e22c9231 | 256 | TEST_ASSERT(pDriver->httpResetProfile(profile)); |
RobMeades | 0:0b75e22c9231 | 257 | TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_IP_ADDRESS, address.get_ip_address())); |
RobMeades | 0:0b75e22c9231 | 258 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 259 | TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_GET, |
RobMeades | 0:0b75e22c9231 | 260 | "/", |
RobMeades | 0:0b75e22c9231 | 261 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 262 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 263 | tr_debug("Received: %s", buf); |
RobMeades | 0:0b75e22c9231 | 264 | // This is what amazon.com returns if TLS is NOT set |
Bilal Qamar |
28:4427f2e6bbab | 265 | TEST_ASSERT(strstr(buf, "HTTP/1.1 403 Forbidden") != NULL); |
RobMeades | 0:0b75e22c9231 | 266 | |
RobMeades | 0:0b75e22c9231 | 267 | TEST_ASSERT(pDriver->httpFreeProfile(profile)); |
RobMeades | 0:0b75e22c9231 | 268 | TEST_ASSERT(pDriver->disconnect() == 0); |
RobMeades | 0:0b75e22c9231 | 269 | // Wait for printfs to leave the building or the test result string gets messed up |
RobMeades | 0:0b75e22c9231 | 270 | wait_ms(500); |
RobMeades | 0:0b75e22c9231 | 271 | } |
RobMeades | 0:0b75e22c9231 | 272 | |
RobMeades | 0:0b75e22c9231 | 273 | // Allocate max profiles |
RobMeades | 0:0b75e22c9231 | 274 | void test_alloc_profiles() { |
RobMeades | 0:0b75e22c9231 | 275 | int profiles[MAX_PROFILES]; |
RobMeades | 0:0b75e22c9231 | 276 | |
RobMeades | 0:0b75e22c9231 | 277 | TEST_ASSERT(pDriver->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN, |
RobMeades | 0:0b75e22c9231 | 278 | MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0); |
RobMeades | 0:0b75e22c9231 | 279 | |
RobMeades | 0:0b75e22c9231 | 280 | // Allocate first profile and use it |
RobMeades | 0:0b75e22c9231 | 281 | profiles[0] = pDriver->httpAllocProfile(); |
RobMeades | 0:0b75e22c9231 | 282 | TEST_ASSERT(profiles[0] >= 0); |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 283 | TEST_ASSERT(pDriver->httpSetPar(profiles[0], UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, "raw.githubusercontent.com")); |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 284 | TEST_ASSERT(pDriver->httpSetPar(profiles[0], UbloxATCellularInterfaceExt::HTTP_SECURE, "1")); |
RobMeades | 0:0b75e22c9231 | 285 | |
RobMeades | 0:0b75e22c9231 | 286 | // Check HTTP get request |
RobMeades | 0:0b75e22c9231 | 287 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 288 | TEST_ASSERT(pDriver->httpCommand(profiles[0], UbloxATCellularInterfaceExt::HTTP_GET, |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 289 | "/u-blox/mbed-os/master/features/cellular/mbed_lib.json", |
RobMeades | 0:0b75e22c9231 | 290 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 291 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 292 | tr_debug("Received: %s", buf); |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 293 | TEST_ASSERT(strstr(buf, "Radio access technology to use. Value in integer: GSM=0, GSM_COMPACT=1, UTRAN=2, EGPRS=3, HSDPA=4, HSUPA=5, HSDPA_HSUPA=6, E_UTRAN=7, CATM1=8 ,NB1=9") != NULL); |
RobMeades | 0:0b75e22c9231 | 294 | |
RobMeades | 0:0b75e22c9231 | 295 | // Check that we stop being able to get profiles at the max number |
RobMeades | 0:0b75e22c9231 | 296 | for (int x = 1; x < sizeof (profiles) / sizeof (profiles[0]); x++) { |
RobMeades | 0:0b75e22c9231 | 297 | profiles[x] = pDriver->httpAllocProfile(); |
RobMeades | 0:0b75e22c9231 | 298 | TEST_ASSERT(profiles[0] >= 0); |
RobMeades | 0:0b75e22c9231 | 299 | } |
RobMeades | 0:0b75e22c9231 | 300 | TEST_ASSERT(pDriver->httpAllocProfile() < 0); |
RobMeades | 0:0b75e22c9231 | 301 | |
RobMeades | 0:0b75e22c9231 | 302 | // Now use the last one and check that it doesn't affect the first one |
RobMeades | 0:0b75e22c9231 | 303 | TEST_ASSERT(pDriver->httpSetPar(profiles[sizeof (profiles) / sizeof (profiles[0]) - 1], |
RobMeades | 0:0b75e22c9231 | 304 | UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, HTTP_ECHO_SERVER)); |
RobMeades | 0:0b75e22c9231 | 305 | |
RobMeades | 0:0b75e22c9231 | 306 | // Check HTTP head request on last profile |
RobMeades | 0:0b75e22c9231 | 307 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 308 | TEST_ASSERT(pDriver->httpCommand(profiles[sizeof (profiles) / sizeof (profiles[0]) - 1], |
RobMeades | 0:0b75e22c9231 | 309 | UbloxATCellularInterfaceExt::HTTP_HEAD, |
RobMeades | 0:0b75e22c9231 | 310 | "/headers", |
RobMeades | 0:0b75e22c9231 | 311 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 312 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 313 | tr_debug("Received: %s", buf); |
RobMeades | 0:0b75e22c9231 | 314 | TEST_ASSERT(strstr(buf, "Content-Length:") != NULL); |
RobMeades | 0:0b75e22c9231 | 315 | |
RobMeades | 0:0b75e22c9231 | 316 | // Check HTTP get request on first profile once more |
RobMeades | 0:0b75e22c9231 | 317 | memset(buf, 0, sizeof (buf)); |
RobMeades | 0:0b75e22c9231 | 318 | TEST_ASSERT(pDriver->httpCommand(profiles[0], UbloxATCellularInterfaceExt::HTTP_GET, |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 319 | "/u-blox/mbed-os/master/features/cellular/mbed_lib.json", |
RobMeades | 0:0b75e22c9231 | 320 | NULL, NULL, 0, NULL, |
RobMeades | 0:0b75e22c9231 | 321 | buf, sizeof (buf)) == NULL); |
RobMeades | 0:0b75e22c9231 | 322 | tr_debug("Received: %s", buf); |
fahim.alavi@u-blox.com | 18:071ae6c6e581 | 323 | TEST_ASSERT(strstr(buf, "Radio access technology to use. Value in integer: GSM=0, GSM_COMPACT=1, UTRAN=2, EGPRS=3, HSDPA=4, HSUPA=5, HSDPA_HSUPA=6, E_UTRAN=7, CATM1=8 ,NB1=9") != NULL); |
RobMeades | 0:0b75e22c9231 | 324 | |
RobMeades | 0:0b75e22c9231 | 325 | // Free the profiles again |
RobMeades | 0:0b75e22c9231 | 326 | for (int x = 0; x < sizeof (profiles) / sizeof (profiles[0]); x++) { |
RobMeades | 0:0b75e22c9231 | 327 | TEST_ASSERT(pDriver->httpFreeProfile(profiles[x])); |
RobMeades | 0:0b75e22c9231 | 328 | } |
RobMeades | 0:0b75e22c9231 | 329 | |
RobMeades | 0:0b75e22c9231 | 330 | TEST_ASSERT(pDriver->disconnect() == 0); |
RobMeades | 0:0b75e22c9231 | 331 | // Wait for printfs to leave the building or the test result string gets messed up |
RobMeades | 0:0b75e22c9231 | 332 | wait_ms(500); |
RobMeades | 0:0b75e22c9231 | 333 | } |
RobMeades | 0:0b75e22c9231 | 334 | |
RobMeades | 0:0b75e22c9231 | 335 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 336 | // TEST ENVIRONMENT |
RobMeades | 0:0b75e22c9231 | 337 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 338 | |
RobMeades | 0:0b75e22c9231 | 339 | // Setup the test environment |
RobMeades | 0:0b75e22c9231 | 340 | utest::v1::status_t test_setup(const size_t number_of_cases) { |
RobMeades | 0:0b75e22c9231 | 341 | // Setup Greentea with a timeout |
RobMeades | 0:0b75e22c9231 | 342 | GREENTEA_SETUP(540, "default_auto"); |
RobMeades | 0:0b75e22c9231 | 343 | return verbose_test_setup_handler(number_of_cases); |
RobMeades | 0:0b75e22c9231 | 344 | } |
RobMeades | 0:0b75e22c9231 | 345 | |
RobMeades | 0:0b75e22c9231 | 346 | // Test cases |
RobMeades | 0:0b75e22c9231 | 347 | Case cases[] = { |
RobMeades | 0:0b75e22c9231 | 348 | Case("HTTP commands", test_http_cmd), |
rob.meades@u-blox.com | 11:3631f62bb359 | 349 | #ifndef TARGET_UBLOX_C027 |
rob.meades@u-blox.com | 11:3631f62bb359 | 350 | // C027 doesn't support TLS |
RobMeades | 0:0b75e22c9231 | 351 | Case("HTTP with TLS", test_http_tls), |
rob.meades@u-blox.com | 11:3631f62bb359 | 352 | #endif |
RobMeades | 0:0b75e22c9231 | 353 | Case("Alloc max profiles", test_alloc_profiles) |
RobMeades | 0:0b75e22c9231 | 354 | }; |
RobMeades | 0:0b75e22c9231 | 355 | |
RobMeades | 0:0b75e22c9231 | 356 | Specification specification(test_setup, cases); |
RobMeades | 0:0b75e22c9231 | 357 | |
RobMeades | 0:0b75e22c9231 | 358 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 359 | // MAIN |
RobMeades | 0:0b75e22c9231 | 360 | // ---------------------------------------------------------------- |
RobMeades | 0:0b75e22c9231 | 361 | |
RobMeades | 0:0b75e22c9231 | 362 | int main() { |
rob.meades@u-blox.com | 5:9fd89567f769 | 363 | |
rob.meades@u-blox.com | 5:9fd89567f769 | 364 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:0b75e22c9231 | 365 | mbed_trace_init(); |
RobMeades | 0:0b75e22c9231 | 366 | |
RobMeades | 0:0b75e22c9231 | 367 | mbed_trace_mutex_wait_function_set(lock); |
RobMeades | 0:0b75e22c9231 | 368 | mbed_trace_mutex_release_function_set(unlock); |
rob.meades@u-blox.com | 5:9fd89567f769 | 369 | #endif |
RobMeades | 0:0b75e22c9231 | 370 | |
RobMeades | 0:0b75e22c9231 | 371 | // Run tests |
RobMeades | 0:0b75e22c9231 | 372 | return !Harness::run(specification); |
RobMeades | 0:0b75e22c9231 | 373 | } |
RobMeades | 0:0b75e22c9231 | 374 | |
RobMeades | 0:0b75e22c9231 | 375 | // End Of File |
RobMeades | 0:0b75e22c9231 | 376 |