Skip to content

Commit 5d7c495

Browse files
committed
channels do ptr-int transmutes so move them to non-check-number-validity test
1 parent 552b77e commit 5d7c495

File tree

6 files changed

+63
-52
lines changed

6 files changed

+63
-52
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
// compile-flags: -Zmiri-disable-isolation
3+
4+
use std::sync::mpsc::{channel, sync_channel};
5+
use std::thread;
6+
7+
// Check if channels are working.
8+
9+
/// The test taken from the Rust documentation.
10+
fn simple_send() {
11+
let (tx, rx) = channel();
12+
thread::spawn(move || {
13+
tx.send(10).unwrap();
14+
});
15+
assert_eq!(rx.recv().unwrap(), 10);
16+
}
17+
18+
/// The test taken from the Rust documentation.
19+
fn multiple_send() {
20+
let (tx, rx) = channel();
21+
for i in 0..10 {
22+
let tx = tx.clone();
23+
thread::spawn(move || {
24+
tx.send(i).unwrap();
25+
});
26+
}
27+
28+
let mut sum = 0;
29+
for _ in 0..10 {
30+
let j = rx.recv().unwrap();
31+
assert!(0 <= j && j < 10);
32+
sum += j;
33+
}
34+
assert_eq!(sum, 45);
35+
}
36+
37+
/// The test taken from the Rust documentation.
38+
fn send_on_sync() {
39+
let (sender, receiver) = sync_channel(1);
40+
41+
// this returns immediately
42+
sender.send(1).unwrap();
43+
44+
thread::spawn(move || {
45+
// this will block until the previous message has been received
46+
sender.send(2).unwrap();
47+
});
48+
49+
assert_eq!(receiver.recv().unwrap(), 1);
50+
assert_eq!(receiver.recv().unwrap(), 2);
51+
}
52+
53+
fn main() {
54+
simple_send();
55+
multiple_send();
56+
send_on_sync();
57+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
warning: thread support is experimental and incomplete: weak memory effects are not emulated.
2+

tests/run-pass/concurrency/simple.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2+
// compile-flags: -Zmiri-check-number-validity
23

34
use std::thread;
45

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: thread support is experimental and incomplete: weak memory effects are not emulated.
22

3-
thread '<unnamed>' panicked at 'Hello!', $DIR/simple.rs:54:9
3+
thread '<unnamed>' panicked at 'Hello!', $DIR/simple.rs:55:9
44
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
5-
thread 'childthread' panicked at 'Hello, world!', $DIR/simple.rs:64:9
5+
thread 'childthread' panicked at 'Hello, world!', $DIR/simple.rs:65:9

tests/run-pass/concurrency/sync.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
// compile-flags: -Zmiri-disable-isolation -Zmiri-check-number-validity
33

4-
use std::sync::mpsc::{channel, sync_channel};
54
use std::sync::{Arc, Barrier, Condvar, Mutex, Once, RwLock};
65
use std::thread;
76
use std::time::{Duration, Instant};
@@ -181,52 +180,6 @@ fn check_rwlock_read_no_deadlock() {
181180
handle.join().unwrap();
182181
}
183182

184-
// Check if channels are working.
185-
186-
/// The test taken from the Rust documentation.
187-
fn simple_send() {
188-
let (tx, rx) = channel();
189-
thread::spawn(move || {
190-
tx.send(10).unwrap();
191-
});
192-
assert_eq!(rx.recv().unwrap(), 10);
193-
}
194-
195-
/// The test taken from the Rust documentation.
196-
fn multiple_send() {
197-
let (tx, rx) = channel();
198-
for i in 0..10 {
199-
let tx = tx.clone();
200-
thread::spawn(move || {
201-
tx.send(i).unwrap();
202-
});
203-
}
204-
205-
let mut sum = 0;
206-
for _ in 0..10 {
207-
let j = rx.recv().unwrap();
208-
assert!(0 <= j && j < 10);
209-
sum += j;
210-
}
211-
assert_eq!(sum, 45);
212-
}
213-
214-
/// The test taken from the Rust documentation.
215-
fn send_on_sync() {
216-
let (sender, receiver) = sync_channel(1);
217-
218-
// this returns immediately
219-
sender.send(1).unwrap();
220-
221-
thread::spawn(move || {
222-
// this will block until the previous message has been received
223-
sender.send(2).unwrap();
224-
});
225-
226-
assert_eq!(receiver.recv().unwrap(), 1);
227-
assert_eq!(receiver.recv().unwrap(), 2);
228-
}
229-
230183
// Check if Rust once statics are working.
231184

232185
static mut VAL: usize = 0;
@@ -353,9 +306,6 @@ fn main() {
353306
check_mutex();
354307
check_rwlock_write();
355308
check_rwlock_read_no_deadlock();
356-
simple_send();
357-
multiple_send();
358-
send_on_sync();
359309
check_once();
360310
check_rwlock_unlock_bug1();
361311
check_rwlock_unlock_bug2();

tests/run-pass/concurrency/thread_locals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2+
// compile-flags: -Zmiri-check-number-validity
23

34
//! The main purpose of this test is to check that if we take a pointer to
45
//! thread's `t1` thread-local `A` and send it to another thread `t2`,

0 commit comments

Comments
 (0)