Hash :
f66e7f36
Author :
Date :
2021-10-28T10:25:09
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include "clar_libgit2.h"
void test_core_init__returns_count(void)
{
/* libgit2_tests 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
}