| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | @@ -629,7 +629,7 @@ func attachDisks(ctx context.Context, inst *limatype.Instance, vmConfig *vz.Virt |
| 6 | |
| 7 | func attachDisplay(inst *limatype.Instance, vmConfig *vz.VirtualMachineConfiguration) error { |
| 8 | switch *inst.Config.Video.Display { |
| 9 | - case "vz", "default": |
| 10 | + case "vz", "default", "offscreen": |
| 11 | var graphicsDeviceConfiguration vz.GraphicsDeviceConfiguration |
| 12 | if *inst.Config.OS == limatype.DARWIN { |
| 13 | var err error |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | @@ -339,9 +339,9 @@ func validateConfig(cfg *limatype.LimaYAML) error { |
| 19 | } |
| 20 | |
| 21 | switch videoDisplay := *cfg.Video.Display; videoDisplay { |
| 22 | - case "vz", "default", "none": |
| 23 | + case "vz", "default", "none", "offscreen": |
| 24 | default: |
| 25 | - logrus.Warnf("field `video.display` must be `vz`, `default`, or `none` for VZ driver , got %#q", videoDisplay) |
| 26 | + logrus.Warnf("field `video.display` must be `vz`, `default`, `none`, or `offscreen` for VZ driver, got %#q", videoDisplay) |
| 27 | } |
| 28 | var vzOpts limatype.VZOpts |
| 29 | if err := limayaml.Convert(cfg.VMOpts[limatype.VZ], &vzOpts, "vmOpts.vz"); err != nil { |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | @@ -9,15 +9,34 @@ import ( |
| 35 | "errors" |
| 36 | "os" |
| 37 | "path/filepath" |
| 38 | + "runtime" |
| 39 | "testing" |
| 40 | "time" |
| 41 | |
| 42 | "gotest.tools/v3/assert" |
| 43 | |
| 44 | + applevz "github.com/Code-Hex/vz/v3" |
| 45 | "github.com/lima-vm/lima/v2/pkg/limatype" |
| 46 | "github.com/lima-vm/lima/v2/pkg/limatype/filenames" |
| 47 | ) |
| 48 | |
| 49 | +func TestOffscreenGuestDisplay(t *testing.T) { |
| 50 | + if runtime.GOARCH != "arm64" { |
| 51 | + t.Skip("macOS guests require Apple Silicon") |
| 52 | + } |
| 53 | + inst := &limatype.Instance{Config: &limatype.LimaYAML{OS: new(limatype.DARWIN)}} |
| 54 | + inst.Config.Video.Display = new("offscreen") |
| 55 | + boot, err := newMacOSBootLoader() |
| 56 | + assert.NilError(t, err) |
| 57 | + config, err := applevz.NewVirtualMachineConfiguration(boot, 2, 4<<30) |
| 58 | + assert.NilError(t, err) |
| 59 | + assert.NilError(t, attachDisplay(inst, config)) |
| 60 | + |
| 61 | + driver := &LimaVzDriver{Instance: inst} |
| 62 | + assert.Equal(t, driver.Info(t.Context()).Features.CanRunGUI, false) |
| 63 | + assert.ErrorContains(t, driver.RunGUI(t.Context()), "RunGUI is not supported") |
| 64 | +} |
| 65 | + |
| 66 | func TestWaitForStopped(t *testing.T) { |
| 67 | t.Run("returns nil after the VM has stopped", func(t *testing.T) { |
| 68 | l := &LimaVzDriver{machine: &virtualMachineWrapper{}} |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | @@ -64,6 +64,10 @@ func Validate(y *limatype.LimaYAML, warn bool) error { |
| 74 | errs = errors.Join(errs, fmt.Errorf("field `arch` must be one of %v; got %#q", limatype.ArchTypes, *y.Arch)) |
| 75 | } |
| 76 | |
| 77 | + if y.Video.Display != nil && *y.Video.Display == "offscreen" && (*y.OS != limatype.DARWIN || y.VMType == nil || *y.VMType != limatype.VZ) { |
| 78 | + errs = errors.Join(errs, errors.New("video.display offscreen requires a macOS guest with the VZ driver")) |
| 79 | + } |
| 80 | + |
| 81 | if y.User.Shell != nil { |
| 82 | shell := *y.User.Shell |
| 83 | if *y.OS == limatype.WINDOWS { |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | @@ -23,6 +23,26 @@ func TestValidateEmpty(t *testing.T) { |
| 89 | assert.Error(t, err, "field `images` must be set") |
| 90 | } |
| 91 | |
| 92 | +func TestOffscreenDisplayRequiresMacOSAndVZ(t *testing.T) { |
| 93 | + for _, tc := range []struct{ os, driver string }{ |
| 94 | + {limatype.DARWIN, limatype.VZ}, |
| 95 | + {limatype.LINUX, limatype.VZ}, |
| 96 | + {limatype.DARWIN, limatype.QEMU}, |
| 97 | + } { |
| 98 | + t.Run(tc.os+"-"+tc.driver, func(t *testing.T) { |
| 99 | + body := fmt.Sprintf("os: %s\nvmType: %s\nvideo: {display: offscreen}\nimages: [{location: /}]\n", tc.os, tc.driver) |
| 100 | + y, err := Load(t.Context(), []byte(body), "lima.yaml") |
| 101 | + assert.NilError(t, err) |
| 102 | + err = Validate(y, false) |
| 103 | + if tc.os == limatype.DARWIN && tc.driver == limatype.VZ { |
| 104 | + assert.NilError(t, err) |
| 105 | + } else { |
| 106 | + assert.ErrorContains(t, err, "offscreen requires a macOS guest") |
| 107 | + } |
| 108 | + }) |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | func TestValidateMinimumLimaVersion(t *testing.T) { |
| 113 | images := `images: [{"location": "/"}]` |
| 114 | |