bug 1300152 - Add nsIDebug2::rustPanic to allow triggering Rust panic for testing. r?froydnj
For testing purposes it will be useful to be able to trigger crashes in Rust
code. Being able to trigger a panic seems like a good place to start. This
will make it easier to validate improvements in crash reporting.
MozReview-Commit-ID: Bh5rBieLLWW
copy from toolkit/crashreporter/test/unit/test_crash_moz_crash.js
copy to toolkit/crashreporter/test/unit/test_crash_rust_panic.js
--- a/toolkit/crashreporter/test/unit/test_crash_moz_crash.js
+++ b/toolkit/crashreporter/test/unit/test_crash_rust_panic.js
@@ -1,15 +1,11 @@
function run_test() {
- // Try crashing with a runtime abort
+ // Try crashing with a Rust panic
do_crash(function() {
- crashType = CrashTestUtils.CRASH_MOZ_CRASH;
- crashReporter.annotateCrashReport("TestKey", "TestValue");
+ Components.classes["@mozilla.org/xpcom/debug;1"].getService(Components.interfaces.nsIDebug2).rustPanic("OH NO");
},
function(mdump, extra) {
- do_check_eq(extra.TestKey, "TestValue");
- do_check_false("OOMAllocationSize" in extra);
- do_check_false("JSOutOfMemory" in extra);
- do_check_false("JSLargeAllocationFailure" in extra);
+ //TODO: check some extra things?
},
// process will exit with a zero exit status
true);
}
--- a/toolkit/crashreporter/test/unit/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit/xpcshell.ini
@@ -2,16 +2,19 @@
head = head_crashreporter.js
skip-if = toolkit == 'android'
support-files =
crasher_subprocess_head.js
crasher_subprocess_tail.js
[test_crash_moz_crash.js]
[test_crash_purevirtual.js]
+[test_crash_rust_panic.js]
+# Fails on Win64, bug 1302078.
+fails-if = os == 'win' && bits == 64
[test_crash_after_js_oom_reported.js]
[test_crash_after_js_oom_recovered.js]
[test_crash_after_js_oom_reported_2.js]
[test_crash_after_js_large_allocation_failure.js]
[test_crash_after_js_large_allocation_failure_reporting.js]
[test_crash_oom.js]
[test_oom_annotation_windows.js]
skip-if = os != 'win'
--- a/toolkit/library/rust/shared/lib.rs
+++ b/toolkit/library/rust/shared/lib.rs
@@ -5,8 +5,17 @@
#[cfg(feature="servo")]
extern crate geckoservo;
extern crate mp4parse_capi;
extern crate nsstring;
extern crate rust_url_capi;
#[cfg(feature = "quantum_render")]
extern crate webrender_bindings;
+
+use std::ffi::CStr;
+use std::os::raw::c_char;
+
+/// Used to implement `nsIDebug2::RustPanic` for testing purposes.
+#[no_mangle]
+pub extern fn intentional_panic(message: *const c_char) {
+ panic!("{}", unsafe { CStr::from_ptr(message) }.to_string_lossy());
+}
--- a/xpcom/base/nsDebugImpl.cpp
+++ b/xpcom/base/nsDebugImpl.cpp
@@ -143,16 +143,26 @@ nsDebugImpl::Break(const char* aFile, in
NS_IMETHODIMP
nsDebugImpl::Abort(const char* aFile, int32_t aLine)
{
NS_DebugBreak(NS_DEBUG_ABORT, nullptr, nullptr, aFile, aLine);
return NS_OK;
}
+// From toolkit/library/rust/lib.rs
+extern "C" void intentional_panic(const char* message);
+
+NS_IMETHODIMP
+nsDebugImpl::RustPanic(const char* aMessage)
+{
+ intentional_panic(aMessage);
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsDebugImpl::GetIsDebugBuild(bool* aResult)
{
#ifdef DEBUG
*aResult = true;
#else
*aResult = false;
#endif
--- a/xpcom/base/nsIDebug2.idl
+++ b/xpcom/base/nsIDebug2.idl
@@ -74,9 +74,16 @@ interface nsIDebug2 : nsISupports
/**
* Request the process to trigger a fatal abort.
*
* @param aFile file containing abort request
* @param aLine line number of abort request
*/
void abort(in string aFile,
in long aLine);
+
+ /**
+ * Request the process to trigger a fatal panic!() from Rust code.
+ *
+ * @param aMessage the string to pass to panic!().
+ */
+ void rustPanic(in string aMessage);
};