diff mbox series

[04/10] tests: replace perl usage with shell built-in

Message ID 1525235166-6448-5-git-send-email-adilger@dilger.ca
State Accepted, archived
Headers show
Series test cleanups and minor improvements | expand

Commit Message

Andreas Dilger May 2, 2018, 4:26 a.m. UTC
A couple of tests use perl only for generating a string of N characters
long.  Instead, expand an environment variable to the required length.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
---
 tests/d_xattr_sorting/script   | 3 ++-
 tests/f_create_symlinks/script | 8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

Comments

Lukas Czerner May 4, 2018, 9:32 a.m. UTC | #1
On Tue, May 01, 2018 at 10:26:00PM -0600, Andreas Dilger wrote:
> A couple of tests use perl only for generating a string of N characters
> long.  Instead, expand an environment variable to the required length.
> 
> Signed-off-by: Andreas Dilger <adilger@dilger.ca>
> ---
>  tests/d_xattr_sorting/script   | 3 ++-
>  tests/f_create_symlinks/script | 8 +++++---
>  2 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/d_xattr_sorting/script b/tests/d_xattr_sorting/script
> index a599f3c..dc92751 100644
> --- a/tests/d_xattr_sorting/script
> +++ b/tests/d_xattr_sorting/script
> @@ -22,7 +22,8 @@ echo Exit status is $status >> $OUT
>  
>  B=$(mktemp ${TMPDIR:-/tmp}/b.XXXXXX)
>  
> -perl -e 'print "x" x 256;' > $B
> +F="xxxxxxxx"; F+=$F; F+=$F; F+=$F; F+=$F; F+=$F
> +echo "$F" | dd of=$B bs=256 count=1 2> /dev/null

We can use this instead

printf 'x%.0s' {1..256}

-Lukas

>  
>  echo "ea_set -f /tmp/b / security.SMEG64" > $OUT.new
>  $DEBUGFS -w -R "ea_set -f $B / security.SMEG64" $TMPFILE >> $OUT.new 2>&1
> diff --git a/tests/f_create_symlinks/script b/tests/f_create_symlinks/script
> index 7d712f5..b7c22d3 100644
> --- a/tests/f_create_symlinks/script
> +++ b/tests/f_create_symlinks/script
> @@ -26,11 +26,13 @@ echo Exit status is $status >> $OUT.new
>  sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new >> $OUT
>  rm -f $OUT.new
>  
> +B="xxxxxxx"; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B
>  for i in 30 60 70 500 1023 1024 1500; do
> -	echo "debugfs -R \"symlink /l_$i $(perl -e "print 'x' x $i;")\" test.img" >> $OUT
> -	$DEBUGFS -w -R "symlink /l_$i $(perl -e "print 'x' x $i;")" $TMPFILE \
> -		 2>&1 | sed -f $cmd_dir/filter.sed >> $OUT
> +	echo "debugfs -R \"symlink /l_$i ${B:1:i}\" test.img" >> $OUT
> +	$DEBUGFS -w -R "symlink /l_$i ${B:1:i}" $TMPFILE 2>&1 |
> +		sed -f $cmd_dir/filter.sed >> $OUT
>  done
> +unset B
>  
>  for i in 30 60 70 500 1023 1024 1500; do
>  	echo "debugfs -R \"stat /l_$i\" test.img" >> $OUT
> -- 
> 1.8.0
>
Andreas Dilger May 4, 2018, 6:42 p.m. UTC | #2
On May 4, 2018, at 3:32 AM, Lukas Czerner <lczerner@redhat.com> wrote:
> 
> On Tue, May 01, 2018 at 10:26:00PM -0600, Andreas Dilger wrote:
>> A couple of tests use perl only for generating a string of N characters
>> long.  Instead, expand an environment variable to the required length.
>> 
>> Signed-off-by: Andreas Dilger <adilger@dilger.ca>
>> ---
>> tests/d_xattr_sorting/script   | 3 ++-
>> tests/f_create_symlinks/script | 8 +++++---
>> 2 files changed, 7 insertions(+), 4 deletions(-)
>> 
>> diff --git a/tests/d_xattr_sorting/script b/tests/d_xattr_sorting/script
>> index a599f3c..dc92751 100644
>> --- a/tests/d_xattr_sorting/script
>> +++ b/tests/d_xattr_sorting/script
>> @@ -22,7 +22,8 @@ echo Exit status is $status >> $OUT
>> 
>> B=$(mktemp ${TMPDIR:-/tmp}/b.XXXXXX)
>> 
>> -perl -e 'print "x" x 256;' > $B
>> +F="xxxxxxxx"; F+=$F; F+=$F; F+=$F; F+=$F; F+=$F
>> +echo "$F" | dd of=$B bs=256 count=1 2> /dev/null
> 
> We can use this instead
> 
> printf 'x%.0s' {1..256}

Sure, I don't think it makes a huge difference either way, since this is
only ever run by developers.  The main goal is to get rid of perl usage.
The printf command/built-in should be available in every shell environment.

Cheers, Andreas

>> 
>> echo "ea_set -f /tmp/b / security.SMEG64" > $OUT.new
>> $DEBUGFS -w -R "ea_set -f $B / security.SMEG64" $TMPFILE >> $OUT.new 2>&1
>> diff --git a/tests/f_create_symlinks/script b/tests/f_create_symlinks/script
>> index 7d712f5..b7c22d3 100644
>> --- a/tests/f_create_symlinks/script
>> +++ b/tests/f_create_symlinks/script
>> @@ -26,11 +26,13 @@ echo Exit status is $status >> $OUT.new
>> sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new >> $OUT
>> rm -f $OUT.new
>> 
>> +B="xxxxxxx"; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B
>> for i in 30 60 70 500 1023 1024 1500; do
>> -	echo "debugfs -R \"symlink /l_$i $(perl -e "print 'x' x $i;")\" test.img" >> $OUT
>> -	$DEBUGFS -w -R "symlink /l_$i $(perl -e "print 'x' x $i;")" $TMPFILE \
>> -		 2>&1 | sed -f $cmd_dir/filter.sed >> $OUT
>> +	echo "debugfs -R \"symlink /l_$i ${B:1:i}\" test.img" >> $OUT
>> +	$DEBUGFS -w -R "symlink /l_$i ${B:1:i}" $TMPFILE 2>&1 |
>> +		sed -f $cmd_dir/filter.sed >> $OUT
>> done
>> +unset B
>> 
>> for i in 30 60 70 500 1023 1024 1500; do
>> 	echo "debugfs -R \"stat /l_$i\" test.img" >> $OUT
>> --
>> 1.8.0
>> 


Cheers, Andreas
Theodore Ts'o June 22, 2018, 4:32 p.m. UTC | #3
On Tue, May 01, 2018 at 10:26:00PM -0600, Andreas Dilger wrote:
> A couple of tests use perl only for generating a string of N characters
> long.  Instead, expand an environment variable to the required length.
> 
> Signed-off-by: Andreas Dilger <adilger@dilger.ca>

Thanks, applied, with the following fix-up.

						- Ted

diff --git a/tests/f_detect_junk/script b/tests/f_detect_junk/script
index ab2a38cb0..12cfdfdff 100644
--- a/tests/f_detect_junk/script
+++ b/tests/f_detect_junk/script
@@ -2,6 +2,7 @@
 
 if [ "$(grep -c 'define HAVE_MAGIC_H' ../lib/config.h)" -eq 0 ]; then
 	echo "$test_name: skipped (no magic)"
+	exit 0
 fi
 
 FSCK_OPT=-fn
Theodore Ts'o June 22, 2018, 4:35 p.m. UTC | #4
On Fri, May 04, 2018 at 11:32:12AM +0200, Lukas Czerner wrote:
> 
> We can use this instead
> 
> printf 'x%.0s' {1..256}
>

Using printf is a bashism, so it fails on dash, and I suspect might be
problematic on folks trying to build e2fsprogs on FreeBSD.

Cheers,

					- Ted
diff mbox series

Patch

diff --git a/tests/d_xattr_sorting/script b/tests/d_xattr_sorting/script
index a599f3c..dc92751 100644
--- a/tests/d_xattr_sorting/script
+++ b/tests/d_xattr_sorting/script
@@ -22,7 +22,8 @@  echo Exit status is $status >> $OUT
 
 B=$(mktemp ${TMPDIR:-/tmp}/b.XXXXXX)
 
-perl -e 'print "x" x 256;' > $B
+F="xxxxxxxx"; F+=$F; F+=$F; F+=$F; F+=$F; F+=$F
+echo "$F" | dd of=$B bs=256 count=1 2> /dev/null
 
 echo "ea_set -f /tmp/b / security.SMEG64" > $OUT.new
 $DEBUGFS -w -R "ea_set -f $B / security.SMEG64" $TMPFILE >> $OUT.new 2>&1
diff --git a/tests/f_create_symlinks/script b/tests/f_create_symlinks/script
index 7d712f5..b7c22d3 100644
--- a/tests/f_create_symlinks/script
+++ b/tests/f_create_symlinks/script
@@ -26,11 +26,13 @@  echo Exit status is $status >> $OUT.new
 sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new >> $OUT
 rm -f $OUT.new
 
+B="xxxxxxx"; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B; B+=$B
 for i in 30 60 70 500 1023 1024 1500; do
-	echo "debugfs -R \"symlink /l_$i $(perl -e "print 'x' x $i;")\" test.img" >> $OUT
-	$DEBUGFS -w -R "symlink /l_$i $(perl -e "print 'x' x $i;")" $TMPFILE \
-		 2>&1 | sed -f $cmd_dir/filter.sed >> $OUT
+	echo "debugfs -R \"symlink /l_$i ${B:1:i}\" test.img" >> $OUT
+	$DEBUGFS -w -R "symlink /l_$i ${B:1:i}" $TMPFILE 2>&1 |
+		sed -f $cmd_dir/filter.sed >> $OUT
 done
+unset B
 
 for i in 30 60 70 500 1023 1024 1500; do
 	echo "debugfs -R \"stat /l_$i\" test.img" >> $OUT