| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348 |
- /*=========================================================================
- Program: CMake - Cross-Platform Makefile Generator
- Module: $RCSfile$
- Language: C++
- Date: $Date$
- Version: $Revision$
- Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
- See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notices for more information.
- =========================================================================*/
- #include "cmCTest.h"
- #include "cmake.h"
- #include "cmMakefile.h"
- #include "cmLocalGenerator.h"
- #include "cmGlobalGenerator.h"
- #include <cmsys/Directory.hxx>
- #include "cmListFileCache.h"
- #include "cmCTestSubmit.h"
- #include "curl/curl.h"
- #include <cmsys/RegularExpression.hxx>
- #include <cmsys/Process.h>
- #include <cmsys/Base64.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- #include <float.h>
- #define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
- // provide some more detailed info on the return code for ctest
- #define CTEST_UPDATE_ERRORS 0x01
- #define CTEST_CONFIGURE_ERRORS 0x02
- #define CTEST_BUILD_ERRORS 0x04
- #define CTEST_TEST_ERRORS 0x08
- #define CTEST_MEMORY_ERRORS 0x10
- static struct tm* GetNightlyTime(std::string str)
- {
- struct tm* lctime;
- time_t tctime = time(0);
- //Convert the nightly start time to seconds. Since we are
- //providing only a time and a timezone, the current date of
- //the local machine is assumed. Consequently, nightlySeconds
- //is the time at which the nightly dashboard was opened or
- //will be opened on the date of the current client machine.
- //As such, this time may be in the past or in the future.
- time_t ntime = curl_getdate(str.c_str(), &tctime);
- tctime = time(0);
- //std::cout << "Seconds: " << tctime << std::endl;
- if ( ntime > tctime )
- {
- // If nightlySeconds is in the past, this is the current
- // open dashboard, then return nightlySeconds. If
- // nightlySeconds is in the future, this is the next
- // dashboard to be opened, so subtract 24 hours to get the
- // time of the current open dashboard
- ntime -= (24 * 60 * 60 );
- //std::cout << "Pick yesterday" << std::endl;
- }
- //std::cout << "nightlySeconds: " << ntime << std::endl;
- lctime = gmtime(&ntime);
- return lctime;
- }
- static std::string CleanString(std::string str)
- {
- std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
- std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
- if ( spos == str.npos )
- {
- return std::string();
- }
- if ( epos != str.npos )
- {
- epos = epos - spos + 1;
- }
- return str.substr(spos, epos);
- }
- static std::string CurrentTime()
- {
- time_t currenttime = time(0);
- struct tm* t = localtime(¤ttime);
- //return ::CleanString(ctime(¤ttime));
- char current_time[1024];
- strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
- //std::cout << "Current_Time: " << current_time << std::endl;
- return ::CleanString(current_time);
- }
- static const char* cmCTestErrorMatches[] = {
- "^[Bb]us [Ee]rror",
- "^[Ss]egmentation [Vv]iolation",
- "^[Ss]egmentation [Ff]ault",
- "([^ :]+):([0-9]+): ([^ \\t])",
- "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
- "^Error ([0-9]+):",
- "^Fatal",
- "^Error: ",
- "^Error ",
- "[0-9] ERROR: ",
- "^\"[^\"]+\", line [0-9]+: [^Ww]",
- "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
- "^ld([^:])*:([ \\t])*ERROR([^:])*:",
- "^ild:([ \\t])*\\(undefined symbol\\)",
- "([^ :]+) : (error|fatal error|catastrophic error)",
- "([^:]+): (Error:|error|undefined reference|multiply defined)",
- "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
- "^fatal error C[0-9]+:",
- ": syntax error ",
- "^collect2: ld returned 1 exit status",
- "Unsatisfied symbols:",
- "Undefined symbols:",
- "^Undefined[ \\t]+first referenced",
- "^CMake Error:",
- ":[ \\t]cannot find",
- ":[ \\t]can't find",
- ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
- ": Invalid loader fixup for symbol",
- ": internal link edit command failed",
- ": Unrecognized option \\`.*\\'",
- "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^W]\\)",
- "ld: 0706-006 Cannot find or open library file: -l ",
- 0
- };
- static const char* cmCTestErrorExceptions[] = {
- "instantiated from ",
- "candidates are:",
- ": warning",
- "makefile:",
- "Makefile:",
- ":[ \\t]+Where:",
- 0
- };
- static const char* cmCTestWarningMatches[] = {
- "([^ :]+):([0-9]+): warning:",
- "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
- "^ld([^:])*:([ \\t])*WARNING([^:])*:",
- "([^:]+): warning ([0-9]+):",
- "^\"[^\"]+\", line [0-9]+: [Ww]arning",
- "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
- "^Warning ([0-9]+):",
- "^Warning ",
- "WARNING: ",
- "([^ :]+) : warning",
- "([^:]+): warning",
- "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\(W\\)",
- 0
- };
- static const char* cmCTestWarningExceptions[] = {
- "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
- "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
- "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
- "WARNING 84 :",
- "WARNING 47 :",
- "makefile:",
- "Makefile:",
- "warning: Clock skew detected. Your build may be incomplete.",
- "/usr/openwin/include/GL/[^:]+:",
- "bind_at_load",
- "XrmQGetResource",
- "IceFlush",
- "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
- "ld32: WARNING 85: definition of dataKey in",
- "cc: warning 422: Unknown option \"\\+b\\.\" ignored",
- "_with_warning_C",
- 0
- };
- static const char* cmCTestMemCheckResultStrings[] = {
- "ABR",
- "ABW",
- "ABWL",
- "COR",
- "EXU",
- "FFM",
- "FIM",
- "FMM",
- "FMR",
- "FMW",
- "FUM",
- "IPR",
- "IPW",
- "MAF",
- "MLK",
- "MPK",
- "NPR",
- "ODS",
- "PAR",
- "PLK",
- "UMC",
- "UMR",
- 0
- };
- std::string cmCTest::MakeXMLSafe(const std::string& str)
- {
- cmOStringStream ost;
- char buffer[10];
- int lcnt = 0;
- for (std::string::size_type pos = 0; pos < str.size(); pos ++ )
- {
- unsigned char ch = str[pos];
- if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13 )
- {
- sprintf(buffer, ">%d<", (int)ch);
- //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
- ost << buffer;
- lcnt += 4;
- }
- else
- {
- switch ( ch )
- {
- case '&': ost << "&"; break;
- case '<': ost << "<"; break;
- case '>': ost << ">"; break;
- case '\n': ost << "\n"; lcnt = 0; break;
- default: ost << ch;
- }
- lcnt ++;
- }
- //if ( lcnt > 120 )
- // {
- // ost << "\n";
- // lcnt = 0;
- // }
- }
- return ost.str();
- }
- std::string cmCTest::MakeURLSafe(const std::string& str)
- {
- cmOStringStream ost;
- char buffer[10];
- for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
- {
- unsigned char ch = str[pos];
- if ( ( ch > 126 || ch < 32 ||
- ch == '&' ||
- ch == '%' ||
- ch == '+' ||
- ch == '=' ||
- ch == '@'
- ) && ch != 9 )
- {
- sprintf(buffer, "%02x;", (unsigned int)ch);
- ost << buffer;
- }
- else
- {
- ost << ch;
- }
- }
- return ost.str();
- }
- bool TryExecutable(const char *dir, const char *file,
- std::string *fullPath, const char *subdir)
- {
- // try current directory
- std::string tryPath;
- if (dir && strcmp(dir,""))
- {
- tryPath = dir;
- tryPath += "/";
- }
-
- if (subdir && strcmp(subdir,""))
- {
- tryPath += subdir;
- tryPath += "/";
- }
-
- tryPath += file;
- if(cmSystemTools::FileExists(tryPath.c_str()))
- {
- *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
- return true;
- }
- tryPath += cmSystemTools::GetExecutableExtension();
- if(cmSystemTools::FileExists(tryPath.c_str()))
- {
- *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
- return true;
- }
- return false;
- }
- cmCTest::cmCTest()
- {
- m_UseIncludeRegExp = false;
- m_UseExcludeRegExp = false;
- m_UseExcludeRegExpFirst = false;
- m_Verbose = false;
- m_DartMode = false;
- m_ShowOnly = false;
- m_RunConfigurationScript = false;
- m_TestModel = cmCTest::EXPERIMENTAL;
- m_TimeOut = 0;
- m_CompatibilityMode = 1;
- int cc;
- for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
- {
- m_Tests[cc] = 0;
- }
- }
- void cmCTest::Initialize()
- {
- m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
- cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
- // parse the dart test file
- std::ifstream fin("DartConfiguration.tcl");
- if(!fin)
- {
- return;
- }
- char buffer[1024];
- while ( fin )
- {
- buffer[0] = 0;
- fin.getline(buffer, 1023);
- buffer[1023] = 0;
- std::string line = ::CleanString(buffer);
- if(line.size() == 0)
- {
- continue;
- }
- while ( fin && (line[line.size()-1] == '\\') )
- {
- line = line.substr(0, line.size()-1);
- buffer[0] = 0;
- fin.getline(buffer, 1023);
- buffer[1023] = 0;
- line += ::CleanString(buffer);
- }
- if ( line[0] == '#' )
- {
- continue;
- }
- std::string::size_type cpos = line.find_first_of(":");
- if ( cpos == line.npos )
- {
- continue;
- }
- std::string key = line.substr(0, cpos);
- std::string value = ::CleanString(line.substr(cpos+1, line.npos));
- m_DartConfiguration[key] = value;
- }
- fin.close();
- if ( m_DartMode )
- {
- m_TimeOut = atoi(m_DartConfiguration["TimeOut"].c_str());
- std::string testingDir = m_ToplevelPath + "/Testing";
- if ( cmSystemTools::FileExists(testingDir.c_str()) )
- {
- if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
- {
- std::cerr << "File " << testingDir << " is in the place of the testing directory"
- << std::endl;
- return;
- }
- }
- else
- {
- if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
- {
- std::cerr << "Cannot create directory " << testingDir
- << std::endl;
- return;
- }
- }
- std::string tagfile = testingDir + "/TAG";
- std::ifstream tfin(tagfile.c_str());
- std::string tag;
- time_t tctime = time(0);
- struct tm *lctime = gmtime(&tctime);
- if ( tfin )
- {
- tfin >> tag;
- tfin.close();
- int year = 0;
- int mon = 0;
- int day = 0;
- int hour = 0;
- int min = 0;
- sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
- &year, &mon, &day, &hour, &min);
- if ( year != lctime->tm_year + 1900 ||
- mon != lctime->tm_mon+1 ||
- day != lctime->tm_mday )
- {
- tag = "";
- }
- }
- if ( tag.size() == 0 || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST])
- {
- //std::cout << "TestModel: " << this->GetTestModelString() << std::endl;
- //std::cout << "TestModel: " << m_TestModel << std::endl;
- if ( m_TestModel == cmCTest::NIGHTLY )
- {
- lctime = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
- }
- char datestring[100];
- sprintf(datestring, "%04d%02d%02d-%02d%02d",
- lctime->tm_year + 1900,
- lctime->tm_mon+1,
- lctime->tm_mday,
- lctime->tm_hour,
- lctime->tm_min);
- tag = datestring;
- std::ofstream ofs(tagfile.c_str());
- if ( ofs )
- {
- ofs << tag << std::endl;
- }
- ofs.close();
- std::cout << "Create new tag: " << tag << std::endl;
- }
- m_CurrentTag = tag;
- }
- }
- bool cmCTest::SetTest(const char* ttype)
- {
- if ( cmSystemTools::LowerCase(ttype) == "all" )
- {
- m_Tests[cmCTest::ALL_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "start" )
- {
- m_Tests[cmCTest::START_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "update" )
- {
- m_Tests[cmCTest::UPDATE_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "configure" )
- {
- m_Tests[cmCTest::CONFIGURE_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "build" )
- {
- m_Tests[cmCTest::BUILD_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "test" )
- {
- m_Tests[cmCTest::TEST_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
- {
- m_Tests[cmCTest::COVERAGE_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
- {
- m_Tests[cmCTest::MEMCHECK_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "notes" )
- {
- m_Tests[cmCTest::NOTES_TEST] = 1;
- }
- else if ( cmSystemTools::LowerCase(ttype) == "submit" )
- {
- m_Tests[cmCTest::SUBMIT_TEST] = 1;
- }
- else
- {
- std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
- return false;
- }
- return true;
- }
- void cmCTest::Finalize()
- {
- }
- std::string cmCTest::FindTheExecutable(const char *exe)
- {
- std::string fullPath = "";
- std::string dir;
- std::string file;
- cmSystemTools::SplitProgramPath(exe, dir, file);
- if(m_ConfigType != "" &&
- ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
- m_ConfigType.c_str()))
- {
- return fullPath;
- }
- if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
- {
- return fullPath;
- }
- if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
- {
- return fullPath;
- }
- if ( m_ConfigType == "" )
- {
- // No config type, so try to guess it
- if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
- {
- return fullPath;
- }
- if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
- {
- return fullPath;
- }
- if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
- {
- return fullPath;
- }
- if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
- {
- return fullPath;
- }
- }
- // if everything else failed, check the users path
- if (dir != "")
- {
- std::string path = cmSystemTools::FindProgram(file.c_str());
- if (path != "")
- {
- return path;
- }
- }
- if ( m_ConfigType != "" )
- {
- dir += "/";
- dir += m_ConfigType;
- dir += "/";
- dir += file;
- cmSystemTools::Error("config type specified on the command line, but test executable not found.",
- dir.c_str());
- return "";
- }
- return fullPath;
- }
- int cmCTest::UpdateDirectory()
- {
- int count = 0;
- std::string::size_type cc, kk;
- std::string cvsCommand = m_DartConfiguration["CVSCommand"];
- if ( cvsCommand.size() == 0 )
- {
- std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
- return -1;
- }
- std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
- if ( cvsOptions.size() == 0 )
- {
- std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
- return -1;
- }
- std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
- if ( sourceDirectory.size() == 0 )
- {
- std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
- return -1;
- }
- std::string extra_update_opts;
- if ( m_TestModel == cmCTest::NIGHTLY )
- {
- struct tm* t = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
- char current_time[1024];
- sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d UTC",
- t->tm_year + 1900,
- t->tm_mon + 1,
- t->tm_mday,
- t->tm_hour,
- t->tm_min,
- t->tm_sec);
- std::string today_update_date = current_time;
-
- extra_update_opts += "-D \"" + today_update_date +"\"";
- //std::cout << "Update: " << extra_update_opts << std::endl;
- }
- std::string command = cvsCommand + " -z3 update " + cvsOptions +
- " " + extra_update_opts;
- std::ofstream os;
- if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
- {
- std::cerr << "Cannot open log file" << std::endl;
- }
- std::string start_time = ::CurrentTime();
-
- std::string goutput;
- int retVal = 0;
- bool res = true;
- std::ofstream ofs;
- if ( !m_ShowOnly )
- {
- res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
- &retVal, sourceDirectory.c_str(),
- m_Verbose, 0 /*m_TimeOut*/);
- if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
- {
- ofs << goutput << std::endl;;
- }
- }
- else
- {
- std::cout << "Update with command: " << command << std::endl;
- }
- os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- << "<Update mode=\"Client\">\n"
- << "\t<Site>" <<m_DartConfiguration["Site"] << "</Site>\n"
- << "\t<BuildName>" << m_DartConfiguration["BuildName"]
- << "</BuildName>\n"
- << "\t<BuildStamp>" << m_CurrentTag << "-"
- << this->GetTestModelString() << "</BuildStamp>" << std::endl;
- os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
- << "\t<UpdateCommand>" << command << "</UpdateCommand>\n"
- << "\t<UpdateReturnStatus>";
- if ( retVal )
- {
- os << goutput;
- }
- os << "</UpdateReturnStatus>" << std::endl;
- std::vector<cmStdString> lines;
- cmSystemTools::Split(goutput.c_str(), lines);
- std::cout << "Updated; gathering version information" << std::endl;
- cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
- cmsys::RegularExpression revision("^revision +([^ ]*) *$");
- cmsys::RegularExpression end_of_file("^=============================================================================$");
- cmsys::RegularExpression end_of_comment("^----------------------------$");
- std::string current_path = "";
- bool first_file = true;
- cmCTest::AuthorsToUpdatesMap authors_files_map;
- int num_updated = 0;
- int num_modified = 0;
- int num_conflicting = 0;
- for ( cc= 0 ; cc < lines.size(); cc ++ )
- {
- const char* line = lines[cc].c_str();
- char mod = line[0];
- if ( line[1] == ' ' && mod != '?' )
- {
- count ++;
- const char* file = line + 2;
- //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
- std::string logcommand = cvsCommand + " -z3 log -N " + file;
- //std::cout << "Do log: " << logcommand << std::endl;
- std::string output;
- res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
- &retVal, sourceDirectory.c_str(),
- m_Verbose, 0 /*m_TimeOut*/);
- if ( ofs )
- {
- ofs << output << std::endl;
- }
- if ( res && retVal == 0)
- {
- //std::cout << output << std::endl;
- std::vector<cmStdString> ulines;
- cmSystemTools::Split(output.c_str(), ulines);
- std::string::size_type sline = 0;
- std::string srevision1 = "Unknown";
- std::string sdate1 = "Unknown";
- std::string sauthor1 = "Unknown";
- std::string semail1 = "Unknown";
- std::string comment1 = "";
- std::string srevision2 = "Unknown";
- std::string sdate2 = "Unknown";
- std::string sauthor2 = "Unknown";
- std::string comment2 = "";
- std::string semail2 = "Unknown";
- bool have_first = false;
- bool have_second = false;
- for ( kk = 0; kk < ulines.size(); kk ++ )
- {
- const char* clp = ulines[kk].c_str();
- if ( !have_second && !sline && revision.find(clp) )
- {
- if ( !have_first )
- {
- srevision1 = revision.match(1);
- }
- else
- {
- srevision2 = revision.match(1);
- }
- }
- else if ( !have_second && !sline && date_author.find(clp) )
- {
- sline = kk + 1;
- if ( !have_first )
- {
- sdate1 = date_author.match(1);
- sauthor1 = date_author.match(2);
- }
- else
- {
- sdate2 = date_author.match(1);
- sauthor2 = date_author.match(2);
- }
- }
- else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
- {
- if ( !have_first )
- {
- have_first = true;
- }
- else if ( !have_second )
- {
- have_second = true;
- }
- sline = 0;
- }
- else if ( sline )
- {
- if ( !have_first )
- {
- comment1 += clp;
- comment1 += "\n";
- }
- else
- {
- comment2 += clp;
- comment2 += "\n";
- }
- }
- }
- if ( mod == 'M' )
- {
- comment1 = "Locally modified file\n";
- }
- if ( mod == 'C' )
- {
- comment1 = "Conflict while updating\n";
- }
- std::string path = cmSystemTools::GetFilenamePath(file);
- std::string fname = cmSystemTools::GetFilenameName(file);
- if ( path != current_path )
- {
- if ( !first_file )
- {
- os << "\t</Directory>" << std::endl;
- }
- else
- {
- first_file = false;
- }
- os << "\t<Directory>\n"
- << "\t\t<Name>" << path << "</Name>" << std::endl;
- }
- if ( mod == 'C' )
- {
- num_conflicting ++;
- os << "\t<Conflicting>" << std::endl;
- }
- else if ( mod == 'M' )
- {
- num_modified ++;
- os << "\t<Modified>" << std::endl;
- }
- else
- {
- num_updated ++;
- os << "\t<Updated>" << std::endl;
- }
- if ( srevision2 == "Unknown" )
- {
- srevision2 = srevision1;
- }
- os << "\t\t<File Directory=\"" << path << "\">" << fname
- << "</File>\n"
- << "\t\t<Directory>" << path << "</Directory>\n"
- << "\t\t<FullName>" << file << "</FullName>\n"
- << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
- << "\t\t<Author>" << sauthor1 << "</Author>\n"
- << "\t\t<Email>" << semail1 << "</Email>\n"
- << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
- << "\t\t<Revision>" << srevision1 << "</Revision>\n"
- << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
- << std::endl;
- if ( srevision2 != srevision1 )
- {
- os
- << "\t\t<Revisions>\n"
- << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
- << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
- << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
- << "\t\t\t<Date>" << sdate1 << "</Date>\n"
- << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
- << "\t\t\t<Email>" << semail1 << "</Email>\n"
- << "\t\t</Revisions>\n"
- << "\t\t<Revisions>\n"
- << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
- << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
- << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
- << "\t\t\t<Date>" << sdate2 << "</Date>\n"
- << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
- << "\t\t\t<Email>" << semail2 << "</Email>\n"
- << "\t\t</Revisions>" << std::endl;
- }
- if ( mod == 'C' )
- {
- os << "\t</Conflicting>" << std::endl;
- }
- else if ( mod == 'M' )
- {
- os << "\t</Modified>" << std::endl;
- }
- else
- {
- os << "\t</Updated>" << std::endl;
- }
- cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
- cmCTest::StringPair p;
- p.first = path;
- p.second = fname;
- u->push_back(p);
- current_path = path;
- }
- }
- }
- if ( num_updated )
- {
- std::cout << "Found " << num_updated << " updated files" << std::endl;
- }
- if ( num_modified )
- {
- std::cout << "Found " << num_modified << " locally modified files"
- << std::endl;
- }
- if ( num_conflicting )
- {
- std::cout << "Found " << num_conflicting << " conflicting files"
- << std::endl;
- }
- if ( !first_file )
- {
- os << "\t</Directory>" << std::endl;
- }
-
- cmCTest::AuthorsToUpdatesMap::iterator it;
- for ( it = authors_files_map.begin();
- it != authors_files_map.end();
- it ++ )
- {
- os << "\t<Author>\n"
- << "\t\t<Name>" << it->first << "</Name>" << std::endl;
- cmCTest::UpdateFiles *u = &(it->second);
- for ( cc = 0; cc < u->size(); cc ++ )
- {
- os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
- << (*u)[cc].second << "</File>" << std::endl;
- }
- os << "\t</Author>" << std::endl;
- }
-
- //std::cout << "End" << std::endl;
- std::string end_time = ::CurrentTime();
- os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
- << "</Update>" << std::endl;
- if ( ofs )
- {
- ofs.close();
- }
- if (! res || retVal )
- {
- std::cerr << "Error(s) when updating the project" << std::endl;
- std::cerr << "Output: " << goutput << std::endl;
- return -1;
- }
- return count;
- }
- int cmCTest::ConfigureDirectory()
- {
- std::cout << "Configure project" << std::endl;
- std::string cCommand = m_DartConfiguration["ConfigureCommand"];
- if ( cCommand.size() == 0 )
- {
- std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
- << std::endl;
- return 1;
- }
- std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
- if ( buildDirectory.size() == 0 )
- {
- std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
- return 1;
- }
- std::string output;
- int retVal = 0;
- int res = 0;
- if ( !m_ShowOnly )
- {
- std::ofstream os;
- if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
- {
- std::cerr << "Cannot open configure file" << std::endl;
- return 1;
- }
- std::string start_time = ::CurrentTime();
- std::ofstream ofs;
- this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
- res = this->RunMakeCommand(cCommand.c_str(), &output,
- &retVal, buildDirectory.c_str(),
- m_Verbose, 0, ofs);
- if ( ofs )
- {
- ofs.close();
- }
-
- if ( os )
- {
- this->StartXML(os);
- os << "<Configure>\n"
- << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
- if ( res == cmsysProcess_State_Exited && retVal )
- {
- os << retVal;
- }
- os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
- //std::cout << "End" << std::endl;
- os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
- std::string end_time = ::CurrentTime();
- os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
- << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
- << "</Configure>" << std::endl;
- this->EndXML(os);
- }
- }
- else
- {
- std::cout << "Configure with command: " << cCommand << std::endl;
- }
- if (! res || retVal )
- {
- std::cerr << "Error(s) when updating the project" << std::endl;
- return 1;
- }
- return 0;
- }
- int cmCTest::BuildDirectory()
- {
- std::cout << "Build project" << std::endl;
- std::string makeCommand = m_DartConfiguration["MakeCommand"];
- if ( makeCommand.size() == 0 )
- {
- std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
- return 1;
- }
- std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
- if ( buildDirectory.size() == 0 )
- {
- std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
- return 1;
- }
- std::ofstream ofs;
- if ( !this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
- {
- std::cerr << "Cannot create LastBuild.log file" << std::endl;
- }
- m_StartBuild = ::CurrentTime();
- std::string output;
- int retVal = 0;
- int res = cmsysProcess_State_Exited;
- if ( !m_ShowOnly )
- {
- res = this->RunMakeCommand(makeCommand.c_str(), &output,
- &retVal, buildDirectory.c_str(),
- m_Verbose, 0, ofs);
- }
- else
- {
- std::cout << "Build with command: " << makeCommand << std::endl;
- }
- m_EndBuild = ::CurrentTime();
- if (res != cmsysProcess_State_Exited || retVal )
- {
- std::cerr << "Error(s) when building project" << std::endl;
- }
- if ( ofs )
- {
- ofs.close();
- }
- int cc;
- if ( m_DartConfiguration["SourceDirectory"].size() > 20 ||
- m_DartConfiguration["BuildDirectory"].size() > 20 )
- {
- std::string srcdir = m_DartConfiguration["SourceDirectory"] + "/";
- std::string bindir = m_DartConfiguration["BuildDirectory"] + "/";
- std::string srcdirrep;
- std::string bindirrep;
- for ( cc = srcdir.size()-2; cc > 0; cc -- )
- {
- if ( srcdir[cc] == '/' )
- {
- srcdirrep = srcdir.c_str() + cc;
- srcdirrep = "/..." + srcdirrep;
- srcdir = srcdir.substr(0, cc+1);
- break;
- }
- }
- for ( cc = bindir.size()-2; cc > 0; cc -- )
- {
- if ( bindir[cc] == '/' )
- {
- bindirrep = bindir.c_str() + cc;
- bindirrep = "/..." + bindirrep;
- bindir = bindir.substr(0, cc+1);
- break;
- }
- }
- cmSystemTools::ReplaceString(output, srcdir.c_str(), "/.../"); //srcdirrep.c_str());
- cmSystemTools::ReplaceString(output, bindir.c_str(), "/.../"); //bindirrep.c_str());
- }
- // Parsing of output for errors and warnings.
- std::vector<cmStdString> lines;
- cmSystemTools::Split(output.c_str(), lines);
-
- // Lines are marked:
- // 0 - nothing
- // 1 - error
- // > 1 - warning
- std::vector<int> markedLines(lines.size(), 0);
-
- // Errors
- for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
- {
- cmsys::RegularExpression re(cmCTestErrorMatches[cc]);
- cmCTest::tm_VectorOfStrings::size_type kk;
- for ( kk = 0; kk < lines.size(); kk ++ )
- {
- if ( re.find(lines[kk]) )
- {
- markedLines[kk] = 1;
- }
- }
- }
- // Warnings
- for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
- {
- cmsys::RegularExpression re(cmCTestWarningMatches[cc]);
- cmCTest::tm_VectorOfStrings::size_type kk;
- for ( kk = 0; kk < lines.size(); kk ++ )
- {
- if ( re.find(lines[kk]) )
- {
- markedLines[kk] += 2;
- }
- }
- }
- // Errors exceptions
- for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
- {
- cmsys::RegularExpression re(cmCTestErrorExceptions[cc]);
- std::vector<int>::size_type kk;
- for ( kk =0; kk < markedLines.size(); kk ++ )
- {
- if ( markedLines[kk] == 1 )
- {
- if ( re.find(lines[kk]) )
- {
- markedLines[kk] = 0;
- }
- }
- }
- }
- // Warning exceptions
- for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
- {
- cmsys::RegularExpression re(cmCTestWarningExceptions[cc]);
- std::vector<int>::size_type kk;
- for ( kk =0; kk < markedLines.size(); kk ++ )
- {
- if ( markedLines[kk] > 1 )
- {
- if ( re.find(lines[kk]) )
- {
- markedLines[kk] = 0;
- }
- }
- }
- }
- std::vector<cmCTestBuildErrorWarning> errorsWarnings;
- int errors = 0;
- int warnings = 0;
- std::vector<int>::size_type kk;
- cmCTestBuildErrorWarning errorwarning;
- for ( kk =0; kk < markedLines.size(); kk ++ )
- {
- errorwarning.m_LineNumber = -1;
- bool found = false;
- if ( markedLines[kk] == 1 )
- {
- //std::cout << "Error: " << lines[kk] << std::endl;
- errorwarning.m_Error = true;
- found = true;
- }
- else if ( markedLines[kk] > 1 )
- {
- //std::cout << "Warning: " << lines[kk] << std::endl;
- errorwarning.m_Error = false;
- found = true;
- }
- if ( found )
- {
- errorwarning.m_LogLine = static_cast<int>(kk+1);
- errorwarning.m_Text = lines[kk];
- errorwarning.m_PreContext = "";
- errorwarning.m_PostContext = "";
- std::vector<int>::size_type jj;
- std::vector<int>::size_type ll = 0;
- if ( kk > 6 )
- {
- ll = kk - 6;
- }
- for ( jj = kk;
- jj > 0 && jj > ll /* && markedLines[jj] == 0 */;
- jj -- );
- for (; jj < kk; jj ++ )
- {
- errorwarning.m_PreContext += lines[jj] + "\n";
- }
- for ( jj = kk+1;
- jj < lines.size() && jj < kk + 7 /* && markedLines[jj] == 0*/;
- jj ++ )
- {
- errorwarning.m_PostContext += lines[jj] + "\n";
- }
- errorsWarnings.push_back(errorwarning);
- if ( errorwarning.m_Error )
- {
- errors ++;
- }
- else
- {
- warnings ++;
- }
- }
- }
- std::cout << " " << errors << " Compiler errors" << std::endl;
- std::cout << " " << warnings << " Compiler warnings" << std::endl;
- if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
- {
- std::cerr << "Cannot create build XML file" << std::endl;
- return 1;
- }
- this->GenerateDartBuildOutput(ofs, errorsWarnings);
- return 0;
- }
-
- int cmCTest::CoverageDirectory()
- {
- std::cout << "Performing coverage" << std::endl;
- cmCTest::tm_VectorOfStrings files;
- cmCTest::tm_VectorOfStrings cfiles;
- cmCTest::tm_VectorOfStrings cdirs;
- bool done = false;
- std::string::size_type cc;
- std::string glob;
- std::map<std::string, std::string> allsourcefiles;
- std::map<std::string, std::string> allbinaryfiles;
- std::string start_time = ::CurrentTime();
- // Find all source files.
- std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
- if ( sourceDirectory.size() == 0 )
- {
- std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
- return 1;
- }
- std::string coverageCommand = m_DartConfiguration["CoverageCommand"];
- if ( coverageCommand.size() == 0 )
- {
- std::cerr << "Coverage command not defined in DartConfiguration.tcl" << std::endl;
- return 1;
- }
- cdirs.push_back(sourceDirectory);
- while ( !done )
- {
- if ( cdirs.size() <= 0 )
- {
- break;
- }
- glob = cdirs[cdirs.size()-1] + "/*";
- //std::cout << "Glob: " << glob << std::endl;
- cdirs.pop_back();
- if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
- {
- for ( cc = 0; cc < cfiles.size(); cc ++ )
- {
- allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
- }
- }
- if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
- {
- for ( cc = 0; cc < cfiles.size(); cc ++ )
- {
- if ( cfiles[cc] != "." && cfiles[cc] != ".." )
- {
- cdirs.push_back(cfiles[cc]);
- }
- }
- }
- }
- // find all binary files
- cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
- while ( !done )
- {
- if ( cdirs.size() <= 0 )
- {
- break;
- }
- glob = cdirs[cdirs.size()-1] + "/*";
- //std::cout << "Glob: " << glob << std::endl;
- cdirs.pop_back();
- if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
- {
- for ( cc = 0; cc < cfiles.size(); cc ++ )
- {
- allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
- }
- }
- if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
- {
- for ( cc = 0; cc < cfiles.size(); cc ++ )
- {
- if ( cfiles[cc] != "." && cfiles[cc] != ".." )
- {
- cdirs.push_back(cfiles[cc]);
- }
- }
- }
- }
- std::map<std::string, std::string>::iterator sit;
- for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
- {
- const std::string& fname = sit->second;
- //std::cout << "File: " << fname << std::endl;
- if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
- {
- files.push_back(fname);
- }
- }
-
- if ( files.size() == 0 )
- {
- std::cerr << "Cannot find any coverage information files (.da)" << std::endl;
- return 1;
- }
- std::ofstream log;
- if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
- {
- std::cerr << "Cannot open log file" << std::endl;
- return 1;
- }
- log.close();
- if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
- {
- std::cerr << "Cannot open log file" << std::endl;
- return 1;
- }
- std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
- cmSystemTools::MakeDirectory(opath.c_str());
- for ( cc = 0; cc < files.size(); cc ++ )
- {
- std::string command = coverageCommand + " -o \"" +
- cmSystemTools::GetFilenamePath(files[cc]) +
- "\" -l \"" + files[cc] + "\"";
- std::string output;
- int retVal = 0;
- //std::cout << "Run gcov on " << files[cc] << std::flush;
- //std::cout << " --- Run [" << command << "]" << std::endl;
- bool res = true;
- if ( !m_ShowOnly )
- {
- res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
- &retVal, opath.c_str(),
- m_Verbose, 0 /*m_TimeOut*/);
- }
- if ( res && retVal == 0 )
- {
- //std::cout << " - done" << std::endl;
- }
- else
- {
- std::cerr << "Run gcov on " << files[cc] << std::flush;
- std::cerr << " [" << command << "]" << std::endl;
- std::cerr << " - fail" << std::endl;
- }
- }
-
- files.clear();
- glob = opath + "/*";
- if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
- {
- std::cerr << "Cannot found any coverage files" << std::endl;
- return 1;
- }
- std::map<std::string, cmCTest::tm_VectorOfStrings > sourcefiles;
- for ( cc = 0; cc < cfiles.size(); cc ++ )
- {
- std::string& fname = cfiles[cc];
- // std::cout << "File: " << fname << std::endl;
- if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
- {
- files.push_back(fname);
- std::string::size_type pos = fname.find(".da.");
- std::string::size_type pos2 = fname.find(".da##");
- if(pos2 != fname.npos)
- {
- pos = pos2+1;
- }
- if ( pos != fname.npos )
- {
- pos += 4;
- std::string::size_type epos = fname.size() - pos - strlen(".gcov");
- std::string nf = fname.substr(pos, epos);
- //std::cout << "Substring: " << nf << std::endl;
- if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
- allbinaryfiles.find(nf) != allbinaryfiles.end() )
- {
- cmCTest::tm_VectorOfStrings &cvec = sourcefiles[nf];
- cvec.push_back(fname);
- }
- }
- }
- }
- // for ( cc = 0; cc < files.size(); cc ++ )
- // {
- // std::cout << "File: " << files[cc] << std::endl;
- // }
- std::map<std::string, cmCTest::tm_VectorOfStrings >::iterator it;
- cmCTest::tm_CoverageMap coverageresults;
- this->StartXML(log);
- log << "<Coverage>\n"
- << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
- int total_tested = 0;
- int total_untested = 0;
- for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
- {
- //std::cerr << "Source file: " << it->first << std::endl;
- cmCTest::tm_VectorOfStrings &gfiles = it->second;
- for ( cc = 0; cc < gfiles.size(); cc ++ )
- {
- //std::cout << "\t" << gfiles[cc] << std::endl;
- std::ifstream ifile(gfiles[cc].c_str());
- if ( !ifile )
- {
- std::cerr << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
- }
- ifile.seekg (0, std::ios::end);
- int length = ifile.tellg();
- ifile.seekg (0, std::ios::beg);
- char *buffer = new char [ length + 1 ];
- ifile.read(buffer, length);
- buffer [length] = 0;
- //std::cout << "Read: " << buffer << std::endl;
- std::vector<cmStdString> lines;
- cmSystemTools::Split(buffer, lines);
- delete [] buffer;
- cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
- std::vector<int>& covlines = cov.m_Lines;
- if ( cov.m_FullPath == "" )
- {
- covlines.insert(covlines.begin(), lines.size(), -1);
- if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
- {
- cov.m_FullPath = allsourcefiles[it->first];
- }
- else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
- {
- cov.m_FullPath = allbinaryfiles[it->first];
- }
- cov.m_AbsolutePath = cov.m_FullPath;
- std::string src_dir = m_DartConfiguration["SourceDirectory"];
- if ( src_dir[src_dir.size()-1] != '/' )
- {
- src_dir = src_dir + "/";
- }
- std::string::size_type spos = cov.m_FullPath.find(src_dir);
- if ( spos == 0 )
- {
- cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
- }
- else
- {
- //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
- //std::cerr << " -- " << src_dir << std::endl;
- cov.m_Show = false;
- continue;
- }
- cov.m_Show = true;
- }
- std::string::size_type kk;
- // std::cerr << "number of lines " << lines.size() << "\n";
- for ( kk = 0; kk < lines.size(); kk ++ )
- {
- std::string& line = lines[kk];
- //std::cerr << line << "\n";
- std::string sub1 = line.substr(0, strlen(" #####"));
- std::string sub2 = line.substr(0, strlen(" ######"));
- int count = atoi(sub2.c_str());
- if ( sub1.compare(" #####") == 0 ||
- sub2.compare(" ######") == 0 )
- {
- if ( covlines[kk] == -1 )
- {
- covlines[kk] = 0;
- }
- cov.m_UnTested ++;
- //std::cout << "Untested - ";
- }
- else if ( count > 0 )
- {
- if ( covlines[kk] == -1 )
- {
- covlines[kk] = 0;
- }
- cov.m_Tested ++;
- covlines[kk] ++;
- //std::cout << "Tested[" << count << "] - ";
- }
- //std::cout << line << std::endl;
- }
- }
- }
- //std::cerr << "Finalizing" << std::endl;
- cmCTest::tm_CoverageMap::iterator cit;
- int ccount = 0;
- std::ofstream cfileoutput;
- int cfileoutputcount = 0;
- char cfileoutputname[100];
- std::string local_start_time = ::CurrentTime();
- std::string local_end_time;
- for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
- {
- cmCTest::cmCTestCoverage &cov = cit->second;
- if ( !cov.m_Show )
- {
- continue;
- }
- // Check if we should ignore the directory
- std::string coverage_dir = cmSystemTools::GetFilenamePath(cov.m_AbsolutePath.c_str());
- coverage_dir += "/.NoDartCoverage";
- if ( cmSystemTools::FileExists(coverage_dir.c_str()) )
- {
- if ( m_Verbose )
- {
- std::cout << "Ignore file: " << cov.m_FullPath.c_str() << std::endl;
- }
- continue;
- }
- if ( ccount == 100 )
- {
- local_end_time = ::CurrentTime();
- cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
- << "</CoverageLog>" << std::endl;
- this->EndXML(cfileoutput);
- cfileoutput.close();
- std::cout << "Close file: " << cfileoutputname << std::endl;
- ccount = 0;
- }
- if ( ccount == 0 )
- {
- sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
- std::cout << "Open file: " << cfileoutputname << std::endl;
- if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
- {
- std::cerr << "Cannot open log file: " << cfileoutputname << std::endl;
- return 1;
- }
- local_start_time = ::CurrentTime();
- this->StartXML(cfileoutput);
- cfileoutput << "<CoverageLog>\n"
- << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
- }
- //std::cerr << "Final process of Source file: " << cit->first << std::endl;
- cov.m_UnTested = 0;
- cov.m_Tested = 0;
- for ( cc = 0; cc < cov.m_Lines.size(); cc ++ )
- {
- if ( cov.m_Lines[cc] == 0 )
- {
- cov.m_UnTested ++;
- }
- else if ( cov.m_Lines[cc] > 0 )
- {
- cov.m_Tested ++;
- }
- }
- std::ifstream ifile(cov.m_AbsolutePath.c_str());
- if ( !ifile )
- {
- std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
- }
- ifile.seekg (0, std::ios::end);
- int length = ifile.tellg();
- ifile.seekg (0, std::ios::beg);
- char *buffer = new char [ length + 1 ];
- ifile.read(buffer, length);
- buffer [length] = 0;
- //std::cout << "Read: " << buffer << std::endl;
- std::vector<cmStdString> lines;
- cmSystemTools::Split(buffer, lines);
- delete [] buffer;
- cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
- << cov.m_FullPath << "\">\n"
- << "\t\t<Report>" << std::endl;
- for ( cc = 0; cc < lines.size(); cc ++ )
- {
- cfileoutput << "\t\t<Line Number=\""
- << static_cast<int>(cc) << "\" Count=\""
- << cov.m_Lines[cc] << "\">"
- << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
- }
- cfileoutput << "\t\t</Report>\n"
- << "\t</File>" << std::endl;
- total_tested += cov.m_Tested;
- total_untested += cov.m_UnTested;
- float cper = 0;
- float cmet = 0;
- if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
- {
- cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
- static_cast<float>(cov.m_Tested + cov.m_UnTested)));
- cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
- static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
- }
- log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
- << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
- << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
- << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
- << "\t\t<PercentCoverage>";
- log.setf(std::ios::fixed, std::ios::floatfield);
- log.precision(2);
- log << (cper) << "</PercentCoverage>\n"
- << "\t\t<CoverageMetric>";
- log.setf(std::ios::fixed, std::ios::floatfield);
- log.precision(2);
- log << (cmet) << "</CoverageMetric>\n"
- << "\t</File>" << std::endl;
- ccount ++;
- }
-
- if ( ccount > 0 )
- {
- local_end_time = ::CurrentTime();
- cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
- << "</CoverageLog>" << std::endl;
- this->EndXML(cfileoutput);
- cfileoutput.close();
- }
- int total_lines = total_tested + total_untested;
- float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
- static_cast<float>(total_lines));
- if ( total_lines == 0 )
- {
- percent_coverage = 0;
- }
- std::string end_time = ::CurrentTime();
- log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
- << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
- << "\t<LOC>" << total_lines << "</LOC>\n"
- << "\t<PercentCoverage>";
- log.setf(std::ios::fixed, std::ios::floatfield);
- log.precision(2);
- log << (percent_coverage)<< "</PercentCoverage>\n"
- << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
- << "</Coverage>" << std::endl;
- this->EndXML(log);
- std::cout << "\tCovered LOC: " << total_tested << std::endl
- << "\tNot covered LOC: " << total_untested << std::endl
- << "\tTotal LOC: " << total_lines << std::endl
- << "\tPercentage Coverage: ";
- std::cout.setf(std::ios::fixed, std::ios::floatfield);
- std::cout.precision(2);
- std::cout << (percent_coverage) << "%" << std::endl;
- return 1;
- }
- bool cmCTest::OpenOutputFile(const std::string& path,
- const std::string& name, std::ofstream& stream)
- {
- std::string testingDir = m_ToplevelPath + "/Testing";
- if ( path.size() > 0 )
- {
- testingDir += "/" + path;
- }
- if ( cmSystemTools::FileExists(testingDir.c_str()) )
- {
- if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
- {
- std::cerr << "File " << testingDir
- << " is in the place of the testing directory"
- << std::endl;
- return false;
- }
- }
- else
- {
- if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
- {
- std::cerr << "Cannot create directory " << testingDir
- << std::endl;
- return false;
- }
- }
- std::string filename = testingDir + "/" + name;
- stream.open(filename.c_str());
- if( !stream )
- {
- std::cerr << "Problem opening file: " << filename << std::endl;
- return false;
- }
- return true;
- }
- void cmCTest::GenerateDartBuildOutput(std::ostream& os,
- std::vector<cmCTestBuildErrorWarning> ew)
- {
- this->StartXML(os);
- os << "<Build>\n"
- << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
- << "<BuildCommand>"
- << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
- << "</BuildCommand>" << std::endl;
-
- std::vector<cmCTestBuildErrorWarning>::iterator it;
- for ( it = ew.begin(); it != ew.end(); it++ )
- {
- cmCTestBuildErrorWarning *cm = &(*it);
- os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
- << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
- << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
- << "\n</Text>" << std::endl;
- if ( cm->m_SourceFile.size() > 0 )
- {
- os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
- << std::endl;
- }
- if ( cm->m_SourceFileTail.size() > 0 )
- {
- os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
- << "</SourceFileTail>" << std::endl;
- }
- if ( cm->m_LineNumber >= 0 )
- {
- os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
- << "</SourceLineNumber>" << std::endl;
- }
- os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
- << "</PreContext>\n"
- << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
- << "</PostContext>\n"
- << "\t\t<RepeatCount>0</RepeatCount>\n"
- << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
- << std::endl;
- }
- os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
- << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
- << "</Build>" << std::endl;
- this->EndXML(os);
- }
-
- void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
- cmCTest::tm_VectorOfStrings &failed,
- bool memcheck)
- {
- // does the DartTestfile.txt exist ?
- if(!cmSystemTools::FileExists("DartTestfile.txt"))
- {
- return;
- }
-
- // parse the file
- std::ifstream fin("DartTestfile.txt");
- if(!fin)
- {
- return;
- }
- int firstTest = 1;
- cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
- cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
- cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
- cmListFileCache cache;
- cmListFile* listFile = cache.GetFileCache("DartTestfile.txt", false);
- for(std::vector<cmListFileFunction>::const_iterator f =
- listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
- {
- const cmListFileFunction& lff = *f;
- const std::string& name = lff.m_Name;
- const std::vector<cmListFileArgument>& args = lff.m_Arguments;
- if (name == "SUBDIRS")
- {
- std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
- for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
- j != args.end(); ++j)
- {
- std::string nwd = cwd + "/";
- nwd += j->Value;
- if (cmSystemTools::FileIsDirectory(nwd.c_str()))
- {
- cmSystemTools::ChangeDirectory(nwd.c_str());
- this->ProcessDirectory(passed, failed, memcheck);
- }
- }
- // return to the original directory
- cmSystemTools::ChangeDirectory(cwd.c_str());
- }
- if (name == "ADD_TEST")
- {
- if (this->m_UseExcludeRegExp &&
- this->m_UseExcludeRegExpFirst &&
- ereg.find(args[0].Value.c_str()))
- {
- continue;
- }
- if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
- {
- continue;
- }
- if (this->m_UseExcludeRegExp &&
- !this->m_UseExcludeRegExpFirst &&
- ereg.find(args[0].Value.c_str()))
- {
- continue;
- }
- cmCTestTestResult cres;
- cres.m_Status = cmCTest::NOT_RUN;
- if (firstTest)
- {
- std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
- if ( m_Verbose )
- {
- std::cerr << "Changing directory into " << nwd.c_str() << "\n";
- }
- firstTest = 0;
- }
- cres.m_Name = args[0].Value;
- if ( m_ShowOnly )
- {
- std::cout << args[0].Value << std::endl;
- }
- else
- {
- fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
- fflush(stderr);
- }
- //std::cerr << "Testing " << args[0] << " ... ";
- // find the test executable
- std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
- std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
- std::string memcheckcommand = "";
- // continue if we did not find the executable
- if (testCommand == "")
- {
- std::cerr << "Unable to find executable: " <<
- args[1].Value.c_str() << "\n";
- m_TestResults.push_back( cres );
- continue;
- }
- // add the arguments
- std::vector<cmListFileArgument>::const_iterator j = args.begin();
- ++j;
- ++j;
- std::vector<const char*> arguments;
- if ( memcheck )
- {
- cmCTest::tm_VectorOfStrings::size_type pp;
- arguments.push_back(m_MemoryTester.c_str());
- memcheckcommand = m_MemoryTester;
- for ( pp = 0; pp < m_MemoryTesterOptionsParsed.size(); pp ++ )
- {
- arguments.push_back(m_MemoryTesterOptionsParsed[pp].c_str());
- memcheckcommand += " ";
- memcheckcommand += cmSystemTools::EscapeSpaces(m_MemoryTesterOptionsParsed[pp].c_str());
- }
- }
- arguments.push_back(actualCommand.c_str());
- for(;j != args.end(); ++j)
- {
- testCommand += " ";
- testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
- arguments.push_back(j->Value.c_str());
- }
- arguments.push_back(0);
- /**
- * Run an executable command and put the stdout in output.
- */
- std::string output;
- int retVal = 0;
- double clock_start, clock_finish;
- clock_start = cmSystemTools::GetTime();
- if ( m_Verbose )
- {
- std::cout << std::endl << (memcheck?"MemCheck":"Test") << " command: " << testCommand << std::endl;
- if ( memcheck )
- {
- std::cout << "Memory check command: " << memcheckcommand << std::endl;
- }
- }
- int res = 0;
- if ( !m_ShowOnly )
- {
- res = this->RunTest(arguments, &output, &retVal);
- }
- clock_finish = cmSystemTools::GetTime();
- cres.m_ExecutionTime = (double)(clock_finish - clock_start);
- cres.m_FullCommandLine = testCommand;
- if ( !m_ShowOnly )
- {
- if (res == cmsysProcess_State_Exited && retVal == 0)
- {
- fprintf(stderr," Passed\n");
- passed.push_back(args[0].Value);
- cres.m_Status = cmCTest::COMPLETED;
- }
- else
- {
- cres.m_Status = cmCTest::FAILED;
- if ( res == cmsysProcess_State_Expired )
- {
- fprintf(stderr,"***Timeout\n");
- cres.m_Status = cmCTest::TIMEOUT;
- }
- else if ( res == cmsysProcess_State_Exception )
- {
- fprintf(stderr,"***Exception: ");
- switch ( retVal )
- {
- case cmsysProcess_Exception_Fault:
- fprintf(stderr,"SegFault");
- cres.m_Status = cmCTest::SEGFAULT;
- break;
- case cmsysProcess_Exception_Illegal:
- fprintf(stderr,"Illegal");
- cres.m_Status = cmCTest::ILLEGAL;
- break;
- case cmsysProcess_Exception_Interrupt:
- fprintf(stderr,"Interrupt");
- cres.m_Status = cmCTest::INTERRUPT;
- break;
- case cmsysProcess_Exception_Numerical:
- fprintf(stderr,"Numerical");
- cres.m_Status = cmCTest::NUMERICAL;
- break;
- default:
- fprintf(stderr,"Other");
- cres.m_Status = cmCTest::OTHER_FAULT;
- }
- fprintf(stderr,"\n");
- }
- else if ( res == cmsysProcess_State_Error )
- {
- fprintf(stderr,"***Bad command\n");
- cres.m_Status = cmCTest::BAD_COMMAND;
- }
- else
- {
- fprintf(stderr,"***Failed\n");
- }
- failed.push_back(args[0].Value);
- }
- if (output != "")
- {
- if (dartStuff.find(output.c_str()))
- {
- std::string dartString = dartStuff.match(1);
- cmSystemTools::ReplaceString(output, dartString.c_str(),"");
- cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
- }
- }
- }
- cres.m_Output = output;
- cres.m_ReturnValue = retVal;
- std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
- if ( nwd.size() > m_ToplevelPath.size() )
- {
- nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
- }
- cmSystemTools::ReplaceString(nwd, "\\", "/");
- cres.m_Path = nwd;
- cres.m_CompletionStatus = "Completed";
- m_TestResults.push_back( cres );
- }
- }
- }
- bool cmCTest::InitializeMemoryChecking()
- {
- // Setup the command
- if ( cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckCommand"].c_str()) )
- {
- m_MemoryTester
- = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["MemoryCheckCommand"].c_str());
- }
- else if ( cmSystemTools::FileExists(m_DartConfiguration["PurifyCommand"].c_str()) )
- {
- m_MemoryTester
- = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["PurifyCommand"].c_str());
- }
- else if ( cmSystemTools::FileExists(m_DartConfiguration["ValgrindCommand"].c_str()) )
- {
- m_MemoryTester
- = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["ValgrindCommand"].c_str());
- }
- else
- {
- std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program."
- << std::endl;
- return false;
- }
- if ( m_MemoryTester[0] == '\"' && m_MemoryTester[m_MemoryTester.size()-1] == '\"' )
- {
- m_MemoryTester = m_MemoryTester.substr(1, m_MemoryTester.size()-2);
- }
- // Setup the options
- if ( m_DartConfiguration["MemoryCheckCommandOptions"].size() )
- {
- m_MemoryTesterOptions = m_DartConfiguration["MemoryCheckCommandOptions"];
- }
- else if ( m_DartConfiguration["ValgrindCommandOptions"].size() )
- {
- m_MemoryTesterOptions = m_DartConfiguration["ValgrindCommandOptions"];
- }
- m_MemoryTesterOutputFile = m_ToplevelPath + "/Testing/Temporary/MemoryChecker.log";
- m_MemoryTesterOutputFile = cmSystemTools::EscapeSpaces(m_MemoryTesterOutputFile.c_str());
- if ( m_MemoryTester.find("valgrind") != std::string::npos )
- {
- m_MemoryTesterStyle = cmCTest::VALGRIND;
- if ( !m_MemoryTesterOptions.size() )
- {
- m_MemoryTesterOptions = "-q --skin=memcheck --leak-check=yes --show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=100";
- }
- if ( m_DartConfiguration["MemoryCheckSuppressionFile"].size() )
- {
- if ( !cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) )
- {
- std::cerr << "Cannot find memory checker suppression file: "
- << m_DartConfiguration["MemoryCheckSuppressionFile"].c_str() << std::endl;
- return false;
- }
- m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) + "";
- }
- }
- else if ( m_MemoryTester.find("purify") != std::string::npos )
- {
- m_MemoryTesterStyle = cmCTest::PURIFY;
- #ifdef _WIN32
- m_MemoryTesterOptions += " /SAVETEXTDATA=" + m_MemoryTesterOutputFile;
- #else
- m_MemoryTesterOptions += " -log-file=" + m_MemoryTesterOutputFile;
- #endif
- }
- else if ( m_MemoryTester.find("boundschecker") != std::string::npos )
- {
- m_MemoryTesterStyle = cmCTest::BOUNDS_CHECKER;
- std::cerr << "Bounds checker not yet implemented" << std::endl;
- return false;
- }
- else
- {
- std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl;
- return false;
- }
- m_MemoryTesterOptionsParsed = cmSystemTools::ParseArguments(m_MemoryTesterOptions.c_str());
- cmCTest::tm_VectorOfStrings::size_type cc;
- for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
- {
- m_MemoryTesterGlobalResults[cc] = 0;
- }
- return true;
- }
- int cmCTest::TestDirectory(bool memcheck)
- {
- std::cout << (memcheck ? "Memory check" : "Test") << " project" << std::endl;
- if ( memcheck )
- {
- if ( !this->InitializeMemoryChecking() )
- {
- return 1;
- }
- }
- cmCTest::tm_VectorOfStrings passed;
- cmCTest::tm_VectorOfStrings failed;
- int total;
- m_StartTest = ::CurrentTime();
- this->ProcessDirectory(passed, failed, memcheck);
- m_EndTest = ::CurrentTime();
- total = int(passed.size()) + int(failed.size());
- if (total == 0)
- {
- if ( !m_ShowOnly )
- {
- std::cerr << "No tests were found!!!\n";
- }
- }
- else
- {
- if (m_Verbose && passed.size() &&
- (m_UseIncludeRegExp || m_UseExcludeRegExp))
- {
- std::cerr << "\nThe following tests passed:\n";
- for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin();
- j != passed.end(); ++j)
- {
- std::cerr << "\t" << *j << "\n";
- }
- }
- float percent = float(passed.size()) * 100.0f / total;
- fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
- percent, int(failed.size()), total);
- if (failed.size())
- {
- std::cerr << "\nThe following tests FAILED:\n";
- for(cmCTest::tm_VectorOfStrings::iterator j = failed.begin();
- j != failed.end(); ++j)
- {
- std::cerr << "\t" << *j << "\n";
- }
- }
- }
- if ( m_DartMode )
- {
- std::ofstream ofs;
- if( !this->OpenOutputFile(m_CurrentTag,
- (memcheck ? (m_CompatibilityMode?"Purify.xml":"MemCheck.xml") : "Test.xml"), ofs) )
- {
- std::cerr << "Cannot create " << (memcheck ? "memory check" : "testing")
- << " XML file" << std::endl;
- return 1;
- }
- if ( memcheck )
- {
- this->GenerateDartMemCheckOutput(ofs);
- }
- else
- {
- this->GenerateDartTestOutput(ofs);
- }
- }
- return int(failed.size());
- }
- int cmCTest::SubmitResults()
- {
- cmCTest::tm_VectorOfStrings files;
- std::string prefix = this->GetSubmitResultsPrefix();
- // TODO:
- // Check if test is enabled
- if ( this->CTestFileExists("Update.xml") )
- {
- files.push_back("Update.xml");
- }
- if ( this->CTestFileExists("Configure.xml") )
- {
- files.push_back("Configure.xml");
- }
- if ( this->CTestFileExists("Build.xml") )
- {
- files.push_back("Build.xml");
- }
- if ( this->CTestFileExists("Test.xml") )
- {
- files.push_back("Test.xml");
- }
- if ( this->CTestFileExists("Coverage.xml") )
- {
- files.push_back("Coverage.xml");
- cmCTest::tm_VectorOfStrings gfiles;
- std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
- std::string::size_type glen = gpath.size() + 1;
- gpath = gpath + "/CoverageLog*";
- //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
- if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
- {
- size_t cc;
- for ( cc = 0; cc < gfiles.size(); cc ++ )
- {
- gfiles[cc] = gfiles[cc].substr(glen);
- //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
- files.push_back(gfiles[cc]);
- }
- }
- else
- {
- std::cerr << "Problem globbing" << std::endl;
- }
- }
- if ( this->CTestFileExists("MemCheck.xml") )
- {
- files.push_back("MemCheck.xml");
- }
- if ( this->CTestFileExists("Purify.xml") )
- {
- files.push_back("Purify.xml");
- }
- if ( this->CTestFileExists("Notes.xml") )
- {
- files.push_back("Notes.xml");
- }
- cmCTestSubmit submit;
- submit.SetVerbose(m_Verbose);
- if ( m_DartConfiguration["DropMethod"] == "" ||
- m_DartConfiguration["DropMethod"] == "ftp" )
- {
- std::cout << " Using FTP submit method" << std::endl;
- std::string url = "ftp://";
- url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
- cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
- m_DartConfiguration["DropSite"] +
- cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
- if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
- files, prefix, url) )
- {
- std::cerr << " Problems when submitting via FTP" << std::endl;
- return 0;
- }
- if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
- {
- std::cerr << " Problems when triggering via HTTP" << std::endl;
- return 0;
- }
- std::cout << " Submission successfull" << std::endl;
- return 1;
- }
- else if ( m_DartConfiguration["DropMethod"] == "http" )
- {
- std::cout << " Using HTTP submit method" << std::endl;
- std::string url = "http://";
- if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
- {
- url += m_DartConfiguration["DropSiteUser"];
- if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
- {
- url += ":" + m_DartConfiguration["DropSitePassword"];
- }
- url += "@";
- }
- url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
- if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
- {
- std::cerr << " Problems when submitting via HTTP" << std::endl;
- return 0;
- }
- if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
- {
- std::cerr << " Problems when triggering via HTTP" << std::endl;
- return 0;
- }
- std::cout << " Submission successfull" << std::endl;
- return 1;
- }
- else
- {
- std::cerr << "SCP submit not yet implemented" << std::endl;
- }
-
- return 0;
- }
- bool cmCTest::CTestFileExists(const std::string& filename)
- {
- std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
- filename;
- return cmSystemTools::FileExists(testingDir.c_str());
- }
- std::string cmCTest::GetSubmitResultsPrefix()
- {
- std::string name = m_DartConfiguration["Site"] +
- "___" + m_DartConfiguration["BuildName"] +
- "___" + m_CurrentTag + "-" +
- this->GetTestModelString() + "___XML___";
- return name;
- }
- void cmCTest::GenerateDartMemCheckOutput(std::ostream& os)
- {
- if ( !m_DartMode )
- {
- return;
- }
- this->StartXML(os);
- if ( m_CompatibilityMode )
- {
- os << "<Purify>" << std::endl;
- }
- else
- {
- os << "<MemCheck>" << std::endl;
- }
- os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
- << "\t<TestList>\n";
- tm_TestResultsVector::size_type cc;
- for ( cc = 0; cc < m_TestResults.size(); cc ++ )
- {
- cmCTestTestResult *result = &m_TestResults[cc];
- os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
- << "/" << this->MakeXMLSafe(result->m_Name)
- << "</Test>" << std::endl;
- }
- os << "\t</TestList>\n";
- for ( cc = 0; cc < m_TestResults.size(); cc ++ )
- {
- cmCTestTestResult *result = &m_TestResults[cc];
- std::string memcheckstr;
- int memcheckresults[cmCTest::NO_MEMORY_FAULT];
- int kk;
- this->ProcessMemCheckOutput(result->m_Output, memcheckstr, memcheckresults);
- os << "\t<Test Status=\"";
- if ( result->m_Status == cmCTest::COMPLETED )
- {
- os << "passed";
- }
- else if ( result->m_Status == cmCTest::NOT_RUN )
- {
- os << "notrun";
- }
- else
- {
- os << "failed";
- }
- os << "\">\n"
- << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
- << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
- << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
- << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
- << "\t\t<FullCommandLine>"
- << this->MakeXMLSafe(result->m_FullCommandLine)
- << "</FullCommandLine>\n"
- << "\t\t<Results>" << std::endl;
- for ( kk = 0; cmCTestMemCheckResultStrings[kk]; kk ++ )
- {
- os << "\t\t\t<" << cmCTestMemCheckResultStrings[kk] << ">"
- << memcheckresults[kk]
- << "</" << cmCTestMemCheckResultStrings[kk] << ">" << std::endl;
- m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
- }
- os
- << "\t\t</Results>\n"
- << "\t<Log>\n" << memcheckstr << std::endl
- << "\t</Log>\n"
- << "\t</Test>" << std::endl;
- }
-
- os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>" << std::endl;
- if ( m_CompatibilityMode )
- {
- os << "</Purify>" << std::endl;
- }
- else
- {
- os << "</MemCheck>" << std::endl;
- }
- this->EndXML(os);
- std::cerr << "Memory checking results:" << std::endl;
- for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
- {
- std::cerr << "\t\t" << cmCTestMemCheckResultStrings[cc] << " - "
- << m_MemoryTesterGlobalResults[cc] << std::endl;
- }
- }
- void cmCTest::GenerateDartTestOutput(std::ostream& os)
- {
- if ( !m_DartMode )
- {
- return;
- }
- this->StartXML(os);
- os << "<Testing>\n"
- << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
- << "\t<TestList>\n";
- tm_TestResultsVector::size_type cc;
- for ( cc = 0; cc < m_TestResults.size(); cc ++ )
- {
- cmCTestTestResult *result = &m_TestResults[cc];
- os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
- << "/" << this->MakeXMLSafe(result->m_Name)
- << "</Test>" << std::endl;
- }
- os << "\t</TestList>\n";
- for ( cc = 0; cc < m_TestResults.size(); cc ++ )
- {
- cmCTestTestResult *result = &m_TestResults[cc];
- os << "\t<Test Status=\"";
- if ( result->m_Status == cmCTest::COMPLETED )
- {
- os << "passed";
- }
- else if ( result->m_Status == cmCTest::NOT_RUN )
- {
- os << "notrun";
- }
- else
- {
- os << "failed";
- }
- os << "\">\n"
- << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
- << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
- << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
- << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
- << "\t\t<FullCommandLine>"
- << this->MakeXMLSafe(result->m_FullCommandLine)
- << "</FullCommandLine>\n"
- << "\t\t<Results>" << std::endl;
- if ( result->m_Status != cmCTest::NOT_RUN )
- {
- if ( result->m_Status != cmCTest::COMPLETED || result->m_ReturnValue )
- {
- os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
- << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
- << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
- << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
- }
- os << result->m_RegressionImages;
- os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
- << "name=\"Execution Time\"><Value>"
- << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
- os
- << "\t\t\t<NamedMeasurement type=\"text/string\" "
- << "name=\"Completion Status\"><Value>"
- << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
- }
- os
- << "\t\t\t<Measurement>\n"
- << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
- << "</Value>\n"
- << "\t\t\t</Measurement>\n"
- << "\t\t</Results>\n"
- << "\t</Test>" << std::endl;
- }
-
- os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
- << "</Testing>" << std::endl;
- this->EndXML(os);
- }
- int cmCTest::ProcessTests()
- {
- int res = 0;
- bool notest = true;
- int cc;
- int update_count = 0;
- for ( cc = 0; cc < LAST_TEST; cc ++ )
- {
- if ( m_Tests[cc] )
- {
- notest = false;
- break;
- }
- }
- if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
- {
- update_count = this->UpdateDirectory();
- if ( update_count < 0 )
- {
- res |= CTEST_UPDATE_ERRORS;
- }
- }
- if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
- {
- return 0;
- }
- if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
- {
- if (this->ConfigureDirectory())
- {
- res |= CTEST_CONFIGURE_ERRORS;
- }
- }
- if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
- {
- if (this->BuildDirectory())
- {
- res |= CTEST_BUILD_ERRORS;
- }
- }
- if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
- {
- if (this->TestDirectory(false))
- {
- res |= CTEST_TEST_ERRORS;
- }
- }
- if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
- {
- this->CoverageDirectory();
- }
- if ( m_Tests[MEMCHECK_TEST] || m_Tests[ALL_TEST] )
- {
- if (this->TestDirectory(true))
- {
- res |= CTEST_MEMORY_ERRORS;
- }
- }
- if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
- {
- this->SubmitResults();
- }
- return res;
- }
- std::string cmCTest::GetTestModelString()
- {
- switch ( m_TestModel )
- {
- case cmCTest::NIGHTLY:
- return "Nightly";
- case cmCTest::CONTINUOUS:
- return "Continuous";
- }
- return "Experimental";
- }
- #define SPACE_REGEX "[ \t\r\n]"
- std::string cmCTest::GenerateRegressionImages(const std::string& xml)
- {
- cmsys::RegularExpression twoattributes(
- "<DartMeasurement"
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*>([^<]*)</DartMeasurement>");
- cmsys::RegularExpression threeattributes(
- "<DartMeasurement"
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*>([^<]*)</DartMeasurement>");
- cmsys::RegularExpression fourattributes(
- "<DartMeasurement"
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*>([^<]*)</DartMeasurement>");
- cmsys::RegularExpression measurementfile(
- "<DartMeasurementFile"
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
- SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
- cmOStringStream ostr;
- bool done = false;
- std::string cxml = xml;
- while ( ! done )
- {
- if ( twoattributes.find(cxml) )
- {
- ostr
- << "\t\t\t<NamedMeasurement"
- << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
- << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
- << "><Value>" << twoattributes.match(5)
- << "</Value></NamedMeasurement>"
- << std::endl;
- cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
- }
- else if ( threeattributes.find(cxml) )
- {
- ostr
- << "\t\t\t<NamedMeasurement"
- << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
- << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
- << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
- << "><Value>" << threeattributes.match(7)
- << "</Value></NamedMeasurement>"
- << std::endl;
- cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
- }
- else if ( fourattributes.find(cxml) )
- {
- ostr
- << "\t\t\t<NamedMeasurement"
- << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
- << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
- << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
- << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
- << "><Value>" << fourattributes.match(9)
- << "</Value></NamedMeasurement>"
- << std::endl;
- cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
- }
- else if ( measurementfile.find(cxml) )
- {
- const std::string& filename = measurementfile.match(5);
- if ( cmSystemTools::FileExists(filename.c_str()) )
- {
- long len = cmSystemTools::FileLength(filename.c_str());
- std::ifstream ifs(filename.c_str(), std::ios::in
- #ifdef _WIN32
- | std::ios::binary
- #endif
- );
- unsigned char *file_buffer = new unsigned char [ len + 1 ];
- ifs.read(reinterpret_cast<char*>(file_buffer), len);
- unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
- unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
- unsigned long cc;
- ostr
- << "\t\t\t<NamedMeasurement"
- << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
- << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
- << " encoding=\"base64\""
- << ">" << std::endl << "\t\t\t\t<Value>";
- for ( cc = 0; cc < rlen; cc ++ )
- {
- ostr << encoded_buffer[cc];
- if ( cc % 60 == 0 && cc )
- {
- ostr << std::endl;
- }
- }
- ostr
- << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
- << std::endl;
- delete [] file_buffer;
- delete [] encoded_buffer;
- }
- else
- {
- int idx = 4;
- if ( measurementfile.match(1) == "name" )
- {
- idx = 2;
- }
- ostr
- << "\t\t\t<NamedMeasurement"
- << " name=\"" << measurementfile.match(idx) << "\""
- << " text=\"text/string\""
- << "><Value>File " << filename << " not found</Value></NamedMeasurement>"
- << std::endl;
- }
- cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
- }
- else
- {
- done = true;
- }
- }
- return ostr.str();
- }
- int cmCTest::RunMakeCommand(const char* command, std::string* output,
- int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
- {
- std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
- if(args.size() < 1)
- {
- return false;
- }
-
- std::vector<const char*> argv;
- for(std::vector<cmStdString>::const_iterator a = args.begin();
- a != args.end(); ++a)
- {
- argv.push_back(a->c_str());
- }
- argv.push_back(0);
- if ( output )
- {
- *output = "";
- }
- cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
- cmsysProcess_SetWorkingDirectory(cp, dir);
- cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
- cmsysProcess_SetTimeout(cp, timeout);
- cmsysProcess_Execute(cp);
-
- std::string::size_type tick = 0;
- std::string::size_type tick_len = 1024;
- std::string::size_type tick_line_len = 50;
- char* data;
- int length;
- if ( !verbose )
- {
- std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
- std::cout << " " << std::flush;
- }
- while(cmsysProcess_WaitForData(cp, &data, &length, 0))
- {
- if ( output )
- {
- for(int cc =0; cc < length; ++cc)
- {
- if(data[cc] == 0)
- {
- data[cc] = '\n';
- }
- }
-
- output->append(data, length);
- if ( !verbose )
- {
- while ( output->size() > (tick * tick_len) )
- {
- tick ++;
- std::cout << "." << std::flush;
- if ( tick % tick_line_len == 0 && tick > 0 )
- {
- std::cout << " Size: ";
- std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
- std::cout << " " << std::flush;
- }
- }
- }
- }
- if(verbose)
- {
- std::cout.write(data, length);
- std::cout.flush();
- }
- if ( ofs )
- {
- ofs.write(data, length);
- ofs.flush();
- }
- }
- std::cout << " Size of output: ";
- std::cout << int(output->size() / 1024.0) << "K" << std::endl;
-
- cmsysProcess_WaitForExit(cp, 0);
-
- int result = cmsysProcess_GetState(cp);
- if(result == cmsysProcess_State_Exited)
- {
- *retVal = cmsysProcess_GetExitValue(cp);
- }
- else if(result == cmsysProcess_State_Exception)
- {
- *retVal = cmsysProcess_GetExitException(cp);
- std::cout << "There was an exception: " << *retVal << std::endl;
- }
- else if(result == cmsysProcess_State_Expired)
- {
- std::cout << "There was a timeout" << std::endl;
- }
- else if(result == cmsysProcess_State_Error)
- {
- *output += "\n*** ERROR executing: ";
- *output += cmsysProcess_GetErrorString(cp);
- }
-
- cmsysProcess_Delete(cp);
-
- return result;
- }
- int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal)
- {
- std::vector<char> tempOutput;
- if ( output )
- {
- *output = "";
- }
- cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
- //std::cout << "Command is: " << argv[0] << std::endl;
- if(cmSystemTools::GetRunCommandHideConsole())
- {
- cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
- }
- cmsysProcess_SetTimeout(cp, m_TimeOut);
- cmsysProcess_Execute(cp);
-
- char* data;
- int length;
- while(cmsysProcess_WaitForData(cp, &data, &length, 0))
- {
- if ( output )
- {
- tempOutput.insert(tempOutput.end(), data, data+length);
- }
- if ( m_Verbose )
- {
- std::cout.write(data, length);
- std::cout.flush();
- }
- }
-
- cmsysProcess_WaitForExit(cp, 0);
- if(output)
- {
- output->append(&*tempOutput.begin(), tempOutput.size());
- }
- int result = cmsysProcess_GetState(cp);
- if(result == cmsysProcess_State_Exited)
- {
- *retVal = cmsysProcess_GetExitValue(cp);
- }
- else if(result == cmsysProcess_State_Exception)
- {
- *retVal = cmsysProcess_GetExitException(cp);
- }
- else if(result == cmsysProcess_State_Error)
- {
- std::string outerr = "\n*** ERROR executing: ";
- outerr += cmsysProcess_GetErrorString(cp);
- *output += outerr;
- if ( m_Verbose )
- {
- std::cout << outerr.c_str() << "\n";
- std::cout.flush();
- }
- }
-
- cmsysProcess_Delete(cp);
-
- return result;
- }
- const char* cmCTest::GetTestStatus(int status)
- {
- static const char statuses[][100] = {
- "Not Run",
- "Timeout",
- "SEGFAULT",
- "ILLEGAL",
- "INTERRUPT",
- "NUMERICAL",
- "OTHER_FAULT",
- "Failed",
- "BAD_COMMAND",
- "Completed"
- };
- if ( status < cmCTest::NOT_RUN || status > cmCTest::COMPLETED )
- {
- return "No Status";
- }
- return statuses[status];
- }
- int cmCTest::RunConfigurationScript()
- {
- m_ConfigurationScript =
- cmSystemTools::CollapseFullPath(m_ConfigurationScript.c_str());
-
- // make sure the file exists
- if (!cmSystemTools::FileExists(m_ConfigurationScript.c_str()))
- {
- return -1;
- }
-
- // create a cmake instance to read the configuration script
- cmake cm;
- cmGlobalGenerator gg;
- gg.SetCMakeInstance(&cm);
-
- // read in the list file to fill the cache
- cmLocalGenerator *lg = gg.CreateLocalGenerator();
- lg->SetGlobalGenerator(&gg);
- // set a variable with the path to the current script
- lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_DIRECTORY",
- cmSystemTools::GetFilenamePath(
- m_ConfigurationScript).c_str());
- lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_NAME",
- cmSystemTools::GetFilenameName(
- m_ConfigurationScript).c_str());
- if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str()))
- {
- return -2;
- }
- // no popup widows
- cmSystemTools::SetRunCommandHideConsole(true);
- // get some info that should be set
- cmMakefile *mf = lg->GetMakefile();
- const char *srcDir = mf->GetDefinition("CTEST_SOURCE_DIRECTORY");
- const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY");
- const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND");
- const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT");
- bool backup = mf->IsOn("CTEST_BACKUP_AND_RESTORE");
-
- // make sure the required info is here
- if (!srcDir || !binDir || !ctestCmd)
- {
- cmSystemTools::Error("Some required settings in the configuration file were missing");
- return -3;
- }
-
- // set any environment variables
- if (ctestEnv)
- {
- static char ctestEnvStatic[100][5000];
- std::vector<std::string> envArgs;
- cmSystemTools::ExpandListArgument(ctestEnv,envArgs);
- int numArgs = envArgs.size();
- // we have a hard limit of 100 env args due to stupid format of putenv
- if (numArgs > 100)
- {
- numArgs = 100;
- }
- // for each variable/argument do a putenv
- int i;
- for (i = 0; i < numArgs; ++i)
- {
- // also limit args to be at most 4K long
- std::string::size_type size = envArgs[i].size();
- if(size > 4999)
- {
- size = 4999;
- }
- strncpy(ctestEnvStatic[i], envArgs[i].c_str(), size);
- ctestEnvStatic[i][4999] = 0;
- putenv(ctestEnvStatic[i]);
- }
- }
- // compute the backup names
- std::string backupSrcDir = srcDir;
- backupSrcDir += "_CMakeBackup";
- std::string backupBinDir = binDir;
- backupBinDir += "_CMakeBackup";
- // backup the binary and src directories if requested
- if (backup)
- {
- // if for some reason those directories exist then first delete them
- if (cmSystemTools::FileExists(backupSrcDir.c_str()))
- {
- cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
- }
- if (cmSystemTools::FileExists(backupBinDir.c_str()))
- {
- cmSystemTools::RemoveADirectory(backupBinDir.c_str());
- }
-
- // first rename the src and binary directories
- rename(srcDir, backupSrcDir.c_str());
- rename(binDir, backupBinDir.c_str());
- }
- // clear the binary directory?
- if (mf->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"))
- {
- // try to avoid deleting directories that we shouldn't
- std::string check = binDir;
- check += "/CMakeCache.txt";
- if (cmSystemTools::FileExists(check.c_str()))
- {
- cmSystemTools::RemoveADirectory(binDir);
- }
- }
-
- // make sure the binary directory exists
- if (!cmSystemTools::FileExists(binDir))
- {
- if (!cmSystemTools::MakeDirectory(binDir))
- {
- cmSystemTools::Error("Unable to create the binary directory");
- return -4;
- }
- }
-
- std::string command;
- std::string output;
- int retVal = 0;
- bool res = 0;
-
- // do an initial cvs update on the src dir
- const char *cvsCmd = mf->GetDefinition("CTEST_CVS_COMMAND");
- if (cvsCmd)
- {
- command = cvsCmd;
- char updateVar[40];
- int i;
- for (i = 1; i < 10; ++i)
- {
- sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i);
- const char *updateVal = mf->GetDefinition(updateVar);
- if (updateVal)
- {
- std::vector<std::string> cvsArgs;
- cmSystemTools::ExpandListArgument(updateVal,cvsArgs);
- if (cvsArgs.size() == 2)
- {
- std::string fullCommand = command;
- fullCommand += " update ";
- fullCommand += cvsArgs[1];
- output.empty();
- retVal = 0;
- res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
- &retVal, cvsArgs[0].c_str(),
- m_Verbose, 0 /*m_TimeOut*/);
- if (!res || retVal != 0)
- {
- cmSystemTools::Error("Unable to perform extra cvs updates");
- return -5;
- }
- }
- }
- }
- }
-
- // put the initial cache into the bin dir
- if (mf->GetDefinition("CTEST_INITIAL_CACHE"))
- {
- const char *initCache = mf->GetDefinition("CTEST_INITIAL_CACHE");
- std::string cacheFile = binDir;
- cacheFile += "/CMakeCache.txt";
- std::ofstream fout(cacheFile.c_str());
- if(!fout)
- {
- return -6;
- }
-
- fout.write(initCache, strlen(initCache));
-
- // Make sure the operating system has finished writing the file
- // before closing it. This will ensure the file is finished before
- // the check below.
- fout.flush();
- fout.close();
- }
-
- // do an initial cmake to setup the DartConfig file
- const char *cmakeCmd = mf->GetDefinition("CTEST_CMAKE_COMMAND");
- if (cmakeCmd)
- {
- command = cmakeCmd;
- command += " \"";
- command += srcDir;
- output.empty();
- command += "\"";
- retVal = 0;
- res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
- &retVal, binDir,
- m_Verbose, 0 /*m_TimeOut*/);
- if (!res || retVal != 0)
- {
- cmSystemTools::Error("Unable to run cmake");
- return -7;
- }
- }
-
- // run ctest
- command = ctestCmd;
- output.empty();
- retVal = 0;
- res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
- &retVal, binDir,
- m_Verbose, 0 /*m_TimeOut*/);
- // did something critical fail in ctest
- if (!res ||
- retVal & CTEST_BUILD_ERRORS)
- {
- // if we backed up the dirs and the build failed, then restore
- // the backed up dirs
- if (backup)
- {
- // if for some reason those directories exist then first delete them
- if (cmSystemTools::FileExists(srcDir))
- {
- cmSystemTools::RemoveADirectory(srcDir);
- }
- if (cmSystemTools::FileExists(binDir))
- {
- cmSystemTools::RemoveADirectory(binDir);
- }
- // rename the src and binary directories
- rename(backupSrcDir.c_str(), srcDir);
- rename(backupBinDir.c_str(), binDir);
- }
- cmSystemTools::Error("Unable to run ctest");
- if (!res)
- {
- return -8;
- }
- return retVal;
- }
- return 0;
- }
- void cmCTest::StartXML(std::ostream& ostr)
- {
- ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
- << "\" BuildStamp=\"" << m_CurrentTag << "-"
- << this->GetTestModelString() << "\" Name=\""
- << m_DartConfiguration["Site"] << "\">" << std::endl;
- }
- void cmCTest::EndXML(std::ostream& ostr)
- {
- ostr << "</Site>" << std::endl;
- }
- bool cmCTest::ProcessMemCheckPurifyOutput(const std::string&, std::string& log,
- int* results)
- {
- if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) )
- {
- log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile;
- std::cerr << log.c_str() << std::endl;
- return false;
- }
- std::ifstream ifs(m_MemoryTesterOutputFile.c_str());
- if ( !ifs )
- {
- log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile;
- std::cerr << log.c_str() << std::endl;
- return false;
- }
- cmOStringStream ostr;
- log = "";
- cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
- std::string line;
- while ( cmSystemTools::GetLineFromStream(ifs, line) )
- {
- int failure = cmCTest::NO_MEMORY_FAULT;
- if ( pfW.find(line) )
- {
- int cc;
- for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
- {
- if ( pfW.match(1) == cmCTestMemCheckResultStrings[cc] )
- {
- failure = cc;
- break;
- }
- }
- if ( cc == cmCTest::NO_MEMORY_FAULT )
- {
- std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl;
- ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl;
- }
- }
- if ( failure != NO_MEMORY_FAULT )
- {
- ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
- results[failure] ++;
- }
- ostr << cmCTest::MakeXMLSafe(line) << std::endl;
- }
-
- log = ostr.str();
- return true;
- }
- bool cmCTest::ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
- int* results)
- {
- std::vector<cmStdString> lines;
- cmSystemTools::Split(str.c_str(), lines);
- std::string::size_type cc;
- cmOStringStream ostr;
- log = "";
- cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
- cmsys::RegularExpression vgFIM(
- "== .*Invalid free\\(\\) / delete / delete\\[\\]");
- cmsys::RegularExpression vgFMM(
- "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
- cmsys::RegularExpression vgMLK(
- "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are definitely lost"
- " in loss record [0-9][0-9]* of [0-9]");
- cmsys::RegularExpression vgPAR(
- "== .*Syscall param .* contains unaddressable byte\\(s\\)");
- cmsys::RegularExpression vgMPK1(
- "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are possibly lost in"
- " loss record [0-9][0-9]* of [0-9]");
- cmsys::RegularExpression vgMPK2(
- "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are still reachable"
- " in loss record [0-9][0-9]* of [0-9]");
- cmsys::RegularExpression vgUMC(
- "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
- cmsys::RegularExpression vgUMR1("== .*Use of uninitialised value of size [0-9][0-9]*");
- cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9][0-9]*");
- cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
- cmsys::RegularExpression vgUMR4(
- "== .*Syscall param .* contains uninitialised or unaddressable byte\\(s\\)");
- cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]");
- for ( cc = 0; cc < lines.size(); cc ++ )
- {
- if ( valgrindLine.find(lines[cc]) )
- {
- int failure = cmCTest::NO_MEMORY_FAULT;
- if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; }
- else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; }
- else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; }
- else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; }
- else if ( vgMPK1.find(lines[cc]) ){ failure = cmCTest::MPK; }
- else if ( vgMPK2.find(lines[cc]) ){ failure = cmCTest::MPK; }
- else if ( vgUMC.find(lines[cc]) ) { failure = cmCTest::UMC; }
- else if ( vgUMR1.find(lines[cc]) ){ failure = cmCTest::UMR; }
- else if ( vgUMR2.find(lines[cc]) ){ failure = cmCTest::UMR; }
- else if ( vgUMR3.find(lines[cc]) ){ failure = cmCTest::UMR; }
- else if ( vgUMR4.find(lines[cc]) ){ failure = cmCTest::UMR; }
- else if ( vgIPW.find(lines[cc]) ) { failure = cmCTest::IPW; }
- if ( failure != cmCTest::NO_MEMORY_FAULT )
- {
- ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
- results[failure] ++;
- }
- ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl;
- }
- }
- log = ostr.str();
- return true;
- }
- bool cmCTest::ProcessMemCheckOutput(const std::string& str, std::string& log, int* results)
- {
- std::string::size_type cc;
- for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
- {
- results[cc] = 0;
- }
- if ( m_MemoryTesterStyle == cmCTest::VALGRIND )
- {
- return ProcessMemCheckValgrindOutput(str, log, results);
- }
- else if ( m_MemoryTesterStyle == cmCTest::PURIFY )
- {
- return ProcessMemCheckPurifyOutput(str, log, results);
- }
- else if ( m_MemoryTesterStyle == cmCTest::BOUNDS_CHECKER )
- {
- log.append("\nMemory checking style used was: ");
- log.append("Bounds Checker");
- }
- else
- {
- log.append("\nMemory checking style used was: ");
- log.append("None that I know");
- log = str;
- }
- return true;
- }
- int cmCTest::GenerateDartNotesOutput(std::ostream& os, const cmCTest::tm_VectorOfStrings& files)
- {
- cmCTest::tm_VectorOfStrings::const_iterator it;
- for ( it = files.begin(); it != files.end(); it ++ )
- {
- if ( !cmSystemTools::FileExists(it->c_str()) )
- {
- std::cerr << "Error creating notes. File " << it->c_str() << " does not exists" << std::endl;
- return 0;
- }
- }
- os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- << "<?xml-stylesheet type=\"text/xsl\" href=\"Dart/Source/Server/XSL/Build.xsl <file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
- << "<Site BuildName=\"" << m_DartConfiguration["BuildName"] << "\" BuildStamp=\""
- << m_CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
- << m_DartConfiguration["Site"] << "\">\n"
- << "<Notes>" << std::endl;
- for ( it = files.begin(); it != files.end(); it ++ )
- {
- std::cout << "\tAdd file: " << it->c_str() << std::endl;
- std::string note_time = ::CurrentTime();
- os << "<Note>\n"
- << "<DateTime>" << note_time << "</DateTime>\n"
- << "<Text>" << std::endl;
- std::ifstream ifs(it->c_str());
- if ( ifs )
- {
- std::string line;
- while ( cmSystemTools::GetLineFromStream(ifs, line) )
- {
- os << this->MakeXMLSafe(line) << std::endl;
- }
- ifs.close();
- }
- else
- {
- os << "Problem reading file: " << it->c_str() << std::endl;
- std::cerr << "Problem reading file: " << it->c_str() << " while creating notes" << std::endl;
- }
- os << "</Text>\n"
- << "</Note>" << std::endl;
- }
- os << "</Notes>\n"
- << "</Site>" << std::endl;
- return 1;
- }
- int cmCTest::GenerateNotesFile(const char* cfiles)
- {
- if ( !cfiles )
- {
- return 1;
- }
- std::vector<cmStdString> files;
- std::cout << "Create notes file" << std::endl;
- files = cmSystemTools::SplitString(cfiles, ';');
- if ( files.size() == 0 )
- {
- return 1;
- }
- std::ofstream ofs;
- if ( !this->OpenOutputFile(m_CurrentTag, "Notes.xml", ofs) )
- {
- std::cerr << "Cannot open notes file" << std::endl;
- return 1;
- }
- this->GenerateDartNotesOutput(ofs, files);
- return 0;
- }
|