Skip to content

Commit 79115f5

Browse files
committed
Auto merge of rust-lang#3848 - tiif:tokiotest, r=RalfJung
Add tokio io test After rust-lang#3804 landed, these tests passed.
2 parents 3a655aa + abcfc17 commit 79115f5

File tree

7 files changed

+72
-9
lines changed

7 files changed

+72
-9
lines changed

src/tools/miri/test_dependencies/Cargo.lock

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ version = "3.16.0"
4444
source = "registry+https://github.com/rust-lang/crates.io-index"
4545
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
4646

47+
[[package]]
48+
name = "bytes"
49+
version = "1.7.1"
50+
source = "registry+https://github.com/rust-lang/crates.io-index"
51+
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
52+
4753
[[package]]
4854
name = "cc"
4955
version = "1.1.7"
@@ -304,6 +310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
304310
checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1"
305311
dependencies = [
306312
"backtrace",
313+
"bytes",
307314
"libc",
308315
"mio",
309316
"pin-project-lite",

src/tools/miri/test_dependencies/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tempfile = "3"
2020
page_size = "0.6"
2121
# Avoid pulling in all of tokio's dependencies.
2222
# However, without `net` and `signal`, tokio uses fewer relevant system APIs.
23-
tokio = { version = "1.24", features = ["macros", "rt-multi-thread", "time", "net", "fs", "sync", "signal"] }
23+
tokio = { version = "1.24", features = ["macros", "rt-multi-thread", "time", "net", "fs", "sync", "signal", "io-util"] }
2424

2525
[target.'cfg(windows)'.dependencies]
2626
windows-sys = { version = "0.52", features = [ "Win32_Foundation", "Win32_System_Threading" ] }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//@compile-flags: -Zmiri-disable-isolation
2+
//@only-target-linux: We only support tokio on Linux
3+
4+
use std::fs::remove_file;
5+
use tokio::fs::{File, OpenOptions};
6+
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
7+
8+
#[path = "../../utils/mod.rs"]
9+
mod utils;
10+
11+
#[tokio::main]
12+
async fn main() {
13+
test_create_and_write().await.unwrap();
14+
test_create_and_read().await.unwrap();
15+
}
16+
17+
async fn test_create_and_write() -> io::Result<()> {
18+
let path = utils::prepare("foo.txt");
19+
let mut file = File::create(&path).await?;
20+
21+
// Write 10 bytes to the file.
22+
file.write(b"some bytes").await?;
23+
assert_eq!(file.metadata().await.unwrap().len(), 10);
24+
25+
remove_file(&path).unwrap();
26+
Ok(())
27+
}
28+
29+
async fn test_create_and_read() -> io::Result<()> {
30+
let bytes = b"more bytes";
31+
let path = utils::prepare_with_content("foo.txt", bytes);
32+
let mut file = OpenOptions::new().read(true).open(&path).await.unwrap();
33+
let mut buffer = [0u8; 10];
34+
35+
// Read the whole file.
36+
file.read(&mut buffer[..]).await?;
37+
assert_eq!(&buffer, b"more bytes");
38+
39+
remove_file(&path).unwrap();
40+
Ok(())
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@only-target-linux: We only support tokio on Linux
2+
use tokio::sync::mpsc;
3+
4+
#[tokio::main]
5+
async fn main() {
6+
let (tx, mut rx) = mpsc::channel(32);
7+
let tx2 = tx.clone();
8+
9+
tokio::spawn(async move {
10+
tx.send("sending from handle").await.unwrap();
11+
});
12+
13+
tokio::spawn(async move {
14+
tx2.send("sending from handle").await.unwrap();
15+
});
16+
17+
while let Some(message) = rx.recv().await {
18+
println!("GOT = {}", message);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GOT = sending from handle
2+
GOT = sending from handle

src/tools/miri/tests/pass-dep/tokio/sleep.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//@compile-flags: -Zmiri-permissive-provenance -Zmiri-backtrace=full
2-
//@only-target-x86_64-unknown-linux: support for tokio only on linux and x86
1+
//@only-target-linux: We only support tokio on Linux
32

43
use tokio::time::{sleep, Duration, Instant};
54

src/tools/miri/tests/pass-dep/tokio/tokio_mvp.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)