1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTest.cxx,v $
6 Date: $Date: 2008/02/03 13:57:41 $
7 Version: $Revision: 1.334 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
21 #include "cmMakefile.h"
22 #include "cmLocalGenerator.h"
23 #include "cmGlobalGenerator.h"
24 #include <cmsys/Directory.hxx>
25 #include <cmsys/SystemInformation.hxx>
26 #include "cmDynamicLoader.h"
27 #include "cmGeneratedFileStream.h"
28 #include "cmCTestCommand.h"
30 #include "cmCTestBuildHandler.h"
31 #include "cmCTestBuildAndTestHandler.h"
32 #include "cmCTestConfigureHandler.h"
33 #include "cmCTestCoverageHandler.h"
34 #include "cmCTestMemCheckHandler.h"
35 #include "cmCTestScriptHandler.h"
36 #include "cmCTestTestHandler.h"
37 #include "cmCTestUpdateHandler.h"
38 #include "cmCTestSubmitHandler.h"
40 #include "cmVersion.h"
42 #include <cmsys/RegularExpression.hxx>
43 #include <cmsys/Process.h>
44 #include <cmsys/Glob.hxx>
50 #include <memory> // auto_ptr
53 #include <be/kernel/OS.h> /* disable_debugger() API. */
56 #define DEBUGOUT std::cout << __LINE__ << " "; std::cout
57 #define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
59 //----------------------------------------------------------------------
60 struct tm
* cmCTest::GetNightlyTime(std::string str
,
64 time_t tctime
= time(0);
65 lctime
= gmtime(&tctime
);
67 // add todays year day and month to the time in str because
68 // curl_getdate no longer assumes the day is today
69 sprintf(buf
, "%d%02d%02d %s", lctime
->tm_year
+1900, lctime
->tm_mday
,
70 lctime
->tm_mon
, str
.c_str());
71 cmCTestLog(this, OUTPUT
, "Determine Nightly Start Time" << std::endl
72 << " Specified time: " << str
.c_str() << std::endl
);
73 //Convert the nightly start time to seconds. Since we are
74 //providing only a time and a timezone, the current date of
75 //the local machine is assumed. Consequently, nightlySeconds
76 //is the time at which the nightly dashboard was opened or
77 //will be opened on the date of the current client machine.
78 //As such, this time may be in the past or in the future.
79 time_t ntime
= curl_getdate(buf
, &tctime
);
80 cmCTestLog(this, DEBUG
, " Get curl time: " << ntime
<< std::endl
);
82 cmCTestLog(this, DEBUG
, " Get the current time: " << tctime
<< std::endl
);
84 const int dayLength
= 24 * 60 * 60;
85 cmCTestLog(this, DEBUG
, "Seconds: " << tctime
<< std::endl
);
86 while ( ntime
> tctime
)
88 // If nightlySeconds is in the past, this is the current
89 // open dashboard, then return nightlySeconds. If
90 // nightlySeconds is in the future, this is the next
91 // dashboard to be opened, so subtract 24 hours to get the
92 // time of the current open dashboard
94 cmCTestLog(this, DEBUG
, "Pick yesterday" << std::endl
);
95 cmCTestLog(this, DEBUG
, " Future time, subtract day: " << ntime
98 while ( tctime
> (ntime
+ dayLength
) )
101 cmCTestLog(this, DEBUG
, " Past time, add day: " << ntime
<< std::endl
);
103 cmCTestLog(this, DEBUG
, "nightlySeconds: " << ntime
<< std::endl
);
104 cmCTestLog(this, DEBUG
, " Current time: " << tctime
105 << " Nightly time: " << ntime
<< std::endl
);
108 cmCTestLog(this, OUTPUT
, " Use future tag, Add a day" << std::endl
);
111 lctime
= gmtime(&ntime
);
115 //----------------------------------------------------------------------
116 std::string
cmCTest::CleanString(const std::string
& str
)
118 std::string::size_type spos
= str
.find_first_not_of(" \n\t\r\f\v");
119 std::string::size_type epos
= str
.find_last_not_of(" \n\t\r\f\v");
120 if ( spos
== str
.npos
)
122 return std::string();
124 if ( epos
!= str
.npos
)
126 epos
= epos
- spos
+ 1;
128 return str
.substr(spos
, epos
);
131 //----------------------------------------------------------------------
132 std::string
cmCTest::CurrentTime()
134 time_t currenttime
= time(0);
135 struct tm
* t
= localtime(¤ttime
);
136 //return ::CleanString(ctime(¤ttime));
137 char current_time
[1024];
138 if ( this->ShortDateFormat
)
140 strftime(current_time
, 1000, "%b %d %H:%M %Z", t
);
144 strftime(current_time
, 1000, "%a %b %d %H:%M:%S %Z %Y", t
);
146 cmCTestLog(this, DEBUG
, " Current_Time: " << current_time
<< std::endl
);
147 return cmCTest::MakeXMLSafe(cmCTest::CleanString(current_time
));
151 //----------------------------------------------------------------------
152 std::string
cmCTest::MakeXMLSafe(const std::string
& str
)
154 std::vector
<char> result
;
156 const char* pos
= str
.c_str();
160 if ( (ch
> 126 || ch
< 32) && ch
!= 9 &&
161 ch
!= 10 && ch
!= 13 && ch
!= '\r' )
164 sprintf(buffer
, "<%d>", (int)ch
);
165 //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
166 result
.insert(result
.end(), buffer
, buffer
+strlen(buffer
));
170 const char* const encodedChars
[] = {
178 result
.insert(result
.end(), encodedChars
[0], encodedChars
[0]+5);
181 result
.insert(result
.end(), encodedChars
[1], encodedChars
[1]+4);
184 result
.insert(result
.end(), encodedChars
[2], encodedChars
[2]+4);
187 result
.push_back('\n');
189 case '\r': break; // Ignore \r
191 result
.push_back(ch
);
195 if ( result
.size() == 0 )
199 return std::string(&*result
.begin(), result
.size());
202 //----------------------------------------------------------------------
203 std::string
cmCTest::MakeURLSafe(const std::string
& str
)
207 for ( std::string::size_type pos
= 0; pos
< str
.size(); pos
++ )
209 unsigned char ch
= str
[pos
];
210 if ( ( ch
> 126 || ch
< 32 ||
218 sprintf(buffer
, "%02x;", (unsigned int)ch
);
229 //----------------------------------------------------------------------
232 this->SubmitIndex
= 0;
233 this->ForceNewCTestProcess
= false;
234 this->TomorrowTag
= false;
235 this->Verbose
= false;
237 this->ShowLineNumbers
= false;
239 this->ExtraVerbose
= false;
240 this->ProduceXML
= false;
241 this->ShowOnly
= false;
242 this->RunConfigurationScript
= false;
243 this->TestModel
= cmCTest::EXPERIMENTAL
;
244 this->InteractiveDebugMode
= true;
246 this->CompressXMLFiles
= false;
247 this->CTestConfigFile
= "";
248 this->OutputLogFile
= 0;
249 this->OutputLogFileLastTag
= -1;
250 this->SuppressUpdatingCTestConfiguration
= false;
251 this->DartVersion
= 1;
254 for ( cc
=0; cc
< cmCTest::LAST_TEST
; cc
++ )
258 this->ShortDateFormat
= true;
260 this->TestingHandlers
["build"] = new cmCTestBuildHandler
;
261 this->TestingHandlers
["buildtest"] = new cmCTestBuildAndTestHandler
;
262 this->TestingHandlers
["coverage"] = new cmCTestCoverageHandler
;
263 this->TestingHandlers
["script"] = new cmCTestScriptHandler
;
264 this->TestingHandlers
["test"] = new cmCTestTestHandler
;
265 this->TestingHandlers
["update"] = new cmCTestUpdateHandler
;
266 this->TestingHandlers
["configure"] = new cmCTestConfigureHandler
;
267 this->TestingHandlers
["memcheck"] = new cmCTestMemCheckHandler
;
268 this->TestingHandlers
["submit"] = new cmCTestSubmitHandler
;
270 cmCTest::t_TestingHandlers::iterator it
;
271 for ( it
= this->TestingHandlers
.begin();
272 it
!= this->TestingHandlers
.end(); ++ it
)
274 it
->second
->SetCTestInstance(this);
277 // Make sure we can capture the build tool output.
278 cmSystemTools::EnableVSConsoleOutput();
281 //----------------------------------------------------------------------
284 cmCTest::t_TestingHandlers::iterator it
;
285 for ( it
= this->TestingHandlers
.begin();
286 it
!= this->TestingHandlers
.end(); ++ it
)
291 this->SetOutputLogFileName(0);
294 //----------------------------------------------------------------------
295 int cmCTest::Initialize(const char* binary_dir
, bool new_tag
,
298 cmCTestLog(this, DEBUG
, "Here: " << __LINE__
<< std::endl
);
299 if(!this->InteractiveDebugMode
)
301 this->BlockTestErrorDiagnostics();
305 cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1");
308 this->BinaryDir
= binary_dir
;
309 cmSystemTools::ConvertToUnixSlashes(this->BinaryDir
);
311 this->UpdateCTestConfiguration();
313 cmCTestLog(this, DEBUG
, "Here: " << __LINE__
<< std::endl
);
314 if ( this->ProduceXML
)
316 cmCTestLog(this, DEBUG
, "Here: " << __LINE__
<< std::endl
);
317 cmCTestLog(this, OUTPUT
,
318 " Site: " << this->GetCTestConfiguration("Site") << std::endl
319 << " Build name: " << this->GetCTestConfiguration("BuildName")
321 cmCTestLog(this, DEBUG
, "Produce XML is on" << std::endl
);
322 if ( this->TestModel
== cmCTest::NIGHTLY
&&
323 this->GetCTestConfiguration("NightlyStartTime").empty() )
325 cmCTestLog(this, WARNING
,
326 "WARNING: No nightly start time found please set in"
327 " CTestConfig.cmake or DartConfig.cmake" << std::endl
);
328 cmCTestLog(this, DEBUG
, "Here: " << __LINE__
<< std::endl
);
334 cmGlobalGenerator gg
;
335 gg
.SetCMakeInstance(&cm
);
336 std::auto_ptr
<cmLocalGenerator
> lg(gg
.CreateLocalGenerator());
337 lg
->SetGlobalGenerator(&gg
);
338 cmMakefile
*mf
= lg
->GetMakefile();
339 if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir
.c_str(), mf
) )
341 cmCTestLog(this, DEBUG
, "Cannot find custom configuration file tree"
346 if ( this->ProduceXML
)
348 std::string testingDir
= this->BinaryDir
+ "/Testing";
349 if ( cmSystemTools::FileExists(testingDir
.c_str()) )
351 if ( !cmSystemTools::FileIsDirectory(testingDir
.c_str()) )
353 cmCTestLog(this, ERROR_MESSAGE
, "File " << testingDir
354 << " is in the place of the testing directory" << std::endl
);
360 if ( !cmSystemTools::MakeDirectory(testingDir
.c_str()) )
362 cmCTestLog(this, ERROR_MESSAGE
, "Cannot create directory "
363 << testingDir
<< std::endl
);
367 std::string tagfile
= testingDir
+ "/TAG";
368 std::ifstream
tfin(tagfile
.c_str());
370 time_t tctime
= time(0);
371 if ( this->TomorrowTag
)
373 tctime
+= ( 24 * 60 * 60 );
375 struct tm
*lctime
= gmtime(&tctime
);
376 if ( tfin
&& cmSystemTools::GetLineFromStream(tfin
, tag
) )
383 sscanf(tag
.c_str(), "%04d%02d%02d-%02d%02d",
384 &year
, &mon
, &day
, &hour
, &min
);
385 if ( year
!= lctime
->tm_year
+ 1900 ||
386 mon
!= lctime
->tm_mon
+1 ||
387 day
!= lctime
->tm_mday
)
392 if ( cmSystemTools::GetLineFromStream(tfin
, tagmode
) )
394 if ( tagmode
.size() > 4 && !( this->Tests
[cmCTest::START_TEST
] ||
395 this->Tests
[ALL_TEST
] ))
397 this->TestModel
= cmCTest::GetTestModelFromString(tagmode
.c_str());
402 if ( tag
.size() == 0 || new_tag
|| this->Tests
[cmCTest::START_TEST
] ||
403 this->Tests
[ALL_TEST
])
405 cmCTestLog(this, DEBUG
, "TestModel: " << this->GetTestModelString()
407 cmCTestLog(this, DEBUG
, "TestModel: " << this->TestModel
<< std::endl
);
408 if ( this->TestModel
== cmCTest::NIGHTLY
)
410 lctime
= this->GetNightlyTime(
411 this->GetCTestConfiguration("NightlyStartTime"), this->TomorrowTag
);
413 char datestring
[100];
414 sprintf(datestring
, "%04d%02d%02d-%02d%02d",
415 lctime
->tm_year
+ 1900,
421 std::ofstream
ofs(tagfile
.c_str());
424 ofs
<< tag
<< std::endl
;
425 ofs
<< this->GetTestModelString() << std::endl
;
430 cmCTestLog(this, OUTPUT
, "Create new tag: " << tag
<< " - "
431 << this->GetTestModelString() << std::endl
);
434 this->CurrentTag
= tag
;
439 //----------------------------------------------------------------------
440 bool cmCTest::InitializeFromCommand(cmCTestCommand
* command
, bool first
)
442 if ( !first
&& !this->CurrentTag
.empty() )
448 = this->GetCTestConfiguration("SourceDirectory").c_str();
449 std::string bld_dir
= this->GetCTestConfiguration("BuildDirectory").c_str();
450 this->DartVersion
= 1;
451 this->SubmitFiles
.clear();
453 cmMakefile
* mf
= command
->GetMakefile();
454 std::string fname
= src_dir
;
455 fname
+= "/CTestConfig.cmake";
456 cmSystemTools::ConvertToUnixSlashes(fname
);
457 if ( cmSystemTools::FileExists(fname
.c_str()) )
459 cmCTestLog(this, OUTPUT
, " Reading ctest configuration file: "
460 << fname
.c_str() << std::endl
);
461 bool readit
= mf
->ReadListFile(mf
->GetCurrentListFile(),
465 std::string m
= "Could not find include file: ";
467 command
->SetError(m
.c_str());
473 cmCTestLog(this, WARNING
, "Cannot locate CTest configuration: "
474 << fname
.c_str() << std::endl
);
478 cmCTestLog(this, HANDLER_OUTPUT
, " Cannot locate CTest configuration: "
479 << fname
.c_str() << std::endl
480 << " Delay the initialization of CTest" << std::endl
);
483 this->SetCTestConfigurationFromCMakeVariable(mf
, "NightlyStartTime",
484 "CTEST_NIGHTLY_START_TIME");
485 this->SetCTestConfigurationFromCMakeVariable(mf
, "Site", "CTEST_SITE");
486 this->SetCTestConfigurationFromCMakeVariable(mf
, "BuildName",
488 const char* dartVersion
= mf
->GetDefinition("CTEST_DART_SERVER_VERSION");
491 this->DartVersion
= atoi(dartVersion
);
492 if ( this->DartVersion
< 0 )
494 cmCTestLog(this, ERROR_MESSAGE
, "Invalid Dart server version: "
495 << dartVersion
<< ". Please specify the version number."
501 if ( !this->Initialize(bld_dir
.c_str(), true, false) )
503 if ( this->GetCTestConfiguration("NightlyStartTime").empty() && first
)
509 cmCTestLog(this, OUTPUT
, " Use " << this->GetTestModelString()
510 << " tag: " << this->GetCurrentTag() << std::endl
);
515 //----------------------------------------------------------------------
516 bool cmCTest::UpdateCTestConfiguration()
518 if ( this->SuppressUpdatingCTestConfiguration
)
522 std::string fileName
= this->CTestConfigFile
;
523 if ( fileName
.empty() )
525 fileName
= this->BinaryDir
+ "/CTestConfiguration.ini";
526 if ( !cmSystemTools::FileExists(fileName
.c_str()) )
528 fileName
= this->BinaryDir
+ "/DartConfiguration.tcl";
531 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, "UpdateCTestConfiguration from :"
532 << fileName
.c_str() << "\n");
533 if ( !cmSystemTools::FileExists(fileName
.c_str()) )
535 // No need to exit if we are not producing XML
536 if ( this->ProduceXML
)
538 cmCTestLog(this, ERROR_MESSAGE
, "Cannot find file: " << fileName
.c_str()
545 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, "Parse Config file:"
546 << fileName
.c_str() << "\n");
547 // parse the dart test file
548 std::ifstream
fin(fileName
.c_str());
558 fin
.getline(buffer
, 1023);
560 std::string line
= cmCTest::CleanString(buffer
);
565 while ( fin
&& (line
[line
.size()-1] == '\\') )
567 line
= line
.substr(0, line
.size()-1);
569 fin
.getline(buffer
, 1023);
571 line
+= cmCTest::CleanString(buffer
);
573 if ( line
[0] == '#' )
577 std::string::size_type cpos
= line
.find_first_of(":");
578 if ( cpos
== line
.npos
)
582 std::string key
= line
.substr(0, cpos
);
584 = cmCTest::CleanString(line
.substr(cpos
+1, line
.npos
));
585 this->CTestConfiguration
[key
] = value
;
589 if ( !this->GetCTestConfiguration("BuildDirectory").empty() )
591 this->BinaryDir
= this->GetCTestConfiguration("BuildDirectory");
592 cmSystemTools::ChangeDirectory(this->BinaryDir
.c_str());
594 this->TimeOut
= atoi(this->GetCTestConfiguration("TimeOut").c_str());
595 if ( this->ProduceXML
)
597 this->CompressXMLFiles
= cmSystemTools::IsOn(
598 this->GetCTestConfiguration("CompressSubmission").c_str());
603 //----------------------------------------------------------------------
604 void cmCTest::BlockTestErrorDiagnostics()
606 cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
607 cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=" CMake_VERSION
);
609 SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
610 #elif defined(__BEOS__)
615 //----------------------------------------------------------------------
616 void cmCTest::SetTestModel(int mode
)
618 this->InteractiveDebugMode
= false;
619 this->TestModel
= mode
;
622 //----------------------------------------------------------------------
623 bool cmCTest::SetTest(const char* ttype
, bool report
)
625 if ( cmSystemTools::LowerCase(ttype
) == "all" )
627 this->Tests
[cmCTest::ALL_TEST
] = 1;
629 else if ( cmSystemTools::LowerCase(ttype
) == "start" )
631 this->Tests
[cmCTest::START_TEST
] = 1;
633 else if ( cmSystemTools::LowerCase(ttype
) == "update" )
635 this->Tests
[cmCTest::UPDATE_TEST
] = 1;
637 else if ( cmSystemTools::LowerCase(ttype
) == "configure" )
639 this->Tests
[cmCTest::CONFIGURE_TEST
] = 1;
641 else if ( cmSystemTools::LowerCase(ttype
) == "build" )
643 this->Tests
[cmCTest::BUILD_TEST
] = 1;
645 else if ( cmSystemTools::LowerCase(ttype
) == "test" )
647 this->Tests
[cmCTest::TEST_TEST
] = 1;
649 else if ( cmSystemTools::LowerCase(ttype
) == "coverage" )
651 this->Tests
[cmCTest::COVERAGE_TEST
] = 1;
653 else if ( cmSystemTools::LowerCase(ttype
) == "memcheck" )
655 this->Tests
[cmCTest::MEMCHECK_TEST
] = 1;
657 else if ( cmSystemTools::LowerCase(ttype
) == "notes" )
659 this->Tests
[cmCTest::NOTES_TEST
] = 1;
661 else if ( cmSystemTools::LowerCase(ttype
) == "submit" )
663 this->Tests
[cmCTest::SUBMIT_TEST
] = 1;
669 cmCTestLog(this, ERROR_MESSAGE
, "Don't know about test \"" << ttype
670 << "\" yet..." << std::endl
);
677 //----------------------------------------------------------------------
678 void cmCTest::Finalize()
682 //----------------------------------------------------------------------
683 bool cmCTest::OpenOutputFile(const std::string
& path
,
684 const std::string
& name
, cmGeneratedFileStream
& stream
,
687 std::string testingDir
= this->BinaryDir
+ "/Testing";
688 if ( path
.size() > 0 )
690 testingDir
+= "/" + path
;
692 if ( cmSystemTools::FileExists(testingDir
.c_str()) )
694 if ( !cmSystemTools::FileIsDirectory(testingDir
.c_str()) )
696 cmCTestLog(this, ERROR_MESSAGE
, "File " << testingDir
697 << " is in the place of the testing directory"
704 if ( !cmSystemTools::MakeDirectory(testingDir
.c_str()) )
706 cmCTestLog(this, ERROR_MESSAGE
, "Cannot create directory " << testingDir
711 std::string filename
= testingDir
+ "/" + name
;
712 stream
.Open(filename
.c_str());
715 cmCTestLog(this, ERROR_MESSAGE
, "Problem opening file: " << filename
721 if ( this->CompressXMLFiles
)
723 stream
.SetCompression(true);
729 //----------------------------------------------------------------------
730 bool cmCTest::AddIfExists(SetOfStrings
& files
, const char* file
)
732 if ( this->CTestFileExists(file
) )
738 std::string name
= file
;
740 if ( this->CTestFileExists(name
.c_str()) )
742 files
.insert(name
.c_str());
752 //----------------------------------------------------------------------
753 bool cmCTest::CTestFileExists(const std::string
& filename
)
755 std::string testingDir
= this->BinaryDir
+ "/Testing/" +
756 this->CurrentTag
+ "/" + filename
;
757 return cmSystemTools::FileExists(testingDir
.c_str());
760 //----------------------------------------------------------------------
761 cmCTestGenericHandler
* cmCTest::GetInitializedHandler(const char* handler
)
763 cmCTest::t_TestingHandlers::iterator it
=
764 this->TestingHandlers
.find(handler
);
765 if ( it
== this->TestingHandlers
.end() )
769 it
->second
->Initialize();
773 //----------------------------------------------------------------------
774 cmCTestGenericHandler
* cmCTest::GetHandler(const char* handler
)
776 cmCTest::t_TestingHandlers::iterator it
=
777 this->TestingHandlers
.find(handler
);
778 if ( it
== this->TestingHandlers
.end() )
785 //----------------------------------------------------------------------
786 int cmCTest::ExecuteHandler(const char* shandler
)
788 cmCTestGenericHandler
* handler
= this->GetHandler(shandler
);
793 handler
->Initialize();
794 return handler
->ProcessHandler();
797 //----------------------------------------------------------------------
798 int cmCTest::ProcessTests()
803 int update_count
= 0;
805 cmCTestLog(this, OUTPUT
, "Start processing tests" << std::endl
);
807 for ( cc
= 0; cc
< LAST_TEST
; cc
++ )
809 if ( this->Tests
[cc
] )
815 if (( this->Tests
[UPDATE_TEST
] || this->Tests
[ALL_TEST
] ) &&
816 (this->GetRemainingTimeAllowed() - 120 > 0))
818 cmCTestGenericHandler
* uphandler
= this->GetHandler("update");
819 uphandler
->SetPersistentOption("SourceDirectory",
820 this->GetCTestConfiguration("SourceDirectory").c_str());
821 update_count
= uphandler
->ProcessHandler();
822 if ( update_count
< 0 )
824 res
|= cmCTest::UPDATE_ERRORS
;
827 if ( this->TestModel
== cmCTest::CONTINUOUS
&& !update_count
)
831 if (( this->Tests
[CONFIGURE_TEST
] || this->Tests
[ALL_TEST
] )&&
832 (this->GetRemainingTimeAllowed() - 120 > 0))
834 if (this->GetHandler("configure")->ProcessHandler() < 0)
836 res
|= cmCTest::CONFIGURE_ERRORS
;
839 if (( this->Tests
[BUILD_TEST
] || this->Tests
[ALL_TEST
] )&&
840 (this->GetRemainingTimeAllowed() - 120 > 0))
842 this->UpdateCTestConfiguration();
843 if (this->GetHandler("build")->ProcessHandler() < 0)
845 res
|= cmCTest::BUILD_ERRORS
;
848 if (( this->Tests
[TEST_TEST
] || this->Tests
[ALL_TEST
] || notest
) &&
849 (this->GetRemainingTimeAllowed() - 120 > 0))
851 this->UpdateCTestConfiguration();
852 if (this->GetHandler("test")->ProcessHandler() < 0)
854 res
|= cmCTest::TEST_ERRORS
;
857 if (( this->Tests
[COVERAGE_TEST
] || this->Tests
[ALL_TEST
] ) &&
858 (this->GetRemainingTimeAllowed() - 120 > 0))
860 this->UpdateCTestConfiguration();
861 if (this->GetHandler("coverage")->ProcessHandler() < 0)
863 res
|= cmCTest::COVERAGE_ERRORS
;
866 if (( this->Tests
[MEMCHECK_TEST
] || this->Tests
[ALL_TEST
] )&&
867 (this->GetRemainingTimeAllowed() - 120 > 0))
869 this->UpdateCTestConfiguration();
870 if (this->GetHandler("memcheck")->ProcessHandler() < 0)
872 res
|= cmCTest::MEMORY_ERRORS
;
877 std::string notes_dir
= this->BinaryDir
+ "/Testing/Notes";
878 if ( cmSystemTools::FileIsDirectory(notes_dir
.c_str()) )
881 d
.Load(notes_dir
.c_str());
883 for ( kk
= 0; kk
< d
.GetNumberOfFiles(); kk
++ )
885 const char* file
= d
.GetFile(kk
);
886 std::string fullname
= notes_dir
+ "/" + file
;
887 if ( cmSystemTools::FileExists(fullname
.c_str()) &&
888 !cmSystemTools::FileIsDirectory(fullname
.c_str()) )
890 if ( this->NotesFiles
.size() > 0 )
892 this->NotesFiles
+= ";";
894 this->NotesFiles
+= fullname
;
895 this->Tests
[NOTES_TEST
] = 1;
900 if ( this->Tests
[NOTES_TEST
] || this->Tests
[ALL_TEST
] )
902 this->UpdateCTestConfiguration();
903 if ( this->NotesFiles
.size() )
905 this->GenerateNotesFile(this->NotesFiles
.c_str());
908 if ( this->Tests
[SUBMIT_TEST
] || this->Tests
[ALL_TEST
] )
910 this->UpdateCTestConfiguration();
911 if (this->GetHandler("submit")->ProcessHandler() < 0)
913 res
|= cmCTest::SUBMIT_ERRORS
;
918 cmCTestLog(this, ERROR_MESSAGE
, "Errors while running CTest"
924 //----------------------------------------------------------------------
925 std::string
cmCTest::GetTestModelString()
927 if ( !this->SpecificTrack
.empty() )
929 return this->SpecificTrack
;
931 switch ( this->TestModel
)
933 case cmCTest::NIGHTLY
:
935 case cmCTest::CONTINUOUS
:
938 return "Experimental";
941 //----------------------------------------------------------------------
942 int cmCTest::GetTestModelFromString(const char* str
)
946 return cmCTest::EXPERIMENTAL
;
948 std::string rstr
= cmSystemTools::LowerCase(str
);
949 if ( strncmp(rstr
.c_str(), "cont", 4) == 0 )
951 return cmCTest::CONTINUOUS
;
953 if ( strncmp(rstr
.c_str(), "nigh", 4) == 0 )
955 return cmCTest::NIGHTLY
;
957 return cmCTest::EXPERIMENTAL
;
960 //######################################################################
961 //######################################################################
962 //######################################################################
963 //######################################################################
965 //----------------------------------------------------------------------
966 int cmCTest::RunMakeCommand(const char* command
, std::string
* output
,
967 int* retVal
, const char* dir
, int timeout
, std::ofstream
& ofs
)
969 // First generate the command and arguments
970 std::vector
<cmStdString
> args
= cmSystemTools::ParseArguments(command
);
977 std::vector
<const char*> argv
;
978 for(std::vector
<cmStdString
>::const_iterator a
= args
.begin();
979 a
!= args
.end(); ++a
)
981 argv
.push_back(a
->c_str());
990 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, "Run command:");
991 std::vector
<const char*>::iterator ait
;
992 for ( ait
= argv
.begin(); ait
!= argv
.end() && *ait
; ++ ait
)
994 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, " \"" << *ait
<< "\"");
996 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, std::endl
);
998 // Now create process object
999 cmsysProcess
* cp
= cmsysProcess_New();
1000 cmsysProcess_SetCommand(cp
, &*argv
.begin());
1001 cmsysProcess_SetWorkingDirectory(cp
, dir
);
1002 cmsysProcess_SetOption(cp
, cmsysProcess_Option_HideWindow
, 1);
1003 cmsysProcess_SetTimeout(cp
, timeout
);
1004 cmsysProcess_Execute(cp
);
1006 // Initialize tick's
1007 std::string::size_type tick
= 0;
1008 std::string::size_type tick_len
= 1024;
1009 std::string::size_type tick_line_len
= 50;
1013 cmCTestLog(this, HANDLER_OUTPUT
,
1014 " Each . represents " << tick_len
<< " bytes of output" << std::endl
1015 << " " << std::flush
);
1016 while(cmsysProcess_WaitForData(cp
, &data
, &length
, 0))
1020 for(int cc
=0; cc
< length
; ++cc
)
1028 output
->append(data
, length
);
1029 while ( output
->size() > (tick
* tick_len
) )
1032 cmCTestLog(this, HANDLER_OUTPUT
, "." << std::flush
);
1033 if ( tick
% tick_line_len
== 0 && tick
> 0 )
1035 cmCTestLog(this, HANDLER_OUTPUT
, " Size: "
1036 << int((output
->size() / 1024.0) + 1) << "K" << std::endl
1037 << " " << std::flush
);
1041 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, cmCTestLogWrite(data
, length
));
1044 ofs
<< cmCTestLogWrite(data
, length
);
1047 cmCTestLog(this, OUTPUT
, " Size of output: "
1048 << int(output
->size() / 1024.0) << "K" << std::endl
);
1050 cmsysProcess_WaitForExit(cp
, 0);
1052 int result
= cmsysProcess_GetState(cp
);
1054 if(result
== cmsysProcess_State_Exited
)
1056 *retVal
= cmsysProcess_GetExitValue(cp
);
1057 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, "Command exited with the value: "
1058 << *retVal
<< std::endl
);
1060 else if(result
== cmsysProcess_State_Exception
)
1062 *retVal
= cmsysProcess_GetExitException(cp
);
1063 cmCTestLog(this, WARNING
, "There was an exception: " << *retVal
1066 else if(result
== cmsysProcess_State_Expired
)
1068 cmCTestLog(this, WARNING
, "There was a timeout" << std::endl
);
1070 else if(result
== cmsysProcess_State_Error
)
1072 *output
+= "\n*** ERROR executing: ";
1073 *output
+= cmsysProcess_GetErrorString(cp
);
1074 *output
+= "\n***The build process failed.";
1075 cmCTestLog(this, ERROR_MESSAGE
, "There was an error: "
1076 << cmsysProcess_GetErrorString(cp
) << std::endl
);
1079 cmsysProcess_Delete(cp
);
1084 //######################################################################
1085 //######################################################################
1086 //######################################################################
1087 //######################################################################
1089 //----------------------------------------------------------------------
1090 int cmCTest::RunTest(std::vector
<const char*> argv
,
1091 std::string
* output
, int *retVal
,
1092 std::ostream
* log
, double testTimeOut
)
1094 // determine how much time we have
1095 double timeout
= this->GetRemainingTimeAllowed() - 120;
1096 if (this->TimeOut
&& this->TimeOut
< timeout
)
1098 timeout
= this->TimeOut
;
1101 && testTimeOut
< this->GetRemainingTimeAllowed())
1103 timeout
= testTimeOut
;
1106 // always have at least 1 second if we got to here
1111 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
,
1112 "Test timeout computed to be: " << timeout
<< "\n");
1113 if(cmSystemTools::SameFile(argv
[0], this->CTestSelf
.c_str()) &&
1114 !this->ForceNewCTestProcess
)
1117 inst
.ConfigType
= this->ConfigType
;
1118 inst
.TimeOut
= timeout
;
1119 std::vector
<std::string
> args
;
1120 for(unsigned int i
=0; i
< argv
.size(); ++i
)
1124 // make sure we pass the timeout in for any build and test
1125 // invocations. Since --build-generator is required this is a
1126 // good place to check for it, and to add the arguments in
1127 if (strcmp(argv
[i
],"--build-generator") == 0 && timeout
)
1129 args
.push_back("--test-timeout");
1130 cmOStringStream msg
;
1132 args
.push_back(msg
.str());
1134 args
.push_back(argv
[i
]);
1139 *log
<< "* Run internal CTest" << std::endl
;
1141 std::string oldpath
= cmSystemTools::GetCurrentWorkingDirectory();
1143 *retVal
= inst
.Run(args
, output
);
1146 *log
<< output
->c_str();
1148 cmSystemTools::ChangeDirectory(oldpath
.c_str());
1150 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
,
1151 "Internal cmCTest object used to run test." << std::endl
1152 << *output
<< std::endl
);
1153 return cmsysProcess_State_Exited
;
1155 std::vector
<char> tempOutput
;
1161 cmsysProcess
* cp
= cmsysProcess_New();
1162 cmsysProcess_SetCommand(cp
, &*argv
.begin());
1163 cmCTestLog(this, DEBUG
, "Command is: " << argv
[0] << std::endl
);
1164 if(cmSystemTools::GetRunCommandHideConsole())
1166 cmsysProcess_SetOption(cp
, cmsysProcess_Option_HideWindow
, 1);
1169 cmsysProcess_SetTimeout(cp
, timeout
);
1170 cmsysProcess_Execute(cp
);
1174 while(cmsysProcess_WaitForData(cp
, &data
, &length
, 0))
1178 tempOutput
.insert(tempOutput
.end(), data
, data
+length
);
1180 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, cmCTestLogWrite(data
, length
));
1183 log
->write(data
, length
);
1187 cmsysProcess_WaitForExit(cp
, 0);
1188 if(output
&& tempOutput
.begin() != tempOutput
.end())
1190 output
->append(&*tempOutput
.begin(), tempOutput
.size());
1192 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, "-- Process completed"
1195 int result
= cmsysProcess_GetState(cp
);
1197 if(result
== cmsysProcess_State_Exited
)
1199 *retVal
= cmsysProcess_GetExitValue(cp
);
1201 else if(result
== cmsysProcess_State_Exception
)
1203 *retVal
= cmsysProcess_GetExitException(cp
);
1204 std::string outerr
= "\n*** Exception executing: ";
1205 outerr
+= cmsysProcess_GetExceptionString(cp
);
1207 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, outerr
.c_str() << std::endl
1210 else if(result
== cmsysProcess_State_Error
)
1212 std::string outerr
= "\n*** ERROR executing: ";
1213 outerr
+= cmsysProcess_GetErrorString(cp
);
1215 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, outerr
.c_str() << std::endl
1218 cmsysProcess_Delete(cp
);
1223 //----------------------------------------------------------------------
1224 void cmCTest::StartXML(std::ostream
& ostr
)
1226 if(this->CurrentTag
.empty())
1228 cmCTestLog(this, ERROR_MESSAGE
,
1229 "Current Tag empty, this may mean"
1230 " NightlStartTime was not set correctly." << std::endl
);
1231 cmSystemTools::SetFatalErrorOccured();
1233 // find out about the system
1234 cmsys::SystemInformation info
;
1237 info
.RunMemoryCheck();
1238 ostr
<< "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1239 << "<Site BuildName=\"" << this->GetCTestConfiguration("BuildName")
1240 << "\"\n\tBuildStamp=\"" << this->CurrentTag
<< "-"
1241 << this->GetTestModelString() << "\"\n\tName=\""
1242 << this->GetCTestConfiguration("Site") << "\"\n\tGenerator=\"ctest"
1243 << cmVersion::GetCMakeVersion() << "\""
1244 << "\tOSName=\"" << info
.GetOSName() << "\"\n"
1245 << "\tHostname=\"" << info
.GetHostname() << "\"\n"
1246 << "\tOSRelease=\"" << info
.GetOSRelease() << "\"\n"
1247 << "\tOSVersion=\"" << info
.GetOSVersion() << "\"\n"
1248 << "\tOSPlatform=\"" << info
.GetOSPlatform() << "\"\n"
1249 << "\tIs64Bits=\"" << info
.Is64Bits() << "\"\n"
1250 << "\tVendorString=\"" << info
.GetVendorString() << "\"\n"
1251 << "\tVendorID=\"" << info
.GetVendorID() << "\"\n"
1252 << "\tFamilyID=\"" << info
.GetFamilyID() << "\"\n"
1253 << "\tModelID=\"" << info
.GetModelID() << "\"\n"
1254 << "\tProcessorCacheSize=\"" << info
.GetProcessorCacheSize() << "\"\n"
1255 << "\tNumberOfLogicalCPU=\"" << info
.GetNumberOfLogicalCPU() << "\"\n"
1256 << "\tNumberOfPhysicalCPU=\""<< info
.GetNumberOfPhysicalCPU() << "\"\n"
1257 << "\tTotalVirtualMemory=\"" << info
.GetTotalVirtualMemory() << "\"\n"
1258 << "\tTotalPhysicalMemory=\""<< info
.GetTotalPhysicalMemory() << "\"\n"
1259 << "\tLogicalProcessorsPerPhysical=\""
1260 << info
.GetLogicalProcessorsPerPhysical() << "\"\n"
1261 << "\tProcessorClockFrequency=\""
1262 << info
.GetProcessorClockFrequency() << "\"\n"
1263 << ">" << std::endl
;
1266 //----------------------------------------------------------------------
1267 void cmCTest::EndXML(std::ostream
& ostr
)
1269 ostr
<< "</Site>" << std::endl
;
1272 //----------------------------------------------------------------------
1273 int cmCTest::GenerateCTestNotesOutput(std::ostream
& os
,
1274 const cmCTest::VectorOfStrings
& files
)
1276 cmCTest::VectorOfStrings::const_iterator it
;
1277 os
<< "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1278 << "<?xml-stylesheet type=\"text/xsl\" "
1279 "href=\"Dart/Source/Server/XSL/Build.xsl "
1280 "<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
1281 << "<Site BuildName=\"" << this->GetCTestConfiguration("BuildName")
1282 << "\" BuildStamp=\""
1283 << this->CurrentTag
<< "-" << this->GetTestModelString() << "\" Name=\""
1284 << this->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
1285 << cmVersion::GetCMakeVersion()
1287 << "<Notes>" << std::endl
;
1289 for ( it
= files
.begin(); it
!= files
.end(); it
++ )
1291 cmCTestLog(this, OUTPUT
, "\tAdd file: " << it
->c_str() << std::endl
);
1292 std::string note_time
= this->CurrentTime();
1293 os
<< "<Note Name=\"" << this->MakeXMLSafe(it
->c_str()) << "\">\n"
1294 << "<Time>" << cmSystemTools::GetTime() << "</Time>\n"
1295 << "<DateTime>" << note_time
<< "</DateTime>\n"
1296 << "<Text>" << std::endl
;
1297 std::ifstream
ifs(it
->c_str());
1301 while ( cmSystemTools::GetLineFromStream(ifs
, line
) )
1303 os
<< this->MakeXMLSafe(line
) << std::endl
;
1309 os
<< "Problem reading file: " << it
->c_str() << std::endl
;
1310 cmCTestLog(this, ERROR_MESSAGE
, "Problem reading file: " << it
->c_str()
1311 << " while creating notes" << std::endl
);
1314 << "</Note>" << std::endl
;
1317 << "</Site>" << std::endl
;
1321 //----------------------------------------------------------------------
1322 int cmCTest::GenerateNotesFile(const std::vector
<cmStdString
> &files
)
1324 cmGeneratedFileStream ofs
;
1325 if ( !this->OpenOutputFile(this->CurrentTag
, "Notes.xml", ofs
) )
1327 cmCTestLog(this, ERROR_MESSAGE
, "Cannot open notes file" << std::endl
);
1331 this->GenerateCTestNotesOutput(ofs
, files
);
1335 //----------------------------------------------------------------------
1336 int cmCTest::GenerateNotesFile(const char* cfiles
)
1343 std::vector
<cmStdString
> files
;
1345 cmCTestLog(this, OUTPUT
, "Create notes file" << std::endl
);
1347 files
= cmSystemTools::SplitString(cfiles
, ';');
1348 if ( files
.size() == 0 )
1353 return this->GenerateNotesFile(files
);
1356 //----------------------------------------------------------------------
1357 bool cmCTest::SubmitExtraFiles(const std::vector
<cmStdString
> &files
)
1359 std::vector
<cmStdString
>::const_iterator it
;
1360 for ( it
= files
.begin();
1364 if ( !cmSystemTools::FileExists(it
->c_str()) )
1366 cmCTestLog(this, ERROR_MESSAGE
, "Cannot find extra file: "
1367 << it
->c_str() << " to submit."
1371 this->AddSubmitFile(it
->c_str());
1376 //----------------------------------------------------------------------
1377 bool cmCTest::SubmitExtraFiles(const char* cfiles
)
1384 std::vector
<cmStdString
> files
;
1386 cmCTestLog(this, OUTPUT
, "Submit extra files" << std::endl
);
1388 files
= cmSystemTools::SplitString(cfiles
, ';');
1389 if ( files
.size() == 0 )
1394 return this->SubmitExtraFiles(files
);
1398 //-------------------------------------------------------
1399 // for a -D argument convert the next argument into
1400 // the proper list of dashboard steps via SetTest
1401 bool cmCTest::AddTestsForDashboardType(std::string
&targ
)
1403 if ( targ
== "Experimental" )
1405 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1406 this->SetTest("Start");
1407 this->SetTest("Configure");
1408 this->SetTest("Build");
1409 this->SetTest("Test");
1410 this->SetTest("Coverage");
1411 this->SetTest("Submit");
1413 else if ( targ
== "ExperimentalStart" )
1415 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1416 this->SetTest("Start");
1418 else if ( targ
== "ExperimentalUpdate" )
1420 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1421 this->SetTest("Update");
1423 else if ( targ
== "ExperimentalConfigure" )
1425 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1426 this->SetTest("Configure");
1428 else if ( targ
== "ExperimentalBuild" )
1430 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1431 this->SetTest("Build");
1433 else if ( targ
== "ExperimentalTest" )
1435 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1436 this->SetTest("Test");
1438 else if ( targ
== "ExperimentalMemCheck"
1439 || targ
== "ExperimentalPurify" )
1441 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1442 this->SetTest("MemCheck");
1444 else if ( targ
== "ExperimentalCoverage" )
1446 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1447 this->SetTest("Coverage");
1449 else if ( targ
== "ExperimentalSubmit" )
1451 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1452 this->SetTest("Submit");
1454 else if ( targ
== "Continuous" )
1456 this->SetTestModel(cmCTest::CONTINUOUS
);
1457 this->SetTest("Start");
1458 this->SetTest("Update");
1459 this->SetTest("Configure");
1460 this->SetTest("Build");
1461 this->SetTest("Test");
1462 this->SetTest("Coverage");
1463 this->SetTest("Submit");
1465 else if ( targ
== "ContinuousStart" )
1467 this->SetTestModel(cmCTest::CONTINUOUS
);
1468 this->SetTest("Start");
1470 else if ( targ
== "ContinuousUpdate" )
1472 this->SetTestModel(cmCTest::CONTINUOUS
);
1473 this->SetTest("Update");
1475 else if ( targ
== "ContinuousConfigure" )
1477 this->SetTestModel(cmCTest::CONTINUOUS
);
1478 this->SetTest("Configure");
1480 else if ( targ
== "ContinuousBuild" )
1482 this->SetTestModel(cmCTest::CONTINUOUS
);
1483 this->SetTest("Build");
1485 else if ( targ
== "ContinuousTest" )
1487 this->SetTestModel(cmCTest::CONTINUOUS
);
1488 this->SetTest("Test");
1490 else if ( targ
== "ContinuousMemCheck"
1491 || targ
== "ContinuousPurify" )
1493 this->SetTestModel(cmCTest::CONTINUOUS
);
1494 this->SetTest("MemCheck");
1496 else if ( targ
== "ContinuousCoverage" )
1498 this->SetTestModel(cmCTest::CONTINUOUS
);
1499 this->SetTest("Coverage");
1501 else if ( targ
== "ContinuousSubmit" )
1503 this->SetTestModel(cmCTest::CONTINUOUS
);
1504 this->SetTest("Submit");
1506 else if ( targ
== "Nightly" )
1508 this->SetTestModel(cmCTest::NIGHTLY
);
1509 this->SetTest("Start");
1510 this->SetTest("Update");
1511 this->SetTest("Configure");
1512 this->SetTest("Build");
1513 this->SetTest("Test");
1514 this->SetTest("Coverage");
1515 this->SetTest("Submit");
1517 else if ( targ
== "NightlyStart" )
1519 this->SetTestModel(cmCTest::NIGHTLY
);
1520 this->SetTest("Start");
1522 else if ( targ
== "NightlyUpdate" )
1524 this->SetTestModel(cmCTest::NIGHTLY
);
1525 this->SetTest("Update");
1527 else if ( targ
== "NightlyConfigure" )
1529 this->SetTestModel(cmCTest::NIGHTLY
);
1530 this->SetTest("Configure");
1532 else if ( targ
== "NightlyBuild" )
1534 this->SetTestModel(cmCTest::NIGHTLY
);
1535 this->SetTest("Build");
1537 else if ( targ
== "NightlyTest" )
1539 this->SetTestModel(cmCTest::NIGHTLY
);
1540 this->SetTest("Test");
1542 else if ( targ
== "NightlyMemCheck"
1543 || targ
== "NightlyPurify" )
1545 this->SetTestModel(cmCTest::NIGHTLY
);
1546 this->SetTest("MemCheck");
1548 else if ( targ
== "NightlyCoverage" )
1550 this->SetTestModel(cmCTest::NIGHTLY
);
1551 this->SetTest("Coverage");
1553 else if ( targ
== "NightlySubmit" )
1555 this->SetTestModel(cmCTest::NIGHTLY
);
1556 this->SetTest("Submit");
1558 else if ( targ
== "MemoryCheck" )
1560 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1561 this->SetTest("Start");
1562 this->SetTest("Configure");
1563 this->SetTest("Build");
1564 this->SetTest("MemCheck");
1565 this->SetTest("Coverage");
1566 this->SetTest("Submit");
1568 else if ( targ
== "NightlyMemoryCheck" )
1570 this->SetTestModel(cmCTest::NIGHTLY
);
1571 this->SetTest("Start");
1572 this->SetTest("Update");
1573 this->SetTest("Configure");
1574 this->SetTest("Build");
1575 this->SetTest("MemCheck");
1576 this->SetTest("Coverage");
1577 this->SetTest("Submit");
1581 cmCTestLog(this, ERROR_MESSAGE
,
1582 "CTest -D called with incorrect option: "
1583 << targ
<< std::endl
);
1584 cmCTestLog(this, ERROR_MESSAGE
, "Available options are:" << std::endl
1585 << " " << "ctest" << " -D Continuous" << std::endl
1587 << " -D Continuous(Start|Update|Configure|Build)" << std::endl
1589 << " -D Continuous(Test|Coverage|MemCheck|Submit)"
1591 << " " << "ctest" << " -D Experimental" << std::endl
1593 << " -D Experimental(Start|Update|Configure|Build)"
1596 << " -D Experimental(Test|Coverage|MemCheck|Submit)"
1598 << " " << "ctest" << " -D Nightly" << std::endl
1600 << " -D Nightly(Start|Update|Configure|Build)" << std::endl
1602 << " -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
1603 << " " << "ctest" << " -D NightlyMemoryCheck" << std::endl
);
1610 //----------------------------------------------------------------------
1611 bool cmCTest::CheckArgument(const std::string
& arg
, const char* varg1
,
1614 if ( varg1
&& arg
== varg1
|| varg2
&& arg
== varg2
)
1622 //----------------------------------------------------------------------
1623 // Processes one command line argument (and its arguments if any)
1624 // for many simple options and then returns
1625 void cmCTest::HandleCommandLineArguments(size_t &i
,
1626 std::vector
<std::string
> &args
)
1628 std::string arg
= args
[i
];
1629 if(this->CheckArgument(arg
, "--ctest-config") && i
< args
.size() - 1)
1632 this->CTestConfigFile
= args
[i
];
1635 if(this->CheckArgument(arg
, "-C", "--build-config") &&
1636 i
< args
.size() - 1)
1639 this->SetConfigType(args
[i
].c_str());
1642 if(this->CheckArgument(arg
, "--debug"))
1645 this->ShowLineNumbers
= true;
1647 if(this->CheckArgument(arg
, "--track") && i
< args
.size() - 1)
1650 this->SpecificTrack
= args
[i
];
1652 if(this->CheckArgument(arg
, "--show-line-numbers"))
1654 this->ShowLineNumbers
= true;
1656 if(this->CheckArgument(arg
, "-Q", "--quiet"))
1660 if(this->CheckArgument(arg
, "-V", "--verbose"))
1662 this->Verbose
= true;
1664 if(this->CheckArgument(arg
, "-VV", "--extra-verbose"))
1666 this->ExtraVerbose
= true;
1667 this->Verbose
= true;
1670 if(this->CheckArgument(arg
, "-N", "--show-only"))
1672 this->ShowOnly
= true;
1675 if(this->CheckArgument(arg
, "-O", "--output-log") && i
< args
.size() - 1 )
1678 this->SetOutputLogFileName(args
[i
].c_str());
1681 if(this->CheckArgument(arg
, "--tomorrow-tag"))
1683 this->TomorrowTag
= true;
1685 if(this->CheckArgument(arg
, "--force-new-ctest-process"))
1687 this->ForceNewCTestProcess
= true;
1689 if(this->CheckArgument(arg
, "--interactive-debug-mode") &&
1690 i
< args
.size() - 1 )
1693 this->InteractiveDebugMode
= cmSystemTools::IsOn(args
[i
].c_str());
1695 if(this->CheckArgument(arg
, "--submit-index") && i
< args
.size() - 1 )
1698 this->SubmitIndex
= atoi(args
[i
].c_str());
1699 if ( this->SubmitIndex
< 0 )
1701 this->SubmitIndex
= 0;
1705 if(this->CheckArgument(arg
, "--overwrite") && i
< args
.size() - 1)
1708 this->AddCTestConfigurationOverwrite(args
[i
].c_str());
1710 if(this->CheckArgument(arg
, "-A", "--add-notes") && i
< args
.size() - 1)
1712 this->ProduceXML
= true;
1713 this->SetTest("Notes");
1715 this->SetNotesFiles(args
[i
].c_str());
1718 // options that control what tests are run
1719 if(this->CheckArgument(arg
, "-I", "--tests-information") &&
1720 i
< args
.size() - 1)
1723 this->GetHandler("test")->SetPersistentOption("TestsToRunInformation",
1725 this->GetHandler("memcheck")->
1726 SetPersistentOption("TestsToRunInformation",args
[i
].c_str());
1728 if(this->CheckArgument(arg
, "-U", "--union"))
1730 this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
1731 this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
1733 if(this->CheckArgument(arg
, "-R", "--tests-regex") && i
< args
.size() - 1)
1736 this->GetHandler("test")->
1737 SetPersistentOption("IncludeRegularExpression", args
[i
].c_str());
1738 this->GetHandler("memcheck")->
1739 SetPersistentOption("IncludeRegularExpression", args
[i
].c_str());
1742 if(this->CheckArgument(arg
, "-E", "--exclude-regex") &&
1743 i
< args
.size() - 1)
1746 this->GetHandler("test")->
1747 SetPersistentOption("ExcludeRegularExpression", args
[i
].c_str());
1748 this->GetHandler("memcheck")->
1749 SetPersistentOption("ExcludeRegularExpression", args
[i
].c_str());
1753 //----------------------------------------------------------------------
1754 // handle the -S -SR and -SP arguments
1755 void cmCTest::HandleScriptArguments(size_t &i
,
1756 std::vector
<std::string
> &args
,
1757 bool &SRArgumentSpecified
)
1759 std::string arg
= args
[i
];
1760 if(this->CheckArgument(arg
, "-SP", "--script-new-process") &&
1761 i
< args
.size() - 1 )
1763 this->RunConfigurationScript
= true;
1765 cmCTestScriptHandler
* ch
1766 = static_cast<cmCTestScriptHandler
*>(this->GetHandler("script"));
1767 // -SR is an internal argument, -SP should be ignored when it is passed
1768 if (!SRArgumentSpecified
)
1770 ch
->AddConfigurationScript(args
[i
].c_str(),false);
1774 if(this->CheckArgument(arg
, "-SR", "--script-run") &&
1775 i
< args
.size() - 1 )
1777 SRArgumentSpecified
= true;
1778 this->RunConfigurationScript
= true;
1780 cmCTestScriptHandler
* ch
1781 = static_cast<cmCTestScriptHandler
*>(this->GetHandler("script"));
1782 ch
->AddConfigurationScript(args
[i
].c_str(),true);
1785 if(this->CheckArgument(arg
, "-S", "--script") && i
< args
.size() - 1 )
1787 this->RunConfigurationScript
= true;
1789 cmCTestScriptHandler
* ch
1790 = static_cast<cmCTestScriptHandler
*>(this->GetHandler("script"));
1791 // -SR is an internal argument, -S should be ignored when it is passed
1792 if (!SRArgumentSpecified
)
1794 ch
->AddConfigurationScript(args
[i
].c_str(),true);
1799 //----------------------------------------------------------------------
1800 // the main entry point of ctest, called from main
1801 int cmCTest::Run(std::vector
<std::string
> &args
, std::string
* output
)
1803 this->FindRunningCMake();
1804 const char* ctestExec
= "ctest";
1805 bool cmakeAndTest
= false;
1806 bool performSomeTest
= true;
1807 bool SRArgumentSpecified
= false;
1809 // copy the command line
1810 for(size_t i
=0; i
< args
.size(); ++i
)
1812 this->InitialCommandLineArguments
.push_back(args
[i
]);
1815 // process the command line arguments
1816 for(size_t i
=1; i
< args
.size(); ++i
)
1818 // handle the simple commandline arguments
1819 this->HandleCommandLineArguments(i
,args
);
1821 // handle the script arguments -S -SR -SP
1822 this->HandleScriptArguments(i
,args
,SRArgumentSpecified
);
1824 // handle a request for a dashboard
1825 std::string arg
= args
[i
];
1826 if(this->CheckArgument(arg
, "-D", "--dashboard") && i
< args
.size() - 1 )
1828 this->ProduceXML
= true;
1830 std::string targ
= args
[i
];
1831 // AddTestsForDashboard parses the dashborad type and converts it
1832 // into the seperate stages
1833 if (!this->AddTestsForDashboardType(targ
))
1835 performSomeTest
= false;
1839 if(this->CheckArgument(arg
, "-T", "--test-action") &&
1840 (i
< args
.size() -1) )
1842 this->ProduceXML
= true;
1844 if ( !this->SetTest(args
[i
].c_str(), false) )
1846 performSomeTest
= false;
1847 cmCTestLog(this, ERROR_MESSAGE
,
1848 "CTest -T called with incorrect option: "
1849 << args
[i
].c_str() << std::endl
);
1850 cmCTestLog(this, ERROR_MESSAGE
, "Available options are:" << std::endl
1851 << " " << ctestExec
<< " -T all" << std::endl
1852 << " " << ctestExec
<< " -T start" << std::endl
1853 << " " << ctestExec
<< " -T update" << std::endl
1854 << " " << ctestExec
<< " -T configure" << std::endl
1855 << " " << ctestExec
<< " -T build" << std::endl
1856 << " " << ctestExec
<< " -T test" << std::endl
1857 << " " << ctestExec
<< " -T coverage" << std::endl
1858 << " " << ctestExec
<< " -T memcheck" << std::endl
1859 << " " << ctestExec
<< " -T notes" << std::endl
1860 << " " << ctestExec
<< " -T submit" << std::endl
);
1864 // what type of test model
1865 if(this->CheckArgument(arg
, "-M", "--test-model") &&
1866 (i
< args
.size() -1) )
1869 std::string
const& str
= args
[i
];
1870 if ( cmSystemTools::LowerCase(str
) == "nightly" )
1872 this->SetTestModel(cmCTest::NIGHTLY
);
1874 else if ( cmSystemTools::LowerCase(str
) == "continuous" )
1876 this->SetTestModel(cmCTest::CONTINUOUS
);
1878 else if ( cmSystemTools::LowerCase(str
) == "experimental" )
1880 this->SetTestModel(cmCTest::EXPERIMENTAL
);
1884 performSomeTest
= false;
1885 cmCTestLog(this, ERROR_MESSAGE
,
1886 "CTest -M called with incorrect option: " << str
.c_str()
1888 cmCTestLog(this, ERROR_MESSAGE
, "Available options are:" << std::endl
1889 << " " << ctestExec
<< " -M Continuous" << std::endl
1890 << " " << ctestExec
<< " -M Experimental" << std::endl
1891 << " " << ctestExec
<< " -M Nightly" << std::endl
);
1895 if(this->CheckArgument(arg
, "--extra-submit") && i
< args
.size() - 1)
1897 this->ProduceXML
= true;
1898 this->SetTest("Submit");
1900 if ( !this->SubmitExtraFiles(args
[i
].c_str()) )
1906 // --build-and-test options
1907 if(this->CheckArgument(arg
, "--build-and-test") && i
< args
.size() - 1)
1909 cmakeAndTest
= true;
1912 // pass the argument to all the handlers as well, but i may no longer be
1913 // set to what it was originally so I'm not sure this is working as
1915 cmCTest::t_TestingHandlers::iterator it
;
1916 for ( it
= this->TestingHandlers
.begin();
1917 it
!= this->TestingHandlers
.end();
1920 if ( !it
->second
->ProcessCommandLineArguments(arg
, i
, args
) )
1922 cmCTestLog(this, ERROR_MESSAGE
,
1923 "Problem parsing command line arguments within a handler");
1927 } // the close of the for argument loop
1930 // now what sould cmake do? if --build-and-test was specified then
1931 // we run the build and test handler and return
1934 this->Verbose
= true;
1935 cmCTestBuildAndTestHandler
* handler
=
1936 static_cast<cmCTestBuildAndTestHandler
*>(this->GetHandler("buildtest"));
1937 int retv
= handler
->ProcessHandler();
1938 *output
= handler
->GetOutput();
1939 #ifdef CMAKE_BUILD_WITH_CMAKE
1940 cmDynamicLoader::FlushCache();
1945 // if some tests must be run
1949 // call process directory
1950 if (this->RunConfigurationScript
)
1952 if ( this->ExtraVerbose
)
1954 cmCTestLog(this, OUTPUT
, "* Extra verbosity turned on" << std::endl
);
1956 cmCTest::t_TestingHandlers::iterator it
;
1957 for ( it
= this->TestingHandlers
.begin();
1958 it
!= this->TestingHandlers
.end();
1961 it
->second
->SetVerbose(this->ExtraVerbose
);
1962 it
->second
->SetSubmitIndex(this->SubmitIndex
);
1964 this->GetHandler("script")->SetVerbose(this->Verbose
);
1965 res
= this->GetHandler("script")->ProcessHandler();
1969 this->ExtraVerbose
= this->Verbose
;
1970 this->Verbose
= true;
1971 cmCTest::t_TestingHandlers::iterator it
;
1972 for ( it
= this->TestingHandlers
.begin();
1973 it
!= this->TestingHandlers
.end();
1976 it
->second
->SetVerbose(this->Verbose
);
1977 it
->second
->SetSubmitIndex(this->SubmitIndex
);
1979 if ( !this->Initialize(
1980 cmSystemTools::GetCurrentWorkingDirectory().c_str()) )
1983 cmCTestLog(this, ERROR_MESSAGE
, "Problem initializing the dashboard."
1988 res
= this->ProcessTests();
1998 //----------------------------------------------------------------------
1999 void cmCTest::FindRunningCMake()
2001 // Find our own executable.
2002 this->CTestSelf
= cmSystemTools::GetExecutableDirectory();
2003 this->CTestSelf
+= "/ctest";
2004 this->CTestSelf
+= cmSystemTools::GetExecutableExtension();
2005 if(!cmSystemTools::FileExists(this->CTestSelf
.c_str()))
2007 cmSystemTools::Error("CTest executable cannot be found at ",
2008 this->CTestSelf
.c_str());
2011 this->CMakeSelf
= cmSystemTools::GetExecutableDirectory();
2012 this->CMakeSelf
+= "/cmake";
2013 this->CMakeSelf
+= cmSystemTools::GetExecutableExtension();
2014 if(!cmSystemTools::FileExists(this->CMakeSelf
.c_str()))
2016 cmSystemTools::Error("CMake executable cannot be found at ",
2017 this->CMakeSelf
.c_str());
2021 //----------------------------------------------------------------------
2022 void cmCTest::SetNotesFiles(const char* notes
)
2028 this->NotesFiles
= notes
;
2031 //----------------------------------------------------------------------
2032 int cmCTest::ReadCustomConfigurationFileTree(const char* dir
, cmMakefile
* mf
)
2035 VectorOfStrings dirs
;
2036 VectorOfStrings ndirs
;
2037 cmCTestLog(this, DEBUG
, "* Read custom CTest configuration directory: "
2038 << dir
<< std::endl
);
2040 std::string fname
= dir
;
2041 fname
+= "/CTestCustom.cmake";
2042 cmCTestLog(this, DEBUG
, "* Check for file: "
2043 << fname
.c_str() << std::endl
);
2044 if ( cmSystemTools::FileExists(fname
.c_str()) )
2046 cmCTestLog(this, DEBUG
, "* Read custom CTest configuration file: "
2047 << fname
.c_str() << std::endl
);
2048 bool erroroc
= cmSystemTools::GetErrorOccuredFlag();
2049 cmSystemTools::ResetErrorOccuredFlag();
2051 if ( !mf
->ReadListFile(0, fname
.c_str()) ||
2052 cmSystemTools::GetErrorOccuredFlag() )
2054 cmCTestLog(this, ERROR_MESSAGE
,
2055 "Problem reading custom configuration: "
2056 << fname
.c_str() << std::endl
);
2061 cmSystemTools::SetErrorOccured();
2065 std::string rexpr
= dir
;
2066 rexpr
+= "/CTestCustom.ctest";
2067 cmCTestLog(this, DEBUG
, "* Check for file: "
2068 << rexpr
.c_str() << std::endl
);
2069 if ( !found
&& cmSystemTools::FileExists(rexpr
.c_str()) )
2073 gl
.FindFiles(rexpr
);
2074 std::vector
<std::string
>& files
= gl
.GetFiles();
2075 std::vector
<std::string
>::iterator fileIt
;
2076 for ( fileIt
= files
.begin(); fileIt
!= files
.end();
2079 cmCTestLog(this, DEBUG
, "* Read custom CTest configuration file: "
2080 << fileIt
->c_str() << std::endl
);
2081 if ( !mf
->ReadListFile(0, fileIt
->c_str()) ||
2082 cmSystemTools::GetErrorOccuredFlag() )
2084 cmCTestLog(this, ERROR_MESSAGE
,
2085 "Problem reading custom configuration: "
2086 << fileIt
->c_str() << std::endl
);
2094 cmCTest::t_TestingHandlers::iterator it
;
2095 for ( it
= this->TestingHandlers
.begin();
2096 it
!= this->TestingHandlers
.end(); ++ it
)
2098 cmCTestLog(this, DEBUG
,
2099 "* Read custom CTest configuration vectors for handler: "
2100 << it
->first
.c_str() << " (" << it
->second
<< ")" << std::endl
);
2101 it
->second
->PopulateCustomVectors(mf
);
2108 //----------------------------------------------------------------------
2109 void cmCTest::PopulateCustomVector(cmMakefile
* mf
, const char* def
,
2110 VectorOfStrings
& vec
)
2116 const char* dval
= mf
->GetDefinition(def
);
2121 cmCTestLog(this, DEBUG
, "PopulateCustomVector: " << def
<< std::endl
);
2122 std::vector
<std::string
> slist
;
2123 cmSystemTools::ExpandListArgument(dval
, slist
);
2124 std::vector
<std::string
>::iterator it
;
2126 for ( it
= slist
.begin(); it
!= slist
.end(); ++it
)
2128 cmCTestLog(this, DEBUG
, " -- " << it
->c_str() << std::endl
);
2129 vec
.push_back(it
->c_str());
2133 //----------------------------------------------------------------------
2134 void cmCTest::PopulateCustomInteger(cmMakefile
* mf
, const char* def
, int& val
)
2140 const char* dval
= mf
->GetDefinition(def
);
2148 //----------------------------------------------------------------------
2149 std::string
cmCTest::GetShortPathToFile(const char* cfname
)
2151 const std::string
& sourceDir
2152 = cmSystemTools::CollapseFullPath(
2153 this->GetCTestConfiguration("SourceDirectory").c_str());
2154 const std::string
& buildDir
2155 = cmSystemTools::CollapseFullPath(
2156 this->GetCTestConfiguration("BuildDirectory").c_str());
2157 std::string fname
= cmSystemTools::CollapseFullPath(cfname
);
2159 // Find relative paths to both directories
2160 std::string srcRelpath
2161 = cmSystemTools::RelativePath(sourceDir
.c_str(), fname
.c_str());
2162 std::string bldRelpath
2163 = cmSystemTools::RelativePath(buildDir
.c_str(), fname
.c_str());
2165 // If any contains "." it is not parent directory
2166 bool inSrc
= srcRelpath
.find("..") == srcRelpath
.npos
;
2167 bool inBld
= bldRelpath
.find("..") == bldRelpath
.npos
;
2168 // TODO: Handle files with .. in their name
2170 std::string
* res
= 0;
2172 if ( inSrc
&& inBld
)
2174 // If both have relative path with no dots, pick the shorter one
2175 if ( srcRelpath
.size() < bldRelpath
.size() )
2201 cmSystemTools::ConvertToUnixSlashes(*res
);
2204 if ( path
[path
.size()-1] == '/' )
2206 path
= path
.substr(0, path
.size()-1);
2210 cmsys::SystemTools::ReplaceString(path
, ":", "_");
2211 cmsys::SystemTools::ReplaceString(path
, " ", "_");
2215 //----------------------------------------------------------------------
2216 std::string
cmCTest::GetCTestConfiguration(const char *name
)
2218 if ( this->CTestConfigurationOverwrites
.find(name
) !=
2219 this->CTestConfigurationOverwrites
.end() )
2221 return this->CTestConfigurationOverwrites
[name
];
2223 return this->CTestConfiguration
[name
];
2226 //----------------------------------------------------------------------
2227 void cmCTest::EmptyCTestConfiguration()
2229 this->CTestConfiguration
.clear();
2232 //----------------------------------------------------------------------
2233 void cmCTest::SetCTestConfiguration(const char *name
, const char* value
)
2235 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
, "SetCTestConfiguration:"
2236 << name
<< ":" << value
<< "\n");
2244 this->CTestConfiguration
.erase(name
);
2247 this->CTestConfiguration
[name
] = value
;
2251 //----------------------------------------------------------------------
2252 std::string
cmCTest::GetCurrentTag()
2254 return this->CurrentTag
;
2257 //----------------------------------------------------------------------
2258 std::string
cmCTest::GetBinaryDir()
2260 return this->BinaryDir
;
2263 //----------------------------------------------------------------------
2264 std::string
const& cmCTest::GetConfigType()
2266 return this->ConfigType
;
2269 //----------------------------------------------------------------------
2270 bool cmCTest::GetShowOnly()
2272 return this->ShowOnly
;
2275 //----------------------------------------------------------------------
2276 void cmCTest::SetProduceXML(bool v
)
2278 this->ProduceXML
= v
;
2281 //----------------------------------------------------------------------
2282 bool cmCTest::GetProduceXML()
2284 return this->ProduceXML
;
2287 //----------------------------------------------------------------------
2288 const char* cmCTest::GetSpecificTrack()
2290 if ( this->SpecificTrack
.empty() )
2294 return this->SpecificTrack
.c_str();
2297 //----------------------------------------------------------------------
2298 void cmCTest::SetSpecificTrack(const char* track
)
2302 this->SpecificTrack
= "";
2305 this->SpecificTrack
= track
;
2308 //----------------------------------------------------------------------
2309 void cmCTest::AddSubmitFile(const char* name
)
2311 this->SubmitFiles
.insert(name
);
2314 //----------------------------------------------------------------------
2315 void cmCTest::AddCTestConfigurationOverwrite(const char* encstr
)
2317 std::string overStr
= encstr
;
2318 size_t epos
= overStr
.find("=");
2319 if ( epos
== overStr
.npos
)
2321 cmCTestLog(this, ERROR_MESSAGE
,
2322 "CTest configuration overwrite specified in the wrong format."
2324 << "Valid format is: --overwrite key=value" << std::endl
2325 << "The specified was: --overwrite " << overStr
.c_str() << std::endl
);
2328 std::string key
= overStr
.substr(0, epos
);
2329 std::string value
= overStr
.substr(epos
+1, overStr
.npos
);
2330 this->CTestConfigurationOverwrites
[key
] = value
;
2333 //----------------------------------------------------------------------
2334 void cmCTest::SetConfigType(const char* ct
)
2336 this->ConfigType
= ct
?ct
:"";
2337 cmSystemTools::ReplaceString(this->ConfigType
, ".\\", "");
2338 std::string confTypeEnv
2339 = "CMAKE_CONFIG_TYPE=" + this->ConfigType
;
2340 cmSystemTools::PutEnv(confTypeEnv
.c_str());
2343 //----------------------------------------------------------------------
2344 bool cmCTest::SetCTestConfigurationFromCMakeVariable(cmMakefile
* mf
,
2345 const char* dconfig
, const char* cmake_var
)
2348 ctvar
= mf
->GetDefinition(cmake_var
);
2353 cmCTestLog(this, HANDLER_VERBOSE_OUTPUT
,
2354 "SetCTestConfigurationFromCMakeVariable:"
2355 << dconfig
<< ":" << cmake_var
);
2356 this->SetCTestConfiguration(dconfig
, ctvar
);
2360 bool cmCTest::RunCommand(
2361 const char* command
,
2362 std::string
* stdOut
,
2363 std::string
* stdErr
,
2368 std::vector
<cmStdString
> args
= cmSystemTools::ParseArguments(command
);
2375 std::vector
<const char*> argv
;
2376 for(std::vector
<cmStdString
>::const_iterator a
= args
.begin();
2377 a
!= args
.end(); ++a
)
2379 argv
.push_back(a
->c_str());
2386 cmsysProcess
* cp
= cmsysProcess_New();
2387 cmsysProcess_SetCommand(cp
, &*argv
.begin());
2388 cmsysProcess_SetWorkingDirectory(cp
, dir
);
2389 if(cmSystemTools::GetRunCommandHideConsole())
2391 cmsysProcess_SetOption(cp
, cmsysProcess_Option_HideWindow
, 1);
2393 cmsysProcess_SetTimeout(cp
, timeout
);
2394 cmsysProcess_Execute(cp
);
2396 std::vector
<char> tempOutput
;
2397 std::vector
<char> tempError
;
2404 res
= cmsysProcess_WaitForData(cp
, &data
, &length
, 0);
2407 case cmsysProcess_Pipe_STDOUT
:
2408 tempOutput
.insert(tempOutput
.end(), data
, data
+length
);
2410 case cmsysProcess_Pipe_STDERR
:
2411 tempError
.insert(tempError
.end(), data
, data
+length
);
2416 if ( (res
== cmsysProcess_Pipe_STDOUT
||
2417 res
== cmsysProcess_Pipe_STDERR
) && this->ExtraVerbose
)
2419 cmSystemTools::Stdout(data
, length
);
2423 cmsysProcess_WaitForExit(cp
, 0);
2424 if ( tempOutput
.size() > 0 )
2426 stdOut
->append(&*tempOutput
.begin(), tempOutput
.size());
2428 if ( tempError
.size() > 0 )
2430 stdErr
->append(&*tempError
.begin(), tempError
.size());
2434 if(cmsysProcess_GetState(cp
) == cmsysProcess_State_Exited
)
2438 *retVal
= cmsysProcess_GetExitValue(cp
);
2442 if ( cmsysProcess_GetExitValue(cp
) != 0 )
2448 else if(cmsysProcess_GetState(cp
) == cmsysProcess_State_Exception
)
2450 const char* exception_str
= cmsysProcess_GetExceptionString(cp
);
2451 cmCTestLog(this, ERROR_MESSAGE
, exception_str
<< std::endl
);
2452 stdErr
->append(exception_str
, strlen(exception_str
));
2455 else if(cmsysProcess_GetState(cp
) == cmsysProcess_State_Error
)
2457 const char* error_str
= cmsysProcess_GetErrorString(cp
);
2458 cmCTestLog(this, ERROR_MESSAGE
, error_str
<< std::endl
);
2459 stdErr
->append(error_str
, strlen(error_str
));
2462 else if(cmsysProcess_GetState(cp
) == cmsysProcess_State_Expired
)
2464 const char* error_str
= "Process terminated due to timeout\n";
2465 cmCTestLog(this, ERROR_MESSAGE
, error_str
<< std::endl
);
2466 stdErr
->append(error_str
, strlen(error_str
));
2470 cmsysProcess_Delete(cp
);
2474 //----------------------------------------------------------------------
2475 void cmCTest::SetOutputLogFileName(const char* name
)
2477 if ( this->OutputLogFile
)
2479 delete this->OutputLogFile
;
2480 this->OutputLogFile
= 0;
2484 this->OutputLogFile
= new cmGeneratedFileStream(name
);
2488 //----------------------------------------------------------------------
2489 static const char* cmCTestStringLogType
[] =
2494 "HANDLER_VERBOSE_OUTPUT",
2500 //----------------------------------------------------------------------
2508 #define cmCTestLogOutputFileLine(stream) \
2509 if ( this->ShowLineNumbers ) \
2511 (stream) << std::endl << file << ":" << line << " "; \
2514 void cmCTest::Log(int logType
, const char* file
, int line
, const char* msg
)
2516 if ( !msg
|| !*msg
)
2520 if ( this->OutputLogFile
)
2522 bool display
= true;
2523 if ( logType
== cmCTest::DEBUG
&& !this->Debug
) { display
= false; }
2524 if ( logType
== cmCTest::HANDLER_VERBOSE_OUTPUT
&& !this->Debug
&&
2525 !this->ExtraVerbose
) { display
= false; }
2528 cmCTestLogOutputFileLine(*this->OutputLogFile
);
2529 if ( logType
!= this->OutputLogFileLastTag
)
2531 *this->OutputLogFile
<< "[";
2532 if ( logType
>= OTHER
|| logType
< 0 )
2534 *this->OutputLogFile
<< "OTHER";
2538 *this->OutputLogFile
<< cmCTestStringLogType
[logType
];
2540 *this->OutputLogFile
<< "] " << std::endl
<< std::flush
;
2542 *this->OutputLogFile
<< msg
<< std::flush
;
2543 if ( logType
!= this->OutputLogFileLastTag
)
2545 *this->OutputLogFile
<< std::endl
<< std::flush
;
2546 this->OutputLogFileLastTag
= logType
;
2557 cmCTestLogOutputFileLine(std::cout
);
2562 case OUTPUT
: case HANDLER_OUTPUT
:
2563 if ( this->Debug
|| this->Verbose
)
2565 cmCTestLogOutputFileLine(std::cout
);
2570 case HANDLER_VERBOSE_OUTPUT
:
2571 if ( this->Debug
|| this->ExtraVerbose
)
2573 cmCTestLogOutputFileLine(std::cout
);
2579 cmCTestLogOutputFileLine(std::cerr
);
2584 cmCTestLogOutputFileLine(std::cerr
);
2587 cmSystemTools::SetErrorOccured();
2590 cmCTestLogOutputFileLine(std::cout
);
2597 //-------------------------------------------------------------------------
2598 double cmCTest::GetRemainingTimeAllowed()
2600 if (!this->GetHandler("script"))
2605 cmCTestScriptHandler
* ch
2606 = static_cast<cmCTestScriptHandler
*>(this->GetHandler("script"));
2608 return ch
->GetRemainingTimeAllowed();