File: hardlink.bash

package info (click to toggle)
ccache 4.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,192 kB
  • sloc: cpp: 47,336; asm: 28,570; sh: 8,709; ansic: 5,357; python: 685; perl: 68; makefile: 23
file content (137 lines) | stat: -rw-r--r-- 3,962 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
SUITE_hardlink_PROBE() {
    # Probe hard link across directories since AFS doesn't support those.
    mkdir dir
    touch dir/file1
    if ! ln dir/file1 file2 >/dev/null 2>&1; then
        echo "file system doesn't support hardlinks"
    fi
}

SUITE_hardlink() {
    # -------------------------------------------------------------------------
    TEST "CCACHE_HARDLINK"

    generate_code 1 test1.c

    $COMPILER -c -o reference_test1.o test1.c

    CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test1.c
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_stat files_in_cache 2
    expect_equal_object_files reference_test1.o test1.o

    mv test1.o test1.o.saved

    CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test1.c
    expect_stat preprocessed_cache_hit 1
    expect_stat cache_miss 1
    expect_stat files_in_cache 2
    if [ ! test1.o -ef test1.o.saved ]; then
        test_failed "Object files not hard linked"
    fi

    $CCACHE_COMPILE -c test1.c
    expect_stat preprocessed_cache_hit 2
    expect_stat cache_miss 1
    expect_stat files_in_cache 2

    if [ test1.o -ef test1.o.saved ]; then
        test_failed "Object files are hard linked"
    fi

    # -------------------------------------------------------------------------
    TEST "Corrupted file size is detected"

    generate_code 1 test1.c

    CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test1.c
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_stat files_in_cache 2

    mv test1.o test1.o.saved

    CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test1.c
    expect_stat preprocessed_cache_hit 1
    expect_stat cache_miss 1
    expect_stat files_in_cache 2

    # -------------------------------------------------------------------------
if $RUN_WIN_XFAIL; then
    TEST "Overwrite assembler"

    generate_code 1 test1.c
    $COMPILER -S -o test1.s test1.c

    $COMPILER -c -o reference_test1.o test1.s

    CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test1.s
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_stat files_in_cache 2

    generate_code 2 test1.c
    $COMPILER -S -o test1.s test1.c

    CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test1.s
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 2
    expect_stat files_in_cache 4

    generate_code 1 test1.c
    $COMPILER -S -o test1.s test1.c

    CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test1.s
    expect_stat preprocessed_cache_hit 1
    expect_stat cache_miss 2
    expect_stat files_in_cache 4
    expect_equal_object_files reference_test1.o test1.o
fi
    # -------------------------------------------------------------------------
if $RUN_WIN_XFAIL; then
    TEST "Automake depend move"

    unset CCACHE_NODIRECT

    generate_code 1 test1.c

    CCACHE_HARDLINK=1 CCACHE_DEPEND=1 $CCACHE_COMPILE -c -MMD -MF test1.d.tmp test1.c
    expect_stat direct_cache_hit 0
    mv test1.d.tmp test1.d || test_failed "first mv failed"

    CCACHE_HARDLINK=1 CCACHE_DEPEND=1 $CCACHE_COMPILE -c -MMD -MF test1.d.tmp test1.c
    expect_stat direct_cache_hit 1
    mv test1.d.tmp test1.d || test_failed "second mv failed"
fi
    # -------------------------------------------------------------------------
if $RUN_WIN_XFAIL; then
    TEST ".d file corrupted by compiler"

    unset CCACHE_NODIRECT
    export CCACHE_SLOPPINESS=include_file_mtime,include_file_ctime
    export CCACHE_HARDLINK=1

    echo "int x;" >test1.c

    $CCACHE_COMPILE -c -MMD test1.c
    expect_stat direct_cache_hit 0
    expect_stat cache_miss 1
    expect_content test1.d "test1.o: test1.c"

    touch test1.h
    echo '#include "test1.h"' >>test1.c

    $CCACHE_COMPILE -c -MMD test1.c
    expect_stat direct_cache_hit 0
    expect_stat cache_miss 2
    expect_content test1.d "test1.o: test1.c test1.h"

    echo "int x;" >test1.c

    $CCACHE_COMPILE -c -MMD test1.c
    expect_stat direct_cache_hit 1
    expect_stat cache_miss 2
    expect_content test1.d "test1.o: test1.c"
fi
}