1/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package {
18    // See: http://go/android-license-faq
19    // Inherits all licenses from parent to get Apache 2.0 and package name.
20    default_applicable_licenses: [
21        "packages_modules_NeuralNetworks_runtime_license",
22    ],
23}
24
25cc_library_static {
26    name: "libneuralnetworks_fuzzer_proto",
27    host_supported: true,
28    vendor_available: true,
29    owner: "google",
30    srcs: ["Model.proto"],
31    proto: {
32        type: "full",
33        export_proto_headers: true,
34    },
35    shared_libs: ["libprotobuf-cpp-full"],
36}
37
38cc_library_static {
39    name: "libneuralnetworks_fuzzer_harness",
40    host_supported: true,
41    vendor_available: true,
42    owner: "google",
43    srcs: [
44        "Converter.cpp",
45        "FuzzHarness.cpp",
46        "StaticAssert.cpp",
47    ],
48    shared_libs: [
49        "libprotobuf-cpp-full",
50    ],
51    static_libs: [
52        "libneuralnetworks_common",
53        "libneuralnetworks_generated_test_harness",
54        "neuralnetworks_types",
55    ],
56    whole_static_libs: [
57        "libneuralnetworks_fuzzer_proto",
58        "libprotobuf-mutator",
59    ],
60    target: {
61        android: {
62            shared_libs: [
63                "libnativewindow",
64            ],
65        },
66    },
67}
68
69filegroup {
70    name: "libneuralnetworks_fuzzer_corpus",
71    srcs: ["corpus/*"],
72}
73
74cc_defaults {
75    name: "libneuralnetworks_fuzzer_defaults",
76    host_supported: true,
77    shared_libs: ["libprotobuf-cpp-full"],
78    static_libs: ["libneuralnetworks_fuzzer_harness"],
79    corpus: [":libneuralnetworks_fuzzer_corpus"],
80}
81
82// The following host binary is disabled because the genrule that uses this
83// binary (below) is disabled and because this binary is 300MB large currently.
84cc_binary_host {
85    name: "libneuralnetworks_fuzzer_generate_corpus",
86    enabled: false,
87    owner: "google",
88    srcs: [
89        "GenerateCorpus.cpp",
90        "StaticAssert.cpp",
91    ],
92    shared_libs: ["libprotobuf-cpp-full"],
93    static_libs: [
94        "libneuralnetworks_fuzzer_proto",
95        "libneuralnetworks_generated_test_harness",
96    ],
97    whole_static_libs: [
98        "neuralnetworks_generated_V1_0_example",
99        "neuralnetworks_generated_V1_1_example",
100        "neuralnetworks_generated_V1_2_example",
101        "neuralnetworks_generated_V1_3_example",
102    ],
103}
104
105// This genrule generates a zip file of 5000+ test cases from the NNAPI test
106// generator. It has been disabled for the time being because cc_fuzz is
107// currently not able to accept a zip file as a fuzzer seed corpus.
108// Alternatively, gensrcs could be used to generate each test case individually;
109// however, the corpus only seems to be able to accept ~500 files.
110genrule {
111    name: "libneuralnetworks_fuzzer_seed_corpus",
112    enabled: false,
113    tools: [
114        "libneuralnetworks_fuzzer_generate_corpus",
115        "soong_zip",
116    ],
117    out: ["libneuralnetworks_fuzzer_seed_corpus.zip"],
118    cmd: "mkdir $(genDir)/corpus && " +
119        "$(location libneuralnetworks_fuzzer_generate_corpus) $(genDir)/corpus && " +
120        "$(location soong_zip) -o $(out) -C $(genDir)/corpus -D $(genDir)/corpus",
121}
122