Skip to content

Commit 066032b

Browse files
committed
apply different reference sizes for f2fs (android) case
1 parent f3bbf53 commit 066032b

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

tests/by-util/test_ls.rs

+43-17
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ fn test_ls_ordering() {
7373
.stdout_matches(&Regex::new("some-dir1:\\ntotal 0").unwrap());
7474
}
7575

76+
#[cfg(all(unix, feature = "df", not(target_os = "freebsd")))]
77+
fn get_filesystem_type(scene: &TestScenario, path: &Path) -> String {
78+
let mut cmd = scene.ccmd("df");
79+
cmd.args(&["-PT"]).arg(path);
80+
let output = cmd.succeeds();
81+
let stdout_str = String::from_utf8_lossy(output.stdout());
82+
println!("output of stat call ({:?}):\n{}", cmd, stdout_str);
83+
let regex_str = r#"Filesystem\s+Type\s+.+[\r\n]+([^\s]+)\s+(?<fstype>[^\s]+)\s+"#;
84+
let regex = Regex::new(regex_str).unwrap();
85+
let m = regex.captures(&stdout_str).unwrap();
86+
let fstype = m["fstype"].to_owned();
87+
println!("detected fstype: {}", fstype);
88+
fstype
89+
}
90+
7691
#[cfg(all(feature = "truncate", feature = "dd"))]
7792
#[test] // FIXME: fix this test for FreeBSD
7893
fn test_ls_allocation_size() {
@@ -81,7 +96,7 @@ fn test_ls_allocation_size() {
8196
at.mkdir("some-dir1");
8297
at.touch("some-dir1/empty-file");
8398

84-
#[cfg(unix)]
99+
#[cfg(all(unix, feature = "df"))]
85100
{
86101
scene
87102
.ccmd("truncate")
@@ -115,13 +130,24 @@ fn test_ls_allocation_size() {
115130
.succeeds()
116131
.stdout_matches(&Regex::new("[^ ] 2 [^ ]").unwrap());
117132

133+
#[cfg(not(target_os = "freebsd"))]
134+
let (zero_file_size_4k, zero_file_size_1k, zero_file_size_8k, zero_file_size_4m) =
135+
match get_filesystem_type(&scene, &scene.fixtures.subdir).as_str() {
136+
// apparently f2fs (flash friendly fs) accepts small overhead for better performance
137+
"f2fs" => (4100, 1025, 8200, "4.1M"),
138+
_ => (4096, 1024, 8192, "4.0M"),
139+
};
140+
118141
#[cfg(not(target_os = "freebsd"))]
119142
scene
120143
.ucmd()
121144
.arg("-s1")
122145
.arg("some-dir1")
123146
.succeeds()
124-
.stdout_is("total 4096\n 0 empty-file\n 0 file-with-holes\n4096 zero-file\n");
147+
.stdout_is(format!(
148+
"total {zero_file_size_4k}\n 0 empty-file\n 0 file-with-holes\n\
149+
{zero_file_size_4k} zero-file\n"
150+
));
125151

126152
scene
127153
.ucmd()
@@ -138,7 +164,7 @@ fn test_ls_allocation_size() {
138164
.arg("some-dir1")
139165
.succeeds()
140166
.stdout_contains("0 empty-file")
141-
.stdout_contains("4096 zero-file");
167+
.stdout_contains(format!("{zero_file_size_4k} zero-file"));
142168

143169
// Test alignment of different block sized files
144170
let res = scene.ucmd().arg("-si1").arg("some-dir1").succeeds();
@@ -185,10 +211,10 @@ fn test_ls_allocation_size() {
185211
.arg("-s1")
186212
.arg("some-dir1")
187213
.succeeds()
188-
.stdout_contains("total 1024")
214+
.stdout_contains(format!("total {zero_file_size_1k}"))
189215
.stdout_contains("0 empty-file")
190216
.stdout_contains("0 file-with-holes")
191-
.stdout_contains("1024 zero-file");
217+
.stdout_contains(format!("{zero_file_size_1k} zero-file"));
192218

193219
#[cfg(not(target_os = "freebsd"))]
194220
scene
@@ -210,10 +236,10 @@ fn test_ls_allocation_size() {
210236
.arg("-s1")
211237
.arg("some-dir1")
212238
.succeeds()
213-
.stdout_contains("total 1024")
239+
.stdout_contains(format!("total {zero_file_size_1k}"))
214240
.stdout_contains("0 empty-file")
215241
.stdout_contains("0 file-with-holes")
216-
.stdout_contains("1024 zero-file");
242+
.stdout_contains(format!("{zero_file_size_1k} zero-file"));
217243

218244
#[cfg(not(target_os = "freebsd"))]
219245
scene
@@ -222,10 +248,10 @@ fn test_ls_allocation_size() {
222248
.arg("-s1")
223249
.arg("some-dir1")
224250
.succeeds()
225-
.stdout_contains("total 8192")
251+
.stdout_contains(format!("total {zero_file_size_8k}"))
226252
.stdout_contains("0 empty-file")
227253
.stdout_contains("0 file-with-holes")
228-
.stdout_contains("8192 zero-file");
254+
.stdout_contains(format!("{zero_file_size_8k} zero-file"));
229255

230256
// -k should make 'ls' ignore the env var
231257
#[cfg(not(target_os = "freebsd"))]
@@ -235,10 +261,10 @@ fn test_ls_allocation_size() {
235261
.arg("-s1k")
236262
.arg("some-dir1")
237263
.succeeds()
238-
.stdout_contains("total 4096")
264+
.stdout_contains(format!("total {zero_file_size_4k}"))
239265
.stdout_contains("0 empty-file")
240266
.stdout_contains("0 file-with-holes")
241-
.stdout_contains("4096 zero-file");
267+
.stdout_contains(format!("{zero_file_size_4k} zero-file"));
242268

243269
// but manually specified blocksize overrides -k
244270
#[cfg(not(target_os = "freebsd"))]
@@ -248,10 +274,10 @@ fn test_ls_allocation_size() {
248274
.arg("--block-size=4K")
249275
.arg("some-dir1")
250276
.succeeds()
251-
.stdout_contains("total 1024")
277+
.stdout_contains(format!("total {zero_file_size_1k}"))
252278
.stdout_contains("0 empty-file")
253279
.stdout_contains("0 file-with-holes")
254-
.stdout_contains("1024 zero-file");
280+
.stdout_contains(format!("{zero_file_size_1k} zero-file"));
255281

256282
#[cfg(not(target_os = "freebsd"))]
257283
scene
@@ -260,10 +286,10 @@ fn test_ls_allocation_size() {
260286
.arg("--block-size=4K")
261287
.arg("some-dir1")
262288
.succeeds()
263-
.stdout_contains("total 1024")
289+
.stdout_contains(format!("total {zero_file_size_1k}"))
264290
.stdout_contains("0 empty-file")
265291
.stdout_contains("0 file-with-holes")
266-
.stdout_contains("1024 zero-file");
292+
.stdout_contains(format!("{zero_file_size_1k} zero-file"));
267293

268294
// si option should always trump the human-readable option
269295
#[cfg(not(target_os = "freebsd"))]
@@ -285,10 +311,10 @@ fn test_ls_allocation_size() {
285311
.arg("--block-size=human-readable")
286312
.arg("some-dir1")
287313
.succeeds()
288-
.stdout_contains("total 4.0M")
314+
.stdout_contains(format!("total {zero_file_size_4m}"))
289315
.stdout_contains("0 empty-file")
290316
.stdout_contains("0 file-with-holes")
291-
.stdout_contains("4.0M zero-file");
317+
.stdout_contains(format!("{zero_file_size_4m} zero-file"));
292318

293319
#[cfg(not(target_os = "freebsd"))]
294320
scene

0 commit comments

Comments
 (0)