Skip to content

Commit 63ff477

Browse files
akretzromanstingler
authored andcommitted
dd: Add test to check for dropped writes
(cherry picked from commit 0f7c531)
1 parent c391af9 commit 63ff477

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/by-util/test_dd.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,41 @@ fn test_wrong_number_err_msg() {
17811781
.stderr_contains("dd: invalid number: '1kBb555'\n");
17821782
}
17831783

1784+
#[test]
1785+
#[cfg(all(
1786+
unix,
1787+
not(target_os = "macos"),
1788+
not(target_os = "freebsd"),
1789+
feature = "printf"
1790+
))]
1791+
fn test_no_dropped_writes() {
1792+
const BLK_SIZE: usize = 0x4000;
1793+
const COUNT: usize = 1000;
1794+
const NUM_BYTES: usize = BLK_SIZE * COUNT;
1795+
1796+
let mut reader_command = Command::new(get_tests_binary());
1797+
let child = reader_command
1798+
.args(&[
1799+
"dd",
1800+
"if=/dev/urandom",
1801+
&format!("bs={}", BLK_SIZE),
1802+
&format!("count={}", COUNT),
1803+
])
1804+
.stdout(Stdio::piped())
1805+
.stderr(Stdio::piped())
1806+
.env("LC_ALL", "C")
1807+
.spawn()
1808+
.unwrap();
1809+
1810+
let output = child.wait_with_output().unwrap();
1811+
assert_eq!(output.stdout.len(), NUM_BYTES);
1812+
assert!(
1813+
str::from_utf8(&output.stderr)
1814+
.unwrap()
1815+
.contains(&format!("{} bytes", NUM_BYTES))
1816+
);
1817+
}
1818+
17841819
#[test]
17851820
#[cfg(any(target_os = "linux", target_os = "android"))]
17861821
fn test_oflag_direct_partial_block() {

0 commit comments

Comments
 (0)