This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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 <mjw@redhat.com>
---
 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 dfee832..1e80d7a 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,12 @@
 2013-04-27  Mark Wielaard  <mjw@redhat.com>
 
+	* 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  <mjw@redhat.com>
+
 	* run-alldts.sh: Add testfile-alldts to tempfiles.
 	* run-elf_cntl_gelf_getshdr.sh: Add test_shdr.out to tempfiles.
 	* run-macro-test.sh: Add readelf.macros.out to tempfiles.
diff --git a/tests/run-native-test.sh b/tests/run-native-test.sh
index b543922..d19007f 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 7bf1f71..3ef218c 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()
 {
-- 
1.8.1.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]