github.com/containers/podman/v4@v4.9.4/pkg/machine/qemu/qemu_command_test.go (about)

     1  //go:build (amd64 && !windows) || (arm64 && !windows)
     2  // +build amd64,!windows arm64,!windows
     3  
     4  package qemu
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  
    10  	"github.com/containers/podman/v4/pkg/machine/define"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func TestQemuCmd(t *testing.T) {
    16  	ignFile, err := define.NewMachineFile(t.TempDir()+"demo-ignition-file.ign", nil)
    17  	assert.NoError(t, err)
    18  
    19  	machineAddrFile, err := define.NewMachineFile(t.TempDir()+"tmp.sock", nil)
    20  	assert.NoError(t, err)
    21  
    22  	readySocket, err := define.NewMachineFile(t.TempDir()+"readySocket.sock", nil)
    23  	assert.NoError(t, err)
    24  
    25  	vmPidFile, err := define.NewMachineFile(t.TempDir()+"vmpidfile.pid", nil)
    26  	assert.NoError(t, err)
    27  
    28  	monitor := Monitor{
    29  		Address: *machineAddrFile,
    30  		Network: "unix",
    31  		Timeout: 3,
    32  	}
    33  	ignPath := ignFile.GetPath()
    34  	addrFilePath := machineAddrFile.GetPath()
    35  	readySocketPath := readySocket.GetPath()
    36  	vmPidFilePath := vmPidFile.GetPath()
    37  	bootableImagePath := t.TempDir() + "test-machine_fedora-coreos-38.20230918.2.0-qemu.x86_64.qcow2"
    38  
    39  	cmd := NewQemuBuilder("/usr/bin/qemu-system-x86_64", []string{})
    40  	cmd.SetMemory(2048)
    41  	cmd.SetCPUs(4)
    42  	cmd.SetIgnitionFile(*ignFile)
    43  	cmd.SetQmpMonitor(monitor)
    44  	cmd.SetNetwork()
    45  	cmd.SetSerialPort(*readySocket, *vmPidFile, "test-machine")
    46  	cmd.SetVirtfsMount("/tmp/path", "vol10", "none", true)
    47  	cmd.SetBootableImage(bootableImagePath)
    48  	cmd.SetDisplay("none")
    49  
    50  	expected := []string{
    51  		"/usr/bin/qemu-system-x86_64",
    52  		"-m", "2048",
    53  		"-smp", "4",
    54  		"-fw_cfg", fmt.Sprintf("name=opt/com.coreos/config,file=%s", ignPath),
    55  		"-qmp", fmt.Sprintf("unix:%s,server=on,wait=off", addrFilePath),
    56  		"-netdev", "socket,id=vlan,fd=3",
    57  		"-device", "virtio-net-pci,netdev=vlan,mac=5a:94:ef:e4:0c:ee",
    58  		"-device", "virtio-serial",
    59  		"-chardev", fmt.Sprintf("socket,path=%s,server=on,wait=off,id=atest-machine_ready", readySocketPath),
    60  		"-device", "virtserialport,chardev=atest-machine_ready,name=org.fedoraproject.port.0",
    61  		"-pidfile", vmPidFilePath,
    62  		"-virtfs", "local,path=/tmp/path,mount_tag=vol10,security_model=none,readonly",
    63  		"-drive", fmt.Sprintf("if=virtio,file=%s", bootableImagePath),
    64  		"-display", "none"}
    65  
    66  	require.Equal(t, cmd.Build(), expected)
    67  }