summaryrefslogtreecommitdiff
path: root/tests/shm.c
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2018-08-14 16:03:03 +0100
committerPhilip Withnall <withnall@endlessm.com>2018-08-16 18:58:27 +0100
commita8dcd4f0decf78afdd22caaaad4ac746e075c3b0 (patch)
tree5f26bd3238f330f280d15ed9421bf88b7258d1e5 /tests/shm.c
parentea8c09f14da4b931cdadbabe2be315f6747ac7b7 (diff)
downloaddconf-a8dcd4f0decf78afdd22caaaad4ac746e075c3b0.tar.gz
tests: Stop using deprecated g_test_trap_fork() API
Use g_test_subprocess() and g_test_trap_subprocess() instead. This requires splitting up some of the unit tests, since subprocesses are handled at a per-test level, and you can’t trivially fork multiple different subprocesses from a single test (like you could with fork()). While fork was safe to use on POSIX (and dconf only targets POSIX), the fact that we had to redefine GLIB_VERSION_MIN_REQUIRED to hide the deprecation errors was not doing wonders for the maintainability of the tests. Signed-off-by: Philip Withnall <withnall@endlessm.com>
Diffstat (limited to 'tests/shm.c')
-rw-r--r--tests/shm.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/tests/shm.c b/tests/shm.c
index 66e67a2..a0cf67e 100644
--- a/tests/shm.c
+++ b/tests/shm.c
@@ -1,7 +1,5 @@
#define _GNU_SOURCE
-#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_36 /* Suppress deprecation warnings */
-
#include "../common/dconf-paths.h"
#include <glib/gstdio.h>
#include <sys/stat.h>
@@ -19,7 +17,7 @@ test_mkdir_fail (void)
{
guint8 *shm;
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ if (g_test_subprocess ())
{
gchar *evil;
gint fd;
@@ -36,8 +34,10 @@ test_mkdir_fail (void)
g_unlink (evil);
g_free (evil);
- exit (0);
+ return;
}
+
+ g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stderr ("*unable to create directory*");
}
@@ -64,7 +64,7 @@ test_open_and_flag (void)
static void
test_invalid_name (void)
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ if (g_test_subprocess ())
{
guint8 *shm;
@@ -73,8 +73,10 @@ test_invalid_name (void)
shm = dconf_shm_open ("foo/bar");
g_assert (shm == NULL);
g_assert (dconf_shm_is_flagged (shm));
- exit (0);
+ return;
}
+
+ g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stderr ("*unable to create*foo/bar*");
}
@@ -107,7 +109,7 @@ pwrite (int fd, const void *buf, size_t count, off_t offset)
static void
test_out_of_space_open (void)
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ if (g_test_subprocess ())
{
guint8 *shm;
@@ -117,8 +119,10 @@ test_out_of_space_open (void)
shm = dconf_shm_open ("foo");
g_assert (shm == NULL);
g_assert (dconf_shm_is_flagged (shm));
- exit (0);
+ return;
}
+
+ g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stderr ("*failed to allocate*foo*");
}
@@ -126,14 +130,16 @@ test_out_of_space_open (void)
static void
test_out_of_space_flag (void)
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ if (g_test_subprocess ())
{
g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
should_fail_pwrite = TRUE;
dconf_shm_flag ("foo");
- exit (0);
+ return;
}
+
+ g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_passed ();
}