diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/qtest/fuzz-virtio-balloon-test.c | 37 | ||||
| -rw-r--r-- | tests/qtest/meson.build | 2 | ||||
| -rw-r--r-- | tests/qtest/virtio-balloon-test.c | 57 |
3 files changed, 58 insertions, 38 deletions
diff --git a/tests/qtest/fuzz-virtio-balloon-test.c b/tests/qtest/fuzz-virtio-balloon-test.c deleted file mode 100644 index ecb597fbee..0000000000 --- a/tests/qtest/fuzz-virtio-balloon-test.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * QTest fuzzer-generated testcase for virtio balloon device - * - * Copyright (c) 2024 Gao Shiyuan <gaoshiyuan@baidu.com> - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#include "qemu/osdep.h" -#include "libqtest.h" - -/* - * https://gitlab.com/qemu-project/qemu/-/issues/2576 - * Used to trigger: - * virtio_address_space_lookup: Assertion `mrs.mr' failed. - */ -static void oss_fuzz_71649(void) -{ - QTestState *s = qtest_init("-device virtio-balloon -machine q35" - " -nodefaults"); - - qtest_outl(s, 0xcf8, 0x80000890); - qtest_outl(s, 0xcfc, 0x2); - qtest_outl(s, 0xcf8, 0x80000891); - qtest_inl(s, 0xcfc); - qtest_quit(s); -} - -int main(int argc, char **argv) -{ - g_test_init(&argc, &argv, NULL); - - qtest_add_func("fuzz/virtio/oss_fuzz_71649", oss_fuzz_71649); - - return g_test_run(); -} - diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index f2f35367ae..bd41c9da5f 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -88,7 +88,7 @@ qtests_i386 = \ (config_all_devices.has_key('CONFIG_MEGASAS_SCSI_PCI') ? ['fuzz-megasas-test'] : []) + \ (config_all_devices.has_key('CONFIG_LSI_SCSI_PCI') ? ['fuzz-lsi53c895a-test'] : []) + \ (config_all_devices.has_key('CONFIG_VIRTIO_SCSI') ? ['fuzz-virtio-scsi-test'] : []) + \ - (config_all_devices.has_key('CONFIG_VIRTIO_BALLOON') ? ['fuzz-virtio-balloon-test'] : []) + \ + (config_all_devices.has_key('CONFIG_VIRTIO_BALLOON') ? ['virtio-balloon-test'] : []) + \ (config_all_devices.has_key('CONFIG_Q35') ? ['q35-test'] : []) + \ (config_all_devices.has_key('CONFIG_SB16') ? ['fuzz-sb16-test'] : []) + \ (config_all_devices.has_key('CONFIG_SDHCI_PCI') ? ['fuzz-sdcard-test'] : []) + \ diff --git a/tests/qtest/virtio-balloon-test.c b/tests/qtest/virtio-balloon-test.c new file mode 100644 index 0000000000..ecdd363b06 --- /dev/null +++ b/tests/qtest/virtio-balloon-test.c @@ -0,0 +1,57 @@ +/* + * QTest test cases for virtio balloon device + * + * Copyright (c) 2024 Gao Shiyuan <gaoshiyuan@baidu.com> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "standard-headers/linux/virtio_balloon.h" + +/* + * https://gitlab.com/qemu-project/qemu/-/issues/2576 + * Used to trigger: + * virtio_address_space_lookup: Assertion `mrs.mr' failed. + */ +static void oss_fuzz_71649(void) +{ + QTestState *s = qtest_init("-device virtio-balloon -machine q35" + " -nodefaults"); + + qtest_outl(s, 0xcf8, 0x80000890); + qtest_outl(s, 0xcfc, 0x2); + qtest_outl(s, 0xcf8, 0x80000891); + qtest_inl(s, 0xcfc); + qtest_quit(s); +} + +static void query_stats(void) +{ + QTestState *s = qtest_init("-device virtio-balloon,id=balloon" + " -nodefaults"); + QDict *ret = qtest_qmp_assert_success_ref( + s, + "{ 'execute': 'qom-get', 'arguments': " \ + "{ 'path': '/machine/peripheral/balloon', " \ + " 'property': 'guest-stats' } }"); + QDict *stats = qdict_get_qdict(ret, "stats"); + + /* We expect 1 entry in the dict for each known kernel stat */ + assert(qdict_size(stats) == VIRTIO_BALLOON_S_NR); + + qobject_unref(ret); + qtest_quit(s); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + qtest_add_func("virtio-balloon/oss_fuzz_71649", oss_fuzz_71649); + qtest_add_func("virtio-balloon/query-stats", query_stats); + + return g_test_run(); +} + |