Skip to content

Commit 87d7da8

Browse files
Jakub Strzebonskicz4rs
Jakub Strzebonski
authored andcommitted
#1550 document and test order of parsing arguments passed from cli, file and appConfig
1 parent a1c3cd2 commit 87d7da8

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

docs/md/tutorial.md

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ int main(int argc, char** argv) {
6565

6666
It is worth noting that if you run your application with any of vt's command-line arguments and at the same time you define and pass `AppConfig` to `vt::initialize`, CLI arguments have a higher priority. In other words, if you predefine in source code and give from the command line the same vt's argument, but with a different value, the program will use the CLI one.
6767

68+
There is also an option to use configuration file. Refer to CLI11 documentation for details https://cliutils.github.io/CLI11/book/chapters/config.html. Important thing to remember - CLI11 processes configuration file before command line arguments, so in the end command line arguments might overwrite values defined in configuration file.
69+
6870
\section tutorial-walkthrough Tutorial Code Snippets
6971

7072
This page walks through the tutorial that exists in the source code. See

src/vt/configs/arguments/args.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ std::tuple<int, std::string> ArgConfig::parse(
716716
return parseToConfig(argc, argv, config_);
717717
}
718718

719-
// if user defines appConfig, parse into temporary config for later comparison.
719+
// If user defines appConfig, parse into temporary config for later comparison.
720720
AppConfig config{*appConfig};
721721
auto const parse_result = parseToConfig(argc, argv, config);
722722

tests/unit/runtime/test_initialization.cc

+91
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
#include <vt/collective/startup.h>
4949

50+
#include <fstream>
51+
5052
namespace vt { namespace tests { namespace unit {
5153

5254
struct TestInitialization : TestParallelHarness { };
@@ -161,4 +163,93 @@ TEST_F(TestInitialization, test_initialize_with_args_and_appconfig) {
161163
EXPECT_EQ(custom_argv[2], nullptr);
162164
}
163165

166+
TEST_F(TestInitialization, test_initialize_with_file_and_args) {
167+
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
168+
169+
static char prog_name[]{"vt_program"};
170+
static char cli_argument[]{"--cli_argument=100"};
171+
static char vt_no_terminate[]{"--vt_no_terminate"};
172+
static char vt_lb_name[]{"--vt_lb_name=RotateLB"};
173+
static char vt_input_config[]{"--vt_input_config=test_cfg.toml"};
174+
175+
std::vector<char *> custom_args;
176+
custom_args.emplace_back(prog_name);
177+
custom_args.emplace_back(cli_argument);
178+
custom_args.emplace_back(vt_no_terminate);
179+
custom_args.emplace_back(vt_input_config);
180+
custom_args.emplace_back(vt_lb_name);
181+
custom_args.emplace_back(nullptr);
182+
183+
int custom_argc = custom_args.size() - 1;
184+
char **custom_argv = custom_args.data();
185+
186+
EXPECT_EQ(custom_argc, 5);
187+
188+
int this_rank;
189+
MPI_Comm_rank(comm, &this_rank);
190+
if (this_rank == 0) {
191+
std::ofstream cfg_file_{"test_cfg.toml", std::ofstream::out | std::ofstream::trunc};
192+
cfg_file_ << "vt_lb_name = RandomLB\n";
193+
cfg_file_.close();
194+
}
195+
MPI_Barrier(comm);
196+
197+
vt::initialize(custom_argc, custom_argv, no_workers, true, &comm);
198+
199+
EXPECT_EQ(theConfig()->prog_name, "vt_program");
200+
EXPECT_EQ(theConfig()->vt_no_terminate, true);
201+
EXPECT_EQ(theConfig()->vt_lb_name, "RotateLB");
202+
203+
EXPECT_EQ(custom_argc, 2);
204+
EXPECT_STREQ(custom_argv[0], "vt_program");
205+
EXPECT_STREQ(custom_argv[1], "--cli_argument=100");
206+
EXPECT_EQ(custom_argv[2], nullptr);
207+
}
208+
209+
TEST_F(TestInitialization, test_initialize_with_file_args_and_appconfig) {
210+
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
211+
212+
static char prog_name[]{"vt_program"};
213+
static char cli_argument[]{"--cli_argument=100"};
214+
static char vt_no_terminate[]{"--vt_no_terminate"};
215+
static char vt_lb_name[]{"--vt_lb_name=RotateLB"};
216+
static char vt_input_config[]{"--vt_input_config=test_cfg.toml"};
217+
218+
std::vector<char*> custom_args;
219+
custom_args.emplace_back(prog_name);
220+
custom_args.emplace_back(cli_argument);
221+
custom_args.emplace_back(vt_no_terminate);
222+
custom_args.emplace_back(vt_input_config);
223+
custom_args.emplace_back(vt_lb_name);
224+
custom_args.emplace_back(nullptr);
225+
226+
int custom_argc = custom_args.size() - 1;
227+
char** custom_argv = custom_args.data();
228+
229+
EXPECT_EQ(custom_argc, 5);
230+
231+
arguments::AppConfig appConfig{};
232+
appConfig.vt_lb_name = "GreedyLB";
233+
234+
int this_rank;
235+
MPI_Comm_rank(comm, &this_rank);
236+
if (this_rank == 0) {
237+
std::ofstream cfg_file_{"test_cfg.toml", std::ofstream::out | std::ofstream::trunc};
238+
cfg_file_ << "vt_lb_name = RandomLB\n";
239+
cfg_file_.close();
240+
}
241+
MPI_Barrier(comm);
242+
243+
vt::initialize(custom_argc, custom_argv, no_workers, true, &comm, &appConfig);
244+
245+
EXPECT_EQ(theConfig()->prog_name, "vt_program");
246+
EXPECT_EQ(theConfig()->vt_no_terminate, true);
247+
EXPECT_EQ(theConfig()->vt_lb_name, "RotateLB");
248+
249+
EXPECT_EQ(custom_argc, 2);
250+
EXPECT_STREQ(custom_argv[0], "vt_program");
251+
EXPECT_STREQ(custom_argv[1], "--cli_argument=100");
252+
EXPECT_EQ(custom_argv[2], nullptr);
253+
}
254+
164255
}}} // end namespace vt::tests::unit

0 commit comments

Comments
 (0)