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 math tests. 6 7This rule delegates testing to libc_test_rules.bzl:libc_test. 8It adds common math dependencies. 9""" 10 11load("//libc/test:libc_test_rules.bzl", "libc_test") 12 13def math_test(name, hdrs = [], deps = [], **kwargs): 14 """Add a target for the unittest of a math function. 15 16 Args: 17 name: The name of the function being tested. 18 hdrs: List of headers to add. 19 deps: The list of other libraries to be linked in to the test target. 20 **kwargs: Attributes relevant for a cc_test. For example, name, srcs. 21 """ 22 test_name = name + "_test" 23 libc_test( 24 name = test_name, 25 srcs = [test_name + ".cpp"] + hdrs, 26 libc_function_deps = ["//libc:func_name".replace("func_name", name)], 27 deps = [ 28 "//libc:__support_cpp_algorithm", 29 "//libc:__support_cpp_bit", 30 "//libc:__support_cpp_limits", 31 "//libc:__support_cpp_type_traits", 32 "//libc:__support_fputil_basic_operations", 33 "//libc:__support_fputil_cast", 34 "//libc:__support_fputil_fenv_impl", 35 "//libc:__support_fputil_fp_bits", 36 "//libc:__support_fputil_manipulation_functions", 37 "//libc:__support_fputil_nearest_integer_operations", 38 "//libc:__support_fputil_normal_float", 39 "//libc:__support_macros_properties_architectures", 40 "//libc:__support_macros_properties_os", 41 "//libc:__support_macros_properties_types", 42 "//libc:__support_math_extras", 43 "//libc:__support_uint128", 44 "//libc:hdr_errno_macros", 45 "//libc:hdr_fenv_macros", 46 "//libc:hdr_math_macros", 47 "//libc/test/UnitTest:fp_test_helpers", 48 ] + deps, 49 **kwargs 50 ) 51 52def math_mpfr_test(name, hdrs = [], deps = [], **kwargs): 53 """Add a target for the unittest of a math function. 54 55 Args: 56 name: The name of the function being tested. 57 hdrs: List of headers to add. 58 deps: The list of other libraries to be linked in to the test target. 59 **kwargs: Attributes relevant for a cc_test. For example, name, srcs. 60 """ 61 math_test( 62 name = name, 63 hdrs = hdrs, 64 deps = deps + ["//libc/utils/MPFRWrapper:mpfr_wrapper"], 65 **kwargs 66 ) 67