1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 12:43:55 +01:00

Add testing for for external arrays in HDF5 back end

This commit is contained in:
q-posev 2023-05-07 16:03:57 +02:00
parent 8da662772c
commit 1b689d9d69
No known key found for this signature in database
3 changed files with 149 additions and 2 deletions

View File

@ -37,7 +37,7 @@ CLEANFILES = trexio.mod
if HAVE_FORTRAN
BUILT_SOURCES = trexio.mod
else
BUILT_SOURCES =
BUILT_SOURCES =
endif
EXTRA_DIST = .git_hash
@ -116,6 +116,7 @@ TESTS_C += \
tests/io_dset_float_hdf5 \
tests/io_dset_int_hdf5 \
tests/io_dset_sparse_hdf5 \
tests/io_dset_external_hdf5 \
tests/io_determinant_hdf5 \
tests/io_jastrow_hdf5 \
tests/io_safe_dset_float_hdf5 \
@ -303,7 +304,7 @@ DEB_FILES = \
helpers-debian/libtrexio0.install \
helpers-debian/libtrexio-dev.install \
helpers-debian/source \
helpers-debian/README.source
helpers-debian/README.source
debian_from_dist: $(DEB_FILES) $(SOURCES) $(trexio_h)
cp ../trexio-$(PACKAGE_VERSION).tar.gz ../libtrexio_$(PACKAGE_VERSION).orig.tar.gz

View File

@ -24,6 +24,7 @@ if(ENABLE_HDF5)
io_dset_float_hdf5
io_dset_str_hdf5
io_dset_sparse_hdf5
io_dset_external_hdf5
io_determinant_hdf5
io_safe_dset_float_hdf5
io_dset_int_hdf5

View File

@ -0,0 +1,145 @@
#include "trexio.h"
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define TEST_BACKEND TREXIO_HDF5
#define TREXIO_FILE "test_dset_external.h5"
#define RM_COMMAND "rm -f -- " TREXIO_FILE
#define VECTOR_NAME "test external vector"
#define MATRIX_NAME "test external matrix"
static int test_write_dset (const char* file_name, const back_end_t backend) {
/* Try to write a dataset with numerical (int) values into the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
// parameters to be written
uint32_t rank_v = 1;
uint64_t dims_v[1] = {12};
int32_t vector[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
uint32_t rank_m = 2;
uint64_t dims_m[2] = {3, 4};
int32_t matrix[12] = {
0 , 1 , 2 ,
3 , 4 , 5 ,
6 , 7 , 8 ,
9 , 10 , 11
};
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'w', backend, &rc);
assert (file != NULL);
// write numerical (int32) vector in an external group of the file
rc = trexio_write_external_int32_array(file, vector, rank_v, dims_v, VECTOR_NAME);
assert (rc == TREXIO_SUCCESS);
// write numerical (int32) matrixin an external group of the file
rc = trexio_write_external_int32_array(file, matrix, rank_m, dims_m, MATRIX_NAME);
assert (rc == TREXIO_SUCCESS);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
return 0;
}
static int test_has_dset (const char* file_name, const back_end_t backend) {
/* Try to check the existence of a dataset in the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
/*================= START OF TEST ==================*/
// open file
file = trexio_open(file_name, 'r', backend, &rc);
assert (file != NULL);
// check that the group exists
rc = trexio_has_external(file);
assert(rc==TREXIO_SUCCESS);
// check that the previously written datasets exist
rc = trexio_has_external_array(file, VECTOR_NAME);
assert (rc == TREXIO_SUCCESS);
// check that the previously written datasets exist
rc = trexio_has_external_array(file, MATRIX_NAME);
assert (rc == TREXIO_SUCCESS);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
return 0;
}
static int test_read_dset (const char* file_name, const back_end_t backend) {
/* Try to read a dataset with numericali (int) values from the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
// parameters to be read
int32_t* vector;
/*================= START OF TEST ==================*/
// open file in 'read' mode
file = trexio_open(file_name, 'r', backend, &rc);
assert (file != NULL);
// read numerical dataset from the file
vector = (int32_t*) calloc(12, sizeof(int32_t));
rc = trexio_read_external_int32_array(file, vector, VECTOR_NAME);
assert (rc == TREXIO_SUCCESS);
assert (vector[0] == 0);
assert (vector[11] == 11);
free(vector);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
return 0;
}
int main(void) {
/*============== Test launcher ================*/
int rc;
rc = system(RM_COMMAND);
assert (rc == 0);
test_write_dset (TREXIO_FILE, TEST_BACKEND);
test_has_dset (TREXIO_FILE, TEST_BACKEND);
test_read_dset (TREXIO_FILE, TEST_BACKEND);
rc = system(RM_COMMAND);
assert (rc == 0);
return 0;
}