name: Ubuntu

on: [push, pull_request]

jobs:
  build:
    name: Build on Ubuntu
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1

    - name: Build
      run: go build

  test-unit:
    name: Unit Testing
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1

    - name: Install dependencies for tests
      run: |
        sudo apt-get update
        sudo apt-get install qemu-system-x86

    - name: Bootstrap
      run: ./tools/qemu-debian-img/bootstrap.sh

    - name: Unit Testing
      run: go test -parallel 1 -v ./...

  test-end-to-end:
    name: End-to-End Testing
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1

    - name: Build
      run: go build

    - name: Install dependencies for tests
      run: |
        sudo apt-get update
        sudo apt-get install qemu-system-x86

    - name: End-to-End Testing [Kernel Module]
      run: |
        cd examples/kernel-module
        ../../out-of-tree kernel autogen --max=1
        ../../out-of-tree pew --qemu-timeout=10m

    - name: End-to-End Testing [Kernel Exploit]
      run: |
        cd examples/kernel-exploit
        ../../out-of-tree kernel autogen --max=1
        ../../out-of-tree pew --threshold=0 --qemu-timeout=10m