mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 07:44:49 +00:00

We want a predictable number of initializations in our multithreaded init test, but we also want to make sure that we have _actually_ initialized `git_libgit2_init` before calling `git_thread_create` (since it now has a sanity check that `git_libgit2_init` has been called). Since `git_thread_create` is internal-only, keep this sanity check. Flip the invocation so that we `git_libgit2_init` before our thread tests and `git_libgit2_shutdown` again after.
55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#include "clar_libgit2.h"
|
|
|
|
void test_core_init__returns_count(void)
|
|
{
|
|
/* libgit2_clar initializes us first, so we have an existing
|
|
* initialization.
|
|
*/
|
|
cl_assert_equal_i(2, git_libgit2_init());
|
|
cl_assert_equal_i(3, git_libgit2_init());
|
|
|
|
cl_assert_equal_i(2, git_libgit2_shutdown());
|
|
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(2, git_libgit2_init());
|
|
|
|
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_shutdown());
|
|
cl_sandbox_set_search_path_defaults();
|
|
#else
|
|
cl_skip();
|
|
#endif
|
|
}
|