Skip to content

Commit

Permalink
test: Fix fd leak causing test error
Browse files Browse the repository at this point in the history
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: kata-containers#1835.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Jul 4, 2019
1 parent 43f2680 commit d8c06b8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions virtcontainers/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,22 +280,34 @@ 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")
assert.NoError(err)

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)
Expand Down

0 comments on commit d8c06b8

Please sign in to comment.