]> git.proxmox.com Git - libgit2.git/blob - tests/libgit2/threads/basic.c
New upstream version 1.5.0+ds
[libgit2.git] / tests / libgit2 / threads / basic.c
1 #include "clar_libgit2.h"
2
3 #include "thread_helpers.h"
4 #include "cache.h"
5
6
7 static git_repository *g_repo;
8
9 void test_threads_basic__initialize(void)
10 {
11 g_repo = cl_git_sandbox_init("testrepo");
12 }
13
14 void test_threads_basic__cleanup(void)
15 {
16 cl_git_sandbox_cleanup();
17 }
18
19
20 void test_threads_basic__cache(void)
21 {
22 /* run several threads polling the cache at the same time */
23 cl_assert(1 == 1);
24 }
25
26 void test_threads_basic__multiple_init(void)
27 {
28 git_repository *nested_repo;
29
30 git_libgit2_init();
31 cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
32 git_repository_free(nested_repo);
33
34 git_libgit2_shutdown();
35 cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
36 git_repository_free(nested_repo);
37 }
38
39 static void *set_error(void *dummy)
40 {
41 git_error_set(GIT_ERROR_INVALID, "oh no, something happened!\n");
42
43 return dummy;
44 }
45
46 /* Set errors so we can check that we free it */
47 void test_threads_basic__set_error(void)
48 {
49 run_in_parallel(1, 4, set_error, NULL, NULL);
50 }
51
52 #ifdef GIT_THREADS
53 static void *return_normally(void *param)
54 {
55 return param;
56 }
57
58 static void *exit_abruptly(void *param)
59 {
60 git_thread_exit(param);
61 return NULL;
62 }
63 #endif
64
65 void test_threads_basic__exit(void)
66 {
67 #ifndef GIT_THREADS
68 clar__skip();
69 #else
70 git_thread thread;
71 void *result;
72
73 /* Ensure that the return value of the threadproc is returned. */
74 cl_git_pass(git_thread_create(&thread, return_normally, (void *)424242));
75 cl_git_pass(git_thread_join(&thread, &result));
76 cl_assert_equal_sz(424242, (size_t)result);
77
78 /* Ensure that the return value of `git_thread_exit` is returned. */
79 cl_git_pass(git_thread_create(&thread, exit_abruptly, (void *)232323));
80 cl_git_pass(git_thread_join(&thread, &result));
81 cl_assert_equal_sz(232323, (size_t)result);
82 #endif
83 }