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