* [PATCH v2] common/rc: generalize _get_filesize()
@ 2019-10-15 10:11 Chao Yu
2019-10-15 18:17 ` Darrick J. Wong
0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2019-10-15 10:11 UTC (permalink / raw)
To: guaneryu; +Cc: fstests, linux-f2fs-devel, 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}'
And in addition, using more simple command "stat -c %s" instead.
- adjust common/defrag, generic/275 and generic/315 to use it
- remove unused _filesize in generic/013
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
v2:
- As suggested by Eryu, let's use "stat -c %s" instead of original
complicated one.
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(-)
diff --git a/common/defrag b/common/defrag
index 1381a4dd..1769013b 100644
--- a/common/defrag
+++ b/common/defrag
@@ -145,7 +145,7 @@ _defrag()
STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
if [ $FSTYP == "f2fs" ]; then
- local filesize=`ls -l $1 | $AWK_PROG '{print $5}'`
+ local filesize=`_get_filesize $1`
$DEFRAG_PROG 0 $filesize $1 >> $seqres.full 2>&1
else
$DEFRAG_PROG -v $1 >> $seqres.full 2>&1
diff --git a/common/rc b/common/rc
index cfaabf10..bd388a4c 100644
--- a/common/rc
+++ b/common/rc
@@ -165,6 +165,11 @@ if [ ! -z "$REPORT_LIST" ]; then
_assert_report_list
fi
+_get_filesize()
+{
+ echo `stat -c %s $1`
+}
+
_mount()
{
$MOUNT_PROG `_mount_ops_filter $*`
diff --git a/tests/generic/013 b/tests/generic/013
index 9e533ee8..bc596102 100755
--- a/tests/generic/013
+++ b/tests/generic/013
@@ -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
diff --git a/tests/generic/275 b/tests/generic/275
index a934c19c..adc82856 100755
--- a/tests/generic/275
+++ b/tests/generic/275
@@ -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."
diff --git a/tests/generic/315 b/tests/generic/315
index fd49b579..808d7d74 100755
--- a/tests/generic/315
+++ b/tests/generic/315
@@ -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
--
2.18.0.rc1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] common/rc: generalize _get_filesize()
2019-10-15 10:11 [PATCH v2] common/rc: generalize _get_filesize() Chao Yu
@ 2019-10-15 18:17 ` Darrick J. Wong
2019-10-16 2:49 ` Chao Yu
0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2019-10-15 18:17 UTC (permalink / raw)
To: Chao Yu; +Cc: guaneryu, fstests, linux-f2fs-devel
On Tue, Oct 15, 2019 at 06:11:49PM +0800, Chao Yu wrote:
> 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}'
>
> And in addition, using more simple command "stat -c %s" instead.
>
> - adjust common/defrag, generic/275 and generic/315 to use it
> - remove unused _filesize in generic/013
>
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
> v2:
> - As suggested by Eryu, let's use "stat -c %s" instead of original
> complicated one.
>
> 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(-)
>
> diff --git a/common/defrag b/common/defrag
> index 1381a4dd..1769013b 100644
> --- a/common/defrag
> +++ b/common/defrag
> @@ -145,7 +145,7 @@ _defrag()
> STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
>
> if [ $FSTYP == "f2fs" ]; then
> - local filesize=`ls -l $1 | $AWK_PROG '{print $5}'`
> + local filesize=`_get_filesize $1`
> $DEFRAG_PROG 0 $filesize $1 >> $seqres.full 2>&1
> else
> $DEFRAG_PROG -v $1 >> $seqres.full 2>&1
> diff --git a/common/rc b/common/rc
> index cfaabf10..bd388a4c 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -165,6 +165,11 @@ if [ ! -z "$REPORT_LIST" ]; then
> _assert_report_list
> fi
>
> +_get_filesize()
> +{
> + echo `stat -c %s $1`
Why bother enclosing this in backticks? Wouldn't this also work?
_get_filesize()
{
stat -c %s "$1"
}
--D
> +}
> +
> _mount()
> {
> $MOUNT_PROG `_mount_ops_filter $*`
> diff --git a/tests/generic/013 b/tests/generic/013
> index 9e533ee8..bc596102 100755
> --- a/tests/generic/013
> +++ b/tests/generic/013
> @@ -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
> diff --git a/tests/generic/275 b/tests/generic/275
> index a934c19c..adc82856 100755
> --- a/tests/generic/275
> +++ b/tests/generic/275
> @@ -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."
>
> diff --git a/tests/generic/315 b/tests/generic/315
> index fd49b579..808d7d74 100755
> --- a/tests/generic/315
> +++ b/tests/generic/315
> @@ -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
> --
> 2.18.0.rc1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] common/rc: generalize _get_filesize()
2019-10-15 18:17 ` Darrick J. Wong
@ 2019-10-16 2:49 ` Chao Yu
0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2019-10-16 2:49 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: guaneryu, fstests, linux-f2fs-devel
On 2019/10/16 2:17, Darrick J. Wong wrote:
> On Tue, Oct 15, 2019 at 06:11:49PM +0800, Chao Yu wrote:
>> 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}'
>>
>> And in addition, using more simple command "stat -c %s" instead.
>>
>> - adjust common/defrag, generic/275 and generic/315 to use it
>> - remove unused _filesize in generic/013
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>> v2:
>> - As suggested by Eryu, let's use "stat -c %s" instead of original
>> complicated one.
>>
>> 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(-)
>>
>> diff --git a/common/defrag b/common/defrag
>> index 1381a4dd..1769013b 100644
>> --- a/common/defrag
>> +++ b/common/defrag
>> @@ -145,7 +145,7 @@ _defrag()
>> STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
>>
>> if [ $FSTYP == "f2fs" ]; then
>> - local filesize=`ls -l $1 | $AWK_PROG '{print $5}'`
>> + local filesize=`_get_filesize $1`
>> $DEFRAG_PROG 0 $filesize $1 >> $seqres.full 2>&1
>> else
>> $DEFRAG_PROG -v $1 >> $seqres.full 2>&1
>> diff --git a/common/rc b/common/rc
>> index cfaabf10..bd388a4c 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -165,6 +165,11 @@ if [ ! -z "$REPORT_LIST" ]; then
>> _assert_report_list
>> fi
>>
>> +_get_filesize()
>> +{
>> + echo `stat -c %s $1`
>
> Why bother enclosing this in backticks? Wouldn't this also work?
>
> _get_filesize()
> {
> stat -c %s "$1"
> }
This can work, thanks for the comments, I've updated it in v3.
Thanks,
>
> --D
>
>> +}
>> +
>> _mount()
>> {
>> $MOUNT_PROG `_mount_ops_filter $*`
>> diff --git a/tests/generic/013 b/tests/generic/013
>> index 9e533ee8..bc596102 100755
>> --- a/tests/generic/013
>> +++ b/tests/generic/013
>> @@ -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
>> diff --git a/tests/generic/275 b/tests/generic/275
>> index a934c19c..adc82856 100755
>> --- a/tests/generic/275
>> +++ b/tests/generic/275
>> @@ -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."
>>
>> diff --git a/tests/generic/315 b/tests/generic/315
>> index fd49b579..808d7d74 100755
>> --- a/tests/generic/315
>> +++ b/tests/generic/315
>> @@ -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
>> --
>> 2.18.0.rc1
>>
> .
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-16 2:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-15 10:11 [PATCH v2] common/rc: generalize _get_filesize() Chao Yu
2019-10-15 18:17 ` Darrick J. Wong
2019-10-16 2:49 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).