Skip to content

Commit d975023

Browse files
committed
Add Bool SimpleTest
1 parent 72f83b2 commit d975023

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed

doc/INSTALL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ To use the CMakeLists.txt file which comes with the source code, you must have
1717
The splashtools and some tests also require an **MPI 2.2** compatible MPI library,
1818
e.g. **OpenMPI 1.5.1** or higher.
1919

20-
Tests require the development version of the **CppUnit** library.
20+
Our *tests* require the development version of the **CppUnit** library and
21+
python support for `h5py` & `numpy`.
2122

2223

2324
Compiling

src/include/splash/basetypes/ColTypeBool.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class ColTypeBool : public CollectionType
3636
ColTypeBool()
3737
{
3838
this->type = H5Tenum_create(H5T_NATIVE_INT8);
39+
const char *names[2] = {"true", "false"};
40+
int64_t val[2] = {1, 0};
41+
H5Tenum_insert(this->type, names[0], &val[0]);
42+
H5Tenum_insert(this->type, names[1], &val[1]);
3943
}
4044

4145
~ColTypeBool()

tests/SimpleDataTest.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ using namespace splash;
4040

4141
SimpleDataTest::SimpleDataTest() :
4242
ctUInt32(),
43-
ctUInt64()
43+
ctUInt64(),
44+
ctBool()
4445
{
4546
dataCollector = new SerialDataCollector(10);
4647
srand(time(NULL));
@@ -74,9 +75,13 @@ bool SimpleDataTest::subtestWriteRead(Dimensions gridSize, Dimensions borderSize
7475
// initial part of the test: data is written to the file, once with and once
7576
// without borders
7677
uint64_t *dataWrite = new uint64_t[bufferSize];
78+
bool *boolWrite = new bool[bufferSize];
7779

7880
for (uint64_t i = 0; i < bufferSize; i++)
81+
{
7982
dataWrite[i] = i;
83+
boolWrite[i] = ( i%2 == 0 );
84+
}
8085

8186
dataCollector->write(10, ctUInt64, dimensions, Selection(gridSize), "deep/folders/data", dataWrite);
8287
datasetNames.insert("deep/folders/data");
@@ -85,6 +90,13 @@ bool SimpleDataTest::subtestWriteRead(Dimensions gridSize, Dimensions borderSize
8590
borderSize), "deep/folders/data_without_borders", dataWrite);
8691
datasetNames.insert("deep/folders/data_without_borders");
8792

93+
dataCollector->write(10, ctBool, dimensions, Selection(gridSize), "deep/folders/data_bool", boolWrite);
94+
datasetNames.insert("deep/folders/data_bool");
95+
96+
dataCollector->write(20, ctBool, dimensions, Selection(gridSize, smallGridSize,
97+
borderSize), "deep/folders/data_bool_without_borders", boolWrite);
98+
datasetNames.insert("deep/folders/data_bool_without_borders");
99+
88100
dataCollector->close();
89101

90102
// first part of the test: read data with borders to a cleared
@@ -103,14 +115,17 @@ bool SimpleDataTest::subtestWriteRead(Dimensions gridSize, Dimensions borderSize
103115
int32_t *ids = NULL;
104116
size_t numIDs = 0;
105117
dataCollector->getEntryIDs(NULL, &numIDs);
118+
#if defined TESTS_DEBUG
119+
printf("number of entry IDs=%d\n", numIDs);
120+
#endif
106121
CPPUNIT_ASSERT(numIDs == 2);
107122
ids = new int32_t[numIDs];
108123
dataCollector->getEntryIDs(ids, NULL);
109124

110125
for (uint32_t j = 0; j < numIDs; ++j)
111126
{
112127
dataCollector->getEntriesForID(ids[j], NULL, &numEntries);
113-
CPPUNIT_ASSERT(numEntries == 1);
128+
CPPUNIT_ASSERT(numEntries == 2);
114129
entries = new DataCollector::DCEntry[numEntries];
115130
dataCollector->getEntriesForID(ids[j], entries, NULL);
116131

@@ -129,16 +144,23 @@ bool SimpleDataTest::subtestWriteRead(Dimensions gridSize, Dimensions borderSize
129144
delete[] ids;
130145

131146
uint64_t *dataRead = new uint64_t[bufferSize];
147+
bool *boolRead = new bool[bufferSize];
132148
for (uint64_t i = 0; i < bufferSize; i++)
149+
{
133150
dataRead[i] = UINT64_MAX;
151+
boolRead[i] = false;
152+
}
134153

135154
Dimensions resultSize;
136155
dataCollector->read(10, "deep/folders/data", resultSize, dataRead);
137156

138157
for (uint32_t i = 0; i < 3; i++)
139158
CPPUNIT_ASSERT(resultSize[i] == gridSize[i]);
140159

160+
dataCollector->read(10, "deep/folders/data_bool", resultSize, boolRead);
161+
141162
for (uint64_t i = 0; i < bufferSize; i++)
163+
{
142164
if (dataRead[i] != dataWrite[i])
143165
{
144166
#if defined TESTS_DEBUG
@@ -147,6 +169,15 @@ bool SimpleDataTest::subtestWriteRead(Dimensions gridSize, Dimensions borderSize
147169
resultsCorrect = false;
148170
break;
149171
}
172+
if (boolRead[i] != boolWrite[i])
173+
{
174+
#if defined TESTS_DEBUG
175+
std::cout << i << ": " << boolRead[i] << " != exptected " << boolWrite[i] << std::endl;
176+
#endif
177+
resultsCorrect = false;
178+
break;
179+
}
180+
}
150181

151182
delete[] dataRead;
152183

@@ -157,8 +188,12 @@ bool SimpleDataTest::subtestWriteRead(Dimensions gridSize, Dimensions borderSize
157188
// locations in a cleared array (-1)
158189

159190
dataRead = new uint64_t[bufferSize];
191+
boolRead = new bool[bufferSize];
160192
for (uint64_t i = 0; i < bufferSize; i++)
193+
{
161194
dataRead[i] = UINT64_MAX;
195+
boolRead[i] = false;
196+
}
162197

163198
dataCollector->read(20, "deep/folders/data_without_borders", gridSize, borderSize,
164199
resultSize, NULL);
@@ -228,7 +263,9 @@ bool SimpleDataTest::subtestWriteRead(Dimensions gridSize, Dimensions borderSize
228263
}
229264

230265
delete[] dataRead;
266+
delete[] boolRead;
231267
delete[] dataWrite;
268+
delete[] boolWrite;
232269

233270
dataCollector->close();
234271

tests/include/SimpleDataTest.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class SimpleDataTest : public CPPUNIT_NS::TestFixture
3434
{
3535
CPPUNIT_TEST_SUITE(SimpleDataTest);
3636

37-
CPPUNIT_TEST(testWriteRead);
3837
CPPUNIT_TEST(testNullWrite);
38+
CPPUNIT_TEST(testWriteRead);
3939

4040
CPPUNIT_TEST_SUITE_END();
4141

@@ -63,6 +63,7 @@ class SimpleDataTest : public CPPUNIT_NS::TestFixture
6363

6464
ColTypeUInt32 ctUInt32;
6565
ColTypeUInt64 ctUInt64;
66+
ColTypeBool ctBool;
6667
DataCollector *dataCollector;
6768
};
6869

tests/readBool.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2015 Axel Huebl
4+
#
5+
# This file is part of libSplash.
6+
#
7+
# libSplash is free software: you can redistribute it and/or modify
8+
# it under the terms of of either the GNU General Public License or
9+
# the GNU Lesser General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# libSplash is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License and the GNU Lesser General Public License
17+
# for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# and the GNU Lesser General Public License along with libSplash.
21+
# If not, see <http://www.gnu.org/licenses/>.
22+
#
23+
24+
import h5py
25+
import numpy as np
26+
27+
f = h5py.File("h5/testWriteRead_0_0_0.h5", "r")
28+
data = f["data/10/deep/folders/data_bool"]
29+
30+
len = data.size
31+
data1d = data[:,:,:].reshape(len)
32+
33+
for i in np.arange(len):
34+
val = ( i%2 == 0 );
35+
if data1d[i] != val:
36+
exit(1)
37+
38+
exit(0)

tests/run_tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function testMPI()
2626
}
2727

2828
testSerial ./SimpleDataTest.cpp.out "Testing simple data read/write..."
29+
testSerial ../readBool.py "Testing h5py compatible read..."
2930

3031
testSerial ./AttributesTest.cpp.out "Testing reading/writing attributes..."
3132

0 commit comments

Comments
 (0)