Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1806 pure virtual call from unit tests #1811

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tests/unit/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/

#include <gtest/gtest.h>
#include <mpi.h>

#include "test_harness.h"

Expand Down Expand Up @@ -72,5 +73,14 @@ int main(int argc, char** argv) {

TestHarness::store_cmdline_args(test_argc, test_argv);

return RUN_ALL_TESTS();
auto ret = RUN_ALL_TESTS();

// if this was a parallel test, finalize MPI
int init = 0;
MPI_Initialized(&init);
if (init) {
MPI_Finalize();
}

return ret;
}
97 changes: 0 additions & 97 deletions tests/unit/mpi_singleton.h

This file was deleted.

10 changes: 5 additions & 5 deletions tests/unit/runtime/test_initialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace vt { namespace tests { namespace unit {
struct TestInitialization : TestParallelHarness { };

TEST_F(TestInitialization, test_initialize_with_args) {
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
MPI_Comm comm = MPI_COMM_WORLD;

static char prog_name[]{"vt_program"};
static char cli_argument[]{"--cli_argument=100"};
Expand Down Expand Up @@ -83,7 +83,7 @@ TEST_F(TestInitialization, test_initialize_with_args) {
}

TEST_F(TestInitialization, test_initialize_with_appconfig) {
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
MPI_Comm comm = MPI_COMM_WORLD;

static char prog_name[]{"vt_program"};
static char cli_argument[]{"--cli_argument=100"};
Expand Down Expand Up @@ -120,7 +120,7 @@ TEST_F(TestInitialization, test_initialize_with_appconfig) {
}

TEST_F(TestInitialization, test_initialize_with_args_and_appconfig) {
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
MPI_Comm comm = MPI_COMM_WORLD;

static char prog_name[]{"vt_program"};
static char cli_argument[]{"--cli_argument=100"};
Expand Down Expand Up @@ -164,7 +164,7 @@ TEST_F(TestInitialization, test_initialize_with_args_and_appconfig) {
}

TEST_F(TestInitialization, test_initialize_with_file_and_args) {
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
MPI_Comm comm = MPI_COMM_WORLD;

static char prog_name[]{"vt_program"};
static char cli_argument[]{"--cli_argument=100"};
Expand Down Expand Up @@ -207,7 +207,7 @@ TEST_F(TestInitialization, test_initialize_with_file_and_args) {
}

TEST_F(TestInitialization, test_initialize_with_file_args_and_appconfig) {
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
MPI_Comm comm = MPI_COMM_WORLD;

static char prog_name[]{"vt_program"};
static char cli_argument[]{"--cli_argument=100"};
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@
#if !defined INCLUDED_UNIT_TEST_HELPERS_H
#define INCLUDED_UNIT_TEST_HELPERS_H

#include "mpi_singleton.h"
#include "vt/context/context.h"
#include <mpi.h>
#include <gtest/gtest.h>

namespace vt { namespace tests { namespace unit {

extern int test_argc;
extern char** test_argv;

/**
* Maximum number of ranks/nodes detected by CMake on this machine.
* Defaults to number of processors detected on the host system.
Expand All @@ -61,7 +64,15 @@ constexpr NodeType CMAKE_DETECTED_MAX_NUM_NODES = vt_detected_max_num_nodes;
* This is using MPI because it can be used before vt initializes.
*/
inline bool isOversubscribed() {
return MPISingletonMultiTest::Get()->getNumRanks() > CMAKE_DETECTED_MAX_NUM_NODES;
// be sure to only call this from parallel tests
int init = 0;
MPI_Initialized(&init);
if (!init) {
MPI_Init(&test_argc, &test_argv);
}
int num_ranks = 0;
MPI_Comm_size(MPI_COMM_WORLD, &num_ranks);
return num_ranks > CMAKE_DETECTED_MAX_NUM_NODES;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/test_parallel_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
#define INCLUDED_UNIT_TEST_PARALLEL_HARNESS_H

#include <vector>
#include <mpi.h>

#include "test_config.h"
#include "test_harness.h"
#include "mpi_singleton.h"

#include "vt/collective/collective_ops.h"
#include "vt/scheduler/scheduler.h"
Expand All @@ -73,15 +73,21 @@ struct TestParallelHarnessAny : TestHarnessAny<TestBase> {
static char throw_on_abort[]{"--vt_throw_on_abort=1"};
addArgs(throw_on_abort);

// communicator is duplicated.
MPI_Comm comm = MPISingletonMultiTest::Get()->getComm();
// initialize MPI if it hasn't already happened
int init = 0;
MPI_Initialized(&init);
if (!init) {
MPI_Init(&test_argc, &test_argv);
}
MPI_Comm comm = MPI_COMM_WORLD;
auto const new_args = injectAdditionalArgs(test_argc, test_argv);
auto custom_argc = new_args.first;
auto custom_argv = new_args.second;
vtAssert(
custom_argv[custom_argc] == nullptr,
"The value of argv[argc] should always be 0"
);
// communicator is duplicated.
CollectiveOps::initialize(custom_argc, custom_argv, no_workers, true, &comm);

#if DEBUG_TEST_HARNESS_PRINT
Expand Down