Skip to content

Commit

Permalink
[rust][test] Updating panic message handlers
Browse files Browse the repository at this point in the history
The latest rust nightly changed the formatting of panic messages in
rust-lang/rust#112849 so that the message now
comes after the source info. This CL updates all checks against the
panic message to properly match the new format.

Bug: 130265
Test: fx test component_manager_logger_test rust-runner-integration-test
host_x64/obj/tools/testing/testparser/test.sh host_x64/symbolizer_tests

Change-Id: Idcb28b8c9a3269f0e1534b703d9231e8d452d801
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/900340
Reviewed-by: Dangyi Liu <dangyi@google.com>
Reviewed-by: Adam Perry <adamperry@google.com>
Reviewed-by: Ankur Mittal <anmittal@google.com>
Reviewed-by: Tyler Mandry <tmandry@google.com>
Commit-Queue: Tyler Mandry <tmandry@google.com>
Reviewed-by: Mike McCreavy <mccreavy@google.com>
  • Loading branch information
Nashenas88 authored and Rebase bot committed Aug 14, 2023
1 parent 712de79 commit c72e563
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/recovery/diagnostics/gumshoe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ can force this test to fail by altering it:
and running the "fx test" command above, and then inspecting
~/output.txt for the error:

thread 'main' panicked at
'MockHandlebarsTrait::trait_register_template_file:
Expectation(<anything>) called more than 3 times'
thread 'main' panicked at ...:
MockHandlebarsTrait::trait_register_template_file:
Expectation(<anything>) called more than 3 times

How To Run Interactively (Harder)

Expand Down
6 changes: 2 additions & 4 deletions src/sys/component_manager/lib/logger/src/klog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,8 @@ mod tests {
// This will panic again if the message is not found,
// and the message will not include "panic_test".
old_hook(info);
expect_message_in_debuglog(format!(
"[component_manager] PANIC: panicked at 'panic_test {}'",
logged_value
));
expect_message_in_debuglog(format!("[component_manager] PANIC: panicked at"));
expect_message_in_debuglog(format!("panic_test {logged_value}"));
}));

init();
Expand Down
34 changes: 24 additions & 10 deletions src/sys/test_runners/rust/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,30 @@ async fn launch_and_run_sample_test_internal(parallel: u16) {

assert_eq!(expected_events, events_without_failing_test_logs);

let panic_message = r"thread 'main' panicked at 'I'm supposed panic!()', ../../src/sys/test_runners/rust/test_data/sample-rust-tests/src/lib.rs:20:9";
assert!(failing_test_logs.len() > 3, "{:?}", failing_test_logs);
assert_eq!(
&failing_test_logs[0..3],
&[
RunEvent::case_stderr("my_tests::failing_test", panic_message),
RunEvent::case_stderr("my_tests::failing_test", "stack backtrace:"),
RunEvent::case_stderr("my_tests::failing_test", "{{{reset}}}"),
]
);
let reset = "{{{reset}}}";
let (reset_index, _) = failing_test_logs
.iter()
.enumerate()
.find(|(_, event)| {
let RunEvent::CaseStderr { name: _, stderr_message: line } = event else {
return false;
};
line == reset
})
.expect("should have reset log");
assert!(failing_test_logs.len() > reset_index, "{:?}", failing_test_logs);
let assert_contains = |msg| {
failing_test_logs[0..reset_index].iter().any(|event| {
let RunEvent::CaseStderr { name: _, stderr_message: line } = event else {
return false;
};
line.contains(msg)
})
};
assert_contains("thread 'main' panicked at");
assert_contains("I'm supposed panic!()");
assert_contains("../../src/sys/test_runners/rust/test_data/sample-rust-tests/src/lib.rs:20:9");
assert_contains("stack backtrace:");
assert_eq!(
failing_test_logs.last().unwrap(),
&RunEvent::case_stderr("my_tests::failing_test", "test failed.")
Expand Down
3 changes: 2 additions & 1 deletion tools/symbolizer/test_cases/rust_crasher_stdout.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is the stdout of `fx shell run fuchsia-pkg://fuchsia.com/crasher#meta/rust_crasher.cmx`
thread 'main' panicked at 'I HAVE PANICKED', ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
thread 'main' panicked at ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
I HAVE PANICKED
stack backtrace:
{{{reset}}}
{{{module:0x0::elf:e1c9115da8f4a732}}}
Expand Down
3 changes: 2 additions & 1 deletion tools/symbolizer/test_cases/rust_crasher_stdout.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is the stdout of `fx shell run fuchsia-pkg://fuchsia.com/crasher#meta/rust_crasher.cmx`
thread 'main' panicked at 'I HAVE PANICKED', ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
thread 'main' panicked at ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
I HAVE PANICKED
stack backtrace:
[[[ELF module #0x0 "" BuildID=e1c9115da8f4a732 0x75701d1000]]]
[[[ELF module #0x1 "libfdio.so" BuildID=f60992baff92044c 0x260ea9cc000]]]
Expand Down
16 changes: 10 additions & 6 deletions tools/testing/testparser/testparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,13 @@ booooo I printed an error, but it doesn't count as fail reason
[stdout - legacy_test]
---- tests::test_add stderr ----
[stdout - legacy_test]
thread 'main' panicked at 'assertion failed: ` + "`(left != right)`" + `
thread 'main' panicked at ../../src/lib/zircon/rust/src/channel.rs:761:9:
[stdout - legacy_test]
assertion failed: ` + "`(left != right)`" + `
[stdout - legacy_test]
left: ` + "`ObjectType(PORT)`" + `,
[stdout - legacy_test]
right: ` + "`ObjectType(PORT)`', ../../src/lib/zircon/rust/src/channel.rs:761:9`" + `
right: ` + "`ObjectType(PORT)`" + `
[stdout - legacy_test]
stack backtrace:
[stdout - legacy_test]
Expand All @@ -556,11 +558,13 @@ stack backtrace:
[stdout - legacy_test]
---- tests::test_substract stderr ----
[stdout - legacy_test]
thread 'main' panicked at 'assertion failed: ` + "`(left != right)`" + `
thread 'main' panicked at ../../src/lib/zircon/rust/src/channel.rs:783:9:
[stdout - legacy_test]
assertion failed: ` + "`(left != right)`" + `
[stdout - legacy_test]
left: ` + "`Err((5, 0))`" + `,
[stdout - legacy_test]
right: ` + "`Err((5, 0))`" + `', ../../src/lib/zircon/rust/src/channel.rs:783:9
right: ` + "`Err((5, 0))`" + `
[stdout - legacy_test]
stack backtrace:
[stdout - legacy_test]
Expand Down Expand Up @@ -606,14 +610,14 @@ One or more test runs failed.`
CaseName: "test_add",
Status: runtests.TestFailure,
Format: "Rust",
FailReason: "thread 'main' panicked at 'assertion failed: `(left != right)`\n left: `ObjectType(PORT)`,\n right: `ObjectType(PORT)`', ../../src/lib/zircon/rust/src/channel.rs:761:9`",
FailReason: "thread 'main' panicked at ../../src/lib/zircon/rust/src/channel.rs:761:9:\nassertion failed: `(left != right)`\n left: `ObjectType(PORT)`,\n right: `ObjectType(PORT)`",
}, {
DisplayName: "tests::test_substract",
SuiteName: "tests",
CaseName: "test_substract",
Status: runtests.TestFailure,
Format: "Rust",
FailReason: "thread 'main' panicked at 'assertion failed: `(left != right)`\n left: `Err((5, 0))`,\n right: `Err((5, 0))`', ../../src/lib/zircon/rust/src/channel.rs:783:9",
FailReason: "thread 'main' panicked at ../../src/lib/zircon/rust/src/channel.rs:783:9:\nassertion failed: `(left != right)`\n left: `Err((5, 0))`,\n right: `Err((5, 0))`",
},
}
testCaseCmp(t, stdout, want)
Expand Down

0 comments on commit c72e563

Please sign in to comment.