Skip to content

Commit 9e69e62

Browse files
committed
add bazel unittest in CI
1 parent c5f98f9 commit 9e69e62

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

.github/workflows/ci-linux.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ jobs:
169169
- uses: actions/checkout@v2
170170
- 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/...
171171

172+
gcc-bazel-unittest:
173+
runs-on: ubuntu-22.04
174+
env:
175+
HTTP_PROXY: http://127.0.0.1:7890 # 假设代理端口是7890
176+
HTTPS_PROXY: http://127.0.0.1:7890
177+
NO_PROXY: localhost,127.0.0.1
178+
steps:
179+
- uses: actions/checkout@v2
180+
# - uses: bazelbuild/setup-bazelisk@v2
181+
- name: run bazel tests
182+
run: bazel test --test_output=errors --verbose_failures -- //test/...
183+
184+
clang-bazel-unittest:
185+
runs-on: ubuntu-22.04
186+
steps:
187+
- uses: actions/checkout@v2
188+
- uses: bazelbuild/setup-bazelisk@v2
189+
- name: run bazel tests
190+
run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang -- //test/... //...
191+
172192
clang-unittest:
173193
runs-on: ubuntu-22.04
174194
steps:

test/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
1717
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test")
1818
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")
1919
load("//test:brpc_unit_test.bzl", "generate_brpc_unit_tests")
20+
load("//test:flat_runfiles.bzl", "flat_runfiles")
21+
22+
flat_runfiles(
23+
name = "root_test_assets",
24+
srcs = [
25+
"cert1.crt",
26+
"cert1.key",
27+
"cert2.crt",
28+
"cert2.key",
29+
"jsonout",
30+
],
31+
)
2032

2133
COPTS = [
2234
"-D__STDC_FORMAT_MACROS",
@@ -206,6 +218,7 @@ generate_brpc_unit_tests(
206218
name = "brpc_test",
207219
srcs = glob(["brpc_*_unittest.cpp"]),
208220
copts = COPTS,
221+
data = [":root_test_assets"],
209222
deps = [
210223
":cc_test_proto",
211224
":sstream_workaround",

test/brpc_unit_test.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
def generate_brpc_unit_tests(name, srcs, deps, copts):
16+
def generate_brpc_unit_tests(name, srcs, deps, copts, data = []):
1717
tests = []
1818
for s in srcs:
1919
tgt = s.replace(".cpp", "")
2020
native.cc_test(
2121
name = tgt,
2222
srcs = [s],
2323
copts = copts,
24+
data = data,
2425
deps = deps,
2526
)
2627
tests.append(":" + tgt)

test/flat_runfiles.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def _flat_runfiles_impl(ctx):
2+
r = ctx.runfiles()
3+
for f in ctx.files.srcs:
4+
r = r.merge(ctx.runfiles(symlinks = {f.basename: f}))
5+
return DefaultInfo(runfiles = r)
6+
7+
flat_runfiles = rule(
8+
implementation = _flat_runfiles_impl,
9+
attrs = {
10+
"srcs": attr.label_list(allow_files = True),
11+
},
12+
)

0 commit comments

Comments
 (0)