Commit 038bda10 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Put variable checksum comparison into its own module.

parent 0441fcc7
......@@ -318,6 +318,8 @@ tests/test_cksum_nc4.in -text
tests/test_cksum_service.in -text
tests/test_grib.c -text
tests/test_grib.sh -text
tests/var_cksum.c -text
tests/var_cksum.h -text
util/mpi_launch_poe -text
util/serialrun.in -text
util/sunf95preproc-wrapper -text
......
......@@ -9,6 +9,7 @@ check_PROGRAMS = test_grib cksum_write cksum_read pio_write
test_grib_SOURCES = test_grib.c
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c \
var_cksum.c var_cksum.h \
cksum.c cksum.h \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c cksum.h cksum.c
......
......@@ -65,8 +65,8 @@ CONFIG_CLEAN_FILES = test_cksum_grib test_cksum_nc test_cksum_nc2 \
test_cksum_ieg pio_write_run pio_cksum_mpinonb \
pio_cksum_fpguard pio_cksum_asynch pio_cksum_writer
CONFIG_CLEAN_VPATH_FILES =
am_cksum_read_OBJECTS = cksum_read.$(OBJEXT) cksum.$(OBJEXT) \
ensure_array_size.$(OBJEXT)
am_cksum_read_OBJECTS = cksum_read.$(OBJEXT) var_cksum.$(OBJEXT) \
cksum.$(OBJEXT) ensure_array_size.$(OBJEXT)
cksum_read_OBJECTS = $(am_cksum_read_OBJECTS)
cksum_read_LDADD = $(LDADD)
cksum_read_DEPENDENCIES =
......@@ -290,6 +290,7 @@ TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
test_grib_SOURCES = test_grib.c
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c \
var_cksum.c var_cksum.h \
cksum.c cksum.h \
ensure_array_size.h ensure_array_size.c
......@@ -394,6 +395,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ensure_array_size.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_grib.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/var_cksum.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
......
......@@ -7,12 +7,7 @@
#include "cksum.h"
#include "ensure_array_size.h"
#include "pio_util.h"
struct cksum_table
{
int code;
uint32_t cksum;
};
#include "var_cksum.h"
struct varSize
{
......@@ -48,52 +43,6 @@ read_table(const char *table_fname, size_t *table_len)
}
static int
compare_checksums(struct cksum_table a[], size_t a_size, const char *src_a,
struct cksum_table b[], size_t b_size, const char *src_b)
{
int checked_a[a_size], checked_b[b_size];
size_t i, j;
int retcode = EXIT_SUCCESS;
for (i = 0; i < a_size; ++i)
checked_a[i] = 0;
for (j = 0; j < b_size; ++j)
checked_b[j] = 0;
for (j = 0; j < b_size; ++j)
for (i = 0; i < a_size; ++i)
if (a[i].code == b[j].code)
{
if (a[i].cksum != b[j].cksum)
{
fprintf(stderr, "checksum error for varID %d, code %d!\n"
"%08lx != %08lx\n", i, a[i].code,
(unsigned long)a[i].cksum, b[j].cksum);
retcode = EXIT_FAILURE;
}
checked_a[i] = 1;
checked_b[j] = 1;
break;
}
for (i = 0; i < a_size; ++i)
if (!checked_a[i])
{
fprintf(stderr, "variable %d, code %d from %s not checked!\n",
i, a[i].code, src_a);
retcode = EXIT_FAILURE;
}
for (j = 0; j < b_size; ++j)
if (!checked_b[j])
{
fprintf(stderr, "variable %d, code %d from %s not checked!\n",
j, b[j].code, src_b);
retcode = EXIT_FAILURE;
}
return retcode;
}
static struct cksum_table *
cksum_stream(const char *fname, size_t *table_len)
{
......@@ -246,9 +195,9 @@ int main(int argc, char *argv[])
= read_table(table_fname, &num_ref_entries);
if (num_ref_entries == -1)
exit(EXIT_FAILURE);
retcode = compare_checksums(file_vars, nvars, "file",
ref_var_table, num_ref_entries,
"reference table");
retcode
= compare_checksums(file_vars, nvars, "file",
ref_var_table, num_ref_entries, "reference table");
free(ref_var_table);
}
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "var_cksum.h"
#include <stdio.h>
#include <stdlib.h>
int
compare_checksums(struct cksum_table a[], size_t a_size, const char *src_a,
struct cksum_table b[], size_t b_size, const char *src_b)
{
int checked_a[a_size], checked_b[b_size];
size_t i, j;
int retcode = EXIT_SUCCESS;
for (i = 0; i < a_size; ++i)
checked_a[i] = 0;
for (j = 0; j < b_size; ++j)
checked_b[j] = 0;
for (j = 0; j < b_size; ++j)
for (i = 0; i < a_size; ++i)
if (a[i].code == b[j].code)
{
if (a[i].cksum != b[j].cksum)
{
fprintf(stderr, "checksum error for varID %d, code %d!\n"
"%08lx != %08lx\n", (int)i, a[i].code,
(unsigned long)a[i].cksum, (unsigned long)b[j].cksum);
retcode = EXIT_FAILURE;
}
checked_a[i] = 1;
checked_b[j] = 1;
break;
}
for (i = 0; i < a_size; ++i)
if (!checked_a[i])
{
fprintf(stderr, "variable %d, code %d from %s not checked!\n",
(int)i, a[i].code, src_a);
retcode = EXIT_FAILURE;
}
for (j = 0; j < b_size; ++j)
if (!checked_b[j])
{
fprintf(stderr, "variable %d, code %d from %s not checked!\n",
(int)j, b[j].code, src_b);
retcode = EXIT_FAILURE;
}
return retcode;
}
#ifndef VAR_CKSUM_H
#define VAR_CKSUM_H
#include <inttypes.h>
#include <stdlib.h>
struct cksum_table
{
int code;
uint32_t cksum;
};
/* returns EXIT_SUCCESS if a contains the same entries with the same
* checksums as b, EXIT_FAILURE otherwise */
int
compare_checksums(struct cksum_table a[], size_t a_size, const char *src_a,
struct cksum_table b[], size_t b_size, const char *src_b);
#endif
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