mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
Merge branch 'test-slice-threadinit' into 'main'
Moving slice-threadinit.c test to glib/tests/ See merge request GNOME/glib!2580
This commit is contained in:
commit
848d7718b6
@ -105,6 +105,7 @@ glib_tests = {
|
|||||||
'extra_sources' : ['memchunks.c'],
|
'extra_sources' : ['memchunks.c'],
|
||||||
},
|
},
|
||||||
'slice-concurrent' : {},
|
'slice-concurrent' : {},
|
||||||
|
'slice-known-pages' : {},
|
||||||
'slist' : {},
|
'slist' : {},
|
||||||
'sort' : {},
|
'sort' : {},
|
||||||
'spawn-multithreaded' : {},
|
'spawn-multithreaded' : {},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* slice-threadinit.c - test GSlice across g_thread_init
|
/* slice-known-pages.c - test GSlice across known pages
|
||||||
* Copyright (C) 2007 Tim Janik
|
* Copyright (C) 2007 Tim Janik
|
||||||
*
|
*
|
||||||
* This work is provided "as is"; redistribution and modification
|
* This work is provided "as is"; redistribution and modification
|
||||||
@ -18,15 +18,20 @@
|
|||||||
* otherwise) arising in any way out of the use of this software, even
|
* otherwise) arising in any way out of the use of this software, even
|
||||||
* if advised of the possibility of such damage.
|
* if advised of the possibility of such damage.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#define N_PAGES (101) /* number of pages to sample */
|
#define N_PAGES (101) /* number of pages to sample */
|
||||||
#define SAMPLE_SIZE (7)
|
#define SAMPLE_SIZE (7)
|
||||||
#define PAGE_SIZE (128) /* must be <= minimum GSlice alignment block */
|
#define PAGE_SIZE (128) /* must be <= minimum GSlice alignment block */
|
||||||
#define MAGAZINE_PROBES { 97, 265, 347 } /* block sizes hopefully unused by g_thread_init */
|
#define MAGAZINE_PROBES \
|
||||||
#define MAX_PROBE_TRIALS (1031) /* must be >= maximum magazine size */
|
{ \
|
||||||
|
97, 265, 347 \
|
||||||
|
} /* block sizes hopefully unused */
|
||||||
|
#define MAX_PROBE_TRIALS (1031) /* must be >= maximum magazine size */
|
||||||
|
|
||||||
#define ALIGN(size, base) ((base) * (gsize) (((size) + (base) - 1) / (base)))
|
#define ALIGN(size, base) \
|
||||||
|
((base) * (gsize) (((size) + (base) - 1) / (base)))
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
void *page;
|
void *page;
|
||||||
@ -34,6 +39,7 @@ static struct {
|
|||||||
} pages[N_PAGES] = { { NULL, NULL }, };
|
} pages[N_PAGES] = { { NULL, NULL }, };
|
||||||
|
|
||||||
static const guint magazine_probes[] = MAGAZINE_PROBES;
|
static const guint magazine_probes[] = MAGAZINE_PROBES;
|
||||||
|
|
||||||
#define N_MAGAZINE_PROBES G_N_ELEMENTS (magazine_probes)
|
#define N_MAGAZINE_PROBES G_N_ELEMENTS (magazine_probes)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -66,9 +72,8 @@ allocate_from_known_page (void)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void
|
||||||
main (int argc,
|
test_slice_known_pages (void)
|
||||||
char *argv[])
|
|
||||||
{
|
{
|
||||||
gsize j, n_pages = 0;
|
gsize j, n_pages = 0;
|
||||||
void *mps[N_MAGAZINE_PROBES];
|
void *mps[N_MAGAZINE_PROBES];
|
||||||
@ -99,15 +104,15 @@ main (int argc,
|
|||||||
release_trash_list (&free_list, SAMPLE_SIZE);
|
release_trash_list (&free_list, SAMPLE_SIZE);
|
||||||
|
|
||||||
/* ensure that we can allocate from known pages */
|
/* ensure that we can allocate from known pages */
|
||||||
if (!allocate_from_known_page())
|
g_assert_true (allocate_from_known_page());
|
||||||
g_error ("failed to allocate from magazine/page cache (before g_thread_init)");
|
|
||||||
/* release intermediate allocations */
|
/* release intermediate allocations */
|
||||||
release_trash_list (&free_list, SAMPLE_SIZE);
|
release_trash_list (&free_list, SAMPLE_SIZE);
|
||||||
|
|
||||||
/* release magazine probes to be retained */
|
/* release magazine probes to be retained */
|
||||||
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
||||||
g_slice_free1 (magazine_probes[j], mps[j]);
|
g_slice_free1 (magazine_probes[j], mps[j]);
|
||||||
/* mps[*] now contains pointers to releaed slices */
|
/* mps[*] now contains pointers to released slices */
|
||||||
|
|
||||||
/* ensure probes were retained */
|
/* ensure probes were retained */
|
||||||
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
||||||
@ -122,19 +127,15 @@ main (int argc,
|
|||||||
trash = g_slist_prepend (trash, mem);
|
trash = g_slist_prepend (trash, mem);
|
||||||
}
|
}
|
||||||
release_trash_list (&trash, magazine_probes[j]);
|
release_trash_list (&trash, magazine_probes[j]);
|
||||||
if (k >= MAX_PROBE_TRIALS) /* failed to reallocate slice */
|
g_assert_cmpint (k, <, MAX_PROBE_TRIALS); /* failed to reallocate slice */
|
||||||
g_error ("failed to reallocate slice from magazine (before g_thread_init): size=%d", magazine_probes[j]);
|
|
||||||
}
|
}
|
||||||
/* mps[*] now contains pointers to reallocated slices */
|
/* mps[*] now contains pointers to reallocated slices */
|
||||||
|
|
||||||
/* release magazine probes to be retained across g_thread_init */
|
/* release magazine probes to be retained across known pages */
|
||||||
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
||||||
g_slice_free1 (magazine_probes[j], mps[j]);
|
g_slice_free1 (magazine_probes[j], mps[j]);
|
||||||
/* mps[*] now contains pointers to released slices */
|
/* mps[*] now contains pointers to released slices */
|
||||||
|
|
||||||
/* initialize threading (should retain allocator state) */
|
|
||||||
g_thread_init (NULL);
|
|
||||||
|
|
||||||
/* ensure probes were retained */
|
/* ensure probes were retained */
|
||||||
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
||||||
{
|
{
|
||||||
@ -148,19 +149,25 @@ main (int argc,
|
|||||||
trash = g_slist_prepend (trash, mem);
|
trash = g_slist_prepend (trash, mem);
|
||||||
}
|
}
|
||||||
release_trash_list (&trash, magazine_probes[j]);
|
release_trash_list (&trash, magazine_probes[j]);
|
||||||
if (k >= MAX_PROBE_TRIALS) /* failed to reallocate slice */
|
g_assert_cmpint (k, <, MAX_PROBE_TRIALS); /* failed to reallocate slice */
|
||||||
g_error ("failed to reallocate slice from magazine (after g_thread_init): size=%d", magazine_probes[j]);
|
|
||||||
}
|
}
|
||||||
/* mps[*] now contains pointers to reallocated slices */
|
/* mps[*] now contains pointers to reallocated slices */
|
||||||
|
|
||||||
/* ensure that we can allocate from known pages */
|
/* ensure that we can allocate from known pages */
|
||||||
if (!allocate_from_known_page())
|
g_assert_true (allocate_from_known_page());
|
||||||
g_error ("failed to allocate from magazine/page cache (after g_thread_init)");
|
|
||||||
|
|
||||||
/* some cleanups */
|
/* some cleanups */
|
||||||
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
for (j = 0; j < N_MAGAZINE_PROBES; j++)
|
||||||
g_slice_free1 (magazine_probes[j], mps[j]);
|
g_slice_free1 (magazine_probes[j], mps[j]);
|
||||||
release_trash_list (&free_list, SAMPLE_SIZE);
|
release_trash_list (&free_list, SAMPLE_SIZE);
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/slice/known_pages", test_slice_known_pages);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
}
|
}
|
@ -16,9 +16,6 @@ subdir('gobject')
|
|||||||
subdir('refcount')
|
subdir('refcount')
|
||||||
|
|
||||||
tests = {
|
tests = {
|
||||||
'slice-threadinit' : {
|
|
||||||
'dependencies' : [libgthread_dep],
|
|
||||||
},
|
|
||||||
'module-test-library' : {
|
'module-test-library' : {
|
||||||
'dependencies' : [libgmodule_dep],
|
'dependencies' : [libgmodule_dep],
|
||||||
'export_dynamic' : true,
|
'export_dynamic' : true,
|
||||||
|
Loading…
Reference in New Issue
Block a user