mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 11:36:16 +00:00
Merge pull request #4527 from bbara/dd-skip-seek
dd: fix GNU test 'dd/skip-seek-past-dev'
This commit is contained in:
commit
e8b27d1714
3 changed files with 112 additions and 14 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2532,6 +2532,16 @@ pub fn expected_result(ts: &TestScenario, args: &[&str]) -> std::result::Result<
|
|||
pub fn run_ucmd_as_root(
|
||||
ts: &TestScenario,
|
||||
args: &[&str],
|
||||
) -> std::result::Result<CmdResult, String> {
|
||||
run_ucmd_as_root_with_stdin_stdout(ts, args, None, None)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn run_ucmd_as_root_with_stdin_stdout(
|
||||
ts: &TestScenario,
|
||||
args: &[&str],
|
||||
stdin: Option<&str>,
|
||||
stdout: Option<&str>,
|
||||
) -> std::result::Result<CmdResult, String> {
|
||||
if is_ci() {
|
||||
Err(format!("{UUTILS_INFO}: {}", "cannot run inside CI"))
|
||||
|
@ -2546,16 +2556,21 @@ pub fn run_ucmd_as_root(
|
|||
Ok(output) if String::from_utf8_lossy(&output.stdout).eq("root\n") => {
|
||||
// we can run sudo and we're root
|
||||
// run ucmd as root:
|
||||
Ok(ts
|
||||
.cmd("sudo")
|
||||
.env("PATH", PATH)
|
||||
let mut cmd = ts.cmd("sudo");
|
||||
cmd.env("PATH", PATH)
|
||||
.envs(DEFAULT_ENV)
|
||||
.arg("-E")
|
||||
.arg("--non-interactive")
|
||||
.arg(&ts.bin_path)
|
||||
.arg(&ts.util_name)
|
||||
.args(args)
|
||||
.run())
|
||||
.args(args);
|
||||
if let Some(stdin) = stdin {
|
||||
cmd.set_stdin(File::open(stdin).unwrap());
|
||||
}
|
||||
if let Some(stdout) = stdout {
|
||||
cmd.set_stdout(File::open(stdout).unwrap());
|
||||
}
|
||||
Ok(cmd.run())
|
||||
}
|
||||
Ok(output)
|
||||
if String::from_utf8_lossy(&output.stderr).eq("sudo: a password is required\n") =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue