[cig-commits] r4864 - in long/3D/Gale/trunk/src/StGermain: .
Base/Container/tests
walter at geodynamics.org
walter at geodynamics.org
Wed Oct 11 13:47:45 PDT 2006
Author: walter
Date: 2006-10-11 13:47:45 -0700 (Wed, 11 Oct 2006)
New Revision: 4864
Modified:
long/3D/Gale/trunk/src/StGermain/
long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c
Log:
r2921 at earth: boo | 2006-10-11 13:42:43 -0700
r2837 at earth (orig r3825): LukeHodkinson | 2006-10-04 18:05:42 -0700
Updating the range set test to use the test
suite class.
Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
- 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2920
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3824
+ 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2921
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3825
Modified: long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c 2006-10-11 20:47:42 UTC (rev 4863)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c 2006-10-11 20:47:45 UTC (rev 4864)
@@ -24,7 +24,7 @@
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
-** $Id: testRangeSet.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+** $Id: testCommTopology.c 2136 2004-09-30 02:47:13Z PatrickSunter $
**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@@ -39,91 +39,6 @@
#include "Base/Container/Container.h"
-Bool testConstruct( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testIndices( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testRanges( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testUnion( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testIntersection( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testSubtraction( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testPickle( unsigned rank, unsigned nProcs, unsigned watch );
-
-
-void runTest( const char* desc, Bool (test)( unsigned, unsigned, unsigned ),
- unsigned nReps, unsigned rank, unsigned nProcs, unsigned watch )
-{
- unsigned success = 0;
- unsigned failure = 1;
- unsigned r_i;
-
- assert( desc );
- assert( test );
-
- if( rank == watch )
- printf( " Running test '%s'... ", desc );
-
- for( r_i = 0; r_i < nReps; r_i++ ) {
- Bool result = test( rank, nProcs, watch );
-
- if( rank == watch ) {
- if( result )
- MPI_Bcast( &success, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- else {
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- break;
- }
- }
- else {
- unsigned status;
-
- MPI_Bcast( &status, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- if( status == failure ) break;
- }
- }
-
- if( rank == watch )
- printf( "%s\n", (r_i == nReps) ? "passed" : "failed" );
-}
-
-
-int main( int argc, char* argv[] ) {
- unsigned rank;
- unsigned nProcs;
- unsigned watch;
-
- /* Initialise MPI, get world info. */
- MPI_Init( &argc, &argv );
- MPI_Comm_size( MPI_COMM_WORLD, (int*)&nProcs );
- MPI_Comm_rank( MPI_COMM_WORLD, (int*)&rank );
-
- /* Initialise StGermain. */
- BaseFoundation_Init( &argc, &argv );
- BaseIO_Init( &argc, &argv );
- BaseContainer_Init( &argc, &argv );
-
- /* Watching a particular processor? */
- watch = (argc >= 2) ? atoi( argv[1] ) : 0;
-
- /* Run some tests. */
- runTest( "construct", testConstruct, 10, rank, nProcs, watch );
- runTest( "set indices", testIndices, 10, rank, nProcs, watch );
- runTest( "ranges", testRanges, 10, rank, nProcs, watch );
- runTest( "union", testIntersection, 10, rank, nProcs, watch );
- runTest( "intersection", testIntersection, 10, rank, nProcs, watch );
- runTest( "subtraction", testIntersection, 10, rank, nProcs, watch );
- runTest( "pickle", testPickle, 10, rank, nProcs, watch );
-
- /* Finalise StGermain. */
- BaseContainer_Finalise();
- BaseIO_Finalise();
- BaseFoundation_Finalise();
-
- /* Close off MPI */
- MPI_Finalize();
-
- return MPI_SUCCESS;
-}
-
-
Bool testConstruct( unsigned rank, unsigned nProcs, unsigned watch ) {
RangeSet* set;
@@ -135,6 +50,7 @@
Bool testIndices( unsigned rank, unsigned nProcs, unsigned watch ) {
+ Bool result = True;
unsigned nInds = 100;
unsigned inds[100];
RangeSet* set;
@@ -152,13 +68,12 @@
if( set->nInds != nInds ||
set->nRanges != 1 )
{
- FreeObject( set );
- return False;
+ result = False;
+ goto done;
}
}
RangeSet_GetIndices( set, &nDstInds, &dstInds );
- FreeObject(set );
if( rank == watch ) {
unsigned ind_i;
@@ -171,18 +86,21 @@
break;
}
if( ind_i < nDstInds ) {
- FreeArray( dstInds );
- return False;
+ result = False;
+ goto done;
}
}
+done:
FreeArray( dstInds );
+ FreeObject(set );
- return True;
+ return result;
}
Bool testRanges( unsigned rank, unsigned nProcs, unsigned watch ) {
+ Bool result = True;
unsigned nInds = 100;
unsigned inds[100];
RangeSet* set;
@@ -198,8 +116,8 @@
if( set->nInds != nInds ||
set->nRanges != nInds/10 )
{
- FreeObject( set );
- return False;
+ result = False;
+ goto done;
}
for( i = 0; i < nInds; i++ ) {
@@ -207,15 +125,16 @@
set->ranges[i/10].end != (i/10)*20 + 10 ||
set->ranges[i/10].step != 1 )
{
- FreeObject( set );
- return False;
+ result = False;
+ goto done;
}
}
}
+done:
FreeObject( set );
- return True;
+ return result;
}
@@ -361,3 +280,48 @@
return True;
}
+
+
+#define nTests 7
+
+TestSuite_Test tests[nTests] = {{"construct", testConstruct, 10},
+ {"set indices", testIndices, 10},
+ {"ranges", testRanges, 10 },
+ {"union", testUnion, 10},
+ {"intersection", testIntersection, 10},
+ {"subtraction", testSubtraction, 10},
+ {"pickle", testPickle, 10}};
+
+
+int main( int argc, char* argv[] ) {
+ TestSuite* suite;
+
+ /* Initialise MPI, get world info. */
+ MPI_Init( &argc, &argv );
+
+ /* Initialise StGermain. */
+ BaseFoundation_Init( &argc, &argv );
+ BaseIO_Init( &argc, &argv );
+ BaseContainer_Init( &argc, &argv );
+
+ /* Create the test suite. */
+ suite = TestSuite_New();
+ TestSuite_SetProcToWatch( suite, (argc >= 2) ? atoi( argv[1] ) : 0 );
+ TestSuite_SetTests( suite, nTests, tests );
+
+ /* Run the tests. */
+ TestSuite_Run( suite );
+
+ /* Destroy test suites. */
+ FreeObject( suite );
+
+ /* Finalise StGermain. */
+ BaseContainer_Finalise();
+ BaseIO_Finalise();
+ BaseFoundation_Finalise();
+
+ /* Close off MPI */
+ MPI_Finalize();
+
+ return MPI_SUCCESS;
+}
More information about the cig-commits
mailing list