test_template.gni 8.2 KB
Newer Older
M
maweiye 已提交
1
import("//build/test.gni")
G
ganlan 已提交
2
import("//third_party/musl/musl_config.gni")
M
maweiye 已提交
3

4 5 6
musl_base_dir = "third_party/musl/"
test_dir = "${musl_base_dir}/libc-test"
out_test_dir = "${root_out_dir}/obj/${musl_base_dir}/libc-test"
7 8 9 10 11

if (current_cpu == "arm") {
  musl_arch = "arm"
} else if (current_cpu == "arm64") {
  musl_arch = "aarch64"
W
wangjiahui 已提交
12 13
} else if (current_cpu == "x86_64") {
  musl_arch = "x86_64"
14
}
M
maweiye 已提交
15 16

musl_include_dir =
17 18 19
    "${root_out_dir}/obj/${musl_base_dir}/usr/include/${musl_arch}-linux-ohos"
musl_lib_dir =
    "${root_out_dir}/obj/${musl_base_dir}/usr/lib/${musl_arch}-linux-ohos"
M
maweiye 已提交
20

M
maweiye 已提交
21
test_lib_dir = "musl/libc-test-lib"
M
maweiye 已提交
22 23 24 25 26 27 28 29

template("test_unittest") {
  assert(defined(invoker.target_name),
         "file name is required in target ${target_name}")

  target_name = invoker.target_name
  target_dir = invoker.target_dir

30 31 32
  target("ohos_executable", "${target_name}") {
    subsystem_name = "musl"
    part_name = "libc-test"
M
maweiye 已提交
33

G
ganlan 已提交
34 35 36 37
    if (target_cpu == "arm64") {
      defines = [ "_ARM64_" ]
    }

M
maweiye 已提交
38 39 40 41
    sources = [ "${target_name}.c" ]
    include_dirs = [
      "//${test_dir}/src/common",
      "//${musl_include_dir}",
W
wangjiahui 已提交
42
      "//${test_dir}/src/functionalext/common",
G
ganlan 已提交
43 44
      "//${musl_base_dir}/include/arpa",
      "//${musl_base_dir}/src/process",
M
maweiye 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58
    ]

    cflags = []

    cflags_c = [
      "-pipe",
      "-std=c99",
      "-D_POSIX_C_SOURCE=200809L",
      "-Wall",
      "-Wno-unused",
      "-Wno-unused-function",
      "-Wno-missing-braces",
      "-Wno-overflow",
      "-Wno-unknown-pragmas",
M
maweiye 已提交
59 60
      "-Wno-unsupported-floating-point-opt",
      "-Wno-ignored-pragmas",
M
maweiye 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
      "-fno-builtin",
      "-frounding-math",
      "-Werror=implicit-function-declaration",
      "-Werror=implicit-int",
      "-Werror=pointer-sign",
      "-Werror=pointer-arith",
      "-g",
      "-D_FILE_OFFSET_BITS=64",
      "-c",
      "-o",
    ]

    ldflags = [ "-nostdlib" ]

    libs = [ "//${out_test_dir}/src/common/libtest.a" ]

    if (target_dir == "math") {
      include_dirs += [
        "//${test_dir}/src/math/crlibm",
        "//${test_dir}/src/math/gen",
        "//${test_dir}/src/math/sanity",
        "//${test_dir}/src/math/special",
        "//${test_dir}/src/math/ucb",
      ]

      cflags += [
        # math/dremf.c:1:9: error: '_GNU_SOURCE' macro redefined [-Werror,-Wmacro-redefined]
        # cflags_c无法生效此命令
        # -Wno-error无法屏蔽错误,改为屏蔽警告
        "-Wno-macro-redefined",
      ]
    }

    if (target_dir == "functional") {
      cflags_c += [
M
maweiye 已提交
96
        # include/${musl_arch}-linux-ohos/endian.h:26:25: error: '&' within '|' [-Werror,-Wbitwise-op-parentheses]
M
maweiye 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109
        "-Wno-error=bitwise-op-parentheses",

        #functional/sscanf.c:73:9: error: magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308 [-Werror,-Wliteral-range]
        "-Wno-error=literal-range",
      ]

      cflags += [
        # functional/strptime.c:3:9: error: '_GNU_SOURCE' macro redefined [-Werror,-Wmacro-redefined]
        "-Wno-macro-redefined",
      ]

      if (target_name == "dlopen") {
        ldflags += [ "-rdynamic" ]
110
        #libs += [ "//${root_out_dir}/${test_lib_dir}/libdlopen_dso.so" ]
M
maweiye 已提交
111 112
      }

Y
yangwenjun 已提交
113 114 115 116 117
      if (target_name == "dlopen_ns") {
        ldflags += [ "-rdynamic" ]
        #libs += [ "//${root_out_dir}/${test_lib_dir}/libdlopen_ns_dso.so" ]
      }

118 119 120 121 122
      if (target_name == "dlclose_reset") {
        ldflags += [ "-rdynamic" ]
        #libs += [ "//${root_out_dir}/${test_lib_dir}/libdlclose_reset_dso.so" ]
      }

123 124
      if (target_name == "tls_align") {
        ldflags += [ "-Wl,-rpath=src/functional" ]
125
        libs += [ "//${root_out_dir}/${test_lib_dir}/libtls_align_dso.so" ]
M
maweiye 已提交
126 127
      }

128 129
      if (target_name == "tls_init") {
        ldflags += [ "-Wl,-rpath=src/functional" ]
130
        libs += [ "//${root_out_dir}/${test_lib_dir}/libtls_init_dso.so" ]
M
maweiye 已提交
131 132 133
      }
    }

G
ganlan 已提交
134
    if (target_dir == "functionalext/fortify") {
135 136 137 138
      if (!defined(defines)) {
        defines = []
      }
      defines += [ "MUSL_FORTIFY_SOURCE=2" ]
G
ganlan 已提交
139 140
    }

W
wangjiahui 已提交
141 142 143 144 145 146 147 148 149 150 151 152
    if (target_dir == "functionalext/ldso_randomization") {
      if (target_name == "ldso_randomization_test") {
        ldflags += [ "-Wl,--export-dynamic,-rpath=./" ]
      }

      if (target_name == "ldso_randomization_manual") {
        ldflags += [ "-Wl,-rpath=./" ]
      }

      include_dirs += [ "//${test_dir}/src/functionalext/common" ]
    }

G
ganlan 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165
    if (target_dir == "functionalext/symver") {
      if (target_name == "dlsym" || target_name == "dlvsym" ||
          target_name == "dynlink" || target_name == "dynlink_default") {
        ldflags += [ "-Wl,-rpath=src/functional" ]
        libs += [
          "//${root_out_dir}/${test_lib_dir}/libdso_easy_symver.so",
          "//${root_out_dir}/${test_lib_dir}/libdso_hard_symver.so",
          "//${root_out_dir}/${test_lib_dir}/libdso_no_symver.so",
          "//${root_out_dir}/${test_lib_dir}/libdso_symver.so",
        ]
      }
    }

M
maweiye 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    if (target_dir == "musl") {
      cflags_c += [ "-w" ]

      libs += [
        "//${musl_lib_dir}/libc.a",
        "//${musl_lib_dir}/libm.a",
        "//${musl_lib_dir}/librt.a",
        "//${musl_lib_dir}/libcrypt.a",
        "//${musl_lib_dir}/libdl.a",
        "//${musl_lib_dir}/libresolv.a",
        "//${musl_lib_dir}/libutil.a",
        "//${musl_lib_dir}/libpthread.a",
      ]
    }

    if (target_dir == "regression") {
      cflags_c += [
        # regression/daemon-failure.c:56:24: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
        "-Wno-string-plus-int",
        "-Wno-error=string-plus-int",
      ]

      cflags += [
        # regression/syscall-sign-extend.c:3:9: error: '_GNU_SOURCE' macro redefined [-Werror,-Wmacro-redefined]
        "-Wno-macro-redefined",
      ]

      if (target_name == "tls_get_new-dtv") {
194
        ldflags += [ "-Wl,-rpath=./" ]
M
maweiye 已提交
195
        libs +=
196
            [ "//${root_out_dir}/${test_lib_dir}/libtls_get_new-dtv_dso.so" ]
M
maweiye 已提交
197 198
      }
    }
W
wangjiahui 已提交
199 200 201 202 203 204 205 206

    if (target_dir == "functionalext/relro") {
      if (target_name == "dlopen_ext_relro_test") {
        include_dirs += [ "//${test_dir}/src/functionalext/common" ]

        ldflags += [ "-Wl,-rpath=./" ]
      }
    }
G
ganlan 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

    if (target_dir == "functionalext/thread") {
      if (!defined(defines)) {
        defines = []
      }
      if (musl_target_os == "linux" && product_path != "" &&
          product_path != rebase_path("//productdefine/common/products")) {
        _product_config = read_file("${product_path}/config.json", "json")
        if (target_name == "pthread_stack_size") {
          if (defined(_product_config.device_stack_size)) {
            defines +=
                [ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ]
          }
        }
        if (target_name == "pthread_guard_size") {
          if (defined(_product_config.device_guard_size)) {
            defines +=
                [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ]
          }
        }
      }
    }
M
maweiye 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
  }
}

template("test_sharedlib") {
  assert(defined(invoker.target_name),
         "shared_lib name is required in target ${target_name}")

  target_name = invoker.target_name

  target("ohos_shared_library", "${target_name}") {
    include_dirs = [ "//${test_dir}/src/common" ]

    sources = [ "${target_name}.c" ]

    cflags_c = [
      "-pipe",
      "-std=c99",
      "-D_POSIX_C_SOURCE=200809L",
      "-Wall",
      "-Wno-unused",
      "-Wno-unused-function",
      "-Wno-missing-braces",
      "-Wno-overflow",
      "-Wno-unknown-pragmas",
M
maweiye 已提交
253
      "-Wno-unsupported-floating-point-opt",
M
maweiye 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
      "-fno-builtin",
      "-frounding-math",
      "-Werror=implicit-function-declaration",
      "-Werror=implicit-int",
      "-Werror=pointer-sign",
      "-Werror=pointer-arith",
      "-g",
      "-D_FILE_OFFSET_BITS=64",
      "-fPIC",
      "-DSHARED",
      "-c",
      "-o",
    ]

    ldflags = [
      "-shared",
      "-nostdlib",
    ]

G
ganlan 已提交
273 274 275 276 277
    if (defined(invoker.version_script)) {
      _version_script = rebase_path(invoker.version_script, root_build_dir)
      ldflags += [ "-Wl,--version-script=${_version_script}" ]
    }

G
ganlan 已提交
278 279 280 281
    if (defined(invoker.deps)) {
      deps = invoker.deps
    }

M
maweiye 已提交
282 283 284 285 286 287 288
    libs = [ "//${out_test_dir}/src/common/libtest.a" ]

    output_name = "${target_name}"

    output_extension = "so"

    subsystem_name = "musl"
M
maweiye 已提交
289
    part_name = "libc-test-lib"
M
maweiye 已提交
290 291
  }
}