Skip to contentSkip to conversation

tests: replace perl usage with shell built-in

PATCH Applied Andreas Dilger 2 participants 4 messages Jul 19, 2020 – Oct 2, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: replace perl usage with shell built-in

A couple of tests use perl only for generating a string of N characters long. Instead of requiring perl to run a few tests, use shell built-in commands and don't repeatedly run a separate subshell just to get a string of characters.

---
 tests/d_xattr_sorting/script    |  2 +-
 tests/f_badsymlinks2/mkimage.sh |  4 +++-
 tests/f_create_symlinks/script  | 12 ++++++------
 util/gen-sample-fs              |  4 +++-
 4 files changed, 13 insertions(+), 9 deletions(-)
tests/d_xattr_sorting/script +1 -1
index 866611502012..65c74840f517 100644
@@ -22,7 +22,7 @@ echo Exit status is $status >> $OUT.new
 
 B=$(mktemp ${TMPDIR:-/tmp}/b.XXXXXX)
 
-perl -e 'print "x" x 256;' > $B
+printf 'x%.0s' {1..256} > $B
 
 echo "ea_set -f /tmp/b / security.SMEG64" >> $OUT.new
 $DEBUGFS -w -R "ea_set -f $B / security.SMEG64" $TMPFILE >> $OUT.new 2>&1
tests/f_badsymlinks2/mkimage.sh +3 -1
index 6bbf020de0d7..297633790bee 100755
@@ -18,10 +18,12 @@ do_tune2fs() {
 	mount image mnt
 }
 
+A=$(printf 'A%.0s' {1..4096})
 symlink() {
 	local len=$1
 	local src=$2
-	local target=$(perl -e 'print "A" x '$len)
+	local target=${A:0:$len}
+
 	ln -s $target $src
 	stat -c %i $src
 }
tests/f_create_symlinks/script +6 -6
index 169f58dbed2f..8906f3d65653 100644
@@ -15,22 +15,22 @@ fi
 dd if=/dev/zero of=$TMPFILE bs=1k count=512 > /dev/null 2>&1
 
 echo mke2fs -q -F -o Linux -b 1024 -g 256 -O inline_data,extents -I 256 test.img 1024 > $OUT.new
-$MKE2FS -q -F -o Linux -b 1024 -g 256 -O inline_data,extents -I 256 $TMPFILE 1024 >> $OUT 2>&1
+$MKE2FS -q -F -o Linux -b 1024 -g 256 -O inline_data,extents -I 256 $TMPFILE 1024 >> $OUT.new 2>&1
 
 $FSCK $FSCK_OPT  -N test_filesys $TMPFILE >> $OUT.new 2>&1
 status=$?
 echo Exit status is $status >> $OUT.new
 
+B=$(printf 'x%.0s' {1..1500})
 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.new
-	$DEBUGFS -w -R "symlink /l_$i $(perl -e "print 'x' x $i;")" $TMPFILE \
-		 2>&1 | sed -f $cmd_dir/filter.sed >> $OUT.new
+	echo "debugfs -R \"symlink /l_$i ${B:0:i}\" test.img" >> $OUT.new
+	$DEBUGFS -w -R "symlink /l_$i ${B:0:i}" $TMPFILE >> $OUT.new 2>&1
 done
+unset B
 
 for i in 30 60 70 500 1023 1024 1500; do
 	echo "debugfs -R \"stat /l_$i\" test.img" >> $OUT.new
-	$DEBUGFS -R "stat /l_$i" $TMPFILE 2>&1 | \
-		 grep -v "time: " >> $OUT.new
+	$DEBUGFS -R "stat /l_$i" $TMPFILE 2>&1 | grep -v "time: " >> $OUT.new
 done
 
 $FSCK $FSCK_OPT  -N test_filesys $TMPFILE >> $OUT.new 2>&1
util/gen-sample-fs +3 -1
index 8e139160fd01..290da33f51c3 100755
@@ -7,8 +7,10 @@ cp /dev/null $FS
 mke2fs -q -t ext4 -O inline_data,^has_journal -I 256 -b 4096 -N 64 $FS 256
 mount -t ext4 $FS $MNT
 ln -s symlink_data $MNT/symlink
+
+L=$(printf 'x%.0s' {1..1024})
 for i in 30 70 500 1023 1024; do
-	ln -s /$(perl -e "print 'x' x $i;") $MNT/l_$i
+	ln -s /${L:0:$i} $MNT/l_$i
 done
 touch $MNT/acl
 setfacl -m u:daemon:r $MNT/acl
Signature · 1 line
2.14.3 (Apple Git-98)
#1 lore raw
Quoted 6 lines · Andreas Dilger

A couple of tests use perl only for generating a string of N characters long. Instead of requiring perl to run a few tests, use shell built-in commands and don't repeatedly run a separate subshell just to get a string of characters.

Thanks, applied.

- Ted

#2 lore raw
Quoted 9 lines · Theodore Y. Ts'o
Quoted 6 lines · Andreas Dilger

A couple of tests use perl only for generating a string of N characters long. Instead of requiring perl to run a few tests, use shell built-in commands and don't repeatedly run a separate subshell just to get a string of characters. h

Thanks, applied.

.... and I have to revert the patch. It's using a non-standard shell construction which fails on strict POSIX compliant shells, such as dash.

- Ted

#3 lore raw
Quoted 10 lines · Theodore Y. Ts'o
Quoted 8 lines · Theodore Y. Ts'o
Quoted 6 lines · Andreas Dilger

A couple of tests use perl only for generating a string of N characters long. Instead of requiring perl to run a few tests, use shell built-in commands and don't repeatedly run a separate subshell just to get a string of characters. h

Quoted 5 lines
Quoted 1 line

Thanks, applied.

.... and I have to revert the patch. It's using a non-standard shell construction which fails on strict POSIX compliant shells, such as dash.

Could you please point out which constructs it is unhappy with? I had an earlier version of the patch using a different mechanism, but then updated it after feedback from Lukas.

Cheers, Andreas