xref: /aosp_15_r20/external/sandboxed-api/sandboxed_api/sandbox2/testcases/BUILD.bazel (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2019 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Description: test cases for sandbox2 unit tests.
16#
17# Some of the following cc_binary options avoid dynamic linking which uses a
18# lot of syscalls (open, mmap, etc.):
19#   linkstatic = True                 Default for cc_binary
20#   features = ["fully_static_link"]  Adds -static
21#
22# Note that linking fully static with an unmodified glibc is not generally
23# considered safe, due to glibc relying heavily on loading shared objects at
24# runtime.
25# The rule of thumb when it is safe to do so is when the program either only
26# uses plain syscalls (bypassing any libc altogether) or if it does not use
27# any networking and none of the functionality from cstdio/stdio.h (due to
28# auto-loading of locale-specific shared objecs).
29
30load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
31
32package(default_visibility = [
33    "//sandboxed_api/sandbox2:__subpackages__",
34])
35
36licenses(["notice"])
37
38cc_binary(
39    name = "abort",
40    testonly = True,
41    srcs = ["abort.cc"],
42    copts = sapi_platform_copts(),
43    features = ["fully_static_link"],
44    deps = ["//sandboxed_api/util:raw_logging"],
45)
46
47cc_binary(
48    name = "add_policy_on_syscalls",
49    testonly = True,
50    srcs = ["add_policy_on_syscalls.cc"],
51    copts = sapi_platform_copts(),
52    features = ["fully_static_link"],
53)
54
55cc_binary(
56    name = "buffer",
57    testonly = True,
58    srcs = ["buffer.cc"],
59    copts = sapi_platform_copts(),
60    features = ["fully_static_link"],
61    deps = [
62        "//sandboxed_api/sandbox2:buffer",
63    ],
64)
65
66cc_binary(
67    name = "ipc",
68    testonly = True,
69    srcs = ["ipc.cc"],
70    copts = sapi_platform_copts(),
71    features = ["fully_static_link"],
72    deps = [
73        "//sandboxed_api/sandbox2:client",
74        "//sandboxed_api/sandbox2:comms",
75        "//sandboxed_api/util:raw_logging",
76        "@com_google_absl//absl/strings",
77    ],
78)
79
80cc_binary(
81    name = "malloc_system",
82    testonly = True,
83    srcs = ["malloc.cc"],
84    copts = sapi_platform_copts(),
85    features = ["fully_static_link"],
86)
87
88cc_binary(
89    name = "minimal_dynamic",
90    testonly = True,
91    srcs = ["minimal.cc"],
92    copts = sapi_platform_copts(),
93)
94
95cc_binary(
96    name = "minimal",
97    testonly = True,
98    srcs = ["minimal.cc"],
99    copts = sapi_platform_copts(),
100    features = ["fully_static_link"],
101)
102
103cc_binary(
104    name = "personality",
105    testonly = True,
106    srcs = ["personality.cc"],
107    copts = sapi_platform_copts(),
108    features = ["fully_static_link"],
109)
110
111cc_binary(
112    name = "pidcomms",
113    testonly = True,
114    srcs = ["pidcomms.cc"],
115    copts = sapi_platform_copts(),
116    features = ["fully_static_link"],
117    deps = [
118        "//sandboxed_api/sandbox2:client",
119        "//sandboxed_api/sandbox2:comms",
120        "//sandboxed_api/util:raw_logging",
121    ],
122)
123
124cc_binary(
125    name = "policy",
126    testonly = True,
127    srcs = ["policy.cc"],
128    copts = sapi_platform_copts(),
129    features = ["fully_static_link"],
130    deps = [
131        "//sandboxed_api:config",
132        "@com_google_absl//absl/base:core_headers",
133    ],
134)
135
136cc_binary(
137    name = "sanitizer",
138    testonly = True,
139    srcs = ["sanitizer.cc"],
140    copts = sapi_platform_copts(),
141    features = ["fully_static_link"],
142)
143
144cc_binary(
145    name = "close_fds",
146    testonly = True,
147    srcs = ["close_fds.cc"],
148    copts = sapi_platform_copts(),
149    deps = [
150        "//sandboxed_api/sandbox2:sanitizer",
151        "@com_google_absl//absl/container:flat_hash_set",
152        "@com_google_absl//absl/log:check",
153        "@com_google_absl//absl/status",
154        "@com_google_absl//absl/strings",
155    ],
156)
157
158cc_binary(
159    name = "sleep",
160    testonly = True,
161    srcs = ["sleep.cc"],
162    copts = sapi_platform_copts(),
163    features = ["fully_static_link"],
164)
165
166cc_library(
167    name = "symbolize_lib",
168    testonly = True,
169    srcs = ["symbolize_lib.cc"],
170    hdrs = ["symbolize_lib.h"],
171    copts = sapi_platform_copts([
172        "-fno-omit-frame-pointer",
173        "-fno-unwind-tables",
174        "-fno-asynchronous-unwind-tables",
175    ]),
176    features = ["fully_static_link"],
177    deps = [
178        "@com_google_absl//absl/base:core_headers",
179    ],
180)
181
182cc_binary(
183    name = "symbolize",
184    testonly = True,
185    srcs = ["symbolize.cc"],
186    copts = sapi_platform_copts(),
187    features = ["fully_static_link"],
188    deps = [
189        ":symbolize_lib",
190        "//sandboxed_api/util:raw_logging",
191        "@com_google_absl//absl/base:core_headers",
192        "@com_google_absl//absl/strings",
193    ],
194)
195
196cc_binary(
197    name = "tsync",
198    testonly = True,
199    srcs = ["tsync.cc"],
200    copts = sapi_platform_copts(),
201    features = ["fully_static_link"],
202    deps = [
203        "//sandboxed_api/sandbox2:client",
204        "//sandboxed_api/sandbox2:comms",
205    ],
206)
207
208cc_binary(
209    name = "starve",
210    testonly = True,
211    srcs = ["starve.cc"],
212    copts = sapi_platform_copts(),
213    features = ["fully_static_link"],
214)
215
216cc_binary(
217    name = "limits",
218    testonly = True,
219    srcs = ["limits.cc"],
220    copts = sapi_platform_copts(),
221    features = ["fully_static_link"],
222)
223
224cc_binary(
225    name = "namespace",
226    testonly = True,
227    srcs = ["namespace.cc"],
228    copts = sapi_platform_copts(),
229    features = ["fully_static_link"],
230    deps = [
231        "//sandboxed_api/sandbox2:comms",
232        "//sandboxed_api/util:file_base",
233        "//sandboxed_api/util:fileops",
234        "@com_google_absl//absl/container:flat_hash_set",
235        "@com_google_absl//absl/log:check",
236        "@com_google_absl//absl/strings",
237    ],
238)
239
240cc_binary(
241    name = "network_proxy",
242    testonly = True,
243    srcs = ["network_proxy.cc"],
244    copts = sapi_platform_copts(),
245    deps = [
246        "//sandboxed_api/sandbox2:client",
247        "//sandboxed_api/sandbox2:comms",
248        "//sandboxed_api/sandbox2/network_proxy:client",
249        "//sandboxed_api/util:fileops",
250        "//sandboxed_api/util:status",
251        "@com_google_absl//absl/base:log_severity",
252        "@com_google_absl//absl/flags:flag",
253        "@com_google_absl//absl/flags:parse",
254        "@com_google_absl//absl/log",
255        "@com_google_absl//absl/log:check",
256        "@com_google_absl//absl/log:globals",
257        "@com_google_absl//absl/log:initialize",
258        "@com_google_absl//absl/status",
259        "@com_google_absl//absl/status:statusor",
260        "@com_google_absl//absl/strings:str_format",
261        "@com_google_absl//absl/strings:string_view",
262    ],
263)
264
265cc_binary(
266    name = "custom_fork",
267    testonly = True,
268    srcs = ["custom_fork.cc"],
269    copts = sapi_platform_copts(),
270    features = ["fully_static_link"],
271    deps = [
272        "//sandboxed_api/sandbox2:comms",
273        "//sandboxed_api/sandbox2:forkingclient",
274        "//sandboxed_api/util:raw_logging",
275    ],
276)
277