From e254c7a799db1b309d87da9fce5bc1c0d0e5b718 Mon Sep 17 00:00:00 2001 From: liaogang Date: Wed, 17 May 2017 20:44:43 +0800 Subject: [PATCH] add go unit test --- paddle/CMakeLists.txt | 4 ++++ paddle/go/CMakeLists.txt | 13 +++++++++++++ paddle/go/adder.go | 10 ++++++++++ paddle/go/cgo_test.cc | 7 +++++++ 4 files changed, 34 insertions(+) create mode 100644 paddle/go/CMakeLists.txt create mode 100644 paddle/go/adder.go create mode 100644 paddle/go/cgo_test.cc diff --git a/paddle/CMakeLists.txt b/paddle/CMakeLists.txt index 769955490..694ebb9ba 100644 --- a/paddle/CMakeLists.txt +++ b/paddle/CMakeLists.txt @@ -9,6 +9,10 @@ add_subdirectory(pserver) add_subdirectory(trainer) add_subdirectory(scripts) +if(${CMAKE_Go_COMPILER}) + add_subdirectory(go) +endif() + find_package(Boost QUIET) if(Boost_FOUND) diff --git a/paddle/go/CMakeLists.txt b/paddle/go/CMakeLists.txt new file mode 100644 index 000000000..482c948a5 --- /dev/null +++ b/paddle/go/CMakeLists.txt @@ -0,0 +1,13 @@ +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +go_library(adder SRCS adder.go) + +# cc_test(cgo_test +# SRCS +# cgo_test.cc +# DEPS +# adder) +add_executable(cgo_test cgo_test.cc) +add_dependencies(cgo_test adder) +target_link_libraries(cgo_test ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} adder) +add_test(cgo_test cgo_test) diff --git a/paddle/go/adder.go b/paddle/go/adder.go new file mode 100644 index 000000000..e14f40fd9 --- /dev/null +++ b/paddle/go/adder.go @@ -0,0 +1,10 @@ +package main + +import "C" + +//export GoAdder +func GoAdder(x, y int) int { + return x + y +} + +func main() {} // Required but ignored diff --git a/paddle/go/cgo_test.cc b/paddle/go/cgo_test.cc new file mode 100644 index 000000000..8d89a92c0 --- /dev/null +++ b/paddle/go/cgo_test.cc @@ -0,0 +1,7 @@ +#include "libadder.h" +#include +#include "gtest/gtest.h" + +TEST(Cgo, Invoke) { + EXPECT_EQ(GoAdder(30, 12), 42); +} -- GitLab