* Brings CMake updates from develop * Brings reduction in pedantic casts from develop * Purges UFAIL from the library (#637) * Committing clang-format changes * Purges UFAIL from the library * H5HL_insert change requested in PR Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Removes gratuitous (double)x.yF casts (#632) * Committing clang-format changes * Removes gratuitous (double)x.yF casts * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Committing clang-format changes * Cleans up a const warning left over from previous constification (#633) * Committing clang-format changes * Adds consts to a few global variables * Cleans up a const warning left over from previous constification Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Formatted source * Bring over some VOL registration changes * VOL cleanup * H5VL_request_status_t substitutions * H5F.c cleanup * Minor API tweaks from develop * Moves H5G package init/teardown to H5Gint.c * H5G cleanup * H5M cleanup * H5SM cleanup * H5T cleanup * H5R cleanup * H5Lpublic.h cleanup * H5L cleanup * H5O cleanup * H5A, H5CS, and H5AC cleanup * Moved H5A init/teardown code to H5Aint.c * Moves H5D I/O functions to H5D.c * H5D cleanup * Misc minor cleanup * H5P close cleanup * H5Tpublic.h cleanup * Fixes err_compat test * H5PLpublic.h cleanup * Updates H5Ppublic.h * H5Fpublic.h updates * H5A.c cleanup * Brings over H5Aexists and related changes * Brings CMake shell testing changes from develop * Close callback changes * H5R and H5Tcommit normalization * err_compat test works now * H5O tweaks * Updates VOL registration code * Brings over H5VL_create_object * H5Tconv.c reformatting * H5T.c tweaks * Brings datatype and reference updates from develop * Brings VOL plugin loading changes from develop * Brings event sets from develop * Brings async functions over * Tools changes * Brings over many tools changes from develop * Brings VOL flags from develop * Fixes h5dump double/float tests * Updates h5repack tests * Brings h5diff test changes from develop * Last h5dump changes * Brings test changes from develop * Committing clang-format changes * Tidied h5_testing() * Brings chunk iteration code + misc from develop * Updates vds test * Enables external link parallel test * Brings updated property lists from develop * H5G changes from develop * H5MF cleanup * Brings vfd_swmr test back into CMake * Updates threadsafe test * Updates plist test * Brings recent changes from develop * Require a C++11 compiler to build the C++ wrappers (#693) * Committing clang-format changes * Requires a C++11 compiler to build the C++ wrappers Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Fix H5FD_mpio_Debug="rw" can report MPI_count instead of bytes (#699) * Removes pre-C99 build and header cruft (#700) * Assumes ANSI C headers exist * Assumes stdbool.h, stdint.h, and inttypes.h are present * Assumes the C++ compiler can handle stdint.h * Removes all work-arounds for missing functionality, especially stdbool.h Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Updates release documents * Brings parallel changes from develop * Adds a VFD/parallel check program for the VFD SWMR shell test * Updates MANIFEST * Disable building VFD SWMR acceptance tests on CMake * Removes err.h from genall5.c * Partial cleanup of H5Cpkg.h * Fixes printf specifiers in H5Cdbg.c * Java and fortran cmake changes (#694) * OESS-98 convert plugin option to FetchContent, add tests * Fixes for pkcfg files because of plugin option * OESS-98 fix tools test for plugins * Keep doxygen comments under 100 chars long - format hint * Whitespace * HDFFV-11144 - Reclassify CMake messages * HDFFV-11099/11100 added help text * Reworked switch statement to compare string instead * Fix typo * Update CDash mode * Correct name of threadsafe * Correct option name * Undo accidental commit * Note LLVM 10 to 11 format default changes * Update format plugin * Undo clang-format version 11 changes * One more correction * Update supported platforms * Revert whitespace changes * Correct whitespace * Changes from PR#3 * HDFFV-11213 added option to control gcc10 warnings diagnostics * HDFFV-11212 Use the new references correctly in JNI utility and tests * format source * Fix typo * Add new test file * HDFFV-11212 - update test and remove unused arg * Minor non-space formatting changes * Use H5I_INVALID_ID instead of "-1" * source formatting * add missing testfile, update jni function * Undo commit of debug code * remove mislocated file * Fix h5repack test for handling of fapls and id close * Update h5diff test files usage text * HDFFV-11212 add new ref tests for JNI export dataset * src format update * Remove blank line typo * src format typo * long double requires %Lg * Another long double foramt specifer S.B. %Lg * issue with t128bit test * Windows issue with h5dump and type. * Fix review issues * refactor function nesting and fix error checks * format fixes * Remove untested functions and javadoc quiet comments * Restore TRY block. * Change string append errors to memory exception * revert to H5_JNI_FATAL_ERROR - support functions need work * Add assertion error for h5util functions * remove duplicate function * format fix * Revert HD function error handling * Update copyright comments * GH #386 java folder copyright corrections * Whitespace * GH #359 implement and fix tools 1.6 API usage * remove excessive comments * Flip inits to correct ifdef section * rework ifdef to be simpler * format issue * Reformat ifdef inits * remove static attribute * format compliance * Update names * Revert because logic relies on float not being int * Changes noticed from creating merge of #412 * Double underscore change * Correct compiler version variable used * Remove header guard underscores * Whitespace cleanup * Split format source and commit changes on repo push * remove pre-split setting * Change windows TS to use older VS. * correct window os name * HDFFV-11212 JNI export util and Javadoc * Suggested review changes * Another change found * Committing clang-format changes * HDFFV-11113 long double in tools * HDFFV-11113 add note * Disable long double tests for now * HDFFV-11228 remove arbitrary CMake warning groups. * Make each flag a string * Some Javadoc warning fixes * Updated javadoc fixes * # WARNING: head commit changed in the meantime HDFFV-11229 Fix long double usage in tools and java Changed h5dump and h5ls to just print 128-bit for long double type. Added test and file for dataset and attributes with all three float types. * Committing clang-format changes * HDFFV-11229 Add release note * HDFFV-11229 windows testfile needed * fix typo * Remove non supported message text * HDFFV-11229 - change ldouble test to check both native and general * HDFFV-11229 add second file compare * HDFFV-11229 fix reference file * HDFFV-11229 autotools check two refs * HDFFV-11229 revert back to removal of NATIVE_LDOUBLE in tools output * Committing clang-format changes * Update release note * Update attribute type of ref file * Change source of ninja for macs * try port instead of brew * Recommended is to use brew. * Undo non long double changes * remove unneeded file * Fix perl and doxygen CMake code * Add "option" command for clang options * Rework CMake add_custom to use the BYPRODUCTS argument * Add stamp files to BYPRODUCTS * Only one copy of file exists * Fix custom cmmand depends targets * Fix fortran custom command DEPENDS * Add LD_LIBRARY_PATH to tests * Add custom target for DEPENDS * Add h5detect conditionaly to generated target DEPENDS * Correct DEPENDS targets * Parallel builds need the mpi compiler for pkgconfig scripts. * install only if MPI build * Fortran target depends * Remove incorrect source attribute * doxygen adjustments * doxygen build updates * Correct version * Correct function version - function has been merged to 1.12 * Correct version string for map functions * Cleanup warnings for tools debug builds * TRILAB-227 - fix indexing for h5diff selections * Correct location of pos to index function call * TRILAB-227 Enable test * Quote subset args * Use MATCHES because of AppleClang * if blocks needed for build modes * Update list of DT platforms * VS2019 correctly displays float values * revert VS2019 change * Issue #669 remove version from pkgcfg filename * remove version from h5cc script * Java reference functions updated enabled fortran in cmake gcc action yaml file java reference test changed to correctly test refs jni reference functions that create ids changed to use jni id logging * Correct BYPRODUCTS argument * Correct more genereated files BYPRODUCTS * BYPRODUCTS must have unique locations * Fix typo Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Removes alternative function enter/leave macro scheme (#678) * Committing clang-format changes * Converted BEGIN_FUNC, etc. macros to FUNC_ENTER * Rips out the BEGIN_FUNC, etc. macros * Removes 'end if', etc. comments from H5HL package * Committing clang-format changes * Fixes an H5EA iterate issue * Fixes an issue in the H5FA iterator code * Further cleanup in bin/trace after macro removal * Iterator changes in H5EA and H5FA Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Split H5L.c internal code to H5Lint.c (#691) * Committing clang-format changes * Splits internal parts of H5L.c to H5Lint.c Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Clean up type size checks in configure.ac (#702) * Committing clang-format changes * C++ warning and build fixes (#707) * Committing clang-format changes * C++ build and warning updates * Fixes all warnings on C++ (with gcc 9.3) * Updates CMake and Autotools C++ builds * Undo warning clobber Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Removes some DEC Alpha cruft from H5detect and H5private.h (#708) * Cleans up hsize_t and haddr_t size guessing (#709) * Cleans up definitions of haddr_t and hsize_t + cruft removal * Formatted source * Updates PGI C/C++ configurations (#715) * Updates PGI C/C++ configurations Tweaks some settings and configures pgc++ to use C++11 * Updated copyright information * Adds an Intel C++ configuration file (#716) * Adds an Intel C++ configuration file * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Updates bin/trace script to correctly wrap H5TRACE macros near clang-format column limit (#719) * Removes clang-format comments from H5O.c call * Fixes bin/trace to correctly wrap lines near the clang-format limit * Removed unused variable from bin/trace * Fixes issue with ccmake that prevents building Fortran (#723) ccmake runs iteratively, and the check_fortran_source_runs macros were clobbering a single output file that did not get updated on further configure iterations Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
717 lines
18 KiB
C++
717 lines
18 KiB
C++
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
* Copyright by The HDF Group. *
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
* All rights reserved. *
|
|
* *
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
* the COPYING file, which can be found at the root of the source code *
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
|
* If you do not have access to either file, you may request a copy from *
|
|
* help@hdfgroup.org. *
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
/* ptableTest.cpp */
|
|
|
|
#include <iostream>
|
|
#include "ptableTest.h"
|
|
|
|
using namespace H5;
|
|
using namespace std;
|
|
|
|
#define TEST_FILE "packettest.h5"
|
|
|
|
/* Main test function */
|
|
int
|
|
main(void)
|
|
{
|
|
herr_t err;
|
|
herr_t num_errors = 0;
|
|
|
|
/* Create new HDF5 file */
|
|
fileID = H5Fcreate(TEST_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
|
if (fileID < 0) {
|
|
fprintf(stderr, "Couldn't create file.\n");
|
|
num_errors = 1;
|
|
}
|
|
else {
|
|
|
|
num_errors += BasicTest();
|
|
|
|
num_errors += TestCompoundDatatype();
|
|
|
|
num_errors += TestGetPacket();
|
|
|
|
num_errors += TestGetNext();
|
|
|
|
num_errors += TestCompress();
|
|
|
|
num_errors += TestErrors();
|
|
|
|
num_errors += SystemTest();
|
|
|
|
/* Test data corruption in packed structs */
|
|
num_errors += TestHDFFV_9758();
|
|
|
|
/* Terminate access to the file. */
|
|
err = H5Fclose(fileID);
|
|
if (err < 0) {
|
|
fprintf(stderr, "Failed to close file.\n");
|
|
num_errors++;
|
|
}
|
|
|
|
/* Delete the file */
|
|
remove(TEST_FILE);
|
|
}
|
|
|
|
if (num_errors == 0)
|
|
/* ALL TESTS PASSED */
|
|
return 0;
|
|
else
|
|
/* ERRORS */
|
|
return -1;
|
|
}
|
|
|
|
const char *BASICTEST_PT("/basicTest");
|
|
int
|
|
BasicTest()
|
|
{
|
|
herr_t err;
|
|
int myRecord;
|
|
hsize_t count;
|
|
int error;
|
|
|
|
printf("Testing %-62s", "basic functionality");
|
|
HDfflush(stdout);
|
|
|
|
FL_PacketTable wrapper(fileID, H5P_DEFAULT, BASICTEST_PT, H5T_NATIVE_INT, 1);
|
|
if (!wrapper.IsValid())
|
|
goto error;
|
|
|
|
/* Ensure initial count is zero */
|
|
count = wrapper.GetPacketCount(error);
|
|
if (count != 0 || error != 0)
|
|
goto error;
|
|
|
|
myRecord = 1;
|
|
|
|
/* add some records test */
|
|
err = wrapper.AppendPacket(&myRecord);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
myRecord = 2;
|
|
|
|
wrapper.AppendPacket(&myRecord);
|
|
|
|
/* get number of records test */
|
|
count = wrapper.GetPacketCount();
|
|
if (count != 2)
|
|
goto error;
|
|
|
|
/* get records test */
|
|
err = wrapper.GetPacket(0, &myRecord);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
if (myRecord != 1)
|
|
goto error;
|
|
|
|
err = wrapper.GetPacket(1, &myRecord);
|
|
if (err < 0)
|
|
goto error;
|
|
if (myRecord != 2)
|
|
goto error;
|
|
|
|
PASSED();
|
|
return 0;
|
|
|
|
error:
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|
|
|
|
const char *CMPDTEST_PT("/compoundTest");
|
|
int
|
|
TestCompoundDatatype()
|
|
{
|
|
hid_t dtypeID;
|
|
hsize_t count;
|
|
int error;
|
|
|
|
printf("Testing %-62s", "compound datatypes");
|
|
HDfflush(stdout);
|
|
|
|
/* Create compound datatype */
|
|
typedef struct {
|
|
short a, b, c;
|
|
int e;
|
|
} compoundType;
|
|
|
|
dtypeID = H5Tcreate(H5T_COMPOUND, sizeof(compoundType));
|
|
|
|
H5Tinsert(dtypeID, "abbey", HOFFSET(compoundType, a), H5T_NATIVE_SHORT);
|
|
H5Tinsert(dtypeID, "bert", HOFFSET(compoundType, b), H5T_NATIVE_SHORT);
|
|
H5Tinsert(dtypeID, "charlie", HOFFSET(compoundType, c), H5T_NATIVE_SHORT);
|
|
H5Tinsert(dtypeID, "ebert", HOFFSET(compoundType, e), H5T_NATIVE_INT);
|
|
|
|
/* Create packet table using default property list. */
|
|
FL_PacketTable wrapper(fileID, H5P_DEFAULT, CMPDTEST_PT, dtypeID, 1);
|
|
|
|
if (!wrapper.IsValid())
|
|
goto error;
|
|
|
|
compoundType first;
|
|
first.a = 1;
|
|
first.b = first.c = 3;
|
|
first.e = 5;
|
|
|
|
/* Write packet */
|
|
wrapper.AppendPacket(&first);
|
|
|
|
count = wrapper.GetPacketCount(error);
|
|
if (count != 1)
|
|
goto error;
|
|
|
|
first.a = first.b = first.c = 0;
|
|
first.e = 0;
|
|
|
|
/* Read packet back */
|
|
wrapper.GetPacket(0, &first);
|
|
|
|
if (first.a != 1)
|
|
goto error;
|
|
if (first.e != 5)
|
|
goto error;
|
|
|
|
PASSED();
|
|
|
|
H5Tclose(dtypeID);
|
|
return 0;
|
|
|
|
error:
|
|
|
|
H5E_BEGIN_TRY
|
|
{
|
|
H5Tclose(dtypeID);
|
|
}
|
|
H5E_END_TRY;
|
|
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|
|
|
|
const char *GETNEXT_PT("/TestGetNext");
|
|
int
|
|
TestGetNext()
|
|
{
|
|
int error;
|
|
int record;
|
|
int records[2];
|
|
int i;
|
|
|
|
printf("Testing %-62s", "GetNextPacket");
|
|
HDfflush(stdout);
|
|
|
|
/* Create a dataset */
|
|
FL_PacketTable wrapper(fileID, H5P_DEFAULT, GETNEXT_PT, H5T_NATIVE_INT, 500);
|
|
|
|
if (!wrapper.IsValid())
|
|
goto error;
|
|
|
|
/* Append 5 records to the dataset */
|
|
for (record = 1; record < 6; record++)
|
|
wrapper.AppendPacket(&record);
|
|
|
|
/* Ensure that we can interate through the records and get the right ones */
|
|
for (i = 1; i < 6; i++) {
|
|
wrapper.GetNextPacket(&record);
|
|
if (record != i)
|
|
goto error;
|
|
}
|
|
|
|
/* Reset the index and check that it worked */
|
|
wrapper.ResetIndex();
|
|
if (wrapper.GetIndex(error) != 0)
|
|
goto error;
|
|
if (error < 0)
|
|
goto error;
|
|
|
|
/* Ensure that we can interate through the records and get the right ones */
|
|
for (i = 1; i < 6; i++) {
|
|
error = wrapper.GetNextPacket(&record);
|
|
if (record != i || error < 0)
|
|
goto error;
|
|
}
|
|
|
|
wrapper.SetIndex(1);
|
|
if (wrapper.GetIndex(error) != 1)
|
|
goto error;
|
|
if (error < 0)
|
|
goto error;
|
|
|
|
/* Ensure we can get multiple records with our index pointer */
|
|
wrapper.GetNextPackets(2, records);
|
|
if (records[0] != 2 || records[1] != 3)
|
|
goto error;
|
|
|
|
/* Ensure our pointer was updated correctly */
|
|
wrapper.GetNextPacket(&record);
|
|
if (record != 4)
|
|
goto error;
|
|
|
|
PASSED();
|
|
return 0;
|
|
|
|
error:
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|
|
|
|
const char *COMPRESS_PT("/compressTest");
|
|
int
|
|
TestCompress()
|
|
{
|
|
#ifdef H5_HAVE_FILTER_DEFLATE
|
|
unsigned int flags = 0;
|
|
unsigned int config = 0;
|
|
size_t cd_nelemts = 0;
|
|
|
|
printf("Testing %-62s", "compression");
|
|
HDfflush(stdout);
|
|
try {
|
|
/* Prepare property list to set compression, randomly use deflate */
|
|
DSetCreatPropList dscreatplist;
|
|
dscreatplist.setDeflate(6);
|
|
|
|
/* Create packet table with compression. */
|
|
FL_PacketTable wrapper(fileID, COMPRESS_PT, H5T_NATIVE_CHAR, 100, dscreatplist.getId());
|
|
|
|
/* Close the property list */
|
|
dscreatplist.close();
|
|
|
|
/* Verify that the deflate filter is set */
|
|
|
|
/* Create an HDF5 C++ file object */
|
|
H5File file;
|
|
file.setId(fileID);
|
|
|
|
/* Make sure that the deflate filter is set by opening the packet table
|
|
* as a dataset and getting its creation property list */
|
|
DataSet dset = file.openDataSet(COMPRESS_PT);
|
|
|
|
DSetCreatPropList dcpl = dset.getCreatePlist();
|
|
|
|
char filter_name[8];
|
|
dcpl.getFilterById(H5Z_FILTER_DEFLATE, flags, cd_nelemts, NULL, 8, filter_name, config);
|
|
if (HDstrncmp(filter_name, "deflate", 7) != 0)
|
|
H5_FAILED()
|
|
}
|
|
catch (Exception const &) {
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|
|
PASSED();
|
|
#else
|
|
SKIPPED();
|
|
HDputs(" deflate filter not enabled");
|
|
#endif /* H5_HAVE_FILTER_DEFLATE */
|
|
return 0;
|
|
}
|
|
|
|
const char *PT_TESTGETPT = "/TestGetPacket";
|
|
int
|
|
TestGetPacket()
|
|
{
|
|
int record;
|
|
int theRecs[3];
|
|
int i;
|
|
printf("Testing %-62s", "GetPacket");
|
|
HDfflush(stdout);
|
|
|
|
/* Create a dataset. Does not need to specify property list because
|
|
there is no compression. */
|
|
FL_PacketTable wrapper(fileID, PT_TESTGETPT, H5T_NATIVE_INT, 1);
|
|
|
|
if (!wrapper.IsValid())
|
|
goto error;
|
|
|
|
/* Append 5 records to the dataset */
|
|
for (record = 1; record < 6; record++)
|
|
wrapper.AppendPacket(&record);
|
|
|
|
/* Ensure that the records were written properly */
|
|
wrapper.GetPacket(1, &record);
|
|
if (record != 2)
|
|
goto error;
|
|
|
|
/* Ensure that we can retrieve multiple records */
|
|
wrapper.GetPackets(1, 3, theRecs);
|
|
for (i = 0; i < 3; i++) {
|
|
if (theRecs[i] != i + 2)
|
|
goto error;
|
|
}
|
|
|
|
PASSED();
|
|
return 0;
|
|
|
|
error:
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|
|
|
|
const char *PT_TESTERROR = "/TestErrors";
|
|
|
|
int
|
|
TestErrors()
|
|
{
|
|
printf("Testing %-62s", "error conditions");
|
|
HDfflush(stdout);
|
|
|
|
/* Create a dataset */
|
|
FL_PacketTable wrapper(fileID, PT_TESTERROR, H5T_NATIVE_INT, 1);
|
|
|
|
if (!wrapper.IsValid())
|
|
goto error;
|
|
|
|
int record;
|
|
int records[3];
|
|
int error;
|
|
|
|
/* Append 4 records to the dataset */
|
|
for (record = 1; record < 5; record++)
|
|
wrapper.AppendPacket(&record);
|
|
|
|
/* Try to confuse functions with bad indexes */
|
|
error = wrapper.GetPacket(static_cast<unsigned>(-1), &record);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPacket(4, &record);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPacket(static_cast<unsigned>(-250), &record);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPacket(3000, &record);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPacket(1, &record);
|
|
if (error < 0)
|
|
goto error;
|
|
|
|
error = wrapper.GetPackets(static_cast<unsigned>(-1), 1, records);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPackets(2, 4, records);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPackets(static_cast<unsigned>(-60), static_cast<unsigned>(-62), records);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPackets(10, 12, records);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPackets(0, 2, records);
|
|
if (error < 0)
|
|
goto error;
|
|
error = wrapper.GetPackets(2, 0, records);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetPackets(1, 1, records);
|
|
if (error < 0)
|
|
goto error;
|
|
error = wrapper.GetPackets(1, 3, records);
|
|
if (error < 0)
|
|
goto error;
|
|
|
|
wrapper.ResetIndex();
|
|
error = wrapper.SetIndex(static_cast<unsigned>(-1));
|
|
if (error >= 0)
|
|
goto error;
|
|
if (wrapper.GetIndex(error) != 0)
|
|
goto error;
|
|
if (error < 0)
|
|
goto error;
|
|
error = wrapper.GetNextPacket(&record);
|
|
if (error < 0)
|
|
goto error;
|
|
if (record != 1)
|
|
goto error;
|
|
if (wrapper.GetIndex(error) != 1)
|
|
goto error;
|
|
if (error < 0)
|
|
goto error;
|
|
error = wrapper.SetIndex(20);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetNextPacket(&record);
|
|
if (error < 0)
|
|
goto error;
|
|
if (record != 2)
|
|
goto error;
|
|
wrapper.SetIndex(3);
|
|
error = wrapper.GetNextPacket(&record);
|
|
if (error < 0)
|
|
goto error;
|
|
if (record != 4)
|
|
goto error;
|
|
if (wrapper.GetIndex(error) != 4)
|
|
goto error;
|
|
if (error < 0)
|
|
goto error;
|
|
error = wrapper.GetNextPacket(&record);
|
|
if (error >= 0)
|
|
goto error;
|
|
|
|
wrapper.ResetIndex();
|
|
error = wrapper.GetNextPackets(10, records);
|
|
if (error >= 0)
|
|
goto error;
|
|
error = wrapper.GetNextPackets(0, records);
|
|
if (error < 0)
|
|
goto error;
|
|
|
|
PASSED();
|
|
return 0;
|
|
|
|
error:
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|
|
|
|
const char *PT_SYSTEMTST1 = "/SystemTest1";
|
|
const char *PT_SYSTEMTST2 = "/SystemTest2";
|
|
int
|
|
SystemTest()
|
|
{
|
|
printf("Testing %-62s", "multiple datatypes");
|
|
HDfflush(stdout);
|
|
|
|
hid_t dtypeID1, dtypeID2;
|
|
hsize_t count;
|
|
int error;
|
|
|
|
/* Creating two inter-related datatypes. Create two datasets and put
|
|
* one datatype in each. */
|
|
typedef struct {
|
|
short a, b, c;
|
|
int e;
|
|
} compoundType;
|
|
|
|
dtypeID1 = H5Tcreate(H5T_COMPOUND, sizeof(compoundType));
|
|
|
|
H5Tinsert(dtypeID1, "abbey", HOFFSET(compoundType, a), H5T_NATIVE_SHORT);
|
|
H5Tinsert(dtypeID1, "bert", HOFFSET(compoundType, b), H5T_NATIVE_SHORT);
|
|
H5Tinsert(dtypeID1, "charlie", HOFFSET(compoundType, c), H5T_NATIVE_SHORT);
|
|
H5Tinsert(dtypeID1, "ebert", HOFFSET(compoundType, e), H5T_NATIVE_INT);
|
|
|
|
typedef struct {
|
|
char f;
|
|
compoundType g;
|
|
} cType2;
|
|
|
|
dtypeID2 = H5Tcreate(H5T_COMPOUND, sizeof(cType2));
|
|
|
|
H5Tinsert(dtypeID2, "f", HOFFSET(cType2, f), H5T_NATIVE_CHAR);
|
|
H5Tinsert(dtypeID2, "g", HOFFSET(cType2, g), dtypeID1);
|
|
|
|
cType2 ct2[10];
|
|
ct2[0].f = 'h';
|
|
ct2[0].g.a = 9;
|
|
ct2[0].g.b = -13;
|
|
ct2[0].g.c = 0;
|
|
ct2[0].g.e = 3000;
|
|
|
|
/* Create the packet table datasets. One used a deprecated constructor */
|
|
FL_PacketTable wrapper1(fileID, PT_SYSTEMTST1, dtypeID1, 1);
|
|
FL_PacketTable wrapper2(fileID, H5P_DEFAULT, PT_SYSTEMTST2, dtypeID2, 1);
|
|
|
|
if (!wrapper1.IsValid())
|
|
goto error;
|
|
if (!wrapper2.IsValid())
|
|
goto error;
|
|
|
|
/* Write and read packets, ensure that nothing is unusual */
|
|
wrapper2.AppendPacket(ct2);
|
|
|
|
count = wrapper1.GetPacketCount();
|
|
if (count != 0)
|
|
goto error;
|
|
|
|
compoundType ct1[10];
|
|
ct1[0].a = 31;
|
|
ct1[0].b = 4607;
|
|
ct1[0].c = -1002;
|
|
ct1[0].e = 3;
|
|
|
|
ct2[1].f = 'b';
|
|
ct2[1].g = ct1[0];
|
|
|
|
wrapper1.AppendPacket(ct1);
|
|
wrapper2.AppendPacket(&ct2[1]);
|
|
|
|
wrapper1.ResetIndex();
|
|
wrapper1.GetNextPacket(&ct1[1]);
|
|
wrapper2.GetPacket(1, &ct2[2]);
|
|
if (wrapper1.GetIndex(error) != 1)
|
|
goto error;
|
|
if (error < 0)
|
|
goto error;
|
|
if (wrapper2.GetIndex(error) != 0)
|
|
goto error;
|
|
if (error < 0)
|
|
goto error;
|
|
|
|
if (ct1[1].b != ct2[2].g.b)
|
|
goto error;
|
|
|
|
H5Tclose(dtypeID1);
|
|
H5Tclose(dtypeID2);
|
|
|
|
PASSED();
|
|
return 0;
|
|
|
|
error:
|
|
H5E_BEGIN_TRY
|
|
{
|
|
H5Tclose(dtypeID1);
|
|
H5Tclose(dtypeID2);
|
|
}
|
|
H5E_END_TRY;
|
|
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* TestHDFFV_9758(): Test that a packet table with compound datatype which
|
|
* contains string type can be created and written correctly. (HDFFV-9758)
|
|
*
|
|
* Notes:
|
|
* Previously, data of the field that follows the string was read back
|
|
* as garbage when #pragma pack(1) is used.
|
|
* 2016/10/20 -BMR
|
|
* Updated:
|
|
* #pragma pack(1) caused failure on Emu because Sparc cannot
|
|
* access misaligned data. Changed it to pack() to do the
|
|
* default alignment.
|
|
* 2016/10/25 -BMR
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#pragma pack() // default alignment
|
|
const char * ABHI_PT("/abhiTest");
|
|
const hsize_t NUM_PACKETS = 5;
|
|
const int STRING_LENGTH = 19; // including terminating NULL
|
|
int
|
|
TestHDFFV_9758()
|
|
{
|
|
hid_t strtype = H5I_INVALID_HID;
|
|
hid_t compound_type = H5I_INVALID_HID;
|
|
herr_t err;
|
|
struct s1_t {
|
|
int a;
|
|
float b;
|
|
double c;
|
|
char d[STRING_LENGTH]; // null terminated string
|
|
int e;
|
|
};
|
|
|
|
s1_t s1[NUM_PACKETS];
|
|
|
|
for (hsize_t i = 0; i < NUM_PACKETS; i++) {
|
|
s1[i].a = static_cast<int>(i);
|
|
s1[i].b = 1.0f * static_cast<float>(i * i);
|
|
s1[i].c = 1.0 / static_cast<double>(i + 1);
|
|
HDsprintf(s1[i].d, "string%" PRIuHSIZE "", i);
|
|
s1[i].e = static_cast<int>(100 + i);
|
|
}
|
|
|
|
printf("Testing %-62s", "data corruption in packed structs (HDFFV-9758)");
|
|
HDfflush(stdout);
|
|
|
|
// Build a compound datatype
|
|
compound_type = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
|
|
if (compound_type < 0)
|
|
goto error;
|
|
|
|
err = H5Tinsert(compound_type, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT);
|
|
if (err < 0)
|
|
goto error;
|
|
err = H5Tinsert(compound_type, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
|
|
if (err < 0)
|
|
goto error;
|
|
err = H5Tinsert(compound_type, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
strtype = H5Tcopy(H5T_C_S1);
|
|
if (compound_type < 0)
|
|
goto error;
|
|
err = H5Tset_size(strtype, STRING_LENGTH); /* create string */
|
|
if (err < 0)
|
|
goto error;
|
|
err = H5Tinsert(compound_type, "d_name", HOFFSET(s1_t, d), strtype);
|
|
if (err < 0)
|
|
goto error;
|
|
err = H5Tinsert(compound_type, "e_name", HOFFSET(s1_t, e), H5T_NATIVE_INT);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
{ // so ptable will go out of scope before PASSED
|
|
|
|
// Create a packet table
|
|
FL_PacketTable ptable(fileID, "/examplePacketTable", compound_type, 1);
|
|
if (!ptable.IsValid())
|
|
goto error;
|
|
|
|
// Add packets to the table
|
|
for (size_t i = 0; i < NUM_PACKETS; i++) {
|
|
/* Appends one packet at the current position */
|
|
err = ptable.AppendPacket(s1 + i);
|
|
if (err < 0)
|
|
goto error;
|
|
}
|
|
|
|
// Check packet count
|
|
const hsize_t count = ptable.GetPacketCount(err);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
if (count != NUM_PACKETS) {
|
|
std::cerr << "Number of packets in packet table should be " << NUM_PACKETS << " but is " << count
|
|
<< endl;
|
|
}
|
|
|
|
// Read and verify the data
|
|
ptable.ResetIndex();
|
|
for (size_t i = 0; i < NUM_PACKETS; i++) {
|
|
s1_t s2;
|
|
HDmemset(&s2, 0, sizeof(s1_t));
|
|
err = ptable.GetNextPacket(&s2);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
if (s2.a != s1[i].a || s2.e != s1[i].e)
|
|
goto error;
|
|
else if (HDstrcmp(s2.d, s1[i].d) != 0)
|
|
goto error;
|
|
}
|
|
} // end of ptable block
|
|
|
|
PASSED();
|
|
return 0;
|
|
|
|
error:
|
|
|
|
H5E_BEGIN_TRY
|
|
{
|
|
H5Tclose(strtype);
|
|
H5Tclose(compound_type);
|
|
H5Fclose(fileID);
|
|
}
|
|
H5E_END_TRY;
|
|
|
|
H5_FAILED();
|
|
return 1;
|
|
}
|