1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Fix the debug results in cp --debug (#6220)

This commit is contained in:
Anirban Halder 2024-04-22 20:32:21 +05:30 committed by GitHub
parent 366af1c056
commit 421b820ec2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1081 additions and 24 deletions

View file

@ -3581,7 +3581,7 @@ fn test_cp_debug_sparse_never() {
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: unknown, reflink: unsupported, sparse detection: no") {
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
@ -3831,6 +3831,642 @@ fn test_acl_preserve() {
assert!(compare_xattrs(&file, &file_target));
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
at.write("a", "hello");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("a")
.arg("b")
.succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
let src_file_metadata = std::fs::metadata(at.plus("a")).unwrap();
if dst_file_metadata.blocks() != src_file_metadata.blocks() {
panic!("File not sparsely copied");
}
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: SEEK_HOLE") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_empty_file_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("a")
.arg("b")
.succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
let src_file_metadata = std::fs::metadata(at.plus("a")).unwrap();
if dst_file_metadata.blocks() != src_file_metadata.blocks() {
panic!("File not sparsely copied");
}
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: unknown, reflink: no, sparse detection: SEEK_HOLE") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_default_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
at.append_bytes("a", "hello".as_bytes());
let result = ts.ucmd().arg("--debug").arg("a").arg("b").succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
let src_file_metadata = std::fs::metadata(at.plus("a")).unwrap();
if dst_file_metadata.blocks() != src_file_metadata.blocks() {
panic!("File not sparsely copied");
}
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: yes, reflink: unsupported, sparse detection: SEEK_HOLE")
{
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_default_less_than_512_bytes() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
at.append_bytes("a", "hello".as_bytes());
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(400).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=auto")
.arg("--sparse=auto")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: yes, reflink: unsupported, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_default_without_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
at.append_bytes("a", "hello".as_bytes());
let filler_bytes = [0_u8; 10000];
at.append_bytes("a", &filler_bytes);
let result = ts.ucmd().arg("--debug").arg("a").arg("b").succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: yes, reflink: unsupported, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_default_empty_file_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
let result = ts.ucmd().arg("--debug").arg("a").arg("b").succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
let src_file_metadata = std::fs::metadata(at.plus("a")).unwrap();
if dst_file_metadata.blocks() != src_file_metadata.blocks() {
panic!("File not sparsely copied");
}
let stdout_str = result.stdout_str();
if !stdout_str
.contains("copy offload: unknown, reflink: unsupported, sparse detection: SEEK_HOLE")
{
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_sparse_always_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
at.write("a", "hello");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("--sparse=always")
.arg("a")
.arg("b")
.succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
let src_file_metadata = std::fs::metadata(at.plus("a")).unwrap();
if dst_file_metadata.blocks() != src_file_metadata.blocks() {
panic!("File not sparsely copied");
}
let stdout_str = result.stdout_str();
if !stdout_str
.contains("copy offload: avoided, reflink: no, sparse detection: SEEK_HOLE + zeros")
{
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_sparse_always_without_hole() {
let ts = TestScenario::new(util_name!());
let empty_bytes = [0_u8; 10000];
let at = &ts.fixtures;
at.touch("a");
at.write("a", "hello");
at.append_bytes("a", &empty_bytes);
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("--sparse=always")
.arg("a")
.arg("b")
.succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
if dst_file_metadata.blocks() != dst_file_metadata.blksize() / 512 {
panic!("Zero sequenced blocks not removed");
}
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: zeros") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_sparse_always_empty_file_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("--sparse=always")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: unknown, reflink: no, sparse detection: SEEK_HOLE") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_cp_default_virtual_file() {
use std::os::unix::prelude::MetadataExt;
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
ts.ucmd()
.arg("/sys/kernel/address_bits")
.arg("b")
.succeeds();
let dest_size = std::fs::metadata(at.plus("b"))
.expect("Metadata of copied file cannot be read")
.size();
if dest_size == 0 {
panic!("Copy unsuccessful");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_auto_sparse_always_non_sparse_file_with_long_zero_sequence() {
let ts = TestScenario::new(util_name!());
let buf: Vec<u8> = vec![0; 4096 * 4];
let at = &ts.fixtures;
at.touch("a");
at.append_bytes("a", &buf);
at.append_bytes("a", "hello".as_bytes());
let result = ts
.ucmd()
.arg("--debug")
.arg("--sparse=always")
.arg("a")
.arg("b")
.succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
if dst_file_metadata.blocks() != dst_file_metadata.blksize() / 512 {
panic!("Zero sequenced blocks not removed");
}
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: unsupported, sparse detection: zeros")
{
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_cp_debug_sparse_never_empty_sparse_file() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let result = ts
.ucmd()
.arg("--debug")
.arg("--sparse=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_sparse_always_non_sparse_file_with_long_zero_sequence() {
let ts = TestScenario::new(util_name!());
let buf: Vec<u8> = vec![0; 4096 * 4];
let at = &ts.fixtures;
at.touch("a");
at.append_bytes("a", &buf);
at.append_bytes("a", "hello".as_bytes());
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("--sparse=always")
.arg("a")
.arg("b")
.succeeds();
let dst_file_metadata = std::fs::metadata(at.plus("b")).unwrap();
if dst_file_metadata.blocks() != dst_file_metadata.blksize() / 512 {
panic!("Zero sequenced blocks not removed");
}
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: zeros") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_cp_debug_sparse_always_sparse_virtual_file() {
let ts = TestScenario::new(util_name!());
let result = ts
.ucmd()
.arg("--debug")
.arg("--sparse=always")
.arg("/sys/kernel/address_bits")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains(
"copy offload: avoided, reflink: unsupported, sparse detection: SEEK_HOLE + zeros",
) {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_less_than_512_bytes() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
at.append_bytes("a", "hello".as_bytes());
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(400).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_sparse_never_empty_file_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("--sparse=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: unknown, reflink: no, sparse detection: SEEK_HOLE") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_file_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
at.append_bytes("a", "hello".as_bytes());
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("--sparse=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: SEEK_HOLE") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_sparse_never_less_than_512_bytes() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
at.append_bytes("a", "hello".as_bytes());
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(400).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=auto")
.arg("--sparse=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_sparse_never_without_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
at.append_bytes("a", "hello".as_bytes());
let filler_bytes = [0_u8; 10000];
at.append_bytes("a", &filler_bytes);
let result = ts
.ucmd()
.arg("--reflink=auto")
.arg("--sparse=never")
.arg("--debug")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_sparse_never_empty_file_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=auto")
.arg("--sparse=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: unknown, reflink: no, sparse detection: SEEK_HOLE") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_sparse_never_file_with_hole() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let f = std::fs::OpenOptions::new()
.write(true)
.open(at.plus("a"))
.unwrap();
f.set_len(10000).unwrap();
at.append_bytes("a", "hello".as_bytes());
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=auto")
.arg("--sparse=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: SEEK_HOLE") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_cp_debug_default_sparse_virtual_file() {
let ts = TestScenario::new(util_name!());
let result = ts
.ucmd()
.arg("--debug")
.arg("/sys/kernel/address_bits")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str
.contains("copy offload: unsupported, reflink: unsupported, sparse detection: SEEK_HOLE")
{
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_cp_debug_sparse_never_zero_sized_virtual_file() {
let ts = TestScenario::new(util_name!());
let result = ts
.ucmd()
.arg("--debug")
.arg("--sparse=never")
.arg("/proc/version")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_cp_debug_default_zero_sized_virtual_file() {
let ts = TestScenario::new(util_name!());
let result = ts
.ucmd()
.arg("--debug")
.arg("/proc/version")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: unsupported, reflink: unsupported, sparse detection: no")
{
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_debug_reflink_never_without_hole() {
let ts = TestScenario::new(util_name!());
let filler_bytes = [0_u8; 1000];
let at = &ts.fixtures;
at.touch("a");
at.write("a", "hello");
at.append_bytes("a", &filler_bytes);
let result = ts
.ucmd()
.arg("--debug")
.arg("--reflink=never")
.arg("a")
.arg("b")
.succeeds();
let stdout_str = result.stdout_str();
if !stdout_str.contains("copy offload: avoided, reflink: no, sparse detection: no") {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
fn test_cp_force_remove_destination_attributes_only_with_symlink() {