fuzzing: When fuzzing, always ASSERT, and abort() instead of SIGTRAP
Currently, when we hit an assertion failure, the fuzzer stops
immediately without producing a crash. This patch makes it so that we do
a hard abort instead which will be caught.
Bug: dawn:295, dawn:293
Fixes: dawn:293
Change-Id: Ie00074e84b51c9aa364aba96c11a35659bbba740
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14682
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/common/Assert.cpp b/src/common/Assert.cpp
index c4d7528..8802c20 100644
--- a/src/common/Assert.cpp
+++ b/src/common/Assert.cpp
@@ -15,11 +15,17 @@
#include "common/Assert.h"
#include "common/Log.h"
+#include <cstdlib>
+
void HandleAssertionFailure(const char* file,
const char* function,
int line,
const char* condition) {
dawn::ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function
<< "): " << condition;
+#if defined(DAWN_ABORT_ON_ASSERT)
+ abort();
+#else
DAWN_BREAKPOINT();
+#endif
}
diff --git a/src/common/BUILD.gn b/src/common/BUILD.gn
index 80ee2c2..a005613 100644
--- a/src/common/BUILD.gn
+++ b/src/common/BUILD.gn
@@ -25,6 +25,12 @@
dcheck_always_on = false
}
+if (build_with_chromium) {
+ import("//build/config/sanitizers/sanitizers.gni")
+} else {
+ use_fuzzing_engine = false
+}
+
###############################################################################
# Common dawn configs
###############################################################################
@@ -43,10 +49,16 @@
]
defines = []
- if (dawn_always_assert || dcheck_always_on || is_debug) {
+ if (dawn_always_assert || dcheck_always_on || is_debug ||
+ use_fuzzing_engine) {
defines += [ "DAWN_ENABLE_ASSERTS" ]
}
+ if (use_fuzzing_engine) {
+ # Does a hard abort when an assertion fails so that fuzzers catch and parse the failure.
+ defines += [ "DAWN_ABORT_ON_ASSERT" ]
+ }
+
if (dawn_enable_d3d12) {
defines += [ "DAWN_ENABLE_BACKEND_D3D12" ]
}