name: Test Asterinas Vsock

on:
  workflow_dispatch:

jobs:
  vsock-test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v4

      - name: Run Vsock Server on Host
        id: host_vsock_server
        run: |
            sudo modprobe vhost_vsock
            sudo apt-get install socat
            echo "Run vsock server on host...."
            socat -ddd VSOCK-LISTEN:1234,fork \
              SYSTEM:'while read cmd; do result=$(eval "$cmd" 2>&1); echo "$result"; done' &
      - name: Run Vsock Client and Server on Guest
        id: guest_vsock_client_server
        run: |
            docker run \
              --privileged --network=host --device=/dev/kvm \
              -v ./:/root/asterinas asterinas/asterinas:0.15.0-20250509 \
              make run AUTO_TEST=vsock ENABLE_KVM=0 SCHEME=microvm RELEASE_MODE=1 &
      - name: Run Vsock Client on Host
        id: host_vsock_client
        run: |
          sleep 6m
          echo "Run vsock client on host...."
          echo "Hello from host" | socat -dd - vsock-connect:3:4321
