Skip to content

Commit a68faff

Browse files
test(profiling): with address sanitizer on bookworm with GH actions (#2432)
* ci: begin migration from buster to bookworm * ci: fix build base for PHP 8.3 * ci: add php-nts-asan * ci: run prof asan tests in github * ci: fix asan test name * ci: run tests as circleci user * ci: nvm, run tests as root user * ci: oops, copy the run-tests.php * ci: complete containers for PHP 7.0-8.2 * ci: fix some issues with bookworm containers * ci: prep for next bookworm build * ci: document bookworm * add lsof * ci: prepare for next release * ci: move caching to before tests * ci: exclude zend_test from asan PHP can have memory issues with modules which are loaded at runtime with the `dl` function, and the `run-tests.php` script does this. The zend_test extension in particular hits this edge, so exclude it. * rebuild without zend_test * fix invalid cache path * fix "correctness" vs "asan" --------- Co-authored-by: Florian Engelhardt <[email protected]>
1 parent fa486a8 commit a68faff

30 files changed

+219
-220
lines changed

.github/workflows/prof_asan.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Profiling ASAN Tests
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
prof-asan:
8+
runs-on: ubuntu-latest
9+
container:
10+
image: datadog/dd-trace-ci:php-8.3_bookworm-1
11+
# https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#user
12+
options: --user root
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
submodules: true
20+
21+
- name: Restore build cache
22+
uses: actions/cache/restore@v3
23+
with:
24+
path: |
25+
~/.cargo/bin/
26+
~/.cargo/registry/index/
27+
~/.cargo/registry/cache/
28+
~/.cargo/git/db/
29+
target/
30+
key: ${{ runner.os }}-cargo-asan-${{ hashFiles('**/Cargo.lock') }}
31+
32+
- name: Build and install profiler
33+
run: |
34+
set -eux
35+
switch-php nts-asan
36+
cd profiling
37+
export CARGO_TARGET_DIR=/tmp/build-cargo
38+
export CC=clang-16
39+
export CFLAGS='-fsanitize=address -fno-omit-frame-pointer'
40+
export LDFLAGS='-fsanitize=address'
41+
export RUSTC_LINKER=lld-16
42+
triplet=$(uname -m)-unknown-linux-gnu
43+
RUSTFLAGS='-Zsanitizer=address' cargo +nightly-2023-05-03 build -Zbuild-std --target $triplet --release
44+
cp -v "$CARGO_TARGET_DIR/$triplet/release/libdatadog_php_profiling.so" "$(php-config --extension-dir)/datadog-profiling.so"
45+
46+
- name: Cache build dependencies
47+
uses: actions/cache/save@v3
48+
with:
49+
path: |
50+
~/.cargo/bin/
51+
~/.cargo/registry/index/
52+
~/.cargo/registry/cache/
53+
~/.cargo/git/db/
54+
/tmp/build-cargo/
55+
key: ${{ runner.os }}-cargo-asan-${{ hashFiles('**/Cargo.lock') }}
56+
57+
- name: Run phpt tests
58+
run: |
59+
set -eux
60+
switch-php nts-asan
61+
cd profiling/tests
62+
cp -v $(php-config --prefix)/lib/php/build/run-tests.php .
63+
php run-tests.php --asan -d extension=datadog-profiling.so phpt
64+

.gitlab/ci-images.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Alpine Compile Extension:
5959
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_TOKEN" $CI_REGISTRY
6060
- docker buildx bake --no-cache --pull --push $PHP_VERSION
6161

62-
Ubuntu Buster:
62+
Ubuntu Bookworm:
6363
stage: ci-build
6464
rules:
6565
- when: manual
@@ -82,8 +82,7 @@ Ubuntu Buster:
8282
- php-7.2
8383
- php-7.1
8484
- php-7.0
85-
- php-master
8685
script:
87-
- cd dockerfiles/ci/buster
86+
- cd dockerfiles/ci/bookworm
8887
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_TOKEN" $CI_REGISTRY
8988
- docker buildx bake --no-cache --pull --push $PHP_VERSION

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ services:
6666
'8.2-buster': { <<: *base_php_service, image: 'datadog/dd-trace-ci:php-8.2_buster' }
6767
'8.3-buster': { <<: *base_php_service, image: 'datadog/dd-trace-ci:php-8.3_buster' }
6868
'php-master-buster': { <<: *base_php_service, image: 'datadog/dd-trace-ci:php-master_buster' }
69+
# --- Bookworm ---
70+
'8.3-bookworm': { <<: *base_php_service, image: 'datadog/dd-trace-ci:php-8.3_bookworm-1' }
6971
# --- CentOS 6 ---
7072
'7.0-centos7': { <<: *base_php_service, image: 'datadog/dd-trace-ci:php-7.0_centos-7' }
7173
'7.1-centos7': { <<: *base_php_service, image: 'datadog/dd-trace-ci:php-7.1_centos-7' }

dockerfiles/ci/bookworm/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BOOKWORM_CURRENT_VERSION=1
2+
BOOKWORM_NEXT_VERSION=1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Patch for OpenSSL 3 support for PHP < 8.1
2+
--- a/ext/openssl/openssl.c
3+
+++ b/ext/openssl/openssl.c
4+
@@ -1325,7 +1325,9 @@
5+
REGISTER_LONG_CONSTANT("OPENSSL_CMS_NOSIGS", CMS_NOSIGS, CONST_CS|CONST_PERSISTENT);
6+
7+
REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_PADDING", RSA_PKCS1_PADDING, CONST_CS|CONST_PERSISTENT);
8+
+#ifdef RSA_SSLV23_PADDING
9+
REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT);
10+
+#endif
11+
REGISTER_LONG_CONSTANT("OPENSSL_NO_PADDING", RSA_NO_PADDING, CONST_CS|CONST_PERSISTENT);
12+
REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_OAEP_PADDING", RSA_PKCS1_OAEP_PADDING, CONST_CS|CONST_PERSISTENT);
13+

dockerfiles/ci/buster/Dockerfile renamed to dockerfiles/ci/bookworm/Dockerfile

Lines changed: 24 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:buster AS base
1+
FROM debian:bookworm AS base
22

33
ENV LANG=C.UTF-8
44
ENV DEBIAN_FRONTEND=noninteractive
@@ -9,9 +9,11 @@ ENV ACCEPT_EULA=Y
99
# with cross-language link-time optimization. Needs to match rustc -Vv's llvm
1010
# version.
1111
ENV DEVLIBS \
12+
catch2 \
1213
clang-16 \
14+
cmake \
15+
lcov \
1316
libclang-16-dev \
14-
libclang-rt-16-dev \
1517
llvm-16-dev \
1618
lld-16 \
1719
libcurl4-openssl-dev \
@@ -32,25 +34,25 @@ ENV DEVLIBS \
3234
libxml2-dev \
3335
libxslt1-dev \
3436
libzip-dev \
37+
lsof \
3538
zlib1g-dev \
36-
libasan5 \
39+
libasan6 \
3740
gnupg \
3841
unixodbc-dev \
39-
unixodbc
42+
unixodbc \
43+
valgrind
4044

45+
#netcat
4146
ENV RUNTIME_DEPS \
4247
apache2 \
4348
apache2-dev \
4449
ca-certificates \
45-
clang \
46-
clang-format \
4750
curl \
4851
debian-goodies \
4952
gdb \
5053
git \
5154
less \
5255
netbase \
53-
netcat \
5456
nginx \
5557
strace \
5658
sudo \
@@ -64,9 +66,9 @@ ENV PHPIZE_DEPS \
6466
autoconf \
6567
bison \
6668
dpkg-dev \
67-
file \
6869
g++ \
6970
gcc \
71+
file \
7072
libc-dev \
7173
make \
7274
pkg-config \
@@ -84,16 +86,15 @@ RUN set -eux; \
8486
ulimit -c unlimited; \
8587
\
8688
# Ensure debug symbols are available
87-
echo "deb http://deb.debian.org/debian-debug/ buster-debug main" | \
89+
echo "deb http://deb.debian.org/debian-debug/ bookworm-debug main" | \
8890
tee -a /etc/apt/sources.list; \
8991
\
90-
# Use LLVM from orig vendor (also LLVM 16 is not shipped with buster)
92+
# Use LLVM from orig vendor (also LLVM 16 is not shipped with bookworm)
9193
apt-get update; \
92-
apt-get install -y curl gnupg; \
93-
echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster-16 main" >> /etc/apt/sources.list; \
94-
echo "deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-16 main" >> /etc/apt/sources.list; \
95-
curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -; \
94+
apt-get install -y curl gnupg software-properties-common; \
9695
curl https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc; \
96+
add-apt-repository "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-16 main"; \
97+
add-apt-repository "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-16 main"; \
9798
\
9899
# prevent Debian's PHP packages from being installed
99100
# https://github.com/docker-library/php/pull/542
@@ -113,11 +114,6 @@ RUN set -eux; \
113114
$PHPIZE_DEPS \
114115
$RUNTIME_DEPS; \
115116
\
116-
# valgrind 3.14 has a fatal bug making it unusable with PHP on arm64, manually install valgrind from bullseye \
117-
curl -O http://ftp.de.debian.org/debian/pool/main/v/valgrind/valgrind_3.16.1-1_${TARGETPLATFORM#linux/}.deb; \
118-
dpkg -i valgrind*.deb; \
119-
rm valgrind*.deb; \
120-
\
121117
# Disable DST ROOT X3 certificate explicitly to fix conflicts with older openssl versions \
122118
sed -ri 's/(mozilla\/DST_Root_CA_X3.crt)/!\1/' /etc/ca-certificates.conf; \
123119
update-ca-certificates; \
@@ -131,52 +127,11 @@ RUN set -eux; \
131127
# Allow nginx to be run as non-root for tests
132128
chown -R circleci:circleci /var/log/nginx/ /var/lib/nginx/;
133129

134-
ENV CMAKE_VERSION="3.24.4"
135-
136-
# Install CMake
137-
RUN set -eux; \
138-
if [ "$(uname -m)" = "aarch64" ]; then \
139-
CMAKE_SHA256="86f823f2636bf715af89da10e04daa476755a799d451baee66247846e95d7bee"; \
140-
else \
141-
CMAKE_SHA256="cac77d28fb8668c179ac02c283b058aeb846fe2133a57d40b503711281ed9f19"; \
142-
fi; \
143-
cd /tmp && curl -L --output cmake.tar.gz https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-$(uname -m).tar.gz; \
144-
(echo "${CMAKE_SHA256} cmake.tar.gz" | sha256sum -c -); \
145-
mkdir -p /opt/cmake/${CMAKE_VERSION}; \
146-
tar --strip-components 1 -C /opt/cmake/${CMAKE_VERSION} -xf /tmp/cmake.tar.gz; \
147-
# Currently there's only one version of cmake, make it default
148-
ln -s /opt/cmake/${CMAKE_VERSION}/bin/cmake /usr/local/bin/cmake; \
149-
rm -rfv /tmp/*
150-
151-
# Install Catch2
152-
RUN set -eux; \
153-
CATCH2_VERSION="2.13.10"; \
154-
CATCH2_SHA256="d54a712b7b1d7708bc7a819a8e6e47b2fde9536f487b89ccbca295072a7d9943"; \
155-
cd /tmp && curl -OL https://github.com/catchorg/Catch2/archive/v${CATCH2_VERSION}.tar.gz; \
156-
(echo "${CATCH2_SHA256} v${CATCH2_VERSION}.tar.gz" | sha256sum -c -); \
157-
mkdir catch2 && cd catch2; \
158-
tar -xf ../v${CATCH2_VERSION}.tar.gz --strip 1; \
159-
/opt/cmake/${CMAKE_VERSION}/bin/cmake -Bbuild -H. -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=/opt/catch2 -DCATCH_BUILD_STATIC_LIBRARY=ON; \
160-
/opt/cmake/${CMAKE_VERSION}/bin/cmake --build build/ --target install; \
161-
rm -rfv /tmp/*
162-
163-
# Install lcov
164-
RUN set -eux; \
165-
LCOV_VERSION="1.15"; \
166-
LCOV_SHA256="c1cda2fa33bec9aa2c2c73c87226cfe97de0831887176b45ee523c5e30f8053a"; \
167-
cd /tmp && curl -OL https://github.com/linux-test-project/lcov/releases/download/v${LCOV_VERSION}/lcov-${LCOV_VERSION}.tar.gz; \
168-
(echo "${LCOV_SHA256} lcov-${LCOV_VERSION}.tar.gz" | sha256sum -c -); \
169-
mkdir lcov && cd lcov; \
170-
tar -xf ../lcov-${LCOV_VERSION}.tar.gz --strip 1; \
171-
make install; \
172-
lcov --version; \
173-
rm -rfv /tmp/*
174-
175130
# Install SqlServer PHP Driver
176131
# https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server
177132
RUN set -eux; \
178-
curl -s https://packages.microsoft.com/keys/microsoft.asc | apt-key add -; \
179-
curl -s https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list; \
133+
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg; \
134+
curl https://packages.microsoft.com/config/debian/12/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list; \
180135
apt-get update; \
181136
apt-get install -y \
182137
msodbcsql18 \
@@ -258,26 +213,19 @@ RUN set -eux; \
258213
mkdir -p $PHP_INSTALL_DIR; \
259214
chown -R circleci:circleci /opt;
260215

261-
# rust sha256sum generated locally after verifying it with sha256
262216
ARG RUST_VERSION="1.71.1"
263-
ARG RUST_SHA256_ARM="c7cf230c740a62ea1ca6a4304d955c286aea44e3c6fc960b986a8c2eeea4ec3f"
264-
ARG RUST_SHA256_X86="34778d1cda674990dfc0537bc600066046ae9cb5d65a07809f7e7da31d4689c4"
217+
# Nightly version which kinda matches v1.71.1
218+
ARG RUST_NIGHTLY_VERSION="-2023-05-03"
265219
# Mount a cache into /rust/cargo if you want to pre-fetch packages or something
266220
ENV CARGO_HOME=/rust/cargo
267221
ENV RUSTUP_HOME=/rust/rustup
268222
RUN mkdir -p -v "${CARGO_HOME}" "${RUSTUP_HOME}" \
269223
&& chmod -R 777 "${CARGO_HOME}" "${RUSTUP_HOME}" \
270224
&& MARCH=$(uname -m) \
271-
&& RUST_SHA256=$(if [ "$MARCH" = "x86_64" ]; then echo ${RUST_SHA256_X86}; elif [ "$MARCH" = "aarch64" ]; then echo ${RUST_SHA256_ARM}; fi) \
272-
&& FILENAME=rust-${RUST_VERSION}-${MARCH}-unknown-linux-gnu.tar.gz \
273-
&& curl -L --write-out '%{http_code}' -O https://static.rust-lang.org/dist/${FILENAME} \
274-
&& printf '%s %s' "$RUST_SHA256" "$FILENAME" | sha256sum --check --status \
275-
&& tar -xf "$FILENAME" \
276-
&& cd ${FILENAME%.tar.gz} \
277-
&& ./install.sh --components="rustc,cargo,clippy-preview,rustfmt-preview,rust-std-${MARCH}-unknown-linux-gnu" \
278-
&& cd - \
279-
&& rm -fr "$FILENAME" "${FILENAME%.tar.gz}" \
280-
&& rm -rfv /tmp/*
225+
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUST_VERSION -c "rustc,cargo,clippy-preview,rustfmt-preview,rust-std" \
226+
&& export PATH="/rust/cargo/bin:$PATH" \
227+
&& rustup install nightly${RUST_NIGHTLY_VERSION} \
228+
&& rustup component add rust-src --toolchain nightly${RUST_NIGHTLY_VERSION}-$MARCH-unknown-linux-gnu
281229

282230
ENV PATH="/rust/cargo/bin:${PATH}"
283231

@@ -291,7 +239,7 @@ USER circleci
291239

292240
RUN set -eux; \
293241
# Pretty prompt
294-
echo "PS1='\[\033[01;32m\]\u\[\033[00m\]\[\033[00;35m\](buster)\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" | \
242+
echo "PS1='\[\033[01;32m\]\u\[\033[00m\]\[\033[00;35m\](bookworm)\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" | \
295243
tee -a /home/circleci/.bashrc; \
296244
# Autocomplete of Makefile targets (see: https://stackoverflow.com/a/38415982)
297245
echo "complete -W \"\\\`grep -oE '^[a-zA-Z0-9_.-]+:([^=]|$)' ?akefile | sed 's/[^a-zA-Z0-9_.-]*$//'\\\`\" make" | \

dockerfiles/ci/bookworm/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The base image should be built and published first, before other jobs run.
2+
3+
The images are versioned, unlike the buster image. This so that when you are
4+
working on the next version of the image, you don't have to worry about
5+
breaking master; you only have to worry about other people also working on
6+
the next version. Version numbers are maintained in .env, and the
7+
docker-compose.yml file will use it, but other files (like the one in the
8+
root of the repository) may also need updated
9+

dockerfiles/ci/buster/build-php.sh renamed to dockerfiles/ci/bookworm/build-php.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ${PHP_SRC_DIR}/configure \
4141
$(if [[ ${PHP_VERSION_ID} -ge 71 ]]; then echo --enable-intl; fi) \
4242
--enable-mbstring \
4343
--enable-opcache \
44-
$(if [[ ${PHP_VERSION_ID} -ge 80 ]]; then echo --enable-zend-test=shared; fi) \
44+
$(if [[ ${PHP_VERSION_ID} -ge 80 ]] && [[ ${INSTALL_VERSION} != *asan* ]]; then echo --enable-zend-test=shared; fi) \
4545
--enable-pcntl \
4646
--enable-soap \
4747
--enable-sockets \

0 commit comments

Comments
 (0)