Skip to content

Commit

Permalink
[Test] Add cpp test to CI (dmlc#567)
Browse files Browse the repository at this point in the history
* add cpptest to ci

* try windows

* Update Jenkinsfile

* Update Jenkinsfile

* Update Jenkinsfile

* Update task_cpp_unit_test.bat

* Change localhost to 127.0.0.1

* windows socket gtest

* lint

* Update task_cpp_unit_test.bat

* fix batch script

* export all symbols

* Update Jenkinsfile

* compile once

* try mxnet compact
  • Loading branch information
VoVAllen authored and jermainewang committed May 30, 2019
1 parent e0ce190 commit 16af6eb
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 22 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-DNOMINMAX)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj")
Expand Down
33 changes: 33 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def build_dgl_win64() {
bat "CALL tests\\scripts\\build_dgl.bat"
}

def cpp_unit_test_linux(){
sh "bash tests/scripts/task_cpp_unit_test.sh"
}

def cpp_unit_test_windows(){
bat "CALL tests\\scripts\\task_cpp_unit_test.bat"
}

def unit_test(backend, dev) {
withEnv(["DGL_LIBRARY_PATH=${env.WORKSPACE}/build", "PYTHONPATH=${env.WORKSPACE}/python", "DGLBACKEND=${backend}"]) {
sh "bash tests/scripts/task_unit_test.sh ${backend}"
Expand Down Expand Up @@ -120,6 +128,28 @@ pipeline {
}
stage("Test") {
parallel {
stage("CPP Test"){
stages{
stage("CPP Unit Test Linux"){
agent {
docker {image "dgllib/dgl-ci-cpu"}
}
steps {
init_git_submodule()
cpp_unit_test_linux()
}
}
stage("CPP Unit Test Windows"){
agent {
label "windows"
}
steps {
init_git_submodule_win64()
cpp_unit_test_windows()
}
}
}
}
stage("Pytorch CPU") {
agent {
docker { image "dgllib/dgl-ci-cpu" }
Expand Down Expand Up @@ -177,6 +207,9 @@ pipeline {
}
stages {
stage("MX Unittest") {
options {
timeout(time: 5, unit: 'MINUTES')
}
steps { unit_test("mxnet", "CPU") }
}
}
Expand Down
4 changes: 2 additions & 2 deletions python/dgl/contrib/graph_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def leave_barrier(worker_id, barrier_id):
def all_enter(worker_id, barrier_id):
return self._barrier.all_enter(worker_id, barrier_id)

self.server = SimpleXMLRPCServer(("localhost", port))
self.server = SimpleXMLRPCServer(("127.0.0.1", port))
self.server.register_function(register, "register")
self.server.register_function(get_graph_info, "get_graph_info")
self.server.register_function(init_ndata, "init_ndata")
Expand Down Expand Up @@ -533,7 +533,7 @@ class SharedMemoryDGLGraph(BaseGraphStore):
def __init__(self, graph_name, port):
self._graph_name = graph_name
self._pid = os.getpid()
self.proxy = xmlrpc.client.ServerProxy("http://localhost:" + str(port) + "/")
self.proxy = xmlrpc.client.ServerProxy("http://127.0.0.1:" + str(port) + "/")
self._worker_id, self._num_workers = self.proxy.register(graph_name)
if self._worker_id < 0:
raise Exception('fail to get graph ' + graph_name + ' from the graph store')
Expand Down
98 changes: 80 additions & 18 deletions tests/cpp/socket_communicator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
#include <gtest/gtest.h>
#include <string.h>
#include <unistd.h>
#include <string>

#include "../src/graph/network/socket_communicator.h"
Expand All @@ -14,24 +13,87 @@ using std::string;
using dgl::network::SocketSender;
using dgl::network::SocketReceiver;

void start_client();
bool start_server();

#ifndef WIN32

#include <unistd.h>

TEST(SocketCommunicatorTest, SendAndRecv) {
int pid = fork();
const char * msg = "0123456789";
ASSERT_GE(pid, 0);
if (pid > 0) { // parent: server
char serbuff[10];
memset(serbuff, '\0', 10);
SocketReceiver receiver;
receiver.Wait("127.0.0.1", 2049, 1, 500);
receiver.Recv(serbuff, 10);
ASSERT_EQ(string("0123456789"), string(serbuff, 10));
receiver.Finalize();
} else { // child: client
sleep(1);
SocketSender sender;
sender.AddReceiver("127.0.0.1", 2049, 0);
sender.Connect();
sender.Send(msg, 10, 0);
sender.Finalize();
if (pid > 0) {
EXPECT_TRUE(start_server());
} else {
start_client();
}
}
}

#else // WIN32

// Win32 doesn't have a fork() equivalent so use threads instead.

#include <windows.h>
#include <winsock2.h>

#pragma comment(lib, "ws2_32.lib")

void sleep(int seconds) {
Sleep(seconds * 1000);
}

DWORD WINAPI _ClientThreadFunc(LPVOID param) {
start_client();
return 0;
}

DWORD WINAPI _ServerThreadFunc(LPVOID param) {
return start_server() ? 1 : 0;
}

TEST(SocketCommunicatorTest, SendAndRecv) {
HANDLE hThreads[2];
WSADATA wsaData;
DWORD retcode, exitcode;

ASSERT_EQ(::WSAStartup(MAKEWORD(2, 2), &wsaData), 0);

hThreads[0] = ::CreateThread(NULL, 0, _ClientThreadFunc, NULL, 0, NULL); // client
ASSERT_TRUE(hThreads[0] != NULL);
hThreads[1] = ::CreateThread(NULL, 0, _ServerThreadFunc, NULL, 0, NULL); // server
ASSERT_TRUE(hThreads[1] != NULL);

retcode = ::WaitForMultipleObjects(2, hThreads, TRUE, INFINITE);
EXPECT_TRUE((retcode <= WAIT_OBJECT_0 + 1) && (retcode >= WAIT_OBJECT_0));

EXPECT_EQ(::GetExitCodeThread(hThreads[1], &exitcode), TRUE);
EXPECT_EQ(exitcode, 1);

EXPECT_EQ(::CloseHandle(hThreads[0]), TRUE);
EXPECT_EQ(::CloseHandle(hThreads[1]), TRUE);

::WSACleanup();
}

#endif // WIN32

void start_client() {
const char * msg = "0123456789";
sleep(1);
SocketSender sender;
sender.AddReceiver("127.0.0.1", 2049, 0);
sender.Connect();
sender.Send(msg, 10, 0);
sender.Finalize();
}

bool start_server() {
char serbuff[10];
memset(serbuff, '\0', 10);
SocketReceiver receiver;
receiver.Wait("127.0.0.1", 2049, 1, 500);
receiver.Recv(serbuff, 10);
receiver.Finalize();
return string("0123456789") == string(serbuff);
}
3 changes: 2 additions & 1 deletion tests/scripts/build_dgl.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ MD build

PUSHD build
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
cmake -DCMAKE_CXX_FLAGS="/DDGL_EXPORTS" -DCMAKE_CONFIGURATION_TYPES="Release" .. -G "Visual Studio 15 2017 Win64" || EXIT /B 1
cmake -DCMAKE_CXX_FLAGS="/DDGL_EXPORTS" -Dgtest_force_shared_crt=ON -DBUILD_CPP_TEST=1 -DCMAKE_CONFIGURATION_TYPES="Release" .. -G "Visual Studio 15 2017 Win64" || EXIT /B 1
msbuild dgl.sln || EXIT /B 1
COPY Release\dgl.dll .
COPY Release\runUnitTests.exe .
POPD

PUSHD python
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/build_dgl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mkdir build
rm -rf _download

pushd build
cmake ..
cmake .. -DBUILD_CPP_TEST=1
make -j4
popd

Expand Down
6 changes: 6 additions & 0 deletions tests/scripts/task_cpp_unit_test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ECHO OFF
SETLOCAL EnableDelayedExpansion

PUSHD build
runUnitTests.exe || EXIT /B 1
POPD
3 changes: 3 additions & 0 deletions tests/scripts/task_cpp_unit_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
pushd build
./runUnitTests

0 comments on commit 16af6eb

Please sign in to comment.