[cig-commits] r4355 - in long/3D/Gale/trunk/src/StGermain: . Base/Foundation/src

walter at geodynamics.org walter at geodynamics.org
Thu Aug 17 17:18:13 PDT 2006


Author: walter
Date: 2006-08-17 17:18:11 -0700 (Thu, 17 Aug 2006)
New Revision: 4355

Added:
   long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.c
   long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.h
Modified:
   long/3D/Gale/trunk/src/StGermain/
   long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/Foundation.h
   long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/types.h
Log:
 r2723 at earth:  boo | 2006-08-17 17:14:28 -0700
  r2677 at earth (orig r3758):  LukeHodkinson | 2006-08-08 02:17:16 -0700
  Adding a class to help implement unit tests.  Essentially,
  this class calls a set of test functions provided by
  each test file, printing success or failure based on
  a boolean return value. Has support for watching a 
  particular parallel processor and repeating tests
  a number of times.
  
 



Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
   - 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2722
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3757
   + 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2723
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3758

Modified: long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/Foundation.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/Foundation.h	2006-08-18 00:18:07 UTC (rev 4354)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/Foundation.h	2006-08-18 00:18:11 UTC (rev 4355)
@@ -43,6 +43,7 @@
 	
 	#include "types.h"
 	#include "shortcuts.h"
+	#include "mem.h"
 	#include "CommonRoutines.h"
 	#include "MemoryTag.h"
 	#include "MemoryPointer.h"
@@ -57,6 +58,7 @@
 	#include "NamedObject_Register.h"
 	#include "TimeMonitor.h"
 	#include "MemMonitor.h"
+	#include "TestSuite.h"
 	#include "Init.h"
 	#include "Finalise.h"
 

Added: long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.c	2006-08-18 00:18:07 UTC (rev 4354)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.c	2006-08-18 00:18:11 UTC (rev 4355)
@@ -0,0 +1,245 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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: TestSuite.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "forwardDecl.h"
+#include "MemoryTag.h"
+#include "Memory.h"
+#include "Class.h"
+#include "TestSuite.h"
+
+
+/* Textual name of this class */
+const Type TestSuite_Type = "TestSuite";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+TestSuite* TestSuite_New() {
+	return _TestSuite_New( sizeof(TestSuite), 
+			      TestSuite_Type, 
+			      _TestSuite_Delete, 
+			      _TestSuite_Print, 
+			      _TestSuite_Copy );
+}
+
+TestSuite* _TestSuite_New( TESTSUITE_DEFARGS ) {
+	TestSuite* self;
+
+	/* Allocate memory */
+	assert( sizeOfSelf >= sizeof(TestSuite) );
+	self = (TestSuite*)_Stg_Class_New( STG_CLASS_PASSARGS );
+
+	/* Virtual info */
+
+	/* TestSuite info */
+	_TestSuite_Init( self );
+
+	return self;
+}
+
+void _TestSuite_Init( TestSuite* self ) {
+	assert( self );
+
+	self->nTests = 0;
+	self->tests = NULL;
+	self->watch = 0;
+	self->nReps = 10;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _TestSuite_Delete( void* testSuite ) {
+	TestSuite*	self = (TestSuite*)testSuite;
+
+	assert( self );
+
+	TestSuite_Destruct( self );
+
+	/* Delete the parent. */
+	_Stg_Class_Delete( self );
+}
+
+void _TestSuite_Print( void* testSuite, struct Stream* stream ) {
+	TestSuite*	self = (TestSuite*)testSuite;
+
+	/* Print parent */
+	Journal_Printf( stream, "TestSuite (ptr): (%p)\n", self );
+	_Stg_Class_Print( self, stream );
+}
+
+void* _TestSuite_Copy( void* testSuite, void* destProc_I, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+#if 0
+	TestSuite*	self = (TestSuite*)testSuite;
+	TestSuite*	newTestSuite;
+	PtrMap*	map = ptrMap;
+	Bool	ownMap = False;
+
+	/* Damn me for making copying so difficult... what was I thinking? */
+	
+	/* We need to create a map if it doesn't already exist. */
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newTestSuite = (TestSuite*)_Mesh_Copy( self, destProc_I, deep, nameExt, map );
+	
+	/* Copy the virtual methods here. */
+
+	/* Deep or shallow? */
+	if( deep ) {
+	}
+	else {
+	}
+	
+	/* If we own the map, get rid of it here. */
+	if( ownMap ) Stg_Class_Delete( map );
+	
+	return (void*)newTestSuite;
+#endif
+
+	return NULL;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void TestSuite_SetTests( void* testSuite, unsigned nTests, TestSuite_Test* tests ) {
+	TestSuite*	self = (TestSuite*)testSuite;
+
+	assert( self );
+	assert( !nTests || tests );
+
+	TestSuite_Destruct( self );
+
+	self->nTests = nTests;
+	if( nTests ) {
+		self->tests = Memory_Alloc_Array( TestSuite_Test, nTests, "TestSuite::tests" );
+		memcpy( self->tests, tests, nTests * sizeof(TestSuite_Test) );
+	}
+}
+
+void TestSuite_SetNReps( void* testSuite, unsigned nReps ) {
+	TestSuite*	self = (TestSuite*)testSuite;
+
+	assert( self );
+
+	self->nReps = nReps;
+}
+
+void TestSuite_SetProcToWatch( void* testSuite, unsigned watch ) {
+	TestSuite*	self = (TestSuite*)testSuite;
+
+	assert( self );
+#ifndef NDEBUG
+	{
+		unsigned	nProcs;
+
+		MPI_Comm_size( MPI_COMM_WORLD, (int*)&nProcs );
+		assert( watch < nProcs );
+	}
+#endif
+
+	self->watch = watch;
+}
+
+void TestSuite_Run( void* testSuite ) {
+	TestSuite*	self = (TestSuite*)testSuite;
+	unsigned	nProcs;
+	unsigned	rank;
+	unsigned	t_i;
+
+	assert( self );
+
+	MPI_Comm_size( MPI_COMM_WORLD, (int*)&nProcs );
+	MPI_Comm_rank( MPI_COMM_WORLD, (int*)&rank );
+
+	for( t_i = 0; t_i < self->nTests; t_i++ ) {
+		TestSuite_Test*	test = self->tests + t_i;
+		unsigned	success = 0;
+		unsigned	failure = 1;
+		unsigned	r_i;
+
+		assert( test );
+		assert( test->name );
+		assert( test->func );
+
+		if( rank == self->watch )
+			printf( "   Running test '%s'... ", test->name );
+
+		for( r_i = 0; r_i < self->nReps; r_i++ ) {
+			Bool	result = test->func( rank, nProcs, self->watch );
+
+			if( rank == self->watch ) {
+				if( result )
+					MPI_Bcast( &success, 1, MPI_UNSIGNED, self->watch, MPI_COMM_WORLD );
+				else {
+					MPI_Bcast( &failure, 1, MPI_UNSIGNED, self->watch, MPI_COMM_WORLD );
+					break;
+				}
+			}
+			else {
+				unsigned	status;
+
+				MPI_Bcast( &status, 1, MPI_UNSIGNED, self->watch, MPI_COMM_WORLD );
+				if( status == failure ) break;
+			}
+		}
+
+		if( rank == self->watch )
+			printf( "%s\n", (r_i == self->nReps) ? "passed" : "failed" );
+	}
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+void TestSuite_Destruct( TestSuite* self ) {
+	assert( self );
+
+	self->nTests = 0;
+	KillArray( self->tests );
+}

Added: long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.h	2006-08-18 00:18:07 UTC (rev 4354)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/TestSuite.h	2006-08-18 00:18:11 UTC (rev 4355)
@@ -0,0 +1,118 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+*/
+/** \file
+**  Role:
+**
+** Assumptions:
+**
+** Invariants:
+**
+** Comments:
+**
+** $Id: RangeSet.h 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifndef __Base_Foundation_TestSuite_h__
+#define __Base_Foundation_TestSuite_h__
+
+	/** Textual name of this class */
+	extern const Type TestSuite_Type;
+
+	/* Forward declaring Stream */
+	struct Stream;
+	struct PtrMap;
+
+	/** Virtual function types */
+
+	/** Class contents */
+	typedef Bool (TestSuite_TestFunc)( unsigned rank, unsigned nProcs, unsigned watch );
+
+	typedef struct {
+		const char*		name;
+		TestSuite_TestFunc*	func;
+	} TestSuite_Test;
+
+	#define __TestSuite				\
+		/* General info */			\
+		__Stg_Class				\
+							\
+		/* Virtual info */			\
+							\
+		/* TestSuite info */			\
+		unsigned		nTests;		\
+		TestSuite_Test*		tests;		\
+		unsigned		watch;		\
+		unsigned		nReps;
+
+	struct TestSuite { __TestSuite };
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Constructors
+	*/
+
+	#define TESTSUITE_DEFARGS		\
+		STG_CLASS_DEFARGS
+
+	#define TESTSUITE_PASSARGS	\
+		STG_CLASS_PASSARGS
+
+	TestSuite* TestSuite_New();
+	TestSuite* _TestSuite_New( TESTSUITE_DEFARGS );
+	void _TestSuite_Init( TestSuite* self );
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Virtual functions
+	*/
+
+	void _TestSuite_Delete( void* testSuite );
+	void _TestSuite_Print( void* testSuite, struct Stream* stream );
+
+	#define TestSuite_Copy( self ) \
+		(TestSuite*)Stg_Class_Copy( self, NULL, False, NULL, NULL )
+	#define TestSuite_DeepCopy( self ) \
+		(TestSuite*)Stg_Class_Copy( self, NULL, True, NULL, NULL )
+	void* _TestSuite_Copy( void* testSuite, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap );
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Public functions
+	*/
+
+	void TestSuite_SetTests( void* testSuite, unsigned nTests, TestSuite_Test* tests );
+	void TestSuite_SetNReps( void* testSuite, unsigned nReps );
+	void TestSuite_SetProcToWatch( void* testSuite, unsigned watch );
+
+	void TestSuite_Run( void* testSuite );
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Private Member functions
+	*/
+
+	void TestSuite_Destruct( TestSuite* self );
+
+#endif /* __Base_Foundation_TestSuite_h__ */

Modified: long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/types.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/types.h	2006-08-18 00:18:07 UTC (rev 4354)
+++ long/3D/Gale/trunk/src/StGermain/Base/Foundation/src/types.h	2006-08-18 00:18:11 UTC (rev 4355)
@@ -60,6 +60,8 @@
 		
 	typedef struct NamedObject_Register	NamedObject_Register;
 	typedef struct _Stg_ObjectList		Stg_ObjectList;
+
+	typedef struct TestSuite		TestSuite;
 	
 	/* Memory module classes */
 	typedef struct MemoryTag		MemoryTag;



More information about the cig-commits mailing list