ANDROID: Add build rules for selftests

tests.zip file contents:
  Length      Date    Time    Name
---------  ---------- -----   ----
    43552  2008-01-01 00:00   bazel-out/k8-fastbuild-ST-c33f95032a75/bin/common/testcases/selftests/x86_64/kselftest_binderfs_test
    14080  2008-01-01 00:00   bazel-out/k8-fastbuild-ST-c33f95032a75/bin/common/testcases/selftests/x86_64/kselftest_breakpoints_tests_breakpoint_test
    14216  2008-01-01 00:00   bazel-out/k8-fastbuild-ST-c33f95032a75/bin/common/testcases/selftests/x86_64/kselftest_breakpoints_tests_step_after_suspend_test
     2955  2008-01-01 00:00   bazel-out/k8-fastbuild-ST-c33f95032a75/bin/common/testcases/selftests/selftests.config
---------                     -------
    74803                     4 files

Change-Id: I34a0ca205d9b505bc38689b03bdb6463288fe56b
Signed-off-by: Weijia He <hwj@google.com>
Bug: 291147200
This commit is contained in:
Weijia He
2023-08-16 22:50:05 +00:00
parent 5e64585fe4
commit 8453aa945e
4 changed files with 232 additions and 0 deletions
+100
View File
@@ -1,11 +1,14 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2021 The Android Open Source Project
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
load("//build/bazel_common_rules/zip:zip.bzl", "zip_archive")
load("//build/kernel/kleaf:common_kernels.bzl", "define_common_kernels")
load(
"//build/kernel/kleaf:kernel.bzl",
"android_filegroup",
"checkpatch",
"ddk_headers",
"kernel_build",
@@ -13,6 +16,7 @@ load(
"kernel_modules_install",
"merged_kernel_uapi_headers",
)
load(":abi.bzl", "cc_binary_with_abi")
load(":modules.bzl", "get_gki_modules_list")
package(
@@ -827,3 +831,99 @@ ddk_headers(
includes = [],
visibility = ["//visibility:private"],
)
_KSELFTEST_DIR = "testcases/selftests"
config_setting(
name = "x86_64",
values = {"platforms": "//build/kernel/kleaf/impl:android_x86_64"},
visibility = ["//visibility:private"],
)
config_setting(
name = "arm64",
values = {"platforms": "//build/kernel/kleaf/impl:android_arm64"},
visibility = ["//visibility:private"],
)
cc_library(
name = "kselftest_headers_lib",
hdrs = glob(["tools/testing/selftests/*.h"]),
visibility = ["//visibility:private"],
)
cc_binary_with_abi(
name = "kselftest_binderfs_test",
srcs = ["tools/testing/selftests/filesystems/binderfs/binderfs_test.c"],
path_prefix = _KSELFTEST_DIR,
target_compatible_with = ["@platforms//os:android"],
visibility = ["//visibility:private"],
deps = [":kselftest_headers_lib"],
)
cc_binary_with_abi(
name = "kselftest_breakpoints_tests_step_after_suspend_test",
srcs = ["tools/testing/selftests/breakpoints/step_after_suspend_test.c"],
path_prefix = _KSELFTEST_DIR,
target_compatible_with = ["@platforms//os:android"],
visibility = ["//visibility:private"],
deps = [":kselftest_headers_lib"],
)
cc_binary_with_abi(
name = "kselftest_breakpoints_tests_breakpoint_test",
srcs = select({
":x86_64": ["tools/testing/selftests/breakpoints/breakpoint_test.c"],
":arm64": ["tools/testing/selftests/breakpoints/breakpoint_test_arm64.c"],
}),
path_prefix = _KSELFTEST_DIR,
target_compatible_with = ["@platforms//os:android"],
visibility = ["//visibility:private"],
deps = [":kselftest_headers_lib"],
)
copy_file(
name = "kselftest_gen_config",
src = select({
":x86_64": "tools/testing/selftests/android/config_x86_64.xml",
":arm64": "tools/testing/selftests/android/config_arm64.xml",
}),
out = _KSELFTEST_DIR + "/selftests.config",
visibility = ["//visibility:private"],
)
android_filegroup(
name = "kselftest_tests_x86_64",
srcs = [
":kselftest_binderfs_test_x86_64",
":kselftest_breakpoints_tests_breakpoint_test_x86_64",
":kselftest_breakpoints_tests_step_after_suspend_test_x86_64",
":kselftest_gen_config",
],
cpu = "x86_64",
visibility = ["//visibility:private"],
)
android_filegroup(
name = "kselftest_tests_arm64",
srcs = [
":kselftest_binderfs_test_arm64",
":kselftest_breakpoints_tests_breakpoint_test_arm64",
":kselftest_breakpoints_tests_step_after_suspend_test_arm64",
":kselftest_gen_config",
],
cpu = "arm64",
visibility = ["//visibility:private"],
)
zip_archive(
name = "tests_zip_x86_64",
srcs = [":kselftest_tests_x86_64"],
out = "tests.zip",
)
zip_archive(
name = "tests_zip_arm64",
srcs = [":kselftest_tests_arm64"],
out = "tests.zip",
)
+74
View File
@@ -0,0 +1,74 @@
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed 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.
"""
ABI aware build rules.
"""
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
visibility("private")
_ALL_ABIS = ["arm64", "x86_64"]
def _build_with_abi(name, build_rule, path_prefix, abis, visibility, **kwargs):
build_rule(name = name, visibility = visibility, **kwargs)
for abi in abis:
copy_file(
name = "{name}_{abi}".format(name = name, abi = abi),
src = ":{name}".format(name = name),
out = paths.join(path_prefix, abi, name),
allow_symlink = True,
visibility = visibility,
)
def cc_binary_with_abi(name, path_prefix = None, abis = None, visibility = None, **kwargs):
"""A cc_binary replacement that generates output in each subdirectory named by abi.
For example:
```
cc_binary_with_abi(
name = "a_binary",
abis = ["x86_64", "arm64"],
path_prefix = "my/path",
)
```
generates 2 rules:
* Rule a_binary_x86_64: Builds the cc_binary and put output in my/path/x86_64/a_binary.
* Rule a_binary_arm64: Builds the cc_binary and put output in my/path/arm64/a_binary.
Args:
name: the name of the build rule.
path_prefix: [Nonconfigurable](https://bazel.build/reference/be/common-definitions#configurable-attributes).
The path prefix to attach to output.
abis: [Nonconfigurable](https://bazel.build/reference/be/common-definitions#configurable-attributes).
The intended abis to generate.
visibility: [Nonconfigurable](https://bazel.build/reference/be/common-definitions#configurable-attributes).
The visibility attribute on a target controls whether the target can be used in other packages.
**kwargs: the rest args that cc_binary uses.
"""
if not path_prefix:
path_prefix = ""
if not abis:
abis = _ALL_ABIS
_build_with_abi(
name = name,
build_rule = native.cc_binary,
path_prefix = path_prefix,
abis = abis,
visibility = visibility,
**kwargs
)
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2023 The Android Open Source Project
Licensed 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.
-->
<configuration description="kselftest">
<option name="test-suite-tag" value="kernel-test" />
<target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer" />
<target_preparer class="com.android.tradefed.targetprep.StopServicesSetup" />
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
<option name="cleanup" value="true" />
<option name="push-file" key="selftests" value="/data/selftests" />
<option name="skip-abi-filtering" value="true" />
</target_preparer>
<test class="com.android.tradefed.testtype.binary.ExecutableTargetTest" >
<option name="test-command-line" key="kselftest_binderfs_test" value="chmod 755 /data/selftests/arm64/kselftest_binderfs_test;/data/selftests/arm64/kselftest_binderfs_test;" />
<option name="test-command-line" key="kselftest_breakpoints_tests_breakpoint_test" value="chmod 755 /data/selftests/arm64/kselftest_breakpoints_tests_breakpoint_test;/data/selftests/arm64/kselftest_breakpoints_tests_breakpoint_test;" />
<option name="test-command-line" key="kselftest_breakpoints_tests_step_after_suspend_test" value="chmod 755 /data/selftests/arm64/kselftest_breakpoints_tests_step_after_suspend_test;/data/selftests/arm64/kselftest_breakpoints_tests_step_after_suspend_test;" />
</test>
</configuration>
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2023 The Android Open Source Project
Licensed 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.
-->
<configuration description="kselftest">
<option name="test-suite-tag" value="kernel-test" />
<target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer" />
<target_preparer class="com.android.tradefed.targetprep.StopServicesSetup" />
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
<option name="cleanup" value="true" />
<option name="push-file" key="selftests" value="/data/selftests" />
<option name="skip-abi-filtering" value="true" />
</target_preparer>
<test class="com.android.tradefed.testtype.binary.ExecutableTargetTest" >
<option name="test-command-line" key="kselftest_binderfs_test" value="chmod 755 /data/selftests/x86_64/kselftest_binderfs_test;/data/selftests/x86_64/kselftest_binderfs_test;" />
<option name="test-command-line" key="kselftest_breakpoints_tests_breakpoint_test" value="chmod 755 /data/selftests/x86_64/kselftest_breakpoints_tests_breakpoint_test;/data/selftests/x86_64/kselftest_breakpoints_tests_breakpoint_test;" />
<option name="test-command-line" key="kselftest_breakpoints_tests_step_after_suspend_test" value="chmod 755 /data/selftests/x86_64/kselftest_breakpoints_tests_step_after_suspend_test;/data/selftests/x86_64/kselftest_breakpoints_tests_step_after_suspend_test;" />
</test>
</configuration>