Whamcloud - gitweb
tests: create crcsum progam to support resizing tests
authorTheodore Ts'o <tytso@mit.edu>
Mon, 1 Apr 2013 00:31:46 +0000 (20:31 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 1 Apr 2013 00:41:23 +0000 (20:41 -0400)
The only checksum program which we can reliably count upon being
installed on all systems is "sum", which is not a particular robust
checksum.  The problem with using md5sum or sha1sum is it hat it may
not be installed on all systems.  So create a crcsum program which is
used so we can validate that a data file on a resized file system has
not been corrupted.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
tests/progs/Makefile.in
tests/progs/crcsum.c [new file with mode: 0644]
tests/test_config

index 0e28192..e3c1ef4 100644 (file)
@@ -13,7 +13,7 @@ INSTALL = @INSTALL@
 
 MK_CMDS=       _SS_DIR_OVERRIDE=../../lib/ss ../../lib/ss/mk_cmds
 
-PROGS=         test_icount
+PROGS=         test_icount crcsum
 
 TEST_REL_OBJS= test_rel.o test_rel_cmds.o
 
@@ -34,6 +34,10 @@ test_rel: $(TEST_REL_OBJS) $(DEPLIBS)
        $(E) "  LD $@"
        $(Q) $(LD) $(ALL_LDFLAGS) -o test_rel $(TEST_REL_OBJS) $(LIBS)
 
+crcsum: crcsum.o $(DEPLIBS)
+       $(E) "  LD $@"
+       $(Q) $(LD) $(ALL_LDFLAGS) -o crcsum crcsum.o $(LIBS)
+
 test_rel_cmds.c: test_rel_cmds.ct
        $(E) "  MK_CMDS $@"
        $(Q) $(MK_CMDS) $(srcdir)/test_rel_cmds.ct
diff --git a/tests/progs/crcsum.c b/tests/progs/crcsum.c
new file mode 100644 (file)
index 0000000..bee979b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * crcsum.c
+ *
+ * Copyright (C) 2013 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+#include <fcntl.h>
+
+#include "et/com_err.h"
+#include "ss/ss.h"
+#include "ext2fs/ext2fs.h"
+
+
+int main(int argc, char **argv)
+{
+       int             c;
+       uint32_t        crc = ~0;
+       uint32_t        (*csum_func)(uint32_t crc, unsigned char const *p,
+                                    size_t len);
+       FILE            *f;
+
+       csum_func = ext2fs_crc32c_le;
+
+       while ((c = getopt (argc, argv, "B")) != EOF) {
+               switch (c) {
+               case 'B':
+                       csum_func = ext2fs_crc32c_be;
+                       break;
+               default:
+                       com_err(argv[0], 0, "Usage: crcsum [-b] [file]\n");
+                       return 1;
+               }
+       }
+
+       if (optind == argc)
+               f = stdin;
+       else {
+               f = fopen(argv[optind], "r");
+               if (!f) {
+                       com_err(argv[0], errno, "while trying to open %s\n",
+                               argv[optind]);
+                       exit(1);
+               }
+       }
+
+       while (!feof(f)) {
+               unsigned char buf[4096];
+
+               int c = fread(buf, 1, sizeof(buf), f);
+
+               if (c)
+                       crc = csum_func(crc, buf, c);
+       }
+       printf("%u\n", crc);
+       return 0;
+}
index 0ba8b5e..36b53b7 100644 (file)
@@ -19,6 +19,7 @@ RESIZE2FS="$USE_VALGRIND $RESIZE2FS_EXE"
 E2UNDO_EXE="../misc/e2undo"
 TEST_REL=../tests/progs/test_rel
 TEST_ICOUNT=../tests/progs/test_icount
+CRCSUM=../tests/progs/crcsum
 LD_LIBRARY_PATH=../lib:../lib/ext2fs:../lib/e2p:../lib/et:../lib/ss
 DYLD_LIBRARY_PATH=../lib:../lib/ext2fs:../lib/e2p:../lib/et:../lib/ss
 export LD_LIBRARY_PATH