Browse Source

Use 'trap' builtin to clean up temporaries in test scripts

Some of the test scripts create temporary files, which we remove at the
end.  Except that we usually forgot to remove them on some exit paths. To
avoid this problem in future, this modifies the scripts to use the shell's
trap 0 functionality to automatically remove the temporaries on any exit.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 13 years ago committed by Jon Loeliger
parent
commit
2ca83614e7
  1. 6
      tests/dtc-checkfails.sh
  2. 10
      tests/fdtget-runtest.sh
  3. 10
      tests/fdtput-runtest.sh

6
tests/dtc-checkfails.sh

@ -10,9 +10,9 @@ for x; do @@ -10,9 +10,9 @@ for x; do
CHECKS="$CHECKS $x"
done

LOG="tmp.log.$$"

LOG=tmp.log.$$
rm -f $LOG
trap "rm -f $LOG" 0

verbose_run_log "$LOG" $VALGRIND "$DTC" -o /dev/null "$@"
ret="$?"
@ -28,6 +28,4 @@ for c in $CHECKS; do @@ -28,6 +28,4 @@ for c in $CHECKS; do
fi
done

rm -f $LOG

PASS

10
tests/fdtget-runtest.sh

@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@

. ./tests.sh

LOG="tmp.log.$$"
EXPECT="tmp.expect.$$"

rm -f $LOG
LOG=tmp.log.$$
EXPECT=tmp.expect.$$
rm -f $LOG $EXPECT
trap "rm -f $LOG $EXPECT" 0

expect="$1"
echo "$expect" >$EXPECT
@ -26,8 +26,6 @@ fi @@ -26,8 +26,6 @@ fi
diff $EXPECT $LOG
ret="$?"

rm -f $LOG $EXPECT

if [ "$ret" -eq 0 ]; then
PASS
else

10
tests/fdtput-runtest.sh

@ -8,10 +8,10 @@ @@ -8,10 +8,10 @@

. ./tests.sh

LOG="tmp.log.$$"
EXPECT="tmp.expect.$$"

rm -f $LOG
LOG=tmp.log.$$
EXPECT=tmp.expect.$$
rm -f $LOG $EXPECT
trap "rm -f $LOG $EXPECT" 0

expect="$1"
echo "$expect" >$EXPECT
@ -46,8 +46,6 @@ fi @@ -46,8 +46,6 @@ fi
diff $EXPECT $LOG
ret="$?"

rm -f $LOG $EXPECT

if [ "$ret" -eq 0 ]; then
PASS
else

Loading…
Cancel
Save