diff options
Diffstat (limited to 'test/testframe.c')
-rw-r--r-- | test/testframe.c | 331 |
1 files changed, 168 insertions, 163 deletions
diff --git a/test/testframe.c b/test/testframe.c index 3c2a335..dbc174a 100644 --- a/test/testframe.c +++ b/test/testframe.c @@ -24,38 +24,36 @@ /* * Definitions for the testing structure. */ -#define MAXTESTNAME 16 -#define MAXTESTDESC 64 +#define MAXTESTNAME 16 +#define MAXTESTDESC 64 typedef struct TestStruct { - int NumErrors; - char Description[MAXTESTDESC]; - int SkipFlag; - char Name[MAXTESTNAME]; + int NumErrors; + char Description[MAXTESTDESC]; + int SkipFlag; + char Name[MAXTESTNAME]; void (*Call)(void); void (*Cleanup)(void); const void *Parameters; } TestStruct; - /* * Variables used by testing framework. */ -static int enable_error_stack = 0; /* enable error stack; disable=0 enable=1 */ -static int num_errs = 0; /* Total number of errors during testing */ -int TestVerbosity = 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 int TestExpress = -1; /* Do TestExpress or not. -1 means not set yet. */ -static TestStruct *Test = NULL; /* Array of tests */ -static unsigned TestAlloc = 0; /* Size of the Test array */ -static unsigned Index = 0; -static const void *Test_parameters = NULL; -static const char *TestProgName = NULL; -static void (*TestPrivateUsage)(void) = NULL; +static int enable_error_stack = 0; /* enable error stack; disable=0 enable=1 */ +static int num_errs = 0; /* Total number of errors during testing */ +int TestVerbosity = 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 int TestExpress = -1; /* Do TestExpress or not. -1 means not set yet. */ +static TestStruct *Test = NULL; /* Array of tests */ +static unsigned TestAlloc = 0; /* Size of the Test array */ +static unsigned 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; - /* * Setup a test function and add it to the list of tests. * It must have no parameters and returns void. @@ -70,7 +68,8 @@ static int (*TestPrivateParser)(int ac, char *av[]) = NULL; * exit EXIT_FAILURE if error is encountered. */ void -AddTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), const char *TheDescr, const void *Parameters) +AddTest(const char *TheName, void (*TheCall)(void), void (*Cleanup)(void), const char *TheDescr, + const void *Parameters) { /* Sanity checking */ if (HDstrlen(TheDescr) >= MAXTESTDESC) { @@ -83,41 +82,41 @@ AddTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), con } /* end if */ /* Check for increasing the Test array size */ - if(Index >= TestAlloc) { - TestStruct *newTest = Test; /* New array of tests */ - unsigned newAlloc = MAX(1, TestAlloc * 2); /* New array size */ + if (Index >= TestAlloc) { + TestStruct *newTest = Test; /* New array of tests */ + unsigned newAlloc = MAX(1, TestAlloc * 2); /* New array size */ /* Reallocate array */ - if(NULL == (newTest = (TestStruct *)HDrealloc(Test, newAlloc * sizeof(TestStruct)))) { - HDprintf("Out of memory for tests, Index = %u, TestAlloc = %u, newAlloc = %u\n", Index, TestAlloc, newAlloc); + if (NULL == (newTest = (TestStruct *)HDrealloc(Test, newAlloc * sizeof(TestStruct)))) { + HDprintf("Out of memory for tests, Index = %u, TestAlloc = %u, newAlloc = %u\n", Index, TestAlloc, + newAlloc); HDexit(EXIT_FAILURE); } /* end if */ /* Update info */ - Test = newTest; + Test = newTest; TestAlloc = newAlloc; } /* end if */ /* Set up test function */ HDstrcpy(Test[Index].Description, TheDescr); - if(*TheName != '-') { + if (*TheName != '-') { HDstrcpy(Test[Index].Name, TheName); Test[Index].SkipFlag = 0; } - else { /* skip test by default */ - HDstrcpy(Test[Index].Name, TheName+1); + else { /* skip test by default */ + HDstrcpy(Test[Index].Name, TheName + 1); Test[Index].SkipFlag = 1; } - Test[Index].Call = TheCall; - Test[Index].Cleanup = Cleanup; - Test[Index].NumErrors = -1; + Test[Index].Call = TheCall; + Test[Index].Cleanup = Cleanup; + Test[Index].NumErrors = -1; Test[Index].Parameters = Parameters; /* Increment test count */ Index++; } - /* * Initialize testing framework * @@ -132,7 +131,8 @@ AddTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), con * Albert Cheng 2004/08/17 * Added the ProgName, private_usage and private_parser arguments. */ -void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_parser)(int ac, char *av[])) +void +TestInit(const char *ProgName, void (*private_usage)(void), int (*private_parser)(int ac, char *av[])) { /* * Turn off automatic error reporting since we do it ourselves. Besides, @@ -146,13 +146,12 @@ void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_p * Record the program name and private routines if provided. */ TestProgName = ProgName; - if(NULL != private_usage) + if (NULL != private_usage) TestPrivateUsage = private_usage; - if(NULL != private_parser) + if (NULL != private_parser) TestPrivateParser = private_parser; } - /* * Print test usage. * First print the common test options, then the extra options if provided. @@ -160,12 +159,13 @@ void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_p * Modification: * 2004/08/18 Albert Cheng. Add TestPrivateUsage feature. */ -void TestUsage(void) +void +TestUsage(void) { unsigned i; - print_func("Usage: %s [-v[erbose] (l[ow]|m[edium]|h[igh]|0-9)] %s\n", - TestProgName, (TestPrivateUsage ? "<extra options>" : "")); + 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"); @@ -180,7 +180,7 @@ 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){ + if (TestPrivateUsage) { print_func("\nExtra options\n"); TestPrivateUsage(); } @@ -195,21 +195,20 @@ void TestUsage(void) print_func("\n\n"); } - /* * Print test info. */ -void TestInfo(const char *ProgName) +void +TestInfo(const char *ProgName) { unsigned major, minor, release; H5get_libversion(&major, &minor, &release); - print_func("\nFor help use: %s -help\n",ProgName); + print_func("\nFor help use: %s -help\n", ProgName); print_func("Linked with hdf5 version %u.%u release %u\n", major, minor, release); } - /* * Parse command line information. * argc, argv: the usual command line argument count and strings @@ -220,60 +219,62 @@ void TestInfo(const char *ProgName) * Modification: * 2004/08/18 Albert Cheng. Add extra_parse feature. */ -void TestParseCmdLine(int argc, char *argv[]) +void +TestParseCmdLine(int argc, char *argv[]) { hbool_t skipped_all = FALSE; - int ret_code; + int ret_code; - while (argv++, --argc > 0){ + while (argv++, --argc > 0) { if ((HDstrcmp(*argv, "-verbose") == 0) || (HDstrcmp(*argv, "-v") == 0)) { - if (argc > 0){ - --argc; ++argv; + if (argc > 0) { + --argc; + ++argv; ParseTestVerbosity(*argv); } - else{ + else { TestUsage(); HDexit(EXIT_FAILURE); } } - else if (((HDstrcmp(*argv, "-exclude") == 0) || - (HDstrcmp(*argv, "-x") == 0))) { - if (argc > 0){ - --argc; ++argv; + else if (((HDstrcmp(*argv, "-exclude") == 0) || (HDstrcmp(*argv, "-x") == 0))) { + if (argc > 0) { + --argc; + ++argv; SetTest(*argv, SKIPTEST); } - else{ + else { TestUsage(); HDexit(EXIT_FAILURE); } } - else if (((HDstrcmp(*argv, "-begin") == 0) || - (HDstrcmp(*argv, "-b") == 0))) { - if (argc > 0){ - --argc; ++argv; + else if (((HDstrcmp(*argv, "-begin") == 0) || (HDstrcmp(*argv, "-b") == 0))) { + if (argc > 0) { + --argc; + ++argv; SetTest(*argv, BEGINTEST); } - else{ + else { TestUsage(); HDexit(EXIT_FAILURE); } } - else if (((HDstrcmp(*argv, "-only") == 0) || - (HDstrcmp(*argv, "-o") == 0))) { - if(argc > 0) { + else if (((HDstrcmp(*argv, "-only") == 0) || (HDstrcmp(*argv, "-o") == 0))) { + if (argc > 0) { unsigned Loop; - --argc; ++argv; + --argc; + ++argv; /* Skip all tests, then activate only one. */ - if(!skipped_all) { - for(Loop = 0; Loop < Index; Loop++) + if (!skipped_all) { + for (Loop = 0; Loop < Index; Loop++) Test[Loop].SkipFlag = 1; skipped_all = TRUE; } /* end if */ SetTest(*argv, ONLYTEST); } - else{ + else { TestUsage(); HDexit(EXIT_FAILURE); } @@ -292,33 +293,33 @@ void TestParseCmdLine(int argc, char *argv[]) /* non-standard option. Break out. */ break; } - } /* Call extra parsing function if provided. */ - if (NULL != TestPrivateParser){ - ret_code=TestPrivateParser(argc+1, argv-1); + if (NULL != TestPrivateParser) { + ret_code = TestPrivateParser(argc + 1, argv - 1); if (ret_code != 0) HDexit(EXIT_FAILURE); } } - /* * Perform Tests. */ -void PerformTests(void) +void +PerformTests(void) { - unsigned Loop; + unsigned Loop; for (Loop = 0; Loop < Index; Loop++) if (Test[Loop].SkipFlag) { MESSAGE(2, ("Skipping -- %s (%s) \n", Test[Loop].Description, Test[Loop].Name)); - } else { + } + else { MESSAGE(2, ("Testing -- %s (%s) \n", Test[Loop].Description, Test[Loop].Name)); MESSAGE(5, ("===============================================\n")); Test[Loop].NumErrors = num_errs; - Test_parameters = Test[Loop].Parameters; + Test_parameters = Test[Loop].Parameters; ALARM_ON; Test[Loop].Call(); ALARM_OFF; @@ -327,22 +328,22 @@ void PerformTests(void) MESSAGE(5, ("There were %d errors detected.\n\n", (int)Test[Loop].NumErrors)); } - Test_parameters = NULL; /* clear it. */ + Test_parameters = NULL; /* clear it. */ MESSAGE(2, ("\n\n")) if (num_errs) - print_func("!!! %d Error(s) were detected !!!\n\n", (int) num_errs); + print_func("!!! %d Error(s) were detected !!!\n\n", (int)num_errs); else print_func("All tests were successful. \n\n"); } - /* * Display test summary. */ -void TestSummary(void) +void +TestSummary(void) { - unsigned Loop; + unsigned Loop; print_func("Summary of Test Results:\n"); print_func("Name of Test Errors Description of Test\n"); @@ -358,52 +359,53 @@ void TestSummary(void) print_func("\n\n"); } - /* * Cleanup files from testing */ -void TestCleanup(void) +void +TestCleanup(void) { - unsigned Loop; + unsigned Loop; MESSAGE(2, ("\nCleaning Up temp files...\n\n")); /* call individual cleanup routines in each source module */ for (Loop = 0; Loop < Index; Loop++) - if (!Test[Loop].SkipFlag && Test[Loop].Cleanup!=NULL) + if (!Test[Loop].SkipFlag && Test[Loop].Cleanup != NULL) Test[Loop].Cleanup(); } - /* * Shutdown the test infrastructure */ -void TestShutdown(void) +void +TestShutdown(void) { - if(Test) + if (Test) HDfree(Test); } - /* * Retrieve the verbosity level for the testing framework */ -H5_ATTR_PURE int GetTestVerbosity(void) +H5_ATTR_PURE int +GetTestVerbosity(void) { - return(TestVerbosity); + return (TestVerbosity); } /* * Set the verbosity level for the testing framework. * Return previous verbosity level. */ -int SetTestVerbosity(int newval) +int +SetTestVerbosity(int newval) { int oldval; - oldval = TestVerbosity; + oldval = TestVerbosity; TestVerbosity = newval; - return(oldval); + return (oldval); } /* @@ -433,28 +435,28 @@ int SetTestVerbosity(int newval) I think this can be easily implemented in the test library (libh5test.a) so that all tests can just call it to check the status of $HDF5TestExpress. */ -int GetTestExpress(void) +int +GetTestExpress(void) { - char * env_val; + char *env_val; /* set it here for now. Should be done in something like h5test_init(). */ - if(TestExpress==-1) - { + if (TestExpress == -1) { env_val = getenv("HDF5TestExpress"); - if(env_val == NULL) + if (env_val == NULL) SetTestExpress(1); - else if(strcmp(env_val, "0") == 0) + else if (strcmp(env_val, "0") == 0) SetTestExpress(0); - else if(strcmp(env_val, "1") == 0) + else if (strcmp(env_val, "1") == 0) SetTestExpress(1); - else if(strcmp(env_val, "2") == 0) + else if (strcmp(env_val, "2") == 0) SetTestExpress(2); else SetTestExpress(3); } - return(TestExpress); + return (TestExpress); } /* @@ -462,50 +464,55 @@ int GetTestExpress(void) * Return previous TestExpress mode. * Values: non-zero means TestExpress mode is on, 0 means off. */ -int SetTestExpress(int newval) +int +SetTestExpress(int newval) { int oldval; - oldval = TestExpress; + oldval = TestExpress; TestExpress = newval; - return(oldval); + return (oldval); } /* * Retrieve Summary request value. * 0 means no summary, 1 means yes. */ -H5_ATTR_PURE int GetTestSummary(void) +H5_ATTR_PURE int +GetTestSummary(void) { - return(Summary); + return (Summary); } /* * Retrieve Cleanup request value. * 0 means no Cleanup, 1 means yes. */ -H5_ATTR_PURE int GetTestCleanup(void) +H5_ATTR_PURE int +GetTestCleanup(void) { - return(CleanUp); + return (CleanUp); } /* * Set cleanup to no. * Return previous cleanup value. */ -int SetTestNoCleanup(void) +int +SetTestNoCleanup(void) { int oldval; - oldval = CleanUp; + oldval = CleanUp; CleanUp = 0; - return(oldval); + return (oldval); } /* * Parse an argument string for verbosity level and set it. */ -void ParseTestVerbosity(char *argv) +void +ParseTestVerbosity(char *argv) { if (*argv == 'l') SetTestVerbosity(VERBO_LO); @@ -517,34 +524,33 @@ void ParseTestVerbosity(char *argv) SetTestVerbosity(atoi(argv)); } - /* * Retrieve the number of testing errors for the testing framework */ -H5_ATTR_PURE int GetTestNumErrs(void) +H5_ATTR_PURE int +GetTestNumErrs(void) { - return(num_errs); + return (num_errs); } - /* * Increment the number of testing errors */ -void IncTestNumErrs(void) +void +IncTestNumErrs(void) { num_errs++; } - /* * Retrieve the current Test Parameters pointer. */ -H5_ATTR_PURE const void *GetTestParameters(void) +H5_ATTR_PURE const void * +GetTestParameters(void) { - return(Test_parameters); + return (Test_parameters); } - /* * This routine is designed to provide equivalent functionality to 'printf' * and also increment the error count for the testing framework. @@ -553,7 +559,7 @@ int TestErrPrintf(const char *format, ...) { va_list arglist; - int ret_value; + int ret_value; /* Increment the error count */ num_errs++; @@ -567,7 +573,6 @@ TestErrPrintf(const char *format, ...) return ret_value; } - /* * Set (control) which test will be tested. * SKIPTEST: skip this test @@ -575,59 +580,59 @@ TestErrPrintf(const char *format, ...) * BEGINETEST: skip all tests before this test * */ -void SetTest(const char *testname, int action) +void +SetTest(const char *testname, int action) { unsigned Loop; - switch (action){ - case SKIPTEST: - for (Loop = 0; Loop < Index; Loop++) - if (HDstrcmp(testname, Test[Loop].Name) == 0){ - Test[Loop].SkipFlag = 1; - break; - } - break; - case BEGINTEST: - for (Loop = 0; Loop < Index; Loop++) { - if (HDstrcmp(testname, Test[Loop].Name) != 0) - Test[Loop].SkipFlag = 1; - else{ - /* Found it. Set it to run. Done. */ - Test[Loop].SkipFlag = 0; - break; + switch (action) { + case SKIPTEST: + for (Loop = 0; Loop < Index; Loop++) + if (HDstrcmp(testname, Test[Loop].Name) == 0) { + Test[Loop].SkipFlag = 1; + break; + } + break; + case BEGINTEST: + for (Loop = 0; Loop < Index; Loop++) { + if (HDstrcmp(testname, Test[Loop].Name) != 0) + Test[Loop].SkipFlag = 1; + else { + /* Found it. Set it to run. Done. */ + Test[Loop].SkipFlag = 0; + break; + } } - } - break; - case ONLYTEST: - for (Loop = 0; Loop < Index; Loop++) { - if (HDstrcmp(testname, Test[Loop].Name) == 0) { - /* Found it. Set it to run. Break to skip the rest. */ - Test[Loop].SkipFlag = 0; - break; + break; + case ONLYTEST: + for (Loop = 0; Loop < Index; Loop++) { + if (HDstrcmp(testname, Test[Loop].Name) == 0) { + /* Found it. Set it to run. Break to skip the rest. */ + Test[Loop].SkipFlag = 0; + break; + } } - } - break; - default: - /* error */ - HDprintf("*** ERROR: Unknown action (%d) for SetTest\n", action); - break; + break; + default: + /* error */ + HDprintf("*** ERROR: Unknown action (%d) for SetTest\n", action); + break; } } - /* * Enable alarm on test execution, configurable by environment variable */ -void TestAlarmOn(void) +void +TestAlarmOn(void) { - char * env_val = HDgetenv("HDF5_ALARM_SECONDS"); /* Alarm environment */ - unsigned long alarm_sec = H5_ALARM_SEC; /* Number of seconds before alarm goes off */ + char * env_val = HDgetenv("HDF5_ALARM_SECONDS"); /* Alarm environment */ + unsigned long alarm_sec = H5_ALARM_SEC; /* Number of seconds before alarm goes off */ /* Get the alarm value from the environment variable, if set */ - if(env_val != NULL) + if (env_val != NULL) alarm_sec = (unsigned)HDstrtoul(env_val, (char **)NULL, 10); /* Set the number of seconds before alarm goes off */ HDalarm((unsigned)alarm_sec); } - |