Commit 6c8e51d1 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add verification of crc function.

parent 7fe861f2
......@@ -324,6 +324,7 @@ tests/Makefile.in -text
tests/cksum.c -text
tests/cksum.h -text
tests/cksum_read.c -text
tests/cksum_verify.c -text
tests/cksum_write.c -text
tests/cksum_write_chunk.c -text
tests/ensure_array_size.c -text
......
## Process this file with automake to produce Makefile.in
#
TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
TESTS = test_grib.sh cksum_verify \
test_cksum_grib test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg \
test_chunk_cksum \
pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
test_resource_copy
check_PROGRAMS = test_grib cksum_write cksum_read pio_write \
check_PROGRAMS = cksum_verify test_grib cksum_write cksum_read pio_write \
test_resource_copy cksum_write_chunk
#
test_grib_SOURCES = test_grib.c
cksum_verify_SOURCES = cksum_verify.c cksum.c cksum.h
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_write_chunk_SOURCES = cksum_write_chunk.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c \
......
......@@ -50,13 +50,14 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 \
test_cksum_ieg test_chunk_cksum pio_write_run \
pio_cksum_mpinonb pio_cksum_fpguard pio_cksum_asynch \
pio_cksum_writer pio_cksum_cdf test_resource_copy$(EXEEXT)
check_PROGRAMS = test_grib$(EXEEXT) cksum_write$(EXEEXT) \
cksum_read$(EXEEXT) pio_write$(EXEEXT) \
TESTS = test_grib.sh cksum_verify$(EXEEXT) test_cksum_grib \
test_cksum_nc test_cksum_extra test_cksum_service \
test_cksum_nc2 test_cksum_nc4 test_cksum_ieg test_chunk_cksum \
pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
test_resource_copy$(EXEEXT)
check_PROGRAMS = cksum_verify$(EXEEXT) test_grib$(EXEEXT) \
cksum_write$(EXEEXT) cksum_read$(EXEEXT) pio_write$(EXEEXT) \
test_resource_copy$(EXEEXT) cksum_write_chunk$(EXEEXT)
subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
......@@ -96,6 +97,10 @@ am_cksum_read_OBJECTS = cksum_read.$(OBJEXT) var_cksum.$(OBJEXT) \
cksum_read_OBJECTS = $(am_cksum_read_OBJECTS)
cksum_read_LDADD = $(LDADD)
cksum_read_DEPENDENCIES = ../src/libcdi.la
am_cksum_verify_OBJECTS = cksum_verify.$(OBJEXT) cksum.$(OBJEXT)
cksum_verify_OBJECTS = $(am_cksum_verify_OBJECTS)
cksum_verify_LDADD = $(LDADD)
cksum_verify_DEPENDENCIES = ../src/libcdi.la
am_cksum_write_OBJECTS = cksum_write.$(OBJEXT) cksum.$(OBJEXT)
cksum_write_OBJECTS = $(am_cksum_write_OBJECTS)
cksum_write_LDADD = $(LDADD)
......@@ -130,12 +135,14 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(cksum_write_chunk_SOURCES) $(pio_write_SOURCES) \
$(test_grib_SOURCES) $(test_resource_copy_SOURCES)
DIST_SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(cksum_write_chunk_SOURCES) $(pio_write_SOURCES) \
$(test_grib_SOURCES) $(test_resource_copy_SOURCES)
SOURCES = $(cksum_read_SOURCES) $(cksum_verify_SOURCES) \
$(cksum_write_SOURCES) $(cksum_write_chunk_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES)
DIST_SOURCES = $(cksum_read_SOURCES) $(cksum_verify_SOURCES) \
$(cksum_write_SOURCES) $(cksum_write_chunk_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
......@@ -333,6 +340,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#
test_grib_SOURCES = test_grib.c
cksum_verify_SOURCES = cksum_verify.c cksum.c cksum.h
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_write_chunk_SOURCES = cksum_write_chunk.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c \
......@@ -425,6 +433,9 @@ clean-checkPROGRAMS:
cksum_read$(EXEEXT): $(cksum_read_OBJECTS) $(cksum_read_DEPENDENCIES) $(EXTRA_cksum_read_DEPENDENCIES)
@rm -f cksum_read$(EXEEXT)
$(LINK) $(cksum_read_OBJECTS) $(cksum_read_LDADD) $(LIBS)
cksum_verify$(EXEEXT): $(cksum_verify_OBJECTS) $(cksum_verify_DEPENDENCIES) $(EXTRA_cksum_verify_DEPENDENCIES)
@rm -f cksum_verify$(EXEEXT)
$(LINK) $(cksum_verify_OBJECTS) $(cksum_verify_LDADD) $(LIBS)
cksum_write$(EXEEXT): $(cksum_write_OBJECTS) $(cksum_write_DEPENDENCIES) $(EXTRA_cksum_write_DEPENDENCIES)
@rm -f cksum_write$(EXEEXT)
$(LINK) $(cksum_write_OBJECTS) $(cksum_write_LDADD) $(LIBS)
......@@ -449,6 +460,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_read.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_verify.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write_chunk.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ensure_array_size.Po@am__quote@
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cksum.h"
enum {
block_size = 16,
};
int
main()
{
unsigned char *test_data, *init_block;
size_t num_blocks = 1000;
if (!(init_block = calloc(block_size * block_size, 1U))
|| !(test_data = calloc((size_t)block_size * num_blocks, 1U)))
return EXIT_FAILURE;
/* this is supposed to be non-random */
srand48(5L);
init_block[7] = 15U;
/* repeat block and rotate */
for (size_t i = 1; i < block_size; ++i)
{
memcpy(init_block + block_size * i,
init_block + block_size - i, i);
memcpy(init_block + block_size * i + i, init_block,
block_size - i);
}
for (size_t i = 0; i < num_blocks; ++i)
{
size_t block_idx = ((size_t)lrand48()) % block_size;
memcpy(test_data + i, init_block + block_idx * block_size,
block_size);
}
uint32_t cksum_result = memcrc(test_data, num_blocks * block_size);
if (cksum_result != UINT32_C(0xc47779cd))
{
printf("unexpected crc result: 0x%8"PRIx32"\n", cksum_result);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment