]> git.proxmox.com Git - mirror_qemu.git/blob - tests/qtest/am53c974-test.c
Merge tag 'pull-ppc-20211217' of https://github.com/legoater/qemu into staging
[mirror_qemu.git] / tests / qtest / am53c974-test.c
1 /*
2 * QTest testcase for am53c974
3 *
4 * Copyright (c) 2021 Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * later. See the COPYING file in the top-level directory.
8 */
9
10 #include "qemu/osdep.h"
11
12 #include "libqos/libqtest.h"
13
14
15 static void test_cmdfifo_underflow_ok(void)
16 {
17 QTestState *s = qtest_init(
18 "-device am53c974,id=scsi "
19 "-device scsi-hd,drive=disk0 -drive "
20 "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
21 qtest_outl(s, 0xcf8, 0x80001004);
22 qtest_outw(s, 0xcfc, 0x01);
23 qtest_outl(s, 0xcf8, 0x8000100e);
24 qtest_outl(s, 0xcfc, 0x8a000000);
25 qtest_outl(s, 0x8a09, 0x42000000);
26 qtest_outl(s, 0x8a0d, 0x00);
27 qtest_outl(s, 0x8a0b, 0x1000);
28 qtest_quit(s);
29 }
30
31 /* Reported as crash_1548bd10e7 */
32 static void test_cmdfifo_underflow2_ok(void)
33 {
34 QTestState *s = qtest_init(
35 "-device am53c974,id=scsi -device scsi-hd,drive=disk0 "
36 "-drive id=disk0,if=none,file=null-co://,format=raw -nodefaults");
37 qtest_outl(s, 0xcf8, 0x80001010);
38 qtest_outl(s, 0xcfc, 0xc000);
39 qtest_outl(s, 0xcf8, 0x80001004);
40 qtest_outw(s, 0xcfc, 0x01);
41 qtest_outw(s, 0xc00c, 0x41);
42 qtest_outw(s, 0xc00a, 0x00);
43 qtest_outl(s, 0xc00a, 0x00);
44 qtest_outw(s, 0xc00c, 0x43);
45 qtest_outw(s, 0xc00b, 0x00);
46 qtest_outw(s, 0xc00b, 0x00);
47 qtest_outw(s, 0xc00c, 0x00);
48 qtest_outl(s, 0xc00a, 0x00);
49 qtest_outw(s, 0xc00a, 0x00);
50 qtest_outl(s, 0xc00a, 0x00);
51 qtest_outw(s, 0xc00c, 0x00);
52 qtest_outl(s, 0xc00a, 0x00);
53 qtest_outw(s, 0xc00a, 0x00);
54 qtest_outl(s, 0xc00a, 0x00);
55 qtest_outw(s, 0xc00c, 0x00);
56 qtest_outl(s, 0xc00a, 0x00);
57 qtest_outw(s, 0xc00a, 0x00);
58 qtest_outl(s, 0xc00a, 0x00);
59 qtest_outw(s, 0xc00c, 0x00);
60 qtest_outl(s, 0xc00a, 0x00);
61 qtest_outl(s, 0xc006, 0x00);
62 qtest_outl(s, 0xc00b, 0x00);
63 qtest_outw(s, 0xc00b, 0x0800);
64 qtest_outw(s, 0xc00b, 0x00);
65 qtest_outw(s, 0xc00b, 0x00);
66 qtest_outl(s, 0xc006, 0x00);
67 qtest_outl(s, 0xc00b, 0x00);
68 qtest_outw(s, 0xc00b, 0x0800);
69 qtest_outw(s, 0xc00b, 0x00);
70 qtest_outw(s, 0xc00b, 0x4100);
71 qtest_outw(s, 0xc00a, 0x00);
72 qtest_outl(s, 0xc00a, 0x100000);
73 qtest_outl(s, 0xc00a, 0x00);
74 qtest_outw(s, 0xc00c, 0x43);
75 qtest_outl(s, 0xc00a, 0x100000);
76 qtest_outl(s, 0xc00a, 0x100000);
77 qtest_quit(s);
78 }
79
80 static void test_cmdfifo_overflow_ok(void)
81 {
82 QTestState *s = qtest_init(
83 "-device am53c974,id=scsi "
84 "-device scsi-hd,drive=disk0 -drive "
85 "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
86 qtest_outl(s, 0xcf8, 0x80001004);
87 qtest_outw(s, 0xcfc, 0x01);
88 qtest_outl(s, 0xcf8, 0x8000100e);
89 qtest_outl(s, 0xcfc, 0x0e000000);
90 qtest_outl(s, 0xe40, 0x03);
91 qtest_outl(s, 0xe0b, 0x4100);
92 qtest_outl(s, 0xe0b, 0x9000);
93 qtest_quit(s);
94 }
95
96 /* Reported as crash_530ff2e211 */
97 static void test_cmdfifo_overflow2_ok(void)
98 {
99 QTestState *s = qtest_init(
100 "-device am53c974,id=scsi -device scsi-hd,drive=disk0 "
101 "-drive id=disk0,if=none,file=null-co://,format=raw -nodefaults");
102 qtest_outl(s, 0xcf8, 0x80001010);
103 qtest_outl(s, 0xcfc, 0xc000);
104 qtest_outl(s, 0xcf8, 0x80001004);
105 qtest_outw(s, 0xcfc, 0x01);
106 qtest_outl(s, 0xc00b, 0x4100);
107 qtest_outw(s, 0xc00b, 0xc200);
108 qtest_outl(s, 0xc03f, 0x0300);
109 qtest_quit(s);
110 }
111
112 /* Reported as crash_0900379669 */
113 static void test_fifo_pop_buf(void)
114 {
115 QTestState *s = qtest_init(
116 "-device am53c974,id=scsi -device scsi-hd,drive=disk0 "
117 "-drive id=disk0,if=none,file=null-co://,format=raw -nodefaults");
118 qtest_outl(s, 0xcf8, 0x80001010);
119 qtest_outl(s, 0xcfc, 0xc000);
120 qtest_outl(s, 0xcf8, 0x80001004);
121 qtest_outw(s, 0xcfc, 0x01);
122 qtest_outb(s, 0xc000, 0x4);
123 qtest_outb(s, 0xc008, 0xa0);
124 qtest_outl(s, 0xc03f, 0x0300);
125 qtest_outl(s, 0xc00b, 0xc300);
126 qtest_outw(s, 0xc00b, 0x9000);
127 qtest_outl(s, 0xc00b, 0xc300);
128 qtest_outl(s, 0xc00b, 0xc300);
129 qtest_outl(s, 0xc00b, 0xc300);
130 qtest_outw(s, 0xc00b, 0x9000);
131 qtest_outw(s, 0xc00b, 0x1000);
132 qtest_quit(s);
133 }
134
135 static void test_target_selected_ok(void)
136 {
137 QTestState *s = qtest_init(
138 "-device am53c974,id=scsi "
139 "-device scsi-hd,drive=disk0 -drive "
140 "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
141 qtest_outl(s, 0xcf8, 0x80001001);
142 qtest_outl(s, 0xcfc, 0x01000000);
143 qtest_outl(s, 0xcf8, 0x8000100e);
144 qtest_outl(s, 0xcfc, 0xef800000);
145 qtest_outl(s, 0xef8b, 0x4100);
146 qtest_outw(s, 0xef80, 0x01);
147 qtest_outl(s, 0xefc0, 0x03);
148 qtest_outl(s, 0xef8b, 0xc100);
149 qtest_outl(s, 0xef8b, 0x9000);
150 qtest_quit(s);
151 }
152
153 static void test_fifo_underflow_on_write_ok(void)
154 {
155 QTestState *s = qtest_init(
156 "-device am53c974,id=scsi "
157 "-device scsi-hd,drive=disk0 -drive "
158 "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
159 qtest_outl(s, 0xcf8, 0x80001010);
160 qtest_outl(s, 0xcfc, 0xc000);
161 qtest_outl(s, 0xcf8, 0x80001004);
162 qtest_outw(s, 0xcfc, 0x01);
163 qtest_outl(s, 0xc008, 0x0a);
164 qtest_outl(s, 0xc009, 0x41000000);
165 qtest_outl(s, 0xc009, 0x41000000);
166 qtest_outl(s, 0xc00b, 0x1000);
167 qtest_quit(s);
168 }
169
170 static void test_cancelled_request_ok(void)
171 {
172 QTestState *s = qtest_init(
173 "-device am53c974,id=scsi "
174 "-device scsi-hd,drive=disk0 -drive "
175 "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
176 qtest_outl(s, 0xcf8, 0x80001010);
177 qtest_outl(s, 0xcfc, 0xc000);
178 qtest_outl(s, 0xcf8, 0x80001004);
179 qtest_outw(s, 0xcfc, 0x05);
180 qtest_outb(s, 0xc046, 0x02);
181 qtest_outl(s, 0xc00b, 0xc100);
182 qtest_outl(s, 0xc040, 0x03);
183 qtest_outl(s, 0xc040, 0x03);
184 qtest_bufwrite(s, 0x0, "\x41", 0x1);
185 qtest_outl(s, 0xc00b, 0xc100);
186 qtest_outw(s, 0xc040, 0x02);
187 qtest_outw(s, 0xc040, 0x81);
188 qtest_outl(s, 0xc00b, 0x9000);
189 qtest_quit(s);
190 }
191
192 static void test_inflight_cancel_ok(void)
193 {
194 QTestState *s = qtest_init(
195 "-device am53c974,id=scsi "
196 "-device scsi-hd,drive=disk0 -drive "
197 "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
198 qtest_outl(s, 0xcf8, 0x80001000);
199 qtest_inw(s, 0xcfc);
200 qtest_outl(s, 0xcf8, 0x80001010);
201 qtest_outl(s, 0xcfc, 0xffffffff);
202 qtest_outl(s, 0xcf8, 0x80001010);
203 qtest_inl(s, 0xcfc);
204 qtest_outl(s, 0xcf8, 0x80001010);
205 qtest_outl(s, 0xcfc, 0xc001);
206 qtest_outl(s, 0xcf8, 0x80001004);
207 qtest_inw(s, 0xcfc);
208 qtest_outl(s, 0xcf8, 0x80001004);
209 qtest_outw(s, 0xcfc, 0x7);
210 qtest_outl(s, 0xcf8, 0x80001004);
211 qtest_inw(s, 0xcfc);
212 qtest_inb(s, 0xc000);
213 qtest_outb(s, 0xc008, 0x8);
214 qtest_outw(s, 0xc00b, 0x4100);
215 qtest_outb(s, 0xc009, 0x0);
216 qtest_outb(s, 0xc009, 0x0);
217 qtest_outw(s, 0xc00b, 0xc212);
218 qtest_outl(s, 0xc042, 0x2c2c5a88);
219 qtest_outw(s, 0xc00b, 0xc212);
220 qtest_outw(s, 0xc00b, 0x415a);
221 qtest_outl(s, 0xc03f, 0x3060303);
222 qtest_outl(s, 0xc00b, 0x5afa9054);
223 qtest_quit(s);
224 }
225
226 static void test_reset_before_transfer_ok(void)
227 {
228 QTestState *s = qtest_init(
229 "-device am53c974,id=scsi "
230 "-device scsi-hd,drive=disk0 -drive "
231 "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
232
233 qtest_outl(s, 0xcf8, 0x80001010);
234 qtest_outl(s, 0xcfc, 0xc000);
235 qtest_outl(s, 0xcf8, 0x80001004);
236 qtest_outw(s, 0xcfc, 0x01);
237 qtest_outl(s, 0xc007, 0x2500);
238 qtest_outl(s, 0xc00a, 0x410000);
239 qtest_outl(s, 0xc00a, 0x410000);
240 qtest_outw(s, 0xc00b, 0x0200);
241 qtest_outw(s, 0xc040, 0x03);
242 qtest_outw(s, 0xc009, 0x00);
243 qtest_outw(s, 0xc00b, 0x00);
244 qtest_outw(s, 0xc009, 0x00);
245 qtest_outw(s, 0xc00b, 0x00);
246 qtest_outw(s, 0xc009, 0x00);
247 qtest_outw(s, 0xc003, 0x1000);
248 qtest_outw(s, 0xc00b, 0x1000);
249 qtest_outl(s, 0xc00b, 0x9000);
250 qtest_outw(s, 0xc00b, 0x1000);
251 qtest_quit(s);
252 }
253
254 int main(int argc, char **argv)
255 {
256 const char *arch = qtest_get_arch();
257
258 g_test_init(&argc, &argv, NULL);
259
260 if (strcmp(arch, "i386") == 0) {
261 qtest_add_func("am53c974/test_cmdfifo_underflow_ok",
262 test_cmdfifo_underflow_ok);
263 qtest_add_func("am53c974/test_cmdfifo_underflow2_ok",
264 test_cmdfifo_underflow2_ok);
265 qtest_add_func("am53c974/test_cmdfifo_overflow_ok",
266 test_cmdfifo_overflow_ok);
267 qtest_add_func("am53c974/test_cmdfifo_overflow2_ok",
268 test_cmdfifo_overflow2_ok);
269 qtest_add_func("am53c974/test_fifo_pop_buf",
270 test_fifo_pop_buf);
271 qtest_add_func("am53c974/test_target_selected_ok",
272 test_target_selected_ok);
273 qtest_add_func("am53c974/test_fifo_underflow_on_write_ok",
274 test_fifo_underflow_on_write_ok);
275 qtest_add_func("am53c974/test_cancelled_request_ok",
276 test_cancelled_request_ok);
277 qtest_add_func("am53c974/test_inflight_cancel_ok",
278 test_inflight_cancel_ok);
279 qtest_add_func("am53c974/test_reset_before_transfer_ok",
280 test_reset_before_transfer_ok);
281 }
282
283 return g_test_run();
284 }