aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Green <aarongreen@google.com>2023-03-17 21:40:50 +0000
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-17 21:40:50 +0000
commitdb944d9c26b24e1fc73b555d1342a67d6b8191e3 (patch)
tree82dcd8c38d6970b8315f405a4f6f0ca86c863885
parentc911fa337f23d57d88a5dbfe5b801c68c9cd7733 (diff)
downloadpigweed-db944d9c26b24e1fc73b555d1342a67d6b8191e3.tar.gz
pw_fuzzer: Reenable fuzzer unit tests
This CL reenables the unit tests generated from fuzzers by non-fuzzing toolchains. It also adds a `enable_test_if` parameter to `pw_fuzzer` to allow setting the `enable_if` parameter on the generated test. This flag is used to disable the tests that have bit-rotted. They will be fixed in subsequent CLs. Change-Id: I66794d02a99a5f279358f2f3f334bb60bafd2824 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/131590 Reviewed-by: Alexei Frolov <frolv@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Aaron Green <aarongreen@google.com>
-rw-r--r--pw_bluetooth_hci/BUILD.gn1
-rw-r--r--pw_fuzzer/BUILD.gn1
-rw-r--r--pw_fuzzer/docs.rst10
-rw-r--r--pw_fuzzer/fuzzer.gni15
-rw-r--r--pw_protobuf/BUILD.gn2
-rw-r--r--pw_tokenizer/BUILD.gn1
6 files changed, 23 insertions, 7 deletions
diff --git a/pw_bluetooth_hci/BUILD.gn b/pw_bluetooth_hci/BUILD.gn
index 0f5107163..45cd1b78c 100644
--- a/pw_bluetooth_hci/BUILD.gn
+++ b/pw_bluetooth_hci/BUILD.gn
@@ -100,6 +100,7 @@ pw_fuzzer("uart_transport_fuzzer") {
dir_pw_status,
dir_pw_stream,
]
+ enable_test_if = false
}
pw_doc_group("docs") {
diff --git a/pw_fuzzer/BUILD.gn b/pw_fuzzer/BUILD.gn
index 0c47c0fe9..c53650ba6 100644
--- a/pw_fuzzer/BUILD.gn
+++ b/pw_fuzzer/BUILD.gn
@@ -92,6 +92,7 @@ pw_fuzzer("toy_fuzzer") {
dir_pw_span,
dir_pw_string,
]
+ enable_test_if = false
}
pw_test_group("tests") {
diff --git a/pw_fuzzer/docs.rst b/pw_fuzzer/docs.rst
index db456c021..02bf05f45 100644
--- a/pw_fuzzer/docs.rst
+++ b/pw_fuzzer/docs.rst
@@ -68,7 +68,9 @@ Building fuzzers with GN
To build a fuzzer, do the following:
-1. Add the GN target to the module using ``pw_fuzzer`` GN template.
+1. Add the GN target to the module using ``pw_fuzzer`` GN template. If you wish
+ to limit when the generated unit test is run, you can set `enable_test_if` in
+ the same manner as `enable_if` for `pw_test`:
.. code::
@@ -78,10 +80,12 @@ To build a fuzzer, do the following:
pw_fuzzer("my_fuzzer") {
sources = [ "my_fuzzer.cc" ]
deps = [ ":my_lib" ]
+ enable_test_if = device_has_1m_flash
}
-2. Add the generated unit test to the module's test group. This helps verify the
- fuzzer can build and run, even when not being built in a fuzzing toolchain.
+2. Add the generated unit test to the module's test group. This test verifies
+ the fuzzer can build and run, even when not being built in a fuzzing
+ toolchain.
.. code::
diff --git a/pw_fuzzer/fuzzer.gni b/pw_fuzzer/fuzzer.gni
index bf47e8695..a43a2d9cb 100644
--- a/pw_fuzzer/fuzzer.gni
+++ b/pw_fuzzer/fuzzer.gni
@@ -31,6 +31,10 @@ import("$dir_pw_unit_test/test.gni")
# for verifying the fuzz target function compiles, links, and runs even when not
# using a fuzzing-capable host or toolchain.
#
+# Args:
+# - enable_test_if: (optional) Passed as `enable_if` to the unit test.
+# Remaining arguments are the same as `pw_executable`.
+#
template("pw_fuzzer") {
if (!pw_toolchain_FUZZING_ENABLED) {
pw_error(target_name) {
@@ -46,7 +50,12 @@ template("pw_fuzzer") {
pw_executable(target_name) {
configs = []
deps = []
- forward_variables_from(invoker, "*", [ "visibility" ])
+ forward_variables_from(invoker,
+ "*",
+ [
+ "enable_test_if",
+ "visibility",
+ ])
forward_variables_from(invoker, [ "visibility" ])
configs += [ "$dir_pw_fuzzer:engine" ]
deps += [ dir_pw_fuzzer ]
@@ -54,12 +63,10 @@ template("pw_fuzzer") {
}
pw_test("${target_name}_test") {
- # TODO(b/234891784): Re-enable when there's better configurability for
- # on-device fuzz testing.
- enable_if = false
deps = []
forward_variables_from(invoker, "*", [ "visibility" ])
forward_variables_from(invoker, [ "visibility" ])
deps += [ "$dir_pw_fuzzer:run_as_unit_test" ]
+ enable_if = !defined(enable_test_if) || enable_test_if
}
}
diff --git a/pw_protobuf/BUILD.gn b/pw_protobuf/BUILD.gn
index 267b999eb..0e0dd3b50 100644
--- a/pw_protobuf/BUILD.gn
+++ b/pw_protobuf/BUILD.gn
@@ -265,6 +265,7 @@ pw_fuzzer("encoder_fuzzer") {
"fuzz.h",
]
deps = [ ":pw_protobuf" ]
+ enable_test_if = false
}
pw_fuzzer("decoder_fuzzer") {
@@ -273,4 +274,5 @@ pw_fuzzer("decoder_fuzzer") {
"fuzz.h",
]
deps = [ ":pw_protobuf" ]
+ enable_test_if = false
}
diff --git a/pw_tokenizer/BUILD.gn b/pw_tokenizer/BUILD.gn
index d114ed293..fc276f456 100644
--- a/pw_tokenizer/BUILD.gn
+++ b/pw_tokenizer/BUILD.gn
@@ -280,6 +280,7 @@ pw_fuzzer("token_database_fuzzer") {
"$dir_pw_preprocessor",
dir_pw_span,
]
+ enable_test_if = false
}
pw_fuzzer("detokenize_fuzzer") {