mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
Hack up glib/tests/array-test to not actually malloc 2G
Fixes the test on machines where that allocation takes very long. https://bugzilla.gnome.org/show_bug.cgi?id=610784
This commit is contained in:
parent
48f3f26263
commit
1ad08a6a9f
@ -100,6 +100,22 @@ array_ref_count (void)
|
||||
g_array_unref (garray2);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
array_large_size_remalloc_impl (gpointer mem,
|
||||
gsize n_bytes)
|
||||
{
|
||||
/* We only care that g_array_set_size() doesn't hang; we'll never
|
||||
* actually use any of the 2G of memory that it requests, so it's
|
||||
* OK that we don't actually allocate the whole thing.
|
||||
*/
|
||||
return realloc (mem, MIN (n_bytes, 1024 * 1024));
|
||||
}
|
||||
|
||||
static GMemVTable array_large_size_mem_vtable = {
|
||||
malloc, array_large_size_remalloc_impl, free,
|
||||
NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static void
|
||||
array_large_size (void)
|
||||
{
|
||||
@ -107,19 +123,15 @@ array_large_size (void)
|
||||
|
||||
g_test_bug ("568760");
|
||||
|
||||
array = g_array_new (TRUE, TRUE, sizeof (char));
|
||||
array = g_array_new (FALSE, FALSE, sizeof (char));
|
||||
|
||||
/* it might take really long until the allocation happens */
|
||||
if (g_test_trap_fork (10 /* s */ * 1000 /* ms */ * 1000 /* µs */, 0))
|
||||
if (g_test_trap_fork (5 /* s */ * 1000 /* ms */ * 1000 /* µs */, 0))
|
||||
{
|
||||
g_mem_set_vtable (&array_large_size_mem_vtable);
|
||||
g_array_set_size (array, 1073750016);
|
||||
exit (0); /* success */
|
||||
}
|
||||
|
||||
if (!g_test_trap_has_passed ())
|
||||
{
|
||||
g_test_trap_assert_stderr ("*failed to allocate 2147483648 bytes*");
|
||||
}
|
||||
g_test_trap_assert_passed ();
|
||||
|
||||
g_array_free (array, TRUE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user