diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index b1704aa4f9..3bc86ea90c 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -169,6 +169,23 @@ jobs: - uses: actions/checkout@v2 - run: bazel build --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define with_debug_bthread_sche_safety=true --define with_debug_lock=true --define with_asan=true -- //... -//example/... + gcc-bazel-unittest: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: run bazel tests + run: bazel test --test_output=errors --verbose_failures --test_timeout=900 --define=with_glog=false --define=BRPC_WITH_GLOG=false -- //test/... + + clang-bazel-unittest: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - run: | + sudo apt-get update && sudo apt-get install -y clang-12 lldb-12 lld-12 libgtest-dev cmake gdb libstdc++6-11-dbg + shell: bash + - name: run bazel tests + run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang-12 --define=with_glog=false --define=BRPC_WITH_GLOG=false -- //test/... + clang-unittest: runs-on: ubuntu-22.04 steps: diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 05420ae310..71fa6e0599 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -16,6 +16,19 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") +load("//test:brpc_unit_test.bzl", "generate_brpc_unit_tests") +load("//test:flat_runfiles.bzl", "flat_runfiles") + +flat_runfiles( + name = "root_test_assets", + srcs = [ + "cert1.crt", + "cert1.key", + "cert2.crt", + "cert2.key", + "jsonout", + ], +) COPTS = [ "-D__STDC_FORMAT_MACROS", @@ -201,6 +214,20 @@ cc_test( ], ) +generate_brpc_unit_tests( + name = "brpc_test", + srcs = glob(["brpc_*_unittest.cpp"]), + copts = COPTS, + data = [":root_test_assets"], + deps = [ + ":cc_test_proto", + ":sstream_workaround", + ":gperftools_helper", + "//:brpc", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) cc_test( name = "bvar_test", diff --git a/test/brpc_alpn_protocol_unittest.cpp b/test/brpc_alpn_protocol_unittest.cpp index 21aada70d6..6c339354ee 100644 --- a/test/brpc_alpn_protocol_unittest.cpp +++ b/test/brpc_alpn_protocol_unittest.cpp @@ -20,12 +20,12 @@ #include "gtest/gtest.h" #include "gflags/gflags.h" - #include "brpc/channel.h" #include "brpc/details/ssl_helper.h" #include "brpc/server.h" #include "butil/endpoint.h" #include "butil/fd_guard.h" +#include "butil/logging.h" #include "echo.pb.h" DEFINE_string(listen_addr, "0.0.0.0:8011", "Server listen address."); @@ -48,7 +48,7 @@ class EchoServerImpl : public test::EchoService { response->set_message(request->message()); brpc::Controller* cntl = static_cast(controller); - LOG(NOTICE) << "protocol:" << cntl->request_protocol(); + LOG(INFO) << "protocol:" << cntl->request_protocol(); } }; diff --git a/test/brpc_http_rpc_protocol_unittest.cpp b/test/brpc_http_rpc_protocol_unittest.cpp index 5a6839c86f..9c2bbc00e2 100644 --- a/test/brpc_http_rpc_protocol_unittest.cpp +++ b/test/brpc_http_rpc_protocol_unittest.cpp @@ -20,7 +20,6 @@ // Date: Sun Jul 13 15:04:18 CST 2014 #include -#include #include #include #include @@ -1128,7 +1127,7 @@ class UploadServiceImpl : public ::test::UploadService { private: void check_header(brpc::Controller* cntl) { const std::string* test_header = cntl->http_request().GetHeader(TEST_PROGRESSIVE_HEADER); - GOOGLE_CHECK_NOTNULL(test_header); + CHECK(test_header != NULL); CHECK_EQ(*test_header, TEST_PROGRESSIVE_HEADER_VAL); } }; diff --git a/test/brpc_unit_test.bzl b/test/brpc_unit_test.bzl new file mode 100644 index 0000000000..b25f66d0bc --- /dev/null +++ b/test/brpc_unit_test.bzl @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def generate_brpc_unit_tests(name, srcs, deps, copts, data = []): + tests = [] + for s in srcs: + tgt = s.replace(".cpp", "") + native.cc_test( + name = tgt, + srcs = [s], + copts = copts, + data = data, + deps = deps, + ) + tests.append(":" + tgt) + + native.test_suite( + name = name, + tests = tests, + ) \ No newline at end of file diff --git a/test/flat_runfiles.bzl b/test/flat_runfiles.bzl new file mode 100644 index 0000000000..807e31ebc5 --- /dev/null +++ b/test/flat_runfiles.bzl @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def _flat_runfiles_impl(ctx): + r = ctx.runfiles() + for f in ctx.files.srcs: + r = r.merge(ctx.runfiles(symlinks = {f.basename: f})) + return DefaultInfo(runfiles = r) + +flat_runfiles = rule( + implementation = _flat_runfiles_impl, + attrs = { + "srcs": attr.label_list(allow_files = True), + }, +)