Merge branch 'refcount_tests' into 'main'

Moving tests/refcount/ directory to gobject/tests/

See merge request GNOME/glib!2553
This commit is contained in:
Philip Withnall 2022-05-26 18:03:00 +00:00
commit d1cb96b5e3
10 changed files with 211 additions and 201 deletions

View File

@ -57,6 +57,28 @@ gobject_tests = {
'signalgroup' : {}, 'signalgroup' : {},
'testing' : {}, 'testing' : {},
'type-flags' : {}, 'type-flags' : {},
'objects-refcount1' : {},
'objects-refcount2' : {'suite' : ['slow']},
'properties-refcount1' : {},
'properties-refcount2' : {'suite' : ['slow']},
'properties-refcount3' : {'suite' : ['slow']},
'properties-refcount4' : {},
'signals-refcount1' : {
'source' : 'signals-refcount.c',
'c_args' : ['-DTESTNUM=1'],
},
'signals-refcount2' : {
'source' : 'signals-refcount.c',
'c_args' : ['-DTESTNUM=2'],
},
'signals-refcount3' : {
'source' : 'signals-refcount.c',
'c_args' : ['-DTESTNUM=3'],
},
'signals-refcount4' : {
'source' : 'signals-refcount.c',
'c_args' : ['-DTESTNUM=4'],
},
} }
if cc.get_id() != 'msvc' if cc.get_id() != 'msvc'

View File

@ -5,7 +5,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#define G_TYPE_TEST (my_test_get_type ()) #define G_TYPE_TEST (my_test_get_type ())
#define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest)) #define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
#define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST)) #define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
#define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass)) #define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
@ -65,7 +65,6 @@ my_test_class_init (GTestClass * klass)
GObjectClass *gobject_class; GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
parent_class = g_type_class_ref (G_TYPE_OBJECT); parent_class = g_type_class_ref (G_TYPE_OBJECT);
gobject_class->dispose = my_test_dispose; gobject_class->dispose = my_test_dispose;
@ -74,7 +73,7 @@ my_test_class_init (GTestClass * klass)
static void static void
my_test_init (GTest * test) my_test_init (GTest * test)
{ {
g_print ("init %p\n", test); g_test_message ("init %p\n", test);
} }
static void static void
@ -84,7 +83,7 @@ my_test_dispose (GObject * object)
test = MY_TEST (object); test = MY_TEST (object);
g_print ("dispose %p!\n", test); g_test_message ("dispose %p!\n", test);
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
@ -92,8 +91,8 @@ my_test_dispose (GObject * object)
static void static void
my_test_do_refcount (GTest * test) my_test_do_refcount (GTest * test)
{ {
g_object_ref (test); g_object_ref (test);
g_object_unref (test); g_object_unref (test);
} }
static gpointer static gpointer
@ -104,25 +103,22 @@ run_thread (GTest * test)
while (!g_atomic_int_get (&stopping)) { while (!g_atomic_int_get (&stopping)) {
my_test_do_refcount (test); my_test_do_refcount (test);
if ((i++ % 10000) == 0) { if ((i++ % 10000) == 0) {
g_print ("."); g_test_message (".");
g_thread_yield(); /* force context switch */ g_thread_yield (); /* force context switch */
} }
} }
return NULL; return NULL;
} }
int static void
main (int argc, char **argv) test_refcount_object_basics (void)
{ {
guint i; guint i;
GTest *test1, *test2; GTest *test1, *test2;
GArray *test_threads; GArray *test_threads;
const guint n_threads = 5; const guint n_threads = 5;
g_print ("START: %s\n", argv[0]);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
test1 = g_object_new (G_TYPE_TEST, NULL); test1 = g_object_new (G_TYPE_TEST, NULL);
test2 = g_object_new (G_TYPE_TEST, NULL); test2 = g_object_new (G_TYPE_TEST, NULL);
@ -133,18 +129,16 @@ main (int argc, char **argv)
for (i = 0; i < n_threads; i++) { for (i = 0; i < n_threads; i++) {
GThread *thread; GThread *thread;
thread = g_thread_create ((GThreadFunc) run_thread, test1, TRUE, NULL); thread = g_thread_new (NULL, (GThreadFunc) run_thread, test1);
g_array_append_val (test_threads, thread); g_array_append_val (test_threads, thread);
thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL); thread = g_thread_new (NULL, (GThreadFunc) run_thread, test2);
g_array_append_val (test_threads, thread); g_array_append_val (test_threads, thread);
} }
g_usleep (5000000); g_usleep (5000000);
g_atomic_int_set (&stopping, 1); g_atomic_int_set (&stopping, 1);
g_print ("\nstopping\n");
/* join all threads */ /* join all threads */
for (i = 0; i < 2 * n_threads; i++) { for (i = 0; i < 2 * n_threads; i++) {
GThread *thread; GThread *thread;
@ -156,8 +150,18 @@ main (int argc, char **argv)
g_object_unref (test1); g_object_unref (test1);
g_object_unref (test2); g_object_unref (test2);
g_array_unref (test_threads); g_array_unref (test_threads);
}
g_print ("stopped\n");
int
return 0; main (int argc, gchar *argv[])
{
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL |
g_log_set_always_fatal (G_LOG_FATAL_MASK));
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gobject/refcount/object-basics", test_refcount_object_basics);
return g_test_run ();
} }

View File

@ -73,7 +73,7 @@ my_test_class_init (GTestClass * klass)
static void static void
my_test_init (GTest * test) my_test_init (GTest * test)
{ {
g_print ("init %p\n", test); g_test_message ("init %p\n", test);
} }
static void static void
@ -83,7 +83,7 @@ my_test_dispose (GObject * object)
test = MY_TEST (object); test = MY_TEST (object);
g_print ("dispose %p!\n", test); g_test_message ("dispose %p!\n", test);
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
@ -92,30 +92,40 @@ static void
my_test_do_refcount (GTest * test) my_test_do_refcount (GTest * test)
{ {
static guint i = 1; static guint i = 1;
if (i++ % 100000 == 0) if (i++ % 100000 == 0)
g_print ("."); g_test_message (".");
g_object_ref (test);
g_object_unref (test); g_object_ref (test);
g_object_unref (test);
}
static void
test_refcount_object_advanced (void)
{
gint i;
GTest *test;
test = g_object_new (G_TYPE_TEST, NULL);
for (i = 0; i < 100000000; i++)
{
my_test_do_refcount (test);
}
g_object_unref (test);
} }
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
gint i; g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
GTest *test; G_LOG_LEVEL_CRITICAL |
g_log_set_always_fatal (G_LOG_FATAL_MASK));
g_print ("START: %s\n", argv[0]); g_test_init (&argc, &argv, NULL);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
test = g_object_new (G_TYPE_TEST, NULL); g_test_add_func ("/gobject/refcount/object-advanced", test_refcount_object_advanced);
for (i=0; i<100000000; i++) { return g_test_run ();
my_test_do_refcount (test);
}
g_object_unref (test);
g_print ("\n");
return 0;
} }

View File

@ -5,7 +5,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#define G_TYPE_TEST (my_test_get_type ()) #define G_TYPE_TEST (my_test_get_type ())
#define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest)) #define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
#define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST)) #define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
#define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass)) #define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
@ -89,12 +89,12 @@ my_test_class_init (GTestClass * klass)
gobject_class->set_property = my_test_set_property; gobject_class->set_property = my_test_set_property;
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_DUMMY, PROP_DUMMY,
g_param_spec_int ("dummy", g_param_spec_int ("dummy",
NULL, NULL,
NULL, NULL,
0, G_MAXINT, 0, 0, G_MAXINT, 0,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
} }
static void static void
@ -110,7 +110,7 @@ my_test_dispose (GObject * object)
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
static void static void
my_test_get_property (GObject *object, my_test_get_property (GObject *object,
guint prop_id, guint prop_id,
GValue *value, GValue *value,
@ -131,7 +131,7 @@ my_test_get_property (GObject *object,
} }
} }
static void static void
my_test_set_property (GObject *object, my_test_set_property (GObject *object,
guint prop_id, guint prop_id,
const GValue *value, const GValue *value,
@ -160,7 +160,7 @@ dummy_notify (GObject *object,
test = MY_TEST (object); test = MY_TEST (object);
test->count++; test->count++;
} }
static void static void
@ -176,12 +176,12 @@ static gpointer
run_thread (GTest * test) run_thread (GTest * test)
{ {
gint i = 1; gint i = 1;
while (!g_atomic_int_get (&stopping)) { while (!g_atomic_int_get (&stopping)) {
my_test_do_property (test); my_test_do_property (test);
if ((i++ % 10000) == 0) if ((i++ % 10000) == 0)
{ {
g_print (".%c", 'a' + test->id); g_test_message (".%c", 'a' + test->id);
g_thread_yield(); /* force context switch */ g_thread_yield(); /* force context switch */
} }
} }
@ -189,49 +189,55 @@ run_thread (GTest * test)
return NULL; return NULL;
} }
int static void
main (int argc, char **argv) test_refcount_properties_1 (void)
{ {
#define N_THREADS 5 #define N_THREADS 5
GThread *test_threads[N_THREADS]; GThread *test_threads[N_THREADS];
GTest *test_objects[N_THREADS]; GTest *test_objects[N_THREADS];
gint i; gint i;
g_print ("START: %s\n", argv[0]);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
for (i = 0; i < N_THREADS; i++) { for (i = 0; i < N_THREADS; i++) {
GTest *test; GTest *test;
test = g_object_new (G_TYPE_TEST, NULL); test = g_object_new (G_TYPE_TEST, NULL);
test_objects[i] = test; test_objects[i] = test;
g_assert (test->count == test->dummy); g_assert_cmpint (test->count, ==, test->dummy);
g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL); g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
} }
g_atomic_int_set (&stopping, FALSE); g_atomic_int_set (&stopping, FALSE);
for (i = 0; i < N_THREADS; i++) for (i = 0; i < N_THREADS; i++)
test_threads[i] = g_thread_create ((GThreadFunc) run_thread, test_objects[i], TRUE, NULL); test_threads[i] = g_thread_new (NULL, (GThreadFunc) run_thread, test_objects[i]);
g_usleep (3000000); g_usleep (3000000);
g_atomic_int_set (&stopping, TRUE); g_atomic_int_set (&stopping, TRUE);
g_print ("\nstopping\n");
/* join all threads */ /* join all threads */
for (i = 0; i < N_THREADS; i++) for (i = 0; i < N_THREADS; i++)
g_thread_join (test_threads[i]); g_thread_join (test_threads[i]);
g_print ("stopped\n");
for (i = 0; i < N_THREADS; i++) { for (i = 0; i < N_THREADS; i++) {
GTest *test = test_objects[i]; GTest *test = test_objects[i];
g_assert (test->count == test->dummy); g_assert_cmpint (test->count, ==, test->dummy);
g_object_unref (test); g_object_unref (test);
} }
}
return 0;
int
main (int argc, gchar *argv[])
{
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL |
g_log_set_always_fatal (G_LOG_FATAL_MASK));
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gobject/refcount/properties-1", test_refcount_properties_1);
return g_test_run ();
} }

View File

@ -87,18 +87,18 @@ my_test_class_init (GTestClass * klass)
gobject_class->set_property = my_test_set_property; gobject_class->set_property = my_test_set_property;
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_DUMMY, PROP_DUMMY,
g_param_spec_int ("dummy", g_param_spec_int ("dummy",
NULL, NULL,
NULL, NULL,
0, G_MAXINT, 0, 0, G_MAXINT, 0,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
} }
static void static void
my_test_init (GTest * test) my_test_init (GTest * test)
{ {
g_print ("init %p\n", test); g_test_message ("init %p\n", test);
} }
static void static void
@ -108,15 +108,15 @@ my_test_dispose (GObject * object)
test = MY_TEST (object); test = MY_TEST (object);
g_print ("dispose %p!\n", test); g_test_message ("dispose %p!\n", test);
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
static void static void
my_test_get_property (GObject *object, my_test_get_property (GObject *object,
guint prop_id, guint prop_id,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GTest *test; GTest *test;
@ -134,11 +134,11 @@ my_test_get_property (GObject *object,
} }
} }
static void static void
my_test_set_property (GObject *object, my_test_set_property (GObject *object,
guint prop_id, guint prop_id,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GTest *test; GTest *test;
@ -163,7 +163,7 @@ dummy_notify (GObject *object,
{ {
count++; count++;
if (count % 10000 == 0) if (count % 10000 == 0)
g_print ("."); g_test_message (".");
} }
static void static void
@ -175,28 +175,36 @@ my_test_do_property (GTest * test)
g_object_set (test, "dummy", dummy + 1, NULL); g_object_set (test, "dummy", dummy + 1, NULL);
} }
int static void
main (int argc, char **argv) test_refcount_properties_2 (void)
{ {
gint i; gint i;
GTest *test; GTest *test;
g_print ("START: %s\n", argv[0]);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
test = g_object_new (G_TYPE_TEST, NULL); test = g_object_new (G_TYPE_TEST, NULL);
g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL); g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
g_assert_cmpint (count, ==, test->dummy);
g_assert (count == test->dummy); for (i = 0; i < 1000000; i++)
{
for (i=0; i<1000000; i++) { my_test_do_property (test);
my_test_do_property (test); }
} g_assert_cmpint (count, ==, test->dummy);
g_assert (count == test->dummy);
g_object_unref (test); g_object_unref (test);
}
return 0;
int
main (int argc, gchar *argv[])
{
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL |
g_log_set_always_fatal (G_LOG_FATAL_MASK));
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gobject/refcount/properties-2", test_refcount_properties_2);
return g_test_run ();
} }

View File

@ -144,28 +144,25 @@ run_thread (GTest * test)
my_test_do_property (test); my_test_do_property (test);
if ((i++ % 10000) == 0) if ((i++ % 10000) == 0)
{ {
g_print (".%c", 'a' + test->id); g_test_message (".%c", 'a' + test->id);
g_thread_yield(); /* force context switch */ g_thread_yield(); /* force context switch */
} }
} }
return NULL; return NULL;
} }
int static void
main (int argc, char **argv) test_refcount_properties_3 (void)
{ {
gint i; gint i;
GTest *test; GTest *test;
GArray *test_threads; GArray *test_threads;
const gint n_threads = 5; const gint n_threads = 5;
g_print ("START: %s\n", argv[0]);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
test = g_object_new (G_TYPE_TEST, NULL); test = g_object_new (G_TYPE_TEST, NULL);
g_assert (test->count == test->dummy); g_assert_cmpint (test->count, ==, test->dummy);
g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL); g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *)); test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
@ -175,13 +172,13 @@ main (int argc, char **argv)
for (i = 0; i < n_threads; i++) { for (i = 0; i < n_threads; i++) {
GThread *thread; GThread *thread;
thread = g_thread_create ((GThreadFunc) run_thread, test, TRUE, NULL); thread = g_thread_new (NULL, (GThreadFunc) run_thread, test);
g_array_append_val (test_threads, thread); g_array_append_val (test_threads, thread);
} }
g_usleep (30000000); g_usleep (30000000);
g_atomic_int_set (&stopping, 1); g_atomic_int_set (&stopping, 1);
g_print ("\nstopping\n"); g_test_message ("\nstopping\n");
/* join all threads */ /* join all threads */
for (i = 0; i < n_threads; i++) { for (i = 0; i < n_threads; i++) {
@ -191,12 +188,23 @@ main (int argc, char **argv)
g_thread_join (thread); g_thread_join (thread);
} }
g_print ("stopped\n"); g_test_message ("stopped\n");
g_test_message ("%d %d\n", test->setcount, test->count);
g_print ("%d %d\n", test->setcount, test->count);
g_array_free (test_threads, TRUE); g_array_free (test_threads, TRUE);
g_object_unref (test); g_object_unref (test);
}
return 0;
int
main (int argc, gchar *argv[])
{
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL |
g_log_set_always_fatal (G_LOG_FATAL_MASK));
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gobject/refcount/properties-3", test_refcount_properties_3);
return g_test_run ();
} }

View File

@ -143,19 +143,15 @@ my_badger_mama_notify (GObject *object,
MyBadger *self; MyBadger *self;
self = MY_BADGER (object); self = MY_BADGER (object);
self->mama_notify_count++; self->mama_notify_count++;
} }
int static void
main (int argc, char **argv) test_refcount_properties_4 (void)
{ {
MyBadger * badger1, * badger2; MyBadger * badger1, * badger2;
gpointer test; gpointer test;
g_print ("START: %s\n", argv[0]);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
badger1 = g_object_new (MY_TYPE_BADGER, NULL); badger1 = g_object_new (MY_TYPE_BADGER, NULL);
badger2 = g_object_new (MY_TYPE_BADGER, NULL); badger2 = g_object_new (MY_TYPE_BADGER, NULL);
@ -163,11 +159,23 @@ main (int argc, char **argv)
g_assert_cmpuint (badger1->mama_notify_count, ==, 1); g_assert_cmpuint (badger1->mama_notify_count, ==, 1);
g_assert_cmpuint (badger2->mama_notify_count, ==, 1); g_assert_cmpuint (badger2->mama_notify_count, ==, 1);
g_object_get (badger1, "mama", &test, NULL); g_object_get (badger1, "mama", &test, NULL);
g_assert (test == badger2); g_assert_cmpmem (test, sizeof (MyBadger), badger2, sizeof (MyBadger));
g_object_unref (test); g_object_unref (test);
g_object_unref (badger1); g_object_unref (badger1);
g_object_unref (badger2); g_object_unref (badger2);
}
return 0;
int
main (int argc, gchar *argv[])
{
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL |
g_log_set_always_fatal (G_LOG_FATAL_MASK));
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gobject/refcount/properties-4", test_refcount_properties_4);
return g_test_run ();
} }

View File

@ -128,7 +128,7 @@ my_test_class_init (GTestClass * klass)
static void static void
my_test_init (GTest * test) my_test_init (GTest * test)
{ {
g_print ("init %p\n", test); g_test_message ("init %p\n", test);
test->value = 0; test->value = 0;
} }
@ -140,7 +140,7 @@ my_test_dispose (GObject * object)
test = MY_TEST (object); test = MY_TEST (object);
g_print ("dispose %p!\n", test); g_test_message ("dispose %p!\n", test);
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
@ -236,8 +236,8 @@ run_thread (GTest * test)
if (TESTNUM == 4) if (TESTNUM == 4)
my_test_do_signal3 (test); my_test_do_signal3 (test);
if ((i++ % 10000) == 0) { if ((i++ % 10000) == 0) {
g_print ("."); g_test_message (".");
g_thread_yield(); /* force context switch */ g_thread_yield (); /* force context switch */
} }
} }
@ -250,20 +250,17 @@ notify (GObject *object, GParamSpec *spec, gpointer user_data)
gint value; gint value;
g_object_get (object, "test-prop", &value, NULL); g_object_get (object, "test-prop", &value, NULL);
/*g_print ("+ %d", value);*/ g_test_message ("+ %d", value);
} }
int static void
main (int argc, char **argv) test_refcount_signals (void)
{ {
gint i; gint i;
GTest *test1, *test2; GTest *test1, *test2;
GArray *test_threads; GArray *test_threads;
const gint n_threads = 1; const gint n_threads = 1;
g_print ("START: %s\n", argv[0]);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
test1 = g_object_new (G_TYPE_TEST, NULL); test1 = g_object_new (G_TYPE_TEST, NULL);
test2 = g_object_new (G_TYPE_TEST, NULL); test2 = g_object_new (G_TYPE_TEST, NULL);
@ -278,19 +275,17 @@ main (int argc, char **argv)
for (i = 0; i < n_threads; i++) { for (i = 0; i < n_threads; i++) {
GThread *thread; GThread *thread;
thread = g_thread_create ((GThreadFunc) run_thread, test1, TRUE, NULL); thread = g_thread_new (NULL, (GThreadFunc) run_thread, test1);
g_array_append_val (test_threads, thread); g_array_append_val (test_threads, thread);
thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL); thread = g_thread_new (NULL, (GThreadFunc) run_thread, test2);
g_array_append_val (test_threads, thread); g_array_append_val (test_threads, thread);
} }
g_usleep (5000000); g_usleep (5000000);
g_atomic_int_set (&stopping, TRUE); g_atomic_int_set (&stopping, TRUE);
g_print ("\nstopping\n"); /* Join all threads */
/* join all threads */
for (i = 0; i < 2 * n_threads; i++) { for (i = 0; i < 2 * n_threads; i++) {
GThread *thread; GThread *thread;
@ -298,11 +293,21 @@ main (int argc, char **argv)
g_thread_join (thread); g_thread_join (thread);
} }
g_print ("stopped\n");
g_array_free (test_threads, TRUE); g_array_free (test_threads, TRUE);
g_object_unref (test1); g_object_unref (test1);
g_object_unref (test2); g_object_unref (test2);
}
return 0;
int
main (int argc, gchar *argv[])
{
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL |
g_log_set_always_fatal (G_LOG_FATAL_MASK));
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gobject/refcount/signals", test_refcount_signals);
return g_test_run ();
} }

View File

@ -13,7 +13,6 @@ test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT'] test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']
subdir('gobject') subdir('gobject')
subdir('refcount')
test_extra_programs = { test_extra_programs = {
'assert-msg-test' : {}, 'assert-msg-test' : {},

View File

@ -1,60 +0,0 @@
refcount_tests = {
'objects' : {},
'objects2' : {'suite' : ['slow']},
'properties' : {},
'properties2' : {'suite' : ['slow']},
'properties3' : {'suite' : ['slow']},
'properties4' : {},
'signal1' : {
'source' : 'signals.c',
'c_args' : ['-DTESTNUM=1'],
},
'signal2' : {
'source' : 'signals.c',
'c_args' : ['-DTESTNUM=2'],
},
'signal3' : {
'source' : 'signals.c',
'c_args' : ['-DTESTNUM=3'],
},
'signal4' : {
'source' : 'signals.c',
'c_args' : ['-DTESTNUM=4'],
},
}
common_c_args = test_cargs + ['-DGLIB_DISABLE_DEPRECATION_WARNINGS']
common_deps = [libm, thread_dep, libglib_dep, libgobject_dep]
foreach test_name, extra_args : refcount_tests
source = extra_args.get('source', test_name + '.c')
extra_sources = extra_args.get('extra_sources', [])
install = installed_tests_enabled and extra_args.get('install', true)
if install
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_conf.set('env', '')
configure_file(
input: installed_tests_template,
output: test_name + '.test',
install_dir: installed_tests_metadir,
configuration: test_conf
)
endif
# FIXME? $(GLIB_DEBUG_FLAGS)
exe = executable(test_name, [source, extra_sources],
c_args : common_c_args + extra_args.get('c_args', []),
dependencies : common_deps + extra_args.get('dependencies', []),
install_dir: installed_tests_execdir,
install: install,
)
suite = ['refcount'] + extra_args.get('suite', [])
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
# FIXME? TESTS_ENVIRONMENT = LIBCHARSET_ALIAS_DIR=$(top_builddir)/glib/libcharset
test(test_name, exe, env : test_env, timeout : timeout, suite : suite)
endforeach