Skip to content

Commit 7f1cc6f

Browse files
committed
ci: add go-http and dotnet-http to test matrix
HTTP server examples need a different test path: start the server in the background, poll until ready, curl the endpoint, check the response body, then kill the server. Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 170b580 commit 7f1cc6f

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

.github/workflows/test-examples.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
- python-agent-driver
6262
- powershell
6363
- networking-py
64+
- go-http
65+
- dotnet-http
6466
steps:
6567
- uses: actions/checkout@v4
6668

@@ -223,6 +225,14 @@ jobs:
223225
- example: networking-py
224226
args: "--port 8080 -- /echo_server_test.py"
225227
expect: "SUCCESS: bind\\+listen on port 8080 allowed"
228+
- example: go-http
229+
args: "--port 8080 -- /bin/server"
230+
expect: "Hello from Hyperlight-Unikraft!"
231+
http_port: "8080"
232+
- example: dotnet-http
233+
args: "--port 8080 -- /app/KestrelHyperlight"
234+
expect: "Hello from Kestrel on Hyperlight!"
235+
http_port: "8080"
226236
steps:
227237
- uses: actions/checkout@v4
228238

@@ -338,6 +348,41 @@ jobs:
338348
mkdir -p "$mount_dir"
339349
mount_args="--mount $mount_dir:/host"
340350
fi
351+
# HTTP server examples: start in background, poll, curl, kill.
352+
http_port="${{ matrix.http_port }}"
353+
if [ -n "$http_port" ]; then
354+
mem_args=""
355+
if [ -n "$memory" ]; then
356+
mem_args="-m $memory"
357+
fi
358+
hyperlight-unikraft -q $mem_args "$kernel" --initrd "$cpio" ${{ matrix.args }} &
359+
server_pid=$!
360+
ready=0
361+
for i in $(seq 1 30); do
362+
if curl -s --max-time 2 "http://localhost:${http_port}" >/dev/null 2>&1; then
363+
ready=1
364+
break
365+
fi
366+
sleep 1
367+
done
368+
if [ "$ready" -ne 1 ]; then
369+
echo "FAIL: server did not become ready within 30s"
370+
kill "$server_pid" 2>/dev/null || true
371+
exit 1
372+
fi
373+
response=$(curl -s --max-time 5 "http://localhost:${http_port}")
374+
kill "$server_pid" 2>/dev/null || true
375+
wait "$server_pid" 2>/dev/null || true
376+
echo "=== HTTP response ==="
377+
echo "$response"
378+
if echo "$response" | grep -qF "$expect"; then
379+
echo "PASS: matched /$expect/"
380+
else
381+
echo "FAIL: did not match /$expect/"
382+
exit 1
383+
fi
384+
exit 0
385+
fi
341386
case "${{ matrix.driver }}" in
342387
multifn-test)
343388
cmd=(timeout 60 /home/runner/work/hyperlight-unikraft/hyperlight-unikraft/host/target/release/multifn-test "$kernel" "$cpio")
@@ -403,6 +448,8 @@ jobs:
403448
- python-agent-driver
404449
- powershell
405450
- networking-py
451+
- go-http
452+
- dotnet-http
406453
steps:
407454
- uses: actions/checkout@v4
408455

@@ -554,6 +601,14 @@ jobs:
554601
- example: networking-py
555602
args: "--port 8080 -- /echo_server_test.py"
556603
expect: "SUCCESS: bind\\+listen on port 8080 allowed"
604+
- example: go-http
605+
args: "--port 8080 -- /bin/server"
606+
expect: "Hello from Hyperlight-Unikraft!"
607+
http_port: "8080"
608+
- example: dotnet-http
609+
args: "--port 8080 -- /app/KestrelHyperlight"
610+
expect: "Hello from Kestrel on Hyperlight!"
611+
http_port: "8080"
557612
steps:
558613
- uses: actions/checkout@v4
559614

@@ -622,6 +677,48 @@ jobs:
622677
$PSNativeCommandUseErrorActionPreference = $false
623678
$ErrorActionPreference = 'Continue'
624679
680+
# HTTP server examples: start in background, poll, curl, kill.
681+
$httpPort = '${{ matrix.http_port }}'
682+
if ($httpPort -ne '') {
683+
$argList = @()
684+
if ($runArgs -ne '') {
685+
$argList = $runArgs.Split(' ') | Where-Object { $_ -ne '' }
686+
}
687+
$memArgs = @()
688+
if ($memory -ne '') {
689+
$memArgs = @('-m', $memory)
690+
}
691+
$proc = Start-Process -FilePath 'hyperlight-unikraft' `
692+
-ArgumentList (@('-q') + $memArgs + @($kernel, '--initrd', $cpio) + $argList) `
693+
-PassThru -NoNewWindow
694+
$ready = $false
695+
for ($i = 0; $i -lt 30; $i++) {
696+
try {
697+
$null = Invoke-WebRequest -Uri "http://localhost:${httpPort}" -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop
698+
$ready = $true
699+
break
700+
} catch {
701+
Start-Sleep -Seconds 1
702+
}
703+
}
704+
if (-not $ready) {
705+
Write-Host "FAIL: server did not become ready within 30s"
706+
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
707+
exit 1
708+
}
709+
$resp = (Invoke-WebRequest -Uri "http://localhost:${httpPort}" -UseBasicParsing -TimeoutSec 5).Content
710+
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
711+
Write-Host "=== HTTP response ==="
712+
Write-Host $resp
713+
if ($resp -match [regex]::Escape($expect)) {
714+
Write-Host "PASS: matched /$expect/"
715+
exit 0
716+
} else {
717+
Write-Host "FAIL: did not match /$expect/"
718+
exit 1
719+
}
720+
}
721+
625722
switch ($driver) {
626723
'multifn-test' {
627724
$out = & multifn-test $kernel $cpio 2>&1

0 commit comments

Comments
 (0)