From: Guus Sliepen Date: Sun, 11 Oct 2015 21:35:02 +0000 (+0200) Subject: Allow dropping a selected range of packets during tests. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=613385ca4a15406aa05149a82830063db8d37a53;p=utcp Allow dropping a selected range of packets during tests. --- diff --git a/test.c b/test.c index 0eb8462..fec0abc 100644 --- a/test.c +++ b/test.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -19,6 +20,10 @@ 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); }