diff options
Diffstat (limited to 'fortran')
-rw-r--r-- | fortran/test/null_vol_connector.c | 148 | ||||
-rw-r--r-- | fortran/test/null_vol_connector.h | 25 | ||||
-rw-r--r-- | fortran/test/test_vol_connector.sh.in | 84 | ||||
-rw-r--r-- | fortran/test/vol_connector.F90 | 187 |
4 files changed, 444 insertions, 0 deletions
diff --git a/fortran/test/null_vol_connector.c b/fortran/test/null_vol_connector.c new file mode 100644 index 0000000..00a22b8 --- /dev/null +++ b/fortran/test/null_vol_connector.c @@ -0,0 +1,148 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* Purpose: A simple virtual object layer (VOL) connector with almost no + * functionality that is used for testing basic plugin handling + * (registration, etc.). + */ + +#include <stdlib.h> +#include "H5PLextern.h" + +#include "null_vol_connector.h" + +static void *H5VL_file_create(const char *name); +static herr_t H5VL_file_close(void *file); + +/* The VOL class struct */ +static const H5VL_class_t null_vol_g = { + 0, /* version */ + NULL_VOL_CONNECTOR_VALUE, /* value */ + NULL_VOL_CONNECTOR_NAME, /* name */ + 0, /* capability flags */ + NULL, /* initialize */ + NULL, /* terminate */ + (size_t)0, /* info size */ + NULL, /* info copy */ + NULL, /* info compare */ + NULL, /* info free */ + NULL, /* info to str */ + NULL, /* str to info */ + NULL, /* get_object */ + NULL, /* get_wrap_ctx */ + NULL, /* wrap_object */ + NULL, /* free_wrap_ctx */ + { /* attribute_cls */ + NULL, /* create */ + NULL, /* open */ + NULL, /* read */ + NULL, /* write */ + NULL, /* get */ + NULL, /* specific */ + NULL, /* optional */ + NULL /* close */ + }, + { /* dataset_cls */ + NULL, /* create */ + NULL, /* open */ + NULL, /* read */ + NULL, /* write */ + NULL, /* get */ + NULL, /* specific */ + NULL, /* optional */ + NULL /* close */ + }, + { /* datatype_cls */ + NULL, /* commit */ + NULL, /* open */ + NULL, /* get_size */ + NULL, /* specific */ + NULL, /* optional */ + NULL /* close */ + }, + { /* file_cls */ + H5VL_file_create, /* create */ + NULL, /* open */ + NULL, /* get */ + NULL, /* specific */ + NULL, /* optional */ + H5VL_file_close /* close */ + }, + { /* group_cls */ + NULL, /* create */ + NULL, /* open */ + NULL, /* get */ + NULL, /* specific */ + NULL, /* optional */ + NULL /* close */ + }, + { /* link_cls */ + NULL, /* create */ + NULL, /* copy */ + NULL, /* move */ + NULL, /* get */ + NULL, /* specific */ + NULL /* optional */ + }, + { /* object_cls */ + NULL, /* open */ + NULL, /* copy */ + NULL, /* get */ + NULL, /* specific */ + NULL /* optional */ + }, + { /* request_cls */ + NULL, /* wait */ + NULL, /* notify */ + NULL, /* cancel */ + NULL, /* specific */ + NULL, /* optional */ + NULL /* free */ + }, + NULL /* optional */ +}; + +typedef struct H5VL_t { + void *under_object; +} H5VL_t; + +/* These two functions are necessary to load this plugin using + * the HDF5 library. + */ + +H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_VOL;} +const void *H5PLget_plugin_info(void) {return &null_vol_g;} + +static void * +H5VL_file_create(const char *name) +{ + hid_t under_fapl; + H5VL_t *file; + + file = (H5VL_t *)calloc(1, sizeof(H5VL_t)); + + file->under_object = fopen(name, "w"); + + return (void *)file; +} + +static herr_t +H5VL_file_close(void *file) +{ + H5VL_t *f = (H5VL_t *)file; + + fclose(f->under_object); + free(f); + + return 1; +} + diff --git a/fortran/test/null_vol_connector.h b/fortran/test/null_vol_connector.h new file mode 100644 index 0000000..11c8826 --- /dev/null +++ b/fortran/test/null_vol_connector.h @@ -0,0 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* Purpose: A simple virtual object layer (VOL) connector with almost no + * functionality that is used for testing basic plugin handling + * (registration, etc.). + */ + +#ifndef _null_vol_connector_H +#define _null_vol_connector_H + +#define NULL_VOL_CONNECTOR_VALUE ((H5VL_class_value_t)160) +#define NULL_VOL_CONNECTOR_NAME "null_vol_connector" + +#endif /* _null_vol_connector_H */ + diff --git a/fortran/test/test_vol_connector.sh.in b/fortran/test/test_vol_connector.sh.in new file mode 100644 index 0000000..ee27f3b --- /dev/null +++ b/fortran/test/test_vol_connector.sh.in @@ -0,0 +1,84 @@ +#! /bin/sh +# +# Copyright by The HDF Group. +# 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 COPYING file, which can be found at the root of the source code +# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +# This shell script is for testing VOL connector plugins. +# +srcdir=@srcdir@ +TOP_BUILDDIR=@top_builddir@ + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +nerrors=0 +verbose=yes +exit_code=$EXIT_SUCCESS + +TEST_NAME=vol_connector +TEST_BIN=`pwd`/$TEST_NAME +FROM_DIR=`pwd`/.libs +case $(uname) in + CYGWIN* ) + NULL_VOL_PLUGIN="$FROM_DIR/cygnull_vol_connector*" + ;; + *) + NULL_VOL_PLUGIN="$FROM_DIR/libnull_vol_connector*" + ;; +esac +TEMP_PLUGIN_DIR=null_vol_plugin_dir +CP="cp -p -r" # Use -p to preserve mode,ownership, timestamps +RM="rm -rf" + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Testing". +# +TESTING() { + SPACES=" " + echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Main Body +# Create test directory if necessary. +test -d $TEMP_PLUGIN_DIR || mkdir -p $TEMP_PLUGIN_DIR +if [ $? != 0 ]; then + echo "Failed to create VOL connector plugin test directory ($TEMP_PLUGIN_DIR)" + exit $EXIT_FAILURE +fi + +# Copy plugin for the tests. +$CP $NULL_VOL_PLUGIN $TEMP_PLUGIN_DIR +if [ $? != 0 ]; then + echo "Failed to copy NULL VOL plugin ($NULL_VOL_PLUGIN) to test directory." + exit $EXIT_FAILURE +fi + +# setup plugin path +ENVCMD="env HDF5_PLUGIN_PATH=${TEMP_PLUGIN_DIR}" + +# Run the test +$ENVCMD $TEST_BIN +if [ $? != 0 ]; then + nerrors=`expr $nerrors + 1` +fi + +# print results +if test $nerrors -ne 0 ; then + echo "$nerrors errors encountered" + exit_code=$EXIT_FAILURE +else + echo "All VOL plugin tests passed." + exit_code=$EXIT_SUCCESS +fi + +# Clean up temporary files/directories and leave +#$RM $TEMP_PLUGIN_DIR + +exit $exit_code diff --git a/fortran/test/vol_connector.F90 b/fortran/test/vol_connector.F90 new file mode 100644 index 0000000..8d3653c --- /dev/null +++ b/fortran/test/vol_connector.F90 @@ -0,0 +1,187 @@ +!****h* root/fortran/test/vol_connector.F90 +! +! NAME +! vol_connector.F90 +! +! FUNCTION +! +! Tests basic Fortran VOL plugin operations (registration, etc.). +! Uses the null VOL connector (built with the testing code) +! which is loaded as a dynamic plugin. +! +! COPYRIGHT +! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +! Copyright by The HDF Group. * +! 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 COPYING file, which can be found at the root of the source code * +! distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * +! If you do not have access to either file, you may request a copy from * +! help@hdfgroup.org. * +! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +! +!***** + +MODULE VOL_TMOD + + USE HDF5 + USE THDF5_F03 + IMPLICIT NONE + + + INTEGER, PARAMETER :: NULL_VOL_CONNECTOR_VALUE = 160 + CHARACTER(LEN=18), PARAMETER :: NULL_VOL_CONNECTOR_NAME = "null_vol_connector" + +CONTAINS + + !------------------------------------------------------------------------- + ! Function: test_registration_by_name() + ! + ! Purpose: Tests if we can load, register, and close a VOL + ! connector by name. + ! + !------------------------------------------------------------------------- + ! + + SUBROUTINE test_registration_by_name(total_error) + + IMPLICIT NONE + + INTEGER, INTENT(INOUT) :: total_error + INTEGER :: error = 0 + + LOGICAL :: is_registered = .FALSE. + INTEGER(hid_t) :: vol_id = 0, vol_id_out = 1 + CHARACTER(LEN=64) :: name + INTEGER(SIZE_T) :: name_len + INTEGER :: cmp = -1 + CHARACTER(LEN=12) :: filename = "h5null.posix" + INTEGER(HID_T) :: file_id + + ! The null VOL connector should not be registered at the start of the test + CALL H5VLis_connector_registered_f( NULL_VOL_CONNECTOR_NAME, is_registered, error) + CALL check("H5VLis_connector_registered_f",error,total_error) + CALL VERIFY("H5VLis_connector_registered_f", is_registered, .FALSE., total_error) + + ! Register the connector by name + CALL H5VLregister_connector_by_name_f(NULL_VOL_CONNECTOR_NAME, vol_id, error) + CALL check("H5VLregister_connector_by_name_f",error,total_error) + + ! The connector should be registered now + CALL H5VLis_connector_registered_f(NULL_VOL_CONNECTOR_NAME, is_registered, error) + CALL check("H5VLis_connector_registered_f",error,total_error) + CALL VERIFY("H5VLis_connector_registered_f", is_registered, .TRUE., total_error) + + CALL H5VLget_connector_id_f(NULL_VOL_CONNECTOR_NAME, vol_id_out, error) + CALL check("H5VLget_connector_id_f",error,total_error) + + CALL H5VLcmp_connector_cls_f( cmp, vol_id_out, vol_id, error) + CALL check("H5VLcmp_connector_cls_f",error, total_error) + CALL VERIFY("H5VLcmp_connector_cls_f", cmp, 0, total_error) + + CALL H5VLclose_f(vol_id_out, error) + + ! Unregister the connector + CALL H5VLunregister_connector_f(vol_id, error) + CALL check("H5VLunregister_connector_f", error, total_error) + + ! The connector should not be registered now + CALL H5VLis_connector_registered_f( NULL_VOL_CONNECTOR_NAME, is_registered, error) + CALL check("H5VLis_connector_registered_f",error,total_error) + CALL VERIFY("H5VLis_connector_registered_f", is_registered, .FALSE., total_error) + + END SUBROUTINE test_registration_by_name + + !------------------------------------------------------------------------- + ! Function: test_registration_by_value() + ! + ! Purpose: Tests if we can load, register, and close a VOL + ! connector by value. + ! + !------------------------------------------------------------------------- + + SUBROUTINE test_registration_by_value(total_error) + + IMPLICIT NONE + + INTEGER, INTENT(INOUT) :: total_error + INTEGER :: error = 0 + + LOGICAL :: is_registered = .FALSE. + INTEGER(hid_t) :: vol_id = 0 + + + ! The null VOL connector should not be registered at the start of the test + CALL H5VLis_connector_registered_f( NULL_VOL_CONNECTOR_NAME, is_registered, error) + CALL check("H5VLis_connector_registered_f",error,total_error) + CALL VERIFY("H5VLis_connector_registered_f", is_registered, .FALSE., total_error) + + ! Register the connector by value + CALL H5VLregister_connector_by_value_f(NULL_VOL_CONNECTOR_VALUE, vol_id, error) + CALL check("H5VLregister_connector_by_value_f", error, total_error) + + ! The connector should be registered now + CALL H5VLis_connector_registered_f(NULL_VOL_CONNECTOR_NAME, is_registered, error) + CALL check("H5VLis_connector_registered_f",error,total_error) + CALL VERIFY("H5VLis_connector_registered_f", is_registered, .TRUE., total_error) + + ! Unregister the connector + CALL H5VLunregister_connector_f(vol_id, error) + CALL check("H5VLunregister_connector_f", error, total_error) + + ! The connector should not be registered now + CALL H5VLis_connector_registered_f( NULL_VOL_CONNECTOR_NAME, is_registered, error) + CALL check("H5VLis_connector_registered_f",error,total_error) + CALL VERIFY("H5VLis_connector_registered_f", is_registered, .FALSE., total_error) + + END SUBROUTINE test_registration_by_value + +END MODULE VOL_TMOD + + +PROGRAM vol_connector + + USE HDF5 + USE THDF5_F03 + USE VOL_TMOD + + IMPLICIT NONE + INTEGER :: total_error = 0 + INTEGER :: error + INTEGER :: ret_total_error + LOGICAL :: cleanup, status + + CALL h5open_f(error) + + cleanup = .TRUE. + CALL h5_env_nocleanup_f(status) + IF(status) cleanup=.FALSE. + + WRITE(*,'(18X,A)') '==============================' + WRITE(*,'(24X,A)') 'FORTRAN VOL tests' + WRITE(*,'(18X,A)') '==============================' + + WRITE(*,'(A)') "Testing VOL connector plugin functionality." + ret_total_error = 0 + CALL test_registration_by_name(ret_total_error) + CALL write_test_status(ret_total_error, ' Testing VOL registration by name', total_error) + + ret_total_error = 0 + CALL test_registration_by_value(ret_total_error) + CALL write_test_status(ret_total_error, ' Testing VOL registration by value', total_error) + + WRITE(*, fmt = '(/18X,A)') '============================================' + WRITE(*, fmt = '(19X, A)', advance='NO') ' FORTRAN VOL tests completed with ' + WRITE(*, fmt = '(I4)', advance='NO') total_error + WRITE(*, fmt = '(A)' ) ' error(s) ! ' + WRITE(*,'(18X,A)') '============================================' + + CALL h5close_f(error) + + ! if errors detected, exit with non-zero code. + IF (total_error .NE. 0) CALL h5_exit_f(1) + +END PROGRAM vol_connector |