Commit cbf3dd65 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add uuid generation to test programs.

parent 24c809b0
......@@ -341,6 +341,8 @@ tests/cksum_read.c -text
tests/cksum_verify.c -text
tests/cksum_write.c -text
tests/cksum_write_chunk.c -text
tests/create_uuid.c -text
tests/create_uuid.h -text
tests/deco2d_model.c -text
tests/ensure_array_size.c -text
tests/ensure_array_size.h -text
......
......@@ -338,6 +338,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
THREADS_LIBS = @THREADS_LIBS@
USER_NAME = @USER_NAME@
USE_MPI = @USE_MPI@
UUID_C_LIB = @UUID_C_LIB@
VERSION = @VERSION@
YAXT_CFLAGS = @YAXT_CFLAGS@
YAXT_LIBS = @YAXT_LIBS@
......
......@@ -311,6 +311,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
THREADS_LIBS = @THREADS_LIBS@
USER_NAME = @USER_NAME@
USE_MPI = @USE_MPI@
UUID_C_LIB = @UUID_C_LIB@
VERSION = @VERSION@
YAXT_CFLAGS = @YAXT_CFLAGS@
YAXT_LIBS = @YAXT_LIBS@
......
......@@ -699,6 +699,7 @@ ax_pthread_config
SYSTEM_TYPE
HOST_NAME
USER_NAME
UUID_C_LIB
AS
CXXCPP
am__fastdepCXX_FALSE
......@@ -24323,24 +24324,13 @@ fi
 
# ----------------------------------------------------------------------
# Checks for header files
for ac_header in malloc.h
for ac_header in malloc.h execinfo.h uuid.h uuid/uuid.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "malloc.h" "ac_cv_header_malloc_h" "$ac_includes_default"
if test "x$ac_cv_header_malloc_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_MALLOC_H 1
_ACEOF
fi
done
for ac_header in execinfo.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "execinfo.h" "ac_cv_header_execinfo_h" "$ac_includes_default"
if test "x$ac_cv_header_execinfo_h" = xyes; then :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_EXECINFO_H 1
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
 
fi
......@@ -24371,6 +24361,89 @@ _ACEOF
fi
done
 
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid_generate in -luuid" >&5
$as_echo_n "checking for uuid_generate in -luuid... " >&6; }
if ${ac_cv_lib_uuid_uuid_generate+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-luuid $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char uuid_generate ();
int
main ()
{
return uuid_generate ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_uuid_uuid_generate=yes
else
ac_cv_lib_uuid_uuid_generate=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_uuid_uuid_generate" >&5
$as_echo "$ac_cv_lib_uuid_uuid_generate" >&6; }
if test "x$ac_cv_lib_uuid_uuid_generate" = xyes; then :
ac_fn_c_check_decl "$LINENO" "uuid_generate" "ac_cv_have_decl_uuid_generate" "$ac_includes_default
#include <uuid/uuid.h>
"
if test "x$ac_cv_have_decl_uuid_generate" = xyes; then :
ac_have_decl=1
else
ac_have_decl=0
fi
cat >>confdefs.h <<_ACEOF
#define HAVE_DECL_UUID_GENERATE $ac_have_decl
_ACEOF
if test $ac_have_decl = 1; then :
UUID_C_LIB=-luuid
fi
else
for ac_func in uuid_create
do :
ac_fn_c_check_func "$LINENO" "uuid_create" "ac_cv_func_uuid_create"
if test "x$ac_cv_func_uuid_create" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_UUID_CREATE 1
_ACEOF
ac_fn_c_check_decl "$LINENO" "uuid_create" "ac_cv_have_decl_uuid_create" "$ac_includes_default
#include <uuid.h>
"
if test "x$ac_cv_have_decl_uuid_create" = xyes; then :
ac_have_decl=1
else
ac_have_decl=0
fi
cat >>confdefs.h <<_ACEOF
#define HAVE_DECL_UUID_CREATE $ac_have_decl
_ACEOF
if test $ac_have_decl = 1; then :
UUID_C_LIB=""
fi
fi
done
fi
# ----------------------------------------------------------------------
# Checks for the availability of ANSI-C99 functions
ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "$ac_includes_default
......
......@@ -64,12 +64,20 @@ AC_CHECK_LIB(malloc, malloc)
AC_CHECK_MEMBERS([struct stat.st_blksize])
# ----------------------------------------------------------------------
# Checks for header files
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(execinfo.h)
AC_CHECK_HEADERS([malloc.h execinfo.h uuid.h uuid/uuid.h])
# ----------------------------------------------------------------------
# Checks for the availability of functions
AC_CHECK_FUNCS([mallinfo])
AC_CHECK_FUNCS([getline])
AC_CHECK_LIB([uuid],[uuid_generate],
[AC_CHECK_DECLS([uuid_generate],
[UUID_C_LIB=-luuid],,[AC_INCLUDES_DEFAULT
@%:@include <uuid/uuid.h>])],
[AC_CHECK_FUNCS([uuid_create],
[AC_CHECK_DECLS([uuid_create],
[UUID_C_LIB=""],,[AC_INCLUDES_DEFAULT
@%:@include <uuid.h>])])])
AC_SUBST([UUID_C_LIB])
# ----------------------------------------------------------------------
# Checks for the availability of ANSI-C99 functions
AC_CHECK_DECLS([isnan],,,[AC_INCLUDES_DEFAULT
......
......@@ -359,6 +359,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
THREADS_LIBS = @THREADS_LIBS@
USER_NAME = @USER_NAME@
USE_MPI = @USE_MPI@
UUID_C_LIB = @UUID_C_LIB@
VERSION = @VERSION@
YAXT_CFLAGS = @YAXT_CFLAGS@
YAXT_LIBS = @YAXT_LIBS@
......
......@@ -353,6 +353,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
THREADS_LIBS = @THREADS_LIBS@
USER_NAME = @USER_NAME@
USE_MPI = @USE_MPI@
UUID_C_LIB = @UUID_C_LIB@
VERSION = @VERSION@
YAXT_CFLAGS = @YAXT_CFLAGS@
YAXT_LIBS = @YAXT_LIBS@
......
......@@ -337,6 +337,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
THREADS_LIBS = @THREADS_LIBS@
USER_NAME = @USER_NAME@
USE_MPI = @USE_MPI@
UUID_C_LIB = @UUID_C_LIB@
VERSION = @VERSION@
YAXT_CFLAGS = @YAXT_CFLAGS@
YAXT_LIBS = @YAXT_LIBS@
......
......@@ -364,6 +364,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
THREADS_LIBS = @THREADS_LIBS@
USER_NAME = @USER_NAME@
USE_MPI = @USE_MPI@
UUID_C_LIB = @UUID_C_LIB@
VERSION = @VERSION@
YAXT_CFLAGS = @YAXT_CFLAGS@
YAXT_LIBS = @YAXT_LIBS@
......
......@@ -16,6 +16,14 @@
*/
#undef HAVE_DECL_ISNAN
/* Define to 1 if you have the declaration of `uuid_create', and to 0 if you
don't. */
#undef HAVE_DECL_UUID_CREATE
/* Define to 1 if you have the declaration of `uuid_generate', and to 0 if you
don't. */
#undef HAVE_DECL_UUID_GENERATE
/* Define to 1 if you have the declaration of `__builtin_ctz', and to 0 if you
don't. */
#undef HAVE_DECL___BUILTIN_CTZ
......@@ -167,6 +175,15 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `uuid_create' function. */
#undef HAVE_UUID_CREATE
/* Define to 1 if you have the <uuid.h> header file. */
#undef HAVE_UUID_H
/* Define to 1 if you have the <uuid/uuid.h> header file. */
#undef HAVE_UUID_UUID_H
/* yaxt library is available */
#undef HAVE_YAXT
......
......@@ -22,24 +22,26 @@ cksum_read_SOURCES = cksum_read.c \
stream_cksum.c stream_cksum.h \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
simple_model_helper.h simple_model_helper.c
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
simple_model_helper.h simple_model_helper.c
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
test_resource_copy_SOURCES = test_resource_copy.c \
$(top_srcdir)/src/resource_unpack.c
test_resource_copy_mpi_SOURCES = test_resource_copy.c
#
AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS)
if USE_MPI
pio_write_LDADD = ../src/libcdipio.la
pio_write_deco2d_LDADD = ../src/libcdipio.la
pio_write_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
pio_write_deco2d_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
TESTS += test_resource_copy_mpi_run
check_PROGRAMS += test_resource_copy_mpi
test_resource_copy_mpi_LDADD = ../src/libcdipio.la
test_resource_copy_mpi_CFLAGS = $(AM_CFLAGS) $(CFLAGS) -DMPI_MARSHALLING
else
pio_write_LDADD = $(LDADD)
pio_write_deco2d_LDADD = $(LDADD)
pio_write_LDADD = $(LDADD) $(UUID_C_LIB)
pio_write_deco2d_LDADD = $(LDADD) $(UUID_C_LIB)
endif
LDADD = ../src/libcdi.la -lm
......
......@@ -153,16 +153,22 @@ cksum_write_chunk_OBJECTS = $(am_cksum_write_chunk_OBJECTS)
cksum_write_chunk_LDADD = $(LDADD)
cksum_write_chunk_DEPENDENCIES = ../src/libcdi.la
am_pio_write_OBJECTS = pio_write.$(OBJEXT) simple_model.$(OBJEXT) \
simple_model_helper.$(OBJEXT)
simple_model_helper.$(OBJEXT) create_uuid.$(OBJEXT)
pio_write_OBJECTS = $(am_pio_write_OBJECTS)
am__DEPENDENCIES_1 = ../src/libcdi.la
@USE_MPI_FALSE@pio_write_DEPENDENCIES = $(am__DEPENDENCIES_1)
@USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la
am__DEPENDENCIES_2 =
@USE_MPI_FALSE@pio_write_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@USE_MPI_FALSE@ $(am__DEPENDENCIES_2)
@USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la \
@USE_MPI_TRUE@ $(am__DEPENDENCIES_2)
am_pio_write_deco2d_OBJECTS = pio_write.$(OBJEXT) \
deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT)
deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT) \
create_uuid.$(OBJEXT)
pio_write_deco2d_OBJECTS = $(am_pio_write_deco2d_OBJECTS)
@USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1)
@USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la
@USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@USE_MPI_FALSE@ $(am__DEPENDENCIES_2)
@USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la \
@USE_MPI_TRUE@ $(am__DEPENDENCIES_2)
am_test_grib_OBJECTS = test_grib.$(OBJEXT)
test_grib_OBJECTS = $(am_test_grib_OBJECTS)
test_grib_LDADD = $(LDADD)
......@@ -396,6 +402,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
THREADS_LIBS = @THREADS_LIBS@
USER_NAME = @USER_NAME@
USE_MPI = @USE_MPI@
UUID_C_LIB = @UUID_C_LIB@
VERSION = @VERSION@
YAXT_CFLAGS = @YAXT_CFLAGS@
YAXT_LIBS = @YAXT_LIBS@
......@@ -470,10 +477,12 @@ cksum_read_SOURCES = cksum_read.c \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
simple_model_helper.h simple_model_helper.c
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
simple_model_helper.h simple_model_helper.c
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
test_resource_copy_SOURCES = test_resource_copy.c \
$(top_srcdir)/src/resource_unpack.c
......@@ -481,10 +490,10 @@ test_resource_copy_SOURCES = test_resource_copy.c \
test_resource_copy_mpi_SOURCES = test_resource_copy.c
#
AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS)
@USE_MPI_FALSE@pio_write_LDADD = $(LDADD)
@USE_MPI_TRUE@pio_write_LDADD = ../src/libcdipio.la
@USE_MPI_FALSE@pio_write_deco2d_LDADD = $(LDADD)
@USE_MPI_TRUE@pio_write_deco2d_LDADD = ../src/libcdipio.la
@USE_MPI_FALSE@pio_write_LDADD = $(LDADD) $(UUID_C_LIB)
@USE_MPI_TRUE@pio_write_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
@USE_MPI_FALSE@pio_write_deco2d_LDADD = $(LDADD) $(UUID_C_LIB)
@USE_MPI_TRUE@pio_write_deco2d_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
@USE_MPI_TRUE@test_resource_copy_mpi_LDADD = ../src/libcdipio.la
@USE_MPI_TRUE@test_resource_copy_mpi_CFLAGS = $(AM_CFLAGS) $(CFLAGS) -DMPI_MARSHALLING
LDADD = ../src/libcdi.la -lm
......@@ -619,6 +628,7 @@ distclean-compile:
@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)/create_uuid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/deco2d_model.Po@am__quote@
@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@
......
......@@ -216,6 +216,28 @@ main(int argc, char *argv[])
zaxisID[1] = zaxisCreate(ZAXIS_PRESSURE, nlev);
zaxisDefLevels(zaxisID[1], levs);
/* add uuids to zaxis and grid */
{
unsigned char uuid[16];
int str2uuid(const char *uuidstr, unsigned char *uuid);
static char gridUUIDTxt[] = "107d7a5b-348c-4d1a-90a9-d745914f2fb6";
str2uuid(gridUUIDTxt, uuid);
gridDefUUID(gridID, uuid);
static char zaxisUUIDTxt[2][37] = {
{ "d157f399-5496-4097-a3d8-437a6dda6311" },
{ "6f784a65-bce8-48c9-afa4-4c40130709c7" }
};
for (int i = 0; i < 2; ++i)
{
str2uuid(zaxisUUIDTxt[i], uuid);
zaxisDefUUID(zaxisID[i], uuid);
}
}
// Create a Time axis
taxisID = taxisCreate(TAXIS_ABSOLUTE);
......@@ -241,7 +263,7 @@ main(int argc, char *argv[])
// Assign the Time axis to the variable list
vlistDefTaxis(vlistID, taxisID);
// Create a dataset in netCDF fromat
// Create a dataset
{
char *fname = fname_create(prefix, suffix);
if ((streamID = streamOpenWrite(fname, filetype)) < 0)
......
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#define _XOPEN_SOURCE 600
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "create_uuid.h"
#ifdef HAVE_DECL_UUID_GENERATE
#include <sys/time.h>
#include <uuid/uuid.h>
void
create_uuid(unsigned char *uuid)
{
static int uuid_seeded = 0;
static char uuid_rand_state[31 * sizeof (long)];
char *caller_rand_state;
if (uuid_seeded)
caller_rand_state = setstate(uuid_rand_state);
else
{
struct timeval tv;
int status = gettimeofday(&tv, NULL);
if (status != 0)
{
perror("uuid random seed generation failed!");
exit(1);
}
unsigned seed = (unsigned)(tv.tv_sec ^ tv.tv_usec);
caller_rand_state = initstate(seed, uuid_rand_state,
sizeof (uuid_rand_state));
uuid_seeded = 1;
}
uuid_generate(uuid);
setstate(caller_rand_state);
}
#elif defined (HAVE_DECL_UUID_CREATE)
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
#include <uuid.h>
void
create_uuid(unsigned char *uuid)
{
unsigned32 status;
uuid_create((uuid_t *)uuid, &status);
if (status == -1)
{
perror("uuid generation failed!");
exit(1);
}
}
#else
#include <sys/time.h>
void
create_uuid(unsigned char *uuid)
{
static int uuid_seeded = 0;
static char uuid_rand_state[31 * sizeof (long)];
char *caller_rand_state;
if (uuid_seeded)
caller_rand_state = setstate(uuid_rand_state);
else
{
struct timeval tv;
int status = gettimeofday(&tv, NULL);
if (status != 0)
{
perror("failed seed generation!");
exit(1);
}
unsigned seed = tv.tv_sec ^ tv.tv_usec;
caller_rand_state = initstate(seed, uuid_rand_state,
sizeof (uuid_rand_state));
uuid_seeded = 1;
}
for (size_t i = 0; i < CDI_UUID_SIZE; ++i)
uuid[i] = (unsigned char)random();
/* encode variant into msb of octet 8 */
uuid[8] = (unsigned char)((uuid[8] & 0x3f) | (1 << 7));
/* encode version 4 ((pseudo-)random uuid) into msb of octet 7 */
uuid[7] = (unsigned char)((uuid[7] & 0x0f) | (4 << 4));
setstate(caller_rand_state);
}
#endif
#ifndef CREATE_UUID_H
#define CREATE_UUID_H
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include "cdi.h"
void
create_uuid(unsigned char uuid[CDI_UUID_SIZE]);
#endif
......@@ -29,6 +29,7 @@ typedef int MPI_Comm;
#include "pio_write.h"
#include "simple_model_helper.h"
#include "create_uuid.h"
enum {
ntfiles = 2,
......@@ -114,7 +115,15 @@ modelRun(struct model_config setup, MPI_Comm comm)
lats[i] = ((double)(i * 180))/nlat - 90.0;
gridDefXvals ( gridID, lons );
gridDefYvals ( gridID, lats );
{
unsigned char uuid[CDI_UUID_SIZE];
if (rank == 0)
create_uuid(uuid);
#if USE_MPI
MPI_Bcast(uuid, CDI_UUID_SIZE, MPI_UNSIGNED_CHAR, 0, comm);
#endif
gridDefUUID(gridID, uuid);
}
levs = xmalloc((size_t)setup.max_nlev * sizeof (levs[0]));
for (i = 0; i < setup.max_nlev; ++i)
levs[i] = 101300.0
......@@ -146,9 +155,23 @@ modelRun(struct model_config setup, MPI_Comm comm)
varDesc[varIdx].zaxisID = varDesc[i].zaxisID;
goto zaxisIDset;
}
varDesc[varIdx].zaxisID
= zaxisCreate(ZAXIS_PRESSURE, varDesc[varIdx].nlev);
zaxisDefLevels(varDesc[varIdx].zaxisID, levs);
if (varLevs == 1)
varDesc[varIdx].zaxisID = zaxisCreate(ZAXIS_SURFACE, 1);
else
{
varDesc[varIdx].zaxisID
= zaxisCreate(ZAXIS_PRESSURE, varDesc[varIdx].nlev);
zaxisDefLevels(varDesc[varIdx].zaxisID, levs);
}
{
unsigned char uuid[16];
if (rank == 0)
create_uuid(uuid);
#if USE_MPI
MPI_Bcast(uuid, CDI_UUID_SIZE, MPI_UNSIGNED_CHAR, 0, comm);
#endif
zaxisDefUUID(varDesc[varIdx].zaxisID, uuid);
}
zaxisIDset:
varDesc[varIdx].id
= vlistDefVar(vlistID, gridID, varDesc[varIdx].zaxisID, TIME_VARIABLE);
......
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