Skip to contentSkip to conversation

common/rc: generalize _get_filesize()

PATCH Superseded Chao Yu 2 participants 3 messages Sep 27, 2019 – Oct 15, 2019

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 common/rc: generalize _get_filesize()

There are some testcases use below command to get file size, generalize it as global function _get_filesize()

ls -l $1 | $AWK_PROG '{print $5}'

- adjust common/defrag, generic/275 and generic/315 to use it
- remove unused _filesize in generic/013

---
 common/defrag     | 2 +-
 common/rc         | 5 +++++
 tests/generic/013 | 5 -----
 tests/generic/275 | 2 +-
 tests/generic/315 | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
common/defrag +1 -1
index 9866d3da..50596f70 100644
@@ -145,7 +145,7 @@ _defrag()
 	STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
 
 	if [ $FSTYP == "f2fs" ]; then
-		_filesize=`ls -l $1 | $AWK_PROG '{print $5}'`
+		_filesize=`_get_filesize $1`
 		$DEFRAG_PROG 0 $_filesize $1 >> $seqres.full 2>&1
 	else
 		$DEFRAG_PROG -v $1 >> $seqres.full 2>&1
common/rc +5 -0
index 66c7fd4d..69735ae6 100644
@@ -165,6 +165,11 @@ if [ ! -z "$REPORT_LIST" ]; then
 	_assert_report_list
 fi
 
+_get_filesize()
+{
+    echo `ls -l $1 | $AWK_PROG '{print $5}'`
+}
+
 _mount()
 {
     $MOUNT_PROG `_mount_ops_filter $*`
tests/generic/013 +0 -5
index 9e533ee8..bc596102 100755
@@ -24,11 +24,6 @@ _cleanup()
     rm -rf $TEST_DIR/fsstress.$$.*
 }
 
-_filesize()
-{
-    ls -l $1 | $AWK_PROG '{print "    filesize = " $5}'
-}
-
 # get standard environment, filters and checks
 . ./common/rc
 . ./common/filter
tests/generic/275 +1 -1
index a934c19c..adc82856 100755
@@ -73,7 +73,7 @@ echo "Bytes written until ENOSPC:" >>$seqres.full
 du $SCRATCH_MNT/tmp1 >>$seqres.full
 
 # And at least some of it should succeed.
-_filesize=`ls -l $SCRATCH_MNT/tmp1 | awk '{print $5}'`
+_filesize=`_get_filesize $SCRATCH_MNT/tmp1`
 [ $_filesize -lt $((128 * 1024)) ] && \
 	_fail "Partial write until enospc failed; wrote $_filesize bytes."
 
tests/generic/315 +1 -1
index fd49b579..808d7d74 100755
@@ -52,7 +52,7 @@ $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
 	$TEST_DIR/testfile.$seq >>$seqres.full 2>&1
 
 # Verify the file size, it should keep unchanged as 0 in this case
-fsize=`ls -l $TEST_DIR/testfile.$seq | awk '{print $5}'`
+fsize=`_get_filesize $TEST_DIR/testfile.$seq`
 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
 
 # Truncate the file size back to 0
Signature · 1 line
2.18.0.rc1
#1 lore raw
Quoted 35 lines · Chao Yu

There are some testcases use below command to get file size, generalize it as global function _get_filesize()

ls -l $1 | $AWK_PROG '{print $5}'

- adjust common/defrag, generic/275 and generic/315 to use it
- remove unused _filesize in generic/013

---
 common/defrag     | 2 +-
 common/rc         | 5 +++++
 tests/generic/013 | 5 -----
 tests/generic/275 | 2 +-
 tests/generic/315 | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
common/defrag +1 -1
index 9866d3da..50596f70 100644
@@ -145,7 +145,7 @@ _defrag()
 	STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
 
 	if [ $FSTYP == "f2fs" ]; then
-		_filesize=`ls -l $1 | $AWK_PROG '{print $5}'`
+		_filesize=`_get_filesize $1`
 		$DEFRAG_PROG 0 $_filesize $1 >> $seqres.full 2>&1
 	else
 		$DEFRAG_PROG -v $1 >> $seqres.full 2>&1
common/rc +0 -0
index 66c7fd4d..69735ae6 100644

common/rc if [ ! -z "$REPORT_LIST" ]; then · line 170

Quoted 6 lines
common/rc +3 -0
@@ -165,6 +165,11 @@ if [ ! -z "$REPORT_LIST" ]; then
 	_assert_report_list
 fi
 
+_get_filesize()
+{
+    echo `ls -l $1 | $AWK_PROG '{print $5}'`

Ah, you could update _get_filesize to use "stat -c %s" version then.

Thanks,
Eryu

Quoted 50 lines
common/rc +2 -0
+}
+
 _mount()
 {
     $MOUNT_PROG `_mount_ops_filter $*`
tests/generic/013 +0 -5
index 9e533ee8..bc596102 100755
@@ -24,11 +24,6 @@ _cleanup()
     rm -rf $TEST_DIR/fsstress.$$.*
 }
 
-_filesize()
-{
-    ls -l $1 | $AWK_PROG '{print "    filesize = " $5}'
-}
-
 # get standard environment, filters and checks
 . ./common/rc
 . ./common/filter
tests/generic/275 +1 -1
index a934c19c..adc82856 100755
@@ -73,7 +73,7 @@ echo "Bytes written until ENOSPC:" >>$seqres.full
 du $SCRATCH_MNT/tmp1 >>$seqres.full
 
 # And at least some of it should succeed.
-_filesize=`ls -l $SCRATCH_MNT/tmp1 | awk '{print $5}'`
+_filesize=`_get_filesize $SCRATCH_MNT/tmp1`
 [ $_filesize -lt $((128 * 1024)) ] && \
 	_fail "Partial write until enospc failed; wrote $_filesize bytes."
 
tests/generic/315 +1 -1
index fd49b579..808d7d74 100755
@@ -52,7 +52,7 @@ $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
 	$TEST_DIR/testfile.$seq >>$seqres.full 2>&1
 
 # Verify the file size, it should keep unchanged as 0 in this case
-fsize=`ls -l $TEST_DIR/testfile.$seq | awk '{print $5}'`
+fsize=`_get_filesize $TEST_DIR/testfile.$seq`
 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
 
 # Truncate the file size back to 0
Signature · 1 line
2.18.0.rc1
author
#2 lore raw
Quoted 39 lines · Eryu Guan
Quoted 38 lines · Chao Yu

There are some testcases use below command to get file size, generalize it as global function _get_filesize()

ls -l $1 | $AWK_PROG '{print $5}'

- adjust common/defrag, generic/275 and generic/315 to use it
- remove unused _filesize in generic/013

---
 common/defrag     | 2 +-
 common/rc         | 5 +++++
 tests/generic/013 | 5 -----
 tests/generic/275 | 2 +-
 tests/generic/315 | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
common/defrag +1 -1
index 9866d3da..50596f70 100644
@@ -145,7 +145,7 @@ _defrag()
 	STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
 
 	if [ $FSTYP == "f2fs" ]; then
-		_filesize=`ls -l $1 | $AWK_PROG '{print $5}'`
+		_filesize=`_get_filesize $1`
 		$DEFRAG_PROG 0 $_filesize $1 >> $seqres.full 2>&1
 	else
 		$DEFRAG_PROG -v $1 >> $seqres.full 2>&1
common/rc +0 -0
index 66c7fd4d..69735ae6 100644
@@ -165,6 +165,11 @@ if [ ! -z "$REPORT_LIST" ]; then
 	_assert_report_list
 fi
 
Quoted 5 lines

common/rc if [ ! -z "$REPORT_LIST" ]; then · line 170

Quoted 3 lines
common/rc +3 -0
+_get_filesize()
+{
+    echo `ls -l $1 | $AWK_PROG '{print $5}'`

Ah, you could update _get_filesize to use "stat -c %s" version then.

Copied. :)

Thanks,

Quoted 56 lines

Thanks,
Eryu

Quoted 50 lines
common/rc +2 -0
+}
+
 _mount()
 {
     $MOUNT_PROG `_mount_ops_filter $*`
tests/generic/013 +0 -5
index 9e533ee8..bc596102 100755
@@ -24,11 +24,6 @@ _cleanup()
     rm -rf $TEST_DIR/fsstress.$$.*
 }
 
-_filesize()
-{
-    ls -l $1 | $AWK_PROG '{print "    filesize = " $5}'
-}
-
 # get standard environment, filters and checks
 . ./common/rc
 . ./common/filter
tests/generic/275 +1 -1
index a934c19c..adc82856 100755
@@ -73,7 +73,7 @@ echo "Bytes written until ENOSPC:" >>$seqres.full
 du $SCRATCH_MNT/tmp1 >>$seqres.full
 
 # And at least some of it should succeed.
-_filesize=`ls -l $SCRATCH_MNT/tmp1 | awk '{print $5}'`
+_filesize=`_get_filesize $SCRATCH_MNT/tmp1`
 [ $_filesize -lt $((128 * 1024)) ] && \
 	_fail "Partial write until enospc failed; wrote $_filesize bytes."
 
tests/generic/315 +1 -1
index fd49b579..808d7d74 100755
@@ -52,7 +52,7 @@ $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
 	$TEST_DIR/testfile.$seq >>$seqres.full 2>&1
 
 # Verify the file size, it should keep unchanged as 0 in this case
-fsize=`ls -l $TEST_DIR/testfile.$seq | awk '{print $5}'`
+fsize=`_get_filesize $TEST_DIR/testfile.$seq`
 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
 
 # Truncate the file size back to 0
Signature · 1 line
2.18.0.rc1

.