summaryrefslogtreecommitdiffstats
path: root/test/tchecksum.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-08-21 23:27:11 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-08-21 23:27:11 (GMT)
commit5fe34046c00065fdc10eb1b6b04309aaaf110331 (patch)
tree94a62100b7a8499c511430f0e8bda33434f8bee2 /test/tchecksum.c
parent6bbe1283673ab7b151d751cb2df409f5babb47b4 (diff)
downloadhdf5-5fe34046c00065fdc10eb1b6b04309aaaf110331.zip
hdf5-5fe34046c00065fdc10eb1b6b04309aaaf110331.tar.gz
hdf5-5fe34046c00065fdc10eb1b6b04309aaaf110331.tar.bz2
[svn-r12605] Description:
Break out a bunch of the misc. routines that were in src/H5.c into more specific modules. Add optimized fletcher32 checksum routine, for checksumming metadata as well as raw data. Tested On: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2) Will test further after checkin...
Diffstat (limited to 'test/tchecksum.c')
-rw-r--r--test/tchecksum.c194
1 files changed, 194 insertions, 0 deletions
diff --git a/test/tchecksum.c b/test/tchecksum.c
new file mode 100644
index 0000000..ff49294
--- /dev/null
+++ b/test/tchecksum.c
@@ -0,0 +1,194 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*-------------------------------------------------------------------------
+ *
+ * Created: tchecksum.c
+ * Aug 21 2006
+ * Quincey Koziol <koziol@hdfgroup.org>
+ *
+ * Purpose: Test internal checksum routine(s)
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/***********/
+/* Headers */
+/***********/
+#include "testhdf5.h"
+
+/**********/
+/* Macros */
+/**********/
+#define BUF_LEN 3093 /* No particular value */
+
+/*******************/
+/* Local variables */
+/*******************/
+uint8_t large_buf[BUF_LEN];
+
+
+/****************************************************************
+**
+** test_chksum_size_one(): Checksum 1 byte buffer
+**
+****************************************************************/
+static void
+test_chksum_size_one(void)
+{
+ uint8_t buf[1] = {23}; /* Buffer to checksum */
+ uint32_t chksum; /* Checksum value */
+
+ /* Buffer w/real data */
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0x17001700, "H5_fletcher32");
+
+ /* Buffer w/zero(s) for data */
+ HDmemset(buf, 0, sizeof(buf));
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+} /* test_chksum_size_one() */
+
+
+/****************************************************************
+**
+** test_chksum_size_two(): Checksum 2 byte buffer
+**
+****************************************************************/
+static void
+test_chksum_size_two(void)
+{
+ uint8_t buf[2] = {23, 187}; /* Buffer to checksum */
+ uint32_t chksum; /* Checksum value */
+
+ /* Buffer w/real data */
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0x17bb17bb, "H5_fletcher32");
+
+ /* Buffer w/zero(s) for data */
+ HDmemset(buf, 0, sizeof(buf));
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+} /* test_chksum_size_two() */
+
+
+/****************************************************************
+**
+** test_chksum_size_three(): Checksum 3 byte buffer
+**
+****************************************************************/
+static void
+test_chksum_size_three(void)
+{
+ uint8_t buf[3] = {23, 187, 98}; /* Buffer to checksum */
+ uint32_t chksum; /* Checksum value */
+
+ /* Buffer w/real data */
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0x917679bb, "H5_fletcher32");
+
+ /* Buffer w/zero(s) for data */
+ HDmemset(buf, 0, sizeof(buf));
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+} /* test_chksum_size_three() */
+
+
+/****************************************************************
+**
+** test_chksum_size_four(): Checksum 4 byte buffer
+**
+****************************************************************/
+static void
+test_chksum_size_four(void)
+{
+ uint8_t buf[4] = {23, 187, 98, 217};/* Buffer to checksum */
+ uint32_t chksum; /* Checksum value */
+
+ /* Buffer w/real data */
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0x924f7a94, "H5_fletcher32");
+
+ /* Buffer w/zero(s) for data */
+ HDmemset(buf, 0, sizeof(buf));
+ chksum = H5_fletcher32(buf, sizeof(buf));
+ VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+} /* test_chksum_size_four() */
+
+
+/****************************************************************
+**
+** test_chksum_large(): Checksum larger buffer
+**
+****************************************************************/
+static void
+test_chksum_large(void)
+{
+ uint32_t chksum; /* Checksum value */
+ size_t u; /* Local index variable */
+
+ /* Initialize buffer w/known data */
+ for(u = 0; u < BUF_LEN; u++)
+ large_buf[u] = u * 3;
+
+ /* Buffer w/real data */
+ chksum = H5_fletcher32(large_buf, sizeof(large_buf));
+ VERIFY(chksum, 0x85b4e2a, "H5_fletcher32");
+
+ /* Buffer w/zero(s) for data */
+ HDmemset(large_buf, 0, sizeof(large_buf));
+ chksum = H5_fletcher32(large_buf, sizeof(large_buf));
+ VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+} /* test_chksum_large() */
+
+
+/****************************************************************
+**
+** test_checksum(): Main checksum testing routine.
+**
+****************************************************************/
+void
+test_checksum(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing checksum algorithm\n"));
+
+ /* Various checks for fletcher32 checksum algorithm */
+ test_chksum_size_one(); /* Test buffer w/only 1 byte */
+ test_chksum_size_two(); /* Test buffer w/only 2 bytes */
+ test_chksum_size_three(); /* Test buffer w/only 3 bytes */
+ test_chksum_size_four(); /* Test buffer w/only 4 bytes */
+ test_chksum_large(); /* Test buffer w/larger # of bytes */
+
+} /* test_checksum() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: cleanup_checksum
+ *
+ * Purpose: Cleanup temporary test files
+ *
+ * Return: none
+ *
+ * Programmer: Quincey Koziol
+ * August 21, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+cleanup_checksum(void)
+{
+ /* no file to clean */
+}
+