]> git.meshlink.io Git - utcp/commitdiff
Allow test program to compare input to a reference file.
authorGuus Sliepen <guus@meshlink.io>
Sun, 2 Jul 2017 12:58:08 +0000 (14:58 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 2 Jul 2017 12:58:08 +0000 (14:58 +0200)
test.c

diff --git a/test.c b/test.c
index 81244f90027819f5a456027c390f5a48ecd5a1ac..4a1bf16e3bff39ca60ac67472b3c4e0c8f9f0cd5 100644 (file)
--- a/test.c
+++ b/test.c
@@ -30,6 +30,7 @@ double dropin;
 double dropout;
 long total_out;
 long total_in;
+FILE *reference;
 
 char *reorder_data;
 size_t reorder_len;
@@ -60,6 +61,17 @@ ssize_t do_recv(struct utcp_connection *c, const void *data, size_t len) {
                }
                return -1;
        }
+       if(reference) {
+               char buf[len];
+               if(fread(buf, len, 1, reference) != 1) {
+                       debug("Error reading reference\n");
+                       abort();
+               }
+               if(memcmp(buf, data, len)) {
+                       debug("Received data differs from reference\n");
+                       abort();
+               }
+       }
        return write(1, data, len);
 }
 
@@ -123,6 +135,10 @@ int main(int argc, char *argv[]) {
        if(getenv("REORDER")) reorder = atof(getenv("REORDER"));
        if(getenv("REORDER_DIST")) reorder_dist = atoi(getenv("REORDER_DIST"));
 
+       char *reference_filename = getenv("REFERENCE");
+       if(reference_filename)
+               reference = fopen(reference_filename, "r");
+
        if(dropto < dropfrom)
                dropto = 1 << 30;