diff mbox

[1/2] * Add lseek test

Message ID 1291638261-19784-2-git-send-email-ldoktor@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lukáš Doktor Dec. 6, 2010, 12:24 p.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/scripts/virtio_guest.py b/client/tests/kvm/scripts/virtio_guest.py
index b039ec9..bc86624 100755
--- a/client/tests/kvm/scripts/virtio_guest.py
+++ b/client/tests/kvm/scripts/virtio_guest.py
@@ -300,6 +300,29 @@  class VirtioGuest:
             print "FAIL: Events: " + str + "  Expected: " + estr
 
 
+    def lseek(self, port, pos, how):
+        """
+        Use lseek on the device. The device is unseekable so PASS is returned
+        when lseek command fails and vice versa.
+
+        @param port: Name of the port
+        @param pos: Offset
+        @param how: Relativ offset os.SEEK_{SET,CUR,END}
+        """
+        fd = self._open([port])[0]
+
+        try:
+            os.lseek(fd, pos, how)
+        except Exception, inst:
+            if inst.errno == 29:
+                print "PASS: the lseek failed as expected"
+            else:
+                print inst
+                print "FAIL: unknown error"
+        else:
+            print "FAIL: the lseek unexpectedly passed"
+
+
     def blocking(self, port, mode=False):
         """
         Set port function mode blocking/nonblocking
diff --git a/client/tests/kvm/tests/virtio_console.py b/client/tests/kvm/tests/virtio_console.py
index d8d2143..30bdcbf 100644
--- a/client/tests/kvm/tests/virtio_console.py
+++ b/client/tests/kvm/tests/virtio_console.py
@@ -671,6 +671,16 @@  def run_virtio_console(test, params, env):
         on_guest("virt.poll('%s', %s)" % (port.name, select.POLLOUT), vm,
                  2)
 
+    def tlseek(vm, port):
+        """
+        Tests the correct handling of lseek (expected fail)
+
+        @param vm: Target virtual machine [vm, session, tmp_dir].
+        @param port: Port used in test.
+        """
+        # The virt.lseek returns PASS when the seek fails
+        on_guest("virt.lseek('%s', 0, 0)" % (port.name), vm, 2)
+
 
     def trw_host_offline(vm, port):
         """
@@ -818,6 +828,7 @@  def run_virtio_console(test, params, env):
             test.do_test(tclose, [vm, send_pt], True)
             test.do_test(tmulti_open, [vm, send_pt], True)
             test.do_test(tpooling, [vm, send_pt])
+            test.do_test(tlseek, [vm, send_pt])
             test.do_test(trw_host_offline, [vm, send_pt])
             test.do_test(trw_nonblocking_mode, [vm, send_pt])
             test.do_test(trw_blocking_mode, [vm, send_pt])