]> git.meshlink.io Git - utcp/commitdiff
Allow dropping a selected range of packets during tests.
authorGuus Sliepen <guus@meshlink.io>
Sun, 11 Oct 2015 21:35:02 +0000 (23:35 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 09:56:07 +0000 (11:56 +0200)
test.c

diff --git a/test.c b/test.c
index 0eb8462b4b60f26a17c87860384d238500748db8..fec0abcdcfff6b001c1d7825d29ab4fa6289f26f 100644 (file)
--- a/test.c
+++ b/test.c
@@ -2,6 +2,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <string.h>
 #include <time.h>
 #include <errno.h>
 struct utcp_connection *c;
 int dir = DIR_READ | DIR_WRITE;
 bool running = true;
+long inpktno;
+long outpktno;
+long dropfrom;
+long dropto;
 double dropin;
 double dropout;
 
@@ -44,7 +49,8 @@ void do_accept(struct utcp_connection *nc, uint16_t port) {
 
 ssize_t do_send(struct utcp *utcp, const void *data, size_t len) {
        int s = *(int *)utcp->priv;
-       if(drand48() < dropout)
+       outpktno++;
+       if(outpktno < dropto && outpktno >= dropfrom && drand48() < dropout)
                return len;
 
        ssize_t result = send(s, data, len, MSG_DONTWAIT);
@@ -65,6 +71,8 @@ int main(int argc, char *argv[]) {
 
        dropin = atof(getenv("DROPIN") ?: "0");
        dropout = atof(getenv("DROPOUT") ?: "0");
+       dropfrom = atoi(getenv("DROPFROM") ?: "0");
+       dropto = atoi(getenv("DROPTO") ?: "0");
 
        struct addrinfo *ai;
        struct addrinfo hint = {
@@ -153,7 +161,8 @@ int main(int argc, char *argv[]) {
                        if(!connected)
                                if(!connect(s, (struct sockaddr *)&ss, sl))
                                        connected = true;
-                       if(drand48() >= dropin)
+                       inpktno++;
+                       if(inpktno >= dropto || inpktno < dropfrom || drand48() >= dropin)
                                utcp_recv(u, buf, len);
                }