-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-original.sh
More file actions
executable file
·1937 lines (1625 loc) · 52.6 KB
/
Copy pathtest-original.sh
File metadata and controls
executable file
·1937 lines (1625 loc) · 52.6 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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
IMAGE_TAG="${LIBWEBP_ORIGINAL_TEST_IMAGE:-libwebp-original-test:ubuntu24.04}"
VARIANT="original"
ONLY=""
SAFE_DEB_DIR="${LIBWEBP_SAFE_DEB_DIR:-}"
usage() {
cat <<'EOF'
usage: test-original.sh [--variant <original|safe>] [--only <name|runtime-package|source-package|slug|tools|tool:name|pkg-config-libwebp|pkg-config-libsharpyuv|pkg-config-libwebpdecoder|pkg-config-libwebpdemux|pkg-config-libwebpmux|cmake-webp>]
In `original` mode, builds the checked-in original libwebp inside an Ubuntu 24.04
Docker container and installs it into /usr/local inside that container.
In `safe` mode, installs the generated safe Debian packages from
$LIBWEBP_SAFE_DEB_DIR inside that same container.
The harness runs an explicit tool-smoke matrix before dependent checks.
`--only tools` runs just the tool matrix, and `--only tool:<name>` runs one tool smoke.
The direct installed-surface probes are addressable through `--only` by their
explicit names: `pkg-config-libwebp`, `pkg-config-libsharpyuv`,
`pkg-config-libwebpdecoder`, `pkg-config-libwebpdemux`, `pkg-config-libwebpmux`,
and `cmake-webp`.
EOF
}
while (($#)); do
case "$1" in
--variant)
VARIANT="${2:?missing value for --variant}"
shift 2
;;
--only)
ONLY="${2:?missing value for --only}"
shift 2
;;
--help|-h)
usage
exit 0
;;
*)
printf 'unknown option: %s\n' "$1" >&2
usage >&2
exit 1
;;
esac
done
case "$VARIANT" in
original|safe)
;;
*)
printf 'unknown variant: %s\n' "$VARIANT" >&2
usage >&2
exit 1
;;
esac
command -v docker >/dev/null 2>&1 || {
printf 'docker is required to run %s\n' "$0" >&2
exit 1
}
[[ -d "$ROOT/original" ]] || {
printf 'missing original source tree\n' >&2
exit 1
}
[[ -f "$ROOT/dependents.json" ]] || {
printf 'missing dependents.json\n' >&2
exit 1
}
if [[ "$VARIANT" == safe ]]; then
[[ -n "$SAFE_DEB_DIR" ]] || {
printf 'LIBWEBP_SAFE_DEB_DIR is required for --variant safe\n' >&2
exit 1
}
[[ -d "$SAFE_DEB_DIR" ]] || {
printf 'missing safe Debian package directory: %s\n' "$SAFE_DEB_DIR" >&2
exit 1
}
fi
docker build -t "$IMAGE_TAG" - <<'DOCKERFILE'
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
dbus-x11 \
emacs-gtk \
ffmpeg \
file \
gimp \
libgdk-pixbuf2.0-bin \
libgif-dev \
libglut-dev \
libjpeg-dev \
libpng-dev \
libsail-common-dev \
libsail-dev \
libsdl2-image-dev \
libtiff-dev \
libvips-dev \
libvips-tools \
libwebkit2gtk-4.1-dev \
libreoffice-core \
libreoffice-draw \
pkg-config \
python3 \
python3-pil \
qt6-base-dev \
qt6-image-formats-plugins \
sail-codecs \
shotwell \
webp-pixbuf-loader \
xauth \
xvfb \
&& rm -rf /var/lib/apt/lists/*
DOCKERFILE
docker_args=(
--rm
-i
-e "LIBWEBP_TEST_ONLY=$ONLY"
-e "LIBWEBP_TEST_VARIANT=$VARIANT"
-v "$ROOT":/work:ro
)
if [[ "$VARIANT" == safe ]]; then
docker_args+=(
-e "LIBWEBP_SAFE_DEB_DIR=/safe-debs"
-v "$SAFE_DEB_DIR":/safe-debs:ro
)
fi
docker run "${docker_args[@]}" "$IMAGE_TAG" bash -s <<'CONTAINER_SCRIPT'
set -euo pipefail
export LANG=C.UTF-8
export LC_ALL=C.UTF-8
ROOT=/work
ONLY_FILTER="${LIBWEBP_TEST_ONLY:-}"
VARIANT="${LIBWEBP_TEST_VARIANT:-original}"
SAFE_DEB_DIR="${LIBWEBP_SAFE_DEB_DIR:-}"
HOME=/tmp/libwebp-home
XDG_RUNTIME_DIR=/tmp/libwebp-runtime
SRC_COPY=/tmp/libwebp-src
BUILD_DIR=/tmp/libwebp-build
FIXTURE_DIR=/tmp/libwebp-fixtures
TEST_ROOT=/tmp/libwebp-dependent-tests
MULTIARCH="$(gcc -print-multiarch)"
ACTIVE_LIBDIR=""
EXPECTED_LIBRARY_PREFIX=""
MATCHED_DEPENDENT=0
MATCHED_TOOL=0
MATCHED_DIRECT_CHECK=0
mkdir -p "$HOME" "$XDG_RUNTIME_DIR" "$FIXTURE_DIR" "$TEST_ROOT"
chmod 700 "$XDG_RUNTIME_DIR"
log_step() {
printf '\n==> %s\n' "$1"
}
die() {
printf 'error: %s\n' "$*" >&2
exit 1
}
require_nonempty_file() {
local path="$1"
[[ -s "$path" ]] || die "expected non-empty file: $path"
}
require_contains() {
local path="$1"
local needle="$2"
grep -F -- "$needle" "$path" >/dev/null 2>&1 || {
printf 'missing expected text in %s: %s\n' "$path" "$needle" >&2
printf -- '--- %s ---\n' "$path" >&2
cat "$path" >&2
exit 1
}
}
find_file_or_die() {
local root="$1"
local pattern="$2"
local path
path="$(find "$root" -path "$pattern" -print -quit 2>/dev/null || true)"
[[ -n "$path" ]] || die "unable to find file matching $pattern under $root"
printf '%s\n' "$path"
}
assert_uses_local_soname() {
local target="$1"
local soname="$2"
local label="${3:-$1}"
local resolved
resolved="$(ldd "$target" 2>/dev/null | awk -v lib="$soname" '$1 == lib { print $3; exit }')"
[[ -n "$resolved" ]] || die "$label does not link against $soname"
resolved_matches_expected_prefix "$resolved" || die "$label resolved $soname to $resolved instead of $EXPECTED_LIBRARY_PREFIX"
}
assert_any_file_under_uses_local_soname() {
local root="$1"
local pattern="$2"
local soname="$3"
local label="$4"
local candidate resolved
while IFS= read -r -d '' candidate; do
resolved="$(ldd "$candidate" 2>/dev/null | awk -v lib="$soname" '$1 == lib { print $3; exit }')"
if [[ -n "$resolved" ]] && resolved_matches_expected_prefix "$resolved"; then
return 0
fi
done < <(find "$root" -type f -name "$pattern" -print0 2>/dev/null)
die "$label did not resolve $soname from $EXPECTED_LIBRARY_PREFIX in any file under $root matching $pattern"
}
resolved_matches_expected_prefix() {
local resolved="$1"
local canonical_prefix canonical_resolved
[[ "$resolved" == "$EXPECTED_LIBRARY_PREFIX"* ]] && return 0
canonical_prefix="$(realpath "$EXPECTED_LIBRARY_PREFIX" 2>/dev/null || printf '%s\n' "$EXPECTED_LIBRARY_PREFIX")"
canonical_resolved="$(realpath "$resolved" 2>/dev/null || printf '%s\n' "$resolved")"
[[ "$canonical_resolved" == "$canonical_prefix"* ]]
}
reset_test_dir() {
local slug="$1"
local dir="$TEST_ROOT/$slug"
rm -rf "$dir"
mkdir -p "$dir"
printf '%s\n' "$dir"
}
should_run() {
local slug="$1"
local name="$2"
local runtime_package="$3"
local source_package="$4"
if [[ -z "$ONLY_FILTER" ]]; then
return 0
fi
if [[ "$ONLY_FILTER" == tools || "$ONLY_FILTER" == tool:* ]] || is_direct_check_name "$ONLY_FILTER"; then
return 1
fi
[[ "$ONLY_FILTER" == "$slug" \
|| "$ONLY_FILTER" == "$name" \
|| "$ONLY_FILTER" == "$runtime_package" \
|| "$ONLY_FILTER" == "$source_package" ]]
}
is_direct_check_name() {
case "$1" in
pkg-config-libwebp|pkg-config-libsharpyuv|pkg-config-libwebpdecoder|pkg-config-libwebpdemux|pkg-config-libwebpmux|cmake-webp)
return 0
;;
*)
return 1
;;
esac
}
run_check() {
local slug="$1"
local name="$2"
local runtime_package="$3"
local source_package="$4"
local func="$5"
if ! should_run "$slug" "$name" "$runtime_package" "$source_package"; then
return 0
fi
MATCHED_DEPENDENT=1
log_step "$name"
"$func"
}
should_run_tool() {
local tool="$1"
if [[ -z "$ONLY_FILTER" ]]; then
return 0
fi
case "$ONLY_FILTER" in
tools)
return 0
;;
tool:*)
[[ "$ONLY_FILTER" == "tool:$tool" ]]
return
;;
pkg-config-libwebp|pkg-config-libsharpyuv|pkg-config-libwebpdecoder|pkg-config-libwebpdemux|pkg-config-libwebpmux|cmake-webp)
return 1
;;
*)
return 0
;;
esac
}
run_tool_check() {
local tool="$1"
local func="$2"
if ! should_run_tool "$tool"; then
return 0
fi
MATCHED_TOOL=1
log_step "Tool smoke: $tool"
"$func"
}
should_run_direct_check() {
local name="$1"
if [[ -z "$ONLY_FILTER" ]]; then
return 0
fi
case "$ONLY_FILTER" in
tools|tool:*)
return 1
;;
pkg-config-libwebp|pkg-config-libsharpyuv|pkg-config-libwebpdecoder|pkg-config-libwebpdemux|pkg-config-libwebpmux|cmake-webp)
[[ "$ONLY_FILTER" == "$name" ]]
return
;;
*)
return 0
;;
esac
}
run_direct_check() {
local name="$1"
local func="$2"
if ! should_run_direct_check "$name"; then
return 0
fi
MATCHED_DIRECT_CHECK=1
log_step "Installed surface: $name"
"$func"
}
validate_dependents_inventory() {
python3 <<'PY'
import json
from pathlib import Path
expected_top_level_keys = {
"schema_version",
"generated_on",
"ubuntu_release",
"metadata_source",
"libwebp_package_versions",
"selection_policy",
"method",
"dependents",
}
expected_package_version_keys = {
"libwebp7",
"libwebpdecoder3",
"libwebpdemux2",
"libwebpmux3",
"libwebp-dev",
}
expected_entry_keys = {
"name",
"source_package",
"runtime_package",
"category",
"runtime_depends_on",
"build_depends_on",
"runtime_functionality",
"runtime_evidence_level",
}
expected_triplets = [
("GIMP", "gimp", "gimp"),
("Pillow", "pillow", "python3-pil"),
("WebKitGTK", "webkit2gtk", "libwebkit2gtk-4.1-0"),
("Qt 6 Image Formats Plugins", "qt6-imageformats", "qt6-image-formats-plugins"),
("SDL2_image", "libsdl2-image", "libsdl2-image-2.0-0"),
("libvips", "vips", "libvips42t64"),
("GNU Emacs (GTK build)", "emacs", "emacs-gtk"),
("Shotwell", "shotwell", "shotwell"),
("LibreOffice", "libreoffice", "libreoffice-core"),
("FFmpeg libavcodec", "ffmpeg", "libavcodec60"),
("webp-pixbuf-loader", "webp-pixbuf-loader", "webp-pixbuf-loader"),
("SAIL codecs", "sail", "sail-codecs"),
]
data = json.loads(Path("/work/dependents.json").read_text(encoding="utf-8"))
if set(data.keys()) != expected_top_level_keys:
raise SystemExit(
f"unexpected dependents.json top-level keys: expected {sorted(expected_top_level_keys)}, found {sorted(data.keys())}"
)
if not isinstance(data["schema_version"], int) or data["schema_version"] <= 0:
raise SystemExit(f"schema_version must be a positive integer, found {data['schema_version']!r}")
for field in ("generated_on", "ubuntu_release", "metadata_source", "selection_policy"):
value = data[field]
if not isinstance(value, str) or not value.strip():
raise SystemExit(f"{field} must be a non-empty string, found {value!r}")
versions = data["libwebp_package_versions"]
if set(versions.keys()) != expected_package_version_keys:
raise SystemExit(
f"unexpected libwebp_package_versions keys: expected {sorted(expected_package_version_keys)}, found {sorted(versions.keys())}"
)
for key, value in versions.items():
if not isinstance(value, str) or not value.strip():
raise SystemExit(f"libwebp_package_versions[{key!r}] must be a non-empty string, found {value!r}")
method = data["method"]
if not isinstance(method, list) or not method:
raise SystemExit(f"method must be a non-empty string array, found {method!r}")
for index, step in enumerate(method):
if not isinstance(step, str) or not step.strip():
raise SystemExit(f"method[{index}] must be a non-empty string, found {step!r}")
dependents = data["dependents"]
if not isinstance(dependents, list) or len(dependents) != len(expected_triplets):
raise SystemExit(
f"dependents must contain exactly {len(expected_triplets)} entries, found {len(dependents) if isinstance(dependents, list) else dependents!r}"
)
actual_triplets = []
for index, entry in enumerate(dependents):
if set(entry.keys()) != expected_entry_keys:
raise SystemExit(
f"unexpected dependent keys at index {index}: expected {sorted(expected_entry_keys)}, found {sorted(entry.keys())}"
)
for field in ("name", "source_package", "runtime_package", "category", "runtime_functionality"):
value = entry[field]
if not isinstance(value, str) or not value.strip():
raise SystemExit(f"dependents[{index}].{field} must be a non-empty string, found {value!r}")
for field in ("runtime_depends_on", "build_depends_on"):
value = entry[field]
if not isinstance(value, list) or not value:
raise SystemExit(f"dependents[{index}].{field} must be a non-empty string array, found {value!r}")
for item_index, item in enumerate(value):
if not isinstance(item, str) or not item.strip():
raise SystemExit(
f"dependents[{index}].{field}[{item_index}] must be a non-empty string, found {item!r}"
)
if entry["runtime_evidence_level"] not in {"explicit", "inferred"}:
raise SystemExit(
f"dependents[{index}].runtime_evidence_level must be 'explicit' or 'inferred', found {entry['runtime_evidence_level']!r}"
)
actual_triplets.append(
(entry["name"], entry["source_package"], entry["runtime_package"])
)
if actual_triplets != expected_triplets:
raise SystemExit(
f"unexpected dependents.json inventory: expected {expected_triplets}, found {actual_triplets}"
)
PY
}
build_original_libwebp() {
local libwebp_so
rm -rf "$SRC_COPY" "$BUILD_DIR"
mkdir -p "$SRC_COPY"
cp -a "$ROOT/original/." "$SRC_COPY"
cmake -S "$SRC_COPY" -B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_SHARED_LIBS=ON \
-DWEBP_BUILD_ANIM_UTILS=ON \
-DWEBP_BUILD_GIF2WEBP=ON \
-DWEBP_LINK_STATIC=OFF \
-DWEBP_BUILD_VWEBP=ON \
>/tmp/libwebp-configure.log 2>&1
cmake --build "$BUILD_DIR" -j"$(nproc)" >/tmp/libwebp-build.log 2>&1
cmake --install "$BUILD_DIR" >/tmp/libwebp-install.log 2>&1
ldconfig
libwebp_so="$(find /usr/local -name 'libwebp.so.7' -print -quit)"
[[ -n "$libwebp_so" ]] || die "failed to locate installed libwebp.so.7 under /usr/local"
ACTIVE_LIBDIR="$(dirname "$libwebp_so")"
EXPECTED_LIBRARY_PREFIX="$ACTIVE_LIBDIR"
export LD_LIBRARY_PATH="$ACTIVE_LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
export CMAKE_PREFIX_PATH="/usr/local${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}"
}
install_safe_packages() {
local version
[[ -d "$SAFE_DEB_DIR" ]] || die "missing safe package directory inside container: $SAFE_DEB_DIR"
dpkg -i "$SAFE_DEB_DIR"/*.deb >/tmp/libwebp-safe-install.log 2>&1 || {
cat /tmp/libwebp-safe-install.log >&2
exit 1
}
ldconfig
version="$(dpkg-query -W -f='${Version}' libwebp7 2>/dev/null || true)"
[[ -n "$version" ]] || die "failed to query installed libwebp7 version after safe package install"
[[ "$version" == *safelibs* ]] || die "safe package install did not replace libwebp7 as expected: $version"
ACTIVE_LIBDIR="/usr/lib/$MULTIARCH"
EXPECTED_LIBRARY_PREFIX="$ACTIVE_LIBDIR"
}
prepare_fixtures() {
cat >"$FIXTURE_DIR/shotwell-exif.py" <<'PY'
from pathlib import Path
model = b"SafeLibs WebP\x00"
payload = bytearray()
payload += b"Exif\x00\x00"
payload += b"II*\x00"
payload += (8).to_bytes(4, "little")
payload += (1).to_bytes(2, "little")
payload += (0x0110).to_bytes(2, "little")
payload += (2).to_bytes(2, "little")
payload += (len(model)).to_bytes(4, "little")
payload += (26).to_bytes(4, "little")
payload += (0).to_bytes(4, "little")
payload += model
Path("shotwell.exif").write_bytes(payload)
PY
cat >"$FIXTURE_DIR/make-animated-frames.py" <<'PY'
from pathlib import Path
source = Path("frame1.ppm").read_bytes()
parts = source.split(b"\n", 3)
if len(parts) != 4 or parts[0] != b"P6":
raise SystemExit("unexpected PPM fixture format")
pixels = bytearray(parts[3])
if len(pixels) < 6:
raise SystemExit("fixture is too small")
pixels[0:3] = bytes([255 - pixels[0], 255 - pixels[1], 255 - pixels[2]])
pixels[3:6] = bytes([pixels[4], pixels[5], pixels[3]])
Path("frame2.ppm").write_bytes(parts[0] + b"\n" + parts[1] + b"\n" + parts[2] + b"\n" + pixels)
PY
cat >"$FIXTURE_DIR/make-image-fixtures.py" <<'PY'
from PIL import Image
Image.open("input.ppm").save("input.png")
frames = [Image.open("frame1.ppm").convert("RGBA"), Image.open("frame2.ppm").convert("RGBA")]
frames[0].save(
"animated.gif",
save_all=True,
append_images=frames[1:],
duration=[80] * len(frames),
loop=0,
disposal=2,
)
PY
cat >"$FIXTURE_DIR/make-animated-webp.py" <<'PY'
from PIL import Image
frames = [Image.open("frame1.ppm").convert("RGBA"), Image.open("frame2.ppm").convert("RGBA")]
frames[0].save(
"animated.webp",
format="WEBP",
save_all=True,
append_images=frames[1:],
duration=[80] * len(frames),
loop=0,
lossless=True,
)
PY
cp "$ROOT/original/examples/test.webp" "$FIXTURE_DIR/input.webp"
cp "$ROOT/original/examples/test_ref.ppm" "$FIXTURE_DIR/input.ppm"
cp "$ROOT/original/examples/test_ref.ppm" "$FIXTURE_DIR/frame1.ppm"
(
cd "$FIXTURE_DIR"
python3 make-animated-frames.py
python3 make-image-fixtures.py
)
require_nonempty_file "$FIXTURE_DIR/input.png"
require_nonempty_file "$FIXTURE_DIR/animated.gif"
(
cd "$FIXTURE_DIR"
python3 shotwell-exif.py
)
require_nonempty_file "$FIXTURE_DIR/shotwell.exif"
}
ensure_animated_webp_fixture() {
if [[ -s "$FIXTURE_DIR/animated.webp" ]]; then
return 0
fi
(
cd "$FIXTURE_DIR"
python3 make-animated-webp.py
cp animated.webp animated-copy.webp
)
require_nonempty_file "$FIXTURE_DIR/animated.webp"
require_nonempty_file "$FIXTURE_DIR/animated-copy.webp"
}
ensure_metadata_webp_fixture() {
if [[ -s "$FIXTURE_DIR/metadata.webp" && -s "$FIXTURE_DIR/extracted.exif" ]]; then
return 0
fi
webpmux -set exif "$FIXTURE_DIR/shotwell.exif" "$FIXTURE_DIR/input.webp" -o "$FIXTURE_DIR/metadata.webp" >/tmp/webpmux-set.log 2>&1 || {
cat /tmp/webpmux-set.log >&2
exit 1
}
webpmux -get exif "$FIXTURE_DIR/metadata.webp" -o "$FIXTURE_DIR/extracted.exif" >/tmp/webpmux-get.log 2>&1 || {
cat /tmp/webpmux-get.log >&2
exit 1
}
require_nonempty_file "$FIXTURE_DIR/metadata.webp"
require_nonempty_file "$FIXTURE_DIR/extracted.exif"
cmp -s "$FIXTURE_DIR/shotwell.exif" "$FIXTURE_DIR/extracted.exif" || die "webpmux EXIF round-trip changed the metadata payload"
}
write_probe_common_header() {
local dir="$1"
cat >"$dir/probe_common.h" <<'C'
#ifndef WEBP_PROBE_COMMON_H
#define WEBP_PROBE_COMMON_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
static int read_file_bytes(const char* path, uint8_t** bytes, size_t* size) {
FILE* file = fopen(path, "rb");
long length = 0;
size_t read_size = 0;
uint8_t* buffer = NULL;
if (file == NULL) return 0;
if (fseek(file, 0, SEEK_END) != 0) {
fclose(file);
return 0;
}
length = ftell(file);
if (length < 0) {
fclose(file);
return 0;
}
if (fseek(file, 0, SEEK_SET) != 0) {
fclose(file);
return 0;
}
buffer = (uint8_t*)malloc((size_t)length);
if (buffer == NULL) {
fclose(file);
return 0;
}
read_size = fread(buffer, 1, (size_t)length, file);
fclose(file);
if (read_size != (size_t)length) {
free(buffer);
return 0;
}
*bytes = buffer;
*size = read_size;
return 1;
}
#endif
C
}
probe_pkg_config_libwebp() {
local dir
dir="$(reset_test_dir pkg-config-libwebp)"
write_probe_common_header "$dir"
cat >"$dir/libwebp_probe.c" <<'C'
#include <stdio.h>
#include <stdlib.h>
#include <webp/decode.h>
#include <webp/encode.h>
#include "probe_common.h"
int main(int argc, char** argv) {
uint8_t* bytes = NULL;
uint8_t* rgba = NULL;
size_t size = 0;
int width = 0;
int height = 0;
const int decoder = WebPGetDecoderVersion();
const int encoder = WebPGetEncoderVersion();
if (argc != 2) return 2;
if (!read_file_bytes(argv[1], &bytes, &size)) return 1;
if (decoder <= 0 || encoder <= 0) {
return 1;
}
if (!WebPGetInfo(bytes, size, &width, &height)) return 1;
rgba = WebPDecodeRGBA(bytes, size, &width, &height);
if (rgba == NULL || width <= 0 || height <= 0) return 1;
printf("decoder=%d encoder=%d image=%dx%d\n", decoder, encoder, width, height);
WebPFree(rgba);
free(bytes);
return 0;
}
C
cc "$dir/libwebp_probe.c" -o "$dir/libwebp-probe" $(pkg-config --cflags --libs libwebp) >/tmp/pkg-config-libwebp-compile.log 2>&1 || {
cat /tmp/pkg-config-libwebp-compile.log >&2
exit 1
}
assert_uses_local_soname "$dir/libwebp-probe" libwebp.so.7 "pkg-config libwebp consumer"
"$dir/libwebp-probe" "$FIXTURE_DIR/input.webp" >"$dir/run.log" 2>&1 || {
cat "$dir/run.log" >&2
exit 1
}
require_contains "$dir/run.log" 'decoder='
}
probe_pkg_config_libsharpyuv() {
local dir
dir="$(reset_test_dir pkg-config-libsharpyuv)"
write_probe_common_header "$dir"
cat >"$dir/libsharpyuv_probe.c" <<'C'
#include <stdio.h>
#include <sharpyuv/sharpyuv.h>
int main(void) {
const int version = SharpYuvGetVersion();
if (version <= 0) {
return 1;
}
printf("sharpyuv=%d\n", version);
return 0;
}
C
cc "$dir/libsharpyuv_probe.c" -o "$dir/libsharpyuv-probe" $(pkg-config --cflags --libs libsharpyuv) >/tmp/pkg-config-libsharpyuv-compile.log 2>&1 || {
cat /tmp/pkg-config-libsharpyuv-compile.log >&2
exit 1
}
assert_uses_local_soname "$dir/libsharpyuv-probe" libsharpyuv.so.0 "pkg-config libsharpyuv consumer"
"$dir/libsharpyuv-probe" >"$dir/run.log" 2>&1 || {
cat "$dir/run.log" >&2
exit 1
}
require_contains "$dir/run.log" 'sharpyuv='
}
probe_pkg_config_libwebpdecoder() {
local dir
dir="$(reset_test_dir pkg-config-libwebpdecoder)"
write_probe_common_header "$dir"
cat >"$dir/libwebpdecoder_probe.c" <<'C'
#include <stdio.h>
#include <stdlib.h>
#include <webp/decode.h>
#include "probe_common.h"
int main(int argc, char** argv) {
uint8_t* bytes = NULL;
size_t size = 0;
int width = 0;
int height = 0;
if (argc != 2) return 2;
if (!read_file_bytes(argv[1], &bytes, &size)) return 1;
if (WebPGetDecoderVersion() <= 0) return 1;
if (!WebPGetInfo(bytes, size, &width, &height)) return 1;
if (width <= 0 || height <= 0) return 1;
printf("%dx%d\n", width, height);
free(bytes);
return 0;
}
C
cc "$dir/libwebpdecoder_probe.c" -o "$dir/libwebpdecoder-probe" $(pkg-config --cflags --libs libwebpdecoder) >/tmp/pkg-config-libwebpdecoder-compile.log 2>&1 || {
cat /tmp/pkg-config-libwebpdecoder-compile.log >&2
exit 1
}
assert_uses_local_soname "$dir/libwebpdecoder-probe" libwebpdecoder.so.3 "pkg-config libwebpdecoder consumer"
"$dir/libwebpdecoder-probe" "$FIXTURE_DIR/input.webp" >"$dir/run.log" 2>&1 || {
cat "$dir/run.log" >&2
exit 1
}
require_contains "$dir/run.log" 'x'
}
probe_pkg_config_libwebpdemux() {
local dir
dir="$(reset_test_dir pkg-config-libwebpdemux)"
write_probe_common_header "$dir"
ensure_animated_webp_fixture
cat >"$dir/libwebpdemux_probe.c" <<'C'
#include <stdio.h>
#include <stdlib.h>
#include <webp/demux.h>
#include "probe_common.h"
int main(int argc, char** argv) {
uint8_t* bytes = NULL;
size_t size = 0;
WebPData data = {0};
WebPDemuxer* demux = NULL;
WebPIterator iter;
uint32_t frame_count = 0;
uint32_t canvas_width = 0;
uint32_t canvas_height = 0;
if (argc != 2) return 2;
if (!read_file_bytes(argv[1], &bytes, &size)) return 1;
data.bytes = bytes;
data.size = size;
demux = WebPDemux(&data);
if (demux == NULL) return 1;
frame_count = WebPDemuxGetI(demux, WEBP_FF_FRAME_COUNT);
canvas_width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
canvas_height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
if (frame_count < 2 || canvas_width == 0 || canvas_height == 0) return 1;
if (!WebPDemuxGetFrame(demux, 1, &iter)) return 1;
if (iter.width == 0 || iter.height == 0) return 1;
WebPDemuxReleaseIterator(&iter);
WebPDemuxDelete(demux);
free(bytes);
printf("%ux%u frames=%u\n", canvas_width, canvas_height, frame_count);
return 0;
}
C
cc "$dir/libwebpdemux_probe.c" -o "$dir/libwebpdemux-probe" $(pkg-config --cflags --libs libwebpdemux) >/tmp/pkg-config-libwebpdemux-compile.log 2>&1 || {
cat /tmp/pkg-config-libwebpdemux-compile.log >&2
exit 1
}
assert_uses_local_soname "$dir/libwebpdemux-probe" libwebpdemux.so.2 "pkg-config libwebpdemux consumer"
"$dir/libwebpdemux-probe" "$FIXTURE_DIR/animated.webp" >"$dir/run.log" 2>&1 || {
cat "$dir/run.log" >&2
exit 1
}
require_contains "$dir/run.log" 'frames='
}
probe_pkg_config_libwebpmux() {
local dir
dir="$(reset_test_dir pkg-config-libwebpmux)"
write_probe_common_header "$dir"
ensure_metadata_webp_fixture
cat >"$dir/libwebpmux_probe.c" <<'C'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <webp/mux.h>
#include "probe_common.h"
static int write_file_bytes(const char* path, const uint8_t* bytes, size_t size) {
FILE* file = fopen(path, "wb");
if (file == NULL) return 0;
if (fwrite(bytes, 1, size, file) != size) {
fclose(file);
return 0;
}
fclose(file);
return 1;
}
int main(int argc, char** argv) {
uint8_t* image_bytes = NULL;
uint8_t* exif_bytes = NULL;
size_t image_size = 0;
size_t exif_size = 0;
WebPData image = {0};
WebPData exif = {0};
WebPData assembled = {0};
WebPData extracted = {0};
WebPMux* mux = NULL;
WebPMux* parsed = NULL;
if (argc != 4) return 2;
if (!read_file_bytes(argv[1], &image_bytes, &image_size)) return 1;
if (!read_file_bytes(argv[2], &exif_bytes, &exif_size)) return 1;
image.bytes = image_bytes;
image.size = image_size;
exif.bytes = exif_bytes;
exif.size = exif_size;
mux = WebPMuxNew();
if (mux == NULL) return 1;
if (WebPMuxSetImage(mux, &image, 1) != WEBP_MUX_OK) return 1;
if (WebPMuxSetChunk(mux, "EXIF", &exif, 1) != WEBP_MUX_OK) return 1;
if (WebPMuxAssemble(mux, &assembled) != WEBP_MUX_OK) return 1;
parsed = WebPMuxCreate(&assembled, 1);
if (parsed == NULL) return 1;
if (WebPMuxGetChunk(parsed, "EXIF", &extracted) != WEBP_MUX_OK) return 1;
if (extracted.size != exif.size || memcmp(extracted.bytes, exif.bytes, exif.size) != 0) return 1;
if (!write_file_bytes(argv[3], assembled.bytes, assembled.size)) return 1;
printf("assembled=%zu\n", assembled.size);
WebPMuxDelete(parsed);
WebPMuxDelete(mux);
free(exif_bytes);
free(image_bytes);
return 0;
}
C
cc "$dir/libwebpmux_probe.c" -o "$dir/libwebpmux-probe" $(pkg-config --cflags --libs libwebpmux) >/tmp/pkg-config-libwebpmux-compile.log 2>&1 || {
cat /tmp/pkg-config-libwebpmux-compile.log >&2
exit 1
}
assert_uses_local_soname "$dir/libwebpmux-probe" libwebpmux.so.3 "pkg-config libwebpmux consumer"
"$dir/libwebpmux-probe" "$FIXTURE_DIR/input.webp" "$FIXTURE_DIR/shotwell.exif" "$dir/mux-output.webp" >"$dir/run.log" 2>&1 || {
cat "$dir/run.log" >&2
exit 1
}
require_contains "$dir/run.log" 'assembled='
require_nonempty_file "$dir/mux-output.webp"
}
probe_cmake_webp() {
local dir
dir="$(reset_test_dir cmake-webp)"
write_probe_common_header "$dir"
ensure_metadata_webp_fixture
ensure_animated_webp_fixture
cat >"$dir/webpdecoder_consumer.c" <<'C'
#include <stdio.h>
#include <stdlib.h>
#include <webp/decode.h>
#include "probe_common.h"
int main(int argc, char** argv) {
uint8_t* bytes = NULL;
size_t size = 0;
int width = 0;
int height = 0;