Skip to content

Commit

Permalink
test: Specify path to EFI firmware for aarch64
Browse files Browse the repository at this point in the history
Without this, there will be no bootloader to start the VM image.

Signed-off-by: Christophe Fergeau <[email protected]>
  • Loading branch information
cfergeau committed Jun 27, 2024
1 parent a5a8392 commit 6f7f49f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
54 changes: 54 additions & 0 deletions test/efi_darwin_arm64_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package e2e

import (
"fmt"
"os"
"path/filepath"
)

func efiArgs() (string, error) {
// file may not exist, that's ok
_ = os.Remove("ovmf_vars.fd")
ovmfVars, err := os.Create("ovmf_vars.fd")
if err != nil {
return "", err
}
defer ovmfVars.Close()
if err := ovmfVars.Truncate(67108864); err != nil {
return "", err
}

edk2Path := getEdk2CodeFd("edk2-aarch64-code.fd")
return fmt.Sprintf(`-drive file=%s,if=pflash,format=raw,readonly=on -drive file=%s,if=pflash,format=raw `, edk2Path, ovmfVars.Name()), nil
}

/*
* When QEmu is installed in a non-default location in the system
* we can use the qemu-system-* binary path to figure the install
* location for Qemu and use it to look for edk2-code-fd
*/
func getEdk2CodeFdPathFromQemuBinaryPath() string {
return filepath.Clean(filepath.Join(filepath.Dir(qemuExecutable()), "..", "share", "qemu"))
}

/*
* QEmu can be installed in multiple locations on MacOS, especially on
* Apple Silicon systems. A build from source will likely install it in
* /usr/local/bin, whereas Homebrew package management standard is to
* install in /opt/homebrew
*/
func getEdk2CodeFd(name string) string {
dirs := []string{
getEdk2CodeFdPathFromQemuBinaryPath(),
"/opt/homebrew/opt/podman/libexec/share/qemu",
"/usr/local/share/qemu",
"/opt/homebrew/share/qemu",
}
for _, dir := range dirs {
fullpath := filepath.Join(dir, name)
if _, err := os.Stat(fullpath); err == nil {
return fullpath
}
}
return name
}
7 changes: 7 additions & 0 deletions test/efi_generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !(darwin && arm64)

package e2e

func efiArgs() (string, error) {
return "", nil
}
10 changes: 7 additions & 3 deletions test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ outer:
break
}

template := `%s -m 2048 -nographic -serial file:%s -snapshot -drive if=virtio,file=%s -fw_cfg name=opt/com.coreos/config,file=%s -netdev socket,id=vlan,connect=127.0.0.1:%d -device virtio-net-pci,netdev=vlan,mac=5a:94:ef:e4:0c:ee`
efiArgs, err := efiArgs()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

template := `%s%s-m 2048 -nographic -serial file:%s -drive if=virtio,file=%s,snapshot=on -fw_cfg name=opt/com.coreos/config,file=%s -netdev socket,id=vlan,connect=127.0.0.1:%d -device virtio-net-pci,netdev=vlan,mac=5a:94:ef:e4:0c:ee`

// #nosec
client = exec.Command(qemuExecutable(), strings.Split(fmt.Sprintf(template, qemuArgs(), qconLog, qemuImage, ignFile, qemuPort), " ")...)
client = exec.Command(qemuExecutable(), strings.Split(fmt.Sprintf(template, qemuArgs(), efiArgs, qconLog, qemuImage, ignFile, qemuPort), " ")...)
client.Stderr = os.Stderr
client.Stdout = os.Stdout
gomega.Expect(client.Start()).Should(gomega.Succeed())
Expand Down Expand Up @@ -175,7 +179,7 @@ func qemuArgs() string {
default:
panic(fmt.Sprintf("unsupported arch: %s", runtime.GOARCH))
}
return fmt.Sprintf("-machine %s,accel=%s:tcg -smp 4 -cpu host", machine, accel)
return fmt.Sprintf("-machine %s,accel=%s:tcg -smp 4 -cpu host ", machine, accel)
}

func createSSHKeys() (string, error) {
Expand Down

0 comments on commit 6f7f49f

Please sign in to comment.