X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fchannels-udp.c;h=40d5605de17f1502f1caeb6b23639811ab6a74fb;hb=4b6c01b1d5383b1a7417244a31ad4652aab2d5db;hp=f026d48b219a0dfa66153775582887daba23b687;hpb=9a2520c36431a8a5fd90451e97f488c22f4decc5;p=meshlink diff --git a/test/channels-udp.c b/test/channels-udp.c index f026d48b..40d5605d 100644 --- a/test/channels-udp.c +++ b/test/channels-udp.c @@ -1,3 +1,7 @@ +#ifdef NDEBUG +#undef NDEBUG +#endif + #include #include #include @@ -16,6 +20,7 @@ struct client { meshlink_handle_t *mesh; meshlink_channel_t *channel; size_t received; + bool got_large_packet; }; static void server_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { @@ -48,10 +53,14 @@ static void client_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *chann (void)data; // We expect always the same amount of data from the server. - assert(len == 1000); assert(mesh->priv); struct client *client = mesh->priv; + assert(len == 512 || len == 65536); client->received += len; + + if(len == 65536) { + client->got_large_packet = true; + } } static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { @@ -91,7 +100,10 @@ static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint return false; } -int main() { +int main(void) { + init_sync_flag(&accept_flag); + init_sync_flag(&close_flag); + meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb); // Open four new meshlink instance, the server and three peers. @@ -131,9 +143,22 @@ int main() { assert(clients[i].channel); } + // Check that we can send up to 65535 bytes without errors + + char large_data[65536] = ""; + + for(int i = 0; i < 3; i++) { + assert(meshlink_channel_send(server, channels[i], large_data, sizeof(large_data) + 1) == -1); + assert(meshlink_channel_send(server, channels[i], large_data, sizeof(large_data)) == sizeof(large_data)); + } + + // Assert that packets larger than 64 kiB are not allowed + + assert(meshlink_channel_send(server, channels[0], large_data, 65537) == -1); + // Stream packets from server to clients for 5 seconds at 40 Mbps (1 kB * 500 Hz) - char data[1000]; + char data[512]; memset(data, 'U', sizeof(data)); for(int j = 0; j < 2500; j++) { @@ -142,7 +167,7 @@ int main() { } const struct timespec req = {0, 2000000}; - clock_nanosleep(CLOCK_MONOTONIC, 0, &req, NULL); + nanosleep(&req, NULL); } // Let the clients close the channels @@ -161,8 +186,9 @@ int main() { } for(int i = 0; i < 3; i++) { - assert(clients[i].received >= 2400000); - assert(clients[i].received <= 2500000); + assert(clients[i].received >= 1000000); + assert(clients[i].received <= 1345536); + assert(clients[i].got_large_packet); } // Clean up.