github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/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  // +build !race
     6  
     7  package integration
     8  
     9  import (
    10  	"os"
    11  	"testing"
    12  	"time"
    13  
    14  	expect "github.com/google/goexpect"
    15  	"github.com/u-root/u-root/pkg/qemu"
    16  	"github.com/u-root/u-root/pkg/vmtest"
    17  )
    18  
    19  func TestESXi(t *testing.T) {
    20  	img := os.Getenv("UROOT_ESXI_IMAGE")
    21  	if _, err := os.Stat(img); err != nil && os.IsNotExist(err) {
    22  		t.Skip("ESXi disk image is not present. Please set UROOT_ESXI_IMAGE= to an installed ESXi disk image.")
    23  	}
    24  
    25  	q, cleanup := vmtest.QEMUTest(t, &vmtest.Options{
    26  		TestCmds: []string{
    27  			`esxiboot -d="/dev/sda" --append="vmkBootVerbose=TRUE vmbLog=TRUE debugLogToSerial=1 logPort=com1"`,
    28  		},
    29  		QEMUOpts: qemu.Options{
    30  			Devices: []qemu.Device{
    31  				qemu.IDEBlockDevice{File: img},
    32  				// If at some point we get virtio-net working
    33  				// again in ESXi, you may need to set num CPUs
    34  				// to 4.
    35  				qemu.ArbitraryArgs{"-smp", "2"},
    36  
    37  				// QEMU is not good enough to do ESXi without KVM. You'll get kernel panic.
    38  				qemu.ArbitraryArgs{"-enable-kvm"},
    39  
    40  				// IvyBridge is the lowest-common-denominator.
    41  				// ESXi 7.0 drops support for SandyBridge
    42  				// afaict.
    43  				qemu.ArbitraryArgs{"-cpu", "IvyBridge"},
    44  
    45  				// Min ESXi requirement is 4G of memory, but in
    46  				// ESXi 7.0 some plugins fail to load at 4G
    47  				// under memory pressure, and we never get to
    48  				// "Boot Successful"
    49  				qemu.ArbitraryArgs{"-m", "8192"},
    50  			},
    51  		},
    52  	})
    53  	defer cleanup()
    54  
    55  	if out, err := q.ExpectBatch([]expect.Batcher{
    56  		// Last Linux print.
    57  		&expect.BExp{R: "kexec_core: Starting new kernel"},
    58  		// First b.b00 ESXi first-stage kernel print
    59  		&expect.BExp{R: "Serial port initialized..."},
    60  		// ~thirdish k.b00 ESXi second-stage kernel print
    61  		&expect.BExp{R: "Parsing command line boot options"},
    62  		// When we can be confident it's done.
    63  		&expect.BExp{R: "Boot Successful"},
    64  	}, 2*time.Minute); err != nil {
    65  		t.Fatalf("VM output did not match expectations: %v", out)
    66  	}
    67  }