Principle 1 — Predictable Names: - rocmModel.srv → rocmModel.server (struct field) - recordMetrics: met → metrics (local var) - backend.go/model.go: cfg → config (local vars) - gguf.go: tc/kc → tensorCount32/kvCount32 (v2 count reads) Principle 2 — Comments as Usage Examples: - Added concrete usage examples to all exported functions: VRAMInfo, ModelInfo, DiscoverModels, GetVRAMInfo, ROCmAvailable, LoadModel, Available, NewClient, Health, ChatComplete, Complete, ReadMetadata, FileTypeName Principle 5 — Test naming (_Good/_Bad/_Ugly): - All test functions renamed to AX-7 convention across: discover_test.go, vram_test.go, server_test.go, internal/gguf/gguf_test.go, internal/llamacpp/client_test.go, internal/llamacpp/health_test.go Also: fix go.sum missing entry for dappco.re/go/core transitive dep (pulled in by go-inference replace directive). All tests pass: go test ./... -short -count=1 Co-Authored-By: Virgil <virgil@lethean.io> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
//go:build linux && amd64
|
|
|
|
package rocm
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestReadSysfsUint64_Good(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "test_value")
|
|
require.NoError(t, os.WriteFile(path, []byte("17163091968\n"), 0644))
|
|
|
|
val, err := readSysfsUint64(path)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, uint64(17163091968), val)
|
|
}
|
|
|
|
func TestReadSysfsUint64_Bad_NotFound(t *testing.T) {
|
|
_, err := readSysfsUint64("/nonexistent/path")
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestReadSysfsUint64_Bad_InvalidContent(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "bad_value")
|
|
require.NoError(t, os.WriteFile(path, []byte("not-a-number\n"), 0644))
|
|
|
|
_, err := readSysfsUint64(path)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestReadSysfsUint64_Bad_EmptyFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "empty_value")
|
|
require.NoError(t, os.WriteFile(path, []byte(""), 0644))
|
|
|
|
_, err := readSysfsUint64(path)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestGetVRAMInfo_Good(t *testing.T) {
|
|
info, err := GetVRAMInfo()
|
|
if err != nil {
|
|
t.Skipf("no VRAM sysfs info available: %v", err)
|
|
}
|
|
|
|
// On this machine, the dGPU (RX 7800 XT) has ~16GB VRAM.
|
|
assert.Greater(t, info.Total, uint64(8*1024*1024*1024), "expected dGPU with >8GB VRAM")
|
|
assert.Greater(t, info.Used, uint64(0), "expected some VRAM in use")
|
|
assert.Equal(t, info.Total-info.Used, info.Free, "Free should equal Total-Used")
|
|
}
|