1a2cd86a9SPhilippe Mathieu-Daudé /* 2a2cd86a9SPhilippe Mathieu-Daudé * QTest fuzzer-generated testcase for sb16 audio device 3a2cd86a9SPhilippe Mathieu-Daudé * 4a2cd86a9SPhilippe Mathieu-Daudé * Copyright (c) 2021 Philippe Mathieu-Daudé <f4bug@amsat.org> 5a2cd86a9SPhilippe Mathieu-Daudé * 6a2cd86a9SPhilippe Mathieu-Daudé * SPDX-License-Identifier: GPL-2.0-or-later 7a2cd86a9SPhilippe Mathieu-Daudé */ 8a2cd86a9SPhilippe Mathieu-Daudé 9a2cd86a9SPhilippe Mathieu-Daudé #include "qemu/osdep.h" 10*907b5105SMarc-André Lureau #include "libqtest.h" 11a2cd86a9SPhilippe Mathieu-Daudé 12a2cd86a9SPhilippe Mathieu-Daudé /* 13a2cd86a9SPhilippe Mathieu-Daudé * This used to trigger the assert in audio_calloc 14a2cd86a9SPhilippe Mathieu-Daudé * https://bugs.launchpad.net/qemu/+bug/1910603 15a2cd86a9SPhilippe Mathieu-Daudé */ 16a2cd86a9SPhilippe Mathieu-Daudé static void test_fuzz_sb16_0x1c(void) 17a2cd86a9SPhilippe Mathieu-Daudé { 18a2cd86a9SPhilippe Mathieu-Daudé QTestState *s = qtest_init("-M q35 -display none " 19a2cd86a9SPhilippe Mathieu-Daudé "-device sb16,audiodev=snd0 " 20a2cd86a9SPhilippe Mathieu-Daudé "-audiodev none,id=snd0"); 21a2cd86a9SPhilippe Mathieu-Daudé qtest_outw(s, 0x22c, 0x41); 22a2cd86a9SPhilippe Mathieu-Daudé qtest_outb(s, 0x22c, 0x00); 23a2cd86a9SPhilippe Mathieu-Daudé qtest_outw(s, 0x22c, 0x1004); 24a2cd86a9SPhilippe Mathieu-Daudé qtest_outw(s, 0x22c, 0x001c); 25a2cd86a9SPhilippe Mathieu-Daudé qtest_quit(s); 26a2cd86a9SPhilippe Mathieu-Daudé } 27a2cd86a9SPhilippe Mathieu-Daudé 28a2cd86a9SPhilippe Mathieu-Daudé static void test_fuzz_sb16_0x91(void) 29a2cd86a9SPhilippe Mathieu-Daudé { 30a2cd86a9SPhilippe Mathieu-Daudé QTestState *s = qtest_init("-M pc -display none " 31a2cd86a9SPhilippe Mathieu-Daudé "-device sb16,audiodev=none " 32a2cd86a9SPhilippe Mathieu-Daudé "-audiodev id=none,driver=none"); 33a2cd86a9SPhilippe Mathieu-Daudé qtest_outw(s, 0x22c, 0xf141); 34a2cd86a9SPhilippe Mathieu-Daudé qtest_outb(s, 0x22c, 0x00); 35a2cd86a9SPhilippe Mathieu-Daudé qtest_outb(s, 0x22c, 0x24); 36a2cd86a9SPhilippe Mathieu-Daudé qtest_outb(s, 0x22c, 0x91); 37a2cd86a9SPhilippe Mathieu-Daudé qtest_quit(s); 38a2cd86a9SPhilippe Mathieu-Daudé } 39a2cd86a9SPhilippe Mathieu-Daudé 4060e543f5SQiang Liu /* 4160e543f5SQiang Liu * This used to trigger the assert in audio_calloc 4260e543f5SQiang Liu * through command 0xd4 4360e543f5SQiang Liu */ 4460e543f5SQiang Liu static void test_fuzz_sb16_0xd4(void) 4560e543f5SQiang Liu { 4660e543f5SQiang Liu QTestState *s = qtest_init("-M pc -display none " 4760e543f5SQiang Liu "-device sb16,audiodev=none " 4860e543f5SQiang Liu "-audiodev id=none,driver=none"); 4960e543f5SQiang Liu qtest_outb(s, 0x22c, 0x41); 5060e543f5SQiang Liu qtest_outb(s, 0x22c, 0x00); 5160e543f5SQiang Liu qtest_outb(s, 0x22c, 0x14); 5260e543f5SQiang Liu qtest_outb(s, 0x22c, 0xd4); 5360e543f5SQiang Liu qtest_quit(s); 5460e543f5SQiang Liu } 5560e543f5SQiang Liu 56a2cd86a9SPhilippe Mathieu-Daudé int main(int argc, char **argv) 57a2cd86a9SPhilippe Mathieu-Daudé { 58a2cd86a9SPhilippe Mathieu-Daudé g_test_init(&argc, &argv, NULL); 59a2cd86a9SPhilippe Mathieu-Daudé 60a2cd86a9SPhilippe Mathieu-Daudé qtest_add_func("fuzz/test_fuzz_sb16/1c", test_fuzz_sb16_0x1c); 61a2cd86a9SPhilippe Mathieu-Daudé qtest_add_func("fuzz/test_fuzz_sb16/91", test_fuzz_sb16_0x91); 6260e543f5SQiang Liu qtest_add_func("fuzz/test_fuzz_sb16/d4", test_fuzz_sb16_0xd4); 63a2cd86a9SPhilippe Mathieu-Daudé 64a2cd86a9SPhilippe Mathieu-Daudé return g_test_run(); 65a2cd86a9SPhilippe Mathieu-Daudé } 66