Adds server.go with the process lifecycle layer that manages spawning llama-server, waiting for readiness, and graceful shutdown. Includes three helper functions (findLlamaServer, freePort, serverEnv) and the full startServer/waitReady/stop lifecycle. The serverEnv function critically filters HIP_VISIBLE_DEVICES to mask the Ryzen 9 iGPU which crashes llama-server if not excluded. Co-Authored-By: Virgil <virgil@lethean.io> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
//go:build linux && amd64
|
|
|
|
package rocm
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFindLlamaServer_InPATH(t *testing.T) {
|
|
// llama-server is at /usr/local/bin/llama-server on this machine.
|
|
path, err := findLlamaServer()
|
|
require.NoError(t, err)
|
|
assert.Contains(t, path, "llama-server")
|
|
}
|
|
|
|
func TestFindLlamaServer_EnvOverride(t *testing.T) {
|
|
t.Setenv("ROCM_LLAMA_SERVER_PATH", "/usr/local/bin/llama-server")
|
|
path, err := findLlamaServer()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "/usr/local/bin/llama-server", path)
|
|
}
|
|
|
|
func TestFindLlamaServer_EnvNotFound(t *testing.T) {
|
|
t.Setenv("ROCM_LLAMA_SERVER_PATH", "/nonexistent/llama-server")
|
|
_, err := findLlamaServer()
|
|
assert.ErrorContains(t, err, "not found")
|
|
}
|
|
|
|
func TestFreePort(t *testing.T) {
|
|
port, err := freePort()
|
|
require.NoError(t, err)
|
|
assert.Greater(t, port, 0)
|
|
assert.Less(t, port, 65536)
|
|
}
|
|
|
|
func TestFreePort_UniquePerCall(t *testing.T) {
|
|
p1, err := freePort()
|
|
require.NoError(t, err)
|
|
p2, err := freePort()
|
|
require.NoError(t, err)
|
|
_ = p1
|
|
_ = p2
|
|
}
|
|
|
|
func TestServerEnv_HIPVisibleDevices(t *testing.T) {
|
|
env := serverEnv()
|
|
var hipVals []string
|
|
for _, e := range env {
|
|
if strings.HasPrefix(e, "HIP_VISIBLE_DEVICES=") {
|
|
hipVals = append(hipVals, e)
|
|
}
|
|
}
|
|
assert.Equal(t, []string{"HIP_VISIBLE_DEVICES=0"}, hipVals)
|
|
}
|
|
|
|
func TestServerEnv_FiltersExistingHIP(t *testing.T) {
|
|
t.Setenv("HIP_VISIBLE_DEVICES", "1")
|
|
env := serverEnv()
|
|
var hipVals []string
|
|
for _, e := range env {
|
|
if strings.HasPrefix(e, "HIP_VISIBLE_DEVICES=") {
|
|
hipVals = append(hipVals, e)
|
|
}
|
|
}
|
|
assert.Equal(t, []string{"HIP_VISIBLE_DEVICES=0"}, hipVals)
|
|
}
|