Skip to content

Commit

Permalink
torture: Use mktemp instead of guessing at unique names
Browse files Browse the repository at this point in the history
This commit drags the rcutorture scripting kicking and screaming into the
twenty-first century by making use of the BSD-derived mktemp command to
create temporary files and directories.  In happy contrast to many of its
ill-behaved predecessors, mktemp seems to actually work reasonably reliably!

Signed-off-by: Paul E. McKenney <[email protected]>
  • Loading branch information
paulmckrcu committed Oct 18, 2022
1 parent 50527f7 commit c211ae9
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 35 deletions.
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/config2csv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ else
fi
scenarios="`echo $scenariosarg | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"

T=/tmp/config2latex.sh.$$
T=`mktemp -d /tmp/config2latex.sh.XXXXXX`
trap 'rm -rf $T' 0
mkdir $T

cat << '---EOF---' >> $T/p.awk
END {
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/config_override.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ else
exit 1
fi

T=${TMPDIR-/tmp}/config_override.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/config_override.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

sed < $override -e 's/^/grep -v "/' -e 's/=.*$/="/' |
awk '
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/configcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#
# Authors: Paul E. McKenney <[email protected]>

T=${TMPDIR-/tmp}/abat-chk-config.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/configcheck.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

cat $1 > $T/.config

Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/configinit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
#
# Authors: Paul E. McKenney <[email protected]>

T=${TMPDIR-/tmp}/configinit.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/configinit.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

# Capture config spec file.

Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/kvm-again.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
scriptname=$0
args="$*"

T=${TMPDIR-/tmp}/kvm-again.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm-again.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

if ! test -d tools/testing/selftests/rcutorture/bin
then
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/kvm-assign-cpus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#
# Usage: kvm-assign-cpus.sh /path/to/sysfs

T=/tmp/kvm-assign-cpus.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm-assign-cpus.sh.XXXXXX`"
trap 'rm -rf $T' 0 2
mkdir $T

sysfsdir=${1-/sys/devices/system/node}
if ! cd "$sysfsdir" > $T/msg 2>&1
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/kvm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ then
fi
resdir=${2}

T=${TMPDIR-/tmp}/test-linux.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm-build.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

cp ${config_template} $T/config
cat << ___EOF___ >> $T/config
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/kvm-end-run-stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ then
exit 1
fi

T=${TMPDIR-/tmp}/kvm-end-run-stats.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm-end-run-stats.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
PATH=${RCUTORTURE}/bin:$PATH; export PATH
Expand Down
13 changes: 6 additions & 7 deletions tools/testing/selftests/rcutorture/bin/kvm-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ fi
shift

# Pathnames:
# T: /tmp/kvm-remote.sh.$$
# resdir: /tmp/kvm-remote.sh.$$/res
# rundir: /tmp/kvm-remote.sh.$$/res/$ds ("-remote" suffix)
# T: /tmp/kvm-remote.sh.NNNNNN where "NNNNNN" is set by mktemp
# resdir: /tmp/kvm-remote.sh.NNNNNN/res
# rundir: /tmp/kvm-remote.sh.NNNNNN/res/$ds ("-remote" suffix)
# oldrun: `pwd`/tools/testing/.../res/$otherds
#
# Pathname segments:
# TD: kvm-remote.sh.$$
# TD: kvm-remote.sh.NNNNNN
# ds: yyyy.mm.dd-hh.mm.ss-remote

TD=kvm-remote.sh.$$
T=${TMPDIR-/tmp}/$TD
T="`mktemp -d ${TMPDIR-/tmp}/kvm-remote.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T
TD="`basename "$T"`"

resdir="$T/res"
ds=`date +%Y.%m.%d-%H.%M.%S`-remote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
#
# Authors: Paul E. McKenney <[email protected]>

T=${TMPDIR-/tmp}/kvm-test-1-run-batch.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm-test-1-run-batch.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

echo ---- Running batch $*
# Check arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
#
# Authors: Paul E. McKenney <[email protected]>

T=${TMPDIR-/tmp}/kvm-test-1-run-qemu.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm-test-1-run-qemu.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

resdir="$1"
if ! test -d "$resdir"
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
#
# Authors: Paul E. McKenney <[email protected]>

T=${TMPDIR-/tmp}/kvm-test-1-run.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm-test-1-run.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

. functions.sh
. $CONFIGFRAG/ver_functions.sh
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/kvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
scriptname=$0
args="$*"

T=${TMPDIR-/tmp}/kvm.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/kvm.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

cd `dirname $scriptname`/../../../../../

Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/parse-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

F=$1
title=$2
T=${TMPDIR-/tmp}/parse-build.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/parse-build.sh.XXXXXX`"
trap 'rm -rf $T' 0
mkdir $T

. functions.sh

Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/rcutorture/bin/torture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ ds="`date +%Y.%m.%d-%H.%M.%S`-torture"
startdate="`date`"
starttime="`get_starttime`"

T=/tmp/torture.sh.$$
T="`mktemp -d ${TMPDIR-/tmp}/torture.sh.XXXXXX`"
trap 'rm -rf $T' 0 2
mkdir $T

echo " --- " $scriptname $args | tee -a $T/log
echo " --- Results directory: " $ds | tee -a $T/log
Expand Down

0 comments on commit c211ae9

Please sign in to comment.