]>
Commit | Line | Data |
---|---|---|
1cb9b31e BS |
1 | #include "clar_libgit2.h" |
2 | ||
fdea219a | 3 | #include "thread_helpers.h" |
1cb9b31e BS |
4 | #include "cache.h" |
5 | ||
6 | ||
7 | static git_repository *g_repo; | |
8 | ||
1ca163ff SG |
9 | void test_threads_basic__initialize(void) |
10 | { | |
11 | g_repo = cl_git_sandbox_init("testrepo"); | |
1cb9b31e BS |
12 | } |
13 | ||
1ca163ff SG |
14 | void test_threads_basic__cleanup(void) |
15 | { | |
16 | cl_git_sandbox_cleanup(); | |
1cb9b31e BS |
17 | } |
18 | ||
19 | ||
1ca163ff SG |
20 | void test_threads_basic__cache(void) |
21 | { | |
ac3d33df | 22 | /* run several threads polling the cache at the same time */ |
1ca163ff | 23 | cl_assert(1 == 1); |
1cb9b31e | 24 | } |
cfd192b0 BS |
25 | |
26 | void test_threads_basic__multiple_init(void) | |
27 | { | |
28 | git_repository *nested_repo; | |
29 | ||
799e22ea | 30 | git_libgit2_init(); |
cfd192b0 BS |
31 | cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git"))); |
32 | git_repository_free(nested_repo); | |
33 | ||
799e22ea | 34 | git_libgit2_shutdown(); |
cfd192b0 BS |
35 | cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git"))); |
36 | git_repository_free(nested_repo); | |
37 | } | |
fdea219a CMN |
38 | |
39 | static void *set_error(void *dummy) | |
40 | { | |
ac3d33df | 41 | git_error_set(GIT_ERROR_INVALID, "oh no, something happened!\n"); |
fdea219a CMN |
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 | } | |
82f15896 | 51 | |
6367c58c | 52 | #ifdef GIT_THREADS |
82f15896 ET |
53 | static void *return_normally(void *param) |
54 | { | |
55 | return param; | |
56 | } | |
c25aa7cd PP |
57 | |
58 | static void *exit_abruptly(void *param) | |
59 | { | |
60 | git_thread_exit(param); | |
61 | return NULL; | |
62 | } | |
6367c58c | 63 | #endif |
82f15896 ET |
64 | |
65 | void test_threads_basic__exit(void) | |
66 | { | |
6367c58c ET |
67 | #ifndef GIT_THREADS |
68 | clar__skip(); | |
69 | #else | |
82f15896 ET |
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. */ | |
c25aa7cd | 79 | cl_git_pass(git_thread_create(&thread, exit_abruptly, (void *)232323)); |
82f15896 ET |
80 | cl_git_pass(git_thread_join(&thread, &result)); |
81 | cl_assert_equal_sz(232323, (size_t)result); | |
6367c58c ET |
82 | #endif |
83 | } |