|
| 1 | +#!/bin/sh |
| 2 | +# Integration test: a dump produced by ext-rdump must be readable by reli, |
| 3 | +# the very tool it targets. Builds the extension, writes a dump, then has |
| 4 | +# reli parse and analyse it. |
| 5 | +# |
| 6 | +# Run inside an official php:8.4-cli image with both trees mounted: |
| 7 | +# docker run --rm -v "$PWD/ext":/ext -v "$PWD/reli":/reli -w /ext \ |
| 8 | +# php:8.4-cli sh ci/reli-integration.sh |
| 9 | +# |
| 10 | +# /ext = this extension's source tree |
| 11 | +# /reli = a checkout of reliforp/reli-prof |
| 12 | +set -eux |
| 13 | + |
| 14 | +# --- toolchain + the extensions reli itself needs -------------------- |
| 15 | +apt-get update |
| 16 | +apt-get install -y --no-install-recommends $PHPIZE_DEPS git unzip libffi-dev |
| 17 | +docker-php-ext-install -j"$(nproc)" ffi pcntl |
| 18 | + |
| 19 | +# --- composer -------------------------------------------------------- |
| 20 | +php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" |
| 21 | +php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer |
| 22 | +rm -f /tmp/composer-setup.php |
| 23 | + |
| 24 | +# --- build ext-rdump ------------------------------------------------- |
| 25 | +cd /ext |
| 26 | +phpize |
| 27 | +./configure --enable-rdump |
| 28 | +make -j"$(nproc)" |
| 29 | +SO="/ext/modules/rdump.so" |
| 30 | +php -d extension="$SO" --ri rdump |
| 31 | + |
| 32 | +# --- install reli ---------------------------------------------------- |
| 33 | +cd /reli |
| 34 | +composer install --no-interaction --no-progress |
| 35 | + |
| 36 | +# --- produce a dump with the extension ------------------------------- |
| 37 | +DUMP=/tmp/reli-integration.rdump |
| 38 | +export DUMP |
| 39 | +rm -f "$DUMP" |
| 40 | +php -d extension="$SO" -r ' |
| 41 | + // Keep distinctive live data on the heap so the analysis has substance. |
| 42 | + $marker = array_fill(0, 1000, str_repeat("reli-rdump-integration", 32)); |
| 43 | + if (!rdump_dump(getenv("DUMP"), true)) { |
| 44 | + fwrite(STDERR, "rdump_dump() returned false\n"); |
| 45 | + exit(1); |
| 46 | + } |
| 47 | +' |
| 48 | +test -s "$DUMP" |
| 49 | + |
| 50 | +# --- reli must read it ---------------------------------------------- |
| 51 | +# FFI is enabled explicitly; reli wires FFI bindings at bootstrap even when |
| 52 | +# reading a file rather than attaching to a live process. |
| 53 | +INSPECT="$(php -d ffi.enable=1 reli inspector:memory:dump:inspect "$DUMP")" |
| 54 | +echo "$INSPECT" | head -20 |
| 55 | +echo "$INSPECT" | grep -q 'Magic:.*RDUMP' || { echo '::error::reli did not recognise the RDUMP magic'; exit 1; } |
| 56 | +echo "$INSPECT" | grep -q 'Format Version:.*3' || { echo '::error::reli read an unexpected format version'; exit 1; } |
| 57 | + |
| 58 | +# Full analysis must also complete without error. |
| 59 | +php -d ffi.enable=1 reli inspector:memory:analyze "$DUMP" -f report \ |
| 60 | + | tee /tmp/reli-analyze.log | head -30 |
| 61 | +grep -q 'Memory Analysis Report' /tmp/reli-analyze.log \ |
| 62 | + || { echo '::error::reli analyze did not produce a report'; exit 1; } |
| 63 | + |
| 64 | +echo "reli-integration OK" |
0 commit comments