Skip to content

Commit

Permalink
Make soft-error assertion less sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
marti4d committed Jan 8, 2025
1 parent 47f5d80 commit e661a78
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
19 changes: 19 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,22 @@ where

serde_json::from_str(contents).expect("expected json")
}

#[allow(unused)]
pub fn assert_soft_errors_in_minidump<'a, 'b, T, I>(
dump: &minidump::Minidump<'a, T>,
expected_errors: I,
) where
T: std::ops::Deref<Target = [u8]> + 'a,
I: IntoIterator<Item = &'b serde_json::Value>,
{
let actual_json = read_minidump_soft_errors_or_panic(dump);
let actual_errors = actual_json.as_array().unwrap();

// Ensure that every error we expect is in the actual list somewhere
for expected_error in expected_errors {
assert!(actual_errors
.iter()
.any(|actual_error| actual_error == expected_error));
}
}
56 changes: 29 additions & 27 deletions tests/linux_minidump_writer.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
#![cfg(any(target_os = "linux", target_os = "android"))]
#![allow(unused_imports, unused_variables)]

use minidump::*;
use minidump_common::format::{GUID, MINIDUMP_STREAM_TYPE::*};
use minidump_writer::{
app_memory::AppMemory,
crash_context::CrashContext,
errors::*,
maps_reader::{MappingEntry, MappingInfo, SystemMappingInfo},
minidump_writer::MinidumpWriter,
module_reader::{BuildId, ReadFromModule},
ptrace_dumper::PtraceDumper,
Pid,
};
use nix::{errno::Errno, sys::signal::Signal};
use procfs_core::process::MMPermissions;
use std::collections::HashSet;

use std::{
io::{BufRead, BufReader},
os::unix::process::ExitStatusExt,
process::{Command, Stdio},
use {
common::*,
minidump::*,
minidump_common::format::{GUID, MINIDUMP_STREAM_TYPE::*},
minidump_writer::{
app_memory::AppMemory,
crash_context::CrashContext,
errors::*,
maps_reader::{MappingEntry, MappingInfo, SystemMappingInfo},
minidump_writer::MinidumpWriter,
module_reader::{BuildId, ReadFromModule},
ptrace_dumper::PtraceDumper,
Pid,
},
nix::{errno::Errno, sys::signal::Signal},
procfs_core::process::MMPermissions,
serde_json::json,
std::{
collections::HashSet,
io::{BufRead, BufReader},
os::unix::process::ExitStatusExt,
process::{Command, Stdio},
},
};

mod common;
use common::*;

#[derive(Debug, PartialEq)]
enum Context {
Expand Down Expand Up @@ -299,6 +301,10 @@ contextual_test! {

contextual_test! {
fn skip_if_requested(context: Context) {
let expected_errors = vec![
json!("PrincipalMappingNotReferenced"),
];

let num_of_threads = 1;
let mut child = start_child_and_wait_for_threads(num_of_threads);
let pid = child.id() as i32;
Expand Down Expand Up @@ -331,13 +337,9 @@ contextual_test! {
assert_eq!(waitres.code(), None);
assert_eq!(status, Signal::SIGKILL as i32);

// Ensure the minidump has a MozSoftErrors present
// Ensure the MozSoftErrors stream contains the expected errors
let dump = Minidump::read_path(tmpfile.path()).expect("failed to read minidump");
let soft_error_json = read_minidump_soft_errors_or_panic(&dump);

assert_eq!(soft_error_json, serde_json::json! {
["PrincipalMappingNotReferenced"]
});
assert_soft_errors_in_minidump(&dump, &expected_errors);
}
}

Expand Down
34 changes: 9 additions & 25 deletions tests/linux_minidump_writer_soft_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn soft_error_stream() {

#[test]
fn soft_error_stream_content() {
let expected_json = json!([
{"InitErrors": [
let expected_errors = vec![
json!({"InitErrors": [
{"StopProcessFailed": {"Stop": "EPERM"}},
{"FillMissingAuxvInfoErrors": ["InvalidFormat"]},
{"EnumerateThreadsErrors": [
Expand All @@ -48,17 +48,17 @@ fn soft_error_stream_content() {
}"
}
]}
]},
{"SuspendThreadsErrors": [{"PtraceAttachError": [1234, "EPERM"]}]},
{"WriteSystemInfoErrors": [
]}),
json!({"SuspendThreadsErrors": [{"PtraceAttachError": [1234, "EPERM"]}]}),
json!({"WriteSystemInfoErrors": [
{"WriteCpuInformationFailed": {"IOError": "\
Custom {\n \
kind: Other,\n \
error: \"test requested cpuinfo file failure\",\n\
}"
}}
]}
]);
]}),
];

let mut child = start_child_and_wait_for_threads(1);
let pid = child.id() as i32;
Expand Down Expand Up @@ -86,23 +86,7 @@ fn soft_error_stream_content() {
child.kill().expect("Failed to kill process");
child.wait().expect("Failed to wait on killed process");

// Ensure the MozSoftErrors stream matches the expected JSON
// Ensure the MozSoftErrors stream contains the expected errors
let dump = Minidump::read_path(tmpfile.path()).expect("failed to read minidump");
let actual_json = read_minidump_soft_errors_or_panic(&dump);

if actual_json != expected_json {
panic!(
"\
JSON mismatch:\n\
=====Expected=====\n\
\n\
{expected_json:#}\n\
\n\
=====Actual=====\n\
\n\
{actual_json:#}\n\
\n\
"
);
}
assert_soft_errors_in_minidump(&dump, &expected_errors);
}

0 comments on commit e661a78

Please sign in to comment.