unittests mock, cleanup (#111)
* cleanup, fix issue involved after remove is_bootstrap parameter * misc * clean * add unittests
This commit is contained in:
@@ -3,12 +3,13 @@ find_package(GTest REQUIRED)
|
||||
add_executable(
|
||||
unit_tests
|
||||
allreduce_base_test.cpp
|
||||
allreduce_mock_test.cpp
|
||||
test_main.cpp)
|
||||
|
||||
target_link_libraries(
|
||||
unit_tests
|
||||
GTest::GTest GTest::Main
|
||||
rabit_base)
|
||||
rabit_base rabit_mock)
|
||||
|
||||
target_include_directories(unit_tests PUBLIC
|
||||
"$<BUILD_INTERFACE:${rabit_SOURCE_DIR}/include>"
|
||||
|
||||
36
test/cpp/allreduce_mock_test.cpp
Normal file
36
test/cpp/allreduce_mock_test.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#define RABIT_CXXTESTDEFS_H
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "../../src/allreduce_mock.h"
|
||||
|
||||
TEST(allreduce_mock, mock_allreduce)
|
||||
{
|
||||
rabit::engine::AllreduceMock m;
|
||||
|
||||
std::string mock_str = "mock=0,0,0,0";
|
||||
char cmd[mock_str.size()+1];
|
||||
std::copy(mock_str.begin(), mock_str.end(), cmd);
|
||||
cmd[mock_str.size()] = '\0';
|
||||
|
||||
char* argv[] = {cmd};
|
||||
m.Init(1, argv);
|
||||
m.rank = 0;
|
||||
EXPECT_EXIT(m.Allreduce(nullptr,0,0,nullptr,nullptr,nullptr), ::testing::ExitedWithCode(255), "");
|
||||
}
|
||||
|
||||
TEST(allreduce_mock, mock_broadcast)
|
||||
{
|
||||
rabit::engine::AllreduceMock m;
|
||||
std::string mock_str = "mock=0,1,2,0";
|
||||
char cmd[mock_str.size()+1];
|
||||
std::copy(mock_str.begin(), mock_str.end(), cmd);
|
||||
cmd[mock_str.size()] = '\0';
|
||||
char* argv[] = {cmd};
|
||||
m.Init(1, argv);
|
||||
m.rank = 0;
|
||||
m.version_number=1;
|
||||
m.seq_counter=2;
|
||||
EXPECT_EXIT(m.Broadcast(nullptr,0,0), ::testing::ExitedWithCode(255), "");
|
||||
}
|
||||
@@ -96,7 +96,7 @@ int main(int argc, char *argv[]) {
|
||||
std::string name = rabit::GetProcessorName();
|
||||
|
||||
int max_rank = rank;
|
||||
rabit::Allreduce<op::Max>(&max_rank, sizeof(int));
|
||||
rabit::Allreduce<op::Max>(&max_rank, 1);
|
||||
utils::Check(max_rank == nproc - 1, "max rank is world size-1");
|
||||
|
||||
Model model;
|
||||
|
||||
Reference in New Issue
Block a user