Skip to content

Commit c7fdae1

Browse files
committed
tests: dd: add skip-seek-past-dev tests
These tests try to read or write past a block device, where the block device is either given as stdin or stdout. It requires access to the block device, and therefore is executed as root. For now, it is assumed that a block device "/dev/sda1" with a size smaller than 10000000000000000 exists.
1 parent 923e2cf commit c7fdae1

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

tests/by-util/test_dd.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, availible, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm abcdefghi nabcde nabcdefg abcdefg
22

3-
use crate::common::util::TestScenario;
3+
use crate::common::util::{run_ucmd_as_root_with_stdin_stdout, TestScenario};
44
#[cfg(all(not(windows), feature = "printf"))]
55
use crate::common::util::{UCommand, TESTS_BINARY};
66

@@ -1562,3 +1562,45 @@ fn test_nocache_file() {
15621562
.succeeds()
15631563
.stderr_only("2048+0 records in\n2048+0 records out\n");
15641564
}
1565+
1566+
#[test]
1567+
#[cfg(unix)]
1568+
fn test_skip_past_dev() {
1569+
// NOTE: This test intends to trigger code which can only be reached with root permissions.
1570+
let ts = TestScenario::new(util_name!());
1571+
1572+
if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
1573+
&ts,
1574+
&["bs=1", "skip=10000000000000000", "count=0", "status=noxfer"],
1575+
Some("/dev/sda1"),
1576+
None,
1577+
) {
1578+
result.stderr_contains("dd: 'standard input': cannot skip: Invalid argument");
1579+
result.stderr_contains("0+0 records in");
1580+
result.stderr_contains("0+0 records out");
1581+
result.code_is(1);
1582+
} else {
1583+
print!("TEST SKIPPED");
1584+
}
1585+
}
1586+
1587+
#[test]
1588+
#[cfg(unix)]
1589+
fn test_seek_past_dev() {
1590+
// NOTE: This test intends to trigger code which can only be reached with root permissions.
1591+
let ts = TestScenario::new(util_name!());
1592+
1593+
if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
1594+
&ts,
1595+
&["bs=1", "seek=10000000000000000", "count=0", "status=noxfer"],
1596+
None,
1597+
Some("/dev/sda1"),
1598+
) {
1599+
result.stderr_contains("dd: 'standard output': cannot seek: Invalid argument");
1600+
result.stderr_contains("0+0 records in");
1601+
result.stderr_contains("0+0 records out");
1602+
result.code_is(1);
1603+
} else {
1604+
print!("TEST SKIPPED");
1605+
}
1606+
}

0 commit comments

Comments
 (0)