name: "Test x86-64  "

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

jobs:
  basic-test:
    runs-on: ubuntu-latest
    container:
      image: asterinas/asterinas:0.17.2-20260407
      options: -v /dev:/dev --privileged
      volumes:
        # Map the following directories on the host into the container so that
        # the container can remove them to save some precious disk space (~16GB),
        # which is quite limited on free-tier Github runners.
        - /usr/lib/google-cloud-sdk:/usr/lib/google-cloud-sdk
        - /usr/local/lib/android:/usr/local/lib/android
        - /usr/share/dotnet:/usr/share/dotnet
    strategy:
      fail-fast: false
      matrix:
        id: ['lint', 'compile', 'usermode_test', 'ktest']
    steps:
      - name: Free disk space
        # Remove unused packages from the host to save disk space.
        run: rm -rf /usr/lib/google-cloud-sdk/* /usr/local/lib/android/* /usr/share/dotnet/*
      - uses: actions/checkout@v4
      - name: Run basic tests
        uses: ./.github/actions/test
        with:
          auto_test: 'general'
          runs_on: 'ubuntu-latest'

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

  boot-test:
    runs-on: ubuntu-latest
    container:
      image: asterinas/asterinas:0.17.2-20260407
      options: -v /dev:/dev --privileged
    strategy:
      fail-fast: false
      matrix:
        include:
          - { variant: 'legacy32', boot_protocol: 'linux-legacy32', smp: 4 }
          - { variant: 'multiboot2-smp4', boot_protocol: 'multiboot', smp: 4 }
    steps:
      - uses: actions/checkout@v4
      - name: Run boot test (${{ matrix.variant }})
        uses: ./.github/actions/test
        with:
          auto_test: 'boot'
          smp: ${{ matrix.smp }}
          boot_protocol: ${{ matrix.boot_protocol }}

  regression-test:
    runs-on: ubuntu-latest
    container:
      image: asterinas/asterinas:0.17.2-20260407
      options: -v /dev:/dev --privileged
      volumes:
        # Map the following directories on the host into the container so that
        # the container can remove them to save some precious disk space (~16GB),
        # which is quite limited on free-tier Github runners.
        - /usr/lib/google-cloud-sdk:/usr/lib/google-cloud-sdk
        - /usr/local/lib/android:/usr/local/lib/android
        - /usr/share/dotnet:/usr/share/dotnet
    strategy:
      fail-fast: false
      matrix:
        include:
          - { variant: 'handover64-debug', release: false, boot_protocol: 'linux-efi-handover64' }
          - { variant: 'multiboot2-smp4',  boot_protocol: 'multiboot2', smp: 4 }
    steps:
      - name: Free disk space
        # Remove unused packages from the host to save disk space.
        run: rm -rf /usr/lib/google-cloud-sdk/* /usr/local/lib/android/* /usr/share/dotnet/*
      - uses: actions/checkout@v4
      - name: Run regression test (${{ matrix.variant }})
        uses: ./.github/actions/test
        with:
          auto_test: 'regression'
          release: ${{ !contains(matrix.release, 'false') }}
          smp: ${{ matrix.smp }}
          boot_protocol: ${{ matrix.boot_protocol || 'linux-efi-handover64' }}

  conformance-test:
    runs-on: ubuntu-latest
    container:
      image: asterinas/asterinas:0.17.2-20260407
      options: -v /dev:/dev --privileged
      volumes:
        # Map the following directories on the host into the container so that
        # the container can remove them to save some precious disk space (~16GB),
        # which is quite limited on free-tier Github runners.
        - /usr/lib/google-cloud-sdk:/usr/lib/google-cloud-sdk
        - /usr/local/lib/android:/usr/local/lib/android
        - /usr/share/dotnet:/usr/share/dotnet
    strategy:
      fail-fast: false
      matrix:
        suite: ['ltp', 'gvisor', 'kselftest']
        variant:
          - 'debug'
          - 'ext2-microvm'
          - 'ext2-iommu-debug'
          - 'exfat-multiboot2-nokvm'
          - 'multiboot2-smp4'
        include:
          - { variant: 'debug', release: false, boot_protocol: 'linux-efi-pe64' }
          - { variant: 'ext2-microvm', scheme: 'microvm', extra_blocklists: 'blocklists.ext2', conformance_test_workdir: '/ext2' }
          - { variant: 'ext2-iommu-debug', scheme: 'iommu', extra_blocklists: 'blocklists.ext2', conformance_test_workdir: '/ext2', release: false }
          - { variant: 'exfat-multiboot2-nokvm', boot_protocol: 'multiboot2', enable_kvm: false, extra_blocklists: 'blocklists.exfat', conformance_test_workdir: '/exfat' }
          - { variant: 'multiboot2-smp4', boot_protocol: 'multiboot2', smp: 4 }
    steps:
      - name: Free disk space
        # Remove unused packages from the host to save disk space.
        run: rm -rf /usr/lib/google-cloud-sdk/* /usr/local/lib/android/* /usr/share/dotnet/*
      - uses: actions/checkout@v4
      - name: Run conformance test (${{ matrix.variant }}, ${{ matrix.suite }})
        uses: ./.github/actions/test
        with:
          auto_test: 'conformance'
          release: ${{ !contains(matrix.release, 'false') }}
          enable_kvm: ${{ !contains(matrix.enable_kvm, 'false') }}
          smp: ${{ matrix.smp }}
          netdev: ${{ matrix.netdev || 'tap' }}
          scheme: ${{ matrix.scheme }}
          extra_blocklists: ${{ matrix.extra_blocklists }}
          conformance_test_suite: ${{ matrix.suite }}
          conformance_test_workdir: ${{ matrix.conformance_test_workdir }}
          boot_protocol: ${{ matrix.boot_protocol || 'linux-efi-handover64' }}

  cross-compile-test:
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: arm-cross-boot
            runs_on: ubuntu-24.04-arm
            image: asterinas/asterinas:0.17.2-20260407
            auto_test: boot
            enable_kvm: false
    runs-on: ${{ matrix.runs_on }}
    container:
      image: ${{ matrix.image }}
    steps:
      - uses: actions/checkout@v4
      - name: Run cross-compile tests (${{ matrix.name }})
        uses: ./.github/actions/test
        with:
          auto_test: ${{ matrix.auto_test }}
          enable_kvm: ${{ matrix.enable_kvm }}
