blob: 2064f6cf024c9abdabf346bd22cee094650908bc [file] [log] [blame]
aizatskycb1a43932015-12-14 20:59:141# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
aizatsky7dfb57342015-12-21 04:02:525# Defines fuzzer_test.
6#
aizatsky43d459a52016-02-13 01:22:187import("//build/config/features.gni")
8import("//build/config/sanitizers/sanitizers.gni")
aizatskycb1a43932015-12-14 20:59:149import("//testing/test.gni")
10
aizatsky7dfb57342015-12-21 04:02:5211# visible for testing only.
12template("fuzzer_test_launcher") {
13 assert(defined(invoker.fuzzer_name), "need fuzzer_name in $target_name.")
14 assert(defined(invoker.dict), "need dict in $target_name.")
15
16 generated_script = "$root_build_dir/$target_name"
17
18 action(target_name) {
19 script = "//testing/libfuzzer/gen_fuzzer_runner.py"
20 args = [
21 "--fuzzer",
22 invoker.fuzzer_name,
23 "--launcher",
24 rebase_path(generated_script, root_build_dir),
25 "--dict",
ochangcfa30ab2016-01-22 01:43:0326 rebase_path("$root_build_dir/" + invoker.dict, root_build_dir),
aizatsky7dfb57342015-12-21 04:02:5227 ]
28 outputs = [
29 generated_script,
30 ]
31 }
32}
33
aizatskycb1a43932015-12-14 20:59:1434# fuzzer_test is used to define individual libfuzzer tests.
35#
36# Supported attributes:
37# - (required) sources - fuzzer test source files
38# - data - test data files.
39# - deps - test dependencies
40# - additional_configs - additional configs to be used for compilation
41# - dict - a dictionary file for the fuzzer.
42#
aizatsky43d459a52016-02-13 01:22:1843# If use_libfuzzer gn flag is defined, then proper fuzzer would be build.
44# Without use_libfuzzer a unit-test style binary would be built on linux
45# and the whole target is a no-op otherwise.
46#
aizatskycb1a43932015-12-14 20:59:1447# The template wraps test() target with appropriate dependencies.
48# If any test run-time options are present (dict), then a launcher
49# file would be generated with <fuzzer_name>.sh name in root output
50# dir (next to test).
51template("fuzzer_test") {
aizatsky43d459a52016-02-13 01:22:1852 if (!disable_libfuzzer && (use_libfuzzer || use_drfuzz || is_linux)) {
53 assert(defined(invoker.sources), "Need sources in $target_name.")
aizatskycb1a43932015-12-14 20:59:1454
aizatsky43d459a52016-02-13 01:22:1855 test_deps = [ "//testing/libfuzzer:libfuzzer_main" ]
aizatskycb1a43932015-12-14 20:59:1456
aizatsky43d459a52016-02-13 01:22:1857 if (defined(invoker.deps)) {
58 test_deps += invoker.deps
59 }
aizatskycb1a43932015-12-14 20:59:1460
aizatsky43d459a52016-02-13 01:22:1861 test_data = []
62 if (defined(invoker.data)) {
63 test_data += invoker.data
64 }
aizatskycb1a43932015-12-14 20:59:1465
aizatsky43d459a52016-02-13 01:22:1866 if (defined(invoker.dict)) {
67 fuzzer_name = target_name
68 launcher_name = target_name + ".sh"
aizatskycb1a43932015-12-14 20:59:1469
aizatsky43d459a52016-02-13 01:22:1870 # Copy dictionary to output
71 copy(target_name + "_dict_copy") {
72 sources = [
73 invoker.dict,
74 ]
75 outputs = [
76 "$root_build_dir/" + invoker.dict,
77 ]
78 }
79
80 fuzzer_test_launcher(launcher_name) {
81 dict = invoker.dict
82 }
83
84 test_deps += [
85 ":$launcher_name",
86 ":" + fuzzer_name + "_dict_copy",
87 ]
88 test_data += [
aizatskycb1a43932015-12-14 20:59:1489 invoker.dict,
aizatsky43d459a52016-02-13 01:22:1890 ":$launcher_name",
aizatskycb1a43932015-12-14 20:59:1491 ]
92 }
93
aizatsky43d459a52016-02-13 01:22:1894 test(target_name) {
95 forward_variables_from(invoker,
96 [
97 "sources",
98 "include_dirs",
99 ])
100 deps = test_deps
101 data = test_data
102
103 if (defined(invoker.additional_configs)) {
104 configs += invoker.additional_configs
105 }
aizatskycb1a43932015-12-14 20:59:14106 }
aizatsky43d459a52016-02-13 01:22:18107 } else {
108 # noop on unsupported platforms.
109 # mark attributes as used.
110 assert(invoker.sources == [] || invoker.sources != [])
aizatskycb1a43932015-12-14 20:59:14111 if (defined(invoker.additional_configs)) {
aizatsky43d459a52016-02-13 01:22:18112 assert(
113 invoker.additional_configs == [] || invoker.additional_configs != [])
114 }
115 if (defined(invoker.deps)) {
116 assert(invoker.deps == [] || invoker.deps != [])
117 }
118 if (defined(invoker.dict)) {
119 assert(invoker.dict == [] || invoker.dict != [])
120 }
121
122 group(target_name) {
aizatskycb1a43932015-12-14 20:59:14123 }
124 }
125}