Skip to content

Commit

Permalink
Continue Cleanup of install tests
Browse files Browse the repository at this point in the history
1) Removing old --copy-tests and --tests options
2) Getting rid of convoluted logic to fun tests in system installed location
3) Introducing the first C++17 filesystem syntax

refs idaholab#19022
  • Loading branch information
permcody authored and grmnptr committed Mar 28, 2022
1 parent b8e5108 commit 3b8b4ea
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 59 deletions.
12 changes: 12 additions & 0 deletions framework/include/parser/CommandLine.h
Expand Up @@ -92,6 +92,18 @@ class CommandLine
template <typename T>
bool search(const std::string & option_name, std::vector<T> & argument);

/**
* Returns an iterator to the underlying argument vector to the position of the option or
* end if the option is not on the command line.
*/
std::vector<std::string>::const_iterator find(const std::string & option_name) const;

// Return an iterator to the beginning of the container of CLI options
std::vector<std::string>::const_iterator begin() const;

// Return an iterator to the beginning of the container of CLI options
std::vector<std::string>::const_iterator end() const;

/**
* Print the usage info for this command line
*/
Expand Down
95 changes: 41 additions & 54 deletions framework/src/base/MooseApp.C
Expand Up @@ -74,6 +74,7 @@
#include <cstdlib> // for system()
#include <chrono>
#include <thread>
#include <filesystem>

#define QUOTE(macro) stringifyName(macro)

Expand Down Expand Up @@ -147,9 +148,6 @@ MooseApp::validParams()
"json", "--json", "Dumps input file syntax in JSON format.");
params.addCommandLineParam<bool>(
"syntax", "--syntax", false, "Dumps the associated Action syntax paths ONLY");
params.addCommandLineParam<bool>("run_tests", "--tests", false, "run all tests");
params.addCommandLineParam<bool>(
"copy_tests", "--copy-tests", false, "copy installed tests to an <appname>_tests dir");
params.addCommandLineParam<bool>(
"show_docs", "--docs", false, "print url/path to the documentation website");
params.addCommandLineParam<bool>("check_input",
Expand All @@ -161,8 +159,8 @@ MooseApp::validParams()
"Copies installed inputs (e.g. tests, examples, etc.) to "
"an directory named <appname>_<dir>.");
params.addCommandLineParam<std::string>("run",
"--run <dir>",
"Runs the inputs in the specified directory copied to a "
"--run",
"Runs the inputs in the current directory copied to a "
"user-writable location by \"--copy-inputs\"");

params.addCommandLineParam<bool>(
Expand Down Expand Up @@ -1413,18 +1411,11 @@ MooseApp::run()
bool
MooseApp::copyInputs()
{
std::string dir_to_copy = "tests";
bool copy_param_valid = false;

if (isParamValid("copy_inputs"))
{
// Get command line argument following --copy-inputs on command line
dir_to_copy = getParam<std::string>("copy_inputs");
copy_param_valid = true;
}
auto dir_to_copy = getParam<std::string>("copy_inputs");

if (getParam<bool>("copy_tests") || copy_param_valid)
{
auto binname = appBinaryName();
if (binname == "")
mooseError("could not locate installed tests to run (unresolved binary/app name)");
Expand Down Expand Up @@ -1468,53 +1459,48 @@ MooseApp::copyInputs()
bool
MooseApp::runInputs()
{
std::string dir_to_run = "tests";
bool run_param_valid = false;
int skip_args = 2;

if (isParamValid("run"))
{
// Get command line argument following --run on command line
dir_to_run = getParam<std::string>("run");
run_param_valid = true;
skip_args = 3;
}
// Here we are going to pass everything after --run on the cli to the TestHarness. That means
// cannot validate these CLIs.
auto it = _command_line->find("run");

if ((isParamValid("run_tests") && getParam<bool>("run_tests")) || run_param_valid)
{
std::string args;
for (int i = skip_args; i < _sys_info->argc(); i++)
args += " " + std::string(*(_sys_info->argv() + i));
auto cmd = MooseUtils::runTestsExecutable() + args;
std::string test_args;
if (it != _command_line->end())
{
// Preincrement here to skip over --run
while (++it != _command_line->end())
test_args += " " + *it;
}

auto cmd = MooseUtils::runTestsExecutable() + test_args;
std::filesystem::path working_dir;
try
{
working_dir = std::filesystem::current_path();
}
catch (...)
{
}

std::string working_dir;
if (MooseUtils::findTestRoot() == "")
{
// run installed tests instead of cwd tests
auto binname = appBinaryName();
if (binname == "")
mooseError("could not locate installed tests to run (unresolved binary/app name)");

working_dir = MooseUtils::installedInputsDir(binname, dir_to_run);
if (working_dir == "")
mooseError("could not find any directory to run");

auto cmdname = Moose::getExecutableName();
if (cmdname.find_first_of("/") != std::string::npos)
cmdname = cmdname.substr(cmdname.find_first_of("/") + 1, std::string::npos);
if (!MooseUtils::checkFileWriteable(MooseUtils::pathjoin(working_dir, "testroot"), false))
mooseError("You don't have permissions to run contents of directory at their current "
"installed location.\nRun \"",
cmdname,
" --copy-inputs <dir>\" to copy the contents of <dir> to a \"./",
binname,
"_<dir>\" directory.\nChange into that directory and try \"",
cmdname,
" --run <dir>\" again.");

int ret = chdir(working_dir.c_str());
if (ret != 0)
mooseError("Failed to change directory into ", working_dir);
auto bin_name = appBinaryName();
if (bin_name == "")
mooseError("Could not locate binary name relative to installed location");

auto cmd_name = Moose::getExecutableName();
mooseError(
"Could not locate installed tests from the current working directory:",
working_dir,
".\nMake sure you are executing this command from within a writable installed inputs ",
"directory.\nRun \"",
cmd_name,
" --copy-inputs <dir>\" to copy the contents of <dir> to a \"./",
bin_name,
"_<dir>\" directory.\nChange into that directory and try \"",
cmd_name,
" --run <dir>\" again.");
}

// Only launch the tests on the root processor
Expand All @@ -1528,6 +1514,7 @@ MooseApp::runInputs()
mooseError("Run failed");
return true;
}

return false;
}

Expand Down
31 changes: 31 additions & 0 deletions framework/src/parser/CommandLine.C
Expand Up @@ -195,6 +195,37 @@ CommandLine::addOption(const std::string & name, Option cli_opt)
_cli_options[name] = cli_opt;
}

std::vector<std::string>::const_iterator
CommandLine::find(const std::string & option_name) const
{
auto pos = _cli_options.find(option_name);
auto it = _args.end();

if (pos != _cli_options.end())
{
for (const auto & search_string : pos->second.cli_switch)
{
auto it = std::find(_args.begin(), _args.end(), search_string);
if (it != _args.end())
return it;
}
}

return it;
}

std::vector<std::string>::const_iterator
CommandLine::begin() const
{
return _args.begin();
}

std::vector<std::string>::const_iterator
CommandLine::end() const
{
return _args.end();
}

bool
CommandLine::search(const std::string & option_name)
{
Expand Down
9 changes: 5 additions & 4 deletions modules/doc/content/application_development/build_system.md
Expand Up @@ -214,9 +214,10 @@ when building MOOSE or a MOOSE-based application.
MOOSE's build system has the ability to create installed binaries suitable for use with the conda package manager, or installation on a shared computing resource such as Sawtooth. The `install` target will copy binary and required libraries to a file tree based on the prefix you configured with (set by the variable `PREFIX` or the `--prefix` argument.

```
$ cd moose/framework
$ cd moose
$ ./configure --prefix=<installation path>
$ make
$ cd <application_dir>
$ make [make options]
$ make install
```

Expand All @@ -241,13 +242,13 @@ Example:
$ cd <user writable location>
$ export PATH=$PATH:<prefix>/bin # See instructions for HPC computers below
$ bison-opt --copy-inputs <installable input type> # e.g. tests, examples, etc.
$ bison-opt --run <installable input type>
$ bison-opt --run
```

Where `<installable input type>` is one of the installable directories as defined by the application developers (i.e. `tests`, `examples`, `tutorials`, etc.)

When using INL HPC systems to run your input, you will load a module that will set your path correctly
When using INL HPC systems to run your input, you will load a module that will set your path correctly.

Example:

Expand Down
2 changes: 1 addition & 1 deletion test/tests/make_install/tests
Expand Up @@ -76,7 +76,7 @@

[run]
type = 'RunApp'
cli_args = "--run tests"
cli_args = "--run"
working_directory = "../../../make_install_test/moose_test_tests"
no_additional_cli_args = True
installed = False
Expand Down

0 comments on commit 3b8b4ea

Please sign in to comment.