# Run all tests on PMEM.
#
# This workflow is run on 'self-hosted' runners.
name: PMEM tests

on:
  workflow_dispatch:
  schedule:
    # run this job at 18:00 UTC every day
    - cron:  '0 18 * * *'

jobs:
  # Test the default build with the basic test suite.
  Basic:
    strategy:
      matrix:
        VALGRIND: [0, 1]
    name: Basic ${{ matrix.VALGRIND == 0  && 'w/o Valgrind' || 'w/ Valgrind' }}
    uses: ./.github/workflows/pmem_test_matrix.yml
    with:
      # Exclude all Valgrind tests. All tests employing Valgrind tooling are run
      # in the dedicated workflows below.
      force_enable: '["none"]'
      valgrind: ${{ matrix.VALGRIND }}


  # Test the default build with force-enabled Valgrind tooling for (persistent)
  # memory error detection.
  Memory:
    uses: ./.github/workflows/pmem_test_matrix.yml
    with:
      force_enable: '["pmemcheck", "memcheck"]'
      valgrind: 1


  # Test the default build with force-enabled Valgrind tooling for thread error
  # detection.
  Thread:
    uses: ./.github/workflows/pmem_test_matrix.yml
    with:
      force_enable: '["drd", "helgrind"]'
      valgrind: 1
      # 9h = 7h20m (the longest workflow execution time) + ~20% leeway.
      timeout_minutes: 540


  # Static builds are tested in this limited scope only.
  static:
    name: Static
    if: github.repository == 'pmem/pmdk'
    runs-on: [self-hosted, rhel]
    strategy:
      fail-fast: false
      matrix:
        build: [static_debug, static_nondebug]

    steps:
      - uses: actions/checkout@v4

      - name: Test prepare
        uses: ./.github/actions/pmem_test_prepare
        with:
          valgrid: 1

      - name: Test run
        uses: ./.github/actions/pmem_test_run
        with:
          build: ${{ matrix.build }}


  # Testing the fault injection scenarios requires including this capability
  # at compile time.
  fault_injection:
    name: Fault injection
    if: github.repository == 'pmem/pmdk'
    runs-on: [self-hosted, rhel]

    steps:
      - uses: actions/checkout@v4

      - name: Test prepare
        uses: ./.github/actions/pmem_test_prepare
        with:
          fault_injection: '1'
          valgrind: 1

      - name: Test run
        uses: ./.github/actions/pmem_test_run
        with:
          build: nondebug # only the production build is considered
          test_label: fault_injection # only dedicated scenarios


  # By default, PMDK is built with NDCTL in order to provide RAS features.
  # This build is only viable as long as DAOS builds PMDK with NDCTL_ENABLE=n
  # https://github.com/daos-stack/pmdk/pull/12
  # It should be removed as soon as following PR is merged
  # https://github.com/daos-stack/pmdk/pull/35
  ndctl_enable_n:
    name: Without ndctl
    if: github.repository == 'pmem/pmdk'
    runs-on: [self-hosted, rhel]

    steps:
      - uses: actions/checkout@v4

      - name: Test prepare
        uses: ./.github/actions/pmem_test_prepare
        with:
          ndctl_enable: n
          valgrind: 0

      - name: Test run
        uses: ./.github/actions/pmem_test_run
        with:
          build: nondebug # only the production build is considered
