From b3b7ae087edbc20891a088db2f4e4f83e186c8b0 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Sun, 23 Oct 2016 21:03:47 -0500 Subject: Purpose: Fix Packet Table issues cont. Description: Misc cleanups and comments in tests. Platforms tested: Linux/32 2.6 (jam) Darwin (osx1010test) Linux/64 (jelly) --- hl/c++/test/ptableTest.cpp | 38 +++++++++++++++++++++----------------- hl/test/test_packet_vlen.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/hl/c++/test/ptableTest.cpp b/hl/c++/test/ptableTest.cpp index 953ec91..68b040e 100644 --- a/hl/c++/test/ptableTest.cpp +++ b/hl/c++/test/ptableTest.cpp @@ -38,20 +38,21 @@ int main(void) } else { - num_errors += BasicTest(); + num_errors += BasicTest(); - num_errors += TestCompoundDatatype(); + num_errors += TestCompoundDatatype(); - num_errors += TestGetPacket(); + num_errors += TestGetPacket(); - num_errors += TestGetNext(); + num_errors += TestGetNext(); - num_errors += TestCompress(); + num_errors += TestCompress(); - num_errors += TestErrors(); + num_errors += TestErrors(); - num_errors += SystemTest(); + num_errors += SystemTest(); + /* Test data corruption in packed structs */ num_errors += TestHDFFV_9758(); /* Terminate access to the file. */ @@ -562,7 +563,7 @@ error: /*------------------------------------------------------------------------- * TestHDFFV_9758(): Test that a packet table with compound datatype which - * contain string type can be created and written correctly. (HDFFV-9758) + * contains string type can be created and written correctly. (HDFFV-9758) * * Notes: * Previously, data of the field that follows the string was read back @@ -599,12 +600,9 @@ int TestHDFFV_9758() s1[i].e = 100+i; } - TESTING("the fix of issue HDFFV-9758") - - FL_PacketTable wrapper(fileID, H5P_DEFAULT, ABHI_PT, H5T_NATIVE_INT, 1); - if(! wrapper.IsValid()) - goto error; + TESTING("data corruption in packed structs (HDFFV-9758)") + // Build a compound datatype compound_type = H5Tcreate(H5T_COMPOUND, sizeof(s1_t)); if (compound_type < 0) goto error; @@ -619,7 +617,7 @@ int TestHDFFV_9758() if (err < 0) goto error; - strtype = H5Tcopy (H5T_C_S1); + strtype = H5Tcopy (H5T_C_S1); if (compound_type < 0) goto error; err = H5Tset_size (strtype, STRING_LENGTH); /* create string */ @@ -632,11 +630,14 @@ int TestHDFFV_9758() if (err < 0) goto error; -{ // so ptable will go out of scope + { // so ptable will go out of scope before PASSED + + // Create a packet table FL_PacketTable ptable(fileID, "/examplePacketTable", compound_type, 1); if (not 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 */ @@ -644,6 +645,7 @@ int TestHDFFV_9758() if (err < 0) goto error; } + // Check packet count const hsize_t count = ptable.GetPacketCount(err); if (err < 0) goto error; @@ -655,8 +657,8 @@ int TestHDFFV_9758() << " but is " << count << endl; } + // Read and verify the data ptable.ResetIndex(); - for (size_t i = 0; i < NUM_PACKETS; i++) { s1_t s2; @@ -670,7 +672,7 @@ int TestHDFFV_9758() else if (HDstrcmp(s2.d, s1[i].d)) goto error; } -} + } // end of ptable block PASSED(); return 0; @@ -678,6 +680,8 @@ int TestHDFFV_9758() error: H5E_BEGIN_TRY { + H5Tclose(strtype); + H5Tclose(compound_type); H5Fclose(fileID); } H5E_END_TRY; diff --git a/hl/test/test_packet_vlen.c b/hl/test/test_packet_vlen.c index a1e90a1..b152a2c 100644 --- a/hl/test/test_packet_vlen.c +++ b/hl/test/test_packet_vlen.c @@ -148,6 +148,7 @@ static int test_VLof_atomic(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (vltype > 0) H5Tclose(vltype); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); @@ -287,6 +288,8 @@ static int test_VLof_comptype(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (cmptype > 0) H5Tclose(cmptype); + if (vltype > 0) H5Tclose(vltype); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); @@ -465,6 +468,9 @@ static int test_compound_VL_VLtype(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (vlatomic > 0) H5Tclose(vlatomic); + if (vlofvl > 0) H5Tclose(vlofvl); + if (comp_vlvl > 0) H5Tclose(comp_vlvl); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); @@ -584,6 +590,8 @@ static int test_VLof_VLtype(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (vlatomic > 0) H5Tclose(vlatomic); + if (vlofvl > 0) H5Tclose(vlofvl); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); @@ -776,6 +784,8 @@ static int adding_attribute(hid_t fid, const char *table_name, const char *attr_ return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (attr_id > 0) H5Aclose(attr_id); + if (space_id > 0) H5Sclose(space_id); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); return ret; } /* adding_attribute */ @@ -898,7 +908,7 @@ static int test_attributes(void) return(ret); error: /* An error has occurred. Clean up and exit. */ - H5Fclose(fid); + if (fid > 0) H5Fclose(fid); H5_FAILED(); return FAIL; } /* test_attributes */ @@ -920,9 +930,8 @@ error: /* An error has occurred. Clean up and exit. */ * 2016/01/27 -BMR *------------------------------------------------------------------------- */ -static herr_t verify_accessors(const char *table_name, herr_t expected_value) +static herr_t verify_accessors(hid_t fid, const char *table_name, herr_t expected_value) { - hid_t fid=H5I_INVALID_HID; /* File identifier */ hid_t ptable=H5I_INVALID_HID; /* Packet table identifier */ hid_t dset_id=H5I_INVALID_HID; /* Dataset associated with the pt */ hid_t dtype_id=H5I_INVALID_HID; /* Dataset identifier */ @@ -931,11 +940,6 @@ static herr_t verify_accessors(const char *table_name, herr_t expected_value) herr_t is_varlen = 0; herr_t ret = FAIL; /* Returned status from a callee */ - /* Open the file. */ - fid = H5Fopen(TEST_FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT); - if (fid < 0) - goto error; - /* Open the named packet table. */ ptable = H5PTopen(fid, table_name); if (ptable < 0) @@ -984,7 +988,8 @@ static herr_t verify_accessors(const char *table_name, herr_t expected_value) error: /* An error has occurred. Clean up and exit. */ if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); - return ret; + H5_FAILED(); + return FAIL; } /* verify_accessors */ /*------------------------------------------------------------------------- @@ -1000,7 +1005,6 @@ error: /* An error has occurred. Clean up and exit. */ static int test_accessors(void) { hid_t fid=H5I_INVALID_HID; /* File identifier */ - hid_t ptable=H5I_INVALID_HID; /* File identifier */ herr_t ret = FAIL; /* Returned status from a callee */ TESTING("accessor functions"); @@ -1010,11 +1014,11 @@ static int test_accessors(void) if (fid < 0) goto error; - ret = verify_accessors(PT_VLEN_ATOMIC, TRUE); + ret = verify_accessors(fid, PT_VLEN_ATOMIC, TRUE); if (ret < 0) goto error; - ret = verify_accessors(PT_FIXED_LEN, FALSE); + ret = verify_accessors(fid, PT_FIXED_LEN, FALSE); if (ret < 0) goto error; @@ -1026,7 +1030,6 @@ static int test_accessors(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ - if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5_FAILED(); return FAIL; @@ -1141,6 +1144,7 @@ static int testfl_VLof_atomic(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (vltype > 0) H5Tclose(vltype); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); @@ -1280,6 +1284,8 @@ static int testfl_VLof_comptype(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (cmptype > 0) H5Tclose(cmptype); + if (vltype > 0) H5Tclose(vltype); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); @@ -1458,6 +1464,9 @@ static int testfl_compound_VL_VLtype(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (vlatomic > 0) H5Tclose(vlatomic); + if (vlofvl > 0) H5Tclose(vlofvl); + if (comp_vlvl > 0) H5Tclose(comp_vlvl); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); @@ -1577,6 +1586,8 @@ static int testfl_VLof_VLtype(void) return SUCCEED; error: /* An error has occurred. Clean up and exit. */ + if (vlatomic > 0) H5Tclose(vlatomic); + if (vlofvl > 0) H5Tclose(vlofvl); if (H5PTis_valid(ptable) > 0) H5PTclose(ptable); if (fid > 0) H5Fclose(fid); H5PTfree_vlen_buff(ptable, NRECORDS, readBuf); -- cgit v0.12