Skip to content

Commit

Permalink
Add BUILD files for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teodor-pripoae committed Jan 3, 2017
1 parent 23f4698 commit d3ede4d
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 2 deletions.
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ cc_binary(
],
visibility = ["//main:__pkg__"],
)

exports_files(["src/sofa/pbrpc/buffer.cc"], ["//unit-test:__pkg__"])
136 changes: 136 additions & 0 deletions unit-test/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
load("@protobuf//:protobuf.bzl", "cc_proto_library")

cc_proto_library(
name = "test_data",
srcs = [
"test_data.proto",
],
include = ".",
default_runtime = "@protobuf//:protobuf",
protoc = "@protobuf//:protoc",
deps = [
"//:cc_protos",
],
)

cc_binary(
name = "test_atomic",
srcs = ["test_atomic.cc"],
deps = [
"//:sofa-pbrpc",
],
visibility = ["//main:__pkg__"],
)

cc_library(
name = "test_buffer-deps",
hdrs = [
"//:src/sofa/pbrpc/buffer.cc",
],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_buffer",
srcs = ["test_buffer.cc"],
deps = [
":test_data",
"//:sofa-pbrpc",
":test_buffer-deps",
],
includes = ["src"],
copts = [
"-fno-access-control",
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_closure",
srcs = ["test_closure.cc"],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_common",
srcs = ["test_common.cc"],
deps = [
"//:sofa-pbrpc"
],
copts = [
"-DBAZEL_BUILD"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_epoll_support",
srcs = ["test_epoll_support.cc"],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_ext_closure",
srcs = ["test_ext_closure.cc"],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_io_service_pool",
srcs = ["test_io_service_pool.cc"],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_thread_group",
srcs = ["test_thread_group.cc"],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_timeout_manager",
srcs = ["test_timeout_manager.cc"],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_tran_buf_pool",
srcs = ["test_tran_buf_pool.cc"],
deps = [
"//:sofa-pbrpc"
],
visibility = ["//main:__pkg__"],
)

cc_binary(
name = "test_web_service",
srcs = ["test_web_service.cc"],
deps = [
"//:sofa-pbrpc"
],
copts = [
"-fno-access-control",
],
visibility = ["//main:__pkg__"],
)
41 changes: 41 additions & 0 deletions unit-test/run_bazel_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

function build()
{
name=$(echo $1 | awk -F '.' '{print $2}' | awk -F '/' '{print $2}')
bazel build :$name
if [ $? -ne 0 ]; then
echo "BUILD FAILED!!! for $name"
exit 1
fi
}

function run()
{
name=$(echo $1 | awk -F '.' '{print $2}' | awk -F '/' '{print $2}')
echo "===========" $name "==========="
bazel run :$name
../bazel-bin/unit-test/$name
if [ $? -ne 0 ]; then
echo "TEST FAILED!!!"
exit 1
fi
}

num=0
for test_case in `find . -name 'test_*.cc' -a` # -perm -100`
do
build $test_case
num=$((num+1))
done

num=0
for test_case in `find . -name 'test_*.cc' -a` # -perm -100`
do
run $test_case
num=$((num+1))
done

echo
echo "CASE NUM: $num"
echo "ALL CASE PASSED!!!"
8 changes: 6 additions & 2 deletions unit-test/test_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <gtest/gtest.h>

using namespace sofa;

class CommonTest : public ::testing::Test
{
protected:
Expand All @@ -19,7 +19,7 @@ class CommonTest : public ::testing::Test
//Called after every TEST_F(CommonTest, *)
};
};

TEST_F(CommonTest, test_log)
{
sofa::pbrpc::internal::set_log_level(sofa::pbrpc::LOG_LEVEL_NOTICE);
Expand Down Expand Up @@ -61,7 +61,11 @@ TEST_F(CommonTest, test_set_log_handler)
ASSERT_NE(old, (void*)NULL);

SLOG(ERROR, "found error %s", "boom!");
#ifdef BAZEL_BUILD
ASSERT_STREQ(s_test_log_buf.c_str(), "level=1 filename=unit-test/test_common.cc found error boom!");
#else
ASSERT_STREQ(s_test_log_buf.c_str(), "level=1 filename=test_common.cc found error boom!");
#endif
}

int main(int argc, char **argv)
Expand Down
2 changes: 2 additions & 0 deletions unit-test/test_data.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
syntax = "proto2";

package sofa.pbrpc.test;

message TestData {
Expand Down

0 comments on commit d3ede4d

Please sign in to comment.