1import("//build/test.gni") 2import("//third_party/musl/musl_config.gni") 3 4musl_base_dir = "third_party/musl/" 5test_dir = "${musl_base_dir}/libc-test" 6out_test_dir = "${root_out_dir}/obj/${musl_base_dir}/libc-test" 7 8if (current_cpu == "arm") { 9 musl_arch = "arm" 10} else if (current_cpu == "arm64") { 11 musl_arch = "aarch64" 12} else if (current_cpu == "x86_64") { 13 musl_arch = "x86_64" 14} 15 16musl_include_dir = 17 "${root_out_dir}/obj/${musl_base_dir}/usr/include/${musl_arch}-linux-ohos" 18musl_lib_dir = 19 "${root_out_dir}/obj/${musl_base_dir}/usr/lib/${musl_arch}-linux-ohos" 20 21test_lib_dir = "musl/libc-test-lib" 22 23musl_src_base = "${root_out_dir}/obj/${musl_base_dir}/${musl_ported_dir}" 24 25template("test_unittest") { 26 assert(defined(invoker.target_name), 27 "file name is required in target ${target_name}") 28 29 target_name = invoker.target_name 30 target_dir = invoker.target_dir 31 if (defined(invoker.musl_unit_test_flag)) { 32 musl_unit_test_flag = invoker.musl_unit_test_flag 33 } 34 target("ohos_executable", "${target_name}") { 35 subsystem_name = "musl" 36 part_name = "libc-test" 37 38 if (target_cpu == "arm64") { 39 defines = [ "_ARM64_" ] 40 } 41 42 sources = [ "${target_name}.c" ] 43 include_dirs = [ 44 "//${test_dir}/src/common", 45 "//${musl_include_dir}", 46 "//${test_dir}/src/functionalext/common", 47 "//${musl_base_dir}/include/arpa", 48 "//${musl_base_dir}/src/process", 49 ] 50 51 cflags = [] 52 53 cflags_c = [ 54 "-pipe", 55 "-std=c99", 56 "-D_POSIX_C_SOURCE=200809L", 57 "-Wall", 58 "-Wno-unused", 59 "-Wno-unused-function", 60 "-Wno-missing-braces", 61 "-Wno-overflow", 62 "-Wno-unknown-pragmas", 63 "-Wno-unsupported-floating-point-opt", 64 "-Wno-ignored-pragmas", 65 "-fno-builtin", 66 "-frounding-math", 67 "-Werror=implicit-function-declaration", 68 "-Werror=implicit-int", 69 "-Werror=pointer-sign", 70 "-Werror=pointer-arith", 71 "-g", 72 "-D_FILE_OFFSET_BITS=64", 73 "-c", 74 "-o", 75 ] 76 77 if (use_pthread_cancel) { 78 cflags += [ "-DFEATURE_PTHREAD_CANCEL" ] 79 } 80 81 ldflags = [ "-nostdlib" ] 82 83 libs = [ "//${out_test_dir}/src/common/libtest.a" ] 84 if (!musl_unit_test_flag) { 85 libs += [ "${musl_lib_dir}/libc.a" ] 86 } 87 88 if (target_dir == "math") { 89 include_dirs += [ 90 "//${test_dir}/src/math/crlibm", 91 "//${test_dir}/src/math/gen", 92 "//${test_dir}/src/math/sanity", 93 "//${test_dir}/src/math/special", 94 "//${test_dir}/src/math/ucb", 95 ] 96 97 cflags += [ 98 # math/dremf.c:1:9: error: '_GNU_SOURCE' macro redefined [-Werror,-Wmacro-redefined] 99 # cflags_c无法生效此命令 100 # -Wno-error无法屏蔽错误,改为屏蔽警告 101 "-Wno-macro-redefined", 102 ] 103 } 104 105 if (target_dir == "functional") { 106 cflags_c += [ 107 # include/${musl_arch}-linux-ohos/endian.h:26:25: error: '&' within '|' [-Werror,-Wbitwise-op-parentheses] 108 "-Wno-error=bitwise-op-parentheses", 109 110 #functional/sscanf.c:73:9: error: magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308 [-Werror,-Wliteral-range] 111 "-Wno-error=literal-range", 112 ] 113 114 cflags += [ 115 # functional/strptime.c:3:9: error: '_GNU_SOURCE' macro redefined [-Werror,-Wmacro-redefined] 116 "-Wno-macro-redefined", 117 ] 118 119 if (target_name == "dlopen") { 120 ldflags += [ "-rdynamic" ] 121 #libs += [ "//${root_out_dir}/${test_lib_dir}/libdlopen_dso.so" ] 122 } 123 124 if (target_name == "dlopen_ns") { 125 ldflags += [ "-rdynamic" ] 126 #libs += [ "//${root_out_dir}/${test_lib_dir}/libdlopen_ns_dso.so" ] 127 } 128 129 if (target_name == "dlclose_reset") { 130 ldflags += [ "-rdynamic" ] 131 #libs += [ "//${root_out_dir}/${test_lib_dir}/libdlclose_reset_dso.so" ] 132 } 133 134 if (target_name == "tls_align") { 135 ldflags += [ "-Wl,-rpath=./" ] 136 libs += [ "//${root_out_dir}/${test_lib_dir}/libtls_align_dso.so" ] 137 } 138 139 if (target_name == "tls_init") { 140 ldflags += [ "-Wl,-rpath=./" ] 141 libs += [ "//${root_out_dir}/${test_lib_dir}/libtls_init_dso.so" ] 142 } 143 144 if (target_name == "test-malloc-info") { 145 deps = [ "//third_party/libxml2:xml2" ] 146 } 147 } 148 149 if (target_dir == "functionalext/fortify") { 150 if (!defined(defines)) { 151 defines = [] 152 } 153 defines += [ "_FORTIFY_SOURCE=2" ] 154 } 155 156 if (target_dir == "functionalext/ldso_randomization") { 157 if (target_name == "ldso_randomization_test") { 158 ldflags += [ "-Wl,--export-dynamic,-rpath=./" ] 159 } 160 161 if (target_name == "ldso_randomization_manual") { 162 ldflags += [ "-Wl,-rpath=./" ] 163 } 164 165 include_dirs += [ "//${test_dir}/src/functionalext/common" ] 166 } 167 168 if (target_dir == "functionalext/symver") { 169 ldflags += [ "-Wl,-rpath=./" ] 170 if (target_name == "dlsym" || target_name == "dlvsym" || 171 target_name == "dynlink" || target_name == "dynlink_default") { 172 libs += [ 173 "//${root_out_dir}/${test_lib_dir}/libdso_easy_symver.so", 174 "//${root_out_dir}/${test_lib_dir}/libdso_hard_symver.so", 175 "//${root_out_dir}/${test_lib_dir}/libdso_no_symver.so", 176 "//${root_out_dir}/${test_lib_dir}/libdso_symver.so", 177 ] 178 } 179 } 180 181 if (target_dir == "musl") { 182 cflags_c += [ "-w" ] 183 184 libs += [ 185 "//${musl_lib_dir}/libc.a", 186 "//${musl_lib_dir}/libm.a", 187 "//${musl_lib_dir}/librt.a", 188 "//${musl_lib_dir}/libcrypt.a", 189 "//${musl_lib_dir}/libdl.a", 190 "//${musl_lib_dir}/libresolv.a", 191 "//${musl_lib_dir}/libutil.a", 192 "//${musl_lib_dir}/libpthread.a", 193 ] 194 } 195 196 if (target_dir == "regression") { 197 cflags_c += [ 198 # regression/daemon-failure.c:56:24: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int] 199 "-Wno-string-plus-int", 200 "-Wno-error=string-plus-int", 201 ] 202 203 cflags += [ 204 # regression/syscall-sign-extend.c:3:9: error: '_GNU_SOURCE' macro redefined [-Werror,-Wmacro-redefined] 205 "-Wno-macro-redefined", 206 ] 207 208 if (target_name == "tls_get_new-dtv") { 209 ldflags += [ "-Wl,-rpath=./" ] 210 libs += 211 [ "//${root_out_dir}/${test_lib_dir}/libtls_get_new-dtv_dso.so" ] 212 } 213 } 214 215 if (target_dir == "functionalext/relro") { 216 if (target_name == "dlopen_ext_relro_test") { 217 include_dirs += [ "//${test_dir}/src/functionalext/common" ] 218 219 ldflags += [ "-Wl,-rpath=./" ] 220 } 221 } 222 223 if (target_dir == "functionalext/thread") { 224 if (!defined(defines)) { 225 defines = [] 226 } 227 if (musl_target_os == "linux" && product_path != "" && 228 product_path != rebase_path("//productdefine/common/products")) { 229 _product_config = read_file("${product_path}/config.json", "json") 230 if (target_name == "pthread_stack_size") { 231 if (defined(_product_config.device_stack_size)) { 232 defines += 233 [ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ] 234 } 235 } 236 if (target_name == "pthread_guard_size") { 237 if (defined(_product_config.device_guard_size)) { 238 defines += 239 [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ] 240 } 241 } 242 } 243 } 244 245 if (target_dir == "functionalext/sigchain") { 246 include_dirs += [ "//${musl_base_dir}/include" ] 247 } 248 } 249} 250 251template("test_sharedlib") { 252 assert(defined(invoker.target_name), 253 "shared_lib name is required in target ${target_name}") 254 255 target_name = invoker.target_name 256 257 target("ohos_shared_library", "${target_name}") { 258 include_dirs = [ "//${test_dir}/src/common" ] 259 260 sources = [ "${target_name}.c" ] 261 262 cflags_c = [ 263 "-pipe", 264 "-std=c99", 265 "-D_POSIX_C_SOURCE=200809L", 266 "-Wall", 267 "-Wno-unused", 268 "-Wno-unused-function", 269 "-Wno-missing-braces", 270 "-Wno-overflow", 271 "-Wno-unknown-pragmas", 272 "-Wno-unsupported-floating-point-opt", 273 "-fno-builtin", 274 "-frounding-math", 275 "-Werror=implicit-function-declaration", 276 "-Werror=implicit-int", 277 "-Werror=pointer-sign", 278 "-Werror=pointer-arith", 279 "-g", 280 "-D_FILE_OFFSET_BITS=64", 281 "-fPIC", 282 "-DSHARED", 283 "-c", 284 "-o", 285 ] 286 287 ldflags = [ 288 "-shared", 289 "-nostdlib", 290 ] 291 292 if (defined(invoker.version_script)) { 293 _version_script = rebase_path(invoker.version_script, root_build_dir) 294 ldflags += [ "-Wl,--version-script=${_version_script}" ] 295 } 296 297 if (defined(invoker.deps)) { 298 deps = invoker.deps 299 } 300 301 libs = [ "//${out_test_dir}/src/common/libtest.a" ] 302 303 output_name = "${target_name}" 304 305 output_extension = "so" 306 307 subsystem_name = "musl" 308 part_name = "libc-test-lib" 309 } 310} 311