Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6bd68fc
Run filecheck on dest-prop/branch.rs
CastilloDel Apr 14, 2024
f238eba
Run filecheck on dest-prop/copy_propagation.rs
CastilloDel Apr 14, 2024
853311c
Run filecheck on dest-prop/cycle.rs
CastilloDel Apr 14, 2024
0692090
Run filecheck on dest-prop/dead_stores_79191.rs and dead_stores_bette…
CastilloDel Apr 14, 2024
f0f867e
Run filecheck on dest-prop/simple.rs
CastilloDel Apr 14, 2024
2d5a483
Acknowledge comments
CastilloDel Jun 26, 2024
04eed9b
Initial implementation of annoymous_pipe
NobodyXu Jun 30, 2024
72bda33
Fix compilation errors
NobodyXu Jun 30, 2024
42e8beb
Implement validation in `TryFrom<OwnedFd> for PIpe*` on unix
NobodyXu Jun 30, 2024
e170c78
Move the mod `pipe` to `std::net`
NobodyXu Jun 30, 2024
473fbce
Fix typo
NobodyXu Jun 30, 2024
97626b6
Fix tidy errors
NobodyXu Jun 30, 2024
d60438f
Validate pipe in `TryFrom<OwnedHandle> for Pipe*`
NobodyXu Jun 30, 2024
b7af685
Refactor: Extract new method `FileDesc::get_access_mode`
NobodyXu Jun 30, 2024
4c6b6bb
Add testing for anonymous pipe
NobodyXu Jul 1, 2024
594abec
Refactor: Put mod `unix` & `windows` into separate files
NobodyXu Jul 2, 2024
d9f0980
Fix `anonymous_pipe` impl for not supported targets
NobodyXu Jul 2, 2024
6c755a3
Optimize: Add `#[inline]` to very simple function
NobodyXu Jul 2, 2024
4819270
use "bootstrap" instead of "rustbuild" in comments and docs
onur-ozkan Jul 6, 2024
99721c8
Clear `inner_attr_ranges` regularly.
nnethercote Jul 8, 2024
d15cee5
Refactor: Make `AcessMode` an enum`
NobodyXu Jul 9, 2024
e22dd1a
Update mod.rs
NobodyXu Jul 10, 2024
100fe5c
Move `std::net::pip*` to a new mod `std::pipe`
NobodyXu Jul 10, 2024
62b846e
Remove use of `macro_rules!`
NobodyXu Jul 10, 2024
4547b30
Replace `TryFrom<Owned*>` with `From`
NobodyXu Jul 10, 2024
72f5999
Fix compilation on non-unix, non-windows targets
NobodyXu Jul 11, 2024
45886cc
Fix compilation error on unsupported target
NobodyXu Jul 12, 2024
7fc6943
Use ManuallyDrop in BufWriter::into_parts
saethlin Jul 12, 2024
4d35754
Add URL and crate_name to test cases
notriddle Jul 13, 2024
17419f6
rustdoc: rename `issue-\d+.rs` tests to have meaningful names
notriddle Jul 13, 2024
42ee400
Move assertion-free rustdoc ice tests to rustdoc-ui
notriddle Jul 13, 2024
fc0d1dc
use `ModeToolBootstrap` for run-make-support's crate tests
onur-ozkan Jul 13, 2024
41070bd
explain why we use in-tree std for compiletest
onur-ozkan Jul 13, 2024
cf0c9eb
Rollup merge of #122300 - CastilloDel:master, r=cjgillot
jhpratt Jul 13, 2024
9df00a2
Rollup merge of #127153 - NobodyXu:pipe, r=jhpratt
jhpratt Jul 13, 2024
40e6379
Rollup merge of #127434 - onur-ozkan:use-bootstrap-instead-of-rustbui…
jhpratt Jul 13, 2024
6982f91
Rollup merge of #127477 - nnethercote:tweak-inner_attr_ranges, r=petr…
jhpratt Jul 13, 2024
e6af63a
Rollup merge of #127659 - saethlin:manually-drop-bufwriter, r=joboet
jhpratt Jul 13, 2024
6e18eaf
Rollup merge of #127671 - notriddle:notriddle/issue-d, r=Mark-Simulacrum
jhpratt Jul 13, 2024
7a165e5
Rollup merge of #127677 - onur-ozkan:use-correct-modes, r=Kobzol
jhpratt Jul 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add testing for anonymous pipe
Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Jul 1, 2024
commit 4c6b6bbb850627ab22f2866b750770bd4e90a183
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,6 @@ mod windows {
}
}
}

#[cfg(test)]
mod tests;
128 changes: 128 additions & 0 deletions library/std/src/sys/anonymous_pipe/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
use super::*;
use crate::io::{Read, Write};

#[test]
fn pipe_creation_and_rw() {
let (mut rx, mut tx) = pipe().unwrap();
tx.write_all(b"12345").unwrap();
drop(tx);

let mut s = String::new();
rx.read_to_string(&mut s).unwrap();
assert_eq!(s, "12345");
}

#[test]
fn pipe_try_clone_and_rw() {
let (mut rx, mut tx) = pipe().unwrap();
tx.try_clone().unwrap().write_all(b"12").unwrap();
tx.write_all(b"345").unwrap();
drop(tx);

let mut s = String::new();
rx.try_clone().unwrap().take(3).read_to_string(&mut s).unwrap();
assert_eq!(s, "123");

s.clear();
rx.read_to_string(&mut s).unwrap();
assert_eq!(s, "45");
}

#[cfg(unix)]
mod unix_specific {
use super::*;

use crate::{
fs::File,
io,
os::fd::{AsRawFd, OwnedFd},
};

#[test]
fn pipe_owned_fd_round_trip_conversion() {
let (rx, tx) = pipe().unwrap();
let raw_fds = (rx.as_raw_fd(), tx.as_raw_fd());
let (rx_owned_fd, tx_owned_fd) = (OwnedFd::from(rx), OwnedFd::from(tx));

let rx = PipeReader::try_from(rx_owned_fd).unwrap();
let tx = PipeWriter::try_from(tx_owned_fd).unwrap();
assert_eq!(raw_fds, (rx.as_raw_fd(), tx.as_raw_fd()));
}

#[test]
fn convert_from_non_pipe_to_pipe_reader_shall_fail() {
let file = File::open("/dev/zero").unwrap();
let err = PipeReader::try_from(OwnedFd::from(file)).unwrap_err();

assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert_eq!(format!("{}", err.get_ref().unwrap()), "Not a pipe");
}

#[test]
fn convert_from_non_pipe_to_pipe_writer_shall_fail() {
let file = File::options().write(true).open("/dev/null").unwrap();
let err = PipeWriter::try_from(OwnedFd::from(file)).unwrap_err();

assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert_eq!(format!("{}", err.get_ref().unwrap()), "Not a pipe");
}

#[test]
fn convert_pipe_writer_to_pipe_reader_shall_fail() {
let (_, tx) = pipe().unwrap();
let fd = tx.as_raw_fd();
let err = PipeReader::try_from(OwnedFd::from(tx)).unwrap_err();

assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert_eq!(format!("{}", err.get_ref().unwrap()), format!("Pipe {fd} is not readable"));
}

#[test]
fn convert_pipe_reader_to_pipe_writer_shall_fail() {
let (rx, _) = pipe().unwrap();
let fd = rx.as_raw_fd();
let err = PipeWriter::try_from(OwnedFd::from(rx)).unwrap_err();

assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert_eq!(format!("{}", err.get_ref().unwrap()), format!("Pipe {fd} is not writable"));
}
}

#[cfg(windows)]
mod windows_specific {
use super::*;

use crate::{
io,
os::windows::io::{AsHandle, AsRawHandle, OwnedHandle},
};

#[test]
fn pipe_owned_handle_round_trip_conversion() {
let (rx, tx) = pipe().unwrap();
let raw_handles = (rx.as_raw_handle(), tx.as_raw_handle());
let (rx_owned_handle, tx_owned_handle) = (OwnedHandle::from(rx), OwnedHandle::from(tx));

let rx = PipeReader::try_from(rx_owned_handle).unwrap();
let tx = PipeWriter::try_from(tx_owned_handle).unwrap();
assert_eq!(raw_handles, (rx.as_raw_handle(), tx.as_raw_handle()));
}

#[test]
fn convert_from_non_pipe_to_pipe_reader_shall_fail() {
let file = io::stdin().as_handle().try_clone_to_owned().unwrap();
let err = PipeReader::try_from(OwnedHandle::from(file)).unwrap_err();

assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert_eq!(format!("{}", err.get_ref().unwrap()), "Not a pipe");
}

#[test]
fn convert_from_non_pipe_to_pipe_writer_shall_fail() {
let file = io::stdout().as_handle().try_clone_to_owned().unwrap();
let err = PipeWriter::try_from(OwnedHandle::from(file)).unwrap_err();

assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert_eq!(format!("{}", err.get_ref().unwrap()), "Not a pipe");
}
}