xref: /openbmc/qemu/tests/qtest/intel-hda-test.c (revision 096b778f)
1 /*
2  * QTest testcase for Intel HDA
3  *
4  * Copyright (c) 2014 SUSE LINUX Products GmbH
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "libqtest-single.h"
12 
13 #define HDA_ID "hda0"
14 #define CODEC_DEVICES " -device hda-output,bus=" HDA_ID ".0" \
15                       " -device hda-micro,bus=" HDA_ID ".0" \
16                       " -device hda-duplex,bus=" HDA_ID ".0"
17 
18 /* Tests only initialization so far. TODO: Replace with functional tests */
19 static void ich6_test(void)
20 {
21     qtest_start("-device intel-hda,id=" HDA_ID CODEC_DEVICES);
22     qtest_end();
23 }
24 
25 static void ich9_test(void)
26 {
27     qtest_start("-machine q35 -device ich9-intel-hda,bus=pcie.0,addr=1b.0,id="
28                 HDA_ID CODEC_DEVICES);
29     qtest_end();
30 }
31 
32 /*
33  * https://gitlab.com/qemu-project/qemu/-/issues/542
34  * Used to trigger:
35  *  AddressSanitizer: stack-overflow
36  */
37 static void test_issue542_ich6(void)
38 {
39     QTestState *s;
40 
41     s = qtest_init("-nographic -nodefaults -M pc-q35-6.2 "
42                    "-device intel-hda,id=" HDA_ID CODEC_DEVICES);
43 
44     qtest_outl(s, 0xcf8, 0x80000804);
45     qtest_outw(s, 0xcfc, 0x06);
46     qtest_bufwrite(s, 0xff0d060f, "\x03", 1);
47     qtest_bufwrite(s, 0x0, "\x12", 1);
48     qtest_bufwrite(s, 0x2, "\x2a", 1);
49     qtest_writeb(s, 0x0, 0x12);
50     qtest_writeb(s, 0x2, 0x2a);
51     qtest_outl(s, 0xcf8, 0x80000811);
52     qtest_outl(s, 0xcfc, 0x006a4400);
53     qtest_bufwrite(s, 0x6a44005a, "\x01", 1);
54     qtest_bufwrite(s, 0x6a44005c, "\x02", 1);
55     qtest_bufwrite(s, 0x6a442050, "\x00\x00\x44\x6a", 4);
56     qtest_bufwrite(s, 0x6a44204a, "\x01", 1);
57     qtest_bufwrite(s, 0x6a44204c, "\x02", 1);
58     qtest_bufwrite(s, 0x6a44005c, "\x02", 1);
59     qtest_bufwrite(s, 0x6a442050, "\x00\x00\x44\x6a", 4);
60     qtest_bufwrite(s, 0x6a44204a, "\x01", 1);
61     qtest_bufwrite(s, 0x6a44204c, "\x02", 1);
62     qtest_quit(s);
63 }
64 
65 int main(int argc, char **argv)
66 {
67     g_test_init(&argc, &argv, NULL);
68     qtest_add_func("/intel-hda/ich6", ich6_test);
69     qtest_add_func("/intel-hda/ich9", ich9_test);
70     qtest_add_func("/intel-hda/fuzz/issue542", test_issue542_ich6);
71 
72     return g_test_run();
73 }
74