OLD | NEW |
1 import logging, re, random | 1 import logging, re, random |
2 from autotest_lib.client.common_lib import error | 2 from autotest_lib.client.common_lib import error |
3 import kvm_subprocess | 3 from autotest_lib.client.virt import aexpect |
4 | 4 |
5 | 5 |
6 def run_iofuzz(test, params, env): | 6 def run_iofuzz(test, params, env): |
7 """ | 7 """ |
8 KVM iofuzz test: | 8 KVM iofuzz test: |
9 1) Log into a guest | 9 1) Log into a guest |
10 2) Enumerate all IO port ranges through /proc/ioports | 10 2) Enumerate all IO port ranges through /proc/ioports |
11 3) On each port of the range: | 11 3) On each port of the range: |
12 * Read it | 12 * Read it |
13 * Write 0 to it | 13 * Write 0 to it |
(...skipping 14 matching lines...) Expand all Loading... |
28 @param session: SSH session stablished to a VM | 28 @param session: SSH session stablished to a VM |
29 @param port: Port where we'll write the data | 29 @param port: Port where we'll write the data |
30 @param data: Integer value that will be written on the port. This | 30 @param data: Integer value that will be written on the port. This |
31 value will be converted to octal before its written. | 31 value will be converted to octal before its written. |
32 """ | 32 """ |
33 logging.debug("outb(0x%x, 0x%x)", port, data) | 33 logging.debug("outb(0x%x, 0x%x)", port, data) |
34 outb_cmd = ("echo -e '\\%s' | dd of=/dev/port seek=%d bs=1 count=1" % | 34 outb_cmd = ("echo -e '\\%s' | dd of=/dev/port seek=%d bs=1 count=1" % |
35 (oct(data), port)) | 35 (oct(data), port)) |
36 try: | 36 try: |
37 session.cmd(outb_cmd) | 37 session.cmd(outb_cmd) |
38 except kvm_subprocess.ShellError, e: | 38 except aexpect.ShellError, e: |
39 logging.debug(e) | 39 logging.debug(e) |
40 | 40 |
41 | 41 |
42 def inb(session, port): | 42 def inb(session, port): |
43 """ | 43 """ |
44 Read from a given port. | 44 Read from a given port. |
45 | 45 |
46 @param session: SSH session stablished to a VM | 46 @param session: SSH session stablished to a VM |
47 @param port: Port where we'll read data | 47 @param port: Port where we'll read data |
48 """ | 48 """ |
49 logging.debug("inb(0x%x)", port) | 49 logging.debug("inb(0x%x)", port) |
50 inb_cmd = "dd if=/dev/port seek=%d of=/dev/null bs=1 count=1" % port | 50 inb_cmd = "dd if=/dev/port seek=%d of=/dev/null bs=1 count=1" % port |
51 try: | 51 try: |
52 session.cmd(inb_cmd) | 52 session.cmd(inb_cmd) |
53 except kvm_subprocess.ShellError, e: | 53 except aexpect.ShellError, e: |
54 logging.debug(e) | 54 logging.debug(e) |
55 | 55 |
56 | 56 |
57 def fuzz(session, inst_list): | 57 def fuzz(session, inst_list): |
58 """ | 58 """ |
59 Executes a series of read/write/randwrite instructions. | 59 Executes a series of read/write/randwrite instructions. |
60 | 60 |
61 If the guest SSH session hangs, an attempt to relogin will be made. | 61 If the guest SSH session hangs, an attempt to relogin will be made. |
62 If it fails, the guest will be reset. If during the process the VM | 62 If it fails, the guest will be reset. If during the process the VM |
63 process abnormally ends, the test fails. | 63 process abnormally ends, the test fails. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 # Write random values to random ports of the range | 128 # Write random values to random ports of the range |
129 for seq in range(fuzz_count * (end - beg + 1)): | 129 for seq in range(fuzz_count * (end - beg + 1)): |
130 inst.append(("write", | 130 inst.append(("write", |
131 [r.randint(beg, end), r.randint(0,255)])) | 131 [r.randint(beg, end), r.randint(0,255)])) |
132 | 132 |
133 fuzz(session, inst) | 133 fuzz(session, inst) |
134 | 134 |
135 finally: | 135 finally: |
136 session.close() | 136 session.close() |
OLD | NEW |