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
|
start_test_helper() {
local endpoint="$1"
export CRSH_IPC_ENDPOINT="${endpoint}"
export CRSH_URL="dummy"
"${STORAGE_TEST_HELPER}" &
local attempts=0
while [ $attempts -lt 50 ]; do
if "${STORAGE_TEST_CLIENT}" "${endpoint}" ping >/dev/null 2>&1; then
return 0
fi
sleep 0.1
attempts=$((attempts + 1))
done
test_failed_internal "Test storage helper failed to start (no response to ping)"
}
SUITE_remote_helper_PROBE() {
if ! python3 --version >/dev/null 2>&1; then
echo "python3 is not available"
fi
}
SUITE_remote_helper_SETUP() {
unset CCACHE_NODIRECT
# Keep the helper alive long enough for the whole test case. A short
# timeout makes the direct-connection checks flaky on slower systems since
# the second compile is a local hit and doesn't touch the helper.
export CRSH_IDLE_TIMEOUT="30"
export CRSH_LOGFILE="ccache-storage-test.log"
generate_code 1 test.c
}
SUITE_remote_helper() {
# -------------------------------------------------------------------------
TEST "Helper auto-spawn and basic operations"
export CCACHE_REMOTE_STORAGE="test://dummy helper=${STORAGE_TEST_HELPER}"
# First compilation: miss, ccache spawns helper and stores
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_stat remote_storage_hit 0
expect_stat remote_storage_miss 1
expect_stat remote_storage_read_hit 0
expect_stat remote_storage_read_miss 2 # result + manifest
expect_stat remote_storage_write 2 # result + manifest
# Second compilation: local hit (helper stays alive)
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_stat remote_storage_hit 0
expect_stat remote_storage_miss 1
# Clear local cache
$CCACHE -C >/dev/null
expect_stat files_in_cache 0
# Third compilation: remote hit from spawned helper
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 2
expect_stat cache_miss 1
expect_stat files_in_cache 2 # fetched from helper
expect_stat remote_storage_hit 1
expect_stat remote_storage_miss 1
expect_stat remote_storage_read_hit 2 # result + manifest
expect_stat remote_storage_read_miss 2
expect_stat remote_storage_write 2
$CCACHE --stop-storage-helpers
# -------------------------------------------------------------------------
TEST "Helper reuse across compilations"
export CCACHE_REMOTE_STORAGE="test://dummy2 helper=${STORAGE_TEST_HELPER}"
# Multiple compilations should reuse same spawned helper
for i in 1 2 3; do
generate_code $i test.c
$CCACHE_COMPILE -c test.c
expect_stat cache_miss $i
done
expect_stat files_in_cache 6 # 3 results + 3 manifests
$CCACHE --stop-storage-helpers
# -------------------------------------------------------------------------
TEST "Direct crsh: connection"
local endpoint="test.sock"
if $HOST_OS_WINDOWS; then
endpoint="ccache-test-$$"
fi
start_test_helper "${endpoint}"
export CCACHE_REMOTE_STORAGE="crsh:${endpoint}"
# First compilation - miss, store to test helper
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_stat remote_storage_hit 0
expect_stat remote_storage_miss 1
expect_stat remote_storage_read_hit 0
expect_stat remote_storage_read_miss 2 # result + manifest
expect_stat remote_storage_write 2 # result + manifest
# Second compilation - local hit
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_stat remote_storage_hit 0
expect_stat remote_storage_miss 1
# Clear local cache
$CCACHE -C >/dev/null
expect_stat files_in_cache 0
# Third compilation - remote hit from test helper
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 2
expect_stat cache_miss 1
expect_stat files_in_cache 2 # fetched from test helper
expect_stat remote_storage_hit 1
expect_stat remote_storage_miss 1
expect_stat remote_storage_read_hit 2 # result + manifest
expect_stat remote_storage_read_miss 2
expect_stat remote_storage_write 2
# -------------------------------------------------------------------------
TEST "Connection failure handling"
local endpoint="nonexistent.sock"
if $HOST_OS_WINDOWS; then
endpoint="ccache-nonexistent-$$"
fi
# Don't start helper - test connection failure
export CCACHE_REMOTE_STORAGE="crsh:${endpoint}"
# Should fall back to local-only operation
$CCACHE_COMPILE -c test.c
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_stat remote_storage_error 1
}
|