void ReadParams(THParams *HarnessParams) { GetEnvironmentParams(HarnessParams); if (HarnessParams->TestCaseDir == NULL) { HarnessError("ERROR: No test suite directory specified. Set the" " %s (or %s) environment variable to the appropriate directory.\n", ENV_DIR, ENV_DIR_ALT); } if (HarnessParams->TestConfigName == NULL) { HarnessError("ERROR: No test configuration file specified. Set the" " %s environment variable to the appropriate directory.\n", ENV_CONFIG); } if (HarnessParams->TestResultsName == NULL) { HarnessError("ERROR: No test results file specified. Set the" " %s environment variable to the appropriate directory.\n", ENV_RESULTS); } if (HarnessParams->XRunFile == NULL) { HarnessError("ERROR: The XRun application was not specified. Set the" " %s environment variable to the appropriate directory.\n", ENV_XRUN); } /* Go to the test suite directory */ if (chdir(HarnessParams->TestCaseDir) != 0) { HarnessError("ERROR: Failed to change into the directory " "specified by TH_TC_DIR. Ensure that TH_TC_DIR is correctly " "set to the root of your test suite.\n"); } /* Open the results file */ HarnessParams->TestResultsFile = fopen(HarnessParams->TestResultsName,"w"); if (HarnessParams->TestResultsFile == 0) { HarnessError("ERROR: Failed to open test results file '%s'.\n", HarnessParams->TestResultsName); } HarnessParams->sumResultsFile = fopen(HarnessParams->sumResultsName,"w"); if (HarnessParams->sumResultsFile == 0) { HarnessError("ERROR: Failed to open summary results file '%s'.\n", HarnessParams->sumResultsName); } }
void WriteSumFile(FILE *SumFile,const char* Name,const char* Section, const char* SubSection, const char *Result,double timeTaken) { int MaxSize; size_t nChars; char logBuffer[LINE_BUF_SIZE*2]; char output[256]; char *processedName; time_t ltime; struct tm *stime; char formattedDate[20]; MaxSize = sizeof(logBuffer); sprintf(output,"%d",(int)ceil(timeTaken)); time(<ime); stime = localtime(<ime); strftime(formattedDate,sizeof(formattedDate),"%Y-%m-%d",stime); ConvertBackSlashesToWindowsStyle((char *)SubSection); processedName = (char *)malloc(strlen(Name)+1); removeSpecialCharacters(Name,processedName); AppendDelimitedStringsSum(logBuffer, MaxSize, C_COMMA, C_ESCAPE, processedName,Section,SubSection,PLATFORM,BUILDTYPE,BUILDNUMBER,formattedDate,Result,output,NULL); free(processedName); // to remove the trailing commas at the end of every line in the summary file // logBuffer[MaxSize - 1] = 0; logBuffer[strlen(logBuffer)-1] = 0; RemoveLinefeeds(logBuffer); nChars = fprintf(SumFile, "%s%s", logBuffer,EOLN); if (nChars < strlen(logBuffer)+1) { HarnessError("ERROR: Failed to write to the file to log the " "results. This is a fatal error. errno is %d.\n",errno); } }
/* * Logs the result of a test case to the file in the following form: * <TestDir>,<Section>,<SubSection>,<Name>,<type>,<result>,<Output> */ void LogResult(FILE *ResultsFile, const char *Section, const char *SubSection, const char *Name, TEST_TYPE Type, const char *TestDir, const char *Phase, const char *Result, const char *Output) { int MaxSize; size_t nChars; char logBuffer[LINE_BUF_SIZE * 2]; char *testType; testType = TypeToString(Type); MaxSize = sizeof(logBuffer); if (Output == NULL) { Output = ""; } /* * Silently fail if we run out of buffer space, but throw a null in to be * safe. */ AppendDelimitedStringsVA(logBuffer, MaxSize, C_COMMA, C_ESCAPE, TestDir, Section, SubSection, Name, testType, Phase, Result, Output, NULL); logBuffer[MaxSize - 1] = 0; RemoveLinefeeds(logBuffer); nChars = fprintf(ResultsFile, "%s\n", logBuffer); if (nChars < strlen(logBuffer)+1) { HarnessError("ERROR: Failed to write to the file to log the " "results. This is a fatal error. errno is %d.\n",errno); } }
/* * Read the parameters for the testharness from the environment. */ void GetEnvironmentParams(THParams *HarnessParams) { char *envString; envString = getenv(ENV_DIR); if (envString != NULL) { HarnessParams->TestCaseDir = strdup(envString); if (HarnessParams->TestCaseDir == NULL) { HarnessError("ERROR: Unable to allocate memory!\n"); } } else { envString = getenv(ENV_DIR_ALT); if (envString != NULL) { HarnessParams->TestCaseDir = strdup(envString); if (HarnessParams->TestCaseDir == NULL) { HarnessError("ERROR: Unable to allocate memory!\n"); } } } envString = getenv(ENV_CONFIG); if (envString != NULL) { HarnessParams->TestConfigName = strdup(envString); if (HarnessParams->TestConfigName == NULL) { HarnessError("ERROR: Unable to allocate memory!\n"); } } envString = getenv(ENV_RESULTS); if (envString != NULL) { HarnessParams->TestResultsName = strdup(envString); if (HarnessParams->TestResultsName == NULL) { HarnessError("ERROR: Unable to allocate memory!\n"); } } envString = getenv(ENV_SUMRES); if (envString != NULL) { HarnessParams->sumResultsName = strdup(envString); if (HarnessParams->sumResultsName == NULL) { HarnessError("ERROR: Unable to allocate memory!\n"); } } envString = getenv(ENV_XRUN); if (envString != NULL) { HarnessParams->XRunFile = strdup(envString); if (HarnessParams->XRunFile == NULL) { HarnessError("ERROR: Unable to allocate memory!\n"); } } envString = getenv(ENV_SUBTEST); if (envString != NULL) { int subLen=0; HarnessParams->SubTest = strdup(envString); if (HarnessParams->SubTest == NULL) { HarnessError("ERROR: Unable to allocate memory!\n"); } subLen = strlen(envString); if(HarnessParams->SubTest[subLen-1]=='\\' || HarnessParams->SubTest[subLen-1]=='/') { HarnessParams->SubTest[subLen-1]='\0'; } } else { HarnessParams->SubTest=NULL; } }