summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/diff/workdir.c66
-rw-r--r--tests/status/worktree.c91
2 files changed, 129 insertions, 28 deletions
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 9e4608e9d..a225ebc89 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -1,21 +1,43 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
#include "repository.h"
-
-#ifdef GIT_PERF
-/* access to diff usage statistics */
-# include "diff.h"
-#endif
+#include <git2/trace.h>
static git_repository *g_repo = NULL;
+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);
+}
+
void test_diff_workdir__initialize(void)
{
+ memset(&g_diff_perf, 0, sizeof(g_diff_perf));
+ cl_git_pass(git_trace_set(GIT_TRACE_TRACE, add_stats));
}
void test_diff_workdir__cleanup(void)
{
cl_git_sandbox_cleanup();
+ cl_git_pass(git_trace_set(0, NULL));
}
void test_diff_workdir__to_index(void)
@@ -64,11 +86,11 @@ void test_diff_workdir__to_index(void)
cl_assert_equal_i(4, exp.line_adds);
cl_assert_equal_i(5, exp.line_dels);
-#ifdef GIT_PERF
+#ifdef GIT_TRACE
cl_assert_equal_sz(
- 13 /* in root */ + 3 /* in subdir */, diff->stat_calls);
- cl_assert_equal_sz(5, diff->oid_calculations);
- cl_assert_equal_sz(1, diff->submodule_lookups);
+ 13 /* in root */ + 3 /* in subdir */, g_diff_perf.stat_calls);
+ cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
+ cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
#endif
}
@@ -1525,6 +1547,8 @@ static void basic_diff_status(git_diff **out, const git_diff_options *opts)
{
diff_expects exp;
+ memset(&g_diff_perf, 0, sizeof(g_diff_perf));
+
cl_git_pass(git_diff_index_to_workdir(out, g_repo, NULL, opts));
memset(&exp, 0, sizeof(exp));
@@ -1558,10 +1582,10 @@ void test_diff_workdir__can_update_index(void)
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
basic_diff_status(&diff, &opts);
-#ifdef GIT_PERF
- cl_assert_equal_sz(diff->stat_calls, 13 + 3);
- cl_assert_equal_sz(diff->oid_calculations, 5);
- cl_assert_equal_sz(diff->submodule_lookups, 1);
+#ifdef GIT_TRACE
+ cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
+ cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
+ cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
#endif
git_diff_free(diff);
@@ -1570,10 +1594,10 @@ void test_diff_workdir__can_update_index(void)
opts.flags |= GIT_DIFF_UPDATE_INDEX;
basic_diff_status(&diff, &opts);
-#ifdef GIT_PERF
- cl_assert_equal_sz(diff->stat_calls, 13 + 3);
- cl_assert_equal_sz(diff->oid_calculations, 5);
- cl_assert_equal_sz(diff->submodule_lookups, 1);
+#ifdef GIT_TRACE
+ cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
+ cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
+ cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
#endif
git_diff_free(diff);
@@ -1581,10 +1605,10 @@ void test_diff_workdir__can_update_index(void)
/* now if we do it again, we should see fewer OID calculations */
basic_diff_status(&diff, &opts);
-#ifdef GIT_PERF
- cl_assert_equal_sz(diff->stat_calls, 13 + 3);
- cl_assert_equal_sz(diff->oid_calculations, 0); /* Yay */
- cl_assert_equal_sz(diff->submodule_lookups, 1);
+#ifdef GIT_TRACE
+ cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
+ cl_assert_equal_sz(0, g_diff_perf.oid_calcs); /* Yay */
+ cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
#endif
git_diff_free(diff);
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index f51c61864..0b94fb1a0 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -5,6 +5,36 @@
#include "posix.h"
#include "util.h"
#include "path.h"
+#include <git2/trace.h>
+
+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);
+}
+
+void test_status_worktree__initialize(void)
+{
+ memset(&g_diff_perf, 0, sizeof(g_diff_perf));
+ cl_git_pass(git_trace_set(GIT_TRACE_TRACE, add_stats));
+}
/**
* Cleanup
@@ -15,6 +45,7 @@
void test_status_worktree__cleanup(void)
{
cl_git_sandbox_cleanup();
+ cl_git_pass(git_trace_set(0, NULL));
}
/**
@@ -40,11 +71,15 @@ void test_status_worktree__whole_repository(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
-void assert_show(const int entry_counts, const char *entry_paths[],
- const unsigned int entry_statuses[], git_status_show_t show)
+void assert_show(
+ const int entry_counts,
+ const char *entry_paths[],
+ const unsigned int entry_statuses[],
+ git_repository *repo,
+ git_status_show_t show,
+ unsigned int extra_flags)
{
status_entry_counts counts;
- git_repository *repo = cl_git_sandbox_init("status");
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
memset(&counts, 0x0, sizeof(status_entry_counts));
@@ -52,7 +87,7 @@ void assert_show(const int entry_counts, const char *entry_paths[],
counts.expected_paths = entry_paths;
counts.expected_statuses = entry_statuses;
- opts.flags = GIT_STATUS_OPT_DEFAULTS;
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | extra_flags;
opts.show = show;
cl_git_pass(
@@ -67,19 +102,19 @@ void assert_show(const int entry_counts, const char *entry_paths[],
void test_status_worktree__show_index_and_workdir(void)
{
assert_show(entry_count0, entry_paths0, entry_statuses0,
- GIT_STATUS_SHOW_INDEX_AND_WORKDIR);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
}
void test_status_worktree__show_index_only(void)
{
assert_show(entry_count5, entry_paths5, entry_statuses5,
- GIT_STATUS_SHOW_INDEX_ONLY);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_INDEX_ONLY, 0);
}
void test_status_worktree__show_workdir_only(void)
{
assert_show(entry_count6, entry_paths6, entry_statuses6,
- GIT_STATUS_SHOW_WORKDIR_ONLY);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_WORKDIR_ONLY, 0);
}
/* this test is equivalent to t18-status.c:statuscb1 */
@@ -877,3 +912,45 @@ void test_status_worktree__long_filenames(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
+/* The update stat cache tests mostly just mirror other tests and try
+ * to make sure that updating the stat cache doesn't change the results
+ * while reducing the amount of work that needs to be done
+ */
+
+void test_status_worktree__update_stat_cache_0(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+
+ assert_show(entry_count0, entry_paths0, entry_statuses0,
+ repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+
+#ifdef GIT_TRACE
+ cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
+ cl_assert_equal_sz(5, 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
+
+ assert_show(entry_count0, entry_paths0, entry_statuses0,
+ repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_OPT_UPDATE_INDEX);
+
+#ifdef GIT_TRACE
+ cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
+ cl_assert_equal_sz(5, 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
+
+ assert_show(entry_count0, entry_paths0, entry_statuses0,
+ repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+
+#ifdef GIT_TRACE
+ 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
+}