-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerfile.test
More file actions
219 lines (187 loc) · 5.34 KB
/
Copy pathContainerfile.test
File metadata and controls
219 lines (187 loc) · 5.34 KB
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
# Containerfile for testing sqlite_sexp with AddressSanitizer and Valgrind
#
# Build:
# podman build -f Containerfile.test -t sqlite_sexp:test .
#
# Run tests with ASAN:
# podman run --rm sqlite_sexp:test asan
#
# Run tests with Valgrind:
# podman run --rm sqlite_sexp:test valgrind
#
# Run all tests:
# podman run --rm sqlite_sexp:test all
FROM alpine:3.23
# Install build dependencies
# Alpine 3.23 has SQLite 3.51.1 with full JSONB support
RUN apk add --no-cache \
build-base \
clang \
compiler-rt \
sqlite \
sqlite-dev \
valgrind
# Set working directory
WORKDIR /app
# Copy source code
COPY src/ ./src/
COPY test/ ./test/
COPY Makefile ./
# Build normal version for basic test
RUN make clean && make
# Build ASAN version
RUN make clean && make asan
# Create test runner script
RUN cat > /app/run_tests.sh << 'SCRIPT'
#!/bin/sh
set -e
MODE="${1:-all}"
run_basic_tests() {
echo "=========================================="
echo "Running basic tests (normal build)..."
echo "=========================================="
echo "SQLite version: $(sqlite3 --version)"
make clean && make
sqlite3 < test/test_basic.sql
sqlite3 < test/test_comprehensive.sql
echo ""
echo "Basic tests PASSED"
}
run_asan_tests() {
echo "=========================================="
echo "Running tests with AddressSanitizer..."
echo "=========================================="
echo "SQLite version: $(sqlite3 --version)"
# Find ASAN runtime library - check multiple locations for different Alpine/LLVM versions
ASAN_LIB=""
for search_path in /usr/lib/llvm*/lib/clang/*/lib/*-linux-musl /usr/lib/clang/*/lib/*-linux-musl /usr/lib/clang; do
found=$(find $search_path -name 'libclang_rt.asan*.so' 2>/dev/null | head -1)
if [ -n "$found" ] && [ -f "$found" ]; then
ASAN_LIB="$found"
break
fi
done
if [ -z "$ASAN_LIB" ]; then
echo "ASAN runtime not found on this system"
echo "Skipping ASAN tests - using Valgrind for memory checking instead"
echo ""
echo "ASAN tests SKIPPED"
return 0
fi
ASAN_LIB_DIR=$(dirname "$ASAN_LIB")
echo "Found ASAN runtime: $ASAN_LIB"
echo "ASAN library directory: $ASAN_LIB_DIR"
# Build extension with ASAN and shared runtime
make clean && make asan
# Configure ASAN options
# - detect_leaks=0: Leak detection has issues with musl libc
# - abort_on_error=1: Make errors fatal
# - symbolize=1: Show symbols in stack traces
# - verify_asan_link_order=0: Required for LD_PRELOAD approach
export ASAN_OPTIONS="detect_leaks=0:abort_on_error=1:symbolize=1:verify_asan_link_order=0"
export LD_PRELOAD="$ASAN_LIB"
export LD_LIBRARY_PATH="$ASAN_LIB_DIR:${LD_LIBRARY_PATH:-}"
echo "ASAN_OPTIONS: $ASAN_OPTIONS"
echo "LD_PRELOAD: $LD_PRELOAD"
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
echo ""
echo "--- Running test_basic.sql ---"
sqlite3 < test/test_basic.sql
echo ""
echo "--- Running test_comprehensive.sql ---"
sqlite3 < test/test_comprehensive.sql
unset LD_PRELOAD
unset LD_LIBRARY_PATH
unset ASAN_OPTIONS
echo ""
echo "ASAN tests PASSED - no memory errors detected"
}
run_valgrind_tests() {
echo "=========================================="
echo "Running tests with Valgrind..."
echo "=========================================="
echo "SQLite version: $(sqlite3 --version)"
make clean && make debug
echo "--- Running test_basic.sql with Valgrind ---"
valgrind --leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--error-exitcode=1 \
--suppressions=/app/valgrind.supp \
sqlite3 < test/test_basic.sql
echo ""
echo "--- Running test_comprehensive.sql with Valgrind ---"
valgrind --leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--error-exitcode=1 \
--suppressions=/app/valgrind.supp \
sqlite3 < test/test_comprehensive.sql
echo ""
echo "Valgrind tests PASSED - no memory errors detected"
}
case "$MODE" in
basic)
run_basic_tests
;;
asan)
run_asan_tests
;;
valgrind)
run_valgrind_tests
;;
all)
run_basic_tests
echo ""
run_asan_tests
echo ""
run_valgrind_tests
echo ""
echo "=========================================="
echo "ALL TESTS PASSED"
echo "=========================================="
;;
*)
echo "Usage: $0 {basic|asan|valgrind|all}"
exit 1
;;
esac
SCRIPT
RUN chmod +x /app/run_tests.sh
# Create Valgrind suppressions file for SQLite internals
RUN cat > /app/valgrind.supp << 'SUPP'
# Valgrind suppressions for SQLite internals
# Some SQLite allocations may appear as leaks but are intentional caching
{
sqlite3_initialize
Memcheck:Leak
...
fun:sqlite3_initialize
}
{
sqlite3_open
Memcheck:Leak
...
fun:sqlite3_open*
}
{
sqlite3_prepare
Memcheck:Leak
...
fun:sqlite3_prepare*
}
{
dlopen_leaks
Memcheck:Leak
...
fun:dlopen*
}
{
sqlite3_extension_init
Memcheck:Leak
...
fun:sqlite3_extension_init
}
SUPP
ENTRYPOINT ["/app/run_tests.sh"]
CMD ["all"]