11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * QTest testcase for Intel HDA
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright (c) 2014 SUSE LINUX Products GmbH
51e8a1faeSThomas Huth *
61e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
71e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
81e8a1faeSThomas Huth */
91e8a1faeSThomas Huth
101e8a1faeSThomas Huth #include "qemu/osdep.h"
111e8a1faeSThomas Huth #include "libqtest-single.h"
121e8a1faeSThomas Huth
131e8a1faeSThomas Huth #define HDA_ID "hda0"
14*50333482SMartin Kletzander #define AUDIODEV " -audiodev driver=none,id=audio0 "
15*50333482SMartin Kletzander #define AUDIODEV_REF "audiodev=audio0"
16*50333482SMartin Kletzander #define CODEC_DEVICES " -device hda-output,bus=" HDA_ID ".0," AUDIODEV_REF \
17*50333482SMartin Kletzander " -device hda-micro,bus=" HDA_ID ".0," AUDIODEV_REF \
18*50333482SMartin Kletzander " -device hda-duplex,bus=" HDA_ID ".0," AUDIODEV_REF
191e8a1faeSThomas Huth
201e8a1faeSThomas Huth /* Tests only initialization so far. TODO: Replace with functional tests */
ich6_test(void)211e8a1faeSThomas Huth static void ich6_test(void)
221e8a1faeSThomas Huth {
23*50333482SMartin Kletzander qtest_start(AUDIODEV "-machine pc -device intel-hda,id=" HDA_ID CODEC_DEVICES);
241e8a1faeSThomas Huth qtest_end();
251e8a1faeSThomas Huth }
261e8a1faeSThomas Huth
ich9_test(void)271e8a1faeSThomas Huth static void ich9_test(void)
281e8a1faeSThomas Huth {
29*50333482SMartin Kletzander qtest_start("-machine q35"
30*50333482SMartin Kletzander AUDIODEV
31*50333482SMartin Kletzander "-device ich9-intel-hda,bus=pcie.0,addr=1b.0,id="
321e8a1faeSThomas Huth HDA_ID CODEC_DEVICES);
331e8a1faeSThomas Huth qtest_end();
341e8a1faeSThomas Huth }
351e8a1faeSThomas Huth
3619a54527SPhilippe Mathieu-Daudé /*
3719a54527SPhilippe Mathieu-Daudé * https://gitlab.com/qemu-project/qemu/-/issues/542
3819a54527SPhilippe Mathieu-Daudé * Used to trigger:
3919a54527SPhilippe Mathieu-Daudé * AddressSanitizer: stack-overflow
4019a54527SPhilippe Mathieu-Daudé */
test_issue542_ich6(void)4119a54527SPhilippe Mathieu-Daudé static void test_issue542_ich6(void)
4219a54527SPhilippe Mathieu-Daudé {
4319a54527SPhilippe Mathieu-Daudé QTestState *s;
4419a54527SPhilippe Mathieu-Daudé
4519a54527SPhilippe Mathieu-Daudé s = qtest_init("-nographic -nodefaults -M pc-q35-6.2 "
46*50333482SMartin Kletzander AUDIODEV
4719a54527SPhilippe Mathieu-Daudé "-device intel-hda,id=" HDA_ID CODEC_DEVICES);
4819a54527SPhilippe Mathieu-Daudé
4919a54527SPhilippe Mathieu-Daudé qtest_outl(s, 0xcf8, 0x80000804);
5019a54527SPhilippe Mathieu-Daudé qtest_outw(s, 0xcfc, 0x06);
5119a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0xff0d060f, "\x03", 1);
5219a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x0, "\x12", 1);
5319a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x2, "\x2a", 1);
5419a54527SPhilippe Mathieu-Daudé qtest_writeb(s, 0x0, 0x12);
5519a54527SPhilippe Mathieu-Daudé qtest_writeb(s, 0x2, 0x2a);
5619a54527SPhilippe Mathieu-Daudé qtest_outl(s, 0xcf8, 0x80000811);
5719a54527SPhilippe Mathieu-Daudé qtest_outl(s, 0xcfc, 0x006a4400);
5819a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a44005a, "\x01", 1);
5919a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a44005c, "\x02", 1);
6019a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a442050, "\x00\x00\x44\x6a", 4);
6119a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a44204a, "\x01", 1);
6219a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a44204c, "\x02", 1);
6319a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a44005c, "\x02", 1);
6419a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a442050, "\x00\x00\x44\x6a", 4);
6519a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a44204a, "\x01", 1);
6619a54527SPhilippe Mathieu-Daudé qtest_bufwrite(s, 0x6a44204c, "\x02", 1);
6719a54527SPhilippe Mathieu-Daudé qtest_quit(s);
6819a54527SPhilippe Mathieu-Daudé }
6919a54527SPhilippe Mathieu-Daudé
main(int argc,char ** argv)701e8a1faeSThomas Huth int main(int argc, char **argv)
711e8a1faeSThomas Huth {
721e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
7308ed0988SJuan Quintela if (qtest_has_machine("pc")) {
741e8a1faeSThomas Huth qtest_add_func("/intel-hda/ich6", ich6_test);
7508ed0988SJuan Quintela }
7608ed0988SJuan Quintela if (qtest_has_machine("q35")) {
771e8a1faeSThomas Huth qtest_add_func("/intel-hda/ich9", ich9_test);
7819a54527SPhilippe Mathieu-Daudé qtest_add_func("/intel-hda/fuzz/issue542", test_issue542_ich6);
7908ed0988SJuan Quintela }
801e8a1faeSThomas Huth return g_test_run();
811e8a1faeSThomas Huth }
82