summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCorentin Wallez <cwallez@chromium.org>2018-08-02 18:48:03 +0200
committerDavid Neto <dneto@google.com>2018-08-03 10:06:11 -0400
commit2d9a325264e3fc81317acc0a68a098f0546c352d (patch)
treed6b1345fd2a41bf472b4690d67ab8bc5d737087d /test
parentc8e7bb1d1a77bc4f2ab170d86ee54a4049531549 (diff)
Refactor BUILD.gn so can easily be embedded in other projects
1. BUILD.gn: Don't use the extra Chromium clang warnings Also removes the unused .gn secondary_sources. 2. Move fuzzers in test/ instead of testing/ This frees up testing/ to be the git subtree of Chromium's src/testing/ that contains test.gni, gtest, gmock and libfuzzer 3. DEPS: get the whole testing/ subtree of Chromium 4. BUILD.gn: Simplify the standalone gtest targets These targets definitions are inspired from ANGLE's and add a variable that is the path of the googletest directory so that it can be made overridable in future commits. 6. BUILD.gn: Add overridable variables for deps dirs This avoids hardcoded paths to dependencies that make it hard to integrate SPIRV-Tools in other GN projects.
Diffstat (limited to 'test')
-rw-r--r--test/fuzzers/BUILD.gn121
-rw-r--r--test/fuzzers/corpora/spv/simple.spvbin0 -> 728 bytes
-rw-r--r--test/fuzzers/spvtools_opt_legalization_fuzzer.cpp37
-rw-r--r--test/fuzzers/spvtools_opt_performance_fuzzer.cpp37
-rw-r--r--test/fuzzers/spvtools_opt_size_fuzzer.cpp37
-rw-r--r--test/fuzzers/spvtools_val_fuzzer.cpp35
6 files changed, 267 insertions, 0 deletions
diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn
new file mode 100644
index 00000000..df8291a5
--- /dev/null
+++ b/test/fuzzers/BUILD.gn
@@ -0,0 +1,121 @@
+# Copyright 2018 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//testing/libfuzzer/fuzzer_test.gni")
+import("//testing/test.gni")
+
+config("fuzzer_config") {
+ configs = [ "../..:spvtools_config" ]
+}
+
+group("fuzzers") {
+ testonly = true
+ deps = []
+
+ if (!build_with_chromium || use_fuzzing_engine) {
+ deps += [ ":fuzzers_bin" ]
+ }
+}
+
+if (!build_with_chromium || use_fuzzing_engine) {
+ group("fuzzers_bin") {
+ testonly = true
+
+ deps = [
+ ":spvtools_val_fuzzer",
+ ":spvtools_opt_legalization_fuzzer",
+ ":spvtools_opt_performance_fuzzer",
+ ":spvtools_opt_size_fuzzer",
+ ]
+ }
+}
+
+template("spvtools_fuzzer") {
+ source_set(target_name) {
+ testonly = true
+ sources = invoker.sources
+ deps = [
+ "../..:spvtools",
+ "../..:spvtools_opt",
+ "../..:spvtools_val",
+ ]
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [
+ "//build/config/compiler:no_chromium_code",
+ ":fuzzer_config",
+ ]
+ }
+}
+
+spvtools_fuzzer("spvtools_opt_performance_fuzzer_src") {
+ sources = [
+ "spvtools_opt_performance_fuzzer.cpp",
+ ]
+}
+
+spvtools_fuzzer("spvtools_opt_legalization_fuzzer_src") {
+ sources = [
+ "spvtools_opt_legalization_fuzzer.cpp",
+ ]
+}
+
+spvtools_fuzzer("spvtools_opt_size_fuzzer_src") {
+ sources = [
+ "spvtools_opt_size_fuzzer.cpp",
+ ]
+}
+
+spvtools_fuzzer("spvtools_val_fuzzer_src") {
+ sources = [
+ "spvtools_val_fuzzer.cpp",
+ ]
+}
+
+if (!build_with_chromium || use_fuzzing_engine) {
+ fuzzer_test("spvtools_opt_performance_fuzzer") {
+ sources = []
+ deps = [
+ ":spvtools_opt_performance_fuzzer_src",
+ ]
+ seed_corpus = "corpora/spv"
+ }
+
+ fuzzer_test("spvtools_opt_legalization_fuzzer") {
+ sources = []
+ deps = [
+ ":spvtools_opt_legalization_fuzzer_src",
+ ]
+ seed_corpus = "corpora/spv"
+ }
+
+ fuzzer_test("spvtools_opt_size_fuzzer") {
+ sources = []
+ deps = [
+ ":spvtools_opt_size_fuzzer_src",
+ ]
+ seed_corpus = "corpora/spv"
+ }
+
+ fuzzer_test("spvtools_val_fuzzer") {
+ sources = []
+ deps = [
+ ":spvtools_val_fuzzer_src",
+ ]
+ seed_corpus = "corpora/spv"
+ }
+}
diff --git a/test/fuzzers/corpora/spv/simple.spv b/test/fuzzers/corpora/spv/simple.spv
new file mode 100644
index 00000000..f972a56f
--- /dev/null
+++ b/test/fuzzers/corpora/spv/simple.spv
Binary files differ
diff --git a/test/fuzzers/spvtools_opt_legalization_fuzzer.cpp b/test/fuzzers/spvtools_opt_legalization_fuzzer.cpp
new file mode 100644
index 00000000..f37dcc84
--- /dev/null
+++ b/test/fuzzers/spvtools_opt_legalization_fuzzer.cpp
@@ -0,0 +1,37 @@
+// Copyright (c) 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <cstdint>
+
+#include "spirv-tools/optimizer.hpp"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_3);
+ optimizer.SetMessageConsumer([](spv_message_level_t, const char*,
+ const spv_position_t&, const char*) {});
+
+ std::vector<uint32_t> input;
+ input.resize(size >> 2);
+
+ size_t count = 0;
+ for (size_t i = 0; (i + 3) < size; i += 4) {
+ input[count++] = data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) |
+ (data[i + 3]) << 24;
+ }
+
+ optimizer.RegisterLegalizationPasses();
+ optimizer.Run(input.data(), input.size(), &input);
+
+ return 0;
+}
diff --git a/test/fuzzers/spvtools_opt_performance_fuzzer.cpp b/test/fuzzers/spvtools_opt_performance_fuzzer.cpp
new file mode 100644
index 00000000..7f94febc
--- /dev/null
+++ b/test/fuzzers/spvtools_opt_performance_fuzzer.cpp
@@ -0,0 +1,37 @@
+// Copyright (c) 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <cstdint>
+
+#include "spirv-tools/optimizer.hpp"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_3);
+ optimizer.SetMessageConsumer([](spv_message_level_t, const char*,
+ const spv_position_t&, const char*) {});
+
+ std::vector<uint32_t> input;
+ input.resize(size >> 2);
+
+ size_t count = 0;
+ for (size_t i = 0; (i + 3) < size; i += 4) {
+ input[count++] = data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) |
+ (data[i + 3]) << 24;
+ }
+
+ optimizer.RegisterPerformancePasses();
+ optimizer.Run(input.data(), input.size(), &input);
+
+ return 0;
+}
diff --git a/test/fuzzers/spvtools_opt_size_fuzzer.cpp b/test/fuzzers/spvtools_opt_size_fuzzer.cpp
new file mode 100644
index 00000000..1f06a71f
--- /dev/null
+++ b/test/fuzzers/spvtools_opt_size_fuzzer.cpp
@@ -0,0 +1,37 @@
+// Copyright (c) 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <cstdint>
+
+#include "spirv-tools/optimizer.hpp"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_3);
+ optimizer.SetMessageConsumer([](spv_message_level_t, const char*,
+ const spv_position_t&, const char*) {});
+
+ std::vector<uint32_t> input;
+ input.resize(size >> 2);
+
+ size_t count = 0;
+ for (size_t i = 0; (i + 3) < size; i += 4) {
+ input[count++] = data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) |
+ (data[i + 3]) << 24;
+ }
+
+ optimizer.RegisterSizePasses();
+ optimizer.Run(input.data(), input.size(), &input);
+
+ return 0;
+}
diff --git a/test/fuzzers/spvtools_val_fuzzer.cpp b/test/fuzzers/spvtools_val_fuzzer.cpp
new file mode 100644
index 00000000..9b06a1f6
--- /dev/null
+++ b/test/fuzzers/spvtools_val_fuzzer.cpp
@@ -0,0 +1,35 @@
+// Copyright (c) 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <cstdint>
+
+#include "spirv-tools/libspirv.hpp"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ spvtools::SpirvTools tools(SPV_ENV_UNIVERSAL_1_3);
+ tools.SetMessageConsumer([](spv_message_level_t, const char*,
+ const spv_position_t&, const char*) {});
+
+ std::vector<uint32_t> input;
+ input.resize(size >> 2);
+
+ size_t count = 0;
+ for (size_t i = 0; (i + 3) < size; i += 4) {
+ input[count++] = data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) |
+ (data[i + 3]) << 24;
+ }
+
+ tools.Validate(input);
+ return 0;
+}