1# Copyright 2019 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
5import("//components/exo/wayland/fuzzer/wayland_templater.gni")
6import("//testing/libfuzzer/fuzzer_test.gni")
7import("//third_party/libprotobuf-mutator/fuzzable_proto_library.gni")
8import("//third_party/protobuf/proto_library.gni")
9
10# This is the canonical list of protocols which the generators should use
11# (though they don't have to)
12kDefaultWaylandProtocols = [
13  "//components/exo/wayland/protocol/aura-shell.xml",
14  "//third_party/wayland/src/protocol/wayland.xml",
15  "//third_party/wayland-protocols/src/stable/presentation-time/presentation-time.xml",
16  "//third_party/wayland-protocols/src/stable/viewporter/viewporter.xml",
17  "//third_party/wayland-protocols/src/unstable/fullscreen-shell/fullscreen-shell-unstable-v1.xml",
18  "//third_party/wayland-protocols/src/unstable/input-timestamps/input-timestamps-unstable-v1.xml",
19  "//third_party/wayland-protocols/src/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml",
20  "//third_party/wayland-protocols/src/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml",
21  "//third_party/wayland-protocols/src/unstable/pointer-gestures/pointer-gestures-unstable-v1.xml",
22  "//third_party/wayland-protocols/src/unstable/relative-pointer/relative-pointer-unstable-v1.xml",
23  "//third_party/wayland-protocols/src/unstable/text-input/text-input-unstable-v1.xml",
24  "//third_party/wayland-protocols/src/unstable/xdg-shell/xdg-shell-unstable-v6.xml",
25  "//third_party/wayland-protocols/unstable/alpha-compositing/alpha-compositing-unstable-v1.xml",
26  "//third_party/wayland-protocols/unstable/cursor-shapes/cursor-shapes-unstable-v1.xml",
27  "//third_party/wayland-protocols/unstable/gaming-input/gaming-input-unstable-v2.xml",
28  "//third_party/wayland-protocols/unstable/keyboard/keyboard-configuration-unstable-v1.xml",
29  "//third_party/wayland-protocols/unstable/keyboard/keyboard-extension-unstable-v1.xml",
30  "//third_party/wayland-protocols/unstable/notification-shell/notification-shell-unstable-v1.xml",
31  "//third_party/wayland-protocols/unstable/remote-shell/remote-shell-unstable-v1.xml",
32  "//third_party/wayland-protocols/unstable/secure-output/secure-output-unstable-v1.xml",
33  "//third_party/wayland-protocols/unstable/stylus/stylus-unstable-v2.xml",
34  "//third_party/wayland-protocols/unstable/stylus-tools/stylus-tools-unstable-v1.xml",
35  "//third_party/wayland-protocols/unstable/vsync-feedback/vsync-feedback-unstable-v1.xml",
36]
37
38wayland_templater("protocol_dump") {
39  sources = [ "misc/dump.tmpl" ]
40  protocols = kDefaultWaylandProtocols
41}
42
43wayland_templater("protocol_graph") {
44  sources = [ "misc/graph.dot.tmpl" ]
45  protocols = kDefaultWaylandProtocols
46}
47
48wayland_templater("protocol_docs") {
49  sources = [ "misc/docs.md.tmpl" ]
50  protocols = kDefaultWaylandProtocols
51}
52
53wayland_templater("actions_tmpl") {
54  sources = [ "actions.proto.tmpl" ]
55  protocols = kDefaultWaylandProtocols
56}
57
58wayland_templater("harness_h_tmpl") {
59  sources = [ "harness.h.tmpl" ]
60  protocols = kDefaultWaylandProtocols
61}
62
63wayland_templater("harness_cc_tmpl") {
64  sources = [ "harness.cc.tmpl" ]
65  protocols = kDefaultWaylandProtocols
66}
67
68# We make the seed corpus by enumerating call sequences to all requests
69# using the wayland_sequencer script.
70wayland_templater("corpus") {
71  sources = [ "corpus.tmpl" ]
72  protocols = kDefaultWaylandProtocols
73  script_override = "wayland_sequencer.py"
74}
75
76if (use_libfuzzer) {
77  fuzzer_test("wayland_fuzzer") {
78    sources = [ "fuzzer.cc" ]
79
80    deps = [
81      ":actions",
82      ":harness",
83      ":server_environment",
84      "//base",
85      "//third_party/libprotobuf-mutator",
86    ]
87
88    libfuzzer_options = [ "len_control=0" ]
89
90    corpus_target_outputs = get_target_outputs(":corpus")
91    seed_corpus = corpus_target_outputs[0]
92    seed_corpus_deps = [ ":corpus" ]
93  }
94}
95
96source_set("unit_tests") {
97  testonly = true
98
99  sources = [ "harness_unittest.cc" ]
100
101  deps = [
102    ":actions",
103    ":harness",
104    "//base",
105    "//components/exo",
106    "//components/exo:test_support",
107    "//components/exo/wayland",
108    "//skia",
109    "//third_party/wayland:wayland_util",
110  ]
111}
112
113source_set("server_environment") {
114  testonly = true
115
116  sources = [
117    "server_environment.cc",
118    "server_environment.h",
119  ]
120
121  deps = [
122    "//base",
123    "//base/test:test_support",
124    "//components/exo",
125    "//components/exo/wayland:wayland",
126    "//components/exo/wayland:wayland_client_test_helper",
127    "//mojo/core/embedder",
128    "//ui/aura",
129    "//ui/base",
130    "//ui/gl:test_support",
131  ]
132}
133
134source_set("harness") {
135  sources = get_target_outputs(":harness_h_tmpl") +
136            get_target_outputs(":harness_cc_tmpl")
137
138  deps = [
139    ":actions",
140    ":harness_cc_tmpl",
141    ":harness_h_tmpl",
142    "//base",
143    "//components/exo/wayland/protocol:aura_shell_protocol",
144    "//third_party/wayland:wayland_client",
145    "//third_party/wayland-protocols:alpha_compositing_protocol",
146    "//third_party/wayland-protocols:cursor_shapes_protocol",
147    "//third_party/wayland-protocols:fullscreen_shell_protocol",
148    "//third_party/wayland-protocols:gaming_input_protocol",
149    "//third_party/wayland-protocols:input_timestamps_protocol",
150    "//third_party/wayland-protocols:keyboard_configuration_protocol",
151    "//third_party/wayland-protocols:keyboard_extension_protocol",
152    "//third_party/wayland-protocols:linux_dmabuf_protocol",
153    "//third_party/wayland-protocols:linux_explicit_synchronization_protocol",
154    "//third_party/wayland-protocols:notification_shell_protocol",
155    "//third_party/wayland-protocols:pointer_gestures_protocol",
156    "//third_party/wayland-protocols:presentation_time_protocol",
157    "//third_party/wayland-protocols:relative_pointer_protocol",
158    "//third_party/wayland-protocols:remote_shell_protocol",
159    "//third_party/wayland-protocols:secure_output_protocol",
160    "//third_party/wayland-protocols:stylus_protocol",
161    "//third_party/wayland-protocols:stylus_tools_protocol",
162    "//third_party/wayland-protocols:text_input_protocol",
163    "//third_party/wayland-protocols:viewporter_protocol",
164    "//third_party/wayland-protocols:vsync_feedback_protocol",
165    "//third_party/wayland-protocols:xdg_shell_protocol",
166  ]
167}
168
169fuzzable_proto_library("actions") {
170  sources = get_target_outputs(":actions_tmpl")
171
172  # Since the .proto file is under gen/ we need to manually tell the
173  # output directory to rebase under the source root.
174  proto_out_dir = rebase_path(".", "//")
175
176  deps = [ ":actions_tmpl" ]
177}
178