wifi test
Dependencies: X_NUCLEO_IKS01A2 mbed-http
easy-connect/wizfi310-driver/TESTS/net/udp_packet_pressure_parallel/main.cpp@0:24d3eb812fd4, 2018-09-05 (annotated)
- Committer:
- JMF
- Date:
- Wed Sep 05 14:28:24 2018 +0000
- Revision:
- 0:24d3eb812fd4
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JMF | 0:24d3eb812fd4 | 1 | #ifndef MBED_EXTENDED_TESTS |
| JMF | 0:24d3eb812fd4 | 2 | #error [NOT_SUPPORTED] Parallel pressure tests are not supported by default |
| JMF | 0:24d3eb812fd4 | 3 | #endif |
| JMF | 0:24d3eb812fd4 | 4 | |
| JMF | 0:24d3eb812fd4 | 5 | #include "mbed.h" |
| JMF | 0:24d3eb812fd4 | 6 | #include "ESP8266Interface.h" |
| JMF | 0:24d3eb812fd4 | 7 | #include "UDPSocket.h" |
| JMF | 0:24d3eb812fd4 | 8 | #include "greentea-client/test_env.h" |
| JMF | 0:24d3eb812fd4 | 9 | #include "unity/unity.h" |
| JMF | 0:24d3eb812fd4 | 10 | #include "utest.h" |
| JMF | 0:24d3eb812fd4 | 11 | |
| JMF | 0:24d3eb812fd4 | 12 | using namespace utest::v1; |
| JMF | 0:24d3eb812fd4 | 13 | |
| JMF | 0:24d3eb812fd4 | 14 | |
| JMF | 0:24d3eb812fd4 | 15 | #ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN |
| JMF | 0:24d3eb812fd4 | 16 | #define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN 64 |
| JMF | 0:24d3eb812fd4 | 17 | #endif |
| JMF | 0:24d3eb812fd4 | 18 | |
| JMF | 0:24d3eb812fd4 | 19 | #ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX |
| JMF | 0:24d3eb812fd4 | 20 | #define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX 0x80000 |
| JMF | 0:24d3eb812fd4 | 21 | #endif |
| JMF | 0:24d3eb812fd4 | 22 | |
| JMF | 0:24d3eb812fd4 | 23 | #ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_TIMEOUT |
| JMF | 0:24d3eb812fd4 | 24 | #define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_TIMEOUT 100 |
| JMF | 0:24d3eb812fd4 | 25 | #endif |
| JMF | 0:24d3eb812fd4 | 26 | |
| JMF | 0:24d3eb812fd4 | 27 | #ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_SEED |
| JMF | 0:24d3eb812fd4 | 28 | #define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_SEED 0x6d626564 |
| JMF | 0:24d3eb812fd4 | 29 | #endif |
| JMF | 0:24d3eb812fd4 | 30 | |
| JMF | 0:24d3eb812fd4 | 31 | #ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS |
| JMF | 0:24d3eb812fd4 | 32 | #define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS 3 |
| JMF | 0:24d3eb812fd4 | 33 | #endif |
| JMF | 0:24d3eb812fd4 | 34 | |
| JMF | 0:24d3eb812fd4 | 35 | #ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG |
| JMF | 0:24d3eb812fd4 | 36 | #define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG false |
| JMF | 0:24d3eb812fd4 | 37 | #endif |
| JMF | 0:24d3eb812fd4 | 38 | |
| JMF | 0:24d3eb812fd4 | 39 | #ifndef MBED_CFG_ESP8266_TX |
| JMF | 0:24d3eb812fd4 | 40 | #define MBED_CFG_ESP8266_TX D1 |
| JMF | 0:24d3eb812fd4 | 41 | #endif |
| JMF | 0:24d3eb812fd4 | 42 | |
| JMF | 0:24d3eb812fd4 | 43 | #ifndef MBED_CFG_ESP8266_RX |
| JMF | 0:24d3eb812fd4 | 44 | #define MBED_CFG_ESP8266_RX D0 |
| JMF | 0:24d3eb812fd4 | 45 | #endif |
| JMF | 0:24d3eb812fd4 | 46 | |
| JMF | 0:24d3eb812fd4 | 47 | #ifndef MBED_CFG_ESP8266_DEBUG |
| JMF | 0:24d3eb812fd4 | 48 | #define MBED_CFG_ESP8266_DEBUG false |
| JMF | 0:24d3eb812fd4 | 49 | #endif |
| JMF | 0:24d3eb812fd4 | 50 | |
| JMF | 0:24d3eb812fd4 | 51 | #define STRINGIZE(x) STRINGIZE2(x) |
| JMF | 0:24d3eb812fd4 | 52 | #define STRINGIZE2(x) #x |
| JMF | 0:24d3eb812fd4 | 53 | |
| JMF | 0:24d3eb812fd4 | 54 | |
| JMF | 0:24d3eb812fd4 | 55 | // Simple xorshift pseudorandom number generator |
| JMF | 0:24d3eb812fd4 | 56 | class RandSeq { |
| JMF | 0:24d3eb812fd4 | 57 | private: |
| JMF | 0:24d3eb812fd4 | 58 | uint32_t x; |
| JMF | 0:24d3eb812fd4 | 59 | uint32_t y; |
| JMF | 0:24d3eb812fd4 | 60 | static const int A = 15; |
| JMF | 0:24d3eb812fd4 | 61 | static const int B = 18; |
| JMF | 0:24d3eb812fd4 | 62 | static const int C = 11; |
| JMF | 0:24d3eb812fd4 | 63 | |
| JMF | 0:24d3eb812fd4 | 64 | public: |
| JMF | 0:24d3eb812fd4 | 65 | RandSeq(uint32_t seed=MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_SEED) |
| JMF | 0:24d3eb812fd4 | 66 | : x(seed), y(seed) {} |
| JMF | 0:24d3eb812fd4 | 67 | |
| JMF | 0:24d3eb812fd4 | 68 | uint32_t next(void) { |
| JMF | 0:24d3eb812fd4 | 69 | x ^= x << A; |
| JMF | 0:24d3eb812fd4 | 70 | x ^= x >> B; |
| JMF | 0:24d3eb812fd4 | 71 | x ^= y ^ (y >> C); |
| JMF | 0:24d3eb812fd4 | 72 | return x + y; |
| JMF | 0:24d3eb812fd4 | 73 | } |
| JMF | 0:24d3eb812fd4 | 74 | |
| JMF | 0:24d3eb812fd4 | 75 | void skip(size_t size) { |
| JMF | 0:24d3eb812fd4 | 76 | for (size_t i = 0; i < size; i++) { |
| JMF | 0:24d3eb812fd4 | 77 | next(); |
| JMF | 0:24d3eb812fd4 | 78 | } |
| JMF | 0:24d3eb812fd4 | 79 | } |
| JMF | 0:24d3eb812fd4 | 80 | |
| JMF | 0:24d3eb812fd4 | 81 | void buffer(uint8_t *buffer, size_t size) { |
| JMF | 0:24d3eb812fd4 | 82 | RandSeq lookahead = *this; |
| JMF | 0:24d3eb812fd4 | 83 | |
| JMF | 0:24d3eb812fd4 | 84 | for (size_t i = 0; i < size; i++) { |
| JMF | 0:24d3eb812fd4 | 85 | buffer[i] = lookahead.next() & 0xff; |
| JMF | 0:24d3eb812fd4 | 86 | } |
| JMF | 0:24d3eb812fd4 | 87 | } |
| JMF | 0:24d3eb812fd4 | 88 | |
| JMF | 0:24d3eb812fd4 | 89 | int cmp(uint8_t *buffer, size_t size) { |
| JMF | 0:24d3eb812fd4 | 90 | RandSeq lookahead = *this; |
| JMF | 0:24d3eb812fd4 | 91 | |
| JMF | 0:24d3eb812fd4 | 92 | for (size_t i = 0; i < size; i++) { |
| JMF | 0:24d3eb812fd4 | 93 | int diff = buffer[i] - (lookahead.next() & 0xff); |
| JMF | 0:24d3eb812fd4 | 94 | if (diff != 0) { |
| JMF | 0:24d3eb812fd4 | 95 | return diff; |
| JMF | 0:24d3eb812fd4 | 96 | } |
| JMF | 0:24d3eb812fd4 | 97 | } |
| JMF | 0:24d3eb812fd4 | 98 | return 0; |
| JMF | 0:24d3eb812fd4 | 99 | } |
| JMF | 0:24d3eb812fd4 | 100 | }; |
| JMF | 0:24d3eb812fd4 | 101 | |
| JMF | 0:24d3eb812fd4 | 102 | // Tries to get the biggest buffer possible on the device. Exponentially |
| JMF | 0:24d3eb812fd4 | 103 | // grows a buffer until heap runs out of space, and uses half to leave |
| JMF | 0:24d3eb812fd4 | 104 | // space for the rest of the program |
| JMF | 0:24d3eb812fd4 | 105 | void generate_buffer(uint8_t **buffer, size_t *size, size_t min, size_t max) { |
| JMF | 0:24d3eb812fd4 | 106 | size_t i = min; |
| JMF | 0:24d3eb812fd4 | 107 | while (i < max) { |
| JMF | 0:24d3eb812fd4 | 108 | void *b = malloc(i); |
| JMF | 0:24d3eb812fd4 | 109 | if (!b) { |
| JMF | 0:24d3eb812fd4 | 110 | i /= 8; |
| JMF | 0:24d3eb812fd4 | 111 | if (i < min) { |
| JMF | 0:24d3eb812fd4 | 112 | i = min; |
| JMF | 0:24d3eb812fd4 | 113 | } |
| JMF | 0:24d3eb812fd4 | 114 | break; |
| JMF | 0:24d3eb812fd4 | 115 | } |
| JMF | 0:24d3eb812fd4 | 116 | free(b); |
| JMF | 0:24d3eb812fd4 | 117 | i *= 2; |
| JMF | 0:24d3eb812fd4 | 118 | } |
| JMF | 0:24d3eb812fd4 | 119 | |
| JMF | 0:24d3eb812fd4 | 120 | *buffer = (uint8_t *)malloc(i); |
| JMF | 0:24d3eb812fd4 | 121 | *size = i; |
| JMF | 0:24d3eb812fd4 | 122 | TEST_ASSERT(buffer); |
| JMF | 0:24d3eb812fd4 | 123 | } |
| JMF | 0:24d3eb812fd4 | 124 | |
| JMF | 0:24d3eb812fd4 | 125 | |
| JMF | 0:24d3eb812fd4 | 126 | // Global variables shared between pressure tests |
| JMF | 0:24d3eb812fd4 | 127 | ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG); |
| JMF | 0:24d3eb812fd4 | 128 | SocketAddress udp_addr; |
| JMF | 0:24d3eb812fd4 | 129 | Timer timer; |
| JMF | 0:24d3eb812fd4 | 130 | Mutex iomutex; |
| JMF | 0:24d3eb812fd4 | 131 | |
| JMF | 0:24d3eb812fd4 | 132 | // Single instance of a pressure test |
| JMF | 0:24d3eb812fd4 | 133 | class PressureTest { |
| JMF | 0:24d3eb812fd4 | 134 | private: |
| JMF | 0:24d3eb812fd4 | 135 | uint8_t *buffer; |
| JMF | 0:24d3eb812fd4 | 136 | size_t buffer_size; |
| JMF | 0:24d3eb812fd4 | 137 | |
| JMF | 0:24d3eb812fd4 | 138 | UDPSocket sock; |
| JMF | 0:24d3eb812fd4 | 139 | Thread thread; |
| JMF | 0:24d3eb812fd4 | 140 | |
| JMF | 0:24d3eb812fd4 | 141 | public: |
| JMF | 0:24d3eb812fd4 | 142 | PressureTest(uint8_t *buffer, size_t buffer_size) |
| JMF | 0:24d3eb812fd4 | 143 | : buffer(buffer), buffer_size(buffer_size) { |
| JMF | 0:24d3eb812fd4 | 144 | } |
| JMF | 0:24d3eb812fd4 | 145 | |
| JMF | 0:24d3eb812fd4 | 146 | void start() { |
| JMF | 0:24d3eb812fd4 | 147 | osStatus status = thread.start(callback(this, &PressureTest::run)); |
| JMF | 0:24d3eb812fd4 | 148 | TEST_ASSERT_EQUAL(osOK, status); |
| JMF | 0:24d3eb812fd4 | 149 | } |
| JMF | 0:24d3eb812fd4 | 150 | |
| JMF | 0:24d3eb812fd4 | 151 | void join() { |
| JMF | 0:24d3eb812fd4 | 152 | osStatus status = thread.join(); |
| JMF | 0:24d3eb812fd4 | 153 | TEST_ASSERT_EQUAL(osOK, status); |
| JMF | 0:24d3eb812fd4 | 154 | } |
| JMF | 0:24d3eb812fd4 | 155 | |
| JMF | 0:24d3eb812fd4 | 156 | void run() { |
| JMF | 0:24d3eb812fd4 | 157 | // Tests exponentially growing sequences |
| JMF | 0:24d3eb812fd4 | 158 | for (size_t size = MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN; |
| JMF | 0:24d3eb812fd4 | 159 | size < MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX; |
| JMF | 0:24d3eb812fd4 | 160 | size *= 2) { |
| JMF | 0:24d3eb812fd4 | 161 | int err = sock.open(&net); |
| JMF | 0:24d3eb812fd4 | 162 | TEST_ASSERT_EQUAL(0, err); |
| JMF | 0:24d3eb812fd4 | 163 | iomutex.lock(); |
| JMF | 0:24d3eb812fd4 | 164 | printf("UDP: %s:%d streaming %d bytes\r\n", |
| JMF | 0:24d3eb812fd4 | 165 | udp_addr.get_ip_address(), udp_addr.get_port(), size); |
| JMF | 0:24d3eb812fd4 | 166 | iomutex.unlock(); |
| JMF | 0:24d3eb812fd4 | 167 | |
| JMF | 0:24d3eb812fd4 | 168 | sock.set_blocking(false); |
| JMF | 0:24d3eb812fd4 | 169 | |
| JMF | 0:24d3eb812fd4 | 170 | // Loop to send/recv all data |
| JMF | 0:24d3eb812fd4 | 171 | RandSeq tx_seq; |
| JMF | 0:24d3eb812fd4 | 172 | RandSeq rx_seq; |
| JMF | 0:24d3eb812fd4 | 173 | size_t rx_count = 0; |
| JMF | 0:24d3eb812fd4 | 174 | size_t tx_count = 0; |
| JMF | 0:24d3eb812fd4 | 175 | int known_time = timer.read_ms(); |
| JMF | 0:24d3eb812fd4 | 176 | size_t window = buffer_size; |
| JMF | 0:24d3eb812fd4 | 177 | |
| JMF | 0:24d3eb812fd4 | 178 | while (tx_count < size || rx_count < size) { |
| JMF | 0:24d3eb812fd4 | 179 | // Send out packets |
| JMF | 0:24d3eb812fd4 | 180 | if (tx_count < size) { |
| JMF | 0:24d3eb812fd4 | 181 | size_t chunk_size = size - tx_count; |
| JMF | 0:24d3eb812fd4 | 182 | if (chunk_size > window) { |
| JMF | 0:24d3eb812fd4 | 183 | chunk_size = window; |
| JMF | 0:24d3eb812fd4 | 184 | } |
| JMF | 0:24d3eb812fd4 | 185 | |
| JMF | 0:24d3eb812fd4 | 186 | tx_seq.buffer(buffer, chunk_size); |
| JMF | 0:24d3eb812fd4 | 187 | int td = sock.sendto(udp_addr, buffer, chunk_size); |
| JMF | 0:24d3eb812fd4 | 188 | |
| JMF | 0:24d3eb812fd4 | 189 | if (td > 0) { |
| JMF | 0:24d3eb812fd4 | 190 | if (MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG) { |
| JMF | 0:24d3eb812fd4 | 191 | iomutex.lock(); |
| JMF | 0:24d3eb812fd4 | 192 | printf("UDP: tx -> %d\r\n", td); |
| JMF | 0:24d3eb812fd4 | 193 | iomutex.unlock(); |
| JMF | 0:24d3eb812fd4 | 194 | } |
| JMF | 0:24d3eb812fd4 | 195 | tx_seq.skip(td); |
| JMF | 0:24d3eb812fd4 | 196 | tx_count += td; |
| JMF | 0:24d3eb812fd4 | 197 | } else if (td != NSAPI_ERROR_WOULD_BLOCK) { |
| JMF | 0:24d3eb812fd4 | 198 | // We may fail to send because of buffering issues, revert to |
| JMF | 0:24d3eb812fd4 | 199 | // last good sequence and cut buffer in half |
| JMF | 0:24d3eb812fd4 | 200 | if (window > MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN) { |
| JMF | 0:24d3eb812fd4 | 201 | window /= 2; |
| JMF | 0:24d3eb812fd4 | 202 | } |
| JMF | 0:24d3eb812fd4 | 203 | |
| JMF | 0:24d3eb812fd4 | 204 | if (MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG) { |
| JMF | 0:24d3eb812fd4 | 205 | iomutex.lock(); |
| JMF | 0:24d3eb812fd4 | 206 | printf("UDP: Not sent (%d), window = %d\r\n", td, window); |
| JMF | 0:24d3eb812fd4 | 207 | iomutex.unlock(); |
| JMF | 0:24d3eb812fd4 | 208 | } |
| JMF | 0:24d3eb812fd4 | 209 | } |
| JMF | 0:24d3eb812fd4 | 210 | } |
| JMF | 0:24d3eb812fd4 | 211 | |
| JMF | 0:24d3eb812fd4 | 212 | // Prioritize recieving over sending packets to avoid flooding |
| JMF | 0:24d3eb812fd4 | 213 | // the network while handling erronous packets |
| JMF | 0:24d3eb812fd4 | 214 | while (rx_count < size) { |
| JMF | 0:24d3eb812fd4 | 215 | int rd = sock.recvfrom(NULL, buffer, buffer_size); |
| JMF | 0:24d3eb812fd4 | 216 | TEST_ASSERT(rd > 0 || rd == NSAPI_ERROR_WOULD_BLOCK); |
| JMF | 0:24d3eb812fd4 | 217 | |
| JMF | 0:24d3eb812fd4 | 218 | if (rd > 0) { |
| JMF | 0:24d3eb812fd4 | 219 | if (MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG) { |
| JMF | 0:24d3eb812fd4 | 220 | iomutex.lock(); |
| JMF | 0:24d3eb812fd4 | 221 | printf("UDP: rx <- %d\r\n", rd); |
| JMF | 0:24d3eb812fd4 | 222 | iomutex.unlock(); |
| JMF | 0:24d3eb812fd4 | 223 | } |
| JMF | 0:24d3eb812fd4 | 224 | |
| JMF | 0:24d3eb812fd4 | 225 | if (rx_seq.cmp(buffer, rd) == 0) { |
| JMF | 0:24d3eb812fd4 | 226 | rx_seq.skip(rd); |
| JMF | 0:24d3eb812fd4 | 227 | rx_count += rd; |
| JMF | 0:24d3eb812fd4 | 228 | known_time = timer.read_ms(); |
| JMF | 0:24d3eb812fd4 | 229 | if (window < MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX) { |
| JMF | 0:24d3eb812fd4 | 230 | window += MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN; |
| JMF | 0:24d3eb812fd4 | 231 | } |
| JMF | 0:24d3eb812fd4 | 232 | } |
| JMF | 0:24d3eb812fd4 | 233 | } else if (timer.read_ms() - known_time > |
| JMF | 0:24d3eb812fd4 | 234 | MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_TIMEOUT) { |
| JMF | 0:24d3eb812fd4 | 235 | // Dropped packet or out of order, revert to last good sequence |
| JMF | 0:24d3eb812fd4 | 236 | // and cut buffer in half |
| JMF | 0:24d3eb812fd4 | 237 | tx_seq = rx_seq; |
| JMF | 0:24d3eb812fd4 | 238 | tx_count = rx_count; |
| JMF | 0:24d3eb812fd4 | 239 | known_time = timer.read_ms(); |
| JMF | 0:24d3eb812fd4 | 240 | if (window > MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN) { |
| JMF | 0:24d3eb812fd4 | 241 | window /= 2; |
| JMF | 0:24d3eb812fd4 | 242 | } |
| JMF | 0:24d3eb812fd4 | 243 | |
| JMF | 0:24d3eb812fd4 | 244 | if (MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG) { |
| JMF | 0:24d3eb812fd4 | 245 | iomutex.lock(); |
| JMF | 0:24d3eb812fd4 | 246 | printf("UDP: Dropped, window = %d\r\n", window); |
| JMF | 0:24d3eb812fd4 | 247 | iomutex.unlock(); |
| JMF | 0:24d3eb812fd4 | 248 | } |
| JMF | 0:24d3eb812fd4 | 249 | } else if (rd == NSAPI_ERROR_WOULD_BLOCK) { |
| JMF | 0:24d3eb812fd4 | 250 | break; |
| JMF | 0:24d3eb812fd4 | 251 | } |
| JMF | 0:24d3eb812fd4 | 252 | } |
| JMF | 0:24d3eb812fd4 | 253 | } |
| JMF | 0:24d3eb812fd4 | 254 | |
| JMF | 0:24d3eb812fd4 | 255 | err = sock.close(); |
| JMF | 0:24d3eb812fd4 | 256 | TEST_ASSERT_EQUAL(0, err); |
| JMF | 0:24d3eb812fd4 | 257 | } |
| JMF | 0:24d3eb812fd4 | 258 | } |
| JMF | 0:24d3eb812fd4 | 259 | }; |
| JMF | 0:24d3eb812fd4 | 260 | |
| JMF | 0:24d3eb812fd4 | 261 | PressureTest *pressure_tests[MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS]; |
| JMF | 0:24d3eb812fd4 | 262 | |
| JMF | 0:24d3eb812fd4 | 263 | |
| JMF | 0:24d3eb812fd4 | 264 | void test_udp_packet_pressure_parallel() { |
| JMF | 0:24d3eb812fd4 | 265 | uint8_t *buffer; |
| JMF | 0:24d3eb812fd4 | 266 | size_t buffer_size; |
| JMF | 0:24d3eb812fd4 | 267 | generate_buffer(&buffer, &buffer_size, |
| JMF | 0:24d3eb812fd4 | 268 | MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN, |
| JMF | 0:24d3eb812fd4 | 269 | MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX); |
| JMF | 0:24d3eb812fd4 | 270 | |
| JMF | 0:24d3eb812fd4 | 271 | size_t buffer_subsize = buffer_size / MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS; |
| JMF | 0:24d3eb812fd4 | 272 | printf("MBED: Generated buffer %d\r\n", buffer_size); |
| JMF | 0:24d3eb812fd4 | 273 | printf("MBED: Split into %d buffers %d\r\n", |
| JMF | 0:24d3eb812fd4 | 274 | MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS, |
| JMF | 0:24d3eb812fd4 | 275 | buffer_subsize); |
| JMF | 0:24d3eb812fd4 | 276 | |
| JMF | 0:24d3eb812fd4 | 277 | int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS)); |
| JMF | 0:24d3eb812fd4 | 278 | TEST_ASSERT_EQUAL(0, err); |
| JMF | 0:24d3eb812fd4 | 279 | |
| JMF | 0:24d3eb812fd4 | 280 | printf("MBED: UDPClient IP address is '%s'\n", net.get_ip_address()); |
| JMF | 0:24d3eb812fd4 | 281 | printf("MBED: UDPClient waiting for server IP and port...\n"); |
| JMF | 0:24d3eb812fd4 | 282 | |
| JMF | 0:24d3eb812fd4 | 283 | greentea_send_kv("target_ip", net.get_ip_address()); |
| JMF | 0:24d3eb812fd4 | 284 | |
| JMF | 0:24d3eb812fd4 | 285 | char recv_key[] = "host_port"; |
| JMF | 0:24d3eb812fd4 | 286 | char ipbuf[60] = {0}; |
| JMF | 0:24d3eb812fd4 | 287 | char portbuf[16] = {0}; |
| JMF | 0:24d3eb812fd4 | 288 | unsigned int port = 0; |
| JMF | 0:24d3eb812fd4 | 289 | |
| JMF | 0:24d3eb812fd4 | 290 | greentea_send_kv("host_ip", " "); |
| JMF | 0:24d3eb812fd4 | 291 | greentea_parse_kv(recv_key, ipbuf, sizeof(recv_key), sizeof(ipbuf)); |
| JMF | 0:24d3eb812fd4 | 292 | |
| JMF | 0:24d3eb812fd4 | 293 | greentea_send_kv("host_port", " "); |
| JMF | 0:24d3eb812fd4 | 294 | greentea_parse_kv(recv_key, portbuf, sizeof(recv_key), sizeof(ipbuf)); |
| JMF | 0:24d3eb812fd4 | 295 | sscanf(portbuf, "%u", &port); |
| JMF | 0:24d3eb812fd4 | 296 | |
| JMF | 0:24d3eb812fd4 | 297 | printf("MBED: Server IP address received: %s:%d \n", ipbuf, port); |
| JMF | 0:24d3eb812fd4 | 298 | udp_addr.set_ip_address(ipbuf); |
| JMF | 0:24d3eb812fd4 | 299 | udp_addr.set_port(port); |
| JMF | 0:24d3eb812fd4 | 300 | |
| JMF | 0:24d3eb812fd4 | 301 | timer.start(); |
| JMF | 0:24d3eb812fd4 | 302 | |
| JMF | 0:24d3eb812fd4 | 303 | // Startup pressure tests in parallel |
| JMF | 0:24d3eb812fd4 | 304 | for (int i = 0; i < MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS; i++) { |
| JMF | 0:24d3eb812fd4 | 305 | pressure_tests[i] = new PressureTest(&buffer[i*buffer_subsize], buffer_subsize); |
| JMF | 0:24d3eb812fd4 | 306 | pressure_tests[i]->start(); |
| JMF | 0:24d3eb812fd4 | 307 | } |
| JMF | 0:24d3eb812fd4 | 308 | |
| JMF | 0:24d3eb812fd4 | 309 | for (int i = 0; i < MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS; i++) { |
| JMF | 0:24d3eb812fd4 | 310 | pressure_tests[i]->join(); |
| JMF | 0:24d3eb812fd4 | 311 | delete pressure_tests[i]; |
| JMF | 0:24d3eb812fd4 | 312 | } |
| JMF | 0:24d3eb812fd4 | 313 | |
| JMF | 0:24d3eb812fd4 | 314 | timer.stop(); |
| JMF | 0:24d3eb812fd4 | 315 | printf("MBED: Time taken: %fs\r\n", timer.read()); |
| JMF | 0:24d3eb812fd4 | 316 | printf("MBED: Speed: %.3fkb/s\r\n", |
| JMF | 0:24d3eb812fd4 | 317 | MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS* |
| JMF | 0:24d3eb812fd4 | 318 | 8*(2*MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX - |
| JMF | 0:24d3eb812fd4 | 319 | MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read())); |
| JMF | 0:24d3eb812fd4 | 320 | |
| JMF | 0:24d3eb812fd4 | 321 | net.disconnect(); |
| JMF | 0:24d3eb812fd4 | 322 | } |
| JMF | 0:24d3eb812fd4 | 323 | |
| JMF | 0:24d3eb812fd4 | 324 | |
| JMF | 0:24d3eb812fd4 | 325 | // Test setup |
| JMF | 0:24d3eb812fd4 | 326 | utest::v1::status_t test_setup(const size_t number_of_cases) { |
| JMF | 0:24d3eb812fd4 | 327 | GREENTEA_SETUP(120, "udp_echo"); |
| JMF | 0:24d3eb812fd4 | 328 | return verbose_test_setup_handler(number_of_cases); |
| JMF | 0:24d3eb812fd4 | 329 | } |
| JMF | 0:24d3eb812fd4 | 330 | |
| JMF | 0:24d3eb812fd4 | 331 | Case cases[] = { |
| JMF | 0:24d3eb812fd4 | 332 | Case("UDP packet pressure parallel", test_udp_packet_pressure_parallel), |
| JMF | 0:24d3eb812fd4 | 333 | }; |
| JMF | 0:24d3eb812fd4 | 334 | |
| JMF | 0:24d3eb812fd4 | 335 | Specification specification(test_setup, cases); |
| JMF | 0:24d3eb812fd4 | 336 | |
| JMF | 0:24d3eb812fd4 | 337 | int main() { |
| JMF | 0:24d3eb812fd4 | 338 | return !Harness::run(specification); |
| JMF | 0:24d3eb812fd4 | 339 | } |
| JMF | 0:24d3eb812fd4 | 340 | |
| JMF | 0:24d3eb812fd4 | 341 |