diff options
author | Thomas Haller <thaller@redhat.com> | 2014-08-04 15:22:25 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-08-04 16:17:36 +0200 |
commit | 242d350fcf473aedd3b0c45295e600743615fd3b (patch) | |
tree | 310dd6fef60732d7c7d1e95217c78d63e49a3a19 /libnm-util | |
parent | 5c31ed880d45ebfaae75f68d1af41bf9a9866d31 (diff) | |
download | NetworkManager-242d350fcf473aedd3b0c45295e600743615fd3b.tar.gz |
libnm-util/test: fix tests not to write a core file
test_libnm_linking() executes ./test-libnm-linking which
is supposed to crash. When the user set `ulimit -c unlimited`
before, this will leave a left-over core file.
In case of `make distcheck`, this is quite bad because it lets
the make target fail:
ERROR: files left in build directory after distclean:
./libnm-util/tests/core.31481
Fix this by setting the (soft) rlimit for writing core files
to 0 before executing the test binary.
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'libnm-util')
-rw-r--r-- | libnm-util/tests/test-general.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c index 26fba2e27a..468cdf21e8 100644 --- a/libnm-util/tests/test-general.c +++ b/libnm-util/tests/test-general.c @@ -25,6 +25,7 @@ #include <netinet/ether.h> #include <linux/if_infiniband.h> #include <sys/wait.h> +#include <sys/resource.h> #include <nm-utils.h> @@ -2447,6 +2448,26 @@ test_connection_normalize_virtual_iface_name (void) } static void +_test_libnm_linking_setup_child_process (gpointer user_data) +{ + int val; + struct rlimit limit; + + /* the child process is supposed to crash. We don't want it + * to write a core dump. */ + + val = getrlimit (RLIMIT_CORE, &limit); + if (val == 0) { + limit.rlim_cur = 0; + val = setrlimit (RLIMIT_CORE, &limit); + if (val == 0) + return; + } + /* on error, do not crash or fail assertion. Instead just exit */ + exit (1); +} + +static void test_libnm_linking (void) { char *argv[] = { "./test-libnm-linking", NULL }; @@ -2454,7 +2475,8 @@ test_libnm_linking (void) int status; GError *error = NULL; - g_spawn_sync (BUILD_DIR, argv, NULL, 0 /*G_SPAWN_DEFAULT*/, NULL, NULL, + g_spawn_sync (BUILD_DIR, argv, NULL, 0 /*G_SPAWN_DEFAULT*/, + _test_libnm_linking_setup_child_process, NULL, &out, &err, &status, &error); g_assert_no_error (error); |