Skip to content

Commit 6638a34

Browse files
committed
Add bazel targets for libc/include/... tests.
Also, set `alwayslink=True` for `//libc/test:LibcUnitTest`. This ensures that the `main` function provided always gets linked into a test target. While not strictly necessary, it makes it so tests like https://github.com/llvm/llvm-project/blob/45d8759cbed0f216786729718608a8be72a505c6/libc/test/include/signbit_test.c will give a duplicate symbol error if they incorrectly depend on `LibcUnitTest`.
1 parent 9d33b92 commit 6638a34

File tree

3 files changed

+338
-11
lines changed

3 files changed

+338
-11
lines changed

utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ libc_test_library(
7171
"//libc:llvm_libc_macros_stdfix_macros",
7272
"//llvm:Support",
7373
],
74+
alwayslink = True,
7475
)
7576

7677
libc_test_library(

utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel

Lines changed: 317 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,335 @@
44

55
# Tests for LLVM libc public headers.
66

7-
load("//libc/test:libc_test_rules.bzl", "libc_test")
7+
load("//libc/test:libc_test_rules.bzl", "libc_test", "libc_test_library")
88

99
package(default_visibility = ["//visibility:public"])
1010

1111
licenses(["notice"])
1212

13+
libc_test(
14+
name = "assert_test",
15+
srcs = ["assert_test.cpp"],
16+
deps = ["//libc:public_headers_deps"],
17+
)
18+
19+
libc_test(
20+
name = "complex_test",
21+
srcs = ["complex_test.cpp"],
22+
deps = [
23+
"//libc:public_headers_deps",
24+
"//libc/test/UnitTest:fp_test_helpers",
25+
],
26+
)
27+
28+
libc_test_library(
29+
name = "fpclassify_test_fixture",
30+
hdrs = ["FpClassifyTest.h"],
31+
deps = ["//libc/test/UnitTest:fp_test_helpers"],
32+
)
33+
34+
libc_test(
35+
name = "fpclassify_test",
36+
srcs = ["fpclassify_test.cpp"],
37+
deps = [
38+
":fpclassify_test_fixture",
39+
"//libc:public_headers_deps",
40+
],
41+
)
42+
43+
libc_test(
44+
name = "fpclassifyf_test",
45+
srcs = ["fpclassifyf_test.cpp"],
46+
deps = [
47+
":fpclassify_test_fixture",
48+
"//libc:public_headers_deps",
49+
],
50+
)
51+
52+
libc_test(
53+
name = "fpclassifyl_test",
54+
srcs = ["fpclassifyl_test.cpp"],
55+
deps = [
56+
":fpclassify_test_fixture",
57+
"//libc:public_headers_deps",
58+
],
59+
)
60+
61+
libc_test(
62+
name = "fpclassify_c_test",
63+
srcs = ["fpclassify_test.c"],
64+
use_test_framework = False,
65+
deps = ["//libc:public_headers_deps"],
66+
)
67+
68+
libc_test_library(
69+
name = "isfinite_test_ficture",
70+
hdrs = ["IsFiniteTest.h"],
71+
deps = ["//libc/test/UnitTest:fp_test_helpers"],
72+
)
73+
74+
libc_test(
75+
name = "isfinite_test",
76+
srcs = ["isfinite_test.cpp"],
77+
deps = [
78+
":isfinite_test_ficture",
79+
"//libc:public_headers_deps",
80+
],
81+
)
82+
83+
libc_test(
84+
name = "isfinitef_test",
85+
srcs = ["isfinitef_test.cpp"],
86+
deps = [
87+
":isfinite_test_ficture",
88+
"//libc:public_headers_deps",
89+
],
90+
)
91+
92+
libc_test(
93+
name = "isfinitel_test",
94+
srcs = ["isfinitel_test.cpp"],
95+
deps = [
96+
":isfinite_test_ficture",
97+
"//libc:public_headers_deps",
98+
],
99+
)
100+
101+
libc_test(
102+
name = "isfinite_c_test",
103+
srcs = ["isfinite_test.c"],
104+
use_test_framework = False,
105+
deps = ["//libc:public_headers_deps"],
106+
)
107+
108+
libc_test_library(
109+
name = "isinf_test_fixture",
110+
hdrs = ["IsInfTest.h"],
111+
deps = ["//libc/test/UnitTest:fp_test_helpers"],
112+
)
113+
114+
libc_test(
115+
name = "isinf_test",
116+
srcs = ["isinf_test.cpp"],
117+
deps = [
118+
":isinf_test_fixture",
119+
"//libc:public_headers_deps",
120+
],
121+
)
122+
123+
libc_test(
124+
name = "isinff_test",
125+
srcs = ["isinff_test.cpp"],
126+
deps = [
127+
":isinf_test_fixture",
128+
"//libc:public_headers_deps",
129+
],
130+
)
131+
132+
libc_test(
133+
name = "isinfl_test",
134+
srcs = ["isinfl_test.cpp"],
135+
deps = [
136+
":isinf_test_fixture",
137+
"//libc:public_headers_deps",
138+
],
139+
)
140+
141+
libc_test(
142+
name = "isinf_c_test",
143+
srcs = ["isinf_test.c"],
144+
use_test_framework = False,
145+
deps = ["//libc:public_headers_deps"],
146+
)
147+
148+
libc_test_library(
149+
name = "isnan_test_fixture",
150+
hdrs = ["IsNanTest.h"],
151+
deps = ["//libc/test/UnitTest:fp_test_helpers"],
152+
)
153+
154+
libc_test(
155+
name = "isnan_test",
156+
srcs = ["isnan_test.cpp"],
157+
deps = [
158+
":isnan_test_fixture",
159+
"//libc:public_headers_deps",
160+
],
161+
)
162+
163+
libc_test(
164+
name = "isnanf_test",
165+
srcs = ["isnanf_test.cpp"],
166+
deps = [
167+
":isnan_test_fixture",
168+
"//libc:public_headers_deps",
169+
],
170+
)
171+
172+
libc_test(
173+
name = "isnanl_test",
174+
srcs = ["isnanl_test.cpp"],
175+
deps = [
176+
":isnan_test_fixture",
177+
"//libc:public_headers_deps",
178+
],
179+
)
180+
181+
libc_test(
182+
name = "isnan_c_test",
183+
srcs = ["isnan_test.c"],
184+
use_test_framework = False,
185+
deps = ["//libc:public_headers_deps"],
186+
)
187+
188+
libc_test_library(
189+
name = "isnormal_test_fixture",
190+
hdrs = ["IsNormalTest.h"],
191+
deps = ["//libc/test/UnitTest:fp_test_helpers"],
192+
)
193+
194+
libc_test(
195+
name = "isnormal_test",
196+
srcs = ["isnormal_test.cpp"],
197+
deps = [
198+
":isnormal_test_fixture",
199+
"//libc:public_headers_deps",
200+
],
201+
)
202+
203+
libc_test(
204+
name = "isnormalf_test",
205+
srcs = ["isnormalf_test.cpp"],
206+
deps = [
207+
":isnormal_test_fixture",
208+
"//libc:public_headers_deps",
209+
],
210+
)
211+
212+
libc_test(
213+
name = "isnormall_test",
214+
srcs = ["isnormall_test.cpp"],
215+
deps = [
216+
":isnormal_test_fixture",
217+
"//libc:public_headers_deps",
218+
],
219+
)
220+
221+
libc_test(
222+
name = "isnormal_c_test",
223+
srcs = ["isnormal_test.c"],
224+
use_test_framework = False,
225+
deps = ["//libc:public_headers_deps"],
226+
)
227+
228+
libc_test(
229+
name = "issubnormal_c_test",
230+
srcs = ["issubnormal_test.c"],
231+
use_test_framework = False,
232+
deps = ["//libc:public_headers_deps"],
233+
)
234+
235+
libc_test_library(
236+
name = "iszero_test_fixture",
237+
hdrs = ["IsZeroTest.h"],
238+
deps = ["//libc/test/UnitTest:fp_test_helpers"],
239+
)
240+
241+
libc_test(
242+
name = "iszero_test",
243+
srcs = ["iszero_test.cpp"],
244+
deps = [
245+
":iszero_test_fixture",
246+
"//libc:public_headers_deps",
247+
],
248+
)
249+
250+
libc_test(
251+
name = "iszerof_test",
252+
srcs = ["iszerof_test.cpp"],
253+
deps = [
254+
":iszero_test_fixture",
255+
"//libc:public_headers_deps",
256+
],
257+
)
258+
259+
libc_test(
260+
name = "iszerol_test",
261+
srcs = ["iszerol_test.cpp"],
262+
deps = [
263+
":iszero_test_fixture",
264+
"//libc:public_headers_deps",
265+
],
266+
)
267+
268+
libc_test(
269+
name = "iszero_c_test",
270+
srcs = ["iszero_test.c"],
271+
use_test_framework = False,
272+
deps = ["//libc:public_headers_deps"],
273+
)
274+
275+
libc_test_library(
276+
name = "signbit_test_fixture",
277+
hdrs = ["SignbitTest.h"],
278+
deps = ["//libc/test/UnitTest:fp_test_helpers"],
279+
)
280+
281+
libc_test(
282+
name = "signbit_test",
283+
srcs = ["signbit_test.cpp"],
284+
deps = [
285+
":signbit_test_fixture",
286+
"//libc:public_headers_deps",
287+
],
288+
)
289+
290+
libc_test(
291+
name = "signbitf_test",
292+
srcs = ["signbitf_test.cpp"],
293+
deps = [
294+
":signbit_test_fixture",
295+
"//libc:public_headers_deps",
296+
],
297+
)
298+
299+
libc_test(
300+
name = "signbitl_test",
301+
srcs = ["signbitl_test.cpp"],
302+
deps = [
303+
":signbit_test_fixture",
304+
"//libc:public_headers_deps",
305+
],
306+
)
307+
13308
libc_test(
14309
name = "stdbit_test",
15310
srcs = [
16311
"stdbit_stub.h",
17312
"stdbit_test.cpp",
18313
],
314+
deps = ["//libc:public_headers_deps"],
315+
)
316+
317+
libc_test(
318+
name = "signbit_c_test",
319+
srcs = ["signbit_test.c"],
320+
use_test_framework = False,
321+
deps = ["//libc:public_headers_deps"],
322+
)
323+
324+
libc_test(
325+
name = "stdckdint_test",
326+
srcs = ["stdckdint_test.cpp"],
327+
deps = ["//libc:public_headers_deps"],
328+
)
329+
330+
libc_test(
331+
name = "sys_queue_test",
332+
srcs = ["sys/queue_test.cpp"],
19333
deps = [
334+
"//libc:__support_char_vector",
335+
"//libc:__support_cpp_string",
20336
"//libc:public_headers_deps",
21337
],
22338
)

utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,38 @@ When performing tests we make sure to always use the internal version.
1515
load("//libc:libc_build_rules.bzl", "libc_common_copts")
1616
load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
1717

18-
def libc_test(name, copts = [], deps = [], local_defines = [], **kwargs):
18+
def libc_test(
19+
name,
20+
copts = [],
21+
deps = [],
22+
local_defines = [],
23+
use_test_framework = True,
24+
**kwargs):
1925
"""Add target for a libc test.
2026
2127
Args:
2228
name: Test target name
2329
copts: The list of options to add to the C++ compilation command.
2430
deps: The list of libc functions and libraries to be linked in.
2531
local_defines: The list of target local_defines if any.
32+
use_test_framework: Whether to use the libc unit test `main` function.
2633
**kwargs: Attributes relevant for a cc_test.
2734
"""
35+
deps = deps + [
36+
"//libc:__support_macros_config",
37+
"//libc:errno",
38+
"//libc:func_aligned_alloc",
39+
"//libc:func_free",
40+
"//libc:func_malloc",
41+
"//libc:func_realloc",
42+
]
43+
if use_test_framework:
44+
deps = deps + ["//libc/test/UnitTest:LibcUnitTest"]
45+
2846
native.cc_test(
2947
name = name,
3048
local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,
31-
deps = [
32-
"//libc/test/UnitTest:LibcUnitTest",
33-
"//libc:__support_macros_config",
34-
"//libc:errno",
35-
"//libc:func_aligned_alloc",
36-
"//libc:func_free",
37-
"//libc:func_malloc",
38-
"//libc:func_realloc",
39-
] + deps,
49+
deps = deps,
4050
copts = copts + libc_common_copts(),
4151
linkstatic = 1,
4252
**kwargs

0 commit comments

Comments
 (0)