@@ -73,6 +73,21 @@ fn test_ls_ordering() {
73
73
. stdout_matches ( & Regex :: new ( "some-dir1:\\ ntotal 0" ) . unwrap ( ) ) ;
74
74
}
75
75
76
+ #[ cfg( all( unix, feature = "df" ) ) ]
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
+
76
91
#[ cfg( all( feature = "truncate" , feature = "dd" ) ) ]
77
92
#[ test] // FIXME: fix this test for FreeBSD
78
93
fn test_ls_allocation_size ( ) {
@@ -81,7 +96,7 @@ fn test_ls_allocation_size() {
81
96
at. mkdir ( "some-dir1" ) ;
82
97
at. touch ( "some-dir1/empty-file" ) ;
83
98
84
- #[ cfg( unix) ]
99
+ #[ cfg( all ( unix, feature = "df" ) ) ]
85
100
{
86
101
scene
87
102
. ccmd ( "truncate" )
@@ -115,13 +130,24 @@ fn test_ls_allocation_size() {
115
130
. succeeds ( )
116
131
. stdout_matches ( & Regex :: new ( "[^ ] 2 [^ ]" ) . unwrap ( ) ) ;
117
132
133
+ let fstype = get_filesystem_type ( & scene, & scene. fixtures . subdir ) ;
134
+ let ( zero_file_size_4k, zero_file_size_1k, zero_file_size_8k, zero_file_size_4m) =
135
+ match fstype. 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
+
118
141
#[ cfg( not( target_os = "freebsd" ) ) ]
119
142
scene
120
143
. ucmd ( )
121
144
. arg ( "-s1" )
122
145
. arg ( "some-dir1" )
123
146
. succeeds ( )
124
- . stdout_is ( "total 4096\n 0 empty-file\n 0 file-with-holes\n 4096 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
+ ) ) ;
125
151
126
152
scene
127
153
. ucmd ( )
@@ -138,7 +164,7 @@ fn test_ls_allocation_size() {
138
164
. arg ( "some-dir1" )
139
165
. succeeds ( )
140
166
. stdout_contains ( "0 empty-file" )
141
- . stdout_contains ( "4096 zero-file") ;
167
+ . stdout_contains ( format ! ( "{zero_file_size_4k} zero-file") ) ;
142
168
143
169
// Test alignment of different block sized files
144
170
let res = scene. ucmd ( ) . arg ( "-si1" ) . arg ( "some-dir1" ) . succeeds ( ) ;
@@ -185,10 +211,10 @@ fn test_ls_allocation_size() {
185
211
. arg ( "-s1" )
186
212
. arg ( "some-dir1" )
187
213
. succeeds ( )
188
- . stdout_contains ( "total 1024" )
214
+ . stdout_contains ( format ! ( "total {zero_file_size_1k}" ) )
189
215
. stdout_contains ( "0 empty-file" )
190
216
. stdout_contains ( "0 file-with-holes" )
191
- . stdout_contains ( "1024 zero-file") ;
217
+ . stdout_contains ( format ! ( "{zero_file_size_1k} zero-file") ) ;
192
218
193
219
#[ cfg( not( target_os = "freebsd" ) ) ]
194
220
scene
@@ -210,10 +236,10 @@ fn test_ls_allocation_size() {
210
236
. arg ( "-s1" )
211
237
. arg ( "some-dir1" )
212
238
. succeeds ( )
213
- . stdout_contains ( "total 1024" )
239
+ . stdout_contains ( format ! ( "total {zero_file_size_1k}" ) )
214
240
. stdout_contains ( "0 empty-file" )
215
241
. stdout_contains ( "0 file-with-holes" )
216
- . stdout_contains ( "1024 zero-file") ;
242
+ . stdout_contains ( format ! ( "{zero_file_size_1k} zero-file") ) ;
217
243
218
244
#[ cfg( not( target_os = "freebsd" ) ) ]
219
245
scene
@@ -222,10 +248,10 @@ fn test_ls_allocation_size() {
222
248
. arg ( "-s1" )
223
249
. arg ( "some-dir1" )
224
250
. succeeds ( )
225
- . stdout_contains ( "total 8192" )
251
+ . stdout_contains ( format ! ( "total {zero_file_size_8k}" ) )
226
252
. stdout_contains ( "0 empty-file" )
227
253
. stdout_contains ( "0 file-with-holes" )
228
- . stdout_contains ( "8192 zero-file") ;
254
+ . stdout_contains ( format ! ( "{zero_file_size_8k} zero-file") ) ;
229
255
230
256
// -k should make 'ls' ignore the env var
231
257
#[ cfg( not( target_os = "freebsd" ) ) ]
@@ -235,10 +261,10 @@ fn test_ls_allocation_size() {
235
261
. arg ( "-s1k" )
236
262
. arg ( "some-dir1" )
237
263
. succeeds ( )
238
- . stdout_contains ( "total 4096" )
264
+ . stdout_contains ( format ! ( "total {zero_file_size_4k}" ) )
239
265
. stdout_contains ( "0 empty-file" )
240
266
. stdout_contains ( "0 file-with-holes" )
241
- . stdout_contains ( "4096 zero-file") ;
267
+ . stdout_contains ( format ! ( "{zero_file_size_4k} zero-file") ) ;
242
268
243
269
// but manually specified blocksize overrides -k
244
270
#[ cfg( not( target_os = "freebsd" ) ) ]
@@ -248,10 +274,10 @@ fn test_ls_allocation_size() {
248
274
. arg ( "--block-size=4K" )
249
275
. arg ( "some-dir1" )
250
276
. succeeds ( )
251
- . stdout_contains ( "total 1024" )
277
+ . stdout_contains ( format ! ( "total {zero_file_size_1k}" ) )
252
278
. stdout_contains ( "0 empty-file" )
253
279
. stdout_contains ( "0 file-with-holes" )
254
- . stdout_contains ( "1024 zero-file") ;
280
+ . stdout_contains ( format ! ( "{zero_file_size_1k} zero-file") ) ;
255
281
256
282
#[ cfg( not( target_os = "freebsd" ) ) ]
257
283
scene
@@ -260,10 +286,10 @@ fn test_ls_allocation_size() {
260
286
. arg ( "--block-size=4K" )
261
287
. arg ( "some-dir1" )
262
288
. succeeds ( )
263
- . stdout_contains ( "total 1024" )
289
+ . stdout_contains ( format ! ( "total {zero_file_size_1k}" ) )
264
290
. stdout_contains ( "0 empty-file" )
265
291
. stdout_contains ( "0 file-with-holes" )
266
- . stdout_contains ( "1024 zero-file") ;
292
+ . stdout_contains ( format ! ( "{zero_file_size_1k} zero-file") ) ;
267
293
268
294
// si option should always trump the human-readable option
269
295
#[ cfg( not( target_os = "freebsd" ) ) ]
@@ -285,10 +311,10 @@ fn test_ls_allocation_size() {
285
311
. arg ( "--block-size=human-readable" )
286
312
. arg ( "some-dir1" )
287
313
. succeeds ( )
288
- . stdout_contains ( "total 4.0M" )
314
+ . stdout_contains ( format ! ( "total {zero_file_size_4m}" ) )
289
315
. stdout_contains ( "0 empty-file" )
290
316
. stdout_contains ( "0 file-with-holes" )
291
- . stdout_contains ( "4.0M zero-file") ;
317
+ . stdout_contains ( format ! ( "{zero_file_size_4m} zero-file") ) ;
292
318
293
319
#[ cfg( not( target_os = "freebsd" ) ) ]
294
320
scene
0 commit comments