various tests: do not provoke SIGTRAP with -m no-undefined

Some of the GLib tests deliberately provoke warnings (or even fatal
errors) in a forked child. Normally, this is fine, but under valgrind
it's somewhat undesirable. We do want to follow fork(), so we can check
for leaks in child processes that exit gracefully; but we don't want to
be told about "leaks" in processes that are crashing, because there'd
be no point in cleaning those up anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=666116
This commit is contained in:
Simon McVittie
2011-12-14 18:08:59 +00:00
committed by Matthias Clasen
parent 5cb29d7909
commit fa4792c35e
13 changed files with 304 additions and 168 deletions

View File

@@ -62,12 +62,15 @@ test_basic (void)
g_action_activate (G_ACTION (action), NULL);
g_assert (!a.did_run);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
g_action_activate (G_ACTION (action), g_variant_new_string ("xxx"));
exit (0);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
g_action_activate (G_ACTION (action), g_variant_new_string ("xxx"));
exit (0);
}
g_test_trap_assert_failed ();
}
g_test_trap_assert_failed ();
g_object_unref (action);
g_assert (!a.did_run);
@@ -87,13 +90,16 @@ test_basic (void)
g_variant_unref (a.params);
a.did_run = FALSE;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
g_action_activate (G_ACTION (action), NULL);
exit (0);
}
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
g_action_activate (G_ACTION (action), NULL);
exit (0);
}
g_test_trap_assert_failed ();
g_test_trap_assert_failed ();
}
g_object_unref (action);
g_assert (!a.did_run);
@@ -250,12 +256,15 @@ test_stateful (void)
g_assert_cmpstr (g_variant_get_string (state, NULL), ==, "hihi");
g_variant_unref (state);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
g_simple_action_set_state (action, g_variant_new_int32 (123));
exit (0);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
g_simple_action_set_state (action, g_variant_new_int32 (123));
exit (0);
}
g_test_trap_assert_failed ();
}
g_test_trap_assert_failed ();
g_simple_action_set_state (action, g_variant_new_string ("hello"));
state = g_action_get_state (G_ACTION (action));
@@ -265,12 +274,17 @@ test_stateful (void)
g_object_unref (action);
action = g_simple_action_new ("foo", NULL);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
g_simple_action_set_state (action, g_variant_new_int32 (123));
exit (0);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
g_simple_action_set_state (action, g_variant_new_int32 (123));
exit (0);
}
g_test_trap_assert_failed ();
}
g_test_trap_assert_failed ();
g_object_unref (action);
}
@@ -339,27 +353,30 @@ test_entries (void)
g_assert (bar_activated);
g_assert (!foo_activated);
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
const GActionEntry bad_type = {
"bad-type", NULL, "ss"
};
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
const GActionEntry bad_type = {
"bad-type", NULL, "ss"
};
g_simple_action_group_add_entries (actions, &bad_type, 1, NULL);
exit (0);
g_simple_action_group_add_entries (actions, &bad_type, 1, NULL);
exit (0);
}
g_test_trap_assert_failed ();
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
const GActionEntry bad_state = {
"bad-state", NULL, NULL, "flse"
};
g_simple_action_group_add_entries (actions, &bad_state, 1, NULL);
exit (0);
}
g_test_trap_assert_failed ();
}
g_test_trap_assert_failed ();
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
const GActionEntry bad_state = {
"bad-state", NULL, NULL, "flse"
};
g_simple_action_group_add_entries (actions, &bad_state, 1, NULL);
exit (0);
}
g_test_trap_assert_failed ();
state = g_action_group_get_action_state (G_ACTION_GROUP (actions), "volume");
g_assert_cmpint (g_variant_get_int32 (state), ==, 0);

View File

@@ -572,26 +572,32 @@ test_expected_interface (GDBusProxy *proxy)
test_bogus_property (proxy);
*/
/* Also check that we complain if setting a cached property of the wrong type */
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_string ("error_me_out!"));
/* Also check that we complain if setting a cached property of the wrong type */
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
{
g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_string ("error_me_out!"));
}
g_test_trap_assert_stderr ("*Trying to set property y of type s but according to the expected interface the type is y*");
g_test_trap_assert_failed();
}
g_test_trap_assert_stderr ("*Trying to set property y of type s but according to the expected interface the type is y*");
g_test_trap_assert_failed();
/* this should work, however (since the type is correct) */
g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_byte (42));
/* Try to get the value of a property where the type we expect is different from
* what we have in our cache (e.g. what the service returned)
*/
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
value = g_dbus_proxy_get_cached_property (proxy, "i");
/* Try to get the value of a property where the type we expect is different from
* what we have in our cache (e.g. what the service returned)
*/
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
{
value = g_dbus_proxy_get_cached_property (proxy, "i");
}
g_test_trap_assert_stderr ("*Trying to get property i with type i but according to the expected interface the type is u*");
g_test_trap_assert_failed();
}
g_test_trap_assert_stderr ("*Trying to get property i with type i but according to the expected interface the type is u*");
g_test_trap_assert_failed();
/* Even if a property does not exist in expected_interface, looking it
* up, or setting it, should never fail. Because it could be that the

View File

@@ -53,7 +53,7 @@ test_basic (void)
g_free (str);
str = NULL;
if (!backend_set)
if (!backend_set && g_test_undefined ())
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
@@ -85,6 +85,9 @@ test_basic (void)
static void
test_unknown_key (void)
{
if (!g_test_undefined ())
return;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
GSettings *settings;
@@ -107,6 +110,9 @@ test_unknown_key (void)
static void
test_no_schema (void)
{
if (!g_test_undefined ())
return;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
GSettings *settings;
@@ -126,6 +132,9 @@ test_no_schema (void)
static void
test_wrong_type (void)
{
if (!g_test_undefined ())
return;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
GSettings *settings;
@@ -156,6 +165,9 @@ test_wrong_type (void)
static void
test_wrong_path (void)
{
if (!g_test_undefined ())
return;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
GSettings *settings G_GNUC_UNUSED;
@@ -170,6 +182,9 @@ test_wrong_path (void)
static void
test_no_path (void)
{
if (!g_test_undefined ())
return;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
GSettings *settings G_GNUC_UNUSED;
@@ -1233,6 +1248,9 @@ test_directional_binding (void)
static void
test_typesafe_binding (void)
{
if (!g_test_undefined ())
return;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
TestObject *obj;
@@ -1356,18 +1374,21 @@ test_no_change_binding (void)
static void
test_no_read_binding (void)
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
TestObject *obj;
GSettings *settings;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
TestObject *obj;
GSettings *settings;
settings = g_settings_new ("org.gtk.test.binding");
obj = test_object_new ();
settings = g_settings_new ("org.gtk.test.binding");
obj = test_object_new ();
g_settings_bind (settings, "string", obj, "no-read", 0);
g_settings_bind (settings, "string", obj, "no-read", 0);
}
g_test_trap_assert_failed ();
g_test_trap_assert_stderr ("*property*is not readable*");
}
g_test_trap_assert_failed ();
g_test_trap_assert_stderr ("*property*is not readable*");
if (g_test_trap_fork (0, 0))
{
@@ -1390,18 +1411,21 @@ test_no_read_binding (void)
static void
test_no_write_binding (void)
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
if (g_test_undefined ())
{
TestObject *obj;
GSettings *settings;
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
TestObject *obj;
GSettings *settings;
settings = g_settings_new ("org.gtk.test.binding");
obj = test_object_new ();
settings = g_settings_new ("org.gtk.test.binding");
obj = test_object_new ();
g_settings_bind (settings, "string", obj, "no-write", 0);
g_settings_bind (settings, "string", obj, "no-write", 0);
}
g_test_trap_assert_failed ();
g_test_trap_assert_stderr ("*property*is not writable*");
}
g_test_trap_assert_failed ();
g_test_trap_assert_stderr ("*property*is not writable*");
if (g_test_trap_fork (0, 0))
{
@@ -1562,7 +1586,7 @@ test_enums (void)
settings = g_settings_new ("org.gtk.test.enums");
direct = g_settings_new ("org.gtk.test.enums.direct");
if (!backend_set)
if (g_test_undefined () && !backend_set)
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
g_settings_get_enum (direct, "test");
@@ -1620,7 +1644,7 @@ test_flags (void)
settings = g_settings_new ("org.gtk.test.enums");
direct = g_settings_new ("org.gtk.test.enums.direct");
if (!backend_set)
if (g_test_undefined () && !backend_set)
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
g_settings_get_flags (direct, "test");
@@ -1690,7 +1714,7 @@ test_range (void)
settings = g_settings_new ("org.gtk.test.range");
direct = g_settings_new ("org.gtk.test.range.direct");
if (!backend_set)
if (g_test_undefined () && !backend_set)
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
g_settings_set_int (settings, "val", 45);