mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-11 14:24:11 +00:00
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 <james.o.hunt@intel.com>
This commit is contained in:
parent
cd4cc02568
commit
fcf9f9f6dd
@ -280,22 +280,33 @@ func TestQemuAddDeviceSerialPortDev(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQemuAddDeviceKataVSOCK(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)
|
contextID := uint64(3)
|
||||||
port := uint32(1024)
|
port := uint32(1024)
|
||||||
vHostFD := os.NewFile(1, "vsock")
|
|
||||||
|
vsockFile, err := os.Create(vsockFilename)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer vsockFile.Close()
|
||||||
|
|
||||||
expectedOut := []govmmQemu.Device{
|
expectedOut := []govmmQemu.Device{
|
||||||
govmmQemu.VSOCKDevice{
|
govmmQemu.VSOCKDevice{
|
||||||
ID: fmt.Sprintf("vsock-%d", contextID),
|
ID: fmt.Sprintf("vsock-%d", contextID),
|
||||||
ContextID: contextID,
|
ContextID: contextID,
|
||||||
VHostFD: vHostFD,
|
VHostFD: vsockFile,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
vsock := kataVSOCK{
|
vsock := kataVSOCK{
|
||||||
contextID: contextID,
|
contextID: contextID,
|
||||||
port: port,
|
port: port,
|
||||||
vhostFd: vHostFD,
|
vhostFd: vsockFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
testQemuAddDevice(t, vsock, vSockPCIDev, expectedOut)
|
testQemuAddDevice(t, vsock, vSockPCIDev, expectedOut)
|
||||||
|
Loading…
Reference in New Issue
Block a user