ctest_start: read model from TAG file

This change reworks ctest_start() so that simply calling
ctest_start(APPEND) will read all the information from the TAG file.
On top of that, it relaxes the argument parsing for ctest_start() to
allow greater flexibility in the argument ordering, and the documentation
for ctest_start() has been cleaned up.
This commit is contained in:
Kyle Edwards
2018-05-03 16:42:09 -04:00
parent d3292d2d10
commit 563781099f
34 changed files with 304 additions and 52 deletions

View File

@@ -5,21 +5,78 @@ Starts the testing for a given model
::
ctest_start(Model [TRACK <track>] [APPEND] [source [binary]] [QUIET])
ctest_start(<model> [<source> [<binary>]] [TRACK <track>] [QUIET])
ctest_start([<model> [<source> [<binary>]]] [TRACK <track>] APPEND [QUIET])
Starts the testing for a given model. The command should be called
after the binary directory is initialized. If the 'source' and
'binary' directory are not specified, it reads the
:variable:`CTEST_SOURCE_DIRECTORY` and :variable:`CTEST_BINARY_DIRECTORY`.
If the track is
specified, the submissions will go to the specified track. If APPEND
is used, the existing TAG is used rather than creating a new one based
on the current time stamp. If ``QUIET`` is used, CTest will suppress any
non-error messages that it otherwise would have printed to the console.
after the binary directory is initialized.
If the :variable:`CTEST_CHECKOUT_COMMAND` variable
(or the :variable:`CTEST_CVS_CHECKOUT` variable)
is set, its content is treated as command-line. The command is
invoked with the current working directory set to the parent of the source
directory, even if the source directory already exists. This can be used
to create the source tree from a version control repository.
The parameters are as follows:
``<model>``
Set the dashboard model. Must be one of ``Experimental``, ``Continuous``, or
``Nightly``. This parameter is required unless ``APPEND`` is specified.
``<source>``
Set the source directory. If not specified, the value of
:variable:`CTEST_SOURCE_DIRECTORY` is used instead.
``<binary>``
Set the binary directory. If not specified, the value of
:variable:`CTEST_BINARY_DIRECTORY` is used instead.
``TRACK <track>``
If ``TRACK`` is used, the submissions will go to the specified track on the
CDash server. If no ``TRACK`` is specified, the name of the model is used by
default.
``APPEND``
If ``APPEND`` is used, the existing ``TAG`` is used rather than creating a new
one based on the current time stamp. If you use ``APPEND``, you can omit the
``<model>`` and ``TRACK <track>`` parameters, because they will be read from
the generated ``TAG`` file. For example:
.. code-block:: cmake
ctest_start(Experimental TRACK TrackExperimental)
Later, in another ``ctest -S`` script:
.. code-block:: cmake
ctest_start(APPEND)
When the second script runs ``ctest_start(APPEND)``, it will read the
``Experimental`` model and ``TrackExperimental`` track from the ``TAG`` file
generated by the first ``ctest_start()`` command. Please note that if you
call ``ctest_start(APPEND)`` and specify a different model or track than
in the first ``ctest_start()`` command, a warning will be issued, and the
new model and track will be used.
``QUIET``
If ``QUIET`` is used, CTest will suppress any non-error messages that it
otherwise would have printed to the console.
The parameters for ``ctest_start()`` can be issued in any order, with the
exception that ``<model>``, ``<source>``, and ``<binary>`` have to appear
in that order with respect to each other. The following are all valid and
equivalent:
.. code-block:: cmake
ctest_start(Experimental path/to/source path/to/binary TRACK SomeTrack QUIET APPEND)
ctest_start(TRACK SomeTrack Experimental QUIET path/to/source APPEND path/to/binary)
ctest_start(APPEND QUIET Experimental path/to/source TRACK SomeTrack path/to/binary)
However, for the sake of readability, it is recommended that you order your
parameters in the order listed at the top of this page.
If the :variable:`CTEST_CHECKOUT_COMMAND` variable (or the
:variable:`CTEST_CVS_CHECKOUT` variable) is set, its content is treated as
command-line. The command is invoked with the current working directory set
to the parent of the source directory, even if the source directory already
exists. This can be used to create the source tree from a version control
repository.

View File

@@ -28,41 +28,41 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
}
size_t cnt = 0;
const char* smodel = args[cnt].c_str();
const char* smodel = nullptr;
const char* src_dir = nullptr;
const char* bld_dir = nullptr;
cnt++;
this->CTest->SetSpecificTrack(nullptr);
if (cnt < args.size() - 1) {
while (cnt < args.size()) {
if (args[cnt] == "TRACK") {
cnt++;
if (cnt >= args.size() || args[cnt] == "APPEND" ||
args[cnt] == "QUIET") {
this->SetError("TRACK argument missing track name");
return false;
}
this->CTest->SetSpecificTrack(args[cnt].c_str());
cnt++;
}
}
if (cnt < args.size()) {
if (args[cnt] == "APPEND") {
} else if (args[cnt] == "APPEND") {
cnt++;
this->CreateNewTag = false;
}
}
if (cnt < args.size()) {
if (args[cnt] == "QUIET") {
} else if (args[cnt] == "QUIET") {
cnt++;
this->Quiet = true;
} else if (!smodel) {
smodel = args[cnt].c_str();
cnt++;
} else if (!src_dir) {
src_dir = args[cnt].c_str();
cnt++;
} else if (!bld_dir) {
bld_dir = args[cnt].c_str();
cnt++;
} else {
this->SetError("Too many arguments");
return false;
}
}
if (cnt < args.size()) {
src_dir = args[cnt].c_str();
cnt++;
if (cnt < args.size()) {
bld_dir = args[cnt].c_str();
}
}
if (!src_dir) {
src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
}
@@ -79,6 +79,11 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
"as an argument or set CTEST_BINARY_DIRECTORY");
return false;
}
if (!smodel && this->CreateNewTag) {
this->SetError("no test model specified and APPEND not specified. Specify "
"either a test model or the APPEND argument");
return false;
}
cmSystemTools::AddKeepPath(src_dir);
cmSystemTools::AddKeepPath(bld_dir);
@@ -92,11 +97,20 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str(),
this->Quiet);
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
<< smodel << std::endl
<< " Source directory: " << src_dir << std::endl
<< " Build directory: " << bld_dir << std::endl,
this->Quiet);
if (smodel) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
<< smodel << std::endl
<< " Source directory: " << src_dir << std::endl
<< " Build directory: " << bld_dir << std::endl,
this->Quiet);
} else {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with "
"to-be-determined model"
<< std::endl
<< " Source directory: " << src_dir << std::endl
<< " Build directory: " << bld_dir << std::endl,
this->Quiet);
}
const char* track = this->CTest->GetSpecificTrack();
if (track) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
@@ -128,7 +142,12 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
this->CTest->SetRunCurrentScript(false);
this->CTest->SetSuppressUpdatingCTestConfiguration(true);
int model = this->CTest->GetTestModelFromString(smodel);
int model;
if (smodel) {
model = this->CTest->GetTestModelFromString(smodel);
} else {
model = cmCTest::UNKNOWN;
}
this->CTest->SetTestModel(model);
this->CTest->SetProduceXML(true);

View File

@@ -474,11 +474,13 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
day != lctime->tm_mday) {
tag.clear();
}
std::string tagmode;
if (cmSystemTools::GetLineFromStream(tfin, tagmode)) {
if (tagmode.size() > 4 && !this->Parts[PartStart]) {
this->TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
}
std::string track;
if (cmSystemTools::GetLineFromStream(tfin, track)) {
this->SpecificTrack = track;
}
std::string model;
if (cmSystemTools::GetLineFromStream(tfin, model)) {
this->TestModel = GetTestModelFromString(model.c_str());
}
tfin.close();
}
@@ -502,6 +504,17 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
if (ofs) {
ofs << tag << std::endl;
ofs << this->GetTestModelString() << std::endl;
switch (this->TestModel) {
case cmCTest::EXPERIMENTAL:
ofs << "Experimental" << std::endl;
break;
case cmCTest::NIGHTLY:
ofs << "Nightly" << std::endl;
break;
case cmCTest::CONTINUOUS:
ofs << "Continuous" << std::endl;
break;
}
}
ofs.close();
if (nullptr == command) {
@@ -512,8 +525,16 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
}
}
} else {
std::string track;
std::string modelStr;
int model = cmCTest::UNKNOWN;
if (tfin) {
cmSystemTools::GetLineFromStream(tfin, tag);
cmSystemTools::GetLineFromStream(tfin, track);
if (cmSystemTools::GetLineFromStream(tfin, modelStr)) {
model = GetTestModelFromString(modelStr.c_str());
}
tfin.close();
}
@@ -523,6 +544,35 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
return 0;
}
if (this->TestModel == cmCTest::UNKNOWN) {
if (model == cmCTest::UNKNOWN) {
cmCTestLog(this, ERROR_MESSAGE,
"TAG file does not contain model and "
"no model specified in start command"
<< std::endl);
return 0;
}
this->SetTestModel(model);
}
if (model != this->TestModel && model != cmCTest::UNKNOWN &&
this->TestModel != cmCTest::UNKNOWN) {
cmCTestOptionalLog(this, WARNING, "Model given in TAG does not match "
"model given in ctest_start()"
<< std::endl,
quiet);
}
if (!this->SpecificTrack.empty() && track != this->SpecificTrack) {
cmCTestOptionalLog(this, WARNING, "Track given in TAG does not match "
"track given in ctest_start()"
<< std::endl,
quiet);
} else {
this->SpecificTrack = track;
}
cmCTestOptionalLog(this, OUTPUT, " Use existing tag: "
<< tag << " - " << this->GetTestModelString()
<< std::endl,

View File

@@ -295,9 +295,10 @@ public:
enum
{
EXPERIMENTAL,
NIGHTLY,
CONTINUOUS
UNKNOWN = -1,
EXPERIMENTAL = 0,
NIGHTLY = 1,
CONTINUOUS = 2,
};
/** provide some more detailed info on the return code for ctest */

View File

@@ -0,0 +1 @@
check_tag_contents("^19551112-2204\nContinuousTrack\nContinuous\n$")

View File

@@ -0,0 +1 @@
^Model given in TAG does not match model given in ctest_start\(\)$

View File

@@ -0,0 +1,8 @@
Run dashboard with model Experimental
Source directory: .*/Tests/RunCMake/ctest_start/AppendDifferentModel
Build directory: .*/Tests/RunCMake/ctest_start/AppendDifferentModel-build
Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/AppendDifferentModel/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use existing tag: 19551112-2204 - ContinuousTrack
Use ContinuousTrack tag: [0-9-]+

View File

@@ -0,0 +1 @@
^Track given in TAG does not match track given in ctest_start\(\)$

View File

@@ -0,0 +1,9 @@
Run dashboard with to-be-determined model
Source directory: .*/Tests/RunCMake/ctest_start/AppendDifferentTrack
Build directory: .*/Tests/RunCMake/ctest_start/AppendDifferentTrack-build
Track: ExperimentalDifferent
Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/AppendDifferentTrack/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use existing tag: 19551112-2204 - ExperimentalDifferent
Use ExperimentalDifferent tag: [0-9-]+

View File

@@ -0,0 +1,8 @@
Run dashboard with model Continuous
Source directory: .*/Tests/RunCMake/ctest_start/AppendNoMatchingTrack
Build directory: .*/Tests/RunCMake/ctest_start/AppendNoMatchingTrack-build
Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/AppendNoMatchingTrack/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use existing tag: 19551112-2204 - SomeWeirdTrackName
Use SomeWeirdTrackName tag: [0-9-]+

View File

@@ -0,0 +1 @@
check_tag_contents("^19551112-2204\nContinuousTrack\nContinuous\n$")

View File

@@ -0,0 +1,8 @@
Run dashboard with to-be-determined model
Source directory: .*/Tests/RunCMake/ctest_start/AppendNoModel
Build directory: .*/Tests/RunCMake/ctest_start/AppendNoModel-build
Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/AppendNoModel/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use existing tag: 19551112-2204 - ContinuousTrack
Use ContinuousTrack tag: [0-9-]+

View File

@@ -0,0 +1,8 @@
Run dashboard with model Continuous
Source directory: .*/Tests/RunCMake/ctest_start/AppendOldContinuous
Build directory: .*/Tests/RunCMake/ctest_start/AppendOldContinuous-build
Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/AppendOldContinuous/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use existing tag: 19551112-2204 - ContinuousTrack
Use ContinuousTrack tag: 19551112-2204

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,3 @@
^TAG file does not contain model and no model specified in start command
CMake Error at .*/Tests/RunCMake/ctest_start/AppendOldNoModel/test.cmake:[0-9]+ \(ctest_start\):
ctest_start unknown error.$

View File

@@ -0,0 +1,6 @@
Run dashboard with to-be-determined model
Source directory: .*/Tests/RunCMake/ctest_start/AppendOldNoModel
Build directory: .*/Tests/RunCMake/ctest_start/AppendOldNoModel-build
Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/AppendOldNoModel/CTestConfig.cmake
Site: test-site
Build name: test-build-name

View File

@@ -0,0 +1 @@
check_tag_contents("^19551112-2204\nContinuousTrack\nContinuous\n$")

View File

@@ -0,0 +1,8 @@
Run dashboard with model Continuous
Source directory: .*/Tests/RunCMake/ctest_start/AppendSameModel
Build directory: .*/Tests/RunCMake/ctest_start/AppendSameModel-build
Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/AppendSameModel/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use existing tag: 19551112-2204 - ContinuousTrack
Use ContinuousTrack tag: [0-9-]+

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,2 @@
^CMake Error at .*/Tests/RunCMake/ctest_start/MissingTrackArg/test\.cmake:[0-9]+ \(ctest_start\):
ctest_start TRACK argument missing track name$

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,2 @@
^CMake Error at .*/Tests/RunCMake/ctest_start/MissingTrackArgAppend/test\.cmake:[0-9]+ \(ctest_start\):
ctest_start TRACK argument missing track name$

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,2 @@
^CMake Error at .*/Tests/RunCMake/ctest_start/MissingTrackArgQuiet/test\.cmake:[0-9]+ \(ctest_start\):
ctest_start TRACK argument missing track name$

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,3 @@
^CMake Error at .*/Tests/RunCMake/ctest_start/NoModel/test\.cmake:[0-9]+ \(ctest_start\):
ctest_start no test model specified and APPEND not specified. Specify
either a test model or the APPEND argument$

View File

@@ -7,11 +7,40 @@ function(run_ctest_start CASE_NAME)
run_ctest(${CASE_NAME})
endfunction()
function(check_tag_contents EXPECTED)
set(_tag_file "${RunCMake_BINARY_DIR}/${CASE_NAME}-build/Testing/TAG")
if(EXISTS "${_tag_file}")
file(READ "${_tag_file}" _tag_contents)
if(NOT _tag_contents MATCHES "${EXPECTED}")
set(RunCMake_TEST_FAILED "Testing/TAG file does not match expected value.\nActual TAG file:\n${_tag_contents}\nExpected TAG file:\n${EXPECTED}\n" PARENT_SCOPE)
endif()
else()
set(RunCMake_TEST_FAILED "Testing/TAG file does not exist." PARENT_SCOPE)
endif()
endfunction()
run_ctest_start(StartQuiet Experimental QUIET)
run_ctest_start(ConfigInSource Experimental)
run_ctest_start(FunctionScope Experimental QUIET)
run_ctest_start(WriteModelToTagExperimental Experimental QUIET)
run_ctest_start(WriteModelToTagContinuous Continuous QUIET)
run_ctest_start(WriteModelToTagNightly Nightly QUIET)
run_ctest_start(WriteModelToTagNoMatchingTrack Continuous TRACK SomeWeirdTrackName QUIET)
run_ctest_start(AppendSameModel Continuous APPEND)
run_ctest_start(AppendDifferentModel Experimental APPEND)
run_ctest_start(AppendNoModel APPEND)
run_ctest_start(AppendDifferentTrack TRACK ExperimentalDifferent APPEND)
run_ctest_start(AppendNoMatchingTrack Continuous APPEND)
run_ctest_start(AppendOldContinuous Continuous APPEND)
run_ctest_start(AppendOldNoModel APPEND)
run_ctest_start(NoModel QUIET)
run_ctest_start(MissingTrackArg Experimental TRACK)
run_ctest_start(MissingTrackArgAppend Experimental TRACK APPEND)
run_ctest_start(MissingTrackArgQuiet Experimental TRACK QUIET)
run_ctest_start(TooManyArgs Experimental
${RunCMake_BINARY_DIR}/TooManyArgs-build
${RunCMake_BINARY_DIR}/TooManyArgs-build
${RunCMake_BINARY_DIR}/TooManyArgs-build)
function(run_ConfigInBuild)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ConfigInBuild-build)

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,2 @@
^CMake Error at .*/Tests/RunCMake/ctest_start/TooManyArgs/test\.cmake:[0-9]+ \(ctest_start\):
ctest_start Too many arguments$

View File

@@ -0,0 +1 @@
check_tag_contents("^[0-9-]+\nContinuous\nContinuous\n$")

View File

@@ -0,0 +1 @@
check_tag_contents("^[0-9-]+\nExperimental\nExperimental\n$")

View File

@@ -0,0 +1 @@
check_tag_contents("^[0-9-]+\nNightly\nNightly\n$")

View File

@@ -0,0 +1 @@
check_tag_contents("^[0-9-]+\nSomeWeirdTrackName\nContinuous\n$")

View File

@@ -8,11 +8,23 @@ set(CTEST_CMAKE_GENERATOR "@RunCMake_GENERATOR@")
set(CTEST_CMAKE_GENERATOR_PLATFORM "@RunCMake_GENERATOR_PLATFORM@")
set(CTEST_CMAKE_GENERATOR_TOOLSET "@RunCMake_GENERATOR_TOOLSET@")
set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
function(setup_tests)
ctest_start(${ctest_start_args})
endfunction()
if("@CASE_NAME@" MATCHES "^Append")
if("@CASE_NAME@" MATCHES "^AppendNoMatchingTrack$")
file(WRITE "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "19551112-2204\nSomeWeirdTrackName\n")
else()
file(WRITE "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "19551112-2204\nContinuousTrack\n")
endif()
if(NOT "@CASE_NAME@" MATCHES "^AppendOld")
file(APPEND "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "Continuous\n")
endif()
endif()
set(ctest_start_args "@CASE_CTEST_START_ARGS@")
if("@CASE_NAME@" STREQUAL "FunctionScope")
setup_tests()