I'm parallelizing an already existent application that uses gTest with MPI. In MPI programs, the first thing to do is to initialize the environment with a call to
MPI_Init( int *argc, char ***argv )
At the end of an MPI program the root process should also call MPI_Finalize. How can I write unit-tests for such an application using Google Test?
In particular, how do I access argc, and argv from the tests before gTest modifies them.
Right now I'm doing:
int argc = 0;
char** argv = NULL;
boost::mpi::environment env(argc,argv);
TEST(component_test, test_name) {
// stuff using mpi
}
and feels wrong.
It is a test framework i.e., a software tool for writing and running unit tests. It is a library for writing C++ tests. It is based on xUnit architecture which is a set of “Frameworks” for programming and automated execution of test cases.
gtest-parallel is a script that executes Google Test binaries in parallel, providing good speedup for single-threaded tests (on multi-core machines) and tests that do not run at 100% CPU (on single- or multi-core machines).
Google Test is not header-only: there are libraries to build. So, as a Visual Studio user, you have essentially two options.
Google test, or gtest is an open source framework for unit testing C\C++ projects. It easily integrates with CMake, has a great assertion engine, and produces XML reports to be for display so that it can be integrated with common CI\CD frameworks.
Just add to @rmhartog's answer.
You probably also want to add below to leave only one listener for printing before RUN_ALL_TESTS(), otherwise, the stdout messages mingle.
::testing::TestEventListeners& listeners =
::testing::UnitTest::GetInstance()->listeners();
if (world.rank() != 0) {
delete listeners.Release(listeners.default_result_printer());
}
Are you sure you want to access the argc
and argv
values before googletest? They are modified to remove googletest specific arguments such as --gtest_filter
so that the application does not see them.
I think what you want to do is simply using the following snippet as your main
:
int main(int argc, char* argv[]) {
int result = 0;
::testing::InitGoogleTest(&argc, argv);
MPI_Init(&argc, &argv);
result = RUN_ALL_TESTS();
MPI_Finalize();
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With