github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/integration/generic-tests/esxi_boot_test.go (about)

     1  // Copyright 2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !race
     6  // +build !race
     7  
     8  package integration
     9  
    10  import (
    11  	"fmt"
    12  	"os"
    13  	"testing"
    14  	"time"
    15  
    16  	expect "github.com/google/goexpect"
    17  	"github.com/mvdan/u-root-coreutils/pkg/qemu"
    18  	"github.com/mvdan/u-root-coreutils/pkg/vmtest"
    19  )
    20  
    21  func TestESXi(t *testing.T) {
    22  	img := os.Getenv("UROOT_ESXI_IMAGE")
    23  	if _, err := os.Stat(img); err != nil && os.IsNotExist(err) {
    24  		t.Skip("ESXi disk image is not present. Please set UROOT_ESXI_IMAGE= to an installed ESXi disk image.")
    25  	}
    26  
    27  	q, cleanup := vmtest.QEMUTest(t, &vmtest.Options{
    28  		TestCmds: []string{
    29  			`esxiboot -d="/dev/sda" --append="vmkBootVerbose=TRUE vmbLog=TRUE debugLogToSerial=1 logPort=com1"`,
    30  		},
    31  		QEMUOpts: qemu.Options{
    32  			Devices: []qemu.Device{
    33  				qemu.IDEBlockDevice{File: img},
    34  				// If at some point we get virtio-net working
    35  				// again in ESXi, you may need to set num CPUs
    36  				// to 4.
    37  				qemu.ArbitraryArgs{"-smp", "2"},
    38  
    39  				// QEMU is not good enough to do ESXi without KVM. You'll get kernel panic.
    40  				qemu.ArbitraryArgs{"-enable-kvm"},
    41  
    42  				// IvyBridge is the lowest-common-denominator.
    43  				// ESXi 7.0 drops support for SandyBridge
    44  				// afaict.
    45  				qemu.ArbitraryArgs{"-cpu", "IvyBridge"},
    46  
    47  				// Min ESXi requirement is 4G of memory, but in
    48  				// ESXi 7.0 some plugins fail to load at 4G
    49  				// under memory pressure, and we never get to
    50  				// "Boot Successful"
    51  				qemu.ArbitraryArgs{"-m", "8192"},
    52  			},
    53  		},
    54  	})
    55  	defer cleanup()
    56  
    57  	if out, err := q.ExpectBatch([]expect.Batcher{
    58  		// Last Linux print.
    59  		&expect.BExp{R: "kexec_core: Starting new kernel"},
    60  		// First b.b00 ESXi first-stage kernel print
    61  		&expect.BExp{R: "Serial port initialized..."},
    62  		// ~thirdish k.b00 ESXi second-stage kernel print
    63  		&expect.BExp{R: "Parsing command line boot options"},
    64  		// When we can be confident it's done.
    65  		&expect.BExp{R: "Boot Successful"},
    66  	}, 2*time.Minute); err != nil {
    67  		t.Fatalf("VM output did not match expectations: %v", out)
    68  	}
    69  }
    70  
    71  func TestESXiNVMe(t *testing.T) {
    72  	img := os.Getenv("UROOT_ESXI_IMAGE")
    73  	if _, err := os.Stat(img); err != nil && os.IsNotExist(err) {
    74  		t.Skip("ESXi disk image is not present. Please set UROOT_ESXI_IMAGE= to an installed ESXi disk image.")
    75  	}
    76  
    77  	q, cleanup := vmtest.QEMUTest(t, &vmtest.Options{
    78  		TestCmds: []string{
    79  			`esxiboot -d="/dev/nvme0n1" --append="vmkBootVerbose=TRUE vmbLog=TRUE debugLogToSerial=1 logPort=com1"`,
    80  		},
    81  		QEMUOpts: qemu.Options{
    82  			Devices: []qemu.Device{
    83  				qemu.ArbitraryArgs{"-device", "nvme,drive=NVME1,serial=nvme-1"},
    84  				qemu.ArbitraryArgs{"-drive", fmt.Sprintf("file=%s,if=none,id=NVME1", img)},
    85  
    86  				// If at some point we get virtio-net working
    87  				// again in ESXi, you may need to set num CPUs
    88  				// to 4.
    89  				qemu.ArbitraryArgs{"-smp", "2"},
    90  
    91  				// QEMU is not good enough to do ESXi without KVM. You'll get kernel panic.
    92  				qemu.ArbitraryArgs{"-enable-kvm"},
    93  
    94  				// IvyBridge is the lowest-common-denominator.
    95  				// ESXi 7.0 drops support for SandyBridge
    96  				// afaict.
    97  				qemu.ArbitraryArgs{"-cpu", "IvyBridge"},
    98  
    99  				// Min ESXi requirement is 4G of memory, but in
   100  				// ESXi 7.0 some plugins fail to load at 4G
   101  				// under memory pressure, and we never get to
   102  				// "Boot Successful"
   103  				qemu.ArbitraryArgs{"-m", "8192"},
   104  			},
   105  		},
   106  	})
   107  	defer cleanup()
   108  
   109  	if out, err := q.ExpectBatch([]expect.Batcher{
   110  		// Last Linux print.
   111  		&expect.BExp{R: "kexec_core: Starting new kernel"},
   112  		// First b.b00 ESXi first-stage kernel print
   113  		&expect.BExp{R: "Serial port initialized..."},
   114  		// ~thirdish k.b00 ESXi second-stage kernel print
   115  		&expect.BExp{R: "Parsing command line boot options"},
   116  		// When we can be confident it's done.
   117  		&expect.BExp{R: "Boot Successful"},
   118  	}, 2*time.Minute); err != nil {
   119  		t.Fatalf("VM output did not match expectations: %v", out)
   120  	}
   121  }