]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5351-unpack-large-objects.sh
leak tests: mark passing SANITIZE=leak tests as leak-free
[thirdparty/git.git] / t / t5351-unpack-large-objects.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2022 Han Xin
4 #
5
6 test_description='git unpack-objects with large objects'
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 prepare_dest () {
12 test_when_finished "rm -rf dest.git" &&
13 git init --bare dest.git &&
14 git -C dest.git config core.bigFileThreshold "$1"
15 }
16
17 test_expect_success "create large objects (1.5 MB) and PACK" '
18 test-tool genrandom foo 1500000 >big-blob &&
19 test_commit --append foo big-blob &&
20 test-tool genrandom bar 1500000 >big-blob &&
21 test_commit --append bar big-blob &&
22 PACK=$(echo HEAD | git pack-objects --revs pack) &&
23 git verify-pack -v pack-$PACK.pack >out &&
24 sed -n -e "s/^\([0-9a-f][0-9a-f]*\).*\(commit\|tree\|blob\).*/\1/p" \
25 <out >obj-list
26 '
27
28 test_expect_success 'set memory limitation to 1MB' '
29 GIT_ALLOC_LIMIT=1m &&
30 export GIT_ALLOC_LIMIT
31 '
32
33 test_expect_success 'unpack-objects failed under memory limitation' '
34 prepare_dest 2m &&
35 test_must_fail git -C dest.git unpack-objects <pack-$PACK.pack 2>err &&
36 grep "fatal: attempting to allocate" err
37 '
38
39 test_expect_success 'unpack-objects works with memory limitation in dry-run mode' '
40 prepare_dest 2m &&
41 git -C dest.git unpack-objects -n <pack-$PACK.pack &&
42 test_stdout_line_count = 0 find dest.git/objects -type f &&
43 test_dir_is_empty dest.git/objects/pack
44 '
45
46 test_expect_success 'unpack big object in stream' '
47 prepare_dest 1m &&
48 git -C dest.git unpack-objects <pack-$PACK.pack &&
49 test_dir_is_empty dest.git/objects/pack
50 '
51
52 BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
53
54 test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' '
55 prepare_dest 1m &&
56 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
57 git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack &&
58 grep fsync/hardware-flush trace2.txt &&
59 test_dir_is_empty dest.git/objects/pack &&
60 git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current &&
61 cmp obj-list current
62 '
63
64 test_expect_success 'do not unpack existing large objects' '
65 prepare_dest 1m &&
66 git -C dest.git index-pack --stdin <pack-$PACK.pack &&
67 git -C dest.git unpack-objects <pack-$PACK.pack &&
68
69 # The destination came up with the exact same pack...
70 DEST_PACK=$(echo dest.git/objects/pack/pack-*.pack) &&
71 test_cmp pack-$PACK.pack $DEST_PACK &&
72
73 # ...and wrote no loose objects
74 test_stdout_line_count = 0 find dest.git/objects -type f ! -name "pack-*"
75 '
76
77 test_done