diff options
author | Garrett Regier <garrett.regier@riftio.com> | 2014-11-08 12:31:58 -0800 |
---|---|---|
committer | Garrett Regier <garrett.regier@riftio.com> | 2014-11-18 10:30:39 -0800 |
commit | 9a2b7a92741fd88fb059882c84eca9381246d554 (patch) | |
tree | 3927de976367d3086becc4e8be680c793ee4d69d /tests/libpeas | |
parent | 47ff5e97b4066822b773c04a063914fecafb20bf (diff) | |
download | libpeas-9a2b7a92741fd88fb059882c84eca9381246d554.tar.gz |
Add an extension test that uses multiple threads
This should act as a good stress test for checking that
libpeas is thread-safe. This also changes testing-utils to
be thread aware.
https://bugzilla.gnome.org/show_bug.cgi?id=739619
Diffstat (limited to 'tests/libpeas')
-rw-r--r-- | tests/libpeas/testing/testing-extension.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/libpeas/testing/testing-extension.c b/tests/libpeas/testing/testing-extension.c index 2fd5dda..97e7dfc 100644 --- a/tests/libpeas/testing/testing-extension.c +++ b/tests/libpeas/testing/testing-extension.c @@ -270,6 +270,64 @@ test_extension_get_settings (PeasEngine *engine, } static void +multiple_threads_in_thread (guint nth_thread) +{ + gint i, j; + PeasEngine *engine; + PeasPluginInfo *info; + GObject *extension; + const gboolean is_slow = strstr (loader, "python") != NULL; + + engine = testing_engine_new (); + 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) + { + g_assert (peas_engine_load_plugin (engine, info)); + + for (j = 0; j < 5; ++j) + { + extension = peas_engine_create_extension (engine, info, + INTROSPECTION_TYPE_BASE, + NULL); + + g_assert (extension != NULL); + g_object_unref (extension); + } + + g_assert (peas_engine_unload_plugin (engine, info)); + } + + testing_engine_free (engine); +} + +static void +test_extension_multiple_threads (PeasEngine *engine, + PeasPluginInfo *info) +{ + gint i; + GThreadPool *pool; + GError *error = NULL; + const gboolean is_slow = strstr (loader, "python") != NULL; + + pool = g_thread_pool_new ((GFunc) multiple_threads_in_thread, + NULL, g_get_num_processors (), TRUE, &error); + g_assert_no_error (error); + + for (i = 0; i < (is_slow ? 20 : 100); ++i) + { + /* Cannot supply NULL as the data... */ + g_thread_pool_push (pool, GUINT_TO_POINTER (i + 1), &error); + g_assert_no_error (error); + } + + g_thread_pool_free (pool, FALSE, TRUE); +} + +static void test_extension_call_no_args (PeasEngine *engine, PeasPluginInfo *info) { @@ -428,6 +486,10 @@ testing_extension_basic (const gchar *loader_) _EXTENSION_TEST (loader, "plugin-info", plugin_info); _EXTENSION_TEST (loader, "get-settings", get_settings); + + /* See peas_engine_enable_loader() */ + if (g_strcmp0 (loader, "lua5.1") != 0) + _EXTENSION_TEST (loader, "multiple-threads", multiple_threads); } void |