| 1 |
#![cfg(any(target_os = "linux", target_os = "android"))] |
| 2 |
|
| 3 |
use { |
| 4 |
common::*, |
| 5 |
minidump::Minidump, |
| 6 |
minidump_writer::{minidump_writer::MinidumpWriter, FailSpotName}, |
| 7 |
serde_json::json, |
| 8 |
}; |
| 9 |
|
| 10 |
mod common; |
| 11 |
|
| 12 |
#[test] |
| 13 |
fn soft_error_stream() { |
| 14 |
let mut child = start_child_and_wait_for_threads(1); |
| 15 |
let pid = child.id() as i32; |
| 16 |
|
| 17 |
let mut tmpfile = tempfile::Builder::new() |
| 18 |
.prefix("soft_error_stream") |
| 19 |
.tempfile() |
| 20 |
.unwrap(); |
| 21 |
|
| 22 |
let mut fail_client = FailSpotName::testing_client(); |
| 23 |
fail_client.set_enabled(FailSpotName::StopProcess, true); |
| 24 |
|
| 25 |
// Write a minidump |
| 26 |
MinidumpWriter::new(pid, pid) |
| 27 |
.dump(&mut tmpfile) |
| 28 |
.expect("cound not write minidump"); |
| 29 |
child.kill().expect("Failed to kill process"); |
| 30 |
child.wait().expect("Failed to wait on killed process"); |
| 31 |
|
| 32 |
// Ensure the minidump has a MozSoftErrors present |
| 33 |
let dump = Minidump::read_path(tmpfile.path()).expect("failed to read minidump"); |
| 34 |
read_minidump_soft_errors_or_panic(&dump); |
| 35 |
} |
| 36 |
|
| 37 |
#[test] |
| 38 |
fn soft_error_stream_content() { |
| 39 |
let expected_errors = vec![ |
| 40 |
json!({"InitErrors": [ |
| 41 |
{"StopProcessFailed": {"Stop": "EPERM"}}, |
| 42 |
{"FillMissingAuxvInfoErrors": ["InvalidFormat"]}, |
| 43 |
{"EnumerateThreadsErrors": [ |
| 44 |
{"ReadThreadNameFailed": "\ |
| 45 |
Custom {\n \ |
| 46 |
kind: Other,\n \ |
| 47 |
error: \"testing requested failure reading thread name\",\n\ |
| 48 |
}" |
| 49 |
} |
| 50 |
]} |
| 51 |
]}), |
| 52 |
json!({"SuspendThreadsErrors": [{"PtraceAttachError": [1234, "EPERM"]}]}), |
| 53 |
json!({"WriteSystemInfoErrors": [ |
| 54 |
{"WriteCpuInformationFailed": {"IOError": "\ |
| 55 |
Custom {\n \ |
| 56 |
kind: Other,\n \ |
| 57 |
error: \"test requested cpuinfo file failure\",\n\ |
| 58 |
}" |
| 59 |
}} |
| 60 |
]}), |
| 61 |
]; |
| 62 |
|
| 63 |
let mut child = start_child_and_wait_for_threads(1); |
| 64 |
let pid = child.id() as i32; |
| 65 |
|
| 66 |
let mut tmpfile = tempfile::Builder::new() |
| 67 |
.prefix("soft_error_stream_content") |
| 68 |
.tempfile() |
| 69 |
.unwrap(); |
| 70 |
|
| 71 |
let mut fail_client = FailSpotName::testing_client(); |
| 72 |
for name in [ |
| 73 |
FailSpotName::StopProcess, |
| 74 |
FailSpotName::FillMissingAuxvInfo, |
| 75 |
FailSpotName::ThreadName, |
| 76 |
FailSpotName::SuspendThreads, |
| 77 |
FailSpotName::CpuInfoFileOpen, |
| 78 |
] { |
| 79 |
fail_client.set_enabled(name, true); |
| 80 |
} |
| 81 |
|
| 82 |
// Write a minidump |
| 83 |
MinidumpWriter::new(pid, pid) |
| 84 |
.dump(&mut tmpfile) |
| 85 |
.expect("cound not write minidump"); |
| 86 |
child.kill().expect("Failed to kill process"); |
| 87 |
child.wait().expect("Failed to wait on killed process"); |
| 88 |
|
| 89 |
// Ensure the MozSoftErrors stream contains the expected errors |
| 90 |
let dump = Minidump::read_path(tmpfile.path()).expect("failed to read minidump"); |
| 91 |
assert_soft_errors_in_minidump(&dump, &expected_errors); |
| 92 |
} |