1

windows tests: move tests, get rid of wine-binfmt

This removes all other Bazel test commands, so all tests can be again
tested with `bazel test ...`.

Also, fixes linux-arm64 glibc tests. Until now they've worked only in
CI. Now they work everywhere I tried.
This commit is contained in:
Motiejus Jakštys 2022-06-02 08:46:16 +03:00 committed by Motiejus Jakštys
parent 86ae317685
commit 3ac217e2cc
8 changed files with 63 additions and 53 deletions

View File

@ -5,7 +5,7 @@ packages:
- qemu-user-static - qemu-user-static
- binfmt-support - binfmt-support
- moreutils - moreutils
- wine-binfmt - wine64
sources: sources:
- https://git.sr.ht/~motiejus/bazel-zig-cc - https://git.sr.ht/~motiejus/bazel-zig-cc
environment: environment:

11
ci/test
View File

@ -1,13 +1,4 @@
#!/bin/bash #!/bin/bash
set -euo pipefail set -xeuo pipefail
bazel test ... bazel test ...
# Windows tests
# Unfortunately wine-binfmt breaks within the bazel sandbox, so we disable it
# to run this test.
bazel test //test/c:winver_windows_amd64 \
--spawn_strategy=standalone
# There is no no easy way to run windows_arm64 binaries on Linux, so we just
# cross compile one for testing.
bazel build //test/c:winver_windows_arm64

View File

@ -1,3 +1,10 @@
def _vars_script(env, run_under, cmd):
ret = ["#!/bin/sh"]
for k, v in env.items():
ret += ['export {}="{}"'.format(k, v)]
ret += ['exec {} {} "$@"'.format(run_under, cmd)]
return "\n".join(ret) + "\n" # trailing newline is easier on the eyes
def _platform_transition_impl(settings, attr): def _platform_transition_impl(settings, attr):
_ignore = settings _ignore = settings
return { return {
@ -17,16 +24,18 @@ def _platform_binary_impl(ctx):
executable = None executable = None
if source_info.files_to_run and source_info.files_to_run.executable: if source_info.files_to_run and source_info.files_to_run.executable:
command = _vars_script(ctx.attr.env, ctx.attr.run_under, source_info.files_to_run.executable.short_path)
executable = ctx.actions.declare_file("{}_{}".format(ctx.file.src.basename, ctx.attr.platform)) executable = ctx.actions.declare_file("{}_{}".format(ctx.file.src.basename, ctx.attr.platform))
ctx.actions.run_shell( ctx.actions.write(
command = "cp {} {}".format(source_info.files_to_run.executable.path, executable.path), output = executable,
inputs = [source_info.files_to_run.executable], content = command,
outputs = [executable], is_executable = True,
) )
return [DefaultInfo( return [DefaultInfo(
files = depset(ctx.files.src),
executable = executable, executable = executable,
files = depset([executable]),
runfiles = ctx.runfiles(files = ctx.files.src),
)] )]
_attrs = { _attrs = {
@ -38,6 +47,12 @@ _attrs = {
"platform": attr.string( "platform": attr.string(
doc = "The platform to build the target for.", doc = "The platform to build the target for.",
), ),
"run_under": attr.string(
doc = "wrapper executable",
),
"env": attr.string_dict(
doc = "Environment variables for the test",
),
"_allowlist_function_transition": attr.label( "_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist", default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
), ),

View File

@ -1,4 +1,4 @@
load("@bazel-zig-cc//rules:platform.bzl", "platform_binary", "platform_test") load("@bazel-zig-cc//rules:platform.bzl", "platform_binary")
cc_binary( cc_binary(
name = "which_libc", name = "which_libc",
@ -13,7 +13,9 @@ cc_binary(
platform_binary( platform_binary(
name = "which_libc_{}".format(name), name = "which_libc_{}".format(name),
src = "which_libc", src = "which_libc",
env = {"QEMU_LD_PREFIX": "/usr/aarch64-linux-gnu"} if is_arm64 else {},
platform = platform, platform = platform,
run_under = "qemu-aarch64-static" if is_arm64 else "",
), ),
sh_test( sh_test(
name = "test_libc_{}".format(name), name = "test_libc_{}".format(name),
@ -25,34 +27,12 @@ cc_binary(
}, },
), ),
) )
for name, platform, want in [ for name, platform, want, is_arm64 in [
("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl", "non-glibc"), ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl", "non-glibc", False),
("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19", "glibc_2.19"), ("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19", "glibc_2.19", False),
("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28", "glibc_2.28"), ("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28", "glibc_2.28", False),
("linux_amd64_gnu.2.31", "//libc_aware/platform:linux_amd64_gnu.2.31", "glibc_2.31"), ("linux_amd64_gnu.2.31", "//libc_aware/platform:linux_amd64_gnu.2.31", "glibc_2.31", False),
("linux_amd64", "//platform:linux_amd64", "glibc_2.19"), ("linux_amd64", "//platform:linux_amd64", "glibc_2.19", False),
("linux_arm64", "//platform:linux_arm64", "glibc_2.28"), ("linux_arm64", "//platform:linux_arm64", "glibc_2.28", True),
] ]
] ]
cc_binary(
name = "winver",
srcs = ["main_winver.c"],
target_compatible_with = [
"@platforms//os:windows",
],
)
platform_test(
name = "winver_windows_amd64",
src = "winver",
platform = "//platform:windows_amd64",
tags = ["manual"],
)
platform_binary(
name = "winver_windows_arm64",
src = "winver",
platform = "//platform:windows_arm64",
tags = ["manual"],
)

View File

@ -1,10 +1,11 @@
#/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
# shellcheck disable=SC2153
want=$WANT want=$WANT
# shellcheck disable=SC2153
binary=$BINARY binary=$BINARY
got=$($binary) got=$($binary)
if [[ "$got" != "$want" ]]; then if [[ "$got" != "$want" ]]; then

View File

@ -41,12 +41,14 @@ go_binary(
platform_test( platform_test(
name = "cgo_test_{}".format(name), name = "cgo_test_{}".format(name),
src = "cgo_test", src = "cgo_test",
env = {"QEMU_LD_PREFIX": "/usr/aarch64-linux-gnu"} if is_arm64 else {},
platform = platform, platform = platform,
run_under = "qemu-aarch64-static" if is_arm64 else "",
) )
for name, platform in [ for name, platform, is_arm64 in [
("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl"), ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl", False),
("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19"), ("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19", False),
("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"), ("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl", True),
("linux_arm64_gnu.2.28", "//libc_aware/platform:linux_arm64_gnu.2.28"), ("linux_arm64_gnu.2.28", "//libc_aware/platform:linux_arm64_gnu.2.28", True),
] ]
] ]

21
test/windows/BUILD Normal file
View File

@ -0,0 +1,21 @@
load("@bazel-zig-cc//rules:platform.bzl", "platform_binary", "platform_test")
cc_binary(
name = "winver",
srcs = ["main.c"],
tags = ["manual"],
)
platform_test(
name = "winver_windows_amd64",
src = "winver",
platform = "//platform:windows_amd64",
run_under = "wine64-stable",
tags = ["no-sandbox"],
)
platform_binary(
name = "winver_windows_arm64",
src = "winver",
platform = "//platform:windows_arm64",
)