1# This file is licensed under the Apache License v2.0 with LLVM Exceptions. 2# See https://llvm.org/LICENSE.txt for license information. 3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 4 5"""LLVM libc starlark rules for tests. 6 7libc functions are created though the libc_build_rules.bzl:libc_function. 8They come in two flavors: 9 - the internal one that is scoped into the `LIBC_NAMESPACE` namespace. 10 - the libc one that is the regular C function. 11 12When performing tests we make sure to always use the internal version. 13""" 14 15load("//libc:libc_build_rules.bzl", "libc_common_copts", "libc_internal_target") 16load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS") 17 18def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], local_defines = [], **kwargs): 19 """Add target for a libc test. 20 21 Args: 22 name: Test target name 23 srcs: List of sources for the test. 24 libc_function_deps: List of libc_function targets used by this test. 25 copts: The list of options to add to the C++ compilation command. 26 deps: The list of other libraries to be linked in to the test target. 27 local_defines: The list of target local_defines if any. 28 **kwargs: Attributes relevant for a libc_test. For example, name, srcs. 29 """ 30 all_function_deps = libc_function_deps + ["//libc:errno"] 31 native.cc_test( 32 name = name, 33 srcs = srcs, 34 local_defines = local_defines + LIBC_CONFIGURE_OPTIONS, 35 deps = [libc_internal_target(d) for d in all_function_deps] + [ 36 "//libc/test/UnitTest:LibcUnitTest", 37 "//libc:__support_macros_config", 38 "//libc:func_aligned_alloc", 39 "//libc:func_free", 40 "//libc:func_malloc", 41 "//libc:func_realloc", 42 ] + deps, 43 copts = copts + libc_common_copts(), 44 linkstatic = 1, 45 **kwargs 46 ) 47