diff options
author | Martin Pool <mbp@sourcefrog.net> | 2000-04-21 14:49:23 +0000 |
---|---|---|
committer | Martin Pool <mbp@sourcefrog.net> | 2000-04-21 14:49:23 +0000 |
commit | 8d1f2d6dcfe9ea572fecff58abb95b80ee0134f1 (patch) | |
tree | 1b230657391b37ac47b22ccdaa9638ec13a67572 | |
parent | 46ec2746845ddc1bdbbec637f9b166ad5e8958cd (diff) | |
download | librsync-8d1f2d6dcfe9ea572fecff58abb95b80ee0134f1.tar.gz |
Add hsmdfour test driver.
Try to check file checksum during decode.
Factor out the common code in test cases.
-rw-r--r-- | .cvsignore | 1 | ||||
-rw-r--r-- | Makefile.am | 15 | ||||
-rw-r--r-- | TODO | 34 | ||||
-rw-r--r-- | dec.c | 87 | ||||
-rw-r--r-- | emit.c | 18 | ||||
-rw-r--r-- | filebuf.c | 17 | ||||
-rw-r--r-- | hsemit.c | 7 | ||||
-rw-r--r-- | hsinhale.c | 20 | ||||
-rw-r--r-- | hsmdfour.c | 78 | ||||
-rw-r--r-- | hsync.h | 45 | ||||
-rw-r--r-- | litbuf.c | 4 | ||||
-rwxr-xr-x | make-cmds.py | 16 | ||||
-rw-r--r-- | netio.c | 8 | ||||
-rw-r--r-- | private.h | 7 | ||||
-rwxr-xr-x | test-chain.sh | 16 | ||||
-rwxr-xr-x | test-cmds.sh | 14 | ||||
-rwxr-xr-x | test-decode.sh | 21 | ||||
-rwxr-xr-x | test-encode.sh | 17 | ||||
-rwxr-xr-x | test-seq.sh | 33 | ||||
-rwxr-xr-x | test-thrice.sh | 14 |
20 files changed, 310 insertions, 162 deletions
@@ -16,6 +16,7 @@ hsemit hsemit hsencode hsinhale +hsmdfour libhsync-*.tar.gz libhsync-*.tar.gz.asc libtool diff --git a/Makefile.am b/Makefile.am index 0a7a028..40f1d81 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,5 @@ ## Process this file with automake to produce Makefile.in +## Copyright (C) 2000 by Martin Pool CFLAGS += -W -Wall -g @DEFS@ @@ -21,10 +22,13 @@ libhsyncdecode_la_SOURCES = dec.c \ private.h netio.c includes.h \ compress.c compress.h \ filebuf.c membuf.c ptrbuf.c \ - inhale.c trace.c hex.c stats.c + inhale.c trace.c hex.c stats.c \ + mdfour.c -noinst_SCRIPTS = test-decode.sh test-encode.sh test-chain.sh test-cmds.sh \ - make-cmds.py test-thrice.sh test-seq.sh +noinst_SCRIPTS = test-decode.sh test-encode.sh \ + test-chain.sh test-cmds.sh \ + make-cmds.py test-thrice.sh test-seq.sh test-meta.sh \ + testfns.sh test_data=test-chain/empty-sig \ test-decode/01-diff \ @@ -65,7 +69,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) $(test_data) include_HEADERS = hsync.h hsyncproto.h -bin_PROGRAMS = hsdecode hsencode +bin_PROGRAMS = hsdecode hsencode hsmdfour check_PROGRAMS = hsemit hsinhale check_DATA = test-cmds/cmds.txt @@ -73,6 +77,9 @@ check_DATA = test-cmds/cmds.txt test-cmds/cmds.txt: make-cmds.py $(PYTHON) ./make-cmds.py > $@ +hsmdfour_SOURCES = hsmdfour.c mdfour.c filebuf.c hex.c trace.c +# hsmdfour_LDADD = libhsyncdecode.la + hsdecode_SOURCES = hsdecode.c hsdecode_LDADD = libhsyncdecode.la @@ -0,0 +1,34 @@ +-*- indented-text -*- + + * Try to make libhsync more generally useful + + * Tease apart the different algorithms inside the library so that + they can be independently re-used. + + * Use more specific names than `encode' and `decode'. I like + `apply' as a description of what the client does. + + * Don't imply any particular encoding format. I don't think we + need callbacks; it's enough that all the users can write their + own implementations of the loops. + + * This ought to make it simpler to get push-structured interfaces. + + * More thorough testing + + * mdfour + + * keep some example files and check that they give the expected + results. + + * try using different input chunk sizes + + * abstract i/o + + * rewrite cat to use our routines, and make sure it passes the + file through correctly however we call it. Different + strategies are possible: using the loop functions or not, using + mapptrs, etc. + + +LocalWords: mdfour LocalWords mapptrs @@ -50,29 +50,36 @@ static int _hs_copy(const uint32_t length, hs_read_fn_t read_fn, void *read_priv, - hs_write_fn_t write_fn, void *write_priv) + hs_write_fn_t write_fn, void *write_priv, + hs_mdfour_t *newsum) { - ssize_t ret; - char *buf; + ssize_t ret; + char *buf; - buf = malloc(length); + buf = malloc(length); + if (!buf) + goto fail; - ret = _hs_read_loop(read_fn, read_priv, buf, length); - if (ret >= 0 && (ret < (int32_t) length)) { - errno = ENODATA; - goto fail; - } + ret = _hs_read_loop(read_fn, read_priv, buf, length); + if (ret >= 0 && (ret < (int32_t) length)) { + errno = ENODATA; + goto fail; + } + + if (newsum) + hs_mdfour_update(newsum, buf, ret); - ret = _hs_write_loop(write_fn, write_priv, buf, ret); - if ((unsigned) ret != length) - goto fail; + ret = _hs_write_loop(write_fn, write_priv, buf, ret); + if ((unsigned) ret != length) + goto fail; - free(buf); - return length; + free(buf); + return length; - fail: - free(buf); - return -1; + fail: + if (buf) + free(buf); + return -1; } @@ -97,6 +104,30 @@ static int _hs_check_gd_header(hs_read_fn_t ltread_fn, void *ltread_priv) } +static int +_hs_check_checksum(hs_read_fn_t ltread_fn, void *ltread_priv, + int length, hs_mdfour_t * newsum) +{ + char *buf; + int ret; + char actual_result[MD4_LENGTH]; + + assert(length == MD4_LENGTH); + buf = malloc(length); + assert(buf); + + ret = _hs_read_loop(ltread_fn, ltread_priv, buf, length); + assert(ret == length); + + hs_mdfour_result(newsum, actual_result); + + assert(memcmp(actual_result, buf, MD4_LENGTH) == 0); + free(buf); + + return 1; +} + + ssize_t hs_decode(hs_readofs_fn_t oldread_fn, void *oldread_priv, @@ -109,12 +140,15 @@ hs_decode(hs_readofs_fn_t oldread_fn, void *oldread_priv, uint32_t length, offset; int kind; char *stats_str; + hs_mdfour_t newsum; _hs_trace("**** begin %s", __FUNCTION__); bzero(stats, sizeof *stats); if (_hs_check_gd_header(ltread_fn, ltread_priv) < 0) return -1; + hs_mdfour_begin(&newsum); + while (1) { ret = _hs_inhale_command(ltread_fn, ltread_priv, &kind, &length, &offset); if (ret < 0) { @@ -126,30 +160,33 @@ hs_decode(hs_readofs_fn_t oldread_fn, void *oldread_priv, _hs_trace("op_eof"); break; /* We're done! Cool bananas */ } else if (kind == op_kind_literal) { - _hs_trace("op_literal len=%d", length); + _hs_trace("LITERAL(len=%d)", length); ret = _hs_copy(length, ltread_fn, ltread_priv, write_fn, - write_priv); + write_priv, &newsum); return_val_if_fail(ret >= 0, -1); stats->lit_cmds++; stats->lit_bytes += length; } else if (kind == op_kind_signature) { - _hs_trace("op_signature len=%d", length); - ret = _hs_copy(length, ltread_fn, ltread_priv, newsig_fn, - newsig_priv); + _hs_trace("SIGNATURE(len=%d)", length); + ret = _hs_copy(length, + ltread_fn, ltread_priv, + newsig_fn, newsig_priv, + NULL); return_val_if_fail(ret >= 0, -1); stats->sig_cmds++; stats->sig_bytes += length; } else if (kind == op_kind_copy) { - _hs_trace("op_copy offset=%d, len=%d", offset, length); + _hs_trace("COPY(offset=%d, len=%d)", offset, length); ret = _hs_copy_ofs(offset, length, oldread_fn, oldread_priv, - write_fn, write_priv); + write_fn, write_priv, + &newsum); return_val_if_fail(ret >= 0, -1); stats->copy_cmds++; stats->copy_bytes += length; } else if (kind == op_kind_checksum) { _hs_trace("CHECKSUM(len=%d)", length); - ret = _hs_check_checksum(ltread_fn, ltread_priv, length, filesum); + ret = _hs_check_checksum(ltread_fn, ltread_priv, length, &newsum); } else { _hs_fatal("unexpected op kind %d!", type); } @@ -66,8 +66,7 @@ int _hs_emit_eof(hs_write_fn_t write_fn, void *write_priv, int -_hs_emit_filesum(hs_write_fn_t write_fn, void *write_priv, - char const *buf, uint32_t size) +_hs_emit_checksum_cmd(hs_write_fn_t write_fn, void *write_priv, uint32_t size) { int ret; @@ -80,6 +79,21 @@ _hs_emit_filesum(hs_write_fn_t write_fn, void *write_priv, if (ret != 2) return -1; + return 3; +} + + + +int +_hs_emit_filesum(hs_write_fn_t write_fn, void *write_priv, + char const *buf, uint32_t size) +{ + int ret; + + ret = _hs_emit_checksum_cmd(write_fn, write_priv, size); + if (ret <= 0) + return -1; + ret = _hs_write_loop(write_fn, write_priv, buf, size); if (ret != (int) size) return -1; @@ -28,6 +28,8 @@ #include "private.h" #include "compress.h" +#undef HS_ALWAYS_READ_SHORT + const int filebuf_tag = 24031976; struct file_buf { @@ -115,6 +117,10 @@ hs_filebuf_read(void *private, char *buf, size_t len) assert(fbuf->dogtag == filebuf_tag); assert(fbuf->fd != -1); +#ifdef HS_ALWAYS_READ_SHORT + len = MIN(len, 100); +#endif + n = read(fbuf->fd, buf, len); return n; @@ -128,6 +134,9 @@ hs_filebuf_write(void *private, char const *buf, size_t len) size_t n; assert(fbuf->dogtag == filebuf_tag); +#ifdef HS_ALWAYS_READ_SHORT + len = MIN(len, 100); +#endif n = write(fbuf->fd, buf, len); if (fbuf->fd_cache != -1 && n > 0) { write(fbuf->fd_cache, buf, n); @@ -145,12 +154,16 @@ hs_filebuf_read_ofs(void *private, char *buf, size_t len, hs_off_t ofs) assert(fbuf->dogtag == filebuf_tag); if (lseek(fbuf->fd, ofs, SEEK_SET) == -1) { - fprintf(stderr, "hs_filebuf_read_ofs: " - "seek to %ld failed: %s\n", (long) ofs, strerror(errno)); + _hs_fatal("hs_filebuf_read_ofs: " + "seek to %ld failed: %s", (long) ofs, strerror(errno)); return -1; } n = read(fbuf->fd, buf, len); + if (n != len) { + _hs_trace("** short read in " __FUNCTION__ ", result=%d", + n); + } return n; } @@ -74,6 +74,13 @@ main(int argc UNUSED, char **argv UNUSED) ret = _hs_emit_signature_cmd(hs_filebuf_write, outfb, len); if (ret < 0) return 1; + } else if (!strcmp(cmd, "CHECKSUM")) { + if (scanf("%d", &len) != 1) + return 1; + + ret = _hs_emit_checksum_cmd(hs_filebuf_write, outfb, len); + if (ret < 0) + return 1; } else { fprintf(stderr, "can't understand command `%s'\n", cmd); @@ -37,23 +37,33 @@ static void print_cmd(int kind, uint32_t len, uint32_t off) { + char const *kind_str; + switch (kind) { case op_kind_eof: printf("EOF\n"); - break; + return; case op_kind_copy: printf("COPY %d %d\n", off, len); - break; + return; + } + + switch (kind) { case op_kind_signature: + kind_str = "SIGNATURE"; + break; case op_kind_literal: - printf("%s %d\n", - kind == op_kind_signature ? "SIGNATURE" : "LITERAL", - len); + kind_str = "LITERAL"; + break; + case op_kind_checksum: + kind_str = "CHECKSUM"; break; default: fprintf(stderr, "bugger! unexpected opcode kind\n"); abort(); } + + printf("%s %d\n", kind_str, len); } diff --git a/hsmdfour.c b/hsmdfour.c new file mode 100644 index 0000000..0ebbca4 --- /dev/null +++ b/hsmdfour.c @@ -0,0 +1,78 @@ +/* -*- mode: c; c-file-style: "k&r"; c-basic-offset: 4 -*- */ +/* hsmdfour.c -- Write out the md4sum of stdin. + + Copyright (C) 2000 by Martin Pool. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +#include "includes.h" +#include "hsync.h" +#include "private.h" + + +int main(int argc, char *argv[]) +{ + hs_mdfour_t sum; + hs_filebuf_t *infb; + char result[MD4_LENGTH], result_str[MD4_LENGTH * 2]; + int buf_len = 1000; + char *buf; + char *tail_ptr; + int len; + int c; + + while ((c = getopt(argc, argv, "b:")) != -1) { + switch (c) { + case '?': + case ':': + return 1; + case 'b': + buf_len = strtol(optarg, &tail_ptr, 10); + if (*tail_ptr || buf_len < 1) { + fprintf(stderr, "-b must have an integer argument\n"); + return 1; + } + break; + } + } + + buf = malloc(buf_len); + assert(buf); + hs_mdfour_begin(&sum); + + infb = hs_filebuf_from_fd(STDIN_FILENO); + assert(infb); + + while (1) { + len = hs_filebuf_read(infb, buf, buf_len); + if (len < 0) { + perror("error in read"); + return 1; + } else if (len == 0) { + break; + } else { + hs_mdfour_update(&sum, buf, len); + } + } + + hs_mdfour_result(&sum, result); + hs_hexify_buf(result_str, result, MD4_LENGTH); + + write(STDOUT_FILENO, result_str, sizeof result_str); + write(STDOUT_FILENO, "\n", 1); + + return 0; +} @@ -1,5 +1,4 @@ -/* -*- mode: c; c-file-style: "k&r" -*- */ - +/* -*- mode: c; c-file-style: "k&r"; c-basic-offset: 4 -*- */ /* libhsync Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au> @@ -20,7 +19,7 @@ */ -extern char const * const hs_libhsync_version; +extern char const *const hs_libhsync_version; #if HAVE_OFF64_T #define hs_off_t off64_t @@ -53,10 +52,10 @@ void _hs_trace_to_stderr(char const *fmt, va_list va); Decode */ typedef struct hs_stats { - int lit_cmds, lit_bytes; - int copy_cmds, copy_bytes; - int sig_cmds, sig_bytes; - int false_matches; + int lit_cmds, lit_bytes; + int copy_cmds, copy_bytes; + int sig_cmds, sig_bytes; + int false_matches; } hs_stats_t; ssize_t @@ -74,9 +73,9 @@ hs_decode(hs_readofs_fn_t oldread_fn, void *oldread_priv, ssize_t hs_encode(hs_read_fn_t read_fn, void *readprivate, - hs_write_fn_t write_fn, void *write_priv, - hs_read_fn_t sigread_fn, void *sigreadprivate, - int new_block_len, hs_stats_t * stats); + hs_write_fn_t write_fn, void *write_priv, + hs_read_fn_t sigread_fn, void *sigreadprivate, + int new_block_len, hs_stats_t * stats); /* ======================================== @@ -98,13 +97,13 @@ ssize_t hs_filebuf_read_ofs(void *private, char *buf, size_t len, hs_off_t ofs); hs_filebuf_t *hs_filebuf_open(char const *filename, int mode); -void hs_filebuf_close(hs_filebuf_t *fbuf); -void hs_filebuf_add_cache(hs_filebuf_t *fb, int); +void hs_filebuf_close(hs_filebuf_t * fbuf); +void hs_filebuf_add_cache(hs_filebuf_t * fb, int); hs_filebuf_t *hs_filebuf_from_fd(int); -hs_filebuf_t * hs_filebuf_from_file(FILE *fp); - +hs_filebuf_t *hs_filebuf_from_file(FILE * fp); + /* ======================================== File map pointers @@ -112,12 +111,12 @@ hs_filebuf_t * hs_filebuf_from_file(FILE *fp); struct hs_map_struct { char *p; - int fd,p_size,p_len; + int fd, p_size, p_len; hs_off_t file_size, p_offset, p_fd_offset; }; + - /* ======================================== Memory buffers @@ -158,17 +157,19 @@ hs_ptrbuf_t *hs_ptrbuf_on_buffer(char *buf, int len); */ typedef struct hs_mdfour { - uint32_t A, B, C, D; - uint32_t totalN; + uint32_t A, B, C, D; + uint32_t totalN; + int tail_len; + char tail[64]; } hs_mdfour_t; void hs_mdfour(unsigned char *out, unsigned char const *in, int n); -void hs_mdfour_begin(hs_mdfour_t *md); -void hs_mdfour_update(hs_mdfour_t *md, unsigned char const *in, int n); -void hs_mdfour_result(hs_mdfour_t *md, unsigned char *out); +void hs_mdfour_begin(hs_mdfour_t * md); +void hs_mdfour_update(hs_mdfour_t * md, unsigned char const *in, int n); +void hs_mdfour_result(hs_mdfour_t * md, unsigned char *out); void hs_hexify_buf(char *to_buf, unsigned char const *from_buf, int from_len); -char * hs_format_stats(hs_stats_t const * stats); +char *hs_format_stats(hs_stats_t const *stats); @@ -72,7 +72,9 @@ _hs_push_literal_buf(hs_membuf_t * litbuf, } ret = _hs_copy_ofs(0, amount, - hs_membuf_read_ofs, litbuf, write_fn, write_priv); + hs_membuf_read_ofs, litbuf, + write_fn, write_priv, + NULL); return_val_if_fail(ret > 0, -1); if (kind == op_kind_literal) { diff --git a/make-cmds.py b/make-cmds.py index b3855a5..9ed6df8 100755 --- a/make-cmds.py +++ b/make-cmds.py @@ -1,6 +1,7 @@ #! /usr/bin/python -# Generate a dangerous command stream for testing libhsync +# Generate a dangerous command stream for testing libhsync. +# $Id$ # Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au> @@ -20,10 +21,12 @@ # USA # This should catch every boundary case -vals = [1, 2, 3, 10, 20, 100, 200, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 300, - 1000, 2000, 1<<16 - 1, 1<<16, 1<<16 + 1, - 1<<18, 1<<20, 1<<22, int(1<<31L - 1)] +byte_vals = [1, 2, 3, 10, 20, 100, 200, 250, 251, 252, 253, + 254, 255] +short_vals = byte_vals + [256, 257, 258, 259, 260, 261, 300, + 1000, 2000, 1<<16 - 1] +vals = short_vals + \ + [1<<16, 1<<16 + 1, 1<<18, 1<<20, 1<<22, int(1<<31L - 1)] for i in vals: print 'LITERAL', i @@ -35,6 +38,9 @@ for offset in [0] + vals: for length in vals: print 'COPY', offset, length +for i in short_vals: + print 'CHECKSUM', i + print 'EOF' @@ -78,7 +78,8 @@ _hs_write_loop(hs_write_fn_t write_fn, void *write_priv, int _hs_copy_ofs(uint32_t offset, uint32_t length, hs_readofs_fn_t readofs_fn, void *readofs_priv, - hs_write_fn_t write_fn, void *write_priv) + hs_write_fn_t write_fn, void *write_priv, + hs_mdfour_t *newsum) { int ret; char *buf; @@ -95,13 +96,16 @@ _hs_copy_ofs(uint32_t offset, uint32_t length, _hs_error("error in read callback: off=%d, len=%d", offset, length); goto fail; - } else if (ret >= 0 && ret < (int) length) { + } else if (ret != (int) length) { _hs_error("short read: off=%d, len=%d, result=%d", offset, length, ret); errno = ENODATA; goto fail; } + if (newsum) + hs_mdfour_update(newsum, buf, ret); + ret = _hs_write_loop(write_fn, write_priv, buf, ret); if (ret != (int) length) { _hs_error("error in write callback: off=%d, len=%d", @@ -1,5 +1,4 @@ -/* -*- mode: c; c-file-style: "k&r" -*- */ - +/* -*- mode: c; c-file-style: "k&r"; c-basic-offset: 4 -*- */ /* private.h -- Private headers for libhsync Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au> @@ -106,7 +105,8 @@ int _hs_write_netvar(hs_write_fn_t write_fn, void *write_priv, int _hs_copy_ofs(uint32_t offset, uint32_t length, hs_readofs_fn_t readofs_fn, void *readofs_priv, - hs_write_fn_t write_fn, void *write_priv); + hs_write_fn_t write_fn, void *write_priv, + hs_mdfour_t *); /* ======================================== @@ -283,6 +283,7 @@ int _hs_emit_filesum(hs_write_fn_t write_fn, void *write_priv, int _hs_emit_literal_cmd(hs_write_fn_t write_fn, void *write_priv, uint32_t size); +int _hs_emit_checksum_cmd(hs_write_fn_t, void *, uint32_t size); int _hs_emit_copy(hs_write_fn_t write_fn, void *write_priv, uint32_t offset, uint32_t length, hs_stats_t * stats); diff --git a/test-chain.sh b/test-chain.sh index e52df34..ecac35e 100755 --- a/test-chain.sh +++ b/test-chain.sh @@ -2,18 +2,13 @@ # Regression test suite for libhsync. +# Copyright (C) 2000 by Martin Pool + # OK, this is how we test feeding hsync it's own filth. Starting # with an empty signature, we generate the difference from one # file to another. -if [ "$srcdir" = "" ] -then - srcdir=`dirname $0` -fi -srcdir=`cd $srcdir; pwd` - -PATH=$srcdir:$PATH -cd $srcdir/test-chain +source testfns.sh $0 $@ diff=diff.tmp files=`echo $srcdir/*.c|head -20` @@ -25,12 +20,9 @@ old=/dev/null fromsig=fromsig.tmp fromlt=fromlt.tmp -echo -n `basename $0` ' ' - for from in $files do - echo from $from - hsencode $from $ltfile /dev/null + run_test hsencode $from $ltfile /dev/null # hsdecode $from # for new in $files diff --git a/test-cmds.sh b/test-cmds.sh index ce38dec..650bec7 100755 --- a/test-cmds.sh +++ b/test-cmds.sh @@ -6,18 +6,12 @@ # We expect the automake-generated Makefile to pass in $srcdir, but if we're # run from the commandline we may not have it. -if [ "$srcdir" = "" ] -then - srcdir=`dirname $0` -fi - -PATH=`cd $srcdir; pwd`:$PATH -cd $srcdir/test-cmds +source testfns.sh $0 $@ out=out.tmp cmds=cmds.txt tmp=bin.tmp -hsemit < $cmds > $tmp -hsinhale > $out < $tmp -diff -b -q $out $cmds +run_test hsemit < $cmds > $tmp +run_test hsinhale > $out < $tmp +run_test diff -b -q $out $cmds diff --git a/test-decode.sh b/test-decode.sh index 8e9a36f..d9efb32 100755 --- a/test-decode.sh +++ b/test-decode.sh @@ -6,15 +6,7 @@ # We expect the automake-generated Makefile to pass in $srcdir, but if we're # run from the commandline we may not have it. -echo -n `basename $0`': ' - -if [ "$srcdir" = "" ] -then - srcdir=`dirname $0` -fi - -PATH=`cd $srcdir; pwd`:$PATH -cd $srcdir/test-decode +source testfns.sh $0 $@ newsig=newsig.tmp out=out.tmp @@ -22,12 +14,9 @@ out=out.tmp for diff in ??-diff do id=`echo $diff|sed -e 's/-diff$//'` - echo -n $id ' ' old=$id-old - hsdecode $old $newsig $out $diff - cmp $out $id-new - cmp $newsig $id-sig -done - -echo
\ No newline at end of file + run_test hsdecode $old $newsig $out $diff + run_test cmp $out $id-new + run_test cmp $newsig $id-sig +done
\ No newline at end of file diff --git a/test-encode.sh b/test-encode.sh index 489c77d..5ba07fd 100755 --- a/test-encode.sh +++ b/test-encode.sh @@ -6,28 +6,17 @@ # We expect the automake-generated Makefile to pass in $srcdir, but if we're # run from the commandline we may not have it. -echo -n `basename $0`': ' - -if [ "$srcdir" = "" ] -then - srcdir=`dirname $0` -fi - -PATH=`cd $srcdir; pwd`:$PATH -cd $srcdir/test-encode +source testfns.sh $0 out=out.tmp for diff in ??-diff do id=`echo $diff|sed -e 's/-diff$//'` - echo -n $id ' ' new=$id-new sig=$id-sig expect=$id-out - hsencode $new $out $sig 32 - cmp $out $expect + run_test hsencode $new $out $sig 32 + run_test cmp $out $expect done - -echo
\ No newline at end of file diff --git a/test-seq.sh b/test-seq.sh index 174be28..2c65e42 100755 --- a/test-seq.sh +++ b/test-seq.sh @@ -1,4 +1,4 @@ -#! /bin/sh -pex +#! /bin/sh -pe # Regression test suite for libhsync. @@ -8,39 +8,22 @@ # with an empty signature, we generate the difference from one # file to another. -if [ "$srcdir" = "" ] -then - srcdir=`dirname $0` -fi -srcdir=`cd $srcdir; pwd` - -PATH=$srcdir:$PATH -testdir=$srcdir/test-seq -[ -d $testdir ] || mkdir $testdir -cd $testdir +source testfns.sh $0 files=`echo in-??` -echo -n `basename $0` ' ' - for old in $files do - echo -n '-' - hsencode $old lt.tmp /dev/null - hsdecode /dev/null sig.tmp old-out.tmp lt.tmp - cmp $old old-out.tmp + run_test hsencode $old lt.tmp /dev/null + run_test hsdecode /dev/null sig.tmp old-out.tmp lt.tmp + run_test cmp $old old-out.tmp for new in $files do if [ $old != $new ] then - echo -n '.' - hsencode $new lt.tmp sig.tmp - hsdecode $old /dev/null new-out.tmp lt.tmp - cmp $new new-out.tmp + run_test hsencode $new lt.tmp sig.tmp + run_test hsdecode $old /dev/null new-out.tmp lt.tmp + run_test cmp $new new-out.tmp fi done done - -echo - - diff --git a/test-thrice.sh b/test-thrice.sh index 971861a..8c99ca6 100755 --- a/test-thrice.sh +++ b/test-thrice.sh @@ -9,20 +9,6 @@ # `What I tell you three times is true' -if [ "$srcdir" = "" ] -then - srcdir=`dirname $0` -fi -srcdir=`cd $srcdir; pwd` - -PATH=$srcdir:$PATH - -testdir=$srcdir/test-thrice -[ -d $testdir ] || mkdir $testdir -cd $testdir - -echo -n `basename $0` ' ' - data=../INSTALL rm -f *.tmp |