2 ********************************************************************************
4 * Copyright (C) 1996-2014, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
16 #include "unicode/utrace.h"
17 #include "unicode/uclean.h"
22 3/20/1999 srl - strncpy called w/o setting nulls at the end
25 #define MAXTESTNAME 128
27 #define MAX_TEST_LOG 4096
30 * How may columns to indent the 'OK' markers.
32 #define FLAG_INDENT 45
34 * How many lines of scrollage can go by before we need to remind the user what the test is.
36 #define PAGE_SIZE_LIMIT 25
45 struct TestNode
* sibling
;
46 struct TestNode
* child
;
47 char name
[1]; /* This is dynamically allocated off the end with malloc. */
51 static const struct TestNode
* currentTest
;
53 typedef enum { RUNTESTS
, SHOWTESTS
} TestMode
;
54 #define TEST_SEPARATOR '/'
60 #include "unicode/ctest.h"
62 static char ERROR_LOG
[MAX_TEST_LOG
][MAXTESTNAME
];
64 /* Local prototypes */
65 static TestNode
* addTestNode( TestNode
*root
, const char *name
);
67 static TestNode
*createTestNode(const char* name
, int32_t nameLen
);
69 static int strncmp_nullcheck( const char* s1
,
73 static void getNextLevel( const char* name
,
75 const char** nextName
);
77 static void iterateTestsWithLevel( const TestNode
*root
, int depth
,
78 const TestNode
** nodeList
,
81 static void help ( const char *argv0
);
84 * Do the work of logging an error. Doesn't increase the error count.
86 * @prefix optional prefix prepended to message, or NULL.
87 * @param pattern printf style pattern
88 * @param ap vprintf style arg list
90 static void vlog_err(const char *prefix
, const char *pattern
, va_list ap
);
91 static void vlog_verbose(const char *prefix
, const char *pattern
, va_list ap
);
92 static UBool
vlog_knownIssue(const char *ticket
, const char *pattern
, va_list ap
);
95 * Log test structure, with indent
96 * @param pattern printf pattern
98 static void log_testinfo_i(const char *pattern
, ...);
101 * Log test structure, NO indent
102 * @param pattern printf pattern
104 static void log_testinfo(const char *pattern
, ...);
106 /* If we need to make the framework multi-thread safe
107 we need to pass around the following vars
109 static int ERRONEOUS_FUNCTION_COUNT
= 0;
110 static int ERROR_COUNT
= 0; /* Count of errors from all tests. */
111 static int ONE_ERROR
= 0; /* were there any other errors? */
112 static int DATA_ERROR_COUNT
= 0; /* count of data related errors or warnings */
113 static int INDENT_LEVEL
= 0;
114 static UBool NO_KNOWN
= FALSE
;
115 static void *knownList
= NULL
;
116 static char gTestName
[1024] = "";
117 static UBool ON_LINE
= FALSE
; /* are we on the top line with our test name? */
118 static UBool HANGING_OUTPUT
= FALSE
; /* did the user leave us without a trailing \n ? */
119 static int GLOBAL_PRINT_COUNT
= 0; /* global count of printouts */
120 int REPEAT_TESTS_INIT
= 0; /* Was REPEAT_TESTS initialized? */
121 int REPEAT_TESTS
= 1; /* Number of times to run the test */
122 int VERBOSITY
= 0; /* be No-verbose by default */
123 int ERR_MSG
=1; /* error messages will be displayed by default*/
124 int QUICK
= 1; /* Skip some of the slower tests? */
125 int WARN_ON_MISSING_DATA
= 0; /* Reduce data errs to warnings? */
126 UTraceLevel ICU_TRACE
= UTRACE_OFF
; /* ICU tracing level */
127 size_t MINIMUM_MEMORY_SIZE_FAILURE
= (size_t)-1; /* Minimum library memory allocation window that will fail. */
128 size_t MAXIMUM_MEMORY_SIZE_FAILURE
= (size_t)-1; /* Maximum library memory allocation window that will fail. */
129 static const char *ARGV_0
= "[ALL]";
130 static const char *XML_FILE_NAME
=NULL
;
131 static char XML_PREFIX
[256];
132 static const char *SUMMARY_FILE
= NULL
;
133 FILE *XML_FILE
= NULL
;
134 /*-------------------------------------------*/
136 /* strncmp that also makes sure there's a \0 at s2[0] */
137 static int strncmp_nullcheck( const char* s1
,
141 if (((int)strlen(s2
) >= n
) && s2
[n
] != 0) {
142 return 3; /* null check fails */
145 return strncmp ( s1
, s2
, n
);
149 static void getNextLevel( const char* name
,
151 const char** nextName
)
153 /* Get the next component of the name */
154 *nextName
= strchr(name
, TEST_SEPARATOR
);
159 *nameLen
= (int)((*nextName
) - name
);
160 (*nextName
)++; /* skip '/' */
161 strncpy(n
, name
, *nameLen
);
163 /*printf("->%s-< [%d] -> [%s]\n", name, *nameLen, *nextName);*/
166 *nameLen
= (int)strlen(name
);
170 static TestNode
*createTestNode(const char* name
, int32_t nameLen
)
174 newNode
= (TestNode
*)malloc(sizeof(TestNode
) + (nameLen
+ 1));
176 newNode
->test
= NULL
;
177 newNode
->sibling
= NULL
;
178 newNode
->child
= NULL
;
180 strncpy( newNode
->name
, name
, nameLen
);
181 newNode
->name
[nameLen
] = 0;
187 cleanUpTestTree(TestNode
*tn
)
189 if(tn
->child
!= NULL
) {
190 cleanUpTestTree(tn
->child
);
192 if(tn
->sibling
!= NULL
) {
193 cleanUpTestTree(tn
->sibling
);
202 addTest(TestNode
** root
,
203 TestFunctionPtr test
,
208 /*if this is the first Test created*/
210 *root
= createTestNode("", 0);
212 newNode
= addTestNode( *root
, name
);
213 assert(newNode
!= 0 );
214 /* printf("addTest: nreName = %s\n", newNode->name );*/
216 newNode
->test
= test
;
219 /* non recursive insert function */
220 static TestNode
*addTestNode ( TestNode
*root
, const char *name
)
222 const char* nextName
;
223 TestNode
*nextNode
, *curNode
;
224 int nameLen
; /* length of current 'name' */
226 /* remove leading slash */
227 if ( *name
== TEST_SEPARATOR
)
234 /* Start with the next child */
235 nextNode
= curNode
->child
;
237 getNextLevel ( name
, &nameLen
, &nextName
);
239 /* printf("* %s\n", name );*/
241 /* if nextNode is already null, then curNode has no children
243 if( nextNode
== NULL
)
245 /* Add all children of the node */
248 /* Get the next component of the name */
249 getNextLevel(name
, &nameLen
, &nextName
);
251 /* update curName to have the next name segment */
252 curNode
->child
= createTestNode(name
, nameLen
);
253 /* printf("*** added %s\n", curNode->child->name );*/
254 curNode
= curNode
->child
;
257 while( name
!= NULL
);
262 /* Search across for the name */
263 while (strncmp_nullcheck ( name
, nextNode
->name
, nameLen
) != 0 )
266 nextNode
= nextNode
-> sibling
;
268 if ( nextNode
== NULL
)
270 /* Did not find 'name' on this level. */
271 nextNode
= createTestNode(name
, nameLen
);
272 curNode
->sibling
= nextNode
;
277 /* nextNode matches 'name' */
279 if (nextName
== NULL
) /* end of the line */
284 /* Loop again with the next item */
291 * Log the time taken. May not output anything.
292 * @param deltaTime change in time
294 void T_CTEST_EXPORT2
str_timeDelta(char *str
, UDate deltaTime
) {
295 if (deltaTime
> 110000.0 ) {
296 double mins
= uprv_floor(deltaTime
/60000.0);
297 sprintf(str
, "[(%.0fm %.1fs)]", mins
, (deltaTime
-(mins
*60000.0))/1000.0);
298 } else if (deltaTime
> 1500.0) {
299 sprintf(str
, "((%.1fs))", deltaTime
/1000.0);
300 } else if(deltaTime
>900.0) {
301 sprintf(str
, "( %.2fs )", deltaTime
/1000.0);
302 } else if(deltaTime
> 5.0) {
303 sprintf(str
, " (%.0fms) ", deltaTime
);
305 str
[0]=0; /* at least terminate it. */
309 static void print_timeDelta(UDate deltaTime
) {
311 str_timeDelta(str
, deltaTime
);
318 * Run or list tests (according to mode) in a subtree.
320 * @param root root of the subtree to operate on
321 * @param depth The depth of this tree (0=root)
322 * @param nodeList an array of MAXTESTS depth that's used for keeping track of where we are. nodeList[depth] points to the 'parent' at depth depth.
323 * @param mode what mode we are operating in.
325 static void iterateTestsWithLevel ( const TestNode
* root
,
327 const TestNode
** nodeList
,
332 char pathToFunction
[MAXTESTNAME
] = "";
333 char separatorString
[2] = { TEST_SEPARATOR
, '\0'};
335 UDate allStartTime
= -1, allStopTime
= -1;
339 allStartTime
= uprv_getRawUTCtime();
345 /* record the current root node, and increment depth. */
346 nodeList
[depth
++] = root
;
347 /* depth is now the depth of root's children. */
349 /* Collect the 'path' to the current subtree. */
350 for ( i
=0;i
<(depth
-1);i
++ )
352 strcat(pathToFunction
, nodeList
[i
]->name
);
353 strcat(pathToFunction
, separatorString
);
355 strcat(pathToFunction
, nodeList
[i
]->name
); /* including 'root' */
357 /* print test name and space. */
358 INDENT_LEVEL
= depth
-1;
360 log_testinfo_i("%s ", root
->name
);
362 log_testinfo_i("(%s) ", ARGV_0
);
364 ON_LINE
= TRUE
; /* we are still on the line with the test name */
367 if ( (mode
== RUNTESTS
) &&
368 (root
->test
!= NULL
)) /* if root is a leaf node, run it */
370 int myERROR_COUNT
= ERROR_COUNT
;
371 int myGLOBAL_PRINT_COUNT
= GLOBAL_PRINT_COUNT
;
373 UDate startTime
, stopTime
;
375 char timeSeconds
[256];
377 const char timeDelta
[] = "(unknown)";
378 const char timeSeconds
[] = "0.000";
381 INDENT_LEVEL
= depth
; /* depth of subitems */
383 HANGING_OUTPUT
=FALSE
;
385 startTime
= uprv_getRawUTCtime();
387 strcpy(gTestName
, pathToFunction
);
388 root
->test(); /* PERFORM THE TEST ************************/
390 stopTime
= uprv_getRawUTCtime();
394 HANGING_OUTPUT
=FALSE
;
396 INDENT_LEVEL
= depth
-1; /* depth of root */
398 if((ONE_ERROR
>0)&&(ERROR_COUNT
==0)) {
399 ERROR_COUNT
++; /* There was an error without a newline */
404 str_timeDelta(timeDelta
, stopTime
-startTime
);
405 sprintf(timeSeconds
, "%f", (stopTime
-startTime
)/1000.0);
407 ctest_xml_testcase(pathToFunction
, pathToFunction
, timeSeconds
, (myERROR_COUNT
!=ERROR_COUNT
)?"error":NULL
);
409 if (myERROR_COUNT
!= ERROR_COUNT
) {
410 log_testinfo_i("} ---[%d ERRORS in %s] ", ERROR_COUNT
- myERROR_COUNT
, pathToFunction
);
411 strcpy(ERROR_LOG
[ERRONEOUS_FUNCTION_COUNT
++], pathToFunction
);
413 if(!ON_LINE
) { /* had some output */
414 int spaces
= FLAG_INDENT
-(depth
-1);
415 log_testinfo_i("} %*s[OK] ", spaces
, "---");
416 if((GLOBAL_PRINT_COUNT
-myGLOBAL_PRINT_COUNT
)>PAGE_SIZE_LIMIT
) {
417 log_testinfo(" %s ", pathToFunction
); /* in case they forgot. */
420 /* put -- out at 30 sp. */
421 int spaces
= FLAG_INDENT
-(strlen(root
->name
)+depth
);
422 if(spaces
<0) spaces
=0;
423 log_testinfo(" %*s[OK] ", spaces
,"---");
428 if(timeDelta
[0]) printf("%s", timeDelta
);
431 ON_LINE
= TRUE
; /* we are back on-line */
434 INDENT_LEVEL
= depth
-1; /* root */
436 /* we want these messages to be at 0 indent. so just push the indent level breifly. */
437 if(mode
==SHOWTESTS
) {
438 log_testinfo("---%s%c\n",pathToFunction
, nodeList
[i
]->test
?' ':TEST_SEPARATOR
);
441 INDENT_LEVEL
= depth
;
444 int myERROR_COUNT
= ERROR_COUNT
;
445 int myGLOBAL_PRINT_COUNT
= GLOBAL_PRINT_COUNT
;
446 if(mode
!=SHOWTESTS
) {
447 INDENT_LEVEL
=depth
-1;
452 iterateTestsWithLevel ( root
->child
, depth
, nodeList
, mode
);
454 if(mode
!=SHOWTESTS
) {
455 INDENT_LEVEL
=depth
-1;
456 log_testinfo_i("} "); /* TODO: summarize subtests */
457 if((depth
>1) && (ERROR_COUNT
> myERROR_COUNT
)) {
458 log_testinfo("[%d %s in %s] ", ERROR_COUNT
-myERROR_COUNT
, (ERROR_COUNT
-myERROR_COUNT
)==1?"error":"errors", pathToFunction
);
459 } else if((GLOBAL_PRINT_COUNT
-myGLOBAL_PRINT_COUNT
)>PAGE_SIZE_LIMIT
|| (depth
<1)) {
460 if(pathToFunction
[0]) {
461 log_testinfo(" %s ", pathToFunction
); /* in case they forgot. */
463 log_testinfo(" / (%s) ", ARGV_0
);
474 allStopTime
= uprv_getRawUTCtime();
475 print_timeDelta(allStopTime
-allStartTime
);
479 if(mode
!=SHOWTESTS
&& ON_LINE
) {
483 if ( depth
!= 0 ) { /* DO NOT iterate over siblings of the root. TODO: why not? */
484 iterateTestsWithLevel ( root
->sibling
, depth
, nodeList
, mode
);
491 showTests ( const TestNode
*root
)
493 /* make up one for them */
494 const TestNode
*nodeList
[MAXTESTS
];
497 log_err("TEST CAN'T BE FOUND!");
499 iterateTestsWithLevel ( root
, 0, nodeList
, SHOWTESTS
);
504 runTests ( const TestNode
*root
)
507 const TestNode
*nodeList
[MAXTESTS
];
508 /* make up one for them */
512 log_err("TEST CAN'T BE FOUND!\n");
514 ERRONEOUS_FUNCTION_COUNT
= ERROR_COUNT
= 0;
515 iterateTestsWithLevel ( root
, 0, nodeList
, RUNTESTS
);
517 /*print out result summary*/
519 ON_LINE
=FALSE
; /* just in case */
521 if(knownList
!= NULL
) {
522 if( udbg_knownIssue_print(knownList
) ) {
523 fprintf(stdout
, "(To run suppressed tests, use the -K option.) \n\n");
525 udbg_knownIssue_close(knownList
);
531 fprintf(stdout
,"\nSUMMARY:\n");
533 fprintf(stdout
,"******* [Total error count:\t%d]\n", ERROR_COUNT
);
535 fprintf(stdout
, " Errors in\n");
536 for (i
=0;i
< ERRONEOUS_FUNCTION_COUNT
; i
++)
537 fprintf(stdout
, "[%s]\n",ERROR_LOG
[i
]);
538 if(SUMMARY_FILE
!= NULL
) {
539 FILE *summf
= fopen(SUMMARY_FILE
, "w");
541 for (i
=0;i
< ERRONEOUS_FUNCTION_COUNT
; i
++)
542 fprintf(summf
, "%s\n",ERROR_LOG
[i
]);
549 log_testinfo("\n[All tests passed successfully...]\n");
552 if(DATA_ERROR_COUNT
) {
553 if(WARN_ON_MISSING_DATA
==0) {
554 log_testinfo("\t*Note* some errors are data-loading related. If the data used is not the \n"
555 "\tstock ICU data (i.e some have been added or removed), consider using\n"
556 "\tthe '-w' option to turn these errors into warnings.\n");
558 log_testinfo("\t*WARNING* some data-loading errors were ignored by the -w option.\n");
563 const char* T_CTEST_EXPORT2
566 if(currentTest
!= NULL
) {
567 return currentTest
->name
;
573 const TestNode
* T_CTEST_EXPORT2
574 getTest(const TestNode
* root
, const char* name
)
576 const char* nextName
;
578 const TestNode
* curNode
;
579 int nameLen
; /* length of current 'name' */
582 log_err("TEST CAN'T BE FOUND!\n");
585 /* remove leading slash */
586 if ( *name
== TEST_SEPARATOR
)
593 /* Start with the next child */
594 nextNode
= curNode
->child
;
596 getNextLevel ( name
, &nameLen
, &nextName
);
598 /* printf("* %s\n", name );*/
600 /* if nextNode is already null, then curNode has no children
602 if( nextNode
== NULL
)
607 /* Search across for the name */
608 while (strncmp_nullcheck ( name
, nextNode
->name
, nameLen
) != 0 )
611 nextNode
= nextNode
-> sibling
;
613 if ( nextNode
== NULL
)
615 /* Did not find 'name' on this level. */
620 /* nextNode matches 'name' */
622 if (nextName
== NULL
) /* end of the line */
627 /* Loop again with the next item */
633 /* =========== io functions ======== */
635 static void go_offline_with_marker(const char *mrk
) {
636 UBool wasON_LINE
= ON_LINE
;
639 log_testinfo(" {\n");
643 if(!HANGING_OUTPUT
|| wasON_LINE
) {
650 static void go_offline() {
651 go_offline_with_marker(NULL
);
654 static void go_offline_err() {
658 static void first_line_verbose() {
659 go_offline_with_marker("v");
662 static void first_line_err() {
663 go_offline_with_marker("!");
666 static void first_line_info() {
667 go_offline_with_marker("\"");
670 static void first_line_test() {
675 static void vlog_err(const char *prefix
, const char *pattern
, va_list ap
)
677 if( ERR_MSG
== FALSE
){
680 fputs("!", stdout
); /* col 1 - bang */
681 fprintf(stdout
, "%-*s", INDENT_LEVEL
,"" );
683 fputs(prefix
, stdout
);
685 vfprintf(stdout
, pattern
, ap
);
688 if((*pattern
==0) || (pattern
[strlen(pattern
)-1]!='\n')) {
693 GLOBAL_PRINT_COUNT
++;
696 static UBool
vlog_knownIssue(const char *ticket
, const char *pattern
, va_list ap
)
699 UBool firstForTicket
;
702 if(NO_KNOWN
) return FALSE
;
703 if(pattern
==NULL
) pattern
="";
705 vsprintf(buf
, pattern
, ap
);
706 knownList
= udbg_knownIssue_open(knownList
, ticket
, gTestName
, buf
,
707 &firstForTicket
, &firstForWhere
);
709 if(firstForTicket
|| firstForWhere
) {
710 log_info("(Known issue #%s) %s\n", ticket
, buf
);
712 log_verbose("(Known issue #%s) %s\n", ticket
, buf
);
720 vlog_info(const char *prefix
, const char *pattern
, va_list ap
)
723 fprintf(stdout
, "%-*s", INDENT_LEVEL
,"" );
725 fputs(prefix
, stdout
);
727 vfprintf(stdout
, pattern
, ap
);
730 if((*pattern
==0) || (pattern
[strlen(pattern
)-1]!='\n')) {
735 GLOBAL_PRINT_COUNT
++;
738 * Log test structure, with indent
740 static void log_testinfo_i(const char *pattern
, ...)
744 fprintf(stdout
, "%-*s", INDENT_LEVEL
,"" );
745 va_start(ap
, pattern
);
746 vfprintf(stdout
, pattern
, ap
);
749 GLOBAL_PRINT_COUNT
++;
752 * Log test structure (no ident)
754 static void log_testinfo(const char *pattern
, ...)
757 va_start(ap
, pattern
);
759 vfprintf(stdout
, pattern
, ap
);
762 GLOBAL_PRINT_COUNT
++;
766 static void vlog_verbose(const char *prefix
, const char *pattern
, va_list ap
)
768 if ( VERBOSITY
== FALSE
)
771 first_line_verbose();
772 fprintf(stdout
, "%-*s", INDENT_LEVEL
,"" );
774 fputs(prefix
, stdout
);
776 vfprintf(stdout
, pattern
, ap
);
779 GLOBAL_PRINT_COUNT
++;
780 if((*pattern
==0) || (pattern
[strlen(pattern
)-1]!='\n')) {
788 log_err(const char* pattern
, ...)
792 if(strchr(pattern
, '\n') != NULL
) {
794 * Count errors only if there is a line feed in the pattern
795 * so that we do not exaggerate our error count.
799 /* Count at least one error. */
802 va_start(ap
, pattern
);
803 vlog_err(NULL
, pattern
, ap
);
806 UBool T_CTEST_EXPORT2
807 log_knownIssue(const char *ticket
, const char *pattern
, ...) {
809 va_start(ap
, pattern
);
810 return vlog_knownIssue(ticket
, pattern
, ap
);
814 log_err_status(UErrorCode status
, const char* pattern
, ...)
817 va_start(ap
, pattern
);
819 if ((status
== U_FILE_ACCESS_ERROR
|| status
== U_MISSING_RESOURCE_ERROR
)) {
820 ++DATA_ERROR_COUNT
; /* for informational message at the end */
822 if (WARN_ON_MISSING_DATA
== 0) {
825 if (strchr(pattern
, '\n') != NULL
) {
830 vlog_err(NULL
, pattern
, ap
); /* no need for prefix in default case */
832 vlog_info("[DATA] ", pattern
, ap
);
837 if(strchr(pattern
, '\n') != NULL
) {
842 vlog_err(NULL
, pattern
, ap
); /* no need for prefix in default case */
847 log_info(const char* pattern
, ...)
851 va_start(ap
, pattern
);
852 vlog_info(NULL
, pattern
, ap
);
856 log_verbose(const char* pattern
, ...)
860 va_start(ap
, pattern
);
861 vlog_verbose(NULL
, pattern
, ap
);
866 log_data_err(const char* pattern
, ...)
869 va_start(ap
, pattern
);
872 ++DATA_ERROR_COUNT
; /* for informational message at the end */
874 if(WARN_ON_MISSING_DATA
== 0) {
876 if(strchr(pattern
, '\n') != NULL
) {
879 vlog_err(NULL
, pattern
, ap
); /* no need for prefix in default case */
881 vlog_info("[DATA] ", pattern
, ap
);
889 static int traceFnNestingDepth
= 0;
891 static void U_CALLCONV
TraceEntry(const void *context
, int32_t fnNumber
) {
893 utrace_format(buf
, sizeof(buf
), traceFnNestingDepth
*3, "%s() enter.\n", utrace_functionName(fnNumber
)); buf
[sizeof(buf
)-1]=0;
895 traceFnNestingDepth
++;
898 static void U_CALLCONV
TraceExit(const void *context
, int32_t fnNumber
, const char *fmt
, va_list args
) { char buf
[500];
900 if (traceFnNestingDepth
>0) {
901 traceFnNestingDepth
--;
903 utrace_format(buf
, sizeof(buf
), traceFnNestingDepth
*3, "%s() ", utrace_functionName(fnNumber
)); buf
[sizeof(buf
)-1]=0;
905 utrace_vformat(buf
, sizeof(buf
), traceFnNestingDepth
*3, fmt
, args
);
906 buf
[sizeof(buf
)-1]=0;
911 static void U_CALLCONV
TraceData(const void *context
, int32_t fnNumber
,
912 int32_t level
, const char *fmt
, va_list args
) {
914 utrace_vformat(buf
, sizeof(buf
), traceFnNestingDepth
*3, fmt
, args
);
915 buf
[sizeof(buf
)-1]=0;
920 static void *U_CALLCONV
ctest_libMalloc(const void *context
, size_t size
) {
922 printf("Allocated %ld\n", (long)size);
924 if (MINIMUM_MEMORY_SIZE_FAILURE
<= size
&& size
<= MAXIMUM_MEMORY_SIZE_FAILURE
) {
929 static void *U_CALLCONV
ctest_libRealloc(const void *context
, void *mem
, size_t size
) {
931 printf("Reallocated %ld\n", (long)size);
933 if (MINIMUM_MEMORY_SIZE_FAILURE
<= size
&& size
<= MAXIMUM_MEMORY_SIZE_FAILURE
) {
934 /*free(mem);*/ /* Realloc doesn't free on failure. */
937 return realloc(mem
, size
);
939 static void U_CALLCONV
ctest_libFree(const void *context
, void *mem
) {
944 initArgs( int argc
, const char* const argv
[], ArgHandlerPtr argHandler
, void *context
)
954 for( i
=1; i
<argc
; i
++)
956 if ( argv
[i
][0] == '/' )
958 /* We don't run the tests here. */
961 else if ((strcmp( argv
[i
], "-a") == 0) || (strcmp(argv
[i
],"-all") == 0))
963 /* We don't run the tests here. */
966 else if (strcmp( argv
[i
], "-v" )==0 || strcmp( argv
[i
], "-verbose")==0)
970 else if (strcmp( argv
[i
], "-l" )==0 )
974 else if (strcmp( argv
[i
], "-e1") == 0)
978 else if (strcmp( argv
[i
], "-e") ==0)
982 else if (strcmp( argv
[i
], "-K") ==0)
986 else if (strncmp( argv
[i
], "-E",2) ==0)
988 SUMMARY_FILE
=argv
[i
]+2;
990 else if (strcmp( argv
[i
], "-w") ==0)
992 WARN_ON_MISSING_DATA
= TRUE
;
994 else if (strcmp( argv
[i
], "-m") ==0)
996 UErrorCode errorCode
= U_ZERO_ERROR
;
1000 MINIMUM_MEMORY_SIZE_FAILURE
= (size_t)strtol(argv
[i
], &endPtr
, 10);
1001 if (endPtr
== argv
[i
]) {
1002 printf("Can't parse %s\n", argv
[i
]);
1006 if (*endPtr
== '-') {
1007 char *maxPtr
= endPtr
+1;
1009 MAXIMUM_MEMORY_SIZE_FAILURE
= (size_t)strtol(maxPtr
, &endPtr
, 10);
1010 if (endPtr
== argv
[i
]) {
1011 printf("Can't parse %s\n", argv
[i
]);
1017 /* Use the default value */
1018 u_setMemoryFunctions(NULL
, ctest_libMalloc
, ctest_libRealloc
, ctest_libFree
, &errorCode
);
1019 if (U_FAILURE(errorCode
)) {
1020 printf("u_setMemoryFunctions returned %s\n", u_errorName(errorCode
));
1024 else if(strcmp( argv
[i
], "-n") == 0 || strcmp( argv
[i
], "-no_err_msg") == 0)
1028 else if (strcmp( argv
[i
], "-r") == 0)
1030 if (!REPEAT_TESTS_INIT
) {
1034 else if (strcmp( argv
[i
], "-x") == 0)
1037 printf("* Error: '-x' option requires an argument. usage: '-x outfile.xml'.\n");
1040 if(ctest_xml_setFileName(argv
[i
])) { /* set the name */
1044 else if (strcmp( argv
[i
], "-t_info") == 0) {
1045 ICU_TRACE
= UTRACE_INFO
;
1047 else if (strcmp( argv
[i
], "-t_error") == 0) {
1048 ICU_TRACE
= UTRACE_ERROR
;
1050 else if (strcmp( argv
[i
], "-t_warn") == 0) {
1051 ICU_TRACE
= UTRACE_WARNING
;
1053 else if (strcmp( argv
[i
], "-t_verbose") == 0) {
1054 ICU_TRACE
= UTRACE_VERBOSE
;
1056 else if (strcmp( argv
[i
], "-t_oc") == 0) {
1057 ICU_TRACE
= UTRACE_OPEN_CLOSE
;
1059 else if (strcmp( argv
[i
], "-h" )==0 || strcmp( argv
[i
], "--help" )==0)
1064 else if (argHandler
!= NULL
&& (argSkip
= argHandler(i
, argc
, argv
, context
)) > 0)
1070 printf("* unknown option: %s\n", argv
[i
]);
1075 if (ICU_TRACE
!= UTRACE_OFF
) {
1076 utrace_setFunctions(NULL
, TraceEntry
, TraceExit
, TraceData
);
1077 utrace_setLevel(ICU_TRACE
);
1080 return 1; /* total error count */
1084 runTestRequest(const TestNode
* root
,
1086 const char* const argv
[])
1089 * This main will parse the l, v, h, n, and path arguments
1091 const TestNode
* toRun
;
1094 int subtreeOptionSeen
= FALSE
;
1100 if(ctest_xml_init(ARGV_0
)) {
1101 return 1; /* couldn't fire up XML thing */
1104 for( i
=1; i
<argc
; i
++)
1106 if ( argv
[i
][0] == '/' )
1108 printf("Selecting subtree '%s'\n", argv
[i
]);
1110 if ( argv
[i
][1] == 0 )
1113 toRun
= getTest(root
, argv
[i
]);
1115 if ( toRun
== NULL
)
1117 printf("* Could not find any matching subtree\n");
1121 ON_LINE
=FALSE
; /* just in case */
1128 ON_LINE
=FALSE
; /* just in case */
1130 errorCount
+= ERROR_COUNT
;
1132 subtreeOptionSeen
= TRUE
;
1133 } else if ((strcmp( argv
[i
], "-a") == 0) || (strcmp(argv
[i
],"-all") == 0)) {
1134 subtreeOptionSeen
=FALSE
;
1135 } else if (strcmp( argv
[i
], "-l") == 0) {
1138 /* else option already handled by initArgs */
1141 if( subtreeOptionSeen
== FALSE
) /* no other subtree given, run the default */
1143 ON_LINE
=FALSE
; /* just in case */
1148 ON_LINE
=FALSE
; /* just in case */
1150 errorCount
+= ERROR_COUNT
;
1154 if( ( doList
== FALSE
) && ( errorCount
> 0 ) )
1155 printf(" Total errors: %d\n", errorCount
);
1158 REPEAT_TESTS_INIT
= 1;
1160 if(ctest_xml_fini()) {
1164 return errorCount
; /* total error count */
1168 * Display program invocation arguments
1171 static void help ( const char *argv0
)
1173 printf("Usage: %s [ -l ] [ -v ] [ -verbose] [-a] [ -all] [-n] [ -no_err_msg]\n"
1174 " [ -h ] [-t_info | -t_error | -t_warn | -t_oc | -t_verbose] [-m n[-q] ]\n"
1175 " [ /path/to/test ]\n",
1177 printf(" -l To get a list of test names\n");
1178 printf(" -e to do exhaustive testing\n");
1179 printf(" -verbose To turn ON verbosity\n");
1180 printf(" -v To turn ON verbosity(same as -verbose)\n");
1181 printf(" -x file.xml Write junit format output to file.xml\n");
1182 printf(" -h To print this message\n");
1183 printf(" -K to turn OFF suppressing known issues\n");
1184 printf(" -n To turn OFF printing error messages\n");
1185 printf(" -w Don't fail on data-loading errs, just warn. Useful if\n"
1186 " user has reduced/changed the common set of ICU data \n");
1187 printf(" -t_info | -t_error | -t_warn | -t_oc | -t_verbose Enable ICU tracing\n");
1188 printf(" -no_err_msg (same as -n) \n");
1189 printf(" -m n[-q] Min-Max memory size that will cause an allocation failure.\n");
1190 printf(" The default is the maximum value of size_t. Max is optional.\n");
1191 printf(" -r Repeat tests after calling u_cleanup \n");
1192 printf(" [/subtest] To run a subtest \n");
1193 printf(" eg: to run just the utility tests type: cintltest /tsutil) \n");
1196 int32_t T_CTEST_EXPORT2
1197 getTestOption ( int32_t testOption
) {
1198 switch (testOption
) {
1199 case VERBOSITY_OPTION
:
1201 case WARN_ON_MISSING_DATA_OPTION
:
1202 return WARN_ON_MISSING_DATA
;
1205 case REPEAT_TESTS_OPTION
:
1206 return REPEAT_TESTS
;
1207 case ERR_MSG_OPTION
:
1209 case ICU_TRACE_OPTION
:
1216 void T_CTEST_EXPORT2
1217 setTestOption ( int32_t testOption
, int32_t value
) {
1218 if (value
== DECREMENT_OPTION_VALUE
) {
1219 value
= getTestOption(testOption
);
1222 switch (testOption
) {
1223 case VERBOSITY_OPTION
:
1226 case WARN_ON_MISSING_DATA_OPTION
:
1227 WARN_ON_MISSING_DATA
= value
;
1232 case REPEAT_TESTS_OPTION
:
1233 REPEAT_TESTS
= value
;
1235 case ICU_TRACE_OPTION
:
1236 ICU_TRACE
= (UTraceLevel
)value
;
1245 * ================== JUnit support ================================
1250 ctest_xml_setFileName(const char *name
) {
1258 ctest_xml_init(const char *rootName
) {
1259 if(!XML_FILE_NAME
) return 0;
1260 XML_FILE
= fopen(XML_FILE_NAME
,"w");
1263 fprintf(stderr
," Error: couldn't open XML output file %s\n", XML_FILE_NAME
);
1266 while(*rootName
&&!isalnum((int)*rootName
)) {
1269 strcpy(XML_PREFIX
,rootName
);
1271 char *p
= XML_PREFIX
+strlen(XML_PREFIX
);
1272 for(p
--;*p
&&p
>XML_PREFIX
&&!isalnum((int)*p
);p
--) {
1277 fprintf(XML_FILE
, "<testsuite name=\"%s\">\n", XML_PREFIX
);
1284 ctest_xml_fini(void) {
1285 if(!XML_FILE
) return 0;
1287 fprintf(XML_FILE
, "</testsuite>\n");
1289 printf(" ( test results written to %s )\n", XML_FILE_NAME
);
1297 ctest_xml_testcase(const char *classname
, const char *name
, const char *timeSeconds
, const char *failMsg
) {
1298 if(!XML_FILE
) return 0;
1300 fprintf(XML_FILE
, "\t<testcase classname=\"%s:%s\" name=\"%s:%s\" time=\"%s\"", XML_PREFIX
, classname
, XML_PREFIX
, name
, timeSeconds
);
1302 fprintf(XML_FILE
, ">\n\t\t<failure type=\"err\" message=\"%s\"/>\n\t</testcase>\n", failMsg
);
1304 fprintf(XML_FILE
, "/>\n");