56 lines
2.5 KiB
Go
56 lines
2.5 KiB
Go
package macosdriver
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
"github.com/Nwflower/reims-go/internal/host"
|
|
"github.com/Nwflower/reims-go/internal/plugin"
|
|
)
|
|
|
|
func TestPrepareHostMemorySMBIOS(t *testing.T) {
|
|
drv := &ReimsMacOSDriver{opts: Options{OwnerID: "builtin.guest.macos"}}
|
|
rep := host.Report{
|
|
MemorySpec: &host.HostMemorySpec{SpeedMHz: 6400, MemoryType: 34, TypeName: "DDR5"},
|
|
}
|
|
|
|
// Disabled by default: clears keyHostMemorySMBIOS.
|
|
var inOff plugin.StartIntent
|
|
drv.prepareHostMemorySMBIOS(config.Config{}, rep, "", func() bool { return true }, &inOff)
|
|
if len(inOff.Args) != 0 || !slices.Contains(inOff.ClearKeys, keyHostMemorySMBIOS) {
|
|
t.Fatalf("default off: got args=%v clear=%v", inOff.Args, inOff.ClearKeys)
|
|
}
|
|
|
|
// Enabled with memory_type support: emits speed + memory_type.
|
|
var inOn plugin.StartIntent
|
|
drv.prepareHostMemorySMBIOS(config.Config{SyncHostMemorySMBIOS: true}, rep, "", func() bool { return true }, &inOn)
|
|
if len(inOn.Args) != 1 || !slices.Equal(inOn.Args[0].Tokens, []string{"-smbios", "type=17,speed=6400,memory_type=34"}) {
|
|
t.Fatalf("enabled with memory_type: got %+v", inOn.Args)
|
|
}
|
|
if err := plugin.ValidateArgFragment(inOn.Args[0]); err != nil {
|
|
t.Fatalf("ValidateArgFragment rejected fragment: %v", err)
|
|
}
|
|
|
|
// Enabled without memory_type support: emits speed only.
|
|
var inNoType plugin.StartIntent
|
|
drv.prepareHostMemorySMBIOS(config.Config{SyncHostMemorySMBIOS: true}, rep, "", func() bool { return false }, &inNoType)
|
|
if len(inNoType.Args) != 1 || !slices.Equal(inNoType.Args[0].Tokens, []string{"-smbios", "type=17,speed=6400"}) {
|
|
t.Fatalf("enabled without memory_type: got %+v", inNoType.Args)
|
|
}
|
|
|
|
// Enabled when host speed unavailable: clears key.
|
|
var inUnknown plugin.StartIntent
|
|
drv.prepareHostMemorySMBIOS(config.Config{SyncHostMemorySMBIOS: true}, host.Report{}, "", func() bool { return true }, &inUnknown)
|
|
if len(inUnknown.Args) != 0 || !slices.Contains(inUnknown.ClearKeys, keyHostMemorySMBIOS) {
|
|
t.Fatalf("unknown speed: got args=%v clear=%v", inUnknown.Args, inUnknown.ClearKeys)
|
|
}
|
|
|
|
// User already supplied a manual -smbios type=17: respect it and clear ours.
|
|
var inManual plugin.StartIntent
|
|
drv.prepareHostMemorySMBIOS(config.Config{SyncHostMemorySMBIOS: true}, rep, "-smbios type=17,speed=5200", func() bool { return true }, &inManual)
|
|
if len(inManual.Args) != 0 || !slices.Contains(inManual.ClearKeys, keyHostMemorySMBIOS) {
|
|
t.Fatalf("user manual type=17: got args=%v clear=%v", inManual.Args, inManual.ClearKeys)
|
|
}
|
|
}
|