bool isIntel() { std::string results; exec::execute("uname -p", results); if(stripEOL(results) == "i386") { return true; } return false; }
double runNoResultsExpected(const String &command, const char * const action) { std::string results; double duration; dt::DateTime start; exec::execute(command, results); duration= dt::DateTime() - start; if(stripEOL(results).size() != 0) { printf("unexpected %s result '%s'\n", action, results.c_str()); } return duration; }
Baseline *newBaseline(const char *confFile) { Baseline *B; FILE *in; const int NItem = 3; char buffer[NItem][MaxLineLen+1]; int i; char *v; in = fopen(confFile, "r"); if(!in) { fprintf(stderr, "Cannot open conf file %s\n", confFile); } B = (Baseline *)calloc(1, sizeof(Baseline)); B->confFile = strdup(confFile); B->ds1 = newDataStream(in); B->ds2 = newDataStream(in); if(!B->ds1 || !B->ds2) { deleteBaseline(B); fclose(in); return 0; } if(B->ds1->ms->sec != B->ds2->ms->sec || B->ds1->ms->ns != B->ds2->ms->ns) { printf("\n\n*** WARNING *** Data stream times do not match ***\n\n"); } for(i = 0; i < NItem; i++) { v = fgets(buffer[i], MaxLineLen, in); if(!v) { deleteBaseline(B); fclose(in); return 0; } stripEOL(buffer[i]); } fclose(in); if(abs(B->ds1->nChan) != abs(B->ds2->nChan)) { fprintf(stderr, "Number of channels per datastream must match (%d %d)\n", B->ds1->nChan, B->ds2->nChan); deleteBaseline(B); return 0; } B->nChan = abs(B->ds1->nChan); B->visFile = strdup(buffer[0]); B->lagFile = strdup(buffer[1]); B->nFFT = atoi(buffer[2]); if(B->nFFT <= 0) { B->nFFT = 0x7FFFFFFF; /* effectively no limit */ } B->visibility = (fftw_complex *)calloc(B->nChan, sizeof(fftw_complex)); B->lags = (fftw_complex *)calloc(B->nChan, sizeof(fftw_complex)); B->ac1 = (double *)calloc(B->nChan, sizeof(double)); B->ac2 = (double *)calloc(B->nChan, sizeof(double)); B->outVis = fopen(B->visFile, "w"); if(!B->outVis) { fprintf(stderr, "Cannot open %s for output\n", B->visFile); deleteBaseline(B); return 0; } B->outLag = fopen(B->lagFile, "w"); if(!B->outLag) { fprintf(stderr, "Cannot open %s for output\n", B->lagFile); deleteBaseline(B); return 0; } B->plan = fftw_plan_dft_1d(B->nChan, B->visibility, B->lags, FFTW_BACKWARD, FFTW_ESTIMATE); /* FIXME: check that ds1 and ds2 have same */ B->deltaF = B->ds1->deltaF; B->deltaT = 1.0/(B->nChan*B->ds1->deltaF); return B; }
DataStream *newDataStream(FILE *in) { const int NItem = 7; DataStream *ds; char buffer[NItem][MaxLineLen+1]; int i; char *v; ds = (DataStream *)calloc(1, sizeof(DataStream)); for(i = 0; i < NItem; i++) { v = fgets(buffer[i], MaxLineLen, in); if(!v) { deleteDataStream(ds); return 0; } stripEOL(buffer[i]); } ds->inputFile = strdup(buffer[0]); ds->dataFormat = strdup(buffer[1]); ds->subBand = atoi(buffer[2]); ds->offset = atoll(buffer[3]); ds->fftSize = atoi(buffer[4]); ds->startChan = atoi(buffer[5]); ds->nChan = atoi(buffer[6]); if(ds->startChan < 0 || ds->startChan > ds->fftSize/2 || (ds->nChan > 0 && (ds->startChan + ds->nChan) > ds->fftSize/2) || (ds->nChan < 0 && (ds->startChan + ds->nChan) < -1)) { printf("The start channel must be in 0 .. %d, inclusive, and\n" "the number of channels to keep must be as well:\n" "For file %s\n" "you have %d < 0 or %d > %d with %d channels to keep\n", ds->fftSize/2, ds->inputFile, ds->startChan, ds->startChan, ds->fftSize/2, ds->nChan); deleteDataStream(ds); ds = 0; return 0; } ds->ms = new_mark5_stream_absorb( new_mark5_stream_file(ds->inputFile, ds->offset), new_mark5_format_generic_from_string(ds->dataFormat) ); if(!ds->ms) { printf("problem opening %s\n", ds->inputFile); deleteDataStream(ds); ds = 0; return 0; } mark5_stream_print(ds->ms); ds->data = (double **)calloc(ds->ms->nchan, sizeof(double *)); for(i = 0; i < ds->ms->nchan; i++) { ds->data[i] = (double *)calloc(ds->fftSize+2, sizeof(double)); } ds->zdata = (fftw_complex *)calloc(ds->fftSize/2+2, sizeof(fftw_complex)); ds->spec = (fftw_complex *)calloc(abs(ds->nChan), sizeof(fftw_complex)); ds->plan = fftw_plan_dft_r2c_1d(ds->fftSize, ds->data[ds->subBand], ds->zdata, FFTW_ESTIMATE); ds->deltaF = (double)(ds->ms->samprate)/(double)(ds->fftSize); return ds; }
void runTest(const String &name, const String &compiler, uint32_t testedLines, double durationInSeconds, double totalTimeInSeconds) { std::string results; std::string command; std::string executableName; std::string logName; std::string runLogName; dt::DateTime start, end; double compilePerfTime, compileCoverageTime, runPerfTime, runCoverageTime, totalTime; uint32_t coverage; uint32_t warnings, errors, failures; bool displayNewLine= false; if(gCompilerLocations[compiler].size() == 0) { exec::execute("which "+compiler, results); if(stripEOL(results).size() == 0) { results= "-"; printf("WARNING: Unable to find compiler %s\n", compiler.c_str()); } gCompilerLocations[compiler]= results; //printf("COMPILER='%s'\n", results.c_str()); } command= gCompilerLocations[compiler]; if(command != "-") { printf("%-18s %9s about %0.3fs\n", name.c_str(), compiler.c_str(), totalTimeInSeconds); executableName= name + '_' + compiler + "_performance"; logName= executableName + "_compile.log"; runLogName= executableName + "_run.log"; command+= " -o bin/tests/"+executableName+" tests/"+name+"_test.cpp " +(gDebugging ? " -g " : "")+gCompilerFlags+" &> bin/logs/"+logName; compilePerfTime= runNoResultsExpected(command, "compile performance"); command= "bin/tests/"+executableName+" &> bin/logs/"+runLogName; runPerfTime= runNoResultsExpected(command, "run performance"); if(runPerfTime < gTestMinimumTimeInSeconds * (1.0 + gTestTimeAllowancePercent/100.0) ) { printf("\tTest is too short, run it %0.1f times\n", 1.0 / runPerfTime); } failures= runIntegerExpected("cat bin/logs/"+runLogName+" | grep FAIL | sort | uniq | wc -l"); if(failures > 0) { printf("\t%d Test Failures\n", failures); } errors= runIntegerExpected("cat bin/logs/"+logName+" | grep error: | sort | uniq | wc -l"); errors+= runIntegerExpected("cat bin/logs/"+logName+" | grep ld: | sort | uniq | wc -l"); if(errors > 0) { printf("\t%d Compile Errors\n", errors); } warnings= runIntegerExpected("cat bin/logs/"+logName+" | grep warning: | sort | uniq | wc -l"); if(warnings > 0) { printf("\t%d Compile Warnings\n", warnings); } executableName= name + '_' + compiler + "_trace"; logName= executableName + "_compile.log"; runLogName= executableName + "_run.log"; command= gCompilerLocations[compiler] + " -o bin/tests/"+executableName+" tests/"+name+"_test.cpp " +(gDebugging ? " -g " : "")+gCompilerFlags+" -include Tracer.h &> bin/logs/"+logName; compileCoverageTime= runNoResultsExpected(command, "compile trace"); command= "bin/tests/"+executableName+" &> bin/logs/"+runLogName; runCoverageTime= runNoResultsExpected(command, "run trace"); coverage= runIntegerExpected("cat bin/logs/"+runLogName+" | grep ../os/"+name+"\\\\.h: | sort | uniq | wc -l"); if( (coverage != testedLines) ) { printf("\tTested Lines: %d Expected %d\n", coverage, testedLines); displayNewLine= true; } if( (runPerfTime > durationInSeconds * (1 + gTestTimeAllowancePercent/100) ) ) { printf("\tTest took %0.3fs seconds, expected %0.3fs seconds\n", runPerfTime+0.000999, durationInSeconds); displayNewLine= true; } totalTime= compilePerfTime + compileCoverageTime + runPerfTime + runCoverageTime; if( (totalTime > totalTimeInSeconds) ) { printf("\tBuild/Test took %0.3fs seconds, expected %0.3fs seconds\n", totalTime+0.000999, totalTimeInSeconds); displayNewLine= true; } if(displayNewLine) { printf("\t%s:%d:%0.3f:%0.3f\n", compiler.c_str(), coverage, runPerfTime > durationInSeconds ? runPerfTime+0.000999 : durationInSeconds, totalTime > totalTimeInSeconds ? totalTime+0.000999 : totalTimeInSeconds ); } if(gVerbose) { printf("Coverage %d (expected %d) Compile: %0.3fs Run: %0.3fs (expected %0.3fs) Trace Compile: %0.3fs Trace Run: %0.3fs\n", coverage, testedLines, compilePerfTime, runPerfTime, durationInSeconds, compileCoverageTime, runCoverageTime ); } gCompilerTimes[name][compiler].perfCompile= compilePerfTime; gCompilerTimes[name][compiler].perfRun= runPerfTime; gCompilerTimes[name][compiler].traceCompile= compileCoverageTime; gCompilerTimes[name][compiler].traceRun= runCoverageTime; gCompilerTimes[name][compiler].testedLines= coverage; gCompilerTimes[name][compiler].warnings= warnings; } }