Skip to content

feat(ffe): support dependent flag evaluations #11405

feat(ffe): support dependent flag evaluations

feat(ffe): support dependent flag evaluations #11405

Workflow file for this run

name: Profiling ASAN/UBSAN Tests
on:
pull_request:
# Seed a default-branch cache that subsequent PRs can restore.
push:
branches: [master]
permissions:
contents: read
env:
# Keep producer and consumers identical: paths also determine cache version.
CARGO_DEPENDENCY_CACHE_PATHS: |
/rust/cargo/registry/index/
/rust/cargo/registry/cache/
/rust/cargo/registry/src/
/rust/cargo/git/db/
/rust/cargo/git/checkouts/
jobs:
cargo-deps:
name: Prepare Cargo dependencies
runs-on: ubuntu-8-core-latest
env:
CARGO_HOME: /rust/cargo
RUSTUP_HOME: /rust/rustup
container:
image: registry.datadoghq.com/dd-trace-ci:bookworm-15
options: --user root
outputs:
cache-key: ${{ steps.cargo-cache.outputs.cache-primary-key }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
submodules: true
- name: Restore Cargo dependencies
id: cargo-cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ env.CARGO_DEPENDENCY_CACHE_PATHS }}
# Sources are shared across PHP versions, architectures and sanitizers.
# Include the toolchain for std's dependencies and the fetch recipe.
key: ${{ runner.os }}-profiler-cargo-deps-v1-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml', '.github/workflows/prof_asan.yml') }}
restore-keys: |
${{ runner.os }}-profiler-cargo-deps-v1-
- name: Fetch Cargo dependencies
if: steps.cargo-cache.outputs.cache-hit != 'true'
run: |
set -eux
# Do not filter the workspace fetch by target: custom cfgs such as
# tokio_unstable activate additional dependencies during the build.
cargo fetch --locked
# ASAN rebuilds std; fetch its dependencies for both Linux targets.
RUSTC_BOOTSTRAP=1 RUSTFLAGS='--cfg tokio_unstable' \
cargo fetch --locked -Zbuild-std=std,panic_abort \
--target aarch64-unknown-linux-gnu \
--target x86_64-unknown-linux-gnu
# appsec_body is built offline by tools/isolate.rs with std rebuilt
# using panic_unwind. Fetch its dev-dependencies and target-specific
# std dependencies too.
RUSTC_BOOTSTRAP=1 cargo fetch --locked \
--manifest-path components-rs/appsec_body/Cargo.toml \
-Zbuild-std=std,panic_unwind \
--target aarch64-unknown-linux-gnu \
--target x86_64-unknown-linux-gnu
- name: Save Cargo dependencies
if: steps.cargo-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ env.CARGO_DEPENDENCY_CACHE_PATHS }}
key: ${{ steps.cargo-cache.outputs.cache-primary-key }}
prof-asan:
name: PHP ${{ matrix.php-version }} ${{ matrix.php-build }} (${{ matrix.runner }})
needs: cargo-deps
# master only prepares the cache; keep the test matrices PR-only.
if: github.event_name == 'pull_request'
runs-on: ${{ matrix.runner }}
strategy:
matrix:
php-version: [8.3, 8.4, 8.5, 8.6]
php-build: [nts-asan, debug-zts-asan]
runner: [arm-8core-linux, ubuntu-8-core-latest]
env:
CARGO_HOME: /rust/cargo
RUSTUP_HOME: /rust/rustup
CARGO_TARGET_DIR: /tmp/build-cargo
PROFILE_EXTENSION: ${{ matrix.php-version == 8.5 && matrix.php-build == 'nts-asan' && matrix.runner == 'ubuntu-8-core-latest' && 'ddtrace.so' || 'datadog-profiling.so' }}
# Applies to nested Cargo commands too. The copied workspace may update
# its lockfile, so use offline rather than frozen.
CARGO_NET_OFFLINE: 'true'
container:
image: registry.datadoghq.com/dd-trace-ci:php-${{matrix.php-version}}_bookworm-15
# https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#user
options: --user root
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
submodules: true
- name: Restore prepared Cargo dependencies
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ env.CARGO_DEPENDENCY_CACHE_PATHS }}
key: ${{ needs.cargo-deps.outputs.cache-key }}
fail-on-cache-miss: true
- name: Cache Cargo target
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /tmp/build-cargo/
key: ${{ runner.os }}-${{ runner.arch }}-cargo-target-asan-${{ matrix.php-version }}-${{ matrix.php-build }}-${{ hashFiles('rust-toolchain.toml') }}-${{ github.sha }}-${{ hashFiles('.github/workflows/prof_asan.yml') }}
- name: Build and install profiler
run: |
set -eux
switch-php ${{ matrix.php-build }}
php -r 'exit((int) ((bool) PHP_ZTS !== ${{ contains(matrix.php-build, 'zts') }}));' || { echo 'ERROR expected ${{ matrix.php-build }} PHP'; exit 1; }
export CC=clang-21
export CFLAGS='-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer'
export LDFLAGS='-fsanitize=address -shared-libasan'
# Both ASAN targets use the pinned stable toolchain and rebuild std.
if [ "${PROFILE_EXTENSION}" = "ddtrace.so" ]; then
make -j$(nproc) compile_combined_asan
cp -v tmp/build_combined_asan/modules/ddtrace.so "$(php-config --extension-dir)/ddtrace.so"
else
make -j$(nproc) compile_profiler_asan
cp -v tmp/build_profiler_asan/modules/datadog-profiling.so "$(php-config --extension-dir)/datadog-profiling.so"
fi
- name: Run phpt tests
run: |
set -eux
switch-php ${{ matrix.php-build }}
php -r 'exit((int) ((bool) PHP_ZTS !== ${{ contains(matrix.php-build, 'zts') }}));' || { echo 'ERROR expected ${{ matrix.php-build }} PHP'; exit 1; }
cd profiling/tests
cp -v $(php-config --prefix)/lib/php/build/run-tests.php .
export DD_PROFILING_OUTPUT_PPROF=/tmp/pprof
export DD_TRACE_ENABLED=false
export DD_INSTRUMENTATION_TELEMETRY_ENABLED=false
export DD_REMOTE_CONFIG_ENABLED=false
# Keep DSO globals visible to LSan until its process-exit leak scan.
export ZEND_DONT_UNLOAD_MODULES=1
export ASAN_OPTIONS="${ASAN_OPTIONS:+$ASAN_OPTIONS:}abort_on_error=1:halt_on_error=1:detect_leaks=1:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:detect_container_overflow=1:detect_odr_violation=2:symbolize=1:disable_coredump=0:unmap_shadow_on_exit=1"
export LSAN_OPTIONS="${LSAN_OPTIONS:+$LSAN_OPTIONS:}exitcode=23:print_suppressions=0:report_objects=1"
php run-tests.php -j$(nproc) --show-diff --asan -d "extension=${PROFILE_EXTENSION}" phpt
prof-ubsan:
name: PHP 8.5 ${{ matrix.php-build }} UBSAN (${{ matrix.runner }})
needs: cargo-deps
if: github.event_name == 'pull_request'
runs-on: ${{ matrix.runner }}
strategy:
matrix:
php-build: [nts, zts]
runner: [arm-8core-linux, ubuntu-8-core-latest]
env:
CARGO_HOME: /rust/cargo
RUSTUP_HOME: /rust/rustup
CARGO_TARGET_DIR: /tmp/build-cargo
CARGO_NET_OFFLINE: 'true'
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
container:
image: registry.datadoghq.com/dd-trace-ci:php-8.5_bookworm-15
options: --user root
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
submodules: true
- name: Restore prepared Cargo dependencies
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ env.CARGO_DEPENDENCY_CACHE_PATHS }}
key: ${{ needs.cargo-deps.outputs.cache-key }}
fail-on-cache-miss: true
- name: Cache Cargo target
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /tmp/build-cargo/
key: ${{ runner.os }}-${{ runner.arch }}-cargo-target-c-ubsan-8.5-${{ matrix.php-build }}-${{ github.sha }}-${{ hashFiles('.github/workflows/prof_asan.yml') }}
- name: Build and install profiler
run: |
set -eux
switch-php ${{ matrix.php-build }}
php -r 'exit((int) ((bool) PHP_ZTS !== ${{ contains(matrix.php-build, 'zts') }}));' || { echo 'ERROR expected ${{ matrix.php-build }} PHP'; exit 1; }
export CC=clang-21
export CXX=clang++-21
export CFLAGS='-fsanitize=undefined,local-bounds -fno-sanitize-recover=all -fno-omit-frame-pointer'
export LDFLAGS='-fsanitize=undefined,local-bounds -fno-sanitize-recover=all'
export RUSTFLAGS='-C link-arg=-fsanitize=undefined,local-bounds -C link-arg=-fno-sanitize-recover=all'
make -j$(nproc) compile_profiler
cp -v tmp/build_profiler/modules/datadog-profiling.so "$(php-config --extension-dir)/datadog-profiling.so"
- name: Run phpt tests
run: |
set -eux
switch-php ${{ matrix.php-build }}
php -r 'exit((int) ((bool) PHP_ZTS !== ${{ contains(matrix.php-build, 'zts') }}));' || { echo 'ERROR expected ${{ matrix.php-build }} PHP'; exit 1; }
cd profiling/tests
cp -v $(php-config --prefix)/lib/php/build/run-tests.php .
export DD_PROFILING_OUTPUT_PPROF=/tmp/pprof
ubsan_runtime=$(clang-21 -print-file-name=libclang_rt.ubsan_standalone-$(uname -m).so)
export LD_PRELOAD="$ubsan_runtime${LD_PRELOAD:+:$LD_PRELOAD}"
php run-tests.php -j$(nproc) --show-diff -d extension=datadog-profiling.so phpt