diff --git a/WORKSPACE b/WORKSPACE index 06495690ab9d11140f1b60ec496f57e40f817d71..38e1628d11c20b5b09bf4e68ad89dad8aa71bdc0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,8 +1,22 @@ +# External dependency to grpc-enabled Google-styleprotobuf bulding +# rules. This method comes from +# https://github.com/pubref/rules_protobuf#usage. git_repository( name = "org_pubref_rules_protobuf", remote = "https://github.com/pubref/rules_protobuf", tag = "v0.7.1", ) +# External dependency to gtest 1.7.0. This method comes from +# https://www.bazel.io/versions/master/docs/tutorial/cpp.html. +new_http_archive( + name = "gtest", + url = "https://github.com/google/googletest/archive/release-1.7.0.zip", + sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0", + build_file = "third_party/gtest.BUILD", + strip_prefix = "googletest-release-1.7.0", +) + + load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cpp_proto_repositories") cpp_proto_repositories() diff --git a/doc/getstarted/build_and_install/docker_install_en.rst b/doc/getstarted/build_and_install/docker_install_en.rst index f6f1bbab428059828d46204610e0f2a769ec5ebc..feb027ccbbcdb68766e3462f0b8180e3734ef9c7 100644 --- a/doc/getstarted/build_and_install/docker_install_en.rst +++ b/doc/getstarted/build_and_install/docker_install_en.rst @@ -161,12 +161,13 @@ The general development workflow with Docker and Bazel is as follows: cd /paddle # where paddle source code has been mounted into the container mkdir -p build cd build - cmake .. + cmake -DWITH_TESTING=ON .. make -j `nproc` + CTEST_OUTPUT_ON_FAILURE=1 ctest or Bazel in the container: .. code-block:: bash cd /paddle - bazel build ... + bazel test ... diff --git a/third_party/gtest.BUILD b/third_party/gtest.BUILD new file mode 100644 index 0000000000000000000000000000000000000000..3e68a1d879311de905fab2f4cd3486a4c72a3532 --- /dev/null +++ b/third_party/gtest.BUILD @@ -0,0 +1,14 @@ +cc_library( + name = "main", + srcs = glob( + ["src/*.cc"], + exclude = ["src/gtest-all.cc"] + ), + hdrs = glob([ + "include/**/*.h", + "src/*.h" + ]), + copts = ["-Iexternal/gtest/include"], + linkopts = ["-pthread"], + visibility = ["//visibility:public"], +) diff --git a/third_party/protobuf_test/BUILD b/third_party/protobuf_test/BUILD index 7c5b1c69947a317c6d82a8c7a140248fb514985f..6208b870829db4470c4b247836de22c1a5e56a2d 100644 --- a/third_party/protobuf_test/BUILD +++ b/third_party/protobuf_test/BUILD @@ -7,6 +7,7 @@ cpp_proto_library( protos = [ "example.proto" ], + with_grpc = True, ) cc_library( @@ -15,3 +16,13 @@ cc_library( hdrs = ["example_lib.h"], deps = [":example_proto"], ) + +cc_test( + name = "example_lib_test", + srcs = ["example_lib_test.cc"], + copts = ["-Iexternal/gtest/include"], + deps =[ + "@gtest//:main", + ":example_lib", + ], +) diff --git a/third_party/protobuf_test/example.proto b/third_party/protobuf_test/example.proto index 57c52d3521f345c9722e21a6ffaea76891c7dc13..6a7eada9c14a9df5d3ef8971b636c14a11da3d11 100644 --- a/third_party/protobuf_test/example.proto +++ b/third_party/protobuf_test/example.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package protos; +package third_party.protobuf_test; message Greeting { string name = 1; diff --git a/third_party/protobuf_test/example_lib.cc b/third_party/protobuf_test/example_lib.cc index 8d55ed66deae3ff05eb1d2f6e2564a65891a8c23..56341a0124c0c22897aad8f5e1b85f9e28567a22 100644 --- a/third_party/protobuf_test/example_lib.cc +++ b/third_party/protobuf_test/example_lib.cc @@ -1,6 +1,11 @@ #include "third_party/protobuf_test/example_lib.h" -#include -std::string get_greet(const ::protos::Greeting& who) { +namespace third_party { +namespace protobuf_test { + +std::string get_greet(const Greeting& who) { return "Hello " + who.name(); } + +} // namespace protobuf_test +} // namespace thrid_party diff --git a/third_party/protobuf_test/example_lib.h b/third_party/protobuf_test/example_lib.h index eaf4dd4cea7e4b23ddf33ec7630dcd4db12be0de..516326e812e19eb162f5392b519904a65c66c660 100644 --- a/third_party/protobuf_test/example_lib.h +++ b/third_party/protobuf_test/example_lib.h @@ -4,4 +4,10 @@ #include -std::string get_greet(const ::protos::Greeting &who); +namespace third_party { +namespace protobuf_test { + +std::string get_greet(const Greeting &who); + +} // namespace protobuf_test +} // namespace third_party diff --git a/third_party/protobuf_test/example_lib_test.cc b/third_party/protobuf_test/example_lib_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..6229f56e6026908fff991765bd6bdaff6f8236ac --- /dev/null +++ b/third_party/protobuf_test/example_lib_test.cc @@ -0,0 +1,15 @@ +#include "third_party/protobuf_test/example_lib.h" + +#include "gtest/gtest.h" + +namespace third_party { +namespace protobuf_test { + +TEST(ProtobufTest, GetGreet) { + Greeting g; + g.set_name("Paddle"); + EXPECT_EQ("Hello Paddle", get_greet(g)); +} + +} // namespace protobuf_test +} // namespace third_party