-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-builds.sh
More file actions
executable file
·449 lines (383 loc) · 13.3 KB
/
Copy pathtest-builds.sh
File metadata and controls
executable file
·449 lines (383 loc) · 13.3 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!/bin/bash
set -euo pipefail
# FFmpeg Multi-Platform Test Script
# Tests ffmpeg builds across different OS/architecture combinations
# Uses QEMU for ARM emulation in Docker
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
FFMPEG_VERSION="8.0"
GITHUB_REPO="owncast/ffmpeg-builds"
RELEASE_TAG="latest"
# Platforms to test (OS/arch/variant)
# Format: "os:arch:variant:docker_image:tag:platform"
# static builds must run everywhere, including old glibc (debian 11 / ubuntu 20.04) and musl (alpine).
# vaapi builds are dynamically linked against glibc >= 2.38, so only new distros apply.
LINUX_PLATFORMS=(
"linux:amd64:static:alpine:3.19:linux/amd64"
"linux:amd64:static:debian:11:linux/amd64"
"linux:amd64:static:debian:12:linux/amd64"
"linux:amd64:static:debian:13:linux/amd64"
"linux:amd64:static:ubuntu:20.04:linux/amd64"
"linux:amd64:static:ubuntu:24.04:linux/amd64"
"linux:amd64:static:fedora:latest:linux/amd64"
"linux:amd64:vaapi:ubuntu:24.04:linux/amd64"
"linux:amd64:vaapi:debian:13:linux/amd64"
"linux:amd64:vaapi:fedora:latest:linux/amd64"
"linux:arm64:static:alpine:3.19:linux/arm64"
"linux:arm64:static:debian:11:linux/arm64"
"linux:arm64:static:debian:12:linux/arm64"
"linux:arm64:static:debian:13:linux/arm64"
"linux:arm64:static:ubuntu:20.04:linux/arm64"
"linux:arm64:static:ubuntu:24.04:linux/arm64"
"linux:arm64:static:fedora:latest:linux/arm64"
"linux:arm64:vaapi:ubuntu:24.04:linux/arm64"
"linux:arm64:vaapi:debian:13:linux/arm64"
"linux:arm64:vaapi:fedora:latest:linux/arm64"
)
# Darwin platforms (cross-compiled, cannot be tested in Docker)
DARWIN_PLATFORMS=(
"darwin:amd64"
"darwin:arm64"
)
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_header() {
echo ""
echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
}
# Check if required tools are installed
check_dependencies() {
local missing=()
if ! command -v docker &> /dev/null; then
missing+=("docker")
fi
if [ ${#missing[@]} -ne 0 ]; then
log_error "Missing required dependencies: ${missing[*]}"
exit 1
fi
}
# Setup QEMU for multi-architecture support
setup_qemu() {
log_info "Setting up QEMU for multi-architecture Docker builds..."
# Check if qemu is already registered
if docker run --rm --privileged multiarch/qemu-user-static --reset -p yes &> /dev/null; then
log_info "QEMU binfmt handlers registered successfully"
else
log_warn "Could not register QEMU handlers (may already be set up or require privileges)"
fi
}
# Download ffmpeg artifact for a specific platform
# Args: $1=os, $2=arch, $3=variant (optional)
get_artifact_url() {
local os="$1"
local arch="$2"
local variant="${3:-}"
local filename="ffmpeg${FFMPEG_VERSION}-${os}-${arch}"
if [ -n "$variant" ]; then
filename="${filename}-${variant}"
fi
filename="${filename}.tar.gz"
if [ "$RELEASE_TAG" = "latest" ]; then
echo "https://github.com/${GITHUB_REPO}/releases/latest/download/${filename}"
else
echo "https://github.com/${GITHUB_REPO}/releases/download/${RELEASE_TAG}/${filename}"
fi
}
# Verify linkage of a linux binary on the host (readelf works cross-arch).
# static builds must have no dynamic interpreter; vaapi builds are expected to be dynamic.
# Args: $1=os, $2=arch, $3=variant
verify_linkage() {
local os="$1" arch="$2" variant="$3"
local test_name="${os}-${arch}-${variant}"
if ! command -v readelf &> /dev/null; then
log_warn "readelf not available; skipping linkage check for ${test_name}"
return 0
fi
local url tmp
url=$(get_artifact_url "$os" "$arch" "$variant")
tmp=$(mktemp -d)
# shellcheck disable=SC2064
trap "rm -rf ${tmp}" RETURN
if ! curl -fsSL "$url" | tar -xz -C "$tmp"; then
log_error "Linkage check: download failed for ${test_name}"
return 1
fi
if [ "$variant" = "static" ]; then
if readelf -l "${tmp}/ffmpeg" | grep -q 'INTERP'; then
log_error "Linkage check FAILED: ${test_name} claims static but has a dynamic interpreter"
return 1
fi
log_info "Linkage check passed: ${test_name} is statically linked"
else
local glibc_floor
glibc_floor=$(readelf --dyn-syms "${tmp}/ffmpeg" 2>/dev/null | grep -oE 'GLIBC_[0-9.]+' | sort -Vu | tail -1)
log_info "Linkage check: ${test_name} is dynamically linked (requires ${glibc_floor:-unknown glibc})"
fi
return 0
}
# Test a Linux platform in Docker
# Args: $1=os, $2=arch, $3=variant, $4=docker_image, $5=docker_tag, $6=platform
test_linux_platform() {
local os="$1"
local arch="$2"
local variant="$3"
local docker_image="$4"
local docker_tag="$5"
local platform="$6"
local artifact_url
artifact_url=$(get_artifact_url "$os" "$arch" "$variant")
local test_name="${os}-${arch}-${variant}"
local container_name="ffmpeg-test-${test_name}"
log_header "Testing: ${test_name} on ${docker_image}:${docker_tag} (${platform})"
log_info "Artifact URL: ${artifact_url}"
log_info "Docker image: ${docker_image}:${docker_tag}"
log_info "Platform: ${platform}"
# Create test script to run inside container
local test_script='
set -e
echo "=== System Information ==="
uname -a
echo ""
echo "=== Downloading ffmpeg ==="
cd /tmp
if command -v curl &> /dev/null; then
curl -fsSL -o ffmpeg.tar.gz "'"${artifact_url}"'"
elif command -v wget &> /dev/null; then
wget -q -O ffmpeg.tar.gz "'"${artifact_url}"'"
else
echo "ERROR: No curl or wget available"
exit 1
fi
echo "Download complete"
echo ""
echo "=== Extracting ffmpeg ==="
tar -xzf ffmpeg.tar.gz
chmod +x ffmpeg
ls -la ffmpeg
echo ""
echo "=== FFmpeg Version ==="
./ffmpeg -version
echo ""
echo "=== Generating test MP4 ==="
# Generate a 3-second test video with color bars and tone
./ffmpeg -y \
-f lavfi -i "testsrc=duration=3:size=640x480:rate=30" \
-f lavfi -i "sine=frequency=440:duration=3" \
-c:v libx264 -preset ultrafast -crf 23 \
-c:a aac -b:a 128k \
-pix_fmt yuv420p \
test_output.mp4
echo ""
echo "=== Verifying output file ==="
ls -la test_output.mp4
./ffmpeg -i test_output.mp4 -hide_banner 2>&1 | head -20
echo ""
echo "=== TEST PASSED ==="
'
# Run the test in Docker
log_info "Starting Docker container..."
# Remove existing container if it exists
docker rm -f "${container_name}" 2>/dev/null || true
local docker_cmd="docker run --rm --name ${container_name} --platform ${platform}"
# Add curl/wget and required libraries based on image type and variant
if [[ "$docker_image" == "alpine"* ]]; then
docker_cmd+=" ${docker_image}:${docker_tag} sh -c 'apk add --no-cache curl > /dev/null 2>&1 && ${test_script}'"
elif [[ "$docker_image" == "fedora"* ]]; then
local extra_packages="curl"
if [[ "$variant" == "vaapi" ]]; then
extra_packages="curl libva"
fi
docker_cmd+=" ${docker_image}:${docker_tag} bash -c 'dnf install -y ${extra_packages} > /dev/null 2>&1 && ${test_script}'"
else
# For vaapi builds, we need to install libva libraries
local extra_packages="curl"
if [[ "$variant" == "vaapi" ]]; then
extra_packages="curl libva2 libva-drm2"
fi
docker_cmd+=" ${docker_image}:${docker_tag} bash -c 'apt-get update > /dev/null 2>&1 && apt-get install -y ${extra_packages} > /dev/null 2>&1 && ${test_script}'"
fi
if eval "${docker_cmd}"; then
log_info "Test PASSED for ${test_name}"
return 0
else
log_error "Test FAILED for ${test_name}"
return 1
fi
}
# Test Darwin platforms (download only, cannot execute)
test_darwin_platform() {
local os="$1"
local arch="$2"
local artifact_url
artifact_url=$(get_artifact_url "$os" "$arch")
local test_name="${os}-${arch}"
log_header "Testing (download only): ${test_name}"
log_info "Artifact URL: ${artifact_url}"
log_warn "Darwin binaries cannot be executed in Docker - download test only"
# Download and verify the archive
local temp_dir
temp_dir=$(mktemp -d)
trap "rm -rf ${temp_dir}" RETURN
log_info "Downloading artifact..."
if curl -fsSL -o "${temp_dir}/ffmpeg.tar.gz" "${artifact_url}"; then
log_info "Download successful"
log_info "Extracting and verifying..."
tar -xzf "${temp_dir}/ffmpeg.tar.gz" -C "${temp_dir}"
if [ -f "${temp_dir}/ffmpeg" ]; then
log_info "Binary extracted successfully"
ls -la "${temp_dir}/ffmpeg"
file "${temp_dir}/ffmpeg" 2>/dev/null || true
log_info "Test PASSED for ${test_name} (download verification only)"
return 0
else
log_error "Binary not found in archive"
return 1
fi
else
log_error "Download failed for ${test_name}"
return 1
fi
}
# Parse command line arguments
SKIP_QEMU_SETUP=false
TEST_LINUX=true
TEST_DARWIN=true
PARALLEL=false
ARCH_FILTER=""
usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --skip-qemu Skip QEMU setup (if already configured)"
echo " --linux-only Only test Linux platforms"
echo " --darwin-only Only test Darwin platforms (download verification)"
echo " --arch ARCH Only test one architecture (amd64 or arm64)"
echo " --tag TAG Test a specific release tag (default: latest)"
echo " --parallel Run tests in parallel (experimental)"
echo " -h, --help Show this help message"
exit 0
}
while [[ $# -gt 0 ]]; do
case $1 in
--skip-qemu)
SKIP_QEMU_SETUP=true
shift
;;
--linux-only)
TEST_DARWIN=false
shift
;;
--darwin-only)
TEST_LINUX=false
shift
;;
--parallel)
PARALLEL=true
shift
;;
--arch)
ARCH_FILTER="$2"
shift 2
;;
--tag)
RELEASE_TAG="$2"
shift 2
;;
-h|--help)
usage
;;
*)
log_error "Unknown option: $1"
usage
;;
esac
done
# Main execution
main() {
log_header "FFmpeg Multi-Platform Test Suite"
log_info "FFmpeg Version: ${FFMPEG_VERSION}"
log_info "Repository: ${GITHUB_REPO}"
echo ""
# Check dependencies
check_dependencies
# Setup QEMU for ARM emulation
if [ "$SKIP_QEMU_SETUP" = false ] && [ "$TEST_LINUX" = true ]; then
setup_qemu
fi
local passed=0
local failed=0
local skipped=0
# Test Linux platforms
if [ "$TEST_LINUX" = true ]; then
log_header "Verifying Binary Linkage"
local seen=""
for platform_spec in "${LINUX_PLATFORMS[@]}"; do
IFS=':' read -r os arch variant docker_image docker_tag docker_platform <<< "$platform_spec"
[ -n "$ARCH_FILTER" ] && [ "$arch" != "$ARCH_FILTER" ] && continue
local key="${os}-${arch}-${variant}"
case " $seen " in *" $key "*) continue ;; esac
seen="$seen $key"
if verify_linkage "$os" "$arch" "$variant"; then
passed=$((passed + 1))
else
failed=$((failed + 1))
fi
done
echo ""
log_header "Testing Linux Platforms"
for platform_spec in "${LINUX_PLATFORMS[@]}"; do
IFS=':' read -r os arch variant docker_image docker_tag docker_platform <<< "$platform_spec"
if [ -n "$ARCH_FILTER" ] && [ "$arch" != "$ARCH_FILTER" ]; then
skipped=$((skipped + 1))
continue
fi
if test_linux_platform "$os" "$arch" "$variant" "$docker_image" "$docker_tag" "$docker_platform"; then
passed=$((passed + 1))
else
failed=$((failed + 1))
fi
echo ""
done
fi
# Test Darwin platforms
if [ "$TEST_DARWIN" = true ]; then
log_header "Testing Darwin Platforms (Download Only)"
for platform_spec in "${DARWIN_PLATFORMS[@]}"; do
IFS=':' read -r os arch <<< "$platform_spec"
if test_darwin_platform "$os" "$arch"; then
passed=$((passed + 1))
else
failed=$((failed + 1))
fi
echo ""
done
fi
# Summary
log_header "Test Summary"
echo -e " ${GREEN}Passed:${NC} ${passed}"
echo -e " ${RED}Failed:${NC} ${failed}"
echo -e " ${YELLOW}Skipped:${NC} ${skipped}"
echo ""
if [ "$failed" -gt 0 ]; then
log_error "Some tests failed!"
exit 1
else
log_info "All tests passed!"
exit 0
fi
}
main