Skip to content

Commit

Permalink
tests: dd: add skip-seek-past-dev tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bbara committed Jul 22, 2023
1 parent fad10ef commit 45a328e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/by-util/test_dd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// 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

#[cfg(unix)]
use crate::common::util::run_ucmd_as_root_with_stdin_stdout;
use crate::common::util::TestScenario;
#[cfg(all(not(windows), feature = "printf"))]
use crate::common::util::{UCommand, TESTS_BINARY};
Expand Down Expand Up @@ -1562,3 +1564,45 @@ fn test_nocache_file() {
.succeeds()
.stderr_only("2048+0 records in\n2048+0 records out\n");
}

#[test]
#[cfg(unix)]
fn test_skip_past_dev() {
// NOTE: This test intends to trigger code which can only be reached with root permissions.
let ts = TestScenario::new(util_name!());

if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
&ts,
&["bs=1", "skip=10000000000000000", "count=0", "status=noxfer"],
Some("/dev/sda1"),
None,
) {
result.stderr_contains("dd: 'standard input': cannot skip: Invalid argument");
result.stderr_contains("0+0 records in");
result.stderr_contains("0+0 records out");
result.code_is(1);
} else {
print!("TEST SKIPPED");
}
}

#[test]
#[cfg(unix)]
fn test_seek_past_dev() {
// NOTE: This test intends to trigger code which can only be reached with root permissions.
let ts = TestScenario::new(util_name!());

if let Ok(result) = run_ucmd_as_root_with_stdin_stdout(
&ts,
&["bs=1", "seek=10000000000000000", "count=0", "status=noxfer"],
None,
Some("/dev/sda1"),
) {
result.stderr_contains("dd: 'standard output': cannot seek: Invalid argument");
result.stderr_contains("0+0 records in");
result.stderr_contains("0+0 records out");
result.code_is(1);
} else {
print!("TEST SKIPPED");
}
}

0 comments on commit 45a328e

Please sign in to comment.