From 094f14ef3857a47deb15bdfe45a1d4fe26655a6a Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Fri, 26 Jul 2019 11:56:03 -0500 Subject: Add HD to string functions. Switched strtoul to strtoumax in H5FDs3comms.c. Removed unused functions and variables in s3 and hdfs TestH5Pfapl*.java. Update Copyright headers. --- config/cmake/ConfigureChecks.cmake | 2 +- java/examples/groups/JavaGroupExample.sh.in | 2 - java/test/TestH5Pfaplhdfs.java | 212 ----- java/test/TestH5Pfapls3.java | 212 ----- src/H5FDros3.c | 34 +- src/H5FDros3.h | 18 +- src/H5FDs3comms.c | 42 +- src/H5FDs3comms.h | 17 +- test/hdfs.c | 18 +- test/ros3.c | 18 +- test/s3comms.c | 18 +- tools/libtest/Makefile.am | 2 +- tools/libtest/h5tools_test_utils.c | 1295 ++++++++++++++++++++++++++ tools/libtest/h5tools_utils.c | 1296 --------------------------- 14 files changed, 1382 insertions(+), 1804 deletions(-) create mode 100644 tools/libtest/h5tools_test_utils.c delete mode 100644 tools/libtest/h5tools_utils.c diff --git a/config/cmake/ConfigureChecks.cmake b/config/cmake/ConfigureChecks.cmake index f295a1c..cb1eb48 100644 --- a/config/cmake/ConfigureChecks.cmake +++ b/config/cmake/ConfigureChecks.cmake @@ -155,7 +155,7 @@ if (NOT WINDOWS) endif () #----------------------------------------------------------------------------- -# Check if ROS3 driver works +# Check if ROS3 driver can be built #----------------------------------------------------------------------------- option (HDF5_ENABLE_ROS3_VFD "Build the ROS3 Virtual File Driver" OFF) if (HDF5_ENABLE_ROS3_VFD) diff --git a/java/examples/groups/JavaGroupExample.sh.in b/java/examples/groups/JavaGroupExample.sh.in index 3ba512a..9d4673f 100644 --- a/java/examples/groups/JavaGroupExample.sh.in +++ b/java/examples/groups/JavaGroupExample.sh.in @@ -64,8 +64,6 @@ $HDFTEST_HOME/h5ex_g_iterate.h5 $HDFTEST_HOME/h5ex_g_visit.h5 " LIST_DATA_FILES=" -$HDFTEST_HOME/h5ex_g_iterate.h5 -$HDFTEST_HOME/h5ex_g_visit.h5 $HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Create.txt $HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Iterate.txt $HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Compact.txt diff --git a/java/test/TestH5Pfaplhdfs.java b/java/test/TestH5Pfaplhdfs.java index 2b0a808..30d326e 100644 --- a/java/test/TestH5Pfaplhdfs.java +++ b/java/test/TestH5Pfaplhdfs.java @@ -41,228 +41,16 @@ import org.junit.rules.TestName; public class TestH5Pfaplhdfs { @Rule public TestName testname = new TestName(); - private static final String H5_FILE = "testPf.h5"; - private static final String H5_LOG_FILE = "testPf.log"; - private static final String H5_FAMILY_FILE = "testPf%05d"; - private static final String H5_MULTI_FILE = "testPfmulti"; - private static char MULTI_LETTERS[] = {'X','s','b','r','g','l','o'}; - private static final int DIM_X = 4; - private static final int DIM_Y = 6; - private static final int DIMF_X = 12; - private static final int DIMF_Y = 18; long H5fid = -1; long H5dsid = -1; long H5did = -1; long H5Fdsid = -1; long H5Fdid = -1; - long[] H5dims = { DIM_X, DIM_Y }; long fapl_id = -1; long plapl_id = -1; long dapl_id = -1; long plist_id = -1; long btplist_id = -1; - long[] H5Fdims = { DIMF_X, DIMF_Y }; - double windchillF[][] = - {{36.0, 31.0, 25.0, 19.0, 13.0, 7.0, 1.0, -5.0, -11.0, -16.0, -22.0, -28.0, -34.0, -40.0, -46.0, -52.0, -57.0, -63.0}, - {34.0, 27.0, 21.0, 15.0, 9.0, 3.0, -4.0, -10.0, -16.0, -22.0, -28.0, -35.0, -41.0, -47.0, -53.0, -59.0, -66.0, -72.0}, - {32.0, 25.0, 19.0, 13.0, 6.0, 0.0, -7.0, -13.0, -19.0, -26.0, -32.0, -39.0, -45.0, -51.0, -58.0, -64.0, -71.0, -77.0}, - {30.0, 24.0, 17.0, 11.0, 4.0, -2.0, -9.0, -15.0, -22.0, -29.0, -35.0, -42.0, -48.0, -55.0, -61.0, -68.0, -74.0, -81.0}, - {29.0, 23.0, 16.0, 9.0, 3.0, -4.0, -11.0, -17.0, -24.0, -31.0, -37.0, -44.0, -51.0, -58.0, -64.0, -71.0, -78.0, -84.0}, - {28.0, 22.0, 15.0, 8.0, 1.0, -5.0, -12.0, -19.0, -26.0, -33.0, -39.0, -46.0, -53.0, -60.0, -67.0, -73.0, -80.0, -87.0}, - {28.0, 21.0, 14.0, 7.0, 0.0, -7.0, -14.0, -21.0, -27.0, -34.0, -41.0, -48.0, -55.0, -62.0, -69.0, -76.0, -82.0, -89.0}, - {27.0, 20.0, 13.0, 6.0, -1.0, -8.0, -15.0, -22.0, -29.0, -36.0, -43.0, -50.0, -57.0, -64.0, -71.0, -78.0, -84.0, -91.0}, - {26.0, 19.0, 12.0, 5.0, -2.0, -9.0, -16.0, -23.0, -30.0, -37.0, -44.0, -51.0, -58.0, -65.0, -72.0, -79.0, -86.0, -93.0}, - {26.0, 19.0, 12.0, 4.0, -3.0, -10.0, -17.0, -24.0, -31.0, -38.0, -45.0, -52.0, -60.0, -67.0, -74.0, -81.0, -88.0, -95.0}, - {25.0, 18.0, 11.0, 4.0, -3.0, -11.0, -18.0, -25.0, -32.0, -39.0, -46.0, -54.0, -61.0, -68.0, -75.0, -82.0, -89.0, -97.0}, - {25.0, 17.0, 10.0, 3.0, -4.0, -11.0, -19.0, -26.0, -33.0, -40.0, -48.0, -55.0, -62.0, -69.0, -76.0, -84.0, -91.0, -98.0} - }; - - private final void _deleteFile(String filename) { - File file = null; - try { - file = new File(filename); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - } - - private final void _deleteLogFile() { - File file = null; - try { - file = new File(H5_LOG_FILE); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - } - - private final void _deleteFamilyFile() { - File file = null; - for(int indx = 0; ;indx++) { - java.text.DecimalFormat myFormat = new java.text.DecimalFormat("00000"); - try { - file = new File("test"+myFormat.format(new Integer(indx))+".h5"); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - else - return; - } - } - - private final void _deleteMultiFile() { - File file = null; - for(int indx = 1;indx<7;indx++) { - try { - file = new File(H5_MULTI_FILE+"-"+MULTI_LETTERS[indx]+".h5"); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - } - } - - private final long _createDataset(long fid, long dsid, String name, long dapl) { - long did = -1; - try { - did = H5.H5Dcreate(fid, name, HDF5Constants.H5T_STD_I32BE, dsid, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, dapl); - } - catch (Throwable err) { - err.printStackTrace(); - fail("H5.H5Dcreate: " + err); - } - assertTrue("TestH5Pfapl._createDataset: ", did > 0); - - return did; - } - - private final void _createFloatDataset() { - try { - H5Fdsid = H5.H5Screate_simple(2, H5Fdims, null); - H5Fdid = H5.H5Dcreate(H5fid, "dsfloat", HDF5Constants.H5T_NATIVE_FLOAT, H5Fdsid, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("H5.H5Dcreate: " + err); - } - assertTrue("TestH5Pfapl._createFloatDataset: ", H5Fdid > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5multiFileDS() { - try { - H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5File(long fapl) { - try { - H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC, - HDF5Constants.H5P_DEFAULT, fapl); - H5dsid = H5.H5Screate_simple(2, H5dims, null); - H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0); - assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0); - assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5familyFile(long fapl) { - try { - H5fid = H5.H5Fcreate(H5_FAMILY_FILE+".h5", HDF5Constants.H5F_ACC_TRUNC, - HDF5Constants.H5P_DEFAULT, fapl); - H5dsid = H5.H5Screate_simple(2, H5dims, null); - H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0); - assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0); - assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5multiFile(long fapl) { - try { - H5fid = H5.H5Fcreate(H5_MULTI_FILE, HDF5Constants.H5F_ACC_TRUNC, - HDF5Constants.H5P_DEFAULT, fapl); - H5dsid = H5.H5Screate_simple(2, H5dims, null); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0); - assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - public void deleteH5file() { - _deleteFile(H5_FILE); - } - - public void deleteH5familyfile() { - _deleteFamilyFile(); - } - - public void deleteH5multifile() { - _deleteMultiFile(); - } @Before public void createFileAccess() diff --git a/java/test/TestH5Pfapls3.java b/java/test/TestH5Pfapls3.java index 3107bc8..00a2a73 100644 --- a/java/test/TestH5Pfapls3.java +++ b/java/test/TestH5Pfapls3.java @@ -41,228 +41,16 @@ import org.junit.rules.TestName; public class TestH5Pfapls3 { @Rule public TestName testname = new TestName(); - private static final String H5_FILE = "testPf.h5"; - private static final String H5_LOG_FILE = "testPf.log"; - private static final String H5_FAMILY_FILE = "testPf%05d"; - private static final String H5_MULTI_FILE = "testPfmulti"; - private static char MULTI_LETTERS[] = {'X','s','b','r','g','l','o'}; - private static final int DIM_X = 4; - private static final int DIM_Y = 6; - private static final int DIMF_X = 12; - private static final int DIMF_Y = 18; long H5fid = -1; long H5dsid = -1; long H5did = -1; long H5Fdsid = -1; long H5Fdid = -1; - long[] H5dims = { DIM_X, DIM_Y }; long fapl_id = -1; long plapl_id = -1; long dapl_id = -1; long plist_id = -1; long btplist_id = -1; - long[] H5Fdims = { DIMF_X, DIMF_Y }; - double windchillF[][] = - {{36.0, 31.0, 25.0, 19.0, 13.0, 7.0, 1.0, -5.0, -11.0, -16.0, -22.0, -28.0, -34.0, -40.0, -46.0, -52.0, -57.0, -63.0}, - {34.0, 27.0, 21.0, 15.0, 9.0, 3.0, -4.0, -10.0, -16.0, -22.0, -28.0, -35.0, -41.0, -47.0, -53.0, -59.0, -66.0, -72.0}, - {32.0, 25.0, 19.0, 13.0, 6.0, 0.0, -7.0, -13.0, -19.0, -26.0, -32.0, -39.0, -45.0, -51.0, -58.0, -64.0, -71.0, -77.0}, - {30.0, 24.0, 17.0, 11.0, 4.0, -2.0, -9.0, -15.0, -22.0, -29.0, -35.0, -42.0, -48.0, -55.0, -61.0, -68.0, -74.0, -81.0}, - {29.0, 23.0, 16.0, 9.0, 3.0, -4.0, -11.0, -17.0, -24.0, -31.0, -37.0, -44.0, -51.0, -58.0, -64.0, -71.0, -78.0, -84.0}, - {28.0, 22.0, 15.0, 8.0, 1.0, -5.0, -12.0, -19.0, -26.0, -33.0, -39.0, -46.0, -53.0, -60.0, -67.0, -73.0, -80.0, -87.0}, - {28.0, 21.0, 14.0, 7.0, 0.0, -7.0, -14.0, -21.0, -27.0, -34.0, -41.0, -48.0, -55.0, -62.0, -69.0, -76.0, -82.0, -89.0}, - {27.0, 20.0, 13.0, 6.0, -1.0, -8.0, -15.0, -22.0, -29.0, -36.0, -43.0, -50.0, -57.0, -64.0, -71.0, -78.0, -84.0, -91.0}, - {26.0, 19.0, 12.0, 5.0, -2.0, -9.0, -16.0, -23.0, -30.0, -37.0, -44.0, -51.0, -58.0, -65.0, -72.0, -79.0, -86.0, -93.0}, - {26.0, 19.0, 12.0, 4.0, -3.0, -10.0, -17.0, -24.0, -31.0, -38.0, -45.0, -52.0, -60.0, -67.0, -74.0, -81.0, -88.0, -95.0}, - {25.0, 18.0, 11.0, 4.0, -3.0, -11.0, -18.0, -25.0, -32.0, -39.0, -46.0, -54.0, -61.0, -68.0, -75.0, -82.0, -89.0, -97.0}, - {25.0, 17.0, 10.0, 3.0, -4.0, -11.0, -19.0, -26.0, -33.0, -40.0, -48.0, -55.0, -62.0, -69.0, -76.0, -84.0, -91.0, -98.0} - }; - - private final void _deleteFile(String filename) { - File file = null; - try { - file = new File(filename); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - } - - private final void _deleteLogFile() { - File file = null; - try { - file = new File(H5_LOG_FILE); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - } - - private final void _deleteFamilyFile() { - File file = null; - for(int indx = 0; ;indx++) { - java.text.DecimalFormat myFormat = new java.text.DecimalFormat("00000"); - try { - file = new File("test"+myFormat.format(new Integer(indx))+".h5"); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - else - return; - } - } - - private final void _deleteMultiFile() { - File file = null; - for(int indx = 1;indx<7;indx++) { - try { - file = new File(H5_MULTI_FILE+"-"+MULTI_LETTERS[indx]+".h5"); - } - catch (Throwable err) {} - - if (file.exists()) { - try {file.delete();} catch (SecurityException e) {} - } - } - } - - private final long _createDataset(long fid, long dsid, String name, long dapl) { - long did = -1; - try { - did = H5.H5Dcreate(fid, name, HDF5Constants.H5T_STD_I32BE, dsid, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, dapl); - } - catch (Throwable err) { - err.printStackTrace(); - fail("H5.H5Dcreate: " + err); - } - assertTrue("TestH5Pfapl._createDataset: ", did > 0); - - return did; - } - - private final void _createFloatDataset() { - try { - H5Fdsid = H5.H5Screate_simple(2, H5Fdims, null); - H5Fdid = H5.H5Dcreate(H5fid, "dsfloat", HDF5Constants.H5T_NATIVE_FLOAT, H5Fdsid, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("H5.H5Dcreate: " + err); - } - assertTrue("TestH5Pfapl._createFloatDataset: ", H5Fdid > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5multiFileDS() { - try { - H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5File(long fapl) { - try { - H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC, - HDF5Constants.H5P_DEFAULT, fapl); - H5dsid = H5.H5Screate_simple(2, H5dims, null); - H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0); - assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0); - assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5familyFile(long fapl) { - try { - H5fid = H5.H5Fcreate(H5_FAMILY_FILE+".h5", HDF5Constants.H5F_ACC_TRUNC, - HDF5Constants.H5P_DEFAULT, fapl); - H5dsid = H5.H5Screate_simple(2, H5dims, null); - H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0); - assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0); - assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - private final void _createH5multiFile(long fapl) { - try { - H5fid = H5.H5Fcreate(H5_MULTI_FILE, HDF5Constants.H5F_ACC_TRUNC, - HDF5Constants.H5P_DEFAULT, fapl); - H5dsid = H5.H5Screate_simple(2, H5dims, null); - } - catch (Throwable err) { - err.printStackTrace(); - fail("TestH5Pfapl.createH5file: " + err); - } - assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0); - assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0); - - try { - H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - } - catch (Throwable err) { - err.printStackTrace(); - } - } - - public void deleteH5file() { - _deleteFile(H5_FILE); - } - - public void deleteH5familyfile() { - _deleteFamilyFile(); - } - - public void deleteH5multifile() { - _deleteMultiFile(); - } @Before public void createFileAccess() diff --git a/src/H5FDros3.c b/src/H5FDros3.c index 8bf0420..86642aa 100644 --- a/src/H5FDros3.c +++ b/src/H5FDros3.c @@ -1,18 +1,18 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Read-Only S3 Virtual File Driver (VFD) * - * Copyright (c) 2017-2018, The HDF Group. * - * * + * Copyright by The HDF Group. * * All rights reserved. * * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * + * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* + * Read-Only S3 Virtual File Driver (VFD) + * * Programmer: Jacob Smith * 2017-10-13 * @@ -1334,14 +1334,14 @@ H5FD_ros3_cmp(const H5FD_t *_f1, HDassert(purl2->host != NULL); /* URL: SCHEME */ - if (strcmp(purl1->scheme, purl2->scheme)) HGOTO_DONE(-1); + if (HDstrcmp(purl1->scheme, purl2->scheme)) HGOTO_DONE(-1); /* URL: HOST */ - if (strcmp(purl1->host, purl2->host)) HGOTO_DONE(-1); + if (HDstrcmp(purl1->host, purl2->host)) HGOTO_DONE(-1); /* URL: PORT */ if (purl1->port && purl2->port) { - if (strcmp(purl1->port, purl2->port)) HGOTO_DONE(-1); + if (HDstrcmp(purl1->port, purl2->port)) HGOTO_DONE(-1); } else if (purl1->port) { HGOTO_DONE(-1); } else if (purl2->port) { @@ -1350,7 +1350,7 @@ H5FD_ros3_cmp(const H5FD_t *_f1, /* URL: PATH */ if (purl1->path && purl2->path) { - if (strcmp(purl1->path, purl2->path)) HGOTO_DONE(-1); + if (HDstrcmp(purl1->path, purl2->path)) HGOTO_DONE(-1); } else if (purl1->path && !purl2->path) { HGOTO_DONE(-1); } else if (purl2->path && !purl1->path) { @@ -1359,7 +1359,7 @@ H5FD_ros3_cmp(const H5FD_t *_f1, /* URL: QUERY */ if (purl1->query && purl2->query) { - if (strcmp(purl1->query, purl2->query)) HGOTO_DONE(-1); + if (HDstrcmp(purl1->query, purl2->query)) HGOTO_DONE(-1); } else if (purl1->query && !purl2->query) { HGOTO_DONE(-1); } else if (purl2->query && !purl1->query) { @@ -1368,7 +1368,7 @@ H5FD_ros3_cmp(const H5FD_t *_f1, /* FAPL: AWS_REGION */ if (f1->fa.aws_region[0] != '\0' && f1->fa.aws_region[0] != '\0') { - if (strcmp(f1->fa.aws_region, f2->fa.aws_region)) HGOTO_DONE(-1); + if (HDstrcmp(f1->fa.aws_region, f2->fa.aws_region)) HGOTO_DONE(-1); } else if (f1->fa.aws_region[0] != '\0') { HGOTO_DONE(-1); } else if (f2->fa.aws_region[0] != '\0') { @@ -1377,7 +1377,7 @@ H5FD_ros3_cmp(const H5FD_t *_f1, /* FAPL: SECRET_ID */ if (f1->fa.secret_id[0] != '\0' && f1->fa.secret_id[0] != '\0') { - if (strcmp(f1->fa.secret_id, f2->fa.secret_id)) HGOTO_DONE(-1); + if (HDstrcmp(f1->fa.secret_id, f2->fa.secret_id)) HGOTO_DONE(-1); } else if (f1->fa.secret_id[0] != '\0') { HGOTO_DONE(-1); } else if (f2->fa.secret_id[0] != '\0') { @@ -1386,7 +1386,7 @@ H5FD_ros3_cmp(const H5FD_t *_f1, /* FAPL: SECRET_KEY */ if (f1->fa.secret_key[0] != '\0' && f1->fa.secret_key[0] != '\0') { - if (strcmp(f1->fa.secret_key, f2->fa.secret_key)) HGOTO_DONE(-1); + if (HDstrcmp(f1->fa.secret_key, f2->fa.secret_key)) HGOTO_DONE(-1); } else if (f1->fa.secret_key[0] != '\0') { HGOTO_DONE(-1); } else if (f2->fa.secret_key[0] != '\0') { diff --git a/src/H5FDros3.h b/src/H5FDros3.h index 49e757c..7dfc95b 100644 --- a/src/H5FDros3.h +++ b/src/H5FDros3.h @@ -1,18 +1,18 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Read-Only S3 Virtual File Driver (VFD) * - * Copyright (c) 2017-2018, The HDF Group. * - * * + * Copyright by The HDF Group. * * All rights reserved. * * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * + * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* + * Read-Only S3 Virtual File Driver (VFD) + * * Programmer: John Mainzer * 2017-10-10 * diff --git a/src/H5FDs3comms.c b/src/H5FDs3comms.c index 7caeacb..4c24866 100644 --- a/src/H5FDs3comms.c +++ b/src/H5FDs3comms.c @@ -1,18 +1,18 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Read-Only S3 Virtual File Driver (VFD) * - * Copyright (c) 2017-2018, The HDF Group. * - * * + * Copyright by The HDF Group. * * All rights reserved. * * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * + * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /***************************************************************************** + * Read-Only S3 Virtual File Driver (VFD) + * * Source for S3 Communications module * * ***NOT A FILE DRIVER*** @@ -1005,7 +1005,7 @@ herr_t H5FD_s3comms_s3r_getsize(s3r_t *handle) { #ifdef H5_HAVE_ROS3_VFD - unsigned long int content_length = 0; + uintmax_t content_length = 0; CURL *curlh = NULL; char *end = NULL; char *headerresponse = NULL; @@ -1135,9 +1135,14 @@ H5FD_s3comms_s3r_getsize(s3r_t *handle) */ *end = '\0'; - content_length = strtoul((const char *)start, + content_length = strtoumax((const char *)start, NULL, 0); + + if (UINTMAX_MAX > SIZE_MAX && content_length > SIZE_MAX) { + HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "content_length overflows size_t\n"); + } + if (content_length == 0 || content_length == ULONG_MAX || errno == ERANGE) /* errno set by strtoul */ @@ -1156,7 +1161,7 @@ H5FD_s3comms_s3r_getsize(s3r_t *handle) if ( CURLE_OK != curl_easy_setopt(curlh, CURLOPT_NOBODY, - 0) ) + NULL) ) { HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while setting CURL option (CURLOPT_NOBODY). " @@ -1166,7 +1171,7 @@ H5FD_s3comms_s3r_getsize(s3r_t *handle) if ( CURLE_OK != curl_easy_setopt(curlh, CURLOPT_HEADERDATA, - 0) ) + NULL) ) { HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while setting CURL option (CURLOPT_HEADERDATA). " @@ -2518,7 +2523,7 @@ done: * + internal error occurred. * + -1 :: unable to format profile label * + -2 :: profile name/label not found in file - * + -3 :: some other error + * + -3 :: some other error * * Programmer: Jacob Smith * 2018-02-27 @@ -2602,14 +2607,14 @@ H5FD__s3comms_load_aws_creds_from_file( "unable to format line prefix") /* found a matching name? */ - if (!strncmp(line_buffer, line_prefix, setting_name_len + 1)) { + if (!HDstrncmp(line_buffer, line_prefix, setting_name_len + 1)) { found_setting = 1; /* skip NULL destination buffer */ if (setting_pointers[setting_i] == NULL) break; - /* advance to end fo name in string */ + /* advance to end of name in string */ do { line_buffer++; } while (*line_buffer != 0 && *line_buffer != '='); @@ -2620,7 +2625,8 @@ H5FD__s3comms_load_aws_creds_from_file( line_buffer++; /* was pointing at '='; advance */ /* copy line buffer into out pointer */ - strcpy(setting_pointers[setting_i], (const char *)line_buffer); + HDstrncpy(setting_pointers[setting_i], (const char *)line_buffer, + HDstrlen(line_buffer)); /* "trim" tailing whitespace by replacing with null terminator*/ buffer_i = 0; @@ -2889,7 +2895,7 @@ H5FD_s3comms_parse_url(const char *str, * READ SCHEME * ***************/ - tmpstr = strchr(curstr, ':'); + tmpstr = HDstrchr(curstr, ':'); if (tmpstr == NULL) { HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid SCHEME construction: probably not URL"); diff --git a/src/H5FDs3comms.h b/src/H5FDs3comms.h index 0524c46..93a5a81 100644 --- a/src/H5FDs3comms.h +++ b/src/H5FDs3comms.h @@ -1,18 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Read-Only S3 Virtual File Driver (VFD) * - * Copyright (c) 2017-2018, The HDF Group. * - * * + * Copyright by The HDF Group. * * All rights reserved. * * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * + * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /***************************************************************************** + * Read-Only S3 Virtual File Driver (VFD) * * This is the header for the S3 Communications module * diff --git a/test/hdfs.c b/test/hdfs.c index 11b9918..57dbac9 100644 --- a/test/hdfs.c +++ b/test/hdfs.c @@ -1,18 +1,18 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Read-Only HDFS Virtual File Driver (VFD) * - * Copyright (c) 2018, The HDF Group. * - * * + * Copyright by The HDF Group. * * All rights reserved. * * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * + * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* + * Read-Only HDFS Virtual File Driver (VFD) + * * Purpose: * * Verify behavior for Read-Only HDFS VFD. diff --git a/test/ros3.c b/test/ros3.c index 51c1a89..60d3932 100644 --- a/test/ros3.c +++ b/test/ros3.c @@ -1,18 +1,18 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Read-Only S3 Virtual File Driver (VFD) * - * Copyright (c) 2017-2018, The HDF Group. * - * * + * Copyright by The HDF Group. * * All rights reserved. * * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * + * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* + * Read-Only S3 Virtual File Driver (VFD) + * * Purpose: * * Verify behavior for Read-Only S3 VFD diff --git a/test/s3comms.c b/test/s3comms.c index 71d93c2..a797e04 100644 --- a/test/s3comms.c +++ b/test/s3comms.c @@ -1,18 +1,18 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Read-Only S3 Virtual File Driver (VFD) * - * Copyright (c) 2017-2018, The HDF Group. * - * * + * Copyright by The HDF Group. * * All rights reserved. * * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * + * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* + * Read-Only S3 Virtual File Driver (VFD) + * * Purpose: Unit tests for the S3 Communications (s3comms) module. * * Programmer: Jacob Smith diff --git a/tools/libtest/Makefile.am b/tools/libtest/Makefile.am index 5aa72b8..a93e25d 100644 --- a/tools/libtest/Makefile.am +++ b/tools/libtest/Makefile.am @@ -27,7 +27,7 @@ LDADD=$(LIBH5TOOLS) $(LIBHDF5) # main target -bin_PROGRAMS=h5tools_utils +bin_PROGRAMS=h5tools_test_utils # check_PROGRAMS=$(TEST_PROG) diff --git a/tools/libtest/h5tools_test_utils.c b/tools/libtest/h5tools_test_utils.c new file mode 100644 index 0000000..ac8e4c0 --- /dev/null +++ b/tools/libtest/h5tools_test_utils.c @@ -0,0 +1,1295 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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: unit-test functionality of the routines in `tools/lib/h5tools_utils` + * + * Jacob Smith 2017-11-10 + */ + +#include "hdf5.h" +#include "H5private.h" +#include "h5tools_utils.h" +/* #include "h5test.h" */ /* linking failure */ + +#define UTIL_TEST_DEBUG 0 + +#ifndef _H5TEST_ + +#define AT() fprintf(stdout, " at %s:%d in %s()...\n", \ + __FILE__, __LINE__, FUNC); + +#define FAILED(msg) { \ + fprintf(stdout, "*FAILED*"); AT() \ + if (msg == NULL) { \ + fprintf(stdout,"(NULL)\n"); \ + } else { \ + fprintf(stdout, "%s\n", msg); \ + } \ + fflush(stdout); \ +} + +#define TESTING(msg) { \ + fprintf(stdout, "TESTING %-62s", (msg)); \ + fflush(stdout); \ +} + +#define PASSED() { \ + fprintf(stdout, " PASSED\n"); \ + fflush(stdout); \ +} + +#endif /* ifndef _H5TEST_ */ + +#ifndef __js_test__ + +#define __js_test__ 1L + +/***************************************************************************** + * + * FILE-LOCAL TESTING MACROS + * + * Purpose: + * + * 1. Upon test failure, goto-jump to single-location teardown in test + * function. E.g., `error:` (consistency with HDF corpus) or + * `failed:` (reflects purpose). + * >>> using "error", in part because `H5E_BEGIN_TRY` expects it. + * 2. Increase clarity and reduce overhead found with `TEST_ERROR`. + * e.g., "if(somefunction(arg, arg2) < 0) TEST_ERROR:" + * requires reading of entire line to know whether this if/call is + * part of the test setup, test operation, or a test unto itself. + * 3. Provide testing macros with optional user-supplied failure message; + * if not supplied (NULL), generate comparison output in the spirit of + * test-driven development. E.g., "expected 5 but was -3" + * User messages clarify test's purpose in code, encouraging description + * without relying on comments. + * 4. Configurable expected-actual order in generated comparison strings. + * Some prefer `VERIFY(expected, actual)`, others + * `VERIFY(actual, expected)`. Provide preprocessor ifdef switch + * to satifsy both parties, assuming one paradigm per test file. + * (One could #undef and redefine the flag through the file as desired, + * but _why_.) + * + * Provided as courtesy, per consideration for inclusion in the library + * proper. + * + * Macros: + * + * JSVERIFY_EXP_ACT - ifdef flag, configures comparison order + * FAIL_IF() - check condition + * FAIL_UNLESS() - check _not_ condition + * JSVERIFY() - long-int equality check; prints reason/comparison + * JSVERIFY_NOT() - long-int inequality check; prints + * JSVERIFY_STR() - string equality check; prints + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *****************************************************************************/ + + +/*---------------------------------------------------------------------------- + * + * ifdef flag: JSVERIFY_EXP_ACT + * + * JSVERIFY macros accept arguments as (EXPECTED, ACTUAL[, reason]) + * default, if this is undefined, is (ACTUAL, EXPECTED[, reason]) + * + *---------------------------------------------------------------------------- + */ +#define JSVERIFY_EXP_ACT 1L + + +/*---------------------------------------------------------------------------- + * + * Macro: JSFAILED_AT() + * + * Purpose: + * + * Preface a test failure by printing "*FAILED*" and location to stdout + * Similar to `H5_FAILED(); AT();` from h5test.h + * + * *FAILED* at somefile.c:12 in function_name()... + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *---------------------------------------------------------------------------- + */ +#define JSFAILED_AT() { \ + HDprintf("*FAILED* at %s:%d in %s()...\n", __FILE__, __LINE__, FUNC); \ +} + + +/*---------------------------------------------------------------------------- + * + * Macro: FAIL_IF() + * + * Purpose: + * + * Make tests more accessible and less cluttered than + * `if (thing == otherthing()) TEST_ERROR` + * paradigm. + * + * The following lines are roughly equivalent: + * + * `if (myfunc() < 0) TEST_ERROR;` (as seen elsewhere in HDF tests) + * `FAIL_IF(myfunc() < 0)` + * + * Prints a generic "FAILED AT" line to stdout and jumps to `error`, + * similar to `TEST_ERROR` in h5test.h + * + * Programmer: Jacob Smith + * 2017-10-23 + * + *---------------------------------------------------------------------------- + */ +#define FAIL_IF(condition) \ +if (condition) { \ + JSFAILED_AT() \ + goto error; \ +} + + +/*---------------------------------------------------------------------------- + * + * Macro: FAIL_UNLESS() + * + * Purpose: + * + * TEST_ERROR wrapper to reduce cognitive overhead from "negative tests", + * e.g., "a != b". + * + * Opposite of FAIL_IF; fails if the given condition is _not_ true. + * + * `FAIL_IF( 5 != my_op() )` + * is equivalent to + * `FAIL_UNLESS( 5 == my_op() )` + * However, `JSVERIFY(5, my_op(), "bad return")` may be even clearer. + * (see JSVERIFY) + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *---------------------------------------------------------------------------- + */ +#define FAIL_UNLESS(condition) \ +if (!(condition)) { \ + JSFAILED_AT() \ + goto error; \ +} + + +/*---------------------------------------------------------------------------- + * + * Macro: JSERR_LONG() + * + * Purpose: + * + * Print an failure message for long-int arguments. + * ERROR-AT printed first. + * If `reason` is given, it is printed on own line and newlined after + * else, prints "expected/actual" aligned on own lines. + * + * *FAILED* at myfile.c:488 in somefunc()... + * forest must be made of trees. + * + * or + * + * *FAILED* at myfile.c:488 in somefunc()... + * ! Expected 425 + * ! Actual 3 + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *---------------------------------------------------------------------------- + */ +#define JSERR_LONG(expected, actual, reason) { \ + JSFAILED_AT() \ + if (reason!= NULL) { \ + HDprintf("%s\n", (reason)); \ + } else { \ + HDprintf(" ! Expected %ld\n ! Actual %ld\n", \ + (long)(expected), (long)(actual)); \ + } \ +} + + +/*---------------------------------------------------------------------------- + * + * Macro: JSERR_STR() + * + * Purpose: + * + * Print an failure message for string arguments. + * ERROR-AT printed first. + * If `reason` is given, it is printed on own line and newlined after + * else, prints "expected/actual" aligned on own lines. + * + * *FAILED* at myfile.c:421 in myfunc()... + * Blue and Red strings don't match! + * + * or + * + * *FAILED* at myfile.c:421 in myfunc()... + * !!! Expected: + * this is my expected + * string + * !!! Actual: + * not what I expected at all + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *---------------------------------------------------------------------------- + */ +#define JSERR_STR(expected, actual, reason) { \ + JSFAILED_AT() \ + if ((reason) != NULL) { \ + HDprintf("%s\n", (reason)); \ + } else { \ + HDprintf("!!! Expected:\n%s\n!!!Actual:\n%s\n", \ + (expected), (actual)); \ + } \ +} + +#ifdef JSVERIFY_EXP_ACT + + +/*---------------------------------------------------------------------------- + * + * Macro: JSVERIFY() + * + * Purpose: + * + * Verify that two long integers are equal. + * If unequal, print failure message + * (with `reason`, if not NULL; expected/actual if NULL) + * and jump to `error` at end of function + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *---------------------------------------------------------------------------- + */ +#define JSVERIFY(expected, actual, reason) \ +if ((long)(actual) != (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)) \ + goto error; \ +} /* JSVERIFY */ + + +/*---------------------------------------------------------------------------- + * + * Macro: JSVERIFY_NOT() + * + * Purpose: + * + * Verify that two long integers are _not_ equal. + * If equal, print failure message + * (with `reason`, if not NULL; expected/actual if NULL) + * and jump to `error` at end of function + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *---------------------------------------------------------------------------- + */ +#define JSVERIFY_NOT(expected, actual, reason) \ +if ((long)(actual) == (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)) \ + goto error; \ +} /* JSVERIFY_NOT */ + + +/*---------------------------------------------------------------------------- + * + * Macro: JSVERIFY_STR() + * + * Purpose: + * + * Verify that two strings are equal. + * If unequal, print failure message + * (with `reason`, if not NULL; expected/actual if NULL) + * and jump to `error` at end of function + * + * Programmer: Jacob Smith + * 2017-10-24 + * + *---------------------------------------------------------------------------- + */ +#define JSVERIFY_STR(expected, actual, reason) \ +if (HDstrcmp((actual), (expected)) != 0) { \ + JSERR_STR((expected), (actual), (reason)); \ + goto error; \ +} /* JSVERIFY_STR */ + + +#else /* JSVERIFY_EXP_ACT not defined */ + /* Repeats macros above, but with actual/expected parameters reversed. */ + + +/*---------------------------------------------------------------------------- + * Macro: JSVERIFY() + * See: JSVERIFY documentation above. + * Programmer: Jacob Smith + * 2017-10-14 + *---------------------------------------------------------------------------- + */ +#define JSVERIFY(actual, expected, reason) \ +if ((long)(actual) != (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)); \ + goto error; \ +} /* JSVERIFY */ + + +/*---------------------------------------------------------------------------- + * Macro: JSVERIFY_NOT() + * See: JSVERIFY_NOT documentation above. + * Programmer: Jacob Smith + * 2017-10-14 + *---------------------------------------------------------------------------- + */ +#define JSVERIFY_NOT(actual, expected, reason) \ +if ((long)(actual) == (long)(expected)) { \ + JSERR_LONG((expected), (actual), (reason)) \ + goto error; \ +} /* JSVERIFY_NOT */ + + +/*---------------------------------------------------------------------------- + * Macro: JSVERIFY_STR() + * See: JSVERIFY_STR documentation above. + * Programmer: Jacob Smith + * 2017-10-14 + *---------------------------------------------------------------------------- + */ +#define JSVERIFY_STR(actual, expected, reason) \ +if (HDstrcmp((actual), (expected)) != 0) { \ + JSERR_STR((expected), (actual), (reason)); \ + goto error; \ +} /* JSVERIFY_STR */ + +#endif /* ifdef/else JSVERIFY_EXP_ACT */ + +#endif /* __js_test__ */ + +/* if > 0, be very verbose when performing tests */ +#define H5TOOLS_UTILS_TEST_DEBUG 0 + +/******************/ +/* TEST FUNCTIONS */ +/******************/ + + +/*---------------------------------------------------------------------------- + * + * Function: test_parse_tuple() + * + * Purpose: + * + * Provide unit tests and specification for the `parse_tuple()` function. + * + * Return: + * + * 0 Tests passed. + * 1 Tests failed. + * + * Programmer: Jacob Smith + * 2017-11-11 + * + * Changes: None. + * + *---------------------------------------------------------------------------- + */ +static unsigned +test_parse_tuple(void) +{ + /************************* + * TEST-LOCAL STRUCTURES * + *************************/ + + struct testcase { + const char *test_msg; /* info about test case */ + const char *in_str; /* input string */ + int sep; /* separator "character" */ + herr_t exp_ret; /* expected SUCCEED / FAIL */ + unsigned exp_nelems; /* expected number of elements */ + /* (no more than 7!) */ + const char *exp_elems[7]; /* list of elements (no more than 7!) */ + }; + + /****************** + * TEST VARIABLES * + ******************/ + + struct testcase cases[] = { + { "bad start", + "words(before)", + ';', + FAIL, + 0, + {NULL}, + }, + { "tuple not closed", + "(not ok", + ',', + FAIL, + 0, + {NULL}, + }, + { "empty tuple", + "()", + '-', + SUCCEED, + 1, + {""}, + }, + { "no separator", + "(stuff keeps on going)", + ',', + SUCCEED, + 1, + {"stuff keeps on going"}, + }, + { "4-ple, escaped seperator", + "(elem0,elem1,el\\,em2,elem3)", /* "el\,em" */ + ',', + SUCCEED, + 4, + {"elem0", "elem1", "el,em2", "elem3"}, + }, + { "5-ple, escaped escaped separator", + "(elem0,elem1,el\\\\,em2,elem3)", + ',', + SUCCEED, + 5, + {"elem0", "elem1", "el\\", "em2", "elem3"}, + }, + { "escaped non-comma separator", + "(5-2-7-2\\-6-2)", + '-', + SUCCEED, + 5, + {"5","2","7","2-6","2"}, + }, + { "embedded close-paren", + "(be;fo)re)", + ';', + SUCCEED, + 2, + {"be", "fo)re"}, + }, + { "embedded non-escaping backslash", + "(be;fo\\re)", + ';', + SUCCEED, + 2, + {"be", "fo\\re"}, + }, + { "double close-paren at end", + "(be;fore))", + ';', + SUCCEED, + 2, + {"be", "fore)"}, + }, + { "empty elements", + "(;a1;;a4;)", + ';', + SUCCEED, + 5, + {"", "a1", "", "a4", ""}, + }, + { "nested tuples with different separators", + "((4,e,a);(6,2,a))", + ';', + SUCCEED, + 2, + {"(4,e,a)","(6,2,a)"}, + }, + { "nested tuples with same separators", + "((4,e,a),(6,2,a))", + ',', + SUCCEED, + 6, + {"(4","e","a)","(6","2","a)"}, + }, + { "real-world use case", + "(us-east-2,AKIAIMC3D3XLYXLN5COA,ugs5aVVnLFCErO/8uW14iWE3K5AgXMpsMlWneO/+)", + ',', + SUCCEED, + 3, + {"us-east-2", + "AKIAIMC3D3XLYXLN5COA", + "ugs5aVVnLFCErO/8uW14iWE3K5AgXMpsMlWneO/+"}, + } + }; + struct testcase tc; + unsigned n_tests = 14; + unsigned i = 0; + unsigned count = 0; + unsigned elem_i = 0; + char **parsed = NULL; + char *cpy = NULL; + herr_t success = TRUE; + hbool_t show_progress = FALSE; + + + + TESTING("arbitrary-count tuple parsing"); + +#if H5TOOLS_UTILS_TEST_DEBUG > 0 + show_progress = TRUE; +#endif /* H5TOOLS_UTILS_TEST_DEBUG */ + + /********* + * TESTS * + *********/ + + for (i = 0; i < n_tests; i++) { + + /* SETUP + */ + HDassert(parsed == NULL); + HDassert(cpy == NULL); + tc = cases[i]; + if (show_progress == TRUE) { + printf("testing %d: %s...\n", i, tc.test_msg); + } + + /* VERIFY + */ + success = parse_tuple(tc.in_str, tc.sep, + &cpy, &count, &parsed); + + JSVERIFY( tc.exp_ret, success, "function returned incorrect value" ) + JSVERIFY( tc.exp_nelems, count, NULL ) + if (success == SUCCEED) { + FAIL_IF( parsed == NULL ) + for (elem_i = 0; elem_i < count; elem_i++) { + JSVERIFY_STR( tc.exp_elems[elem_i], parsed[elem_i], NULL ) + } + /* TEARDOWN */ + HDassert(parsed != NULL); + HDassert(cpy != NULL); + free(parsed); + parsed = NULL; + free(cpy); + cpy = NULL; + } else { + FAIL_IF( parsed != NULL ) + } /* if parse_tuple() == SUCCEED or no */ + + } /* for each testcase */ + + PASSED(); + return 0; + +error: + /*********** + * CLEANUP * + ***********/ + + if (parsed != NULL) free(parsed); + if (cpy != NULL) free(cpy); + + return 1; + +} /* test_parse_tuple */ + + +/*---------------------------------------------------------------------------- + * + * Function: test_populate_ros3_fa() + * + * Purpose: Verify behavior of `populate_ros3_fa()` + * + * Return: 0 if test passes + * 1 if failure + * + * Programmer: Jacob Smith + * 2017-11-13 + * + * Changes: None + * + *---------------------------------------------------------------------------- + */ +static unsigned +test_populate_ros3_fa(void) +{ +#ifdef H5_HAVE_ROS3_VFD + /************************* + * TEST-LOCAL STRUCTURES * + *************************/ + + /************************ + * TEST-LOCAL VARIABLES * + ************************/ + + hbool_t show_progress = FALSE; + int bad_version = 0xf87a; /* arbitrarily wrong version number */ +#endif /* H5_HAVE_ROS3_VFD */ + + TESTING("programmatic ros3 fapl population"); + +#ifndef H5_HAVE_ROS3_VFD + puts(" -SKIP-"); + puts(" Read-Only S3 VFD not enabled"); + fflush(stdout); + return 0; +#else +#if H5TOOLS_UTILS_TEST_DEBUG > 0 + show_progress = TRUE; +#endif /* H5TOOLS_UTILS_TEST_DEBUG */ + + HDassert(bad_version != H5FD__CURR_ROS3_FAPL_T_VERSION); + + /********* + * TESTS * + *********/ + + /* NULL fapl config pointer fails + */ + { + const char *values[] = {"x", "y", "z"}; + + if (show_progress) { HDprintf("NULL fapl pointer\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(NULL, values), + "fapl pointer cannot be null" ) + } + + /* NULL values pointer yields default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, TRUE, "u", "v", "w"}; + + if (show_progress) { HDprintf("NULL values pointer\n"); } + + JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, NULL), + "NULL values pointer yields \"default\" fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* all-empty values + * yields default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, TRUE, "u", "v", "w"}; + const char *values[] = {"", "", ""}; + + if (show_progress) { HDprintf("all empty values\n"); } + + JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, values), + "empty values yields \"default\" fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* successfully set fapl with values + * excess value is ignored + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"x", "y", "z", "a"}; + + if (show_progress) { HDprintf("successful full set\n"); } + + JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, values), + "four values" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( TRUE, fa.authenticate, NULL ) + JSVERIFY_STR( "x", fa.aws_region, NULL ) + JSVERIFY_STR( "y", fa.secret_id, NULL ) + JSVERIFY_STR( "z", fa.secret_key, NULL ) + } + + /* NULL region + * yeilds default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {NULL, "y", "z", NULL}; + + if (show_progress) { HDprintf("NULL region\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* empty region + * yeilds default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"", "y", "z", NULL}; + + if (show_progress) { HDprintf("empty region; non-empty id, key\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* region overflow + * yeilds default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = { + "somewhere over the rainbow not too high " \ + "there is another rainbow bounding some darkened sky", + "y", + "z"}; + + if (show_progress) { HDprintf("region overflow\n"); } + + HDassert(HDstrlen(values[0]) > H5FD__ROS3_MAX_REGION_LEN); + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* NULL id + * yields default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"x", NULL, "z", NULL}; + + if (show_progress) { HDprintf("NULL id\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* empty id (non-empty region, key) + * yeilds default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"x", "", "z", NULL}; + + if (show_progress) { HDprintf("empty id; non-empty region and key\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* id overflow + * partial set: region + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = { + "x", + "Why is it necessary to solve the problem? " \ + "What benefits will you receive by solving the problem? " \ + "What is the unknown? " \ + "What is it you don't yet understand? " \ + "What is the information you have? " \ + "What isn't the problem? " \ + "Is the information insufficient, redundant, or contradictory? " \ + "Should you draw a diagram or figure of the problem? " \ + "What are the boundaries of the problem? " \ + "Can you separate the various parts of the problem?", + "z"}; + + if (show_progress) { HDprintf("id overflow\n"); } + + HDassert(HDstrlen(values[1]) > H5FD__ROS3_MAX_SECRET_ID_LEN); + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "x", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* NULL key + * yields default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"x", "y", NULL, NULL}; + + if (show_progress) { HDprintf("NULL key\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* empty key (non-empty region, id) + * yeilds authenticating fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"x", "y", "", NULL}; + + if (show_progress) { HDprintf("empty key; non-empty region and id\n"); } + + JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( TRUE, fa.authenticate, NULL ) + JSVERIFY_STR( "x", fa.aws_region, NULL ) + JSVERIFY_STR( "y", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* empty key, region (non-empty id) + * yeilds default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"", "y", "", NULL}; + + if (show_progress) { HDprintf("empty key and region; non-empty id\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* empty key, id (non-empty region) + * yeilds default fapl + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = {"x", "", "", NULL}; + + if (show_progress) { HDprintf("empty key and id; non-empty region\n"); } + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "", fa.aws_region, NULL ) + JSVERIFY_STR( "", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* key overflow + * partial set: region, id + */ + { + H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; + const char *values[] = { + "x", + "y", + "Why is it necessary to solve the problem? " \ + "What benefits will you receive by solving the problem? " \ + "What is the unknown? " \ + "What is it you don't yet understand? " \ + "What is the information you have? " \ + "What isn't the problem? " \ + "Is the information insufficient, redundant, or contradictory? " \ + "Should you draw a diagram or figure of the problem? " \ + "What are the boundaries of the problem? " \ + "Can you separate the various parts of the problem?"}; + + if (show_progress) { HDprintf("key overflow\n"); } + + HDassert(HDstrlen(values[2]) > H5FD__ROS3_MAX_SECRET_KEY_LEN); + + JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), + "could not fill fapl" ) + JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) + JSVERIFY( FALSE, fa.authenticate, NULL ) + JSVERIFY_STR( "x", fa.aws_region, NULL ) + JSVERIFY_STR( "y", fa.secret_id, NULL ) + JSVERIFY_STR( "", fa.secret_key, NULL ) + } + + /* use case + */ + { + H5FD_ros3_fapl_t fa = {0, 0, "", "", ""}; + const char *values[] = { + "us-east-2", + "AKIAIMC3D3XLYXLN5COA", + "ugs5aVVnLFCErO/8uW14iWE3K5AgXMpsMlWneO/+" + }; + JSVERIFY( 1, + h5tools_populate_ros3_fapl(&fa, values), + "unable to set use case" ) + JSVERIFY( 1, fa.version, "version check" ) + JSVERIFY( 1, fa.authenticate, "should authenticate" ) + } + + PASSED(); + return 0; + +error : + /*********** + * CLEANUP * + ***********/ + + return 1; + +#endif /* H5_HAVE_ROS3_VFD */ + +} /* test_populate_ros3_fa */ + + +/*---------------------------------------------------------------------------- + * + * Function: test_set_configured_fapl() + * + * Purpose: Verify `h5tools_set_configured_fapl()` with ROS3 VFD + * + * Return: 0 if test passes + * 1 if failure + * + * Programmer: Jacob Smith + * 2018-07-12 + * + * Changes: None + * + *---------------------------------------------------------------------------- + */ +static unsigned +test_set_configured_fapl(void) +{ +#define UTIL_TEST_NOFAPL 1 +#define UTIL_TEST_DEFAULT 2 +#define UTIL_TEST_CREATE 3 + + /************************* + * TEST-LOCAL STRUCTURES * + *************************/ + typedef struct testcase { + const char message[88]; + int expected; + int fapl_choice; + const char vfdname[12]; + void *conf_fa; + } testcase; + + typedef struct other_fa_t { + int a; + int b; + int c; + } other_fa_t; + + /************************ + * TEST-LOCAL VARIABLES * + ************************/ + + hid_t fapl_id = -1; + other_fa_t wrong_fa = {0x432, 0xf82, 0x9093}; + H5FD_ros3_fapl_t ros3_anon_fa = {1, FALSE, "", "", ""}; + H5FD_ros3_fapl_t ros3_auth_fa = { + 1, /* fapl version */ + TRUE, /* authenticate */ + "us-east-1", /* aws region */ + "12345677890abcdef", /* simulate access key ID */ + "oiwnerwe9u0234nJw0-aoj+dsf", /* simulate secret key */ + }; + H5FD_hdfs_fapl_t hdfs_fa = { + 1, /* fapl version */ + "", /* namenode name */ + 0, /* namenode port */ + "", /* kerberos ticket cache */ + "", /* user name */ + 2048, /* stream buffer size */ + }; + unsigned n_cases = 7; /* number of common testcases */ + testcase cases[] = { + { "(common) should fail: no fapl id", + 0, + UTIL_TEST_NOFAPL, + "", + NULL, + }, + { "(common) should fail: no fapl id (with struct)", + 0, + UTIL_TEST_NOFAPL, + "", + &wrong_fa, + }, + { "(common) H5P_DEFAULT with no struct should succeed", + 1, + UTIL_TEST_DEFAULT, + "", + NULL, + }, + { "(common) H5P_DEFAULT with (ignored) struct should succeed", + 1, + UTIL_TEST_DEFAULT, + "", + &wrong_fa, + }, + { "(common) provided fapl entry should not fail", + 1, + UTIL_TEST_CREATE, + "", + NULL, + }, + { "(common) provided fapl entry should not fail; ignores struct", + 1, + UTIL_TEST_CREATE, + "", + &wrong_fa, + }, + { "(common) should fail: unrecoginzed vfd name", + 0, + UTIL_TEST_DEFAULT, + "unknown", + NULL, + }, + +#ifdef H5_HAVE_ROS3_VFD + /* WARNING: add number of ROS3 test cases after array definition + */ + { "(ROS3) should fail: no fapl id, no struct", + 0, + UTIL_TEST_NOFAPL, + "ros3", + NULL, + }, + { "(ROS3) should fail: no fapl id", + 0, + UTIL_TEST_NOFAPL, + "ros3", + &ros3_anon_fa, + }, + { "(ROS3) should fail: no struct", + 0, + UTIL_TEST_CREATE, + "ros3", + NULL, + }, + { "(ROS3) successful set", + 1, + UTIL_TEST_CREATE, + "ros3", + &ros3_anon_fa, + }, + { "(ROS3) should fail: attempt to set DEFAULT fapl", + 0, + UTIL_TEST_DEFAULT, + "ros3", + &ros3_anon_fa, + }, +#endif /* H5_HAVE_ROS3_VFD */ + +#ifdef H5_HAVE_LIBHDFS + /* WARNING: add number of HDFS test cases after array definition + */ + { "(HDFS) should fail: no fapl id, no struct", + 0, + UTIL_TEST_NOFAPL, + "hdfs", + NULL, + }, + { "(HDFS) should fail: no fapl id", + 0, + UTIL_TEST_NOFAPL, + "hdfs", + &hdfs_fa, + }, + { "(HDFS) should fail: no struct", + 0, + UTIL_TEST_CREATE, + "hdfs", + NULL, + }, + { "(HDFS) successful set", + 1, + UTIL_TEST_CREATE, + "hdfs", + &hdfs_fa, + }, + { "(HDFS) should fail: attempt to set DEFAULT fapl", + 0, + UTIL_TEST_DEFAULT, + "hdfs", + &hdfs_fa, + }, +#endif /* H5_HAVE_LIBHDFS */ + + }; /* testcases `cases` array */ + +#ifdef H5_HAVE_ROS3_VFD + n_cases += 5; +#endif /* H5_HAVE_ROS3_VFD */ + +#ifdef H5_HAVE_LIBHDFS + n_cases += 5; +#endif /* H5_HAVE_LIBHDFS */ + + TESTING("programmatic fapl set"); + + for (unsigned i = 0; i < n_cases; i++) { + int result; + testcase C = cases[i]; + + fapl_id = -1; + +#if UTIL_TEST_DEBUG + HDfprintf(stderr, "setup test %d\t%s\n", i, C.message); fflush(stderr); +#endif /* UTIL_TEST_DEBUG */ + + /* per-test setup */ + if (C.fapl_choice == UTIL_TEST_DEFAULT) { + fapl_id = H5P_DEFAULT; + } else if (C.fapl_choice == UTIL_TEST_CREATE) { + fapl_id = H5Pcreate(H5P_FILE_ACCESS); + FAIL_IF( fapl_id < 0 ) + } + +#if UTIL_TEST_DEBUG + HDfprintf(stderr, "before test\n"); fflush(stderr); +#endif /* UTIL_TEST_DEBUG */ + + /* test */ + result = h5tools_set_configured_fapl( + fapl_id, + C.vfdname, + C.conf_fa); + JSVERIFY( result, C.expected, C.message ) + +#if UTIL_TEST_DEBUG + HDfprintf(stderr, "after test\n"); fflush(stderr); +#endif /* UTIL_TEST_DEBUG */ + + /* per-test-teardown */ + if (fapl_id > 0) { + FAIL_IF( FAIL == H5Pclose(fapl_id) ) + } + fapl_id = -1; + +#if UTIL_TEST_DEBUG + HDfprintf(stderr, "after cleanup\n"); fflush(stderr); +#endif /* UTIL_TEST_DEBUG */ + + } + +#if UTIL_TEST_DEBUG + HDfprintf(stderr, "after loop\n"); fflush(stderr); +#endif /* UTIL_TEST_DEBUG */ + + PASSED(); + return 0; + +error : + /*********** + * CLEANUP * + ***********/ + +#if UTIL_TEST_DEBUG + HDfprintf(stderr, "ERROR\n"); fflush(stderr); +#endif /* UTIL_TEST_DEBUG */ + + if (fapl_id > 0) { + (void)H5Pclose(fapl_id); + } + + return 1; + +#undef UTIL_TEST_NOFAPL +#undef UTIL_TEST_DEFAULT +#undef UTIL_TEST_CREATE +} /* test_set_configured_fapl */ + + +/*---------------------------------------------------------------------------- + * + * Function: main() + * + * Purpose: Run all test functions. + * + * Return: 0 iff all test pass + * 1 iff any failures + * + * Programmer: Jacob Smith + * 2017-11-10 + * + * Changes: None. + * + *---------------------------------------------------------------------------- + */ +int +main(void) +{ + unsigned nerrors = 0; + +#ifdef _H5TEST_ + h5reset(); /* h5test? */ +#endif /* _H5TEST_ */ + + HDfprintf(stdout, "Testing h5tools_utils corpus.\n"); + + nerrors += test_parse_tuple(); + nerrors += test_populate_ros3_fa(); + nerrors += test_set_configured_fapl(); + + if (nerrors > 0) { + HDfprintf(stdout, "***** %d h5tools_utils TEST%s FAILED! *****\n", + nerrors, + nerrors > 1 ? "S" : ""); + nerrors = 1; + } else { + HDfprintf(stdout, "All h5tools_utils tests passed\n"); + } + + return (int)nerrors; + +} /* main */ + + diff --git a/tools/libtest/h5tools_utils.c b/tools/libtest/h5tools_utils.c deleted file mode 100644 index 56e8a01..0000000 --- a/tools/libtest/h5tools_utils.c +++ /dev/null @@ -1,1296 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright (c) 2017-2018, The HDF Group. * - * * - * All rights reserved. * - * * - * NOTICE: * - * All information contained herein is, and remains, the property of The HDF * - * Group. The intellectual and technical concepts contained herein are * - * proprietary to The HDF Group. Dissemination of this information or * - * reproduction of this material is strictly forbidden unless prior written * - * permission is obtained from The HDF Group. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* - * Purpose: unit-test functionality of the routines in `tools/lib/h5tools_utils` - * - * Jacob Smith 2017-11-10 - */ - -#include "hdf5.h" -#include "H5private.h" -#include "h5tools_utils.h" -/* #include "h5test.h" */ /* linking failure */ - -#define UTIL_TEST_DEBUG 0 - -#ifndef _H5TEST_ - -#define AT() fprintf(stdout, " at %s:%d in %s()...\n", \ - __FILE__, __LINE__, FUNC); - -#define FAILED(msg) { \ - fprintf(stdout, "*FAILED*"); AT() \ - if (msg == NULL) { \ - fprintf(stdout,"(NULL)\n"); \ - } else { \ - fprintf(stdout, "%s\n", msg); \ - } \ - fflush(stdout); \ -} - -#define TESTING(msg) { \ - fprintf(stdout, "TESTING %-62s", (msg)); \ - fflush(stdout); \ -} - -#define PASSED() { \ - fprintf(stdout, " PASSED\n"); \ - fflush(stdout); \ -} - -#endif /* ifndef _H5TEST_ */ - -#ifndef __js_test__ - -#define __js_test__ 1L - -/***************************************************************************** - * - * FILE-LOCAL TESTING MACROS - * - * Purpose: - * - * 1. Upon test failure, goto-jump to single-location teardown in test - * function. E.g., `error:` (consistency with HDF corpus) or - * `failed:` (reflects purpose). - * >>> using "error", in part because `H5E_BEGIN_TRY` expects it. - * 2. Increase clarity and reduce overhead found with `TEST_ERROR`. - * e.g., "if(somefunction(arg, arg2) < 0) TEST_ERROR:" - * requires reading of entire line to know whether this if/call is - * part of the test setup, test operation, or a test unto itself. - * 3. Provide testing macros with optional user-supplied failure message; - * if not supplied (NULL), generate comparison output in the spirit of - * test-driven development. E.g., "expected 5 but was -3" - * User messages clarify test's purpose in code, encouraging description - * without relying on comments. - * 4. Configurable expected-actual order in generated comparison strings. - * Some prefer `VERIFY(expected, actual)`, others - * `VERIFY(actual, expected)`. Provide preprocessor ifdef switch - * to satifsy both parties, assuming one paradigm per test file. - * (One could #undef and redefine the flag through the file as desired, - * but _why_.) - * - * Provided as courtesy, per consideration for inclusion in the library - * proper. - * - * Macros: - * - * JSVERIFY_EXP_ACT - ifdef flag, configures comparison order - * FAIL_IF() - check condition - * FAIL_UNLESS() - check _not_ condition - * JSVERIFY() - long-int equality check; prints reason/comparison - * JSVERIFY_NOT() - long-int inequality check; prints - * JSVERIFY_STR() - string equality check; prints - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *****************************************************************************/ - - -/*---------------------------------------------------------------------------- - * - * ifdef flag: JSVERIFY_EXP_ACT - * - * JSVERIFY macros accept arguments as (EXPECTED, ACTUAL[, reason]) - * default, if this is undefined, is (ACTUAL, EXPECTED[, reason]) - * - *---------------------------------------------------------------------------- - */ -#define JSVERIFY_EXP_ACT 1L - - -/*---------------------------------------------------------------------------- - * - * Macro: JSFAILED_AT() - * - * Purpose: - * - * Preface a test failure by printing "*FAILED*" and location to stdout - * Similar to `H5_FAILED(); AT();` from h5test.h - * - * *FAILED* at somefile.c:12 in function_name()... - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *---------------------------------------------------------------------------- - */ -#define JSFAILED_AT() { \ - HDprintf("*FAILED* at %s:%d in %s()...\n", __FILE__, __LINE__, FUNC); \ -} - - -/*---------------------------------------------------------------------------- - * - * Macro: FAIL_IF() - * - * Purpose: - * - * Make tests more accessible and less cluttered than - * `if (thing == otherthing()) TEST_ERROR` - * paradigm. - * - * The following lines are roughly equivalent: - * - * `if (myfunc() < 0) TEST_ERROR;` (as seen elsewhere in HDF tests) - * `FAIL_IF(myfunc() < 0)` - * - * Prints a generic "FAILED AT" line to stdout and jumps to `error`, - * similar to `TEST_ERROR` in h5test.h - * - * Programmer: Jacob Smith - * 2017-10-23 - * - *---------------------------------------------------------------------------- - */ -#define FAIL_IF(condition) \ -if (condition) { \ - JSFAILED_AT() \ - goto error; \ -} - - -/*---------------------------------------------------------------------------- - * - * Macro: FAIL_UNLESS() - * - * Purpose: - * - * TEST_ERROR wrapper to reduce cognitive overhead from "negative tests", - * e.g., "a != b". - * - * Opposite of FAIL_IF; fails if the given condition is _not_ true. - * - * `FAIL_IF( 5 != my_op() )` - * is equivalent to - * `FAIL_UNLESS( 5 == my_op() )` - * However, `JSVERIFY(5, my_op(), "bad return")` may be even clearer. - * (see JSVERIFY) - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *---------------------------------------------------------------------------- - */ -#define FAIL_UNLESS(condition) \ -if (!(condition)) { \ - JSFAILED_AT() \ - goto error; \ -} - - -/*---------------------------------------------------------------------------- - * - * Macro: JSERR_LONG() - * - * Purpose: - * - * Print an failure message for long-int arguments. - * ERROR-AT printed first. - * If `reason` is given, it is printed on own line and newlined after - * else, prints "expected/actual" aligned on own lines. - * - * *FAILED* at myfile.c:488 in somefunc()... - * forest must be made of trees. - * - * or - * - * *FAILED* at myfile.c:488 in somefunc()... - * ! Expected 425 - * ! Actual 3 - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *---------------------------------------------------------------------------- - */ -#define JSERR_LONG(expected, actual, reason) { \ - JSFAILED_AT() \ - if (reason!= NULL) { \ - HDprintf("%s\n", (reason)); \ - } else { \ - HDprintf(" ! Expected %ld\n ! Actual %ld\n", \ - (long)(expected), (long)(actual)); \ - } \ -} - - -/*---------------------------------------------------------------------------- - * - * Macro: JSERR_STR() - * - * Purpose: - * - * Print an failure message for string arguments. - * ERROR-AT printed first. - * If `reason` is given, it is printed on own line and newlined after - * else, prints "expected/actual" aligned on own lines. - * - * *FAILED* at myfile.c:421 in myfunc()... - * Blue and Red strings don't match! - * - * or - * - * *FAILED* at myfile.c:421 in myfunc()... - * !!! Expected: - * this is my expected - * string - * !!! Actual: - * not what I expected at all - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *---------------------------------------------------------------------------- - */ -#define JSERR_STR(expected, actual, reason) { \ - JSFAILED_AT() \ - if ((reason) != NULL) { \ - HDprintf("%s\n", (reason)); \ - } else { \ - HDprintf("!!! Expected:\n%s\n!!!Actual:\n%s\n", \ - (expected), (actual)); \ - } \ -} - -#ifdef JSVERIFY_EXP_ACT - - -/*---------------------------------------------------------------------------- - * - * Macro: JSVERIFY() - * - * Purpose: - * - * Verify that two long integers are equal. - * If unequal, print failure message - * (with `reason`, if not NULL; expected/actual if NULL) - * and jump to `error` at end of function - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *---------------------------------------------------------------------------- - */ -#define JSVERIFY(expected, actual, reason) \ -if ((long)(actual) != (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)) \ - goto error; \ -} /* JSVERIFY */ - - -/*---------------------------------------------------------------------------- - * - * Macro: JSVERIFY_NOT() - * - * Purpose: - * - * Verify that two long integers are _not_ equal. - * If equal, print failure message - * (with `reason`, if not NULL; expected/actual if NULL) - * and jump to `error` at end of function - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *---------------------------------------------------------------------------- - */ -#define JSVERIFY_NOT(expected, actual, reason) \ -if ((long)(actual) == (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)) \ - goto error; \ -} /* JSVERIFY_NOT */ - - -/*---------------------------------------------------------------------------- - * - * Macro: JSVERIFY_STR() - * - * Purpose: - * - * Verify that two strings are equal. - * If unequal, print failure message - * (with `reason`, if not NULL; expected/actual if NULL) - * and jump to `error` at end of function - * - * Programmer: Jacob Smith - * 2017-10-24 - * - *---------------------------------------------------------------------------- - */ -#define JSVERIFY_STR(expected, actual, reason) \ -if (strcmp((actual), (expected)) != 0) { \ - JSERR_STR((expected), (actual), (reason)); \ - goto error; \ -} /* JSVERIFY_STR */ - - -#else /* JSVERIFY_EXP_ACT not defined */ - /* Repeats macros above, but with actual/expected parameters reversed. */ - - -/*---------------------------------------------------------------------------- - * Macro: JSVERIFY() - * See: JSVERIFY documentation above. - * Programmer: Jacob Smith - * 2017-10-14 - *---------------------------------------------------------------------------- - */ -#define JSVERIFY(actual, expected, reason) \ -if ((long)(actual) != (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)); \ - goto error; \ -} /* JSVERIFY */ - - -/*---------------------------------------------------------------------------- - * Macro: JSVERIFY_NOT() - * See: JSVERIFY_NOT documentation above. - * Programmer: Jacob Smith - * 2017-10-14 - *---------------------------------------------------------------------------- - */ -#define JSVERIFY_NOT(actual, expected, reason) \ -if ((long)(actual) == (long)(expected)) { \ - JSERR_LONG((expected), (actual), (reason)) \ - goto error; \ -} /* JSVERIFY_NOT */ - - -/*---------------------------------------------------------------------------- - * Macro: JSVERIFY_STR() - * See: JSVERIFY_STR documentation above. - * Programmer: Jacob Smith - * 2017-10-14 - *---------------------------------------------------------------------------- - */ -#define JSVERIFY_STR(actual, expected, reason) \ -if (strcmp((actual), (expected)) != 0) { \ - JSERR_STR((expected), (actual), (reason)); \ - goto error; \ -} /* JSVERIFY_STR */ - -#endif /* ifdef/else JSVERIFY_EXP_ACT */ - -#endif /* __js_test__ */ - -/* if > 0, be very verbose when performing tests */ -#define H5TOOLS_UTILS_TEST_DEBUG 0 - -/******************/ -/* TEST FUNCTIONS */ -/******************/ - - -/*---------------------------------------------------------------------------- - * - * Function: test_parse_tuple() - * - * Purpose: - * - * Provide unit tests and specification for the `parse_tuple()` function. - * - * Return: - * - * 0 Tests passed. - * 1 Tests failed. - * - * Programmer: Jacob Smith - * 2017-11-11 - * - * Changes: None. - * - *---------------------------------------------------------------------------- - */ -static unsigned -test_parse_tuple(void) -{ - /************************* - * TEST-LOCAL STRUCTURES * - *************************/ - - struct testcase { - const char *test_msg; /* info about test case */ - const char *in_str; /* input string */ - int sep; /* separator "character" */ - herr_t exp_ret; /* expected SUCCEED / FAIL */ - unsigned exp_nelems; /* expected number of elements */ - /* (no more than 7!) */ - const char *exp_elems[7]; /* list of elements (no more than 7!) */ - }; - - /****************** - * TEST VARIABLES * - ******************/ - - struct testcase cases[] = { - { "bad start", - "words(before)", - ';', - FAIL, - 0, - {NULL}, - }, - { "tuple not closed", - "(not ok", - ',', - FAIL, - 0, - {NULL}, - }, - { "empty tuple", - "()", - '-', - SUCCEED, - 1, - {""}, - }, - { "no separator", - "(stuff keeps on going)", - ',', - SUCCEED, - 1, - {"stuff keeps on going"}, - }, - { "4-ple, escaped seperator", - "(elem0,elem1,el\\,em2,elem3)", /* "el\,em" */ - ',', - SUCCEED, - 4, - {"elem0", "elem1", "el,em2", "elem3"}, - }, - { "5-ple, escaped escaped separator", - "(elem0,elem1,el\\\\,em2,elem3)", - ',', - SUCCEED, - 5, - {"elem0", "elem1", "el\\", "em2", "elem3"}, - }, - { "escaped non-comma separator", - "(5-2-7-2\\-6-2)", - '-', - SUCCEED, - 5, - {"5","2","7","2-6","2"}, - }, - { "embedded close-paren", - "(be;fo)re)", - ';', - SUCCEED, - 2, - {"be", "fo)re"}, - }, - { "embedded non-escaping backslash", - "(be;fo\\re)", - ';', - SUCCEED, - 2, - {"be", "fo\\re"}, - }, - { "double close-paren at end", - "(be;fore))", - ';', - SUCCEED, - 2, - {"be", "fore)"}, - }, - { "empty elements", - "(;a1;;a4;)", - ';', - SUCCEED, - 5, - {"", "a1", "", "a4", ""}, - }, - { "nested tuples with different separators", - "((4,e,a);(6,2,a))", - ';', - SUCCEED, - 2, - {"(4,e,a)","(6,2,a)"}, - }, - { "nested tuples with same separators", - "((4,e,a),(6,2,a))", - ',', - SUCCEED, - 6, - {"(4","e","a)","(6","2","a)"}, - }, - { "real-world use case", - "(us-east-2,AKIAIMC3D3XLYXLN5COA,ugs5aVVnLFCErO/8uW14iWE3K5AgXMpsMlWneO/+)", - ',', - SUCCEED, - 3, - {"us-east-2", - "AKIAIMC3D3XLYXLN5COA", - "ugs5aVVnLFCErO/8uW14iWE3K5AgXMpsMlWneO/+"}, - } - }; - struct testcase tc; - unsigned n_tests = 14; - unsigned i = 0; - unsigned count = 0; - unsigned elem_i = 0; - char **parsed = NULL; - char *cpy = NULL; - herr_t success = TRUE; - hbool_t show_progress = FALSE; - - - - TESTING("arbitrary-count tuple parsing"); - -#if H5TOOLS_UTILS_TEST_DEBUG > 0 - show_progress = TRUE; -#endif /* H5TOOLS_UTILS_TEST_DEBUG */ - - /********* - * TESTS * - *********/ - - for (i = 0; i < n_tests; i++) { - - /* SETUP - */ - HDassert(parsed == NULL); - HDassert(cpy == NULL); - tc = cases[i]; - if (show_progress == TRUE) { - printf("testing %d: %s...\n", i, tc.test_msg); - } - - /* VERIFY - */ - success = parse_tuple(tc.in_str, tc.sep, - &cpy, &count, &parsed); - - JSVERIFY( tc.exp_ret, success, "function returned incorrect value" ) - JSVERIFY( tc.exp_nelems, count, NULL ) - if (success == SUCCEED) { - FAIL_IF( parsed == NULL ) - for (elem_i = 0; elem_i < count; elem_i++) { - JSVERIFY_STR( tc.exp_elems[elem_i], parsed[elem_i], NULL ) - } - /* TEARDOWN */ - HDassert(parsed != NULL); - HDassert(cpy != NULL); - free(parsed); - parsed = NULL; - free(cpy); - cpy = NULL; - } else { - FAIL_IF( parsed != NULL ) - } /* if parse_tuple() == SUCCEED or no */ - - } /* for each testcase */ - - PASSED(); - return 0; - -error: - /*********** - * CLEANUP * - ***********/ - - if (parsed != NULL) free(parsed); - if (cpy != NULL) free(cpy); - - return 1; - -} /* test_parse_tuple */ - - -/*---------------------------------------------------------------------------- - * - * Function: test_populate_ros3_fa() - * - * Purpose: Verify behavior of `populate_ros3_fa()` - * - * Return: 0 if test passes - * 1 if failure - * - * Programmer: Jacob Smith - * 2017-11-13 - * - * Changes: None - * - *---------------------------------------------------------------------------- - */ -static unsigned -test_populate_ros3_fa(void) -{ -#ifdef H5_HAVE_ROS3_VFD - /************************* - * TEST-LOCAL STRUCTURES * - *************************/ - - /************************ - * TEST-LOCAL VARIABLES * - ************************/ - - hbool_t show_progress = FALSE; - int bad_version = 0xf87a; /* arbitrarily wrong version number */ -#endif /* H5_HAVE_ROS3_VFD */ - - TESTING("programmatic ros3 fapl population"); - -#ifndef H5_HAVE_ROS3_VFD - puts(" -SKIP-"); - puts(" Read-Only S3 VFD not enabled"); - fflush(stdout); - return 0; -#else -#if H5TOOLS_UTILS_TEST_DEBUG > 0 - show_progress = TRUE; -#endif /* H5TOOLS_UTILS_TEST_DEBUG */ - - HDassert(bad_version != H5FD__CURR_ROS3_FAPL_T_VERSION); - - /********* - * TESTS * - *********/ - - /* NULL fapl config pointer fails - */ - { - const char *values[] = {"x", "y", "z"}; - - if (show_progress) { HDprintf("NULL fapl pointer\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(NULL, values), - "fapl pointer cannot be null" ) - } - - /* NULL values pointer yields default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, TRUE, "u", "v", "w"}; - - if (show_progress) { HDprintf("NULL values pointer\n"); } - - JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, NULL), - "NULL values pointer yields \"default\" fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* all-empty values - * yields default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, TRUE, "u", "v", "w"}; - const char *values[] = {"", "", ""}; - - if (show_progress) { HDprintf("all empty values\n"); } - - JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, values), - "empty values yields \"default\" fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* successfully set fapl with values - * excess value is ignored - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"x", "y", "z", "a"}; - - if (show_progress) { HDprintf("successful full set\n"); } - - JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, values), - "four values" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( TRUE, fa.authenticate, NULL ) - JSVERIFY_STR( "x", fa.aws_region, NULL ) - JSVERIFY_STR( "y", fa.secret_id, NULL ) - JSVERIFY_STR( "z", fa.secret_key, NULL ) - } - - /* NULL region - * yeilds default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {NULL, "y", "z", NULL}; - - if (show_progress) { HDprintf("NULL region\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* empty region - * yeilds default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"", "y", "z", NULL}; - - if (show_progress) { HDprintf("empty region; non-empty id, key\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* region overflow - * yeilds default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = { - "somewhere over the rainbow not too high " \ - "there is another rainbow bounding some darkened sky", - "y", - "z"}; - - if (show_progress) { HDprintf("region overflow\n"); } - - HDassert(strlen(values[0]) > H5FD__ROS3_MAX_REGION_LEN); - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* NULL id - * yields default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"x", NULL, "z", NULL}; - - if (show_progress) { HDprintf("NULL id\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* empty id (non-empty region, key) - * yeilds default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"x", "", "z", NULL}; - - if (show_progress) { HDprintf("empty id; non-empty region and key\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* id overflow - * partial set: region - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = { - "x", - "Why is it necessary to solve the problem? " \ - "What benefits will you receive by solving the problem? " \ - "What is the unknown? " \ - "What is it you don't yet understand? " \ - "What is the information you have? " \ - "What isn't the problem? " \ - "Is the information insufficient, redundant, or contradictory? " \ - "Should you draw a diagram or figure of the problem? " \ - "What are the boundaries of the problem? " \ - "Can you separate the various parts of the problem?", - "z"}; - - if (show_progress) { HDprintf("id overflow\n"); } - - HDassert(strlen(values[1]) > H5FD__ROS3_MAX_SECRET_ID_LEN); - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "x", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* NULL key - * yields default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"x", "y", NULL, NULL}; - - if (show_progress) { HDprintf("NULL key\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* empty key (non-empty region, id) - * yeilds authenticating fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"x", "y", "", NULL}; - - if (show_progress) { HDprintf("empty key; non-empty region and id\n"); } - - JSVERIFY( 1, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( TRUE, fa.authenticate, NULL ) - JSVERIFY_STR( "x", fa.aws_region, NULL ) - JSVERIFY_STR( "y", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* empty key, region (non-empty id) - * yeilds default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"", "y", "", NULL}; - - if (show_progress) { HDprintf("empty key and region; non-empty id\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* empty key, id (non-empty region) - * yeilds default fapl - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = {"x", "", "", NULL}; - - if (show_progress) { HDprintf("empty key and id; non-empty region\n"); } - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "", fa.aws_region, NULL ) - JSVERIFY_STR( "", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* key overflow - * partial set: region, id - */ - { - H5FD_ros3_fapl_t fa = {bad_version, FALSE, "a", "b", "c"}; - const char *values[] = { - "x", - "y", - "Why is it necessary to solve the problem? " \ - "What benefits will you receive by solving the problem? " \ - "What is the unknown? " \ - "What is it you don't yet understand? " \ - "What is the information you have? " \ - "What isn't the problem? " \ - "Is the information insufficient, redundant, or contradictory? " \ - "Should you draw a diagram or figure of the problem? " \ - "What are the boundaries of the problem? " \ - "Can you separate the various parts of the problem?"}; - - if (show_progress) { HDprintf("key overflow\n"); } - - HDassert(strlen(values[2]) > H5FD__ROS3_MAX_SECRET_KEY_LEN); - - JSVERIFY( 0, h5tools_populate_ros3_fapl(&fa, values), - "could not fill fapl" ) - JSVERIFY( H5FD__CURR_ROS3_FAPL_T_VERSION, fa.version, NULL ) - JSVERIFY( FALSE, fa.authenticate, NULL ) - JSVERIFY_STR( "x", fa.aws_region, NULL ) - JSVERIFY_STR( "y", fa.secret_id, NULL ) - JSVERIFY_STR( "", fa.secret_key, NULL ) - } - - /* use case - */ - { - H5FD_ros3_fapl_t fa = {0, 0, "", "", ""}; - const char *values[] = { - "us-east-2", - "AKIAIMC3D3XLYXLN5COA", - "ugs5aVVnLFCErO/8uW14iWE3K5AgXMpsMlWneO/+" - }; - JSVERIFY( 1, - h5tools_populate_ros3_fapl(&fa, values), - "unable to set use case" ) - JSVERIFY( 1, fa.version, "version check" ) - JSVERIFY( 1, fa.authenticate, "should authenticate" ) - } - - PASSED(); - return 0; - -error : - /*********** - * CLEANUP * - ***********/ - - return 1; - -#endif /* H5_HAVE_ROS3_VFD */ - -} /* test_populate_ros3_fa */ - - -/*---------------------------------------------------------------------------- - * - * Function: test_set_configured_fapl() - * - * Purpose: Verify `h5tools_set_configured_fapl()` with ROS3 VFD - * - * Return: 0 if test passes - * 1 if failure - * - * Programmer: Jacob Smith - * 2018-07-12 - * - * Changes: None - * - *---------------------------------------------------------------------------- - */ -static unsigned -test_set_configured_fapl(void) -{ -#define UTIL_TEST_NOFAPL 1 -#define UTIL_TEST_DEFAULT 2 -#define UTIL_TEST_CREATE 3 - - /************************* - * TEST-LOCAL STRUCTURES * - *************************/ - typedef struct testcase { - const char message[88]; - int expected; - int fapl_choice; - const char vfdname[12]; - void *conf_fa; - } testcase; - - typedef struct other_fa_t { - int a; - int b; - int c; - } other_fa_t; - - /************************ - * TEST-LOCAL VARIABLES * - ************************/ - - hid_t fapl_id = -1; - other_fa_t wrong_fa = {0x432, 0xf82, 0x9093}; - H5FD_ros3_fapl_t ros3_anon_fa = {1, FALSE, "", "", ""}; - H5FD_ros3_fapl_t ros3_auth_fa = { - 1, /* fapl version */ - TRUE, /* authenticate */ - "us-east-1", /* aws region */ - "12345677890abcdef", /* simulate access key ID */ - "oiwnerwe9u0234nJw0-aoj+dsf", /* simulate secret key */ - }; - H5FD_hdfs_fapl_t hdfs_fa = { - 1, /* fapl version */ - "", /* namenode name */ - 0, /* namenode port */ - "", /* kerberos ticket cache */ - "", /* user name */ - 2048, /* stream buffer size */ - }; - unsigned n_cases = 7; /* number of common testcases */ - testcase cases[] = { - { "(common) should fail: no fapl id", - 0, - UTIL_TEST_NOFAPL, - "", - NULL, - }, - { "(common) should fail: no fapl id (with struct)", - 0, - UTIL_TEST_NOFAPL, - "", - &wrong_fa, - }, - { "(common) H5P_DEFAULT with no struct should succeed", - 1, - UTIL_TEST_DEFAULT, - "", - NULL, - }, - { "(common) H5P_DEFAULT with (ignored) struct should succeed", - 1, - UTIL_TEST_DEFAULT, - "", - &wrong_fa, - }, - { "(common) provided fapl entry should not fail", - 1, - UTIL_TEST_CREATE, - "", - NULL, - }, - { "(common) provided fapl entry should not fail; ignores struct", - 1, - UTIL_TEST_CREATE, - "", - &wrong_fa, - }, - { "(common) should fail: unrecoginzed vfd name", - 0, - UTIL_TEST_DEFAULT, - "unknown", - NULL, - }, - -#ifdef H5_HAVE_ROS3_VFD - /* WARNING: add number of ROS3 test cases after array definition - */ - { "(ROS3) should fail: no fapl id, no struct", - 0, - UTIL_TEST_NOFAPL, - "ros3", - NULL, - }, - { "(ROS3) should fail: no fapl id", - 0, - UTIL_TEST_NOFAPL, - "ros3", - &ros3_anon_fa, - }, - { "(ROS3) should fail: no struct", - 0, - UTIL_TEST_CREATE, - "ros3", - NULL, - }, - { "(ROS3) successful set", - 1, - UTIL_TEST_CREATE, - "ros3", - &ros3_anon_fa, - }, - { "(ROS3) should fail: attempt to set DEFAULT fapl", - 0, - UTIL_TEST_DEFAULT, - "ros3", - &ros3_anon_fa, - }, -#endif /* H5_HAVE_ROS3_VFD */ - -#ifdef H5_HAVE_LIBHDFS - /* WARNING: add number of HDFS test cases after array definition - */ - { "(HDFS) should fail: no fapl id, no struct", - 0, - UTIL_TEST_NOFAPL, - "hdfs", - NULL, - }, - { "(HDFS) should fail: no fapl id", - 0, - UTIL_TEST_NOFAPL, - "hdfs", - &hdfs_fa, - }, - { "(HDFS) should fail: no struct", - 0, - UTIL_TEST_CREATE, - "hdfs", - NULL, - }, - { "(HDFS) successful set", - 1, - UTIL_TEST_CREATE, - "hdfs", - &hdfs_fa, - }, - { "(HDFS) should fail: attempt to set DEFAULT fapl", - 0, - UTIL_TEST_DEFAULT, - "hdfs", - &hdfs_fa, - }, -#endif /* H5_HAVE_LIBHDFS */ - - }; /* testcases `cases` array */ - -#ifdef H5_HAVE_ROS3_VFD - n_cases += 5; -#endif /* H5_HAVE_ROS3_VFD */ - -#ifdef H5_HAVE_LIBHDFS - n_cases += 5; -#endif /* H5_HAVE_LIBHDFS */ - - TESTING("programmatic fapl set"); - - for (unsigned i = 0; i < n_cases; i++) { - int result; - testcase C = cases[i]; - - fapl_id = -1; - -#if UTIL_TEST_DEBUG - HDfprintf(stderr, "setup test %d\t%s\n", i, C.message); fflush(stderr); -#endif /* UTIL_TEST_DEBUG */ - - /* per-test setup */ - if (C.fapl_choice == UTIL_TEST_DEFAULT) { - fapl_id = H5P_DEFAULT; - } else if (C.fapl_choice == UTIL_TEST_CREATE) { - fapl_id = H5Pcreate(H5P_FILE_ACCESS); - FAIL_IF( fapl_id < 0 ) - } - -#if UTIL_TEST_DEBUG - HDfprintf(stderr, "before test\n"); fflush(stderr); -#endif /* UTIL_TEST_DEBUG */ - - /* test */ - result = h5tools_set_configured_fapl( - fapl_id, - C.vfdname, - C.conf_fa); - JSVERIFY( result, C.expected, C.message ) - -#if UTIL_TEST_DEBUG - HDfprintf(stderr, "after test\n"); fflush(stderr); -#endif /* UTIL_TEST_DEBUG */ - - /* per-test-teardown */ - if (fapl_id > 0) { - FAIL_IF( FAIL == H5Pclose(fapl_id) ) - } - fapl_id = -1; - -#if UTIL_TEST_DEBUG - HDfprintf(stderr, "after cleanup\n"); fflush(stderr); -#endif /* UTIL_TEST_DEBUG */ - - } - -#if UTIL_TEST_DEBUG - HDfprintf(stderr, "after loop\n"); fflush(stderr); -#endif /* UTIL_TEST_DEBUG */ - - PASSED(); - return 0; - -error : - /*********** - * CLEANUP * - ***********/ - -#if UTIL_TEST_DEBUG - HDfprintf(stderr, "ERROR\n"); fflush(stderr); -#endif /* UTIL_TEST_DEBUG */ - - if (fapl_id > 0) { - (void)H5Pclose(fapl_id); - } - - return 1; - -#undef UTIL_TEST_NOFAPL -#undef UTIL_TEST_DEFAULT -#undef UTIL_TEST_CREATE -} /* test_set_configured_fapl */ - - -/*---------------------------------------------------------------------------- - * - * Function: main() - * - * Purpose: Run all test functions. - * - * Return: 0 iff all test pass - * 1 iff any failures - * - * Programmer: Jacob Smith - * 2017-11-10 - * - * Changes: None. - * - *---------------------------------------------------------------------------- - */ -int -main(void) -{ - unsigned nerrors = 0; - -#ifdef _H5TEST_ - h5reset(); /* h5test? */ -#endif /* _H5TEST_ */ - - HDfprintf(stdout, "Testing h5tools_utils corpus.\n"); - - nerrors += test_parse_tuple(); - nerrors += test_populate_ros3_fa(); - nerrors += test_set_configured_fapl(); - - if (nerrors > 0) { - HDfprintf(stdout, "***** %d h5tools_utils TEST%s FAILED! *****\n", - nerrors, - nerrors > 1 ? "S" : ""); - nerrors = 1; - } else { - HDfprintf(stdout, "All h5tools_utils tests passed\n"); - } - - return (int)nerrors; - -} /* main */ - - -- cgit v0.12