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 authored and Eric Ernst committed Jul 17, 2019
1 parent 5628825 commit c980da4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions virtcontainers/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c980da4

Please sign in to comment.