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    // A large-scale-change added 'default_applicable_licenses' to import
20    // all of the 'license_kinds' from "packages_modules_NeuralNetworks_runtime_license"
21    // to get the below license kinds:
22    //   SPDX-license-identifier-Apache-2.0
23    default_applicable_licenses: [
24        "packages_modules_NeuralNetworks_runtime_license",
25    ],
26}
27
28cc_library_static {
29    name: "libneuralnetworks_fuzzer_proto",
30    owner: "google",
31    srcs: ["Model.proto"],
32    proto: {
33        type: "full",
34        export_proto_headers: true,
35    },
36    shared_libs: ["libprotobuf-cpp-full"],
37}
38
39cc_library_static {
40    name: "libneuralnetworks_fuzzer_harness",
41    owner: "google",
42    srcs: [
43        "Converter.cpp",
44        "FuzzHarness.cpp",
45        "StaticAssert.cpp",
46    ],
47    shared_libs: [
48        "android.hidl.memory@1.0",
49        "libhidlmemory",
50        "libnativewindow",
51        "libprotobuf-cpp-full",
52    ],
53    static_libs: [
54        "libneuralnetworks_common",
55        "libneuralnetworks_generated_test_harness",
56        "libneuralnetworks_static",
57    ],
58    whole_static_libs: [
59        "libneuralnetworks_fuzzer_proto",
60        "libprotobuf-mutator",
61        "neuralnetworks_types",
62    ],
63}
64
65filegroup {
66    name: "libneuralnetworks_fuzzer_corpus",
67    srcs: ["corpus/*"],
68}
69
70cc_defaults {
71    name: "libneuralnetworks_fuzzer_defaults",
72    shared_libs: ["libprotobuf-cpp-full"],
73    static_libs: ["libneuralnetworks_fuzzer_harness"],
74    corpus: [":libneuralnetworks_fuzzer_corpus"],
75}
76
77// The following host binary is disabled because the genrule that uses this
78// binary (below) is disabled and because this binary is 300MB large currently.
79cc_binary_host {
80    name: "libneuralnetworks_fuzzer_generate_corpus",
81    enabled: false,
82    owner: "google",
83    srcs: [
84        "GenerateCorpus.cpp",
85        "StaticAssert.cpp",
86    ],
87    shared_libs: ["libprotobuf-cpp-full"],
88    static_libs: [
89        "libneuralnetworks_fuzzer_proto",
90        "libneuralnetworks_generated_test_harness",
91    ],
92    whole_static_libs: [
93        "neuralnetworks_generated_V1_0_example",
94        "neuralnetworks_generated_V1_1_example",
95        "neuralnetworks_generated_V1_2_example",
96        "neuralnetworks_generated_V1_3_example",
97    ],
98}
99
100// This genrule generates a zip file of 5000+ test cases from the NNAPI test
101// generator. It has been disabled for the time being because cc_fuzz is
102// currently not able to accept a zip file as a fuzzer seed corpus.
103// Alternatively, gensrcs could be used to generate each test case individually;
104// however, the corpus only seems to be able to accept ~500 files.
105genrule {
106    name: "libneuralnetworks_fuzzer_seed_corpus",
107    enabled: false,
108    tools: [
109        "libneuralnetworks_fuzzer_generate_corpus",
110        "soong_zip",
111    ],
112    out: ["libneuralnetworks_fuzzer_seed_corpus.zip"],
113    cmd: "mkdir $(genDir)/corpus && " +
114        "$(location libneuralnetworks_fuzzer_generate_corpus) $(genDir)/corpus && " +
115        "$(location soong_zip) -o $(out) -C $(genDir)/corpus -D $(genDir)/corpus",
116}
117