From 527e21ec4de92870f1b4c88b9465dc010e926260 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 27 Apr 2013 23:15:44 +0200 Subject: [PATCH] tests: Tests that override EXIT (0) trap need to cleanup themselves. Since trap handlers don't nest tests that install their own EXIT (0) trap handler need to cleanup themselves. Add an exit_cleanup helper function to test-subr.sh that can be used by run-native-test.sh to exit cleanly. Signed-off-by: Mark Wielaard --- tests/ChangeLog | 7 +++++++ tests/run-native-test.sh | 11 +++++++++-- tests/test-subr.sh | 10 ++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/ChangeLog b/tests/ChangeLog index e6722dace..6f1af3dc5 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +2013-04-27 Mark Wielaard + + * test-subr.sh (exit_cleanup): New function. + (trap): Use exit_cleanup as argument. + * run-native-test.sh (native_exit): New function. + (trap): For EXIT (0) use native_exit as argument. + 2013-04-27 Mark Wielaard * update1.c (main): Use unique tempfile name and unlink file. diff --git a/tests/run-native-test.sh b/tests/run-native-test.sh index b543922c3..d19007f2f 100755 --- a/tests/run-native-test.sh +++ b/tests/run-native-test.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005, 2006 Red Hat, Inc. +# Copyright (C) 2005, 2006, 2013 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -45,7 +45,14 @@ native_cleanup() test_cleanup } -trap native_cleanup 0 1 2 15 +native_exit() +{ + native_cleanup + exit_cleanup +} + +trap native_cleanup 1 2 15 +trap native_exit 0 for cc in "$HOSTCC" "$HOST_CC" cc gcc "$CC"; do test "x$cc" != x || continue diff --git a/tests/test-subr.sh b/tests/test-subr.sh index 7bf1f71d3..3ef218c66 100644 --- a/tests/test-subr.sh +++ b/tests/test-subr.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005-2012 Red Hat, Inc. +# Copyright (C) 2005-2013 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -31,7 +31,13 @@ pushd "$test_dir" > /dev/null #export LC_ALL remove_files= -trap 'rm -f $remove_files; popd > /dev/null; rmdir $test_dir' 0 + +# Tests that trap EXIT (0) themselves should call this explicitly. +exit_cleanup() +{ + rm -f $remove_files; popd > /dev/null; rmdir $test_dir +} +trap exit_cleanup 0 tempfiles() { -- 2.47.2