summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-11-01 14:30:38 +0100
committerPatrick Steinhardt <ps@pks.im>2016-11-02 08:53:52 +0100
commit1c33ecc4456186f4cc6570876ed5c47031b7ef1b (patch)
tree0f07c2d0da9e134113b938c802bc5f76eb78f092
parent038f0e1b4cf6333d9835776b72e6bf8fe4975de5 (diff)
downloadlibgit2-1c33ecc4456186f4cc6570876ed5c47031b7ef1b.tar.gz
tests: core: test deinitialization and concurrent initializationpks/synchronize-shutdown
Exercise the logic surrounding deinitialization of the libgit2 library as well as repeated concurrent de- and reinitialization. This tries to catch races and makes sure that it is possible to reinitialize libgit2 multiple times. After deinitializing libgit2, we have to make sure to setup options required for testing. Currently, this only includes setting up the configuration search path again. Before, this has been set up once in `tests/main.c`.
-rw-r--r--tests/core/init.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/core/init.c b/tests/core/init.c
index e17b7845f..cd90b378d 100644
--- a/tests/core/init.c
+++ b/tests/core/init.c
@@ -12,3 +12,43 @@ void test_core_init__returns_count(void)
cl_assert_equal_i(1, git_libgit2_shutdown());
}
+void test_core_init__reinit_succeeds(void)
+{
+ cl_assert_equal_i(0, git_libgit2_shutdown());
+ cl_assert_equal_i(1, git_libgit2_init());
+ cl_sandbox_set_search_path_defaults();
+}
+
+#ifdef GIT_THREADS
+static void *reinit(void *unused)
+{
+ unsigned i;
+
+ for (i = 0; i < 20; i++) {
+ cl_assert(git_libgit2_init() > 0);
+ cl_assert(git_libgit2_shutdown() >= 0);
+ }
+
+ return unused;
+}
+#endif
+
+void test_core_init__concurrent_init_succeeds(void)
+{
+#ifdef GIT_THREADS
+ git_thread threads[10];
+ unsigned i;
+
+ cl_assert_equal_i(0, git_libgit2_shutdown());
+
+ for (i = 0; i < ARRAY_SIZE(threads); i++)
+ git_thread_create(&threads[i], reinit, NULL);
+ for (i = 0; i < ARRAY_SIZE(threads); i++)
+ git_thread_join(&threads[i], NULL);
+
+ cl_assert_equal_i(1, git_libgit2_init());
+ cl_sandbox_set_search_path_defaults();
+#else
+ cl_skip();
+#endif
+}