[svn-r9115] Purpose:

feature

Description:
Another revamp of the test interface.
TestInit: is used to register Test Program name, test program specific
   Usage and option parsing routines.
TestUsage: will invoke extra usage routine if provided.
TestParseCmdLine: will invoke extra option parsing routine if provided.
GetTestSummary() and GetTestCleanup() replaces the previous Summary and
CleanUp arguments of TestParseCmdLine.

test/testhdf5, test/ttsafe.c, testpar/t_mpi.c, testpar/testphdf5.c:
   All have been updated to use the new Test Routines.

testpar/t_mpi.c:
   Also a fix of a compiler optimization bug when pgcc in Linux is
   used to compile it.  Changed buf[] and expected to unsigned char
   type to avoid a bug that failed to do sign-extension.

Platforms tested:
"h5committested"
Also tested thread-safe option in eirene.
This commit is contained in:
Albert Cheng 2004-08-19 01:32:47 -05:00
parent 3fe6ec1141
commit 3c59678775
7 changed files with 91 additions and 50 deletions

View File

@ -47,11 +47,8 @@ using namespace H5;
int
main(int argc, char *argv[])
{
int Summary = 0;
int CleanUp = 1;
/* Initialize testing framework */
TestInit();
TestInit(argv[0], NULL, NULL);
// testing file creation and opening in tfile.cpp
AddTest("file", test_file, cleanup_file, "File I/O Operations", NULL);
@ -74,17 +71,17 @@ Comment out tests that are not done yet */
TestInfo(argv[0]);
/* Parse command line arguments */
TestParseCmdLine(argc,argv,&Summary,&CleanUp,NULL);
TestParseCmdLine(argc,argv);
/* Perform requested testing */
PerformTests();
/* Display test summary, if requested */
if (Summary)
if (GetTestSummary())
TestSummary();
/* Clean up test files, if allowed */
if (CleanUp && !getenv("HDF5_NOCLEANUP"))
if (GetTestCleanup() && !getenv("HDF5_NOCLEANUP"))
TestCleanup();
return (GetTestNumErrs());

View File

@ -124,13 +124,15 @@ H5TEST_DLL void AddTest(const char *TheName, void (*TheCall) (void),
void (*Cleanup) (void), const char *TheDescr,
const void *Parameters);
H5TEST_DLL void TestInfo(const char *ProgName);
H5TEST_DLL void TestParseCmdLine(int argc, char *argv[], int *Summary, int *CleanUp, int (*extra_parse)(int ac, char *av[]));
H5TEST_DLL void TestParseCmdLine(int argc, char *argv[]);
H5TEST_DLL void PerformTests(void);
H5TEST_DLL void TestSummary(void);
H5TEST_DLL void TestCleanup(void);
H5TEST_DLL void TestInit(void);
H5TEST_DLL void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_parser)(int ac, char *av[]));
H5TEST_DLL int GetTestVerbosity(void);
H5TEST_DLL int SetTestVerbosity(int newval);
H5TEST_DLL int GetTestSummary(void);
H5TEST_DLL int GetTestCleanup(void);
H5TEST_DLL void ParseTestVerbosity(char *argv);
H5TEST_DLL int GetTestNumErrs(void);
H5TEST_DLL const void *GetTestParameters(void);

View File

@ -45,9 +45,14 @@ typedef struct TestStruct {
*/
static int num_errs = 0; /* Total number of errors during testing */
static int Verbosity = VERBO_DEF; /* Default Verbosity is Low */
static int Summary = 0; /* Show test summary. Default is no. */
static int CleanUp = 1; /* Do cleanup or not. Default is yes. */
static TestStruct Test[MAXNUMOFTESTS];
static int Index = 0;
static const void *Test_parameters = NULL;
static const char *TestProgName = NULL;
static void (*TestPrivateUsage)(void) = NULL;
static int (*TestPrivateParser)(int ac, char *av[]) = NULL;
/*
@ -103,8 +108,19 @@ AddTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), con
/*
* Initialize testing framework
*
* ProgName: Name of test program.
* private_usage: Optional routine provided by test program to print the
* private portion of usage page. Default to NULL which means none is
* provided.
* private_parser: Optional routine provided by test program to parse the
* private options. Default to NULL which means none is provided.
*
* Modifications:
* Albert Cheng 2004/08/17
* Added the ProgName, private_usage and private_parser arguments.
*/
void TestInit(void)
void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_parser)(int ac, char *av[]))
{
#if !(defined MAC || defined __MWERKS__ || defined SYMANTEC_C)
/* Un-buffer the stdout and stderr */
@ -123,17 +139,30 @@ void TestInit(void)
H5Eset_auto (H5E_DEFAULT, NULL, NULL);
#endif /* H5_WANT_H5_V1_6_COMPAT */
/*
* Record the program name and private routines if provided.
*/
TestProgName = ProgName;
if (NULL != private_usage)
TestPrivateUsage = private_usage;
if (NULL != private_parser)
TestPrivateParser = private_parser;
}
/*
* Print test usage.
* First print the common test options, then the extra options if provided.
*
* Modification:
* 2004/08/18 Albert Cheng. Add TestPrivateUsage feature.
*/
void TestUsage(void)
{
int i;
print_func("Usage: ttsafe [-v[erbose] (l[ow]|m[edium]|h[igh]|0-9)] \n");
print_func("Usage: %s [-v[erbose] (l[ow]|m[edium]|h[igh]|0-9)] %s\n",
TestProgName, (TestPrivateUsage ? "<extra options>" : ""));
print_func(" [-[e]x[clude] name+] \n");
print_func(" [-o[nly] name+] \n");
print_func(" [-b[egin] name] \n");
@ -148,6 +177,10 @@ void TestUsage(void)
print_func("summary prints a summary of test results at the end\n");
print_func("cleanoff does not delete *.hdf files after execution of tests\n");
print_func("help print out this information\n");
if (TestPrivateUsage){
print_func("\nExtra options\n");
TestPrivateUsage();
}
print_func("\n\n");
print_func("This program currently tests the following: \n\n");
print_func("%16s %s\n", "Name", "Description");
@ -177,15 +210,11 @@ void TestInfo(const char *ProgName)
/*
* Parse command line information.
* argc, argv: the usual command line argument count and strings
* Summary: Return if summary is desired. Default no.
* CleanUp: Return if Cleanup is desired. Default yes.
* extra_parse: Extra Parse function provided by individual application.
* NULL means no extra parsing needed.
*
* Modification:
* 2004/08/12 Albert Cheng. Add extra_parse feature.
* 2004/08/18 Albert Cheng. Add extra_parse feature.
*/
void TestParseCmdLine(int argc, char *argv[], int *Summary, int *CleanUp, int (*extra_parse)(int ac, char *av[]))
void TestParseCmdLine(int argc, char *argv[])
{
while (argv++, --argc > 0){
if ((HDstrcmp(*argv, "-verbose") == 0) ||
@ -233,13 +262,13 @@ void TestParseCmdLine(int argc, char *argv[], int *Summary, int *CleanUp, int (*
}
}
else if ((HDstrcmp(*argv, "-summary") == 0) || (HDstrcmp(*argv, "-s") == 0))
*Summary = 1;
Summary = 1;
else if ((HDstrcmp(*argv, "-help") == 0) || (HDstrcmp(*argv, "-h") == 0)) {
TestUsage();
exit(0);
}
else if ((HDstrcmp(*argv, "-cleanoff") == 0) || (HDstrcmp(*argv, "-c") == 0))
*CleanUp = 0;
CleanUp = 0;
else {
/* non-standard option. Break out. */
break;
@ -248,8 +277,8 @@ void TestParseCmdLine(int argc, char *argv[], int *Summary, int *CleanUp, int (*
}
/* Call extra parsing function if provided. */
if (NULL != extra_parse){
extra_parse(argc+1, argv-1);
if (NULL != TestPrivateParser){
TestPrivateParser(argc+1, argv-1);
}
}
@ -344,6 +373,24 @@ int SetTestVerbosity(int newval)
return(oldval);
}
/*
* Retrieve Summary request value.
* 0 means no summary, 1 means yes.
*/
int GetTestSummary(void)
{
return(Summary);
}
/*
* Retrieve Cleanup request value.
* 0 means no Cleanup, 1 means yes.
*/
int GetTestCleanup(void)
{
return(CleanUp);
}
/*
* Parse an argument string for verbosity level and set it.
*/

View File

@ -39,11 +39,8 @@
int
main(int argc, char *argv[])
{
int Summary = 0;
int CleanUp = 1;
/* Initialize testing framework */
TestInit();
TestInit(argv[0], NULL, NULL);
/* Tests are generally arranged from least to most complexity... */
AddTest("configure", test_configure, cleanup_configure, "Configure definitions", NULL);
@ -64,23 +61,22 @@ main(int argc, char *argv[])
AddTest("array", test_array, cleanup_array, "Array Datatypes", NULL);
AddTest("genprop", test_genprop, cleanup_genprop, "Generic Properties", NULL);
AddTest("misc", test_misc, cleanup_misc, "Miscellaneous", NULL);
AddTest("id", test_ids, NULL, "Public ID Functions", NULL);
/* Display testing information */
TestInfo(argv[0]);
/* Parse command line arguments */
TestParseCmdLine(argc,argv,&Summary,&CleanUp,NULL);
TestParseCmdLine(argc,argv);
/* Perform requested testing */
PerformTests();
/* Display test summary, if requested */
if (Summary)
if (GetTestSummary())
TestSummary();
/* Clean up test files, if allowed */
if (CleanUp && !getenv("HDF5_NOCLEANUP"))
if (GetTestCleanup() && !getenv("HDF5_NOCLEANUP"))
TestCleanup();
return (GetTestNumErrs());

View File

@ -85,10 +85,8 @@ char *gen_name(int value)
int main(int argc, char *argv[])
{
int Summary = 0, CleanUp = 1;
/* Initialize testing framework */
TestInit();
TestInit(argv[0], NULL, NULL);
/* Tests are generally arranged from least to most complexity... */
AddTest("dcreate", tts_dcreate, cleanup_dcreate, "multi-dataset creation", NULL);
@ -100,17 +98,17 @@ int main(int argc, char *argv[])
TestInfo(argv[0]);
/* Parse command line arguments */
TestParseCmdLine(argc,argv,&Summary,&CleanUp,NULL);
TestParseCmdLine(argc,argv);
/* Perform requested testing */
PerformTests();
/* Display test summary, if requested */
if (Summary)
if (GetTestSummary())
TestSummary();
/* Clean up test files, if allowed */
if (CleanUp && !getenv("HDF5_NOCLEANUP"))
if (GetTestCleanup() && !getenv("HDF5_NOCLEANUP"))
TestCleanup();
return GetTestNumErrs();

View File

@ -54,7 +54,7 @@ test_mpio_overlap_writes(char *filename)
MPI_File fh;
int i;
int vrfyerrs;
char buf[4093]; /* use some prime number for size */
unsigned char buf[4093]; /* use some prime number for size */
int bufsize = sizeof(buf);
MPI_Offset stride;
MPI_Offset mpi_off;
@ -97,7 +97,7 @@ test_mpio_overlap_writes(char *filename)
/* set data to some trivial pattern for easy verification */
for (i=0; i<stride; i++)
buf[i] = (char)(mpi_off+i);
buf[i] = (unsigned char)(mpi_off+i);
mrc = MPI_File_write_at(fh, mpi_off, buf, (int)stride, MPI_BYTE,
&mpi_stat);
VRFY((mrc==MPI_SUCCESS), "");
@ -143,12 +143,13 @@ test_mpio_overlap_writes(char *filename)
VRFY((mrc==MPI_SUCCESS), "");
vrfyerrs=0;
for (i=0; i<stride; i++){
char expected;
expected = (char)(mpi_off+i);
if ((buf[i] != expected) &&
(vrfyerrs++ < MAX_ERR_REPORT || VERBOSE_MED))
printf("proc %d: found data error at [%ld], expect %d, got %d\n",
unsigned char expected;
expected = (unsigned char)(mpi_off+i);
if ((expected != buf[i]) &&
(vrfyerrs++ < MAX_ERR_REPORT || VERBOSE_MED)) {
printf("proc %d: found data error at [%ld], expect %u, got %u\n",
mpi_rank, (long)(mpi_off+i), expected, buf[i]);
}
}
if (vrfyerrs > MAX_ERR_REPORT && !VERBOSE_MED)
printf("proc %d: [more errors ...]\n", mpi_rank);
@ -341,9 +342,10 @@ test_mpio_gb_file(char *filename)
vrfyerrs=0;
for (j=0; j<MB; j++){
if ((*(buf+j) != expected) &&
(vrfyerrs++ < MAX_ERR_REPORT || VERBOSE_MED))
(vrfyerrs++ < MAX_ERR_REPORT || VERBOSE_MED)){
printf("proc %d: found data error at [%ld+%d], expect %d, got %d\n",
mpi_rank, (long)mpi_off, j, expected, *(buf+j));
}
}
if (vrfyerrs > MAX_ERR_REPORT && !VERBOSE_MED)
printf("proc %d: [more errors ...]\n", mpi_rank);
@ -669,6 +671,7 @@ main(int argc, char **argv)
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
H5open();
TestInit(argv[0], NULL, parse_options);
if (parse_options(argc, argv) != 0){
if (MAINPROCESS)
usage();

View File

@ -121,7 +121,7 @@ int MPI_Init(int *argc, char ***argv)
static void
usage(void)
{
printf("Usage: testphdf5 [-r] [-w] [-v<verbosity>] [-m<n_datasets>] [-n<n_groups>] "
printf(" [-r] [-w] [-v<verbosity>] [-m<n_datasets>] [-n<n_groups>] "
"[-o] [-f <prefix>] [-d <dim0> <dim1>]\n");
printf("\t-r\t\tno read test\n");
printf("\t-w\t\tno write test\n");
@ -368,8 +368,6 @@ int main(int argc, char **argv)
int mpi_size, mpi_rank; /* mpi variables */
H5Ptest_param_t ndsets_params, ngroups_params;
H5Ptest_param_t collngroups_params;
int Summary = 0;
int CleanUp = 1;
/* Un-buffer the stdout and stderr */
setbuf(stderr, NULL);
@ -388,7 +386,7 @@ int main(int argc, char **argv)
h5_show_hostname();
/* Initialize testing framework */
TestInit();
TestInit(argv[0], usage, parse_options);
/* Tests are generally arranged from least to most complexity... */
AddTest("mpio_dup", test_fapl_mpio_dup, NULL,
@ -476,7 +474,7 @@ int main(int argc, char **argv)
H5Pset_fapl_mpio(fapl, MPI_COMM_WORLD, MPI_INFO_NULL);
/* Parse command line arguments */
TestParseCmdLine(argc, argv, &Summary, &CleanUp, parse_options);
TestParseCmdLine(argc, argv);
/*
if (parse_options(argc, argv) != 0){
@ -501,11 +499,11 @@ int main(int argc, char **argv)
PerformTests();
/* Display test summary, if requested */
if (Summary)
if (GetTestSummary())
TestSummary();
/* Clean up test files, if allowed */
if (CleanUp && !getenv("HDF5_NOCLEANUP"))
if (GetTestCleanup() && !getenv("HDF5_NOCLEANUP"))
TestCleanup();
nerrors += GetTestNumErrs();