go-rocm/vram_test.go
Snider 9aaa404397
Some checks failed
Security Scan / security (pull_request) Successful in 7s
Test / Vet & Build (pull_request) Failing after 21s
fix(dx): audit coding standards and add tests for untested paths
- CLAUDE.md: document coreerr.E() error handling and go-io exclusion
- server_test.go: replace fmt.Errorf with coreerr.E() in test fixtures
- gguf_test.go: add tests for v2 format, skipValue (all type branches),
  readTypedValue uint64 path, unsupported version, truncated file
- discover_test.go: add test for corrupt GGUF file skipping
- vram_test.go: add tests for invalid/empty sysfs content

Coverage: 65.8% → 79.2% (+13.4%)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 08:50:17 +00:00

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(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_NotFound(t *testing.T) {
_, err := readSysfsUint64("/nonexistent/path")
assert.Error(t, err)
}
func TestReadSysfsUint64_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_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(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")
}