Skip to content

Commit

Permalink
fix android 10
Browse files Browse the repository at this point in the history
  • Loading branch information
cre4ture committed Apr 28, 2024
1 parent ee8beb3 commit 29038d3
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ fn get_allocated_size_variant(scene: &TestScenario, path: &Path) -> AllocatedSiz

struct ExpectedSizes {
empty_file_1k_blocks: i32,
empty_file_bytes: i32,
empty_file_blocks_512: i32,
empty_file_bytes: &'static str,
empty_file_4k_blocks: i32,
empty_file_si: &'static str,
file_with_holes_1k_blocks: i32,
Expand All @@ -204,14 +205,16 @@ struct ExpectedSizes {
zero_file_size_blocksize_8192: i32,
zero_file_bytes: &'static str,
zero_file_si: &'static str,
total_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_bytes: 0,
empty_file_blocks_512: 0,
empty_file_bytes: "0",
empty_file_4k_blocks: 0,
empty_file_si: "0",
file_with_holes_1k_blocks: 0,
Expand All @@ -224,26 +227,30 @@ impl ExpectedSizes {
zero_file_size_blocksize_8192: 512,
zero_file_bytes: "4.0M",
zero_file_si: "4.2M",
total_si: "4.2M",
},
AllocatedSizeVariant::Android10Plus => Self {
empty_file_1k_blocks: 4,
empty_file_bytes: 4 * 512,
empty_file_blocks_512: 4 * 2,
empty_file_bytes: "4.0K",
empty_file_4k_blocks: 1,
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",
file_with_holes_bytes: "4.0K",
file_with_holes_si: "4.1k",
zero_file_size_1k_blocks: 4100,
zero_file_4k_blocks: 1025,
zero_file_size_blocksize_512: 8216,
zero_file_size_blocksize_8192: 512,
zero_file_bytes: "8.2M",
zero_file_si: "4.3M",
zero_file_size_blocksize_512: 8200,
zero_file_size_blocksize_8192: 513,
zero_file_bytes: "4.1M",
zero_file_si: "4.2M",
total_si: "4.3M",
},
AllocatedSizeVariant::F2fs4100 => Self {
empty_file_1k_blocks: 0,
empty_file_bytes: 0,
empty_file_blocks_512: 0,
empty_file_bytes: "0",
empty_file_4k_blocks: 0,
empty_file_si: "0",
file_with_holes_1k_blocks: 0,
Expand All @@ -256,10 +263,12 @@ impl ExpectedSizes {
zero_file_size_blocksize_8192: 512,
zero_file_bytes: "4.1M",
zero_file_si: "4.2M",
total_si: "4.2M",
},
AllocatedSizeVariant::ZFS => Self {
empty_file_1k_blocks: 1,
empty_file_bytes: 512,
empty_file_blocks_512: 2,
empty_file_bytes: "1.0K",
empty_file_4k_blocks: 1,
empty_file_si: "512",
file_with_holes_1k_blocks: 1,
Expand All @@ -272,10 +281,12 @@ impl ExpectedSizes {
zero_file_size_blocksize_8192: 514,
zero_file_bytes: "4.1M",
zero_file_si: "4.3M",
total_si: "4.3M",
},
AllocatedSizeVariant::UFS => Self {
empty_file_1k_blocks: 0,
empty_file_bytes: 0,
empty_file_blocks_512: 0,
empty_file_bytes: "0",
empty_file_4k_blocks: 0,
empty_file_si: "0",
file_with_holes_1k_blocks: 64,
Expand All @@ -288,6 +299,7 @@ impl ExpectedSizes {
zero_file_size_blocksize_8192: 514,
zero_file_bytes: "4.1M",
zero_file_si: "4.3M",
total_si: "4.3M",
},
}
}
Expand Down Expand Up @@ -471,9 +483,9 @@ fn test_ls_allocation_size_7(test_setup_1: (TestScenario, ExpectedSizes)) {
.arg("--si")
.arg("some-dir1")
.succeeds()
.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!("total {}", es.total_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));
}

Expand All @@ -500,16 +512,16 @@ fn test_ls_allocation_size_8(test_setup_1: (TestScenario, ExpectedSizes)) {
fn test_ls_allocation_size_9(test_setup_1: (TestScenario, ExpectedSizes)) {
let (scene, es) = test_setup_1;

let total = es.zero_file_size_blocksize_512 + 2 * es.empty_file_4k_blocks;
let total = es.zero_file_size_blocksize_512 + 2 * es.empty_file_blocks_512;
scene
.ucmd()
.env("POSIXLY_CORRECT", "true")
.arg("-s1")
.arg("some-dir1")
.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!("{} empty-file", es.empty_file_blocks_512))
.stdout_contains(format!("{} file-with-holes", es.empty_file_blocks_512))
.stdout_contains(format!("{} zero-file", es.zero_file_size_blocksize_512));
}

Expand Down Expand Up @@ -581,8 +593,8 @@ fn test_ls_allocation_size_13(test_setup_1: (TestScenario, ExpectedSizes)) {
.arg("--si")
.arg("some-dir1")
.succeeds()
.stdout_contains(format!("total {}", es.zero_file_si))
.stdout_contains(format!("{} empty-file", es.empty_file_bytes))
.stdout_contains(format!("total {}", es.total_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));
}
Expand All @@ -591,7 +603,6 @@ fn test_ls_allocation_size_13(test_setup_1: (TestScenario, ExpectedSizes)) {
#[rstest]
fn test_ls_allocation_size_14(test_setup_1: (TestScenario, ExpectedSizes)) {
let (scene, es) = test_setup_1;
let scene = scene.enable_uu_logs_debug();

scene
.ucmd()
Expand All @@ -616,7 +627,7 @@ 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_si))
.stdout_contains(format!("total {}", es.total_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));
Expand Down

0 comments on commit 29038d3

Please sign in to comment.