name: "On-demand test"
on:
  workflow_dispatch:
    inputs:
      branch:
        description: 'Branch or tag to test'
        required: true
        default: 'master'
        type: string
      args:
        description: 'Common test options'
        default: '-d'
        type: string
      unit_args:
        description: 'Unit test options'
        type: string
      run_args:
        description: 'Run test options'
        type: string
      python_args:
        description: 'Python test options'
        type: string

jobs:
  run-uftrace-tests:
    if: github.repository == 'namhyung/uftrace'
    runs-on: ubuntu-latest
    steps:
      - name: "checkout"
        uses: actions/checkout@v4
        with:
          ref: ${{ inputs.branch }}

      - name: "install dependencies"
        run: sudo ./misc/install-deps.sh -y

      - name: "configure build env"
        run: ./configure

      - name: "build the source"
        run: make DEBUG=1

      - name: "setup run-time env"
        run: |
          sudo sh -c "echo 1 > /proc/sys/kernel/perf_event_paranoid"
          sudo sh -c "echo 0 > /proc/sys/kernel/kptr_restrict"
          sudo sh -c "chmod +x /sys/kernel/tracing"

      - name: "run tests"
        run: make test -j1 DEBUG=1 TESTARG="${{ inputs.args }}" UNITTESTARG="${{ inputs.unit_args }}" RUNTESTARG="${{ inputs.run_args }}" PYTESTARG="${{ inputs.python_args }}"
