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"
10907b5105SMarc-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é */
test_fuzz_sb16_0x1c(void)16a2cd86a9SPhilippe Mathieu-Daudé static void test_fuzz_sb16_0x1c(void)
17a2cd86a9SPhilippe Mathieu-Daudé {
18*f15cfe41SJuan Quintela QTestState *s = qtest_init("-M q35 "
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é
test_fuzz_sb16_0x91(void)28a2cd86a9SPhilippe Mathieu-Daudé static void test_fuzz_sb16_0x91(void)
29a2cd86a9SPhilippe Mathieu-Daudé {
30*f15cfe41SJuan Quintela QTestState *s = qtest_init("-M pc "
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 */
test_fuzz_sb16_0xd4(void)4460e543f5SQiang Liu static void test_fuzz_sb16_0xd4(void)
4560e543f5SQiang Liu {
46*f15cfe41SJuan Quintela QTestState *s = qtest_init("-M pc "
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
main(int argc,char ** argv)56a2cd86a9SPhilippe Mathieu-Daudé int main(int argc, char **argv)
57a2cd86a9SPhilippe Mathieu-Daudé {
58a2cd86a9SPhilippe Mathieu-Daudé g_test_init(&argc, &argv, NULL);
59a2cd86a9SPhilippe Mathieu-Daudé
601dbea818SJuan Quintela if (qtest_has_machine("q35")) {
61a2cd86a9SPhilippe Mathieu-Daudé qtest_add_func("fuzz/test_fuzz_sb16/1c", test_fuzz_sb16_0x1c);
621dbea818SJuan Quintela }
631dbea818SJuan Quintela if (qtest_has_machine("pc")) {
64a2cd86a9SPhilippe Mathieu-Daudé qtest_add_func("fuzz/test_fuzz_sb16/91", test_fuzz_sb16_0x91);
6560e543f5SQiang Liu qtest_add_func("fuzz/test_fuzz_sb16/d4", test_fuzz_sb16_0xd4);
661dbea818SJuan Quintela }
67a2cd86a9SPhilippe Mathieu-Daudé
68a2cd86a9SPhilippe Mathieu-Daudé return g_test_run();
69a2cd86a9SPhilippe Mathieu-Daudé }
70