|
47 | 47 |
|
48 | 48 | #include <vt/collective/startup.h>
|
49 | 49 |
|
| 50 | +#include <fstream> |
| 51 | + |
50 | 52 | namespace vt { namespace tests { namespace unit {
|
51 | 53 |
|
52 | 54 | struct TestInitialization : TestParallelHarness { };
|
@@ -161,4 +163,93 @@ TEST_F(TestInitialization, test_initialize_with_args_and_appconfig) {
|
161 | 163 | EXPECT_EQ(custom_argv[2], nullptr);
|
162 | 164 | }
|
163 | 165 |
|
| 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 | + |
164 | 255 | }}} // end namespace vt::tests::unit
|
0 commit comments