name: Profiling Native Tests with Sanitizers

on:
  push:
    branches:
      - main
      - "mq-working-branch**"
  pull_request:
    paths:
    - ddtrace/internal/datadog/profiling/**
    - ddtrace/profiling/**
    - .github/workflows/profiling-native.yml
  workflow_dispatch: {}

jobs:
  test:
    runs-on: ${{ matrix.os }}
    timeout-minutes: 9
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04]
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
        memcpy-mode: ["default", "fast"]
        sanitizer: ["safety", "thread", "valgrind"]

    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          persist-credentials: false
          fetch-depth: 1

      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
        with:
          python-version: ${{ matrix.python-version }}

      - uses: KyleMayes/install-llvm-action@a7a1a882e2d06ebe05d5bb97c3e1f8c984ae96fc # v2.0.7
        with:
          version: "19"
          cached: true

      - name: Install Valgrind
        if: ${{ matrix.sanitizer == 'valgrind' }}
        run: |
          sudo apt update
          sudo apt-get install -y valgrind

      - name: Run tests with sanitizers
        run: |
          # DEV: We currently have tests in dd_wrapper and stack_v2, setting
          # stack_v2 here will also run tests in dd_wrapper. Revisit this when
          # that changes.
          if [ "${{matrix.memcpy-mode}}" == "fast" ]; then
            export ECHION_USE_FAST_COPY_MEMORY=1
          else
            export ECHION_USE_FAST_COPY_MEMORY=0
          fi

          ./ddtrace/internal/datadog/profiling/build_standalone.sh --${{matrix.sanitizer}} RelWithDebInfo stack_v2_test
