2024-10-17 00:45:00 +00:00
|
|
|
package discover
|
2023-11-29 19:00:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-05-22 05:21:04 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-11-29 19:00:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBasicGetGPUInfo(t *testing.T) {
|
|
|
|
info := GetGPUInfo()
|
2024-05-22 05:21:04 +00:00
|
|
|
assert.NotEmpty(t, len(info))
|
2024-03-30 16:50:05 +00:00
|
|
|
assert.Contains(t, "cuda rocm cpu metal", info[0].Library)
|
|
|
|
if info[0].Library != "cpu" {
|
|
|
|
assert.Greater(t, info[0].TotalMemory, uint64(0))
|
|
|
|
assert.Greater(t, info[0].FreeMemory, uint64(0))
|
2023-11-29 19:00:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-22 23:43:31 +00:00
|
|
|
func TestCPUMemInfo(t *testing.T) {
|
2024-03-30 16:50:05 +00:00
|
|
|
info, err := GetCPUMem()
|
2024-05-22 05:21:04 +00:00
|
|
|
require.NoError(t, err)
|
2023-12-22 23:43:31 +00:00
|
|
|
switch runtime.GOOS {
|
|
|
|
case "darwin":
|
|
|
|
t.Skip("CPU memory not populated on darwin")
|
|
|
|
case "linux", "windows":
|
|
|
|
assert.Greater(t, info.TotalMemory, uint64(0))
|
|
|
|
assert.Greater(t, info.FreeMemory, uint64(0))
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-23 22:11:56 +00:00
|
|
|
func TestByLibrary(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
input []GpuInfo
|
|
|
|
expect int
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := map[string]*testCase{
|
|
|
|
"empty": {input: []GpuInfo{}, expect: 0},
|
|
|
|
"cpu": {input: []GpuInfo{{Library: "cpu"}}, expect: 1},
|
|
|
|
"cpu + GPU": {input: []GpuInfo{{Library: "cpu"}, {Library: "cuda"}}, expect: 2},
|
|
|
|
"cpu + 2 GPU no variant": {input: []GpuInfo{{Library: "cpu"}, {Library: "cuda"}, {Library: "cuda"}}, expect: 2},
|
|
|
|
"cpu + 2 GPU same variant": {input: []GpuInfo{{Library: "cpu"}, {Library: "cuda", Variant: "v11"}, {Library: "cuda", Variant: "v11"}}, expect: 2},
|
|
|
|
"cpu + 2 GPU diff variant": {input: []GpuInfo{{Library: "cpu"}, {Library: "cuda", Variant: "v11"}, {Library: "cuda", Variant: "v12"}}, expect: 3},
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range testCases {
|
|
|
|
t.Run(k, func(t *testing.T) {
|
|
|
|
resp := (GpuInfoList)(v.input).ByLibrary()
|
|
|
|
if len(resp) != v.expect {
|
|
|
|
t.Fatalf("expected length %d, got %d => %+v", v.expect, len(resp), resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
// TODO - add some logic to figure out card type through other means and actually verify we got back what we expected
|