X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Flizard-test.c;h=137cdc79249a5b7d725ca9b70978f46f3fdaa06e;hb=c4bf633211b0424492b5a3937d6a6d2e0d79a4cf;hp=2c5c14940bb9b33d80769e1ab629405f1792e872;hpb=728e8c27a9fad3acb359d587e48298c88c18aa15;p=libucw.git diff --git a/lib/lizard-test.c b/lib/lizard-test.c index 2c5c1494..137cdc79 100644 --- a/lib/lizard-test.c +++ b/lib/lizard-test.c @@ -1,12 +1,12 @@ #include "lib/lib.h" -#include "lib/conf.h" +#include "lib/getopt.h" #include "lib/fastbuf.h" +#include "lib/ff-binary.h" #include "lib/lizard.h" #include #include #include #include -#include static char *options = CF_SHORT_OPTS "cdtx"; static char *help = "\ @@ -14,10 +14,10 @@ Usage: lizard-test input-file [output-file]\n\ \n\ Options:\n" CF_USAGE -"-c\t\tCompress (default)\n\ +"-c\t\tCompress\n\ -d\t\tDecompress\n\ --t\t\tCompress, decompress, and compare (in memory only)\n\ --x, -xx, -xxx\tMake the test crash by underestimating the output buffer\n\ +-t\t\tCompress, decompress, and compare (in memory only, default)\n\ +-x\t\tLet the test crash by shrinking the output buffer\n\ "; static void NONRET @@ -31,7 +31,7 @@ int main(int argc, char **argv) { int opt; - uns action = 'c'; + uns action = 't'; uns crash = 0; log_init(argv[0]); while ((opt = cf_getopt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0) @@ -54,6 +54,7 @@ main(int argc, char **argv) void *mi, *mo; int li, lo; + uns adler = 0; struct stat st; stat(argv[optind], &st); @@ -67,7 +68,8 @@ main(int argc, char **argv) else { lo = bgetl(fi); - li -= 4; + adler = bgetl(fi); + li -= 8; } mi = xmalloc(li); mo = xmalloc(lo); @@ -76,12 +78,16 @@ main(int argc, char **argv) printf("%d ", li); if (action == 'd') - printf("->expected %d ", lo); + printf("->expected %d (%08x) ", lo, adler); fflush(stdout); if (action != 'd') lo = lizard_compress(mi, li, mo); else + { lo = lizard_decompress(mi, mo); + if (adler32(mo, lo) != adler) + printf("wrong Adler32 "); + } printf("-> %d ", lo); fflush(stdout); @@ -89,45 +95,25 @@ main(int argc, char **argv) { struct fastbuf *fo = bopen(argv[optind+1], O_CREAT | O_TRUNC | O_WRONLY, 1<<16); if (action == 'c') + { bputl(fo, li); + bputl(fo, adler32(mi, li)); + } bwrite(fo, mo, lo); bclose(fo); } else { - struct lizard_buffer *buf = lizard_alloc(li); - uns exp_len = li; - if (crash==1) - { - if (exp_len >= PAGE_SIZE) - exp_len -= PAGE_SIZE; - else - exp_len = 0; - printf("Setting shorter output buffer to %d: ", exp_len); - fflush(stdout); - } - int lv = lizard_decompress_safe(mo, buf, exp_len); - printf("-> %d ", lv); - fflush(stdout); - if (crash >= 2) - { - uns guarded_pos = (lv + PAGE_SIZE-1)/PAGE_SIZE * PAGE_SIZE; - printf("Reading from guarded memory: %d\n", ((byte *) (buf->ptr)) [guarded_pos]); - if (crash == 2) - { - printf("Writing to guarded memory: "); - fflush(stdout); - ((byte *) (buf->ptr)) [guarded_pos] = 0; - printf("succeeded\n"); - } - if (crash == 3) - { - printf("Reading behind guarded memory: "); - fflush(stdout); - printf("%d\n", ((byte *) (buf->ptr)) [guarded_pos + PAGE_SIZE] = 0); - } - } - if (lv != li || memcmp(mi, buf->ptr, li)) + int smaller_li; + if (li >= (int) CPU_PAGE_SIZE) + smaller_li = li - CPU_PAGE_SIZE; + else + smaller_li = 0; + struct lizard_buffer *buf = lizard_alloc(); + byte *ptr = lizard_decompress_safe(mo, buf, crash ? smaller_li : li); + if (!ptr) + printf("err: %m"); + else if (memcmp(mi, ptr, li)) printf("WRONG"); else printf("OK");