From: Guus Sliepen Date: Sun, 2 Jul 2017 12:58:08 +0000 (+0200) Subject: Allow test program to compare input to a reference file. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=b52e9aa456dfeedfaa8c3be0e8347d1e1477b611;p=utcp Allow test program to compare input to a reference file. --- diff --git a/test.c b/test.c index 81244f9..4a1bf16 100644 --- 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;