diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:08 +0000 |
commit | 29b5ab554790bb57337a3b6ab9dcd963cf69d22e (patch) | |
tree | be1456d2bc6c1fb078695fad7bc8f6b212062d3c /tests/util/init.c | |
parent | Initial commit. (diff) | |
download | libgit2-29b5ab554790bb57337a3b6ab9dcd963cf69d22e.tar.xz libgit2-29b5ab554790bb57337a3b6ab9dcd963cf69d22e.zip |
Adding upstream version 1.7.2+ds.upstream/1.7.2+ds
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/util/init.c')
-rw-r--r-- | tests/util/init.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/util/init.c b/tests/util/init.c new file mode 100644 index 0000000..78b3dd0 --- /dev/null +++ b/tests/util/init.c @@ -0,0 +1,54 @@ +#include "clar_libgit2.h" + +void test_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_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_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 +} |