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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
start_http_server() {
local port="$1"
local cache_dir="$2"
local credentials="$3" # optional parameter
mkdir -p "${cache_dir}"
"${HTTP_SERVER}" --bind localhost --directory "${cache_dir}" "${port}" \
${credentials:+--basic-auth ${credentials}} \
&>http-server.log &
"${HTTP_CLIENT}" "http://localhost:${port}" &>http-client.log \
${credentials:+--basic-auth ${credentials}} \
|| test_failed_internal "Cannot connect to server"
}
maybe_start_ipv6_http_server() {
local port="$1"
local cache_dir="$2"
local credentials="$3" # optional parameter
mkdir -p "${cache_dir}"
"${HTTP_SERVER}" --bind "::1" --directory "${cache_dir}" "${port}" \
${credentials:+--basic-auth ${credentials}} \
&>http-server.log &
"${HTTP_CLIENT}" "http://[::1]:${port}" &>http-client.log \
${credentials:+--basic-auth ${credentials}} \
|| return 1
}
SUITE_remote_http_PROBE() {
if ! "${HTTP_SERVER}" --help >/dev/null 2>&1; then
echo "cannot execute ${HTTP_SERVER} - Python 3 might be missing"
fi
}
SUITE_remote_http_SETUP() {
unset CCACHE_NODIRECT
generate_code 1 test.c
}
SUITE_remote_http() {
# -------------------------------------------------------------------------
TEST "Subdirs layout"
start_http_server 12780 remote
export CCACHE_REMOTE_STORAGE="http://localhost:12780"
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
subdirs=$(find remote -type d | wc -l)
if [ "${subdirs}" -lt 2 ]; then # "remote" itself counts as one
test_failed "Expected subdirectories in remote"
fi
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
$CCACHE -C >/dev/null
expect_stat files_in_cache 0
expect_file_count 2 '*' remote # result + manifest
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 2
expect_stat cache_miss 1
expect_stat files_in_cache 2 # fetched from remote
expect_file_count 2 '*' remote # result + manifest
# -------------------------------------------------------------------------
TEST "Flat layout"
start_http_server 12780 remote
export CCACHE_REMOTE_STORAGE="http://localhost:12780|layout=flat"
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
subdirs=$(find remote -type d | wc -l)
if [ "${subdirs}" -ne 1 ]; then # "remote" itself counts as one
test_failed "Expected no subdirectories in remote"
fi
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
$CCACHE -C >/dev/null
expect_stat files_in_cache 0
expect_file_count 2 '*' remote # result + manifest
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 2
expect_stat cache_miss 1
expect_stat files_in_cache 2 # fetched from remote
expect_file_count 2 '*' remote # result + manifest
# -------------------------------------------------------------------------
TEST "Bazel layout"
start_http_server 12780 remote
mkdir remote/ac
export CCACHE_REMOTE_STORAGE="http://localhost:12780|layout=bazel"
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote/ac # result + manifest
if [ "$(ls remote/ac | grep -Ec '^[0-9a-f]{64}$')" -ne 2 ]; then
test_failed "Bazel layout filenames not as expected"
fi
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote/ac # result + manifest
$CCACHE -C >/dev/null
expect_stat files_in_cache 0
expect_file_count 2 '*' remote/ac # result + manifest
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 2
expect_stat cache_miss 1
expect_stat files_in_cache 2 # fetched from remote
expect_file_count 2 '*' remote/ac # result + manifest
# -------------------------------------------------------------------------
TEST "Basic auth"
start_http_server 12780 remote "somebody:secret123"
export CCACHE_REMOTE_STORAGE="http://somebody:secret123@localhost:12780"
CCACHE_DEBUG=1 $CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
expect_not_contains test.o.*.ccache-log secret123
# -------------------------------------------------------------------------
# This test fails sporadically.
# Mostly with MSVC 32 bit, but from time to time also with all other
# Windows test runs.
# Probably the http-server is doing something wrong here.
if $RUN_WIN_XFAIL; then
TEST "Basic auth required"
start_http_server 12780 remote "somebody:secret123"
# no authentication configured on client
export CCACHE_REMOTE_STORAGE="http://localhost:12780"
CCACHE_DEBUG=1 $CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 0 '*' remote # result + manifest
expect_contains test.o.*.ccache-log "status code: 401"
fi
# -------------------------------------------------------------------------
# This test fails sporadically.
# Mostly with MSVC 32 bit, but from time to time also with all other
# Windows test runs.
# Probably the http-server is doing something wrong here.
if $RUN_WIN_XFAIL; then
TEST "Basic auth failed"
start_http_server 12780 remote "somebody:secret123"
export CCACHE_REMOTE_STORAGE="http://somebody:wrong@localhost:12780"
CCACHE_DEBUG=1 $CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 0 '*' remote # result + manifest
expect_not_contains test.o.*.ccache-log secret123
expect_contains test.o.*.ccache-log "status code: 401"
fi
# -------------------------------------------------------------------------
TEST "Port sharding"
start_http_server 12780 remote
export CCACHE_REMOTE_STORAGE="http://localhost:*|shards=12780"
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
subdirs=$(find remote -type d | wc -l)
if [ "${subdirs}" -lt 2 ]; then # "remote" itself counts as one
test_failed "Expected subdirectories in remote"
fi
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
# -------------------------------------------------------------------------
TEST "IPv6 address"
if maybe_start_ipv6_http_server 12780 remote; then
export CCACHE_REMOTE_STORAGE="http://[::1]:12780"
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' remote # result + manifest
$CCACHE -C >/dev/null
expect_stat files_in_cache 0
expect_file_count 2 '*' remote # result + manifest
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 2
expect_stat cache_miss 1
expect_stat files_in_cache 2 # fetched from remote
expect_file_count 2 '*' remote # result + manifest
fi
}
|