Skip to content

Commit

Permalink
fix freebsd UFS
Browse files Browse the repository at this point in the history
  • Loading branch information
cre4ture committed Apr 28, 2024
1 parent 2a01ce4 commit 1c21b65
Showing 1 changed file with 76 additions and 58 deletions.
134 changes: 76 additions & 58 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,85 +205,103 @@ fn get_filesystem_type(scene: &TestScenario, path: &Path) -> String {

struct ExpectedSizes {
empty_file_1k_blocks: i32,
empty_file_size_bytes: i32,
empty_file_bytes: i32,
empty_file_4k_blocks: i32,
empty_file_4k_si_size: &'static str,
empty_file_si: &'static str,
file_with_holes_1k_blocks: i32,
file_with_holes_4k_blocks: i32,
file_with_holes_bytes: &'static str,
file_with_holes_si: &'static str,
zero_file_size_1k_blocks: i32,
zero_file_size_1k: i32,
zero_file_4k_blocks: i32,
zero_file_size_blocksize_512: i32,
zero_file_size_blocksize_8192: i32,
zero_file_size_4m: &'static str,
zero_file_size_si_4m2: &'static str,
zero_file_bytes: &'static str,
zero_file_si: &'static str,
}

impl ExpectedSizes {
fn new(scene: &TestScenario, path: &Path) -> Self {
match get_allocated_size_variant(&scene, path) {
AllocatedSizeVariant::Default4096 => Self {
empty_file_1k_blocks: 0,
empty_file_size_bytes: 0,
empty_file_bytes: 0,
empty_file_4k_blocks: 0,
empty_file_4k_si_size: "0",
empty_file_si: "0",
file_with_holes_1k_blocks: 0,
file_with_holes_4k_blocks: 0,
file_with_holes_bytes: "0",
file_with_holes_si: "0",
zero_file_size_1k_blocks: 4096,
zero_file_size_1k: 1024,
zero_file_4k_blocks: 1024,
zero_file_size_blocksize_512: 8192,
zero_file_size_blocksize_8192: 512,
zero_file_size_4m: "4.0M",
zero_file_size_si_4m2: "4.2M",
zero_file_bytes: "4.0M",
zero_file_si: "4.2M",
},
AllocatedSizeVariant::Android10Plus => Self {

Check warning on line 242 in tests/by-util/test_ls.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_ls.rs#L242

Added line #L242 was not covered by tests
empty_file_1k_blocks: 4,
empty_file_size_bytes: 4 * 512,
empty_file_bytes: 4 * 512,
empty_file_4k_blocks: 1,
empty_file_4k_si_size: "4.1k",
empty_file_si: "4.1k",
file_with_holes_1k_blocks: 4,
file_with_holes_4k_blocks: 1,
file_with_holes_bytes: "2.0K",
file_with_holes_si: "2.1k",
zero_file_size_1k_blocks: 4100,
zero_file_size_1k: 1025,
zero_file_4k_blocks: 1025,
zero_file_size_blocksize_512: 8216,
zero_file_size_blocksize_8192: 512,
zero_file_size_4m: "8.2M",
zero_file_size_si_4m2: "4.3M",
zero_file_bytes: "8.2M",
zero_file_si: "4.3M",
},
AllocatedSizeVariant::F2fs4100 => Self {

Check warning on line 258 in tests/by-util/test_ls.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_ls.rs#L257-L258

Added lines #L257 - L258 were not covered by tests
empty_file_1k_blocks: 0,
empty_file_size_bytes: 0,
empty_file_bytes: 0,
empty_file_4k_blocks: 0,
empty_file_4k_si_size: "0",
empty_file_si: "0",
file_with_holes_1k_blocks: 0,
file_with_holes_4k_blocks: 0,
file_with_holes_bytes: "0",
file_with_holes_si: "0",
zero_file_size_1k_blocks: 4100,
zero_file_size_1k: 1025,
zero_file_4k_blocks: 1025,
zero_file_size_blocksize_512: 8200,
zero_file_size_blocksize_8192: 512,
zero_file_size_4m: "4.1M",
zero_file_size_si_4m2: "4.2M",
zero_file_bytes: "4.1M",
zero_file_si: "4.2M",
},
AllocatedSizeVariant::ZFS => Self {

Check warning on line 274 in tests/by-util/test_ls.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_ls.rs#L274

Added line #L274 was not covered by tests
empty_file_1k_blocks: 1,
empty_file_size_bytes: 512,
empty_file_bytes: 512,
empty_file_4k_blocks: 1,
empty_file_4k_si_size: "0",
empty_file_si: "512",
file_with_holes_1k_blocks: 1,
file_with_holes_4k_blocks: 1,
file_with_holes_bytes: "512",
file_with_holes_si: "512",
zero_file_size_1k_blocks: 4105,
zero_file_size_1k: 1027,
zero_file_4k_blocks: 1027,
zero_file_size_blocksize_512: 8209,
zero_file_size_blocksize_8192: 514,
zero_file_size_4m: "4.1M",
zero_file_size_si_4m2: "4.3M",
zero_file_bytes: "4.1M",
zero_file_si: "4.3M",
},
AllocatedSizeVariant::UFS => Self {

Check warning on line 290 in tests/by-util/test_ls.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_ls.rs#L290

Added line #L290 was not covered by tests
empty_file_1k_blocks: 0,
empty_file_size_bytes: 0,
empty_file_bytes: 0,
empty_file_4k_blocks: 0,
empty_file_4k_si_size: "0",
empty_file_si: "0",
file_with_holes_1k_blocks: 64,
file_with_holes_4k_blocks: 16,
file_with_holes_bytes: "64K",
file_with_holes_si: "66k",
zero_file_size_1k_blocks: 4128,
zero_file_size_1k: 1026,
zero_file_4k_blocks: 1032,
zero_file_size_blocksize_512: 8209,
zero_file_size_blocksize_8192: 514,
zero_file_size_4m: "4.1M",
zero_file_size_si_4m2: "4.3M",
zero_file_bytes: "4.1M",
zero_file_si: "4.3M",
},
}
}
Expand Down Expand Up @@ -458,7 +476,7 @@ fn test_ls_allocation_size_6(test_setup_1: (TestScenario, ExpectedSizes)) {
let (scene, es) = test_setup_1;

{
let total = es.zero_file_size_1k + 2 * es.empty_file_4k_blocks;
let total = es.zero_file_4k_blocks + 2 * es.empty_file_4k_blocks;
scene
.ucmd()
.env("BLOCK_SIZE", "4K")
Expand All @@ -468,7 +486,7 @@ fn test_ls_allocation_size_6(test_setup_1: (TestScenario, ExpectedSizes)) {
.stdout_contains(format!("total {total}"))
.stdout_contains(format!("{} empty-file", es.empty_file_4k_blocks))
.stdout_contains(format!("{} file-with-holes", es.empty_file_4k_blocks))
.stdout_contains(format!("{} zero-file", es.zero_file_size_1k));
.stdout_contains(format!("{} zero-file", es.zero_file_4k_blocks));
}
}

Expand All @@ -484,18 +502,18 @@ fn test_ls_allocation_size_7(test_setup_1: (TestScenario, ExpectedSizes)) {
.arg("--si")
.arg("some-dir1")
.succeeds()
.stdout_contains(format!("total {}", es.zero_file_size_si_4m2))
.stdout_contains(format!("{} empty-file", es.empty_file_size_bytes))
.stdout_contains(format!("{} file-with-holes", es.empty_file_size_bytes))
.stdout_contains(format!("{} zero-file", es.zero_file_size_si_4m2));
.stdout_contains(format!("total {}", es.zero_file_si))
.stdout_contains(format!("{} empty-file", es.empty_file_bytes))
.stdout_contains(format!("{} file-with-holes", es.empty_file_bytes))
.stdout_contains(format!("{} zero-file", es.zero_file_si));
}

#[cfg(all(feature = "truncate", feature = "dd"))]
#[rstest]
fn test_ls_allocation_size_8(test_setup_1: (TestScenario, ExpectedSizes)) {
let (scene, es) = test_setup_1;

let total = es.zero_file_size_1k + 2 * es.empty_file_4k_blocks;
let total = es.zero_file_4k_blocks + 2 * es.empty_file_4k_blocks;
scene
.ucmd()
.env("BLOCK_SIZE", "4096")
Expand All @@ -505,7 +523,7 @@ fn test_ls_allocation_size_8(test_setup_1: (TestScenario, ExpectedSizes)) {
.stdout_contains(format!("total {}", total))
.stdout_contains(format!("{} empty-file", es.empty_file_4k_blocks))
.stdout_contains(format!("{} file-with-holes", es.empty_file_4k_blocks))
.stdout_contains(format!("{} zero-file", es.zero_file_size_1k));
.stdout_contains(format!("{} zero-file", es.zero_file_4k_blocks));
}

#[cfg(all(feature = "truncate", feature = "dd"))]
Expand All @@ -532,7 +550,7 @@ fn test_ls_allocation_size_10(test_setup_1: (TestScenario, ExpectedSizes)) {
let (scene, es) = test_setup_1;

Check failure on line 550 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:550; use `cargo fmt -- "tests/by-util/test_ls.rs"`)

Check failure on line 550 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:550; use `cargo fmt -- "tests/by-util/test_ls.rs"`)

// -k should make 'ls' ignore the env var
let total = es.zero_file_size_1k_blocks + 2 * es.empty_file_1k_blocks;
let total = es.zero_file_size_1k_blocks + es.file_with_holes_1k_blocks + es.empty_file_1k_blocks;
scene
.ucmd()
.env("BLOCK_SIZE", "4K")
Expand All @@ -541,7 +559,7 @@ fn test_ls_allocation_size_10(test_setup_1: (TestScenario, ExpectedSizes)) {
.succeeds()
.stdout_contains(format!("total {}", total))
.stdout_contains(format!("{} empty-file", es.empty_file_1k_blocks))
.stdout_contains(format!("{} file-with-holes", es.empty_file_1k_blocks))
.stdout_contains(format!("{} file-with-holes", es.file_with_holes_1k_blocks))
.stdout_contains(format!("{} zero-file", es.zero_file_size_1k_blocks));
}

Expand All @@ -551,7 +569,7 @@ fn test_ls_allocation_size_11(test_setup_1: (TestScenario, ExpectedSizes)) {
let (scene, es) = test_setup_1;

// but manually specified blocksize overrides -k
let total = es.zero_file_size_1k + 2 * es.empty_file_4k_blocks;
let total = es.zero_file_4k_blocks + es.file_with_holes_4k_blocks + es.empty_file_4k_blocks;
scene
.ucmd()
.arg("-s1k")
Expand All @@ -560,16 +578,16 @@ fn test_ls_allocation_size_11(test_setup_1: (TestScenario, ExpectedSizes)) {
.succeeds()
.stdout_contains(format!("total {}", total))
.stdout_contains(format!("{} empty-file", es.empty_file_4k_blocks))
.stdout_contains(format!("{} file-with-holes", es.empty_file_4k_blocks))
.stdout_contains(format!("{} zero-file", es.zero_file_size_1k));
.stdout_contains(format!("{} file-with-holes", es.file_with_holes_4k_blocks))
.stdout_contains(format!("{} zero-file", es.zero_file_4k_blocks));
}

#[cfg(all(feature = "truncate", feature = "dd"))]
#[rstest]
fn test_ls_allocation_size_12(test_setup_1: (TestScenario, ExpectedSizes)) {
let (scene, es) = test_setup_1;

let total = es.zero_file_size_1k + 2 * es.empty_file_4k_blocks;
let total = es.zero_file_4k_blocks + es.file_with_holes_4k_blocks + es.empty_file_4k_blocks;
scene
.ucmd()
.arg("-s1")
Expand All @@ -578,8 +596,8 @@ fn test_ls_allocation_size_12(test_setup_1: (TestScenario, ExpectedSizes)) {
.succeeds()
.stdout_contains(format!("total {}", total))
.stdout_contains(format!("{} empty-file", es.empty_file_4k_blocks))
.stdout_contains(format!("{} file-with-holes", es.empty_file_4k_blocks))
.stdout_contains(format!("{} zero-file", es.zero_file_size_1k));
.stdout_contains(format!("{} file-with-holes", es.file_with_holes_4k_blocks))
.stdout_contains(format!("{} zero-file", es.zero_file_4k_blocks));
}

#[cfg(all(feature = "truncate", feature = "dd"))]
Expand All @@ -594,10 +612,10 @@ fn test_ls_allocation_size_13(test_setup_1: (TestScenario, ExpectedSizes)) {
.arg("--si")
.arg("some-dir1")
.succeeds()
.stdout_contains(format!("total {}", es.zero_file_size_si_4m2))
.stdout_contains(format!("{} empty-file", es.empty_file_size_bytes))
.stdout_contains(format!("{} file-with-holes", es.empty_file_size_bytes))
.stdout_contains(format!("{} zero-file", es.zero_file_size_si_4m2));
.stdout_contains(format!("total {}", es.zero_file_si))
.stdout_contains(format!("{} empty-file", es.empty_file_bytes))
.stdout_contains(format!("{} file-with-holes", es.file_with_holes_si))
.stdout_contains(format!("{} zero-file", es.zero_file_si));
}

#[cfg(all(feature = "truncate", feature = "dd"))]
Expand All @@ -611,10 +629,10 @@ fn test_ls_allocation_size_14(test_setup_1: (TestScenario, ExpectedSizes)) {
.arg("--block-size=human-readable")
.arg("some-dir1")
.succeeds()
.stdout_contains(format!("total {}", es.zero_file_size_4m))
.stdout_contains(format!("{} empty-file", es.empty_file_size_bytes))
.stdout_contains(format!("{} file-with-holes", es.empty_file_size_bytes))
.stdout_contains(format!("{} zero-file", es.zero_file_size_4m));
.stdout_contains(format!("total {}", es.zero_file_bytes))
.stdout_contains(format!("{} empty-file", es.empty_file_bytes))
.stdout_contains(format!("{} file-with-holes", es.file_with_holes_bytes))
.stdout_contains(format!("{} zero-file", es.zero_file_bytes));
}

#[cfg(all(feature = "truncate", feature = "dd"))]
Expand All @@ -628,10 +646,10 @@ fn test_ls_allocation_size_15(test_setup_1: (TestScenario, ExpectedSizes)) {
.arg("--block-size=si")
.arg("some-dir1")
.succeeds()
.stdout_contains(format!("total {}", es.zero_file_size_si_4m2))
.stdout_contains(format!("{} empty-file", es.empty_file_size_bytes))
.stdout_contains(format!("{} file-with-holes", es.empty_file_size_bytes))
.stdout_contains(format!("{} zero-file", es.zero_file_size_si_4m2));
.stdout_contains(format!("total {}", es.zero_file_si))
.stdout_contains(format!("{} empty-file", es.empty_file_si))
.stdout_contains(format!("{} file-with-holes", es.file_with_holes_si))
.stdout_contains(format!("{} zero-file", es.zero_file_si));
}

#[test]
Expand Down

0 comments on commit 1c21b65

Please sign in to comment.