mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
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 --HG-- rename : toolkit/crashreporter/test/unit/test_crash_moz_crash.js => toolkit/crashreporter/test/unit/test_crash_rust_panic.js extra : rebase_source : ba9f626ca2d2852f966e93401b8f8f7543615310 extra : source : 8c9117de1e7f40af42b7cbce25bc3780c032fe45
This commit is contained in:
parent
267eba61cb
commit
5f9adc61f1
11
toolkit/crashreporter/test/unit/test_crash_rust_panic.js
Normal file
11
toolkit/crashreporter/test/unit/test_crash_rust_panic.js
Normal file
@ -0,0 +1,11 @@
|
||||
function run_test() {
|
||||
// Try crashing with a Rust panic
|
||||
do_crash(function() {
|
||||
Components.classes["@mozilla.org/xpcom/debug;1"].getService(Components.interfaces.nsIDebug2).rustPanic("OH NO");
|
||||
},
|
||||
function(mdump, extra) {
|
||||
//TODO: check some extra things?
|
||||
},
|
||||
// process will exit with a zero exit status
|
||||
true);
|
||||
}
|
@ -7,6 +7,9 @@ support-files =
|
||||
|
||||
[test_crash_moz_crash.js]
|
||||
[test_crash_purevirtual.js]
|
||||
[test_crash_rust_panic.js]
|
||||
# Fails on Win64, bug 1302078.
|
||||
fail-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]
|
||||
|
@ -10,3 +10,12 @@ 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 "C" fn intentional_panic(message: *const c_char) {
|
||||
panic!("{}", unsafe { CStr::from_ptr(message) }.to_string_lossy());
|
||||
}
|
||||
|
@ -148,6 +148,16 @@ nsDebugImpl::Abort(const char* aFile, int32_t 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)
|
||||
{
|
||||
|
@ -79,4 +79,11 @@ interface nsIDebug2 : nsISupports
|
||||
*/
|
||||
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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user