/*====================================================================*\ FILE : TstError.c PURPOSE : Pro/TOOLKIT test code error reporting utilities. HISTORY.. DATE AUTHOR MODIFICATIONS DESC 26 Jan 96 Alistair $$1 Created 21 Feb 96 Michael $$2 Expl cast to int strlen - ProTestErrorlogReopen 02-Dec-96 mgs $$3 Added logging directory env 04-Nov-97 H-03-29 Pavel $$4 Added function TEST_CALL_REPORT 06-Nov-97 H-03-29 Pavel $$5 Fix message writing bug in TEST_CALL_REPORT 19-Nov-97 H-03-35 Pavel $$6 TEST_CALL_REPORT->ProTestCallReport 20-Jan-98 H-03-37 aab $$7 Fix some bugs for c++ compiler 17-Mar-98 H-03-41 Alexey $$8 Add the name of running trail file to log file 02-Jul-98 H-03-49 Misha $$9 Add default regression test name 26-Nov-98 I-01-27 Pavel $$10 Support for crash_rep 20-Feb-01 J-01-28 Senthil $$11 fflush is included after fprintf \*====================================================================*/ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include "ProToolkit.h" #include "ProArray.h" /*--------------------------------------------------------------------*\ C System includes \*--------------------------------------------------------------------*/ #include #include #include /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include "TestError.h" /*--------------------------------------------------------------------*\ Application macros \*--------------------------------------------------------------------*/ #define MAX_STAT_SIZE 38 /*--------------------------------------------------------------------*\ Application data types \*--------------------------------------------------------------------*/ typedef struct { int num; ProError status; char call[MAX_STAT_SIZE]; }TestStatistic; typedef struct { char function_name[40]; ProError permited_err_code; } PermitedErrors; /*--------------------------------------------------------------------*\ Application global/external data \*--------------------------------------------------------------------*/ static FILE *errlog_fp=NULL; static char errlog_name[PRO_PATH_SIZE]={'\0'}; TestStatistic *statistic = NULL; char trail_name[PRO_PATH_SIZE] = ""; /* The name of currently running trail file */ static PermitedErrors permited_errors[] = { {"ProMenuProcess", PRO_TK_E_FOUND}, {"ProModelitemNameGet", PRO_TK_E_NOT_FOUND}, {"ProSelect", PRO_TK_PICK_ABOVE}, {"ProSelect", PRO_TK_USER_ABORT}, {"ProSolidDisplay", PRO_TK_E_FOUND}, {"ProGraphicsColorSet", PRO_TK_NO_CHANGE}, {"ProLinestyleSet", PRO_TK_NO_CHANGE} }; /*====================================================================*\ Function : ProTestStatisticCmp() Purpose : compare two files by version \*====================================================================*/ int ProTestStatisticCmp(TestStatistic *st1, TestStatistic *st2) { int call_result; call_result = strncmp (st1->call, st2->call, MAX_STAT_SIZE); if (call_result == 0) { call_result = st1->status - st2->status; } return (call_result); } /*====================================================================*\ FUNCTION : ProTestStatisticWrite() PURPOSE : Write the specified params to the statistic file. \*====================================================================*/ int ProTestStatisticWrite (char *call, char *from, ProError status) { int i, line_num, line_found = 0; TestStatistic line; ProArraySizeGet ((ProArray)statistic, &line_num); if (errlog_fp == NULL) return (0); for (i = 0; i < line_num; i++) { if (strncmp (statistic[i].call, call, MAX_STAT_SIZE)==0) { if (statistic[i].status == status) { statistic[i].num++; line_found = 1; break; } } } if (!line_found) { strncpy (line.call, call, MAX_STAT_SIZE); if (strlen (call) >= MAX_STAT_SIZE) { line.call[MAX_STAT_SIZE-4] = '\0'; strcat (line.call, ".."); } line.status = status; line.num = 1; ProArrayObjectAdd ((ProArray*)&statistic, PRO_VALUE_UNUSED, 1, &line); if (line_num > 1) { qsort(statistic, line_num+1, sizeof(TestStatistic), (int (*)(PRO_CONST_ARG void *, PRO_CONST_ARG void *)) ProTestStatisticCmp); } } return (1); } /*====================================================================*\ FUNCTION : TEST_CALL_REPORT PURPOSE : report a Pro/TOOLKIT function call, and status, if status expression false call = name of Pro/TOOLKIT function from = name of function calling the Pro/Toolkit function status = status returned by Pro/Toolkit function error = BOOLEAN expression whether status is reportable \*====================================================================*/ void ProTestCallReport(char *call, char *from, ProError status,int error) { int i, mode; char str[100], *p_ch, line[100]; if (error) { strcpy(line, call); p_ch = strchr(line, '('); if (p_ch != NULL) *p_ch = '\0'; for (i=0; i.log" and open the file for write. \*--------------------------------------------------------------------*/ if( regtest_name == NULL ) regtest_name = default_regtest_name; dot = strchr(regtest_name, '.'); if(dot != NULL) *dot = '\0'; strcpy(errlog_name, regtest_name); strcat(errlog_name, ".log"); strcat(log_dir, errlog_name); strcpy(errlog_name, log_dir); errlog_fp = fopen(errlog_name,"a"); /*--------------------------------------------------------------------*\ Write a header \*--------------------------------------------------------------------*/ t = time(NULL); fprintf(errlog_fp, "# Pro/TOOLKIT Regression Test Log\n"); fflush(errlog_fp); fprintf(errlog_fp, "#--------------------------------\n"); fflush(errlog_fp); fprintf(errlog_fp, "# Pro/ENGINEER version : %s\n", proe_vsn); fflush(errlog_fp); fprintf(errlog_fp, "# Pro/ENGINEER build : %s\n", build); fflush(errlog_fp); fprintf(errlog_fp, "# Started at : %s", ctime((time_t*)&t)); fflush(errlog_fp); if( strlen( trail_name ) ) { fprintf(errlog_fp, "# Trail file name : %s\n", trail_name ); fflush(errlog_fp); } fprintf(errlog_fp, "#\n" ); fflush(errlog_fp); fprintf(errlog_fp, "# Pro/TOOLKIT Function Called From Status\n#\n"); fflush(errlog_fp); if (runmode == TEST_RUN_MODE_STAT) { if (statistic == NULL) { status = ProArrayAlloc (0, sizeof (TestStatistic), 10, (ProArray*)&statistic); } } return(0); } /*====================================================================*\ FUNCTION : ProTestErrlogReopen() PURPOSE : To reopen an ongoing error log file \*====================================================================*/ int ProTestErrlogReopen() { if( (int) strlen(errlog_name) > 0) errlog_fp = fopen(errlog_name,"a"); return(0); } /*====================================================================*\ FUNCTION : ProTestErrlogClose() PURPOSE : Flush and close the error log file. \*====================================================================*/ int ProTestErrlogClose() { int num, i; if(errlog_fp != NULL) { if (statistic != NULL) { ProArraySizeGet ((ProArray)statistic, &num); for (i = 0; i < num; i++) { fprintf (errlog_fp, "%-37s% -20s% -6d% -6d\n", statistic[i].call, "internal()", statistic[i].status, statistic[i].num); } ProArrayFree ((ProArray*)&statistic); } fflush(errlog_fp); fclose(errlog_fp); errlog_fp = NULL; } return(0); } /*====================================================================*\ FUNCTION : ProTestErrlogWrite() PURPOSE : Write the specified string to the error log file. \*====================================================================*/ int ProTestErrlogWrite( char *str) { if(errlog_fp == NULL) return(0); fprintf(errlog_fp, "%s", str); fflush(errlog_fp); ProTestErrlogClose(); ProTestErrlogReopen(); return(0); } /*====================================================================*\ FUNCTION : ProUtilCommandLineParse() PURPOSE : Parse the specified command line setting global params \*====================================================================*/ int ProUtilCommandLineParse( int argc, char *argv[] ) { char *p; int i; for( i=1; i