about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-28 08:52:03 +0000
committerbors <bors@rust-lang.org>2024-08-28 08:52:03 +0000
commit79115f538aca805455d6c207d8870dee884c63f3 (patch)
tree50698f98144e6dde687133b37121f3b2513cc66b
parent3a655aa4cbdea7f19b888db5d3b45c49720984b4 (diff)
parentabcfc17dc761d1d64859aaad247271500bfafdda (diff)
downloadrust-79115f538aca805455d6c207d8870dee884c63f3.tar.gz
rust-79115f538aca805455d6c207d8870dee884c63f3.zip
Auto merge of #3848 - tiif:tokiotest, r=RalfJung
Add tokio io test

After #3804 landed, these tests passed.
-rw-r--r--src/tools/miri/test_dependencies/Cargo.lock7
-rw-r--r--src/tools/miri/test_dependencies/Cargo.toml2
-rw-r--r--src/tools/miri/tests/pass-dep/tokio/file-io.rs41
-rw-r--r--src/tools/miri/tests/pass-dep/tokio/mpsc-await.rs20
-rw-r--r--src/tools/miri/tests/pass-dep/tokio/mpsc-await.stdout2
-rw-r--r--src/tools/miri/tests/pass-dep/tokio/sleep.rs3
-rw-r--r--src/tools/miri/tests/pass-dep/tokio/tokio_mvp.rs6
7 files changed, 72 insertions, 9 deletions
diff --git a/src/tools/miri/test_dependencies/Cargo.lock b/src/tools/miri/test_dependencies/Cargo.lock
index bbead878223..39d41281728 100644
--- a/src/tools/miri/test_dependencies/Cargo.lock
+++ b/src/tools/miri/test_dependencies/Cargo.lock
@@ -45,6 +45,12 @@ 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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -304,6 +310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1"
 dependencies = [
  "backtrace",
+ "bytes",
  "libc",
  "mio",
  "pin-project-lite",
diff --git a/src/tools/miri/test_dependencies/Cargo.toml b/src/tools/miri/test_dependencies/Cargo.toml
index ce11a8abb0e..c24422df26c 100644
--- a/src/tools/miri/test_dependencies/Cargo.toml
+++ b/src/tools/miri/test_dependencies/Cargo.toml
@@ -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" ] }
diff --git a/src/tools/miri/tests/pass-dep/tokio/file-io.rs b/src/tools/miri/tests/pass-dep/tokio/file-io.rs
new file mode 100644
index 00000000000..d14af299cd4
--- /dev/null
+++ b/src/tools/miri/tests/pass-dep/tokio/file-io.rs
@@ -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(())
+}
diff --git a/src/tools/miri/tests/pass-dep/tokio/mpsc-await.rs b/src/tools/miri/tests/pass-dep/tokio/mpsc-await.rs
new file mode 100644
index 00000000000..7dea07c6e7d
--- /dev/null
+++ b/src/tools/miri/tests/pass-dep/tokio/mpsc-await.rs
@@ -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);
+    }
+}
diff --git a/src/tools/miri/tests/pass-dep/tokio/mpsc-await.stdout b/src/tools/miri/tests/pass-dep/tokio/mpsc-await.stdout
new file mode 100644
index 00000000000..52dc6483186
--- /dev/null
+++ b/src/tools/miri/tests/pass-dep/tokio/mpsc-await.stdout
@@ -0,0 +1,2 @@
+GOT = sending from handle
+GOT = sending from handle
diff --git a/src/tools/miri/tests/pass-dep/tokio/sleep.rs b/src/tools/miri/tests/pass-dep/tokio/sleep.rs
index e6b02c02d03..5e63037c8a6 100644
--- a/src/tools/miri/tests/pass-dep/tokio/sleep.rs
+++ b/src/tools/miri/tests/pass-dep/tokio/sleep.rs
@@ -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};
 
diff --git a/src/tools/miri/tests/pass-dep/tokio/tokio_mvp.rs b/src/tools/miri/tests/pass-dep/tokio/tokio_mvp.rs
deleted file mode 100644
index 769a7a7d384..00000000000
--- a/src/tools/miri/tests/pass-dep/tokio/tokio_mvp.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-// Need to disable preemption to stay on the supported MVP codepath in mio.
-//@compile-flags: -Zmiri-permissive-provenance -Zmiri-preemption-rate=0
-//@only-target-x86_64-unknown-linux: support for tokio exists only on linux and x86
-
-#[tokio::main]
-async fn main() {}