name: "Test x86-64  "

on:
  workflow_dispatch:
  pull_request:
  push:
    branches:
      - main

jobs:
  basic-test:
    runs-on: ubuntu-latest
    container:
      image: asterinas/asterinas:0.16.0-20250802
      options: --device=/dev/kvm --privileged
    strategy:
      matrix:
        id: ['lint', 'compile', 'usermode_test', 'ktest']
      fail-fast: false
    steps:
      - uses: actions/checkout@v4
      - name: Run basic tests
        uses: ./.github/actions/test
        with:
          auto_test: 'general'
          runs_on: 'ubuntu-latest'

  integration-test:
    runs-on: ubuntu-latest
    container:
      image: asterinas/asterinas:0.16.0-20250802
      options: --device=/dev/kvm --privileged
    strategy:
      matrix:
        include:
          # SMP Boot Test (Linux Legacy 32-bit Boot Protocol)
          - test_id: 'boot-legacy32'
            boot_protocol: 'linux-legacy32'
            smp: 4
          # SMP Boot Test (Multiboot)
          - test_id: 'boot-multiboot2-smp4'
            boot_protocol: 'multiboot'
            smp: 4

          # Syscall Test (Linux EFI PE/COFF Boot Protocol) (Debug Build)
          - test_id: 'syscall-debug'
            release: false
            boot_protocol: 'linux-efi-pe64'
          # Syscall Test at Ext2 (MicroVM)
          - test_id: 'syscall-ext2-microvm'
            scheme: 'microvm'
            syscall_test_workdir: '/ext2'
          # Syscall Test at Ext2 (IOMMU) (Debug Build)
          - test_id: 'syscall-ext2-iommu-debug'
            scheme: 'iommu'
            syscall_test_workdir: '/ext2'
            release: false
          # Syscall Test at Exfat (Multiboot2) (without KVM enabled)
          - test_id: 'syscall-exfat-multiboot2-nokvm'
            boot_protocol: 'multiboot2'
            enable_kvm: false
            extra_blocklists: 'blocklists.exfat'
            syscall_test_workdir: '/exfat'
          # SMP Syscall Test (Multiboot2)
          - test_id: 'syscall-multiboot2-smp4'
            boot_protocol: 'multiboot2'
            smp: 4

          # General Test (Linux EFI Handover)
          - test_id: 'general-handover64'
            boot_protocol: 'linux-efi-handover64'
          # SMP General Test (Multiboot2)
          - test_id: 'general-multiboot2-smp4'
            boot_protocol: 'multiboot2'
            smp: 4
      fail-fast: false
    steps:
      - uses: actions/checkout@v4
      - name: Run integration tests ${{ (startsWith(matrix.test_id, 'syscall') && 'with LTP') || '' }}
        uses: ./.github/actions/test
        with:
          auto_test: ${{ (startsWith(matrix.test_id, 'boot') && 'boot') ||
              (startsWith(matrix.test_id, 'syscall') && 'syscall') || 'test' }}
          release: ${{ matrix.release || true }}
          enable_kvm: ${{ matrix.enable_kvm || true }}
          smp: ${{ matrix.smp }}
          netdev: ${{ matrix.netdev || 'tap' }}
          scheme: ${{ matrix.scheme }}
          extra_blocklists: ${{ matrix.extra_blocklists }}
          syscall_test_suite: 'ltp'
          syscall_test_workdir: ${{ matrix.syscall_test_workdir }}
          boot_protocol: ${{ matrix.boot_protocol || 'linux-efi-handover64' }}
      - name: Run integration tests ${{ (startsWith(matrix.test_id, 'syscall') && 'with gVisor') || '' }}
        if: ${{ startsWith(matrix.test_id, 'syscall') }}
        uses: ./.github/actions/test
        with:
          auto_test: ${{ (startsWith(matrix.test_id, 'boot') && 'boot') ||
              (startsWith(matrix.test_id, 'syscall') && 'syscall') || 'test' }}
          release: ${{ matrix.release || true }}
          enable_kvm: ${{ matrix.enable_kvm || true }}
          smp: ${{ matrix.smp }}
          netdev: ${{ matrix.netdev || 'tap' }}
          scheme: ${{ matrix.scheme }}
          extra_blocklists: ${{ matrix.extra_blocklists }}
          syscall_test_suite: 'gvisor'
          syscall_test_workdir: ${{ matrix.syscall_test_workdir }}
          boot_protocol: ${{ matrix.boot_protocol || 'linux-efi-handover64' }}

  osdk-test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        image: ['asterinas/asterinas:0.16.0-20250802', 'asterinas/osdk:0.16.0-20250802']
      fail-fast: false
    container:
      image: ${{ matrix.image }}
      options: --device=/dev/kvm --privileged
    steps:
      - uses: actions/checkout@v4
      - name: Run OSDK tests
        uses: ./.github/actions/test
        with:
          auto_test: 'osdk'
          intel_tdx: false
