Giter VIP home page Giter VIP logo

gtest_mpi's Introduction

gtest_mpi

A header-only c++ library to support EXPECTS_* macros in Google Test in MPI environment.

Usage

Just change all your gtest/gtest.h header file to gtest_mpi.h, and call GTestMPI::Init after initialize MPI.

#include "gtest_mpi.h"

int main(int argc, char **argv) {
    MPI_Init(&argc, &argv);                   // Initialize MPI.
    GTestMPI::Init();                         // Initialize gtest_mpi.
    ::testing::InitGoogleTest(&argc, argv);   // Initialize Google Test.
    auto result = RUN_ALL_TESTS();            // Run tests.
    MPI_Finalize();                           // Finalize MPI.
    return result;
}

User should make sure that all processes in MPI always call the same EXPECT_* macro in Google Test at the same time.

TEST(BinaryTest, Test1) {
    if (GTestMPI::Rank() == 2) {
        double x = 1;
        double y = 2;
        EXPECT_EQ(x, y);       // Correct!
    } else {
        int a = 1;
        int b = 1;
        EXPECT_EQ(a, b);       // Correct!
    }
}

TEST(BinaryTest, Test2) {
    if (GTestMPI::Rank() == 2) {
        double x = 1;
        double y = 2;
        EXPECT_EQ(x, y);       // Wrong! All processes should call EXPECT_* macro at the same time.
    }
}

TEST(BinaryTest, Test3) {
    if (GTestMPI::Rank() == 2) {
        double x = 1;
        double y = 2;
        EXPECT_EQ(x, y);
    } else {
        int a = 1;
        int b = 1;
        EXPECT_GE(a, b);       // Wrong! All processes should call the same EXPECT_* macro.
    }
}

When running the correct code, the output will show the process number.

[ RUN      ] BinaryTest.Test1
~/gtest_mpi/example.cpp:25: Failure
Expected equality of these values:
  x, on process 2
    Which is: 1
  y, on process 2
    Which is: 2
[  FAILED  ] BinaryTest.Test1 (0 ms)

Run Example

mkdir build
cd build
cmake .. && make
cd ..
./run.sh proc_num

Supported

Now, only part of EXPECT_* macros are supported. EXPECT_NEAR, EXPECT_PRED*, Expection Assertions and Death Assertions are not supported yet. Coming soon!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.