Skip to content

Commit 3976008

Browse files
authored
Unrolled build for rust-lang#138720
Rollup merge of rust-lang#138720 - Jeff-A-Martin:channel-stack-overflow-test-fuchsia, r=wesleywiser 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.
2 parents 3f690c2 + ef815f3 commit 3976008

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tests/ui/std/channel-stack-overflow-issue-102246.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,30 @@
1010
// Ref: https://github.com/rust-lang/rust/issues/102246
1111

1212
use std::sync::mpsc::channel;
13-
use std::thread;
13+
use std::thread::Builder;
1414

1515
const N: usize = 32_768;
16+
const SLOTS: usize = 32;
17+
// Use a stack size that's smaller than N * SLOTS, proving the allocation is on the heap.
18+
//
19+
// The test explicitly specifies the stack size, because not all platforms have the same default
20+
// size.
21+
const STACK_SIZE: usize = (N*SLOTS) - 1;
22+
1623
struct BigStruct {
1724
_data: [u8; N],
1825
}
1926

2027
fn main() {
2128
let (sender, receiver) = channel::<BigStruct>();
2229

23-
let thread1 = thread::spawn(move || {
30+
let thread1 = Builder::new().stack_size(STACK_SIZE).spawn(move || {
2431
sender.send(BigStruct { _data: [0u8; N] }).unwrap();
25-
});
26-
32+
}).expect("thread1 should spawn successfully");
2733
thread1.join().unwrap();
28-
for _data in receiver.try_iter() {}
34+
35+
let thread2 = Builder::new().stack_size(STACK_SIZE).spawn(move || {
36+
for _data in receiver.try_iter() {}
37+
}).expect("thread2 should spawn successfully");
38+
thread2.join().unwrap();
2939
}

0 commit comments

Comments
 (0)