3 #include "lib/fastbuf.h"
4 #include "lib/lizard.h"
11 static char *options = CF_SHORT_OPTS "cdtx";
12 static char *help = "\
13 Usage: lizard-test <options> input-file [output-file]\n\
17 "-c\t\tCompress (default)\n\
19 -t\t\tCompress, decompress, and compare (in memory only)\n\
20 -x, -xx, -xxx\tMake the test crash by underestimating the output buffer\n\
31 main(int argc, char **argv)
37 while ((opt = cf_getopt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0)
51 if (action == 't' && argc != optind+1
52 || action != 't' && argc != optind+2)
59 stat(argv[optind], &st);
61 struct fastbuf *fi = bopen(argv[optind], O_RDONLY, 1<<16);
64 lo = li * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
65 li += LIZARD_NEEDS_CHARS;
74 li = bread(fi, mi, li);
79 printf("->expected %d ", lo);
82 lo = lizard_compress(mi, li, mo);
84 lo = lizard_decompress(mi, mo);
90 struct fastbuf *fo = bopen(argv[optind+1], O_CREAT | O_TRUNC | O_WRONLY, 1<<16);
98 struct lizard_buffer *buf = lizard_alloc(li);
102 if (exp_len >= PAGE_SIZE)
103 exp_len -= PAGE_SIZE;
106 printf("Setting shorter output buffer to %d: ", exp_len);
109 int lv = lizard_decompress_safe(mo, buf, exp_len);
110 printf("-> %d ", lv);
114 uns guarded_pos = (lv + PAGE_SIZE-1)/PAGE_SIZE * PAGE_SIZE;
115 printf("Reading from guarded memory: %d\n", ((byte *) (buf->ptr)) [guarded_pos]);
118 printf("Writing to guarded memory: ");
120 ((byte *) (buf->ptr)) [guarded_pos] = 0;
121 printf("succeeded\n");
125 printf("Reading behind guarded memory: ");
127 printf("%d\n", ((byte *) (buf->ptr)) [guarded_pos + PAGE_SIZE] = 0);
130 if (lv != li || memcmp(mi, buf->ptr, li))