about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeff Martin <martinjeffrey@google.com>2025-03-19 12:55:02 -0400
committerJeff Martin <martinjeffrey@google.com>2025-03-19 12:55:02 -0400
commitef815f3205eedec26c715463f51a6793e2fa651f (patch)
treeeed4e26e88a6d1eb629b9e0c6305b6d328481ac2
parenta7fc463dd8fbeca800d4b3efc501069502cffe64 (diff)
downloadrust-ef815f3205eedec26c715463f51a6793e2fa651f.tar.gz
rust-ef815f3205eedec26c715463f51a6793e2fa651f.zip
Specify a concrete stack size in channel tests
The channel-stack-overflow-issue-102246 regression test fails on
platforms with a small default stack size (e.g. Fuchsia, with a default
of 256KiB). Update the test to specify an exact stack size for both the
sender and receiver operations, to ensure it is platform agnostic.

Set the stack size to less than the total allocation size of the mpsc
channel, to continue to prove that the allocation is on the heap.
-rw-r--r--tests/ui/std/channel-stack-overflow-issue-102246.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/tests/ui/std/channel-stack-overflow-issue-102246.rs b/tests/ui/std/channel-stack-overflow-issue-102246.rs
index 984ebdd553f..7bf6647bdc5 100644
--- a/tests/ui/std/channel-stack-overflow-issue-102246.rs
+++ b/tests/ui/std/channel-stack-overflow-issue-102246.rs
@@ -10,9 +10,16 @@
 // Ref: https://github.com/rust-lang/rust/issues/102246
 
 use std::sync::mpsc::channel;
-use std::thread;
+use std::thread::Builder;
 
 const N: usize = 32_768;
+const SLOTS: usize = 32;
+// Use a stack size that's smaller than N * SLOTS, proving the allocation is on the heap.
+//
+// The test explicitly specifies the stack size, because not all platforms have the same default
+// size.
+const STACK_SIZE: usize = (N*SLOTS) - 1;
+
 struct BigStruct {
     _data: [u8; N],
 }
@@ -20,10 +27,13 @@ struct BigStruct {
 fn main() {
     let (sender, receiver) = channel::<BigStruct>();
 
-    let thread1 = thread::spawn(move || {
+    let thread1 = Builder::new().stack_size(STACK_SIZE).spawn(move || {
         sender.send(BigStruct { _data: [0u8; N] }).unwrap();
-    });
-
+    }).expect("thread1 should spawn successfully");
     thread1.join().unwrap();
-    for _data in receiver.try_iter() {}
+
+    let thread2 = Builder::new().stack_size(STACK_SIZE).spawn(move || {
+        for _data in receiver.try_iter() {}
+    }).expect("thread2 should spawn successfully");
+    thread2.join().unwrap();
 }