Skip to content

Commit c72e563

Browse files
Nashenas88Rebase bot
authored and
Rebase bot
committed
[rust][test] Updating panic message handlers
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 <[email protected]> Reviewed-by: Adam Perry <[email protected]> Reviewed-by: Ankur Mittal <[email protected]> Reviewed-by: Tyler Mandry <[email protected]> Commit-Queue: Tyler Mandry <[email protected]> Reviewed-by: Mike McCreavy <[email protected]>
1 parent 712de79 commit c72e563

File tree

6 files changed

+43
-25
lines changed

6 files changed

+43
-25
lines changed

src/recovery/diagnostics/gumshoe/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ can force this test to fail by altering it:
4545
and running the "fx test" command above, and then inspecting
4646
~/output.txt for the error:
4747

48-
thread 'main' panicked at
49-
'MockHandlebarsTrait::trait_register_template_file:
50-
Expectation(<anything>) called more than 3 times'
48+
thread 'main' panicked at ...:
49+
MockHandlebarsTrait::trait_register_template_file:
50+
Expectation(<anything>) called more than 3 times
5151

5252
How To Run Interactively (Harder)
5353

src/sys/component_manager/lib/logger/src/klog.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ mod tests {
224224
// This will panic again if the message is not found,
225225
// and the message will not include "panic_test".
226226
old_hook(info);
227-
expect_message_in_debuglog(format!(
228-
"[component_manager] PANIC: panicked at 'panic_test {}'",
229-
logged_value
230-
));
227+
expect_message_in_debuglog(format!("[component_manager] PANIC: panicked at"));
228+
expect_message_in_debuglog(format!("panic_test {logged_value}"));
231229
}));
232230

233231
init();

src/sys/test_runners/rust/tests/main.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,30 @@ async fn launch_and_run_sample_test_internal(parallel: u16) {
9999

100100
assert_eq!(expected_events, events_without_failing_test_logs);
101101

102-
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";
103-
assert!(failing_test_logs.len() > 3, "{:?}", failing_test_logs);
104-
assert_eq!(
105-
&failing_test_logs[0..3],
106-
&[
107-
RunEvent::case_stderr("my_tests::failing_test", panic_message),
108-
RunEvent::case_stderr("my_tests::failing_test", "stack backtrace:"),
109-
RunEvent::case_stderr("my_tests::failing_test", "{{{reset}}}"),
110-
]
111-
);
102+
let reset = "{{{reset}}}";
103+
let (reset_index, _) = failing_test_logs
104+
.iter()
105+
.enumerate()
106+
.find(|(_, event)| {
107+
let RunEvent::CaseStderr { name: _, stderr_message: line } = event else {
108+
return false;
109+
};
110+
line == reset
111+
})
112+
.expect("should have reset log");
113+
assert!(failing_test_logs.len() > reset_index, "{:?}", failing_test_logs);
114+
let assert_contains = |msg| {
115+
failing_test_logs[0..reset_index].iter().any(|event| {
116+
let RunEvent::CaseStderr { name: _, stderr_message: line } = event else {
117+
return false;
118+
};
119+
line.contains(msg)
120+
})
121+
};
122+
assert_contains("thread 'main' panicked at");
123+
assert_contains("I'm supposed panic!()");
124+
assert_contains("../../src/sys/test_runners/rust/test_data/sample-rust-tests/src/lib.rs:20:9");
125+
assert_contains("stack backtrace:");
112126
assert_eq!(
113127
failing_test_logs.last().unwrap(),
114128
&RunEvent::case_stderr("my_tests::failing_test", "test failed.")

tools/symbolizer/test_cases/rust_crasher_stdout.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This is the stdout of `fx shell run fuchsia-pkg://fuchsia.com/crasher#meta/rust_crasher.cmx`
2-
thread 'main' panicked at 'I HAVE PANICKED', ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
2+
thread 'main' panicked at ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
3+
I HAVE PANICKED
34
stack backtrace:
45
{{{reset}}}
56
{{{module:0x0::elf:e1c9115da8f4a732}}}

tools/symbolizer/test_cases/rust_crasher_stdout.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This is the stdout of `fx shell run fuchsia-pkg://fuchsia.com/crasher#meta/rust_crasher.cmx`
2-
thread 'main' panicked at 'I HAVE PANICKED', ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
2+
thread 'main' panicked at ../../src/developer/forensics/crasher/rust/src/main.rs:6:5
3+
I HAVE PANICKED
34
stack backtrace:
45
[[[ELF module #0x0 "" BuildID=e1c9115da8f4a732 0x75701d1000]]]
56
[[[ELF module #0x1 "libfdio.so" BuildID=f60992baff92044c 0x260ea9cc000]]]

tools/testing/testparser/testparser_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,13 @@ booooo I printed an error, but it doesn't count as fail reason
537537
[stdout - legacy_test]
538538
---- tests::test_add stderr ----
539539
[stdout - legacy_test]
540-
thread 'main' panicked at 'assertion failed: ` + "`(left != right)`" + `
540+
thread 'main' panicked at ../../src/lib/zircon/rust/src/channel.rs:761:9:
541+
[stdout - legacy_test]
542+
assertion failed: ` + "`(left != right)`" + `
541543
[stdout - legacy_test]
542544
left: ` + "`ObjectType(PORT)`" + `,
543545
[stdout - legacy_test]
544-
right: ` + "`ObjectType(PORT)`', ../../src/lib/zircon/rust/src/channel.rs:761:9`" + `
546+
right: ` + "`ObjectType(PORT)`" + `
545547
[stdout - legacy_test]
546548
stack backtrace:
547549
[stdout - legacy_test]
@@ -556,11 +558,13 @@ stack backtrace:
556558
[stdout - legacy_test]
557559
---- tests::test_substract stderr ----
558560
[stdout - legacy_test]
559-
thread 'main' panicked at 'assertion failed: ` + "`(left != right)`" + `
561+
thread 'main' panicked at ../../src/lib/zircon/rust/src/channel.rs:783:9:
562+
[stdout - legacy_test]
563+
assertion failed: ` + "`(left != right)`" + `
560564
[stdout - legacy_test]
561565
left: ` + "`Err((5, 0))`" + `,
562566
[stdout - legacy_test]
563-
right: ` + "`Err((5, 0))`" + `', ../../src/lib/zircon/rust/src/channel.rs:783:9
567+
right: ` + "`Err((5, 0))`" + `
564568
[stdout - legacy_test]
565569
stack backtrace:
566570
[stdout - legacy_test]
@@ -606,14 +610,14 @@ One or more test runs failed.`
606610
CaseName: "test_add",
607611
Status: runtests.TestFailure,
608612
Format: "Rust",
609-
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`",
613+
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)`",
610614
}, {
611615
DisplayName: "tests::test_substract",
612616
SuiteName: "tests",
613617
CaseName: "test_substract",
614618
Status: runtests.TestFailure,
615619
Format: "Rust",
616-
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",
620+
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))`",
617621
},
618622
}
619623
testCaseCmp(t, stdout, want)

0 commit comments

Comments
 (0)