Skip to content

Commit

Permalink
Auto merge of rust-lang#3848 - tiif:tokiotest, r=RalfJung
Browse files Browse the repository at this point in the history
Add tokio io test

After rust-lang#3804 landed, these tests passed.
  • Loading branch information
bors committed Aug 28, 2024
2 parents 3a655aa + abcfc17 commit 79115f5
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/tools/miri/test_dependencies/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"

[[package]]
name = "bytes"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"

[[package]]
name = "cc"
version = "1.1.7"
Expand Down Expand Up @@ -304,6 +310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"pin-project-lite",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/test_dependencies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tempfile = "3"
page_size = "0.6"
# Avoid pulling in all of tokio's dependencies.
# However, without `net` and `signal`, tokio uses fewer relevant system APIs.
tokio = { version = "1.24", features = ["macros", "rt-multi-thread", "time", "net", "fs", "sync", "signal"] }
tokio = { version = "1.24", features = ["macros", "rt-multi-thread", "time", "net", "fs", "sync", "signal", "io-util"] }

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.52", features = [ "Win32_Foundation", "Win32_System_Threading" ] }
Expand Down
41 changes: 41 additions & 0 deletions src/tools/miri/tests/pass-dep/tokio/file-io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//@compile-flags: -Zmiri-disable-isolation
//@only-target-linux: We only support tokio on Linux

use std::fs::remove_file;
use tokio::fs::{File, OpenOptions};
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};

#[path = "../../utils/mod.rs"]
mod utils;

#[tokio::main]
async fn main() {
test_create_and_write().await.unwrap();
test_create_and_read().await.unwrap();
}

async fn test_create_and_write() -> io::Result<()> {
let path = utils::prepare("foo.txt");
let mut file = File::create(&path).await?;

// Write 10 bytes to the file.
file.write(b"some bytes").await?;
assert_eq!(file.metadata().await.unwrap().len(), 10);

remove_file(&path).unwrap();
Ok(())
}

async fn test_create_and_read() -> io::Result<()> {
let bytes = b"more bytes";
let path = utils::prepare_with_content("foo.txt", bytes);
let mut file = OpenOptions::new().read(true).open(&path).await.unwrap();
let mut buffer = [0u8; 10];

// Read the whole file.
file.read(&mut buffer[..]).await?;
assert_eq!(&buffer, b"more bytes");

remove_file(&path).unwrap();
Ok(())
}
20 changes: 20 additions & 0 deletions src/tools/miri/tests/pass-dep/tokio/mpsc-await.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@only-target-linux: We only support tokio on Linux
use tokio::sync::mpsc;

#[tokio::main]
async fn main() {
let (tx, mut rx) = mpsc::channel(32);
let tx2 = tx.clone();

tokio::spawn(async move {
tx.send("sending from handle").await.unwrap();
});

tokio::spawn(async move {
tx2.send("sending from handle").await.unwrap();
});

while let Some(message) = rx.recv().await {
println!("GOT = {}", message);
}
}
2 changes: 2 additions & 0 deletions src/tools/miri/tests/pass-dep/tokio/mpsc-await.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GOT = sending from handle
GOT = sending from handle
3 changes: 1 addition & 2 deletions src/tools/miri/tests/pass-dep/tokio/sleep.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@compile-flags: -Zmiri-permissive-provenance -Zmiri-backtrace=full
//@only-target-x86_64-unknown-linux: support for tokio only on linux and x86
//@only-target-linux: We only support tokio on Linux

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

Expand Down
6 changes: 0 additions & 6 deletions src/tools/miri/tests/pass-dep/tokio/tokio_mvp.rs

This file was deleted.

0 comments on commit 79115f5

Please sign in to comment.