[PATCH wayland] tests: disable coredumps on sanity-test

Pekka Paalanen ppaalanen at gmail.com
Wed Feb 14 12:38:44 UTC 2018


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

SEGV and ABRT by default cause a core dump, which may create a file,
launch crash handlers, and so on. sanity-test has 21 processes that
are expected to crash like this. Disable core dumps on them all.

I counted 21 entries in coredumpctl list, while only 16 functions needed
patching. After this patch no entries appear in coredumpctl list.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 configure.ac         |  3 ++-
 tests/sanity-test.c  | 18 ++++++++++++++++++
 tests/test-helpers.c | 30 ++++++++++++++++++++++++++++++
 tests/test-runner.h  |  3 +++
 4 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 2542243..b09fb7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,8 @@ if test "x$GCC" = "xyes"; then
 fi
 AC_SUBST(GCC_CFLAGS)
 
-AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate])
+AC_CHECK_HEADERS([sys/prctl.h])
+AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
 AC_ARG_ENABLE([libraries],
 	      [AC_HELP_STRING([--disable-libraries],
diff --git a/tests/sanity-test.c b/tests/sanity-test.c
index 7a93da3..66ca16f 100644
--- a/tests/sanity-test.c
+++ b/tests/sanity-test.c
@@ -53,11 +53,13 @@ FAIL_TEST(exit_failure)
 
 FAIL_TEST(fail_abort)
 {
+	test_disable_coredumps();
 	abort();
 }
 
 FAIL_TEST(fail_wl_abort)
 {
+	test_disable_coredumps();
 	wl_abort("Abort the program\n");
 }
 
@@ -68,11 +70,13 @@ FAIL_TEST(fail_kill)
 
 FAIL_TEST(fail_segv)
 {
+	test_disable_coredumps();
 	* (char **) 0 = "Goodbye, world";
 }
 
 FAIL_TEST(sanity_assert)
 {
+	test_disable_coredumps();
 	/* must fail */
 	assert(0);
 }
@@ -87,6 +91,7 @@ FAIL_TEST(sanity_malloc_direct)
 	assert(p);	/* assert that we got memory, also prevents
 			 * the malloc from getting optimized away. */
 	free(NULL);	/* NULL must not be counted */
+	test_disable_coredumps();
 }
 
 TEST(disable_leak_checks)
@@ -114,6 +119,8 @@ FAIL_TEST(sanity_malloc_indirect)
 	wl_array_add(&array, 14);
 
 	/* not freeing array, must leak */
+
+	test_disable_coredumps();
 }
 
 FAIL_TEST(tc_client_memory_leaks)
@@ -121,6 +128,7 @@ FAIL_TEST(tc_client_memory_leaks)
 	struct display *d = display_create();
 	client_create_noarg(d, sanity_malloc_direct);
 	display_run(d);
+	test_disable_coredumps();
 	display_destroy(d);
 }
 
@@ -129,6 +137,7 @@ FAIL_TEST(tc_client_memory_leaks2)
 	struct display *d = display_create();
 	client_create_noarg(d, sanity_malloc_indirect);
 	display_run(d);
+	test_disable_coredumps();
 	display_destroy(d);
 }
 
@@ -141,6 +150,8 @@ FAIL_TEST(sanity_fd_leak)
 	/* leak 2 file descriptors */
 	if (pipe(fd) < 0)
 		exit(EXIT_SUCCESS); /* failed to fail */
+
+	test_disable_coredumps();
 }
 
 FAIL_TEST(sanity_fd_leak_exec)
@@ -152,6 +163,7 @@ FAIL_TEST(sanity_fd_leak_exec)
 	if (pipe(fd) < 0)
 		exit(EXIT_SUCCESS); /* failed to fail */
 
+	test_disable_coredumps();
 	exec_fd_leak_check(nr_fds);
 }
 
@@ -212,6 +224,7 @@ FAIL_TEST(tc_client_fd_leaks)
 	client_create_noarg(d, sanity_fd_leak);
 	display_run(d);
 
+	test_disable_coredumps();
 	display_destroy(d);
 }
 
@@ -222,12 +235,14 @@ FAIL_TEST(tc_client_fd_leaks_exec)
 	client_create_noarg(d, sanity_fd_leak);
 	display_run(d);
 
+	test_disable_coredumps();
 	display_destroy(d);
 }
 
 FAIL_TEST(timeout_tst)
 {
 	test_set_timeout(1);
+	test_disable_coredumps();
 	/* test should reach timeout */
 	test_sleep(2);
 }
@@ -247,6 +262,7 @@ FAIL_TEST(timeout_reset_tst)
 	test_set_timeout(10);
 	test_set_timeout(1);
 
+	test_disable_coredumps();
 	/* test should fail on timeout */
 	test_sleep(2);
 }
@@ -265,6 +281,7 @@ FAIL_TEST(tc_timeout_tst)
 	struct display *d = display_create();
 	client_create_noarg(d, timeout_tst);
 	display_run(d);
+	test_disable_coredumps();
 	display_destroy(d);
 }
 
@@ -273,6 +290,7 @@ FAIL_TEST(tc_timeout2_tst)
 	struct display *d = display_create();
 	client_create_noarg(d, timeout_reset_tst);
 	display_run(d);
+	test_disable_coredumps();
 	display_destroy(d);
 }
 
diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index a990003..b2189d8 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -23,12 +23,20 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #include <assert.h>
 #include <errno.h>
 #include <dirent.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
 
 #include "test-runner.h"
 
@@ -97,3 +105,25 @@ test_sleep(unsigned int sec)
 
 	assert(nanosleep(&ts, NULL) == 0);
 }
+
+/** Try to disable coredumps
+ *
+ * Useful for tests that crash on purpose, to avoid creating a core file
+ * or launching an application crash handler service or cluttering coredumpctl.
+ *
+ * NOTE: Calling this may make the process undebuggable.
+ */
+void
+test_disable_coredumps(void)
+{
+	struct rlimit r;
+
+	if (getrlimit(RLIMIT_CORE, &r) == 0) {
+		r.rlim_cur = 0;
+		setrlimit(RLIMIT_CORE, &r);
+	}
+
+#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
+	prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
+#endif
+}
diff --git a/tests/test-runner.h b/tests/test-runner.h
index 81ed034..9c47a2b 100644
--- a/tests/test-runner.h
+++ b/tests/test-runner.h
@@ -86,6 +86,9 @@ test_usleep(useconds_t);
 void
 test_sleep(unsigned int);
 
+void
+test_disable_coredumps(void);
+
 #define DISABLE_LEAK_CHECKS			\
 	do {					\
 		extern int leak_check_enabled;	\
-- 
2.13.6



More information about the wayland-devel mailing list