#include "lib/lib.h"
-#include "lib/conf.h"
+#include "lib/getopt.h"
#include "lib/fastbuf.h"
-#include "lib/lizzard.h"
+#include "lib/ff-binary.h"
+#include "lib/lizard.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
-static char *options = CF_SHORT_OPTS "cdt";
+static char *options = CF_SHORT_OPTS "cdtx";
static char *help = "\
-Usage: lizzard-test <options> input-file [output-file]\n\
+Usage: lizard-test <options> 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\
+-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
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)
switch (opt)
case 't':
action = opt;
break;
+ case 'x':
+ crash++;
+ break;
default:
usage();
}
usage();
void *mi, *mo;
- uns li, lo;
+ int li, lo;
+ uns adler = 0;
struct stat st;
stat(argv[optind], &st);
struct fastbuf *fi = bopen(argv[optind], O_RDONLY, 1<<16);
if (action != 'd')
{
- lo = li * LIZZARD_MAX_MULTIPLY + LIZZARD_MAX_ADD;
- li += LIZZARD_NEEDS_CHARS;
+ lo = li * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
+ li += LIZARD_NEEDS_CHARS;
}
else
{
lo = bgetl(fi);
- li -= 4;
+ adler = bgetl(fi);
+ li -= 8;
}
mi = xmalloc(li);
mo = xmalloc(lo);
printf("%d ", li);
if (action == 'd')
- printf("->expected %d ", lo);
+ printf("->expected %d (%08x) ", lo, adler);
fflush(stdout);
if (action != 'd')
- lo = lizzard_compress(mi, li, mo);
+ lo = lizard_compress(mi, li, mo);
else
- lo = lizzard_decompress(mi, mo);
+ {
+ lo = lizard_decompress(mi, mo);
+ if (adler32(mo, lo) != adler)
+ printf("wrong Adler32 ");
+ }
printf("-> %d ", lo);
fflush(stdout);
{
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
{
- void *mv;
- uns lv;
- mv = xmalloc(li);
- lv = lizzard_decompress(mo, mv);
- printf("-> %d ", lv);
- fflush(stdout);
- if (lv != li || memcmp(mi, mv, lv))
+ 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");
+ lizard_free(buf);
}
printf("\n");
}