[glib] Hack up glib/tests/array-test to not actually malloc 2G
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Hack up glib/tests/array-test to not actually malloc 2G
- Date: Thu, 24 Jun 2010 20:03:18 +0000 (UTC)
commit 1ad08a6a9fc5bf700de31c928d4fc7031bd8fd19
Author: Dan Winship <danw gnome org>
Date: Thu Jun 24 14:23:37 2010 -0400
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
glib/tests/array-test.c | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/glib/tests/array-test.c b/glib/tests/array-test.c
index 6bfe46b..16d617e 100644
--- a/glib/tests/array-test.c
+++ b/glib/tests/array-test.c
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]