qemu-iotests: add test for fd passing via SCM rights
cover qemu-iotests: add test for fd passing via SCM rights
This series add test case for fd passing with unix socket at runtime. Since getfd and closefd interface will interact with monitor's data, so it will help to do regression test for monitor patches. Since python2 do not support sendmsg(), so a C helper program is added to do the job.
Wenchao Xia (3):
1 qemu-iotests: add unix socket help program
2 qemu-iotests: add infrastructure of fd passing via SCM 3 qemu-iotests: add tests for runtime fd passing via SCM rights
QMP/qmp.py | 6 ++ configure | 2 +- tests/Makefile | 4 +- tests/qemu-iotests/045 | 37 ++++++++++- tests/qemu-iotests/045.out | 4 +- tests/qemu-iotests/check | 1 + tests/qemu-iotests/iotests.py | 26 +++++++ tests/qemu-iotests/socket_scm_helper.c | 119 ++++++++++++++++++++++++++++++++ 8 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 tests/qemu-iotests/socket_scm_helper.c
PATCH 1/3 qemu-iotests: add unix socket help program
This program can do a sendmsg call to transfer fd with unix socket, which is not supported in python2.
The built binary will not be deleted in clean, but it is a existing issue in ./tests, which should be solved in another patch.
--- configure | 2 +- tests/Makefile | 4 +- tests/qemu-iotests/socket_scm_helper.c | 119 ++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tests/qemu-iotests/socket_scm_helper.c
configure +1 -1
@@ -4507,7 +4507,7 @@ if [ "$dtc_internal" = "yes" ]; then fi # build tree in object directory in case the source is not in the current directory -DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa" +DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests" DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw" DIRS="$DIRS roms/seabios roms/vgabios" DIRS="$DIRS qapi-generated"
tests/Makefile +3 -1
@@ -172,6 +172,8 @@ tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) +tests/qemu-iotests/socket_scm_helper(EXESUF): tests/qemu-iotests/socket_scm_helper.o + $(call LINK, $^) # QTest rules
@@ -250,7 +252,7 @@ check-report.html: check-report.xml # Other tests .PHONY: check-tests/qemu-iotests-quick.sh -check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF) qemu-io$(EXESUF) +check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF) qemu-io$(EXESUF) tests/qemu-iotests/socket_scm_helper$(EXESUF) $< .PHONY: check-tests/test-qapi.py
tests/qemu-iotests/socket_scm_helper.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 2/3 qemu-iotests: add infrastructure of fd passing via SCM
In reply to Wenchao XiaThis patch make use of the compiled scm helper program to transfer fd via unix socket at runtime.
--- QMP/qmp.py | 6 ++++++ tests/qemu-iotests/check | 1 + tests/qemu-iotests/iotests.py | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 0 deletions(-)
QMP/qmp.py +6 -0
@@ -188,3 +188,9 @@ class QEMUMonitorProtocol: def settimeout(self, timeout): self.__sock.settimeout(timeout) + + def get_sock_fd(self): + return self.__sock.fileno() + + def is_scm_available(self): + return self.__sock.family == socket.AF_UNIX
tests/qemu-iotests/check +1 -0
@@ -164,6 +164,7 @@ QEMU_IO -- $QEMU_IO IMGFMT -- $FULL_IMGFMT_DETAILS IMGPROTO -- $FULL_IMGPROTO_DETAILS PLATFORM -- $FULL_HOST_DETAILS +SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER EOF #MKFS_OPTIONS -- $FULL_MKFS_OPTIONS
tests/qemu-iotests/iotests.py +26 -0
@@ -38,6 +38,8 @@ imgfmt = os.environ.get('IMGFMT', 'raw') imgproto = os.environ.get('IMGPROTO', 'file') test_dir = os.environ.get('TEST_DIR', '/var/tmp') +socket_scm_helper = os.environ.get('SOCKET_SCM_HELPER', 'socket_scm_helper') + def qemu_img(*args): '''Run qemu-img and return the exit code''' devnull = open('/dev/null', 'r+')
@@ -80,6 +82,12 @@ class VM(object): '-display', 'none', '-vga', 'none'] self._num_drives = 0 + #This can be used to add unused monitor + def add_monitor_telnet(self, ip, port): + args = 'tcp:%s:%d,server,nowait,telnet' % (ip, port) + self._args.append('-monitor') + self._args.append(args) + def add_drive(self, path, opts=''): '''Add a virtio-blk drive to the VM''' options = ['if=virtio',
@@ -112,6 +120,24 @@ class VM(object): self._args.append(','.join(options)) return self + #Sendmsg must carry out some data to get qemu's notice, so send a blank + #by default. + def send_fd_scm(self, fd, msg=' '): + #In iotest.py, the qmp should always use unix socket. + assert self._qmp.is_scm_available() + fd_bin = socket_scm_helper + if os.path.exists(fd_bin) == False: + print "Scm help program does not present, path %s." % fd_bin + return -1 + fd_param = ["%s" % fd_bin, + "%d" % self._qmp.get_sock_fd(), + "%d" % fd, + "%s" % msg] + devnull = open('/dev/null', 'rb') + p = subprocess.Popen(fd_param, stdin=devnull, stdout=sys.stdout, + stderr=sys.stderr) + return p.wait() + def launch(self): '''Launch the VM and establish a QMP connection''' devnull = open('/dev/null', 'rb')
Signature · 1 line
1.7.1
PATCH 3/3 qemu-iotests: add tests for runtime fd passing via SCM rights
In reply to Wenchao XiaThis case will test whether the monitor can receive fd at runtime. To verify better, additional monitor is created to see if qemu can handler two monitor instance correctly.
--- tests/qemu-iotests/045 | 37 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/045.out | 4 ++-- 2 files changed, 38 insertions(+), 3 deletions(-)
tests/qemu-iotests/045 +36 -1
@@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Tests for fdsets. +# Tests for fdsets and getfd. # # Copyright (C) 2012 IBM Corp. #
@@ -125,5 +125,40 @@ class TestFdSets(iotests.QMPTestCase): 'No file descriptor supplied via SCM_RIGHTS') self.vm.shutdown() +#Add fd at runtime, there are two ways: monitor related or fdset related +class TestSCMFd(iotests.QMPTestCase): + def setUp(self): + self.vm = iotests.VM() + qemu_img('create', '-f', iotests.imgfmt, image0, '128K') + self.file0 = open(image0, 'r') + self.vm.add_monitor_telnet("0",4445) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + self.file0.close() + os.remove(image0) + + def _send_fd_by_SCM(self): + ret = self.vm.send_fd_scm(self.file0.fileno()) + self.assertEqual(ret, 0, 'Failed to send fd with UNIX SCM') + + def test_add_fd(self): + self._send_fd_by_SCM() + result = self.vm.qmp('add-fd', fdset_id=2, opaque='image0:r') + self.assert_qmp(result, 'return/fdset-id', 2) + + def test_getfd(self): + self._send_fd_by_SCM() + result = self.vm.qmp('getfd', fdname='image0:r') + self.assert_qmp(result, 'return', {}) + + def test_closefd(self): + self._send_fd_by_SCM() + result = self.vm.qmp('getfd', fdname='image0:r') + self.assert_qmp(result, 'return', {}) + result = self.vm.qmp('closefd', fdname='image0:r') + self.assert_qmp(result, 'return', {}) + if __name__ == '__main__': iotests.main(supported_fmts=['raw'])
tests/qemu-iotests/045.out +2 -2
@@ -1,5 +1,5 @@ -...... +......... ---------------------------------------------------------------------- -Ran 6 tests +Ran 9 tests OK
Signature · 1 line
1.7.1
Quoted 19 lines · Wenchao Xia
This series add test case for fd passing with unix socket at runtime. Since getfd and closefd interface will interact with monitor's data, so it will help to do regression test for monitor patches. Since python2 do not support
sendmsg(), so a C helper program is added to do the job.Wenchao Xia (3):
1 qemu-iotests: add unix socket help program
2 qemu-iotests: add infrastructure of fd passing via SCM 3 qemu-iotests: add tests for runtime fd passing via SCM rightsQMP/qmp.py | 6 ++ configure | 2 +- tests/Makefile | 4 +- tests/qemu-iotests/045 | 37 ++++++++++- tests/qemu-iotests/045.out | 4 +- tests/qemu-iotests/check | 1 + tests/qemu-iotests/iotests.py | 26 +++++++ tests/qemu-iotests/socket_scm_helper.c | 119 ++++++++++++++++++++++++++++++++ 8 files changed, 194 insertions(+), 5 deletions(-)
Quoted 3 lines
create mode 100644
tests/qemu-iotests/socket_scm_helper.c
This version have one issue in Makefile, will respin.
Signature · 3 lines
Best Regards Wenchao Xia