From 17f4d17021148b038e2f2c7942eea6004e06a06c Mon Sep 17 00:00:00 2001 From: Benjamin Bara Date: Sat, 22 Jul 2023 11:26:56 +0200 Subject: [PATCH] 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. --- tests/by-util/test_dd.rs | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index fe38acca4..8ebf57c1c 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -4,6 +4,8 @@ // file that was distributed with this source code. // 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}; @@ -1566,3 +1568,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"); + } +}