CommandLineProgramContext &initForCommandLine(int *argc, char ***argv) { gmx::init(argc, argv); GMX_RELEASE_ASSERT(!g_commandLineContext, "initForCommandLine() calls cannot be nested"); #ifdef GMX_LIB_MPI // TODO: Rewrite this to not use t_commrec once there is clarity on // the approach for MPI in C++ code. // TODO: Consider whether the argument broadcast would better be done // in CommandLineModuleManager. t_commrec cr; std::memset(&cr, 0, sizeof(cr)); gmx_fill_commrec_from_mpi(&cr); if (PAR(&cr)) { broadcastArguments(&cr, argc, argv); } #endif try { g_commandLineContext.reset(new CommandLineProgramContext(*argc, *argv)); setProgramContext(g_commandLineContext.get()); } catch (const std::exception &ex) { printFatalErrorMessage(stderr, ex); std::exit(processExceptionAtExit(ex)); } return *g_commandLineContext; }
void initTestUtils(const char *dataPath, const char *tempPath, int *argc, char ***argv) { gmx::initForCommandLine(argc, argv); try { ::testing::InitGoogleMock(argc, *argv); if (dataPath != NULL) { TestFileManager::setInputDataDirectory(dataPath); } if (tempPath != NULL) { TestFileManager::setGlobalOutputTempDirectory(tempPath); } bool bHelp = false; Options options(NULL, NULL); // TODO: A single option that accepts multiple names would be nicer. // Also, we recognize -help, but GTest doesn't, which leads to a bit // unintuitive behavior. options.addOption(BooleanOption("h").store(&bHelp) .description("Print GROMACS-specific unit test options")); options.addOption(BooleanOption("help").store(&bHelp).hidden()); options.addOption(BooleanOption("?").store(&bHelp).hidden()); // TODO: Consider removing this option from test binaries that do not need it. initReferenceData(&options); TestOptionsRegistry::getInstance().initOptions(&options); try { CommandLineParser(&options).parse(argc, *argv); options.finish(); } catch (const UserInputError &) { printHelp(options); throw; } if (bHelp) { printHelp(options); } setFatalErrorHandler(NULL); initMPIOutput(); } catch (const std::exception &ex) { printFatalErrorMessage(stderr, ex); std::exit(processExceptionAtExit(ex)); } }
CommandLineProgramContext &initForCommandLine(int *argc, char ***argv) { gmx::init(argc, argv); GMX_RELEASE_ASSERT(!g_commandLineContext, "initForCommandLine() calls cannot be nested"); // TODO: Consider whether the argument broadcast would better be done // in CommandLineModuleManager. broadcastArguments(argc, argv); try { g_commandLineContext = compat::make_unique<CommandLineProgramContext>(*argc, *argv); setProgramContext(g_commandLineContext.get()); g_libFileFinder = compat::make_unique<DataFileFinder>(); g_libFileFinder->setSearchPathFromEnv("GMXLIB"); setLibraryFileFinder(g_libFileFinder.get()); } catch (const std::exception &ex) { printFatalErrorMessage(stderr, ex); std::exit(processExceptionAtExit(ex)); } return *g_commandLineContext; }
int processExceptionAtExitForCommandLine(const std::exception &ex) { int rc = processExceptionAtExit(ex); // Currently this aborts for real MPI finalizeForCommandLine(); // thus this MPI_Finalize doesn't matter. return rc; }