aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest/am53c974-test.c
blob: ed3ac7db20de80ffd8a3bf3dd0ebf04d0e8e1de2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
 * QTest testcase for am53c974
 *
 * Copyright (c) 2021 Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or
 * later. See the COPYING file in the top-level directory.
 */

#include "qemu/osdep.h"

#include "libqtest.h"


static void test_cmdfifo_underflow_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi "
        "-device scsi-hd,drive=disk0 -drive "
        "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x01);
    qtest_outl(s, 0xcf8, 0x8000100e);
    qtest_outl(s, 0xcfc, 0x8a000000);
    qtest_outl(s, 0x8a09, 0x42000000);
    qtest_outl(s, 0x8a0d, 0x00);
    qtest_outl(s, 0x8a0b, 0x1000);
    qtest_quit(s);
}

/* Reported as crash_1548bd10e7 */
static void test_cmdfifo_underflow2_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi -device scsi-hd,drive=disk0 "
        "-drive id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xc000);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x01);
    qtest_outw(s, 0xc00c, 0x41);
    qtest_outw(s, 0xc00a, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00c, 0x43);
    qtest_outw(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc00c, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00a, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00c, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00a, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00c, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00a, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00c, 0x00);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outl(s, 0xc006, 0x00);
    qtest_outl(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc00b, 0x0800);
    qtest_outw(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc00b, 0x00);
    qtest_outl(s, 0xc006, 0x00);
    qtest_outl(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc00b, 0x0800);
    qtest_outw(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc00b, 0x4100);
    qtest_outw(s, 0xc00a, 0x00);
    qtest_outl(s, 0xc00a, 0x100000);
    qtest_outl(s, 0xc00a, 0x00);
    qtest_outw(s, 0xc00c, 0x43);
    qtest_outl(s, 0xc00a, 0x100000);
    qtest_outl(s, 0xc00a, 0x100000);
    qtest_quit(s);
}

static void test_cmdfifo_overflow_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi "
        "-device scsi-hd,drive=disk0 -drive "
        "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x01);
    qtest_outl(s, 0xcf8, 0x8000100e);
    qtest_outl(s, 0xcfc, 0x0e000000);
    qtest_outl(s, 0xe40, 0x03);
    qtest_outl(s, 0xe0b, 0x4100);
    qtest_outl(s, 0xe0b, 0x9000);
    qtest_quit(s);
}

/* Reported as crash_530ff2e211 */
static void test_cmdfifo_overflow2_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi -device scsi-hd,drive=disk0 "
        "-drive id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xc000);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x01);
    qtest_outl(s, 0xc00b, 0x4100);
    qtest_outw(s, 0xc00b, 0xc200);
    qtest_outl(s, 0xc03f, 0x0300);
    qtest_quit(s);
}

/* Reported as crash_0900379669 */
static void test_fifo_pop_buf(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi -device scsi-hd,drive=disk0 "
        "-drive id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xc000);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x01);
    qtest_outb(s, 0xc000, 0x4);
    qtest_outb(s, 0xc008, 0xa0);
    qtest_outl(s, 0xc03f, 0x0300);
    qtest_outl(s, 0xc00b, 0xc300);
    qtest_outw(s, 0xc00b, 0x9000);
    qtest_outl(s, 0xc00b, 0xc300);
    qtest_outl(s, 0xc00b, 0xc300);
    qtest_outl(s, 0xc00b, 0xc300);
    qtest_outw(s, 0xc00b, 0x9000);
    qtest_outw(s, 0xc00b, 0x1000);
    qtest_quit(s);
}

static void test_target_selected_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi "
        "-device scsi-hd,drive=disk0 -drive "
        "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001001);
    qtest_outl(s, 0xcfc, 0x01000000);
    qtest_outl(s, 0xcf8, 0x8000100e);
    qtest_outl(s, 0xcfc, 0xef800000);
    qtest_outl(s, 0xef8b, 0x4100);
    qtest_outw(s, 0xef80, 0x01);
    qtest_outl(s, 0xefc0, 0x03);
    qtest_outl(s, 0xef8b, 0xc100);
    qtest_outl(s, 0xef8b, 0x9000);
    qtest_quit(s);
}

static void test_fifo_underflow_on_write_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi "
        "-device scsi-hd,drive=disk0 -drive "
        "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xc000);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x01);
    qtest_outl(s, 0xc008, 0x0a);
    qtest_outl(s, 0xc009, 0x41000000);
    qtest_outl(s, 0xc009, 0x41000000);
    qtest_outl(s, 0xc00b, 0x1000);
    qtest_quit(s);
}

static void test_cancelled_request_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi "
        "-device scsi-hd,drive=disk0 -drive "
        "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xc000);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x05);
    qtest_outb(s, 0xc046, 0x02);
    qtest_outl(s, 0xc00b, 0xc100);
    qtest_outl(s, 0xc040, 0x03);
    qtest_outl(s, 0xc040, 0x03);
    qtest_bufwrite(s, 0x0, "\x41", 0x1);
    qtest_outl(s, 0xc00b, 0xc100);
    qtest_outw(s, 0xc040, 0x02);
    qtest_outw(s, 0xc040, 0x81);
    qtest_outl(s, 0xc00b, 0x9000);
    qtest_quit(s);
}

static void test_inflight_cancel_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi "
        "-device scsi-hd,drive=disk0 -drive "
        "id=disk0,if=none,file=null-co://,format=raw -nodefaults");
    qtest_outl(s, 0xcf8, 0x80001000);
    qtest_inw(s, 0xcfc);
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xffffffff);
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_inl(s, 0xcfc);
    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xc001);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_inw(s, 0xcfc);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x7);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_inw(s, 0xcfc);
    qtest_inb(s, 0xc000);
    qtest_outb(s, 0xc008, 0x8);
    qtest_outw(s, 0xc00b, 0x4100);
    qtest_outb(s, 0xc009, 0x0);
    qtest_outb(s, 0xc009, 0x0);
    qtest_outw(s, 0xc00b, 0xc212);
    qtest_outl(s, 0xc042, 0x2c2c5a88);
    qtest_outw(s, 0xc00b, 0xc212);
    qtest_outw(s, 0xc00b, 0x415a);
    qtest_outl(s, 0xc03f, 0x3060303);
    qtest_outl(s, 0xc00b, 0x5afa9054);
    qtest_quit(s);
}

static void test_reset_before_transfer_ok(void)
{
    QTestState *s = qtest_init(
        "-device am53c974,id=scsi "
        "-device scsi-hd,drive=disk0 -drive "
        "id=disk0,if=none,file=null-co://,format=raw -nodefaults");

    qtest_outl(s, 0xcf8, 0x80001010);
    qtest_outl(s, 0xcfc, 0xc000);
    qtest_outl(s, 0xcf8, 0x80001004);
    qtest_outw(s, 0xcfc, 0x01);
    qtest_outl(s, 0xc007, 0x2500);
    qtest_outl(s, 0xc00a, 0x410000);
    qtest_outl(s, 0xc00a, 0x410000);
    qtest_outw(s, 0xc00b, 0x0200);
    qtest_outw(s, 0xc040, 0x03);
    qtest_outw(s, 0xc009, 0x00);
    qtest_outw(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc009, 0x00);
    qtest_outw(s, 0xc00b, 0x00);
    qtest_outw(s, 0xc009, 0x00);
    qtest_outw(s, 0xc003, 0x1000);
    qtest_outw(s, 0xc00b, 0x1000);
    qtest_outl(s, 0xc00b, 0x9000);
    qtest_outw(s, 0xc00b, 0x1000);
    qtest_quit(s);
}

int main(int argc, char **argv)
{
    const char *arch = qtest_get_arch();

    g_test_init(&argc, &argv, NULL);

    if (strcmp(arch, "i386") == 0) {
        qtest_add_func("am53c974/test_cmdfifo_underflow_ok",
                       test_cmdfifo_underflow_ok);
        qtest_add_func("am53c974/test_cmdfifo_underflow2_ok",
                       test_cmdfifo_underflow2_ok);
        qtest_add_func("am53c974/test_cmdfifo_overflow_ok",
                       test_cmdfifo_overflow_ok);
        qtest_add_func("am53c974/test_cmdfifo_overflow2_ok",
                       test_cmdfifo_overflow2_ok);
        qtest_add_func("am53c974/test_fifo_pop_buf",
                       test_fifo_pop_buf);
        qtest_add_func("am53c974/test_target_selected_ok",
                       test_target_selected_ok);
        qtest_add_func("am53c974/test_fifo_underflow_on_write_ok",
                       test_fifo_underflow_on_write_ok);
        qtest_add_func("am53c974/test_cancelled_request_ok",
                       test_cancelled_request_ok);
        qtest_add_func("am53c974/test_inflight_cancel_ok",
                       test_inflight_cancel_ok);
        qtest_add_func("am53c974/test_reset_before_transfer_ok",
                       test_reset_before_transfer_ok);
    }

    return g_test_run();
}