diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/acceptance/reverse_debugging.py | 208 | ||||
-rw-r--r-- | tests/ptimer-test-stubs.c | 5 | ||||
-rwxr-xr-x | tests/qemu-iotests/261 | 19 | ||||
-rw-r--r-- | tests/qemu-iotests/261.out | 51 | ||||
-rw-r--r-- | tests/qemu-iotests/267.out | 48 | ||||
-rw-r--r-- | tests/qtest/meson.build | 6 | ||||
-rw-r--r-- | tests/test-timed-average.c | 2 |
7 files changed, 284 insertions, 55 deletions
diff --git a/tests/acceptance/reverse_debugging.py b/tests/acceptance/reverse_debugging.py new file mode 100644 index 0000000000..b72fdf6cdc --- /dev/null +++ b/tests/acceptance/reverse_debugging.py @@ -0,0 +1,208 @@ +# Reverse debugging test +# +# Copyright (c) 2020 ISP RAS +# +# Author: +# Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. +import os +import logging + +from avocado import skipIf +from avocado_qemu import BUILD_DIR +from avocado.utils import gdb +from avocado.utils import process +from avocado.utils.path import find_command +from boot_linux_console import LinuxKernelTest + +class ReverseDebugging(LinuxKernelTest): + """ + Test GDB reverse debugging commands: reverse step and reverse continue. + Recording saves the execution of some instructions and makes an initial + VM snapshot to allow reverse execution. + Replay saves the order of the first instructions and then checks that they + are executed backwards in the correct order. + After that the execution is replayed to the end, and reverse continue + command is checked by setting several breakpoints, and asserting + that the execution is stopped at the last of them. + """ + + timeout = 10 + STEPS = 10 + endian_is_le = True + + def run_vm(self, record, shift, args, replay_path, image_path): + logger = logging.getLogger('replay') + vm = self.get_vm() + vm.set_console() + if record: + logger.info('recording the execution...') + mode = 'record' + else: + logger.info('replaying the execution...') + mode = 'replay' + vm.add_args('-s', '-S') + vm.add_args('-icount', 'shift=%s,rr=%s,rrfile=%s,rrsnapshot=init' % + (shift, mode, replay_path), + '-net', 'none') + vm.add_args('-drive', 'file=%s,if=none' % image_path) + if args: + vm.add_args(*args) + vm.launch() + return vm + + @staticmethod + def get_reg_le(g, reg): + res = g.cmd(b'p%x' % reg) + num = 0 + for i in range(len(res))[-2::-2]: + num = 0x100 * num + int(res[i:i + 2], 16) + return num + + @staticmethod + def get_reg_be(g, reg): + res = g.cmd(b'p%x' % reg) + return int(res, 16) + + def get_reg(self, g, reg): + # value may be encoded in BE or LE order + if self.endian_is_le: + return self.get_reg_le(g, reg) + else: + return self.get_reg_be(g, reg) + + def get_pc(self, g): + return self.get_reg(g, self.REG_PC) + + def check_pc(self, g, addr): + pc = self.get_pc(g) + if pc != addr: + self.fail('Invalid PC (read %x instead of %x)' % (pc, addr)) + + @staticmethod + def gdb_step(g): + g.cmd(b's', b'T05thread:01;') + + @staticmethod + def gdb_bstep(g): + g.cmd(b'bs', b'T05thread:01;') + + @staticmethod + def vm_get_icount(vm): + return vm.qmp('query-replay')['return']['icount'] + + def reverse_debugging(self, shift=7, args=None): + logger = logging.getLogger('replay') + + # create qcow2 for snapshots + logger.info('creating qcow2 image for VM snapshots') + image_path = os.path.join(self.workdir, 'disk.qcow2') + qemu_img = os.path.join(BUILD_DIR, 'qemu-img') + if not os.path.exists(qemu_img): + qemu_img = find_command('qemu-img', False) + if qemu_img is False: + self.cancel('Could not find "qemu-img", which is required to ' + 'create the temporary qcow2 image') + cmd = '%s create -f qcow2 %s 128M' % (qemu_img, image_path) + process.run(cmd) + + replay_path = os.path.join(self.workdir, 'replay.bin') + + # record the log + vm = self.run_vm(True, shift, args, replay_path, image_path) + while self.vm_get_icount(vm) <= self.STEPS: + pass + last_icount = self.vm_get_icount(vm) + vm.shutdown() + + logger.info("recorded log with %s+ steps" % last_icount) + + # replay and run debug commands + vm = self.run_vm(False, shift, args, replay_path, image_path) + logger.info('connecting to gdbstub') + g = gdb.GDBRemote('127.0.0.1', 1234, False, False) + g.connect() + r = g.cmd(b'qSupported') + if b'qXfer:features:read+' in r: + g.cmd(b'qXfer:features:read:target.xml:0,ffb') + if b'ReverseStep+' not in r: + self.fail('Reverse step is not supported by QEMU') + if b'ReverseContinue+' not in r: + self.fail('Reverse continue is not supported by QEMU') + + logger.info('stepping forward') + steps = [] + # record first instruction addresses + for _ in range(self.STEPS): + pc = self.get_pc(g) + logger.info('saving position %x' % pc) + steps.append(pc) + self.gdb_step(g) + + # visit the recorded instruction in reverse order + logger.info('stepping backward') + for addr in steps[::-1]: + self.gdb_bstep(g) + self.check_pc(g, addr) + logger.info('found position %x' % addr) + + logger.info('seeking to the end (icount %s)' % (last_icount - 1)) + vm.qmp('replay-break', icount=last_icount - 1) + # continue - will return after pausing + g.cmd(b'c', b'T02thread:01;') + + logger.info('setting breakpoints') + for addr in steps: + # hardware breakpoint at addr with len=1 + g.cmd(b'Z1,%x,1' % addr, b'OK') + + logger.info('running reverse continue to reach %x' % steps[-1]) + # reverse continue - will return after stopping at the breakpoint + g.cmd(b'bc', b'T05thread:01;') + + # assume that none of the first instructions is executed again + # breaking the order of the breakpoints + self.check_pc(g, steps[-1]) + logger.info('successfully reached %x' % steps[-1]) + + logger.info('exitting gdb and qemu') + vm.shutdown() + +class ReverseDebugging_X86_64(ReverseDebugging): + REG_PC = 0x10 + REG_CS = 0x12 + def get_pc(self, g): + return self.get_reg_le(g, self.REG_PC) \ + + self.get_reg_le(g, self.REG_CS) * 0x10 + + # unidentified gitlab timeout problem + @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') + def test_x86_64_pc(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=machine:pc + """ + # start with BIOS only + self.reverse_debugging() + +class ReverseDebugging_AArch64(ReverseDebugging): + REG_PC = 32 + + # unidentified gitlab timeout problem + @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') + def test_aarch64_virt(self): + """ + :avocado: tags=arch:aarch64 + :avocado: tags=machine:virt + :avocado: tags=cpu:cortex-a53 + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/29/Everything/aarch64/os/images/pxeboot' + '/vmlinuz') + kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + + self.reverse_debugging( + args=('-kernel', kernel_path, '-cpu', 'cortex-a53')) diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c index ed393d9082..e935a1395e 100644 --- a/tests/ptimer-test-stubs.c +++ b/tests/ptimer-test-stubs.c @@ -12,6 +12,7 @@ #include "qemu/main-loop.h" #include "sysemu/replay.h" #include "migration/vmstate.h" +#include "sysemu/cpu-timers.h" #include "ptimer-test.h" @@ -30,8 +31,8 @@ QEMUTimerListGroup main_loop_tlg; int64_t ptimer_test_time_ns; -/* Do not artificially limit period - see hw/core/ptimer.c. */ -int use_icount = 1; +/* under qtest_enabled(), will not artificially limit period - see hw/core/ptimer.c. */ +int use_icount; bool qtest_allowed; void timer_init_full(QEMUTimer *ts, diff --git a/tests/qemu-iotests/261 b/tests/qemu-iotests/261 index ddcb04f285..847b4c6a37 100755 --- a/tests/qemu-iotests/261 +++ b/tests/qemu-iotests/261 @@ -91,7 +91,10 @@ print_snapshot_table() if [ $extra_len -ge 16 ]; then echo " Disk size: $(peek_file_be "$1" $((extra_ofs + 8)) 8)" fi - if [ $extra_len -gt 16 ]; then + if [ $extra_len -ge 24 ]; then + echo " Icount: $(peek_file_be "$1" $((extra_ofs + 16)) 8)" + fi + if [ $extra_len -gt 24 ]; then echo ' Unknown extra data:' \ "$(peek_file_raw "$1" $((extra_ofs + 16)) $((extra_len - 16)) \ | tr -d '\0')" @@ -198,12 +201,12 @@ truncate -s 0 "$TEST_DIR/sn0-extra" truncate -s $(($(snapshot_table_entry_size "$TEST_DIR/sn0-pre") - 40)) \ "$TEST_DIR/sn0-post" -# Set sn1's extra data size to 42 -poke_file "$TEST_DIR/sn1-pre" 36 '\x00\x00\x00\x2a' -truncate -s 42 "$TEST_DIR/sn1-extra" -poke_file "$TEST_DIR/sn1-extra" 16 'very important data' +# Set sn1's extra data size to 50 +poke_file "$TEST_DIR/sn1-pre" 36 '\x00\x00\x00\x32' +truncate -s 50 "$TEST_DIR/sn1-extra" +poke_file "$TEST_DIR/sn1-extra" 24 'very important data' # Grow sn1-post to pad -truncate -s $(($(snapshot_table_entry_size "$TEST_DIR/sn1-pre") - 82)) \ +truncate -s $(($(snapshot_table_entry_size "$TEST_DIR/sn1-pre") - 90)) \ "$TEST_DIR/sn1-post" # Set sn2's extra data size to 8 @@ -389,7 +392,7 @@ _check_test_img -r all echo echo "$((sn_count - 1)) snapshots should remain:" -echo " qemu-img info reports $(_img_info | grep -c '^ \{34\}') snapshots" +echo " qemu-img info reports $(_img_info | grep -c '^ \{32\}') snapshots" echo " Image header reports $(peek_file_be "$TEST_IMG" 60 4) snapshots" echo @@ -516,7 +519,7 @@ _check_test_img -r all echo echo '65536 snapshots should remain:' -echo " qemu-img info reports $(_img_info | grep -c '^ \{34\}') snapshots" +echo " qemu-img info reports $(_img_info | grep -c '^ \{32\}') snapshots" echo " Image header reports $(peek_file_be "$TEST_IMG" 60 4) snapshots" # success, all done diff --git a/tests/qemu-iotests/261.out b/tests/qemu-iotests/261.out index 2600354566..612433ae40 100644 --- a/tests/qemu-iotests/261.out +++ b/tests/qemu-iotests/261.out @@ -12,9 +12,10 @@ Snapshots in TEST_DIR/t.IMGFMT.v2.orig: [1] ID: 2 Name: sn1 - Extra data size: 42 + Extra data size: 50 VM state size: 0 Disk size: 67108864 + Icount: 0 Unknown extra data: very important data [2] ID: 3 @@ -29,22 +30,25 @@ Snapshots in TEST_DIR/t.IMGFMT.v3.orig: [0] ID: 1 Name: sn0 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 [1] ID: 2 Name: sn1 - Extra data size: 42 + Extra data size: 50 VM state size: 0 Disk size: 67108864 + Icount: 0 Unknown extra data: very important data [2] ID: 3 Name: sn2 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 === Repair botched v3 === @@ -61,22 +65,25 @@ Snapshots in TEST_DIR/t.IMGFMT: [0] ID: 1 Name: sn0 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 [1] ID: 2 Name: sn1 - Extra data size: 42 + Extra data size: 50 VM state size: 0 Disk size: 67108864 + Icount: 0 Unknown extra data: very important data [2] ID: 3 Name: sn2 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 === Add new snapshot === @@ -85,28 +92,32 @@ Snapshots in TEST_DIR/t.IMGFMT: [0] ID: 1 Name: sn0 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 [1] ID: 2 Name: sn1 - Extra data size: 42 + Extra data size: 50 VM state size: 0 Disk size: 67108864 + Icount: 0 Unknown extra data: very important data [2] ID: 3 Name: sn2 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 [3] ID: 4 Name: sn3 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 0 === Remove different snapshots === @@ -116,16 +127,18 @@ Snapshots in TEST_DIR/t.IMGFMT: [0] ID: 2 Name: sn1 - Extra data size: 42 + Extra data size: 50 VM state size: 0 Disk size: 67108864 + Icount: 0 Unknown extra data: very important data [1] ID: 3 Name: sn2 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 --- sn1 --- No errors were found on the image. @@ -133,15 +146,17 @@ Snapshots in TEST_DIR/t.IMGFMT: [0] ID: 1 Name: sn0 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 [1] ID: 3 Name: sn2 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 --- sn2 --- No errors were found on the image. @@ -149,15 +164,17 @@ Snapshots in TEST_DIR/t.IMGFMT: [0] ID: 1 Name: sn0 - Extra data size: 16 + Extra data size: 24 VM state size: 0 Disk size: 67108864 + Icount: 18446744073709551615 [1] ID: 2 Name: sn1 - Extra data size: 42 + Extra data size: 50 VM state size: 0 Disk size: 67108864 + Icount: 0 Unknown extra data: very important data === Reject too much unknown extra data === diff --git a/tests/qemu-iotests/267.out b/tests/qemu-iotests/267.out index 215902b3ad..27471ffae8 100644 --- a/tests/qemu-iotests/267.out +++ b/tests/qemu-iotests/267.out @@ -33,8 +33,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit @@ -44,8 +44,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit @@ -69,8 +69,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit @@ -94,8 +94,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit @@ -105,8 +105,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit @@ -119,8 +119,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit @@ -134,8 +134,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit @@ -145,15 +145,15 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit Internal snapshots on overlay: Snapshot list: -ID TAG VM SIZE DATE VM CLOCK -1 snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +1 snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 Internal snapshots on backing file: === -blockdev with NBD server on the backing file === @@ -166,17 +166,17 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 (qemu) info snapshots List of snapshots present on all disks: -ID TAG VM SIZE DATE VM CLOCK --- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +-- snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 (qemu) loadvm snap0 (qemu) quit Internal snapshots on overlay: Snapshot list: -ID TAG VM SIZE DATE VM CLOCK -1 snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +1 snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 Internal snapshots on backing file: Snapshot list: -ID TAG VM SIZE DATE VM CLOCK -1 snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 +ID TAG VM SIZE DATE VM CLOCK ICOUNT +1 snap0 SIZE yyyy-mm-dd hh:mm:ss 00:00:00.000 *** done diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 4f7757ee93..ad33ac311d 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -23,7 +23,7 @@ qtests_pci = \ (config_all_devices.has_key('CONFIG_IVSHMEM_DEVICE') ? ['ivshmem-test'] : []) qtests_i386 = \ - (config_host.has_key('CONFIG_SLIRP') ? ['pxe-test', 'test-netfilter'] : []) + \ + (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) + \ (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) + \ (have_tools ? ['ahci-test'] : []) + \ (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ @@ -117,7 +117,7 @@ qtests_ppc64 = \ (config_all_devices.has_key('CONFIG_PSERIES') ? ['device-plug-test'] : []) + \ (config_all_devices.has_key('CONFIG_POWERNV') ? ['pnv-xscom-test'] : []) + \ (config_all_devices.has_key('CONFIG_PSERIES') ? ['rtas-test'] : []) + \ - (config_host.has_key('CONFIG_SLIRP') ? ['pxe-test', 'test-netfilter'] : []) + \ + (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) + \ (config_all_devices.has_key('CONFIG_USB_UHCI') ? ['usb-hcd-uhci-test'] : []) + \ (config_all_devices.has_key('CONFIG_USB_XHCI_NEC') ? ['usb-hcd-xhci-test'] : []) + \ (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) + \ @@ -151,7 +151,7 @@ qtests_aarch64 = \ 'migration-test'] qtests_s390x = \ - (config_host.has_key('CONFIG_SLIRP') ? ['pxe-test', 'test-netfilter'] : []) + \ + (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) + \ (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) + \ (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \ ['boot-serial-test', diff --git a/tests/test-timed-average.c b/tests/test-timed-average.c index e2bcf5fe13..82c92500df 100644 --- a/tests/test-timed-average.c +++ b/tests/test-timed-average.c @@ -11,7 +11,7 @@ */ #include "qemu/osdep.h" - +#include "sysemu/cpu-timers.h" #include "qemu/timed-average.h" /* This is the clock for QEMU_CLOCK_VIRTUAL */ |