name: Kernel Test

on:
  pull_request:
  push:
    branches:
      - main

jobs:
  lint:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    container: asterinas/asterinas:0.4.2
    steps:
      - run: echo "Running in asterinas/asterinas:0.4.2"

      - uses: actions/checkout@v4
      
      - name: Check
        id: check
        run: make check

  unit-test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    container: asterinas/asterinas:0.4.2
    steps:
      - run: echo "Running in asterinas/asterinas:0.4.2"

      - uses: actions/checkout@v4

      - name: Usermode Unit test
        id: usermode_unit_test
        run: make test

      - name: Ktest Unit Test
        id: ktest_unit_test
        run: make ktest

      # TODO: add component check.

  integration-test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    container: asterinas/asterinas:0.4.2
    steps:
      - run: echo "Running in asterinas/asterinas:0.4.2"

      - uses: actions/checkout@v4

      - name: Boot Test (Multiboot)
        id: boot_test_mb
        run: make run AUTO_TEST=boot ENABLE_KVM=0 BOOT_PROTOCOL=multiboot RELEASE_MODE=1

      - name: Boot Test (Multiboot2)
        id: boot_test_mb2
        run: make run AUTO_TEST=boot ENABLE_KVM=0 BOOT_PROTOCOL=multiboot2 RELEASE_MODE=1

      - name: Boot Test (MicroVM)
        id: boot_test_microvm
        run: make run AUTO_TEST=boot ENABLE_KVM=0 SCHEME=microvm RELEASE_MODE=1

      - name: Boot Test (Linux Legacy 32-bit Boot Protocol)
        id: boot_test_linux_legacy32
        run: make run AUTO_TEST=boot ENABLE_KVM=0 BOOT_PROTOCOL=linux-legacy32 RELEASE_MODE=1

      - name: Boot Test (Linux EFI Handover Boot Protocol)
        id: boot_test_linux_efi_handover64
        run: make run AUTO_TEST=boot ENABLE_KVM=0 BOOT_PROTOCOL=linux-efi-handover64 RELEASE_MODE=1

      - name: Syscall Test (Linux EFI Handover Boot Protocol)
        id: syscall_test
        run: make run AUTO_TEST=syscall ENABLE_KVM=0 BOOT_PROTOCOL=linux-efi-handover64 RELEASE_MODE=1

      - name: Syscall Test at Ext2 (MicroVM)
        id: syscall_test_at_ext2
        run: make run AUTO_TEST=syscall SYSCALL_TEST_DIR=/ext2 ENABLE_KVM=0 SCHEME=microvm RELEASE_MODE=1

      - name: Syscall Test at Exfat
        id: syscall_test_at_exfat_linux
        run: make run AUTO_TEST=syscall SYSCALL_TEST_DIR=/exfat EXTRA_BLOCKLISTS_DIRS=blocklists.exfat ENABLE_KVM=0 BOOT_PROTOCOL=linux-efi-handover64 RELEASE_MODE=1
        
      - name: Regression Test (Multiboot2)
        id: regression_test_linux
        run: make run AUTO_TEST=regression ENABLE_KVM=0 BOOT_PROTOCOL=multiboot2 RELEASE_MODE=1
