diff options
author | Garrett Regier <garrett.regier@riftio.com> | 2014-11-16 12:22:33 -0800 |
---|---|---|
committer | Garrett Regier <garrett.regier@riftio.com> | 2014-11-18 10:30:39 -0800 |
commit | cbd4ecf6f2026f9be895efa49ad5dbbb7a1c806c (patch) | |
tree | e7936092ac320e1e2d0892ebd21dfa1b1e7e3bf5 /tests | |
parent | 58b36ad61c11bf26f29d7f7df1ee914b2da200e1 (diff) | |
download | libpeas-cbd4ecf6f2026f9be895efa49ad5dbbb7a1c806c.tar.gz |
Add nonglobal plugin loader support
This allows multiple threads to each have a PeasEngine
and be used without internal locking. It also allows using
lua5.1 plugins from multiple threads.
https://bugzilla.gnome.org/show_bug.cgi?id=739831
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libpeas/testing/testing-extension.c | 50 | ||||
-rw-r--r-- | tests/libpeas/testing/testing.c | 4 | ||||
-rw-r--r-- | tests/libpeas/testing/testing.h | 8 | ||||
-rw-r--r-- | tests/testing-util/testing-util.c | 8 | ||||
-rw-r--r-- | tests/testing-util/testing-util.h | 17 |
5 files changed, 60 insertions, 27 deletions
diff --git a/tests/libpeas/testing/testing-extension.c b/tests/libpeas/testing/testing-extension.c index 97e7dfc..d5dba02 100644 --- a/tests/libpeas/testing/testing-extension.c +++ b/tests/libpeas/testing/testing-extension.c @@ -1,8 +1,8 @@ /* - * testing-extensin.c + * testing-extension.c * This file is part of libpeas * - * Copyright (C) 2011 - Garrett Regier + * Copyright (C) 2011-2014 - Garrett Regier * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as published by @@ -270,25 +270,25 @@ test_extension_get_settings (PeasEngine *engine, } static void -multiple_threads_in_thread (guint nth_thread) +multiple_threads_in_thread (guint nth_thread, + gboolean use_nonglobal_loaders) { gint i, j; PeasEngine *engine; PeasPluginInfo *info; GObject *extension; - const gboolean is_slow = strstr (loader, "python") != NULL; - engine = testing_engine_new (); + engine = testing_engine_new_full (use_nonglobal_loaders); peas_engine_enable_loader (engine, loader); info = peas_engine_get_plugin_info (engine, extension_plugin); g_assert (info != NULL); - for (i = 0; i < (is_slow ? 5 : 20); ++i) + for (i = 0; i < 10; ++i) { g_assert (peas_engine_load_plugin (engine, info)); - for (j = 0; j < 5; ++j) + for (j = 0; j < 50; ++j) { extension = peas_engine_create_extension (engine, info, INTROSPECTION_TYPE_BASE, @@ -306,18 +306,22 @@ multiple_threads_in_thread (guint nth_thread) static void test_extension_multiple_threads (PeasEngine *engine, - PeasPluginInfo *info) + PeasPluginInfo *info, + gboolean use_nonglobal_loaders) { - gint i; + gint i, n_threads; GThreadPool *pool; GError *error = NULL; - const gboolean is_slow = strstr (loader, "python") != NULL; + + /* Avoid too many threads, but try to get some good contention */ + n_threads = g_get_num_processors () + 2; pool = g_thread_pool_new ((GFunc) multiple_threads_in_thread, - NULL, g_get_num_processors (), TRUE, &error); + GINT_TO_POINTER (use_nonglobal_loaders), + n_threads, TRUE, &error); g_assert_no_error (error); - for (i = 0; i < (is_slow ? 20 : 100); ++i) + for (i = 0; i < g_thread_pool_get_max_threads (pool); ++i) { /* Cannot supply NULL as the data... */ g_thread_pool_push (pool, GUINT_TO_POINTER (i + 1), &error); @@ -328,6 +332,20 @@ test_extension_multiple_threads (PeasEngine *engine, } static void +test_extension_multiple_threads_global_loaders (PeasEngine *engine, + PeasPluginInfo *info) +{ + test_extension_multiple_threads (engine, info, FALSE); +} + +static void +test_extension_multiple_threads_nonglobal_loaders (PeasEngine *engine, + PeasPluginInfo *info) +{ + test_extension_multiple_threads (engine, info, TRUE); +} + +static void test_extension_call_no_args (PeasEngine *engine, PeasPluginInfo *info) { @@ -489,7 +507,13 @@ testing_extension_basic (const gchar *loader_) /* See peas_engine_enable_loader() */ if (g_strcmp0 (loader, "lua5.1") != 0) - _EXTENSION_TEST (loader, "multiple-threads", multiple_threads); + { + _EXTENSION_TEST (loader, "multiple-threads/global-loaders", + multiple_threads_global_loaders); + } + + _EXTENSION_TEST (loader, "multiple-threads/nonglobal-loaders", + multiple_threads_nonglobal_loaders); } void diff --git a/tests/libpeas/testing/testing.c b/tests/libpeas/testing/testing.c index aeb387e..741e313 100644 --- a/tests/libpeas/testing/testing.c +++ b/tests/libpeas/testing/testing.c @@ -55,7 +55,7 @@ testing_init (gint *argc, } PeasEngine * -testing_engine_new (void) +testing_engine_new_full (gboolean nonglobal_loaders) { PeasEngine *engine; @@ -75,7 +75,7 @@ testing_engine_new (void) testing_util_push_log_hook ("*Error loading *unkown-loader.plugin*"); /* Must be after pushing log hooks */ - engine = testing_util_engine_new (); + engine = testing_util_engine_new_full (nonglobal_loaders); peas_engine_add_search_path (engine, BUILDDIR "/tests/libpeas/plugins", SRCDIR "/tests/libpeas/plugins"); diff --git a/tests/libpeas/testing/testing.h b/tests/libpeas/testing/testing.h index f638268..23a8932 100644 --- a/tests/libpeas/testing/testing.h +++ b/tests/libpeas/testing/testing.h @@ -27,10 +27,12 @@ G_BEGIN_DECLS -void testing_init (gint *argc, - gchar ***argv); +void testing_init (gint *argc, + gchar ***argv); -PeasEngine *testing_engine_new (void); +PeasEngine *testing_engine_new_full (gboolean nonglobal_loaders); + +#define testing_engine_new() (testing_engine_new_full (FALSE)) /* libtesting-util functions which do not need to be overridden */ #define testing_engine_free testing_util_engine_free diff --git a/tests/testing-util/testing-util.c b/tests/testing-util/testing-util.c index bd0f839..3b98fe9 100644 --- a/tests/testing-util/testing-util.c +++ b/tests/testing-util/testing-util.c @@ -203,7 +203,7 @@ engine_weak_notify (gpointer unused, } PeasEngine * -testing_util_engine_new (void) +testing_util_engine_new_full (gboolean nonglobal_loaders) { PeasEngine *engine; @@ -215,7 +215,11 @@ testing_util_engine_new (void) g_assert (g_private_get (&engine_key) == NULL); /* Must be after requiring typelibs */ - engine = peas_engine_new (); + if (!nonglobal_loaders) + engine = peas_engine_new (); + else + engine = peas_engine_new_with_nonglobal_loaders (); + g_private_set (&engine_key, engine); g_object_weak_ref (G_OBJECT (engine), diff --git a/tests/testing-util/testing-util.h b/tests/testing-util/testing-util.h index 3832794..726120f 100644 --- a/tests/testing-util/testing-util.h +++ b/tests/testing-util/testing-util.h @@ -26,16 +26,19 @@ G_BEGIN_DECLS -void testing_util_init (void); +void testing_util_init (void); -PeasEngine *testing_util_engine_new (void); -void testing_util_engine_free (PeasEngine *engine); +PeasEngine *testing_util_engine_new_full (gboolean nonglobal_loaders); +void testing_util_engine_free (PeasEngine *engine); -int testing_util_run_tests (void); +int testing_util_run_tests (void); -void testing_util_push_log_hook (const gchar *pattern); -void testing_util_pop_log_hook (void); -void testing_util_pop_log_hooks (void); +void testing_util_push_log_hook (const gchar *pattern); +void testing_util_pop_log_hook (void); +void testing_util_pop_log_hooks (void); + + +#define testing_util_engine_new() (testing_util_engine_new_full (FALSE)) G_END_DECLS |