Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-12-12 03:02:20 +0400
committerRussell Belfer <rb@github.com>2013-12-12 03:02:20 +0400
commit7697e54176ccab22ed6d4597d7256e9a1e6ff202 (patch)
tree69c1bdd91bcf767b28bd6bc5ea9612084c1a765c /tests/pack
parent8b22d862fb4419b219210027f18c1e97dd36fa8b (diff)
Test cancel from indexer progress callback
This adds tests that try canceling an indexer operation from within the progress callback. After writing the tests, I wanted to run this under valgrind and had a number of errors in that situation because mmap wasn't working. I added a CMake option to force emulation of mmap and consolidated the Amiga-specific code into that new place (so we don't actually need separate Amiga code now, just have to turn on -DNO_MMAP). Additionally, I made the indexer code propagate error codes more reliably than it used to.
Diffstat (limited to 'tests/pack')
-rw-r--r--tests/pack/indexer.c23
-rw-r--r--tests/pack/packbuilder.c25
2 files changed, 34 insertions, 14 deletions
diff --git a/tests/pack/indexer.c b/tests/pack/indexer.c
index 07963a9e7..084f8e666 100644
--- a/tests/pack/indexer.c
+++ b/tests/pack/indexer.c
@@ -11,7 +11,7 @@
* This is a packfile with three objects. The second is a delta which
* depends on the third, which is also a delta.
*/
-unsigned char out_of_order_pack[] = {
+static const unsigned char out_of_order_pack[] = {
0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03,
0x32, 0x78, 0x9c, 0x63, 0x67, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x76,
0xe6, 0x8f, 0xe8, 0x12, 0x9b, 0x54, 0x6b, 0x10, 0x1a, 0xee, 0x95, 0x10,
@@ -23,13 +23,13 @@ unsigned char out_of_order_pack[] = {
0x19, 0x87, 0x58, 0x80, 0x61, 0x09, 0x9a, 0x33, 0xca, 0x7a, 0x31, 0x92,
0x6f, 0xae, 0x66, 0x75
};
-unsigned int out_of_order_pack_len = 112;
+static const unsigned int out_of_order_pack_len = 112;
/*
* Packfile with two objects. The second is a delta against an object
* which is not in the packfile
*/
-unsigned char thin_pack[] = {
+static const unsigned char thin_pack[] = {
0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
0x32, 0x78, 0x9c, 0x63, 0x67, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x76,
0xe6, 0x8f, 0xe8, 0x12, 0x9b, 0x54, 0x6b, 0x10, 0x1a, 0xee, 0x95, 0x10,
@@ -38,18 +38,19 @@ unsigned char thin_pack[] = {
0x3a, 0x6f, 0x39, 0xd1, 0xfe, 0x66, 0x68, 0x6b, 0xa5, 0xe5, 0xe2, 0x97,
0xac, 0x94, 0x6c, 0x76, 0x0b, 0x04
};
-unsigned int thin_pack_len = 78;
+static const unsigned int thin_pack_len = 78;
-unsigned char base_obj[] = { 07, 076 };
-unsigned int base_obj_len = 2;
+static const unsigned char base_obj[] = { 07, 076 };
+static const unsigned int base_obj_len = 2;
void test_pack_indexer__out_of_order(void)
{
- git_indexer *idx;
- git_transfer_progress stats;
+ git_indexer *idx = 0;
+ git_transfer_progress stats = { 0 };
cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL));
- cl_git_pass(git_indexer_append(idx, out_of_order_pack, out_of_order_pack_len, &stats));
+ cl_git_pass(git_indexer_append(
+ idx, out_of_order_pack, out_of_order_pack_len, &stats));
cl_git_pass(git_indexer_commit(idx, &stats));
cl_assert_equal_i(stats.total_objects, 3);
@@ -61,8 +62,8 @@ void test_pack_indexer__out_of_order(void)
void test_pack_indexer__fix_thin(void)
{
- git_indexer *idx;
- git_transfer_progress stats;
+ git_indexer *idx = NULL;
+ git_transfer_progress stats = { 0 };
git_repository *repo;
git_odb *odb;
git_oid id, should_id;
diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c
index 1ae2322a5..53db81828 100644
--- a/tests/pack/packbuilder.c
+++ b/tests/pack/packbuilder.c
@@ -12,6 +12,7 @@ static git_packbuilder *_packbuilder;
static git_indexer *_indexer;
static git_vector _commits;
static int _commits_is_initialized;
+static git_transfer_progress _stats;
void test_pack_packbuilder__initialize(void)
{
@@ -20,6 +21,7 @@ void test_pack_packbuilder__initialize(void)
cl_git_pass(git_packbuilder_new(&_packbuilder, _repo));
cl_git_pass(git_vector_init(&_commits, 0, NULL));
_commits_is_initialized = 1;
+ memset(&_stats, 0, sizeof(_stats));
}
void test_pack_packbuilder__cleanup(void)
@@ -184,11 +186,10 @@ void test_pack_packbuilder__permissions_readwrite(void)
test_write_pack_permission(0666, 0666);
}
-static git_transfer_progress stats;
static int foreach_cb(void *buf, size_t len, void *payload)
{
git_indexer *idx = (git_indexer *) payload;
- cl_git_pass(git_indexer_append(idx, buf, len, &stats));
+ cl_git_pass(git_indexer_append(idx, buf, len, &_stats));
return 0;
}
@@ -199,6 +200,24 @@ void test_pack_packbuilder__foreach(void)
seed_packbuilder();
cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL));
cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx));
- cl_git_pass(git_indexer_commit(idx, &stats));
+ cl_git_pass(git_indexer_commit(idx, &_stats));
+ git_indexer_free(idx);
+}
+
+static int foreach_cancel_cb(void *buf, size_t len, void *payload)
+{
+ git_indexer *idx = (git_indexer *)payload;
+ cl_git_pass(git_indexer_append(idx, buf, len, &_stats));
+ return (_stats.total_objects > 2) ? -1111 : 0;
+}
+
+void test_pack_packbuilder__foreach_with_cancel(void)
+{
+ git_indexer *idx;
+
+ seed_packbuilder();
+ cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL));
+ cl_git_fail_with(
+ git_packbuilder_foreach(_packbuilder, foreach_cancel_cb, idx), -1111);
git_indexer_free(idx);
}