mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-09-26 21:01:42 +08:00

Tests that are currently on the main branch only runs against a qemu VM. We have other use cases that needs to be tested like running against a vfkit VM. This commit reorganizes the tests code a bit by moving the files that can be shared to support different implementation in their own folder. The reasoning behind this is that every hypervisor should have its own beforeSuite func to download/run a specific VM image. By moving the utils files we can reuse the same code. For the same reason the code targeting qemu is moved to the test-qemu folder. By doing so, we can run the tests within the test-qemu folder on the ubuntu workflow and, in future, when the nested virt will be enabled on github runners, the vfkit tests on macOS. Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package e2eqemu
|
|
|
|
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
|
|
}
|