From fcf9f9f6dd6b0338e6c673700459d64d46844f45 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Thu, 4 Jul 2019 15:50:41 +0100 Subject: [PATCH] test: Fix fd leak causing test error Update the `TestQemuAddDeviceKataVSOCK` test so that it: - Doesn't hard-code the file descriptor number. - Cleans up after itself. The latter issue was causing an odd error similar to the following in the test output: ``` Unable to launch /tmp/vc-tmp-526112270/hypervisor: fork/exec /tmp/vc-tmp-526112270/hypervisor: permission denied ``` Partially fixes: #1835. Signed-off-by: James O. D. Hunt --- virtcontainers/qemu_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/virtcontainers/qemu_test.go b/virtcontainers/qemu_test.go index d1e95f4ea..5a29335ab 100644 --- a/virtcontainers/qemu_test.go +++ b/virtcontainers/qemu_test.go @@ -280,22 +280,33 @@ func TestQemuAddDeviceSerialPortDev(t *testing.T) { } func TestQemuAddDeviceKataVSOCK(t *testing.T) { + assert := assert.New(t) + + dir, err := ioutil.TempDir("", "") + assert.NoError(err) + defer os.RemoveAll(dir) + + vsockFilename := filepath.Join(dir, "vsock") + contextID := uint64(3) port := uint32(1024) - vHostFD := os.NewFile(1, "vsock") + + vsockFile, err := os.Create(vsockFilename) + assert.NoError(err) + defer vsockFile.Close() expectedOut := []govmmQemu.Device{ govmmQemu.VSOCKDevice{ ID: fmt.Sprintf("vsock-%d", contextID), ContextID: contextID, - VHostFD: vHostFD, + VHostFD: vsockFile, }, } vsock := kataVSOCK{ contextID: contextID, port: port, - vhostFd: vHostFD, + vhostFd: vsockFile, } testQemuAddDevice(t, vsock, vSockPCIDev, expectedOut)