diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/diff/diff_helpers.c | 19 | ||||
-rw-r--r-- | tests/diff/diff_helpers.h | 14 | ||||
-rw-r--r-- | tests/diff/workdir.c | 29 | ||||
-rw-r--r-- | tests/status/worktree.c | 32 | ||||
-rw-r--r-- | tests/trace/trace.c | 39 |
5 files changed, 64 insertions, 69 deletions
diff --git a/tests/diff/diff_helpers.c b/tests/diff/diff_helpers.c index 279cb20c5..5de9834ba 100644 --- a/tests/diff/diff_helpers.c +++ b/tests/diff/diff_helpers.c @@ -229,3 +229,22 @@ void diff_print_raw(FILE *fp, git_diff *diff) git_diff_print(diff, GIT_DIFF_FORMAT_RAW, git_diff_print_callback__to_file_handle, fp ? fp : stderr)); } + +void diff_perf_track_stats( + git_trace_level_t level, + void *cb_payload, + void *msg_payload, + const char *msg) +{ + diff_perf *data = cb_payload; + + if (!(level & GIT_TRACE_PERF)) + return; + + if (!strcmp("stat", msg)) + data->stat_calls += msg_payload ? *((size_t *)msg_payload) : 1; + else if (!strcmp("submodule_lookup", msg)) + data->submodule_lookups++; + else if (!strcmp("oid_calculation", msg)) + data->oid_calcs++; +} diff --git a/tests/diff/diff_helpers.h b/tests/diff/diff_helpers.h index bf21f4b1f..3ed538702 100644 --- a/tests/diff/diff_helpers.h +++ b/tests/diff/diff_helpers.h @@ -62,3 +62,17 @@ extern int diff_foreach_via_iterator( extern void diff_print(FILE *fp, git_diff *diff); extern void diff_print_raw(FILE *fp, git_diff *diff); + +#include "git2/trace.h" + +typedef struct { + size_t stat_calls; + size_t oid_calcs; + size_t submodule_lookups; +} diff_perf; + +extern void diff_perf_track_stats( + git_trace_level_t level, + void *cb_payload, + void *msg_payload, + const char *msg); diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c index 0fd41d3e0..952c9022b 100644 --- a/tests/diff/workdir.c +++ b/tests/diff/workdir.c @@ -1,40 +1,19 @@ #include "clar_libgit2.h" #include "diff_helpers.h" #include "repository.h" -#include <git2/trace.h> static git_repository *g_repo = NULL; #ifdef GIT_TRACE -static struct { - size_t stat_calls; - size_t oid_calcs; - size_t submodule_lookups; -} g_diff_perf; - -static void add_stats(git_trace_level_t level, const char *msg) -{ - const char *assign = strchr(msg, '='); - - GIT_UNUSED(level); - - if (!assign) - return; - - if (!strncmp("stat", msg, (assign - msg))) - g_diff_perf.stat_calls += atoi(assign + 1); - else if (!strncmp("submodule_lookup", msg, (assign - msg))) - g_diff_perf.submodule_lookups += atoi(assign + 1); - else if (!strncmp("oid_calculation", msg, (assign - msg))) - g_diff_perf.oid_calcs += atoi(assign + 1); -} +static diff_perf g_diff_perf; #endif void test_diff_workdir__initialize(void) { #ifdef GIT_TRACE memset(&g_diff_perf, 0, sizeof(g_diff_perf)); - cl_git_pass(git_trace_set(GIT_TRACE_TRACE, add_stats)); + cl_git_pass(git_trace_set( + GIT_TRACE_PERF, diff_perf_track_stats, &g_diff_perf)); #endif } @@ -42,7 +21,7 @@ void test_diff_workdir__cleanup(void) { cl_git_sandbox_cleanup(); #ifdef GIT_TRACE - cl_git_pass(git_trace_set(0, NULL)); + cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL)); #endif } diff --git a/tests/status/worktree.c b/tests/status/worktree.c index c1d6be982..06864ad59 100644 --- a/tests/status/worktree.c +++ b/tests/status/worktree.c @@ -5,38 +5,18 @@ #include "posix.h" #include "util.h" #include "path.h" -#include <git2/trace.h> +#include "../diff/diff_helpers.h" #ifdef GIT_TRACE -static struct { - size_t stat_calls; - size_t oid_calcs; - size_t submodule_lookups; -} g_diff_perf; - -static void add_stats(git_trace_level_t level, const char *msg) -{ - const char *assign = strchr(msg, '='); - - GIT_UNUSED(level); - - if (!assign) - return; - - if (!strncmp("stat", msg, (assign - msg))) - g_diff_perf.stat_calls += atoi(assign + 1); - else if (!strncmp("submodule_lookup", msg, (assign - msg))) - g_diff_perf.submodule_lookups += atoi(assign + 1); - else if (!strncmp("oid_calculation", msg, (assign - msg))) - g_diff_perf.oid_calcs += atoi(assign + 1); -} +static diff_perf g_diff_perf; #endif void test_status_worktree__initialize(void) { #ifdef GIT_TRACE memset(&g_diff_perf, 0, sizeof(g_diff_perf)); - cl_git_pass(git_trace_set(GIT_TRACE_TRACE, add_stats)); + cl_git_pass(git_trace_set( + GIT_TRACE_PERF, diff_perf_track_stats, &g_diff_perf)); #endif } @@ -50,7 +30,7 @@ void test_status_worktree__cleanup(void) { cl_git_sandbox_cleanup(); #ifdef GIT_TRACE - cl_git_pass(git_trace_set(0, NULL)); + cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL)); #endif } @@ -956,7 +936,5 @@ void test_status_worktree__update_stat_cache_0(void) cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls); cl_assert_equal_sz(0, g_diff_perf.oid_calcs); cl_assert_equal_sz(1, g_diff_perf.submodule_lookups); - - memset(&g_diff_perf, 0, sizeof(g_diff_perf)); #endif } diff --git a/tests/trace/trace.c b/tests/trace/trace.c index 87b325378..328539379 100644 --- a/tests/trace/trace.c +++ b/tests/trace/trace.c @@ -3,44 +3,49 @@ static int written = 0; -static void trace_callback(git_trace_level_t level, const char *message) +static void trace_callback( + git_trace_level_t level, + void *cb_payload, + void *msg_payload, + const char *msg) { - GIT_UNUSED(level); + GIT_UNUSED(level); GIT_UNUSED(msg_payload); - cl_assert(strcmp(message, "Hello world!") == 0); + cl_assert(strcmp(msg, "Hello world!") == 0); - written = 1; + if (cb_payload) + *((int *)cb_payload) = 1; } void test_trace_trace__initialize(void) { - git_trace_set(GIT_TRACE_INFO, trace_callback); + git_trace_set(GIT_TRACE_INFO_AND_BELOW, trace_callback, &written); written = 0; } void test_trace_trace__cleanup(void) { - git_trace_set(GIT_TRACE_NONE, NULL); + git_trace_set(GIT_TRACE_NONE, NULL, NULL); } void test_trace_trace__sets(void) { #ifdef GIT_TRACE - cl_assert(git_trace_level() == GIT_TRACE_INFO); + cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW); #endif } void test_trace_trace__can_reset(void) { #ifdef GIT_TRACE - cl_assert(git_trace_level() == GIT_TRACE_INFO); - cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback)); + cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW); + cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback, &written)); cl_assert(written == 0); - git_trace(GIT_TRACE_INFO, "Hello %s!", "world"); + git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world"); cl_assert(written == 0); - git_trace(GIT_TRACE_ERROR, "Hello %s!", "world"); + git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world"); cl_assert(written == 1); #endif } @@ -48,13 +53,13 @@ void test_trace_trace__can_reset(void) void test_trace_trace__can_unset(void) { #ifdef GIT_TRACE - cl_assert(git_trace_level() == GIT_TRACE_INFO); - cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL)); + cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW); + cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL)); cl_assert(git_trace_level() == GIT_TRACE_NONE); cl_assert(written == 0); - git_trace(GIT_TRACE_FATAL, "Hello %s!", "world"); + git_trace(GIT_TRACE_FATAL, NULL, "Hello %s!", "world"); cl_assert(written == 0); #endif } @@ -63,7 +68,7 @@ void test_trace_trace__skips_higher_level(void) { #ifdef GIT_TRACE cl_assert(written == 0); - git_trace(GIT_TRACE_DEBUG, "Hello %s!", "world"); + git_trace(GIT_TRACE_DEBUG, NULL, "Hello %s!", "world"); cl_assert(written == 0); #endif } @@ -72,7 +77,7 @@ void test_trace_trace__writes(void) { #ifdef GIT_TRACE cl_assert(written == 0); - git_trace(GIT_TRACE_INFO, "Hello %s!", "world"); + git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world"); cl_assert(written == 1); #endif } @@ -81,7 +86,7 @@ void test_trace_trace__writes_lower_level(void) { #ifdef GIT_TRACE cl_assert(written == 0); - git_trace(GIT_TRACE_ERROR, "Hello %s!", "world"); + git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world"); cl_assert(written == 1); #endif } |