summaryrefslogtreecommitdiffstats
path: root/third_party/rust/crash-context/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/crash-context/tests
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/crash-context/tests')
-rw-r--r--third_party/rust/crash-context/tests/capture_context.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/third_party/rust/crash-context/tests/capture_context.rs b/third_party/rust/crash-context/tests/capture_context.rs
new file mode 100644
index 0000000000..641e1dd706
--- /dev/null
+++ b/third_party/rust/crash-context/tests/capture_context.rs
@@ -0,0 +1,49 @@
+#[test]
+fn captures() {
+ fn one() {
+ two();
+ }
+
+ fn two() {
+ three();
+ }
+
+ #[allow(unsafe_code)]
+ fn three() {
+ cfg_if::cfg_if! {
+ if #[cfg(target_os = "windows")] {
+ let ctx = unsafe {
+ let mut ctx = std::mem::MaybeUninit::zeroed();
+ crash_context::capture_context(ctx.as_mut_ptr());
+
+ ctx.assume_init()
+ };
+
+ cfg_if::cfg_if! {
+ if #[cfg(target_arch = "x86_64")] {
+ assert!(ctx.Rbp != 0);
+ assert!(ctx.Rsp != 0);
+ assert!(ctx.Rip != 0);
+ } else if #[cfg(target_arch = "x86")] {
+ assert!(ctx.Ebp != 0);
+ assert!(ctx.Esp != 0);
+ assert!(ctx.Eip != 0);
+ }
+ }
+ } else if #[cfg(all(target_os = "linux", target_arch = "x86_64"))] {
+ let ctx = unsafe {
+ let mut ctx = std::mem::MaybeUninit::zeroed();
+ assert_eq!(crash_context::crash_context_getcontext(ctx.as_mut_ptr()), 0);
+ ctx.assume_init()
+ };
+
+ let gregs = &ctx.uc_mcontext.gregs;
+ assert!(gregs[libc::REG_RBP as usize] != 0);
+ assert!(gregs[libc::REG_RSP as usize] != 0);
+ assert!(gregs[libc::REG_RIP as usize] != 0);
+ }
+ }
+ }
+
+ one();
+}