void test_threads_basic__exit(void) { #ifndef GIT_THREADS clar__skip(); #else git_thread thread; void *result; /* Ensure that the return value of the threadproc is returned. */ cl_git_pass(git_thread_create(&thread, return_normally, (void *)424242)); cl_git_pass(git_thread_join(&thread, &result)); cl_assert_equal_sz(424242, (size_t)result); /* Ensure that the return value of `git_thread_exit` is returned. */ cl_git_pass(git_thread_create(&thread, return_normally, (void *)232323)); cl_git_pass(git_thread_join(&thread, &result)); cl_assert_equal_sz(232323, (size_t)result); #endif }
void test_threads_refdb__iterator(void) { int r, t; git_thread th[THREADS]; int id[THREADS]; git_oid head; git_reference *ref; char name[128]; git_refdb *refdb; g_repo = cl_git_sandbox_init("testrepo2"); cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); /* make a bunch of references */ for (r = 0; r < 200; ++r) { p_snprintf(name, sizeof(name), "refs/heads/direct-%03d", r); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL)); git_reference_free(ref); } cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); git_refdb_free(refdb); g_expected = 206; for (r = 0; r < REPEAT; ++r) { g_repo = cl_git_sandbox_reopen(); /* reopen to flush caches */ for (t = 0; t < THREADS; ++t) { id[t] = t; #ifdef GIT_THREADS cl_git_pass(git_thread_create(&th[t], iterate_refs, &id[t])); #else th[t] = t; iterate_refs(&id[t]); #endif } #ifdef GIT_THREADS for (t = 0; t < THREADS; ++t) { cl_git_pass(git_thread_join(&th[t], NULL)); } #endif memset(th, 0, sizeof(th)); } }
void test_threads_refdb__edit_while_iterate(void) { int r, t; int id[THREADS]; git_oid head; git_reference *ref; char name[128]; git_refdb *refdb; #ifdef GIT_THREADS git_thread th[THREADS]; #endif g_repo = cl_git_sandbox_init("testrepo2"); cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); /* make a bunch of references */ for (r = 0; r < 50; ++r) { p_snprintf(name, sizeof(name), "refs/heads/starter-%03d", r); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL)); git_reference_free(ref); } cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); git_refdb_free(refdb); g_expected = -1; g_repo = cl_git_sandbox_reopen(); /* reopen to flush caches */ for (t = 0; t < THREADS; ++t) { void *(*fn)(void *arg); switch (t & 0x3) { case 0: fn = create_refs; break; case 1: fn = delete_refs; break; default: fn = iterate_refs; break; } id[t] = t; /* It appears with all reflog writing changes, etc., that this * test has started to fail quite frequently, so let's disable it * for now by just running on a single thread... */ /* #ifdef GIT_THREADS */ /* cl_git_pass(git_thread_create(&th[t], fn, &id[t])); */ /* #else */ fn(&id[t]); /* #endif */ } #ifdef GIT_THREADS /* for (t = 0; t < THREADS; ++t) { */ /* cl_git_pass(git_thread_join(th[t], NULL)); */ /* } */ memset(th, 0, sizeof(th)); for (t = 0; t < THREADS; ++t) { id[t] = t; cl_git_pass(git_thread_create(&th[t], iterate_refs, &id[t])); } for (t = 0; t < THREADS; ++t) { cl_git_pass(git_thread_join(&th[t], NULL)); } #endif }
void test_threads_refdb__edit_while_iterate(void) { int r, t; struct th_data th_data[THREADS]; git_oid head; git_reference *ref; char name[128]; git_refdb *refdb; #ifdef GIT_THREADS git_thread th[THREADS]; #endif g_repo = cl_git_sandbox_init("testrepo2"); cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); /* make a bunch of references */ for (r = 0; r < 50; ++r) { p_snprintf(name, sizeof(name), "refs/heads/starter-%03d", r); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL)); git_reference_free(ref); } cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); git_refdb_free(refdb); g_expected = -1; g_repo = cl_git_sandbox_reopen(); /* reopen to flush caches */ for (t = 0; t < THREADS; ++t) { void *(*fn)(void *arg); switch (t & 0x3) { case 0: fn = create_refs; break; case 1: fn = delete_refs; break; default: fn = iterate_refs; break; } th_data[t].id = t; th_data[t].path = git_repository_path(g_repo); #ifdef GIT_THREADS cl_git_pass(git_thread_create(&th[t], fn, &th_data[t])); #else fn(&th_data[t]); #endif } #ifdef GIT_THREADS for (t = 0; t < THREADS; ++t) { cl_git_pass(git_thread_join(&th[t], NULL)); cl_git_thread_check(&th_data[t]); } memset(th, 0, sizeof(th)); for (t = 0; t < THREADS; ++t) { th_data[t].id = t; cl_git_pass(git_thread_create(&th[t], iterate_refs, &th_data[t])); } for (t = 0; t < THREADS; ++t) { cl_git_pass(git_thread_join(&th[t], NULL)); cl_git_thread_check(&th_data[t]); } #endif }