name: C Zephyr tests

on:
  workflow_call:
    inputs:
      compiler-ref:
        required: false
        type: string
      runtime-ref:
        required: false
        type: string
      use-cpp:
        required: false
        type: boolean
        default: false
      scheduler:
        required: false
        type: string

jobs:
  zephyr-tests:
    runs-on: ubuntu-24.04
    steps:
      - name: Check out lingua-franca repository
        uses: actions/checkout@v3
        with:
          repository: lf-lang/lingua-franca
          submodules: true
          ref: ${{ inputs.compiler-ref }}
          fetch-depth: 0
      - name: Prepare build environment
        uses: ./.github/actions/prepare-build-env
      - name: Setup Zephyr
        uses: ./.github/actions/setup-zephyr
      - name: Check out specific ref of reactor-c
        uses: actions/checkout@v3
        with:
          repository: lf-lang/reactor-c
          path: core/src/main/resources/lib/c/reactor-c
          ref: ${{ inputs.runtime-ref }}
        if: ${{ inputs.runtime-ref }}
      - name: Run Zephyr smoke tests
        run: |
          ./gradlew core:integrationTest \
            --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrUnthreaded* \
            --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrThreaded* core:integrationTestCodeCoverageReport
          ./.github/scripts/run-zephyr-tests.sh test/C/src-gen
          rm -rf test/C/src-gen
      # - name: Run basic tests
      #   run: |
      #     ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildBasic* core:integrationTestCodeCoverageReport
      #     ./.github/scripts/run-zephyr-tests.sh test/C/src-gen
      #     rm -rf test/C/src-gen
      # - name: Run concurrent tests
      #   run: |
      #     ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildConcurrent* core:integrationTestCodeCoverageReport
      #     ./.github/scripts/run-zephyr-tests.sh test/C/src-gen
      #     rm -rf test/C/src-gen
      - name: Run Zephyr board tests
        run: |
          ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrBoards* core:integrationTestCodeCoverageReport
          rm -rf test/C/src-gen
      - name: Smoke test of lf-west-template
        run: |
          export LFC=$(pwd)/bin/lfc-dev
          cd $LF_WEST_TEMPLATE_BASE
          west lfc apps/HelloWorld/src/HelloWorld.lf --lfc $LFC --build "-p always"
          west lfc apps/NrfBlinky/src/NrfBlinky.lf --lfc $LFC --build "-p always"
          west lfc apps/NrfBlinky/src/NrfToggleGPIO.lf --lfc $LFC --build "-p always"
          west build -b qemu_cortex_m3 -p always apps/HelloZephyr
      - name: Report to CodeCov
        uses: ./.github/actions/report-code-coverage
        with:
          files: core/build/reports/jacoco/integrationTestCodeCoverageReport/integrationTestCodeCoverageReport.xml
        if: ${{ github.repository == 'lf-lang/lingua-franca' }}
