xref: /openbmc/qemu/tests/qtest/fuzz-virtio-scsi-test.c (revision b43957dcdda3c6190b94a0d186897f8fc8ecec7a)
1*b43957dcSPhilippe Mathieu-Daudé /*
2*b43957dcSPhilippe Mathieu-Daudé  * QTest fuzzer-generated testcase for virtio-scsi device
3*b43957dcSPhilippe Mathieu-Daudé  *
4*b43957dcSPhilippe Mathieu-Daudé  * Copyright (c) 2020 Li Qiang <liq3ea@gmail.com>
5*b43957dcSPhilippe Mathieu-Daudé  *
6*b43957dcSPhilippe Mathieu-Daudé  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7*b43957dcSPhilippe Mathieu-Daudé  * See the COPYING file in the top-level directory.
8*b43957dcSPhilippe Mathieu-Daudé  */
9*b43957dcSPhilippe Mathieu-Daudé 
10*b43957dcSPhilippe Mathieu-Daudé #include "qemu/osdep.h"
11*b43957dcSPhilippe Mathieu-Daudé 
12*b43957dcSPhilippe Mathieu-Daudé #include "libqos/libqtest.h"
13*b43957dcSPhilippe Mathieu-Daudé 
14*b43957dcSPhilippe Mathieu-Daudé /*
15*b43957dcSPhilippe Mathieu-Daudé  * Here a MemoryRegionCache pointed to an MMIO region but had a
16*b43957dcSPhilippe Mathieu-Daudé  * larger size than the underlying region.
17*b43957dcSPhilippe Mathieu-Daudé  */
18*b43957dcSPhilippe Mathieu-Daudé static void test_mmio_oob_from_memory_region_cache(void)
19*b43957dcSPhilippe Mathieu-Daudé {
20*b43957dcSPhilippe Mathieu-Daudé     QTestState *s;
21*b43957dcSPhilippe Mathieu-Daudé 
22*b43957dcSPhilippe Mathieu-Daudé     s = qtest_init("-M pc-q35-5.2 -display none -m 512M "
23*b43957dcSPhilippe Mathieu-Daudé                    "-device virtio-scsi,num_queues=8,addr=03.0 ");
24*b43957dcSPhilippe Mathieu-Daudé 
25*b43957dcSPhilippe Mathieu-Daudé     qtest_outl(s, 0xcf8, 0x80001811);
26*b43957dcSPhilippe Mathieu-Daudé     qtest_outb(s, 0xcfc, 0x6e);
27*b43957dcSPhilippe Mathieu-Daudé     qtest_outl(s, 0xcf8, 0x80001824);
28*b43957dcSPhilippe Mathieu-Daudé     qtest_outl(s, 0xcf8, 0x80001813);
29*b43957dcSPhilippe Mathieu-Daudé     qtest_outl(s, 0xcfc, 0xa080000);
30*b43957dcSPhilippe Mathieu-Daudé     qtest_outl(s, 0xcf8, 0x80001802);
31*b43957dcSPhilippe Mathieu-Daudé     qtest_outl(s, 0xcfc, 0x5a175a63);
32*b43957dcSPhilippe Mathieu-Daudé     qtest_outb(s, 0x6e08, 0x9e);
33*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f003, 0xff);
34*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f004, 0x01);
35*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9e012, 0x0e);
36*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9e01b, 0x0e);
37*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f006, 0x01);
38*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f008, 0x01);
39*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f00a, 0x01);
40*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f00c, 0x01);
41*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f00e, 0x01);
42*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f010, 0x01);
43*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f012, 0x01);
44*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f014, 0x01);
45*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f016, 0x01);
46*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f018, 0x01);
47*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f01a, 0x01);
48*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f01c, 0x01);
49*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f01e, 0x01);
50*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f020, 0x01);
51*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f022, 0x01);
52*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f024, 0x01);
53*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f026, 0x01);
54*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f028, 0x01);
55*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f02a, 0x01);
56*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f02c, 0x01);
57*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f02e, 0x01);
58*b43957dcSPhilippe Mathieu-Daudé     qtest_writeb(s, 0x9f030, 0x01);
59*b43957dcSPhilippe Mathieu-Daudé     qtest_outb(s, 0x6e10, 0x00);
60*b43957dcSPhilippe Mathieu-Daudé     qtest_quit(s);
61*b43957dcSPhilippe Mathieu-Daudé }
62*b43957dcSPhilippe Mathieu-Daudé 
63*b43957dcSPhilippe Mathieu-Daudé int main(int argc, char **argv)
64*b43957dcSPhilippe Mathieu-Daudé {
65*b43957dcSPhilippe Mathieu-Daudé     const char *arch = qtest_get_arch();
66*b43957dcSPhilippe Mathieu-Daudé 
67*b43957dcSPhilippe Mathieu-Daudé     g_test_init(&argc, &argv, NULL);
68*b43957dcSPhilippe Mathieu-Daudé 
69*b43957dcSPhilippe Mathieu-Daudé     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
70*b43957dcSPhilippe Mathieu-Daudé         qtest_add_func("fuzz/test_mmio_oob_from_memory_region_cache",
71*b43957dcSPhilippe Mathieu-Daudé                        test_mmio_oob_from_memory_region_cache);
72*b43957dcSPhilippe Mathieu-Daudé     }
73*b43957dcSPhilippe Mathieu-Daudé 
74*b43957dcSPhilippe Mathieu-Daudé     return g_test_run();
75*b43957dcSPhilippe Mathieu-Daudé }
76