1package {
2    // See: http://go/android-license-faq
3    // A large-scale-change added 'default_applicable_licenses' to import
4    // all of the 'license_kinds' from "packages_modules_DnsResolver_license"
5    // to get the below license kinds:
6    //   SPDX-license-identifier-Apache-2.0
7    default_applicable_licenses: ["packages_modules_DnsResolver_license"],
8}
9
10cc_test_library {
11    name: "libnetd_test_resolv_utils",
12    defaults: ["netd_defaults", "resolv_test_defaults"],
13    srcs: [
14        "resolv_test_utils.cpp",
15    ],
16    header_libs: [
17        "libnetd_resolv_headers",
18    ],
19    shared_libs: [
20        "libutils",
21    ],
22    static_libs: [
23        "netd_aidl_interface-lateststable-ndk_platform",
24        "libnetd_test_dnsresponder_ndk",
25        "libnetdutils",
26        "libgmock",
27    ],
28}
29
30cc_library_host_static {
31    name: "golddata_proto_host",
32    proto: {
33        export_proto_headers: true,
34        type: "full",
35    },
36    srcs: [
37        "golddata.proto",
38    ],
39}
40
41cc_binary_host {
42    name: "resolv_gold_test_pbtxt2pb_host",
43    cflags: [
44        "-Wall",
45        "-Werror",
46    ],
47    srcs: ["pbtxt2pb_converter_host.cpp"],
48    static_libs: [
49        "golddata_proto_host",
50        "libc++fs",
51        "libprotobuf-cpp-full",
52    ],
53}
54
55genrule {
56    name: "resolv_gold_test_pbtxt2pb",
57    tools: [
58        "resolv_gold_test_pbtxt2pb_host",
59        "soong_zip",
60    ],
61    srcs: ["testdata/*.pbtxt"],
62    // convert .pbtxt to .pb files; zip them as a single pb.zip.
63    cmd: "mkdir $(genDir)/pb && for fname in $(in); " +
64         "do $(location resolv_gold_test_pbtxt2pb_host) --in_file=$$fname " +
65         "--out_dir=$(genDir)/pb; done && " +
66         "$(location soong_zip) -o $(out) -C $(genDir)/pb -D $(genDir)/pb",
67    out: ["testdata/pb.zip"],
68}
69
70cc_library_static {
71    name: "golddata_proto",
72    defaults: ["netd_defaults"],
73    proto: {
74        export_proto_headers: true,
75        type: "lite",
76    },
77    srcs: [
78        "golddata.proto",
79    ],
80    tidy: false,
81}
82
83cc_test {
84    name: "resolv_gold_test",
85    test_suites: ["general-tests", "mts-dnsresolver"],
86    require_root: true,
87    // b/151392634, this is a workaround because MTS
88    // can not handle the test with testdata correctly.
89    // TODO: Remove the xml after MTS fixing the problem.
90    test_config: "resolv_gold_test_config.xml",
91    defaults: ["netd_defaults", "resolv_test_defaults"],
92    data: [":resolv_gold_test_pbtxt2pb"],
93    srcs: [
94        "resolv_gold_test.cpp",
95    ],
96    header_libs: [
97        "libnetd_client_headers",
98    ],
99    shared_libs: [
100        "libbinder_ndk",
101    ],
102    static_libs: [
103        "dnsresolver_aidl_interface-lateststable-ndk_platform",
104        "golddata_proto",
105        "libcrypto_static",
106        "libgmock",
107        "libnetd_resolv",
108        "libnetd_test_dnsresponder_ndk",
109        "libnetd_test_resolv_utils",
110        "libnetdutils",
111        "libprotobuf-cpp-lite",
112        "libssl",
113        "netd_aidl_interface-lateststable-ndk_platform",
114        "netd_event_listener_interface-lateststable-ndk_platform",
115        "server_configurable_flags",
116        "stats_proto",
117    ],
118    // MTS test binary can't be built under compile_multilib = "both" and having test data.
119    // However, MTS coverage requires 32 bit test binary to run.
120    compile_multilib: "prefer32",
121}
122
123cc_test {
124    name: "resolv_stress_test",
125    test_suites: ["general-tests", "mts-dnsresolver"],
126    // This won't work with test_config
127    // require_root: true,
128    // TODO: Remove resolv_test_mts_coverage_defaults after mts coverage switched to 64-bit device.
129    defaults: ["netd_defaults", "resolv_test_defaults", "resolv_test_mts_coverage_defaults"],
130    srcs: [
131        "resolv_stress_test.cpp",
132    ],
133    header_libs: [
134        "libnetd_resolv_headers",
135    ],
136    shared_libs: [
137        "libbinder_ndk",
138        "libnetd_client",
139    ],
140    static_libs: [
141        "dnsresolver_aidl_interface-lateststable-ndk_platform",
142        "libgmock",
143        "libnetd_test_dnsresponder_ndk",
144        "libnetd_test_resolv_utils",
145        "libnetdutils",
146        "libutils",
147        "netd_event_listener_interface-lateststable-ndk_platform",
148        "netd_aidl_interface-lateststable-ndk_platform",
149    ],
150}
151
152cc_test {
153    name: "resolv_integration_test",
154    test_suites: ["general-tests", "mts-dnsresolver"],
155    require_root: true,
156    test_config_template: ":resolv_test_config_template",
157    defaults: ["netd_defaults", "resolv_test_defaults"],
158    tidy: false, // cuts test build time by > 1m30s
159    srcs: [
160        "dns_responder/dns_responder.cpp",
161        "dnsresolver_binder_test.cpp",
162        "resolv_integration_test.cpp",
163        "tun_forwarder.cpp",
164    ],
165    header_libs: [
166        "dnsproxyd_protocol_headers",
167        "libnetd_resolv_headers",
168    ],
169    // TODO: make static link libc++ work.
170    //stl: "libc++_static",
171    shared_libs: [
172        "libbinder_ndk",
173        "libnetd_client",
174    ],
175    static_libs: [
176        "dnsresolver_aidl_interface-lateststable-ndk_platform",
177        "libbpf_android",
178        "libcrypto_static",
179        "libgmock",
180        "libnetd_test_dnsresponder_ndk",
181        "libnetd_test_metrics_listener",
182        "libnetd_test_resolv_utils",
183        "libnetdutils",
184        "libssl",
185        "libutils",
186        "netd_aidl_interface-lateststable-ndk_platform",
187        "netd_event_listener_interface-lateststable-ndk_platform",
188        "libipchecksum",
189        "resolv_unsolicited_listener",
190    ],
191    // This test talks to the DnsResolver module over a binary protocol on a socket, so keep it as
192    // multilib setting is worth because we might be able to get some coverage for the case where
193    // 32bit apps talk to 64bit resolvers.
194    compile_multilib: "both",
195    multilib: {
196        lib32: {
197            suffix: "32",
198        },
199        lib64: {
200            suffix: "64",
201        },
202    },
203}
204
205cc_test {
206    name: "resolv_unit_test",
207    test_suites: [
208        "general-tests",
209        "mts-dnsresolver",
210    ],
211    require_root: true,
212    // TODO: Drop root privileges and make it be an real unit test.
213    // TODO: Remove resolv_test_mts_coverage_defaults after mts coverage switched to 64-bit device.
214    defaults: [
215        "netd_defaults",
216        "resolv_test_defaults",
217        "resolv_test_mts_coverage_defaults",
218    ],
219    srcs: [
220        "resolv_cache_unit_test.cpp",
221        "resolv_callback_unit_test.cpp",
222        "resolv_tls_unit_test.cpp",
223        "resolv_unit_test.cpp",
224        ":resolv_unit_test_files",
225    ],
226    shared_libs: [
227        "libbinder_ndk",
228    ],
229    static_libs: [
230        "dnsresolver_aidl_interface-lateststable-ndk_platform",
231        "netd_aidl_interface-lateststable-ndk_platform",
232        "netd_event_listener_interface-lateststable-ndk_platform",
233        "libcrypto_static",
234        "libcutils",
235        "libgmock",
236        "libnetd_resolv",
237        "libnetd_test_dnsresponder_ndk",
238        "libnetd_test_resolv_utils",
239        "libnetdutils",
240        "libprotobuf-cpp-lite",
241        "libssl",
242        "libstatslog_resolv",
243        "libstatspush_compat",
244        "libsysutils",
245        "libutils",
246        "resolv_stats_test_utils",
247        "server_configurable_flags",
248        "stats_proto",
249    ],
250}
251
252cc_test_library {
253    name: "resolv_stats_test_utils",
254    srcs: [
255        "resolv_stats_test_utils.cpp"
256    ],
257    defaults: ["netd_defaults", "resolv_test_defaults"],
258    export_include_dirs: ["."],
259    static_libs: [
260        "libgmock",
261        "libnetdutils",
262        "libprotobuf-cpp-lite",
263        "stats_proto",
264    ],
265}
266
267cc_test {
268    name: "resolv_stats_test_utils_test",
269    srcs: [
270        "resolv_stats_test_utils_test.cpp",
271    ],
272    defaults: ["netd_defaults", "resolv_test_defaults"],
273    test_suites: ["general-tests"],
274    test_mainline_modules: [
275        "CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex",
276        "CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex"
277    ],
278    static_libs: [
279        "libgmock",
280        "libprotobuf-cpp-lite",
281        "resolv_stats_test_utils",
282        "stats_proto",
283    ],
284}
285
286cc_test {
287    name: "doh_ffi_test",
288    test_suites: [
289        "general-tests",
290    ],
291    defaults: ["netd_defaults"],
292    header_libs: [
293        "libnetd_resolv_internal_headers",
294    ],
295    srcs: ["doh_ffi_test.cpp"],
296    static_libs: [
297        "libcrypto_static",
298        "libdoh_ffi",
299        "libgmock",
300        "liblog",
301        "libring-core",
302        "libssl",
303    ],
304    min_sdk_version: "29",
305}
306