4 * Copyright (c) 2013 Kevin Wolf <kwolf@redhat.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
30 #include "libqos/libqos.h"
31 #include "libqos/pci-pc.h"
32 #include "libqos/malloc-pc.h"
34 #include "qemu-common.h"
35 #include "hw/pci/pci_ids.h"
36 #include "hw/pci/pci_regs.h"
38 #define TEST_IMAGE_SIZE 64 * 1024 * 1024
41 #define IDE_PCI_FUNC 1
43 #define IDE_BASE 0x1f0
44 #define IDE_PRIMARY_IRQ 14
46 #define ATAPI_BLOCK_SIZE 2048
48 /* How many bytes to receive via ATAPI PIO at one time.
49 * Must be less than 0xFFFF. */
50 #define BYTE_COUNT_LIMIT 5120
86 CMD_FLUSH_CACHE
= 0xe7,
96 BM_CMD_WRITE
= 0x8, /* write = from device to memory */
106 PRDT_EOT
= 0x80000000,
109 #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
110 #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
112 static QPCIBus
*pcibus
= NULL
;
113 static QGuestAllocator
*guest_malloc
;
115 static char tmp_path
[] = "/tmp/qtest.XXXXXX";
116 static char debug_path
[] = "/tmp/qtest-blkdebug.XXXXXX";
118 static void ide_test_start(const char *cmdline_fmt
, ...)
123 va_start(ap
, cmdline_fmt
);
124 cmdline
= g_strdup_vprintf(cmdline_fmt
, ap
);
127 qtest_start(cmdline
);
128 guest_malloc
= pc_alloc_init();
133 static void ide_test_quit(void)
135 pc_alloc_uninit(guest_malloc
);
140 static QPCIDevice
*get_pci_device(uint16_t *bmdma_base
)
143 uint16_t vendor_id
, device_id
;
146 pcibus
= qpci_init_pc();
149 /* Find PCI device and verify it's the right one */
150 dev
= qpci_device_find(pcibus
, QPCI_DEVFN(IDE_PCI_DEV
, IDE_PCI_FUNC
));
151 g_assert(dev
!= NULL
);
153 vendor_id
= qpci_config_readw(dev
, PCI_VENDOR_ID
);
154 device_id
= qpci_config_readw(dev
, PCI_DEVICE_ID
);
155 g_assert(vendor_id
== PCI_VENDOR_ID_INTEL
);
156 g_assert(device_id
== PCI_DEVICE_ID_INTEL_82371SB_1
);
159 *bmdma_base
= (uint16_t)(uintptr_t) qpci_iomap(dev
, 4, NULL
);
161 qpci_device_enable(dev
);
166 static void free_pci_device(QPCIDevice
*dev
)
168 /* libqos doesn't have a function for this, so free it manually */
172 typedef struct PrdtEntry
{
175 } QEMU_PACKED PrdtEntry
;
177 #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
178 #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
180 static int send_dma_request(int cmd
, uint64_t sector
, int nb_sectors
,
181 PrdtEntry
*prdt
, int prdt_entries
,
182 void(*post_exec
)(uint64_t sector
, int nb_sectors
))
186 uintptr_t guest_prdt
;
192 dev
= get_pci_device(&bmdma_base
);
200 /* Assuming we only test data reads w/ ATAPI, otherwise we need to know
201 * the SCSI command being sent in the packet, too. */
208 g_assert_not_reached();
211 if (flags
& CMDF_NO_BM
) {
212 qpci_config_writew(dev
, PCI_COMMAND
,
213 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
216 /* Select device 0 */
217 outb(IDE_BASE
+ reg_device
, 0 | LBA
);
219 /* Stop any running transfer, clear any pending interrupt */
220 outb(bmdma_base
+ bmreg_cmd
, 0);
221 outb(bmdma_base
+ bmreg_status
, BM_STS_INTR
);
224 len
= sizeof(*prdt
) * prdt_entries
;
225 guest_prdt
= guest_alloc(guest_malloc
, len
);
226 memwrite(guest_prdt
, prdt
, len
);
227 outl(bmdma_base
+ bmreg_prdt
, guest_prdt
);
229 /* ATA DMA command */
230 if (cmd
== CMD_PACKET
) {
231 /* Enables ATAPI DMA; otherwise PIO is attempted */
232 outb(IDE_BASE
+ reg_feature
, 0x01);
234 outb(IDE_BASE
+ reg_nsectors
, nb_sectors
);
235 outb(IDE_BASE
+ reg_lba_low
, sector
& 0xff);
236 outb(IDE_BASE
+ reg_lba_middle
, (sector
>> 8) & 0xff);
237 outb(IDE_BASE
+ reg_lba_high
, (sector
>> 16) & 0xff);
240 outb(IDE_BASE
+ reg_command
, cmd
);
243 post_exec(sector
, nb_sectors
);
246 /* Start DMA transfer */
247 outb(bmdma_base
+ bmreg_cmd
, BM_CMD_START
| (from_dev
? BM_CMD_WRITE
: 0));
249 if (flags
& CMDF_ABORT
) {
250 outb(bmdma_base
+ bmreg_cmd
, 0);
253 /* Wait for the DMA transfer to complete */
255 status
= inb(bmdma_base
+ bmreg_status
);
256 } while ((status
& (BM_STS_ACTIVE
| BM_STS_INTR
)) == BM_STS_ACTIVE
);
258 g_assert_cmpint(get_irq(IDE_PRIMARY_IRQ
), ==, !!(status
& BM_STS_INTR
));
260 /* Check IDE status code */
261 assert_bit_set(inb(IDE_BASE
+ reg_status
), DRDY
);
262 assert_bit_clear(inb(IDE_BASE
+ reg_status
), BSY
| DRQ
);
264 /* Reading the status register clears the IRQ */
265 g_assert(!get_irq(IDE_PRIMARY_IRQ
));
267 /* Stop DMA transfer if still active */
268 if (status
& BM_STS_ACTIVE
) {
269 outb(bmdma_base
+ bmreg_cmd
, 0);
272 free_pci_device(dev
);
277 static void test_bmdma_simple_rw(void)
283 uintptr_t guest_buf
= guest_alloc(guest_malloc
, len
);
287 .addr
= cpu_to_le32(guest_buf
),
288 .size
= cpu_to_le32(len
| PRDT_EOT
),
293 cmpbuf
= g_malloc(len
);
295 /* Write 0x55 pattern to sector 0 */
296 memset(buf
, 0x55, len
);
297 memwrite(guest_buf
, buf
, len
);
299 status
= send_dma_request(CMD_WRITE_DMA
, 0, 1, prdt
,
300 ARRAY_SIZE(prdt
), NULL
);
301 g_assert_cmphex(status
, ==, BM_STS_INTR
);
302 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
304 /* Write 0xaa pattern to sector 1 */
305 memset(buf
, 0xaa, len
);
306 memwrite(guest_buf
, buf
, len
);
308 status
= send_dma_request(CMD_WRITE_DMA
, 1, 1, prdt
,
309 ARRAY_SIZE(prdt
), NULL
);
310 g_assert_cmphex(status
, ==, BM_STS_INTR
);
311 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
313 /* Read and verify 0x55 pattern in sector 0 */
314 memset(cmpbuf
, 0x55, len
);
316 status
= send_dma_request(CMD_READ_DMA
, 0, 1, prdt
, ARRAY_SIZE(prdt
), NULL
);
317 g_assert_cmphex(status
, ==, BM_STS_INTR
);
318 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
320 memread(guest_buf
, buf
, len
);
321 g_assert(memcmp(buf
, cmpbuf
, len
) == 0);
323 /* Read and verify 0xaa pattern in sector 1 */
324 memset(cmpbuf
, 0xaa, len
);
326 status
= send_dma_request(CMD_READ_DMA
, 1, 1, prdt
, ARRAY_SIZE(prdt
), NULL
);
327 g_assert_cmphex(status
, ==, BM_STS_INTR
);
328 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
330 memread(guest_buf
, buf
, len
);
331 g_assert(memcmp(buf
, cmpbuf
, len
) == 0);
338 static void test_bmdma_short_prdt(void)
345 .size
= cpu_to_le32(0x10 | PRDT_EOT
),
350 status
= send_dma_request(CMD_READ_DMA
, 0, 1,
351 prdt
, ARRAY_SIZE(prdt
), NULL
);
352 g_assert_cmphex(status
, ==, 0);
353 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
355 /* Abort the request before it completes */
356 status
= send_dma_request(CMD_READ_DMA
| CMDF_ABORT
, 0, 1,
357 prdt
, ARRAY_SIZE(prdt
), NULL
);
358 g_assert_cmphex(status
, ==, 0);
359 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
362 static void test_bmdma_one_sector_short_prdt(void)
366 /* Read 2 sectors but only give 1 sector in PRDT */
370 .size
= cpu_to_le32(0x200 | PRDT_EOT
),
375 status
= send_dma_request(CMD_READ_DMA
, 0, 2,
376 prdt
, ARRAY_SIZE(prdt
), NULL
);
377 g_assert_cmphex(status
, ==, 0);
378 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
380 /* Abort the request before it completes */
381 status
= send_dma_request(CMD_READ_DMA
| CMDF_ABORT
, 0, 2,
382 prdt
, ARRAY_SIZE(prdt
), NULL
);
383 g_assert_cmphex(status
, ==, 0);
384 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
387 static void test_bmdma_long_prdt(void)
394 .size
= cpu_to_le32(0x1000 | PRDT_EOT
),
399 status
= send_dma_request(CMD_READ_DMA
, 0, 1,
400 prdt
, ARRAY_SIZE(prdt
), NULL
);
401 g_assert_cmphex(status
, ==, BM_STS_ACTIVE
| BM_STS_INTR
);
402 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
404 /* Abort the request before it completes */
405 status
= send_dma_request(CMD_READ_DMA
| CMDF_ABORT
, 0, 1,
406 prdt
, ARRAY_SIZE(prdt
), NULL
);
407 g_assert_cmphex(status
, ==, BM_STS_INTR
);
408 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
411 static void test_bmdma_no_busmaster(void)
415 /* No PRDT_EOT, each entry addr 0/size 64k, and in theory qemu shouldn't be
416 * able to access it anyway because the Bus Master bit in the PCI command
417 * register isn't set. This is complete nonsense, but it used to be pretty
418 * good at confusing and occasionally crashing qemu. */
419 PrdtEntry prdt
[4096] = { };
421 status
= send_dma_request(CMD_READ_DMA
| CMDF_NO_BM
, 0, 512,
422 prdt
, ARRAY_SIZE(prdt
), NULL
);
424 /* Not entirely clear what the expected result is, but this is what we get
425 * in practice. At least we want to be aware of any changes. */
426 g_assert_cmphex(status
, ==, BM_STS_ACTIVE
| BM_STS_INTR
);
427 assert_bit_clear(inb(IDE_BASE
+ reg_status
), DF
| ERR
);
430 static void test_bmdma_setup(void)
433 "-drive file=%s,if=ide,serial=%s,cache=writeback,format=raw "
434 "-global ide-hd.ver=%s",
435 tmp_path
, "testdisk", "version");
436 qtest_irq_intercept_in(global_qtest
, "ioapic");
439 static void test_bmdma_teardown(void)
444 static void string_cpu_to_be16(uint16_t *s
, size_t bytes
)
446 g_assert((bytes
& 1) == 0);
450 *s
= cpu_to_be16(*s
);
455 static void test_identify(void)
463 "-drive file=%s,if=ide,serial=%s,cache=writeback,format=raw "
464 "-global ide-hd.ver=%s",
465 tmp_path
, "testdisk", "version");
467 /* IDENTIFY command on device 0*/
468 outb(IDE_BASE
+ reg_device
, 0);
469 outb(IDE_BASE
+ reg_command
, CMD_IDENTIFY
);
471 /* Read in the IDENTIFY buffer and check registers */
472 data
= inb(IDE_BASE
+ reg_device
);
473 g_assert_cmpint(data
& DEV
, ==, 0);
475 for (i
= 0; i
< 256; i
++) {
476 data
= inb(IDE_BASE
+ reg_status
);
477 assert_bit_set(data
, DRDY
| DRQ
);
478 assert_bit_clear(data
, BSY
| DF
| ERR
);
480 ((uint16_t*) buf
)[i
] = inw(IDE_BASE
+ reg_data
);
483 data
= inb(IDE_BASE
+ reg_status
);
484 assert_bit_set(data
, DRDY
);
485 assert_bit_clear(data
, BSY
| DF
| ERR
| DRQ
);
487 /* Check serial number/version in the buffer */
488 string_cpu_to_be16(&buf
[10], 20);
489 ret
= memcmp(&buf
[10], "testdisk ", 20);
492 string_cpu_to_be16(&buf
[23], 8);
493 ret
= memcmp(&buf
[23], "version ", 8);
496 /* Write cache enabled bit */
497 assert_bit_set(buf
[85], 0x20);
502 static void test_flush(void)
507 "-drive file=blkdebug::%s,if=ide,cache=writeback,format=raw",
510 /* Delay the completion of the flush request until we explicitly do it */
511 g_free(hmp("qemu-io ide0-hd0 \"break flush_to_os A\""));
513 /* FLUSH CACHE command on device 0*/
514 outb(IDE_BASE
+ reg_device
, 0);
515 outb(IDE_BASE
+ reg_command
, CMD_FLUSH_CACHE
);
517 /* Check status while request is in flight*/
518 data
= inb(IDE_BASE
+ reg_status
);
519 assert_bit_set(data
, BSY
| DRDY
);
520 assert_bit_clear(data
, DF
| ERR
| DRQ
);
522 /* Complete the command */
523 g_free(hmp("qemu-io ide0-hd0 \"resume A\""));
525 /* Check registers */
526 data
= inb(IDE_BASE
+ reg_device
);
527 g_assert_cmpint(data
& DEV
, ==, 0);
530 data
= inb(IDE_BASE
+ reg_status
);
531 } while (data
& BSY
);
533 assert_bit_set(data
, DRDY
);
534 assert_bit_clear(data
, BSY
| DF
| ERR
| DRQ
);
539 static void test_retry_flush(const char *machine
)
544 prepare_blkdebug_script(debug_path
, "flush_to_disk");
548 "-drive file=blkdebug:%s:%s,if=ide,cache=writeback,format=raw,"
549 "rerror=stop,werror=stop",
550 debug_path
, tmp_path
);
552 /* FLUSH CACHE command on device 0*/
553 outb(IDE_BASE
+ reg_device
, 0);
554 outb(IDE_BASE
+ reg_command
, CMD_FLUSH_CACHE
);
556 /* Check status while request is in flight*/
557 data
= inb(IDE_BASE
+ reg_status
);
558 assert_bit_set(data
, BSY
| DRDY
);
559 assert_bit_clear(data
, DF
| ERR
| DRQ
);
561 qmp_eventwait("STOP");
563 /* Complete the command */
564 s
= "{'execute':'cont' }";
565 qmp_discard_response(s
);
567 /* Check registers */
568 data
= inb(IDE_BASE
+ reg_device
);
569 g_assert_cmpint(data
& DEV
, ==, 0);
572 data
= inb(IDE_BASE
+ reg_status
);
573 } while (data
& BSY
);
575 assert_bit_set(data
, DRDY
);
576 assert_bit_clear(data
, BSY
| DF
| ERR
| DRQ
);
581 static void test_flush_nodev(void)
585 /* FLUSH CACHE command on device 0*/
586 outb(IDE_BASE
+ reg_device
, 0);
587 outb(IDE_BASE
+ reg_command
, CMD_FLUSH_CACHE
);
589 /* Just testing that qemu doesn't crash... */
594 static void test_pci_retry_flush(void)
596 test_retry_flush("pc");
599 static void test_isa_retry_flush(void)
601 test_retry_flush("isapc");
604 typedef struct Read10CDB
{
612 } __attribute__((__packed__
)) Read10CDB
;
614 static void send_scsi_cdb_read10(uint64_t lba
, int nblocks
)
616 Read10CDB pkt
= { .padding
= 0 };
619 g_assert_cmpint(lba
, <=, UINT32_MAX
);
620 g_assert_cmpint(nblocks
, <=, UINT16_MAX
);
621 g_assert_cmpint(nblocks
, >=, 0);
623 /* Construct SCSI CDB packet */
625 pkt
.lba
= cpu_to_be32(lba
);
626 pkt
.nblocks
= cpu_to_be16(nblocks
);
629 for (i
= 0; i
< sizeof(Read10CDB
)/2; i
++) {
630 outw(IDE_BASE
+ reg_data
, cpu_to_le16(((uint16_t *)&pkt
)[i
]));
634 static void nsleep(int64_t nsecs
)
636 const struct timespec val
= { .tv_nsec
= nsecs
};
637 nanosleep(&val
, NULL
);
641 static uint8_t ide_wait_clear(uint8_t flag
)
646 /* Wait with a 5 second timeout */
649 data
= inb(IDE_BASE
+ reg_status
);
650 if (!(data
& flag
)) {
653 if (difftime(time(NULL
), st
) > 5.0) {
658 g_assert_not_reached();
661 static void ide_wait_intr(int irq
)
672 if (difftime(time(NULL
), st
) > 5.0) {
678 g_assert_not_reached();
681 static void cdrom_pio_impl(int nblocks
)
684 int patt_blocks
= MAX(16, nblocks
);
685 size_t patt_len
= ATAPI_BLOCK_SIZE
* patt_blocks
;
686 char *pattern
= g_malloc(patt_len
);
687 size_t rxsize
= ATAPI_BLOCK_SIZE
* nblocks
;
688 uint16_t *rx
= g_malloc0(rxsize
);
693 /* Prepopulate the CDROM with an interesting pattern */
694 generate_pattern(pattern
, patt_len
, ATAPI_BLOCK_SIZE
);
695 fh
= fopen(tmp_path
, "w+");
696 fwrite(pattern
, ATAPI_BLOCK_SIZE
, patt_blocks
, fh
);
699 ide_test_start("-drive if=none,file=%s,media=cdrom,format=raw,id=sr0,index=0 "
700 "-device ide-cd,drive=sr0,bus=ide.0", tmp_path
);
701 qtest_irq_intercept_in(global_qtest
, "ioapic");
703 /* PACKET command on device 0 */
704 outb(IDE_BASE
+ reg_device
, 0);
705 outb(IDE_BASE
+ reg_lba_middle
, BYTE_COUNT_LIMIT
& 0xFF);
706 outb(IDE_BASE
+ reg_lba_high
, (BYTE_COUNT_LIMIT
>> 8 & 0xFF));
707 outb(IDE_BASE
+ reg_command
, CMD_PACKET
);
708 /* HP0: Check_Status_A State */
710 data
= ide_wait_clear(BSY
);
711 /* HP1: Send_Packet State */
712 assert_bit_set(data
, DRQ
| DRDY
);
713 assert_bit_clear(data
, ERR
| DF
| BSY
);
715 /* SCSI CDB (READ10) -- read n*2048 bytes from block 0 */
716 send_scsi_cdb_read10(0, nblocks
);
718 /* Read data back: occurs in bursts of 'BYTE_COUNT_LIMIT' bytes.
719 * If BYTE_COUNT_LIMIT is odd, we transfer BYTE_COUNT_LIMIT - 1 bytes.
720 * We allow an odd limit only when the remaining transfer size is
721 * less than BYTE_COUNT_LIMIT. However, SCSI's read10 command can only
722 * request n blocks, so our request size is always even.
723 * For this reason, we assume there is never a hanging byte to fetch. */
724 g_assert(!(rxsize
& 1));
725 limit
= BYTE_COUNT_LIMIT
& ~1;
726 for (i
= 0; i
< DIV_ROUND_UP(rxsize
, limit
); i
++) {
727 size_t offset
= i
* (limit
/ 2);
728 size_t rem
= (rxsize
/ 2) - offset
;
730 /* HP3: INTRQ_Wait */
731 ide_wait_intr(IDE_PRIMARY_IRQ
);
733 /* HP2: Check_Status_B (and clear IRQ) */
734 data
= ide_wait_clear(BSY
);
735 assert_bit_set(data
, DRQ
| DRDY
);
736 assert_bit_clear(data
, ERR
| DF
| BSY
);
738 /* HP4: Transfer_Data */
739 for (j
= 0; j
< MIN((limit
/ 2), rem
); j
++) {
740 rx
[offset
+ j
] = le16_to_cpu(inw(IDE_BASE
+ reg_data
));
744 /* Check for final completion IRQ */
745 ide_wait_intr(IDE_PRIMARY_IRQ
);
747 /* Sanity check final state */
748 data
= ide_wait_clear(DRQ
);
749 assert_bit_set(data
, DRDY
);
750 assert_bit_clear(data
, DRQ
| ERR
| DF
| BSY
);
752 g_assert_cmpint(memcmp(pattern
, rx
, rxsize
), ==, 0);
755 test_bmdma_teardown();
758 static void test_cdrom_pio(void)
763 static void test_cdrom_pio_large(void)
765 /* Test a few loops of the PIO DRQ mechanism. */
766 cdrom_pio_impl(BYTE_COUNT_LIMIT
* 4 / ATAPI_BLOCK_SIZE
);
770 static void test_cdrom_dma(void)
772 static const size_t len
= ATAPI_BLOCK_SIZE
;
773 char *pattern
= g_malloc(ATAPI_BLOCK_SIZE
* 16);
774 char *rx
= g_malloc0(len
);
779 ide_test_start("-drive if=none,file=%s,media=cdrom,format=raw,id=sr0,index=0 "
780 "-device ide-cd,drive=sr0,bus=ide.0", tmp_path
);
781 qtest_irq_intercept_in(global_qtest
, "ioapic");
783 guest_buf
= guest_alloc(guest_malloc
, len
);
784 prdt
[0].addr
= cpu_to_le32(guest_buf
);
785 prdt
[0].size
= cpu_to_le32(len
| PRDT_EOT
);
787 generate_pattern(pattern
, ATAPI_BLOCK_SIZE
* 16, ATAPI_BLOCK_SIZE
);
788 fh
= fopen(tmp_path
, "w+");
789 fwrite(pattern
, ATAPI_BLOCK_SIZE
, 16, fh
);
792 send_dma_request(CMD_PACKET
, 0, 1, prdt
, 1, send_scsi_cdb_read10
);
794 /* Read back data from guest memory into local qtest memory */
795 memread(guest_buf
, rx
, len
);
796 g_assert_cmpint(memcmp(pattern
, rx
, len
), ==, 0);
800 test_bmdma_teardown();
803 int main(int argc
, char **argv
)
805 const char *arch
= qtest_get_arch();
809 /* Check architecture */
810 if (strcmp(arch
, "i386") && strcmp(arch
, "x86_64")) {
811 g_test_message("Skipping test for non-x86\n");
815 /* Create temporary blkdebug instructions */
816 fd
= mkstemp(debug_path
);
820 /* Create a temporary raw image */
821 fd
= mkstemp(tmp_path
);
823 ret
= ftruncate(fd
, TEST_IMAGE_SIZE
);
828 g_test_init(&argc
, &argv
, NULL
);
830 qtest_add_func("/ide/identify", test_identify
);
832 qtest_add_func("/ide/bmdma/setup", test_bmdma_setup
);
833 qtest_add_func("/ide/bmdma/simple_rw", test_bmdma_simple_rw
);
834 qtest_add_func("/ide/bmdma/short_prdt", test_bmdma_short_prdt
);
835 qtest_add_func("/ide/bmdma/one_sector_short_prdt",
836 test_bmdma_one_sector_short_prdt
);
837 qtest_add_func("/ide/bmdma/long_prdt", test_bmdma_long_prdt
);
838 qtest_add_func("/ide/bmdma/no_busmaster", test_bmdma_no_busmaster
);
839 qtest_add_func("/ide/bmdma/teardown", test_bmdma_teardown
);
841 qtest_add_func("/ide/flush", test_flush
);
842 qtest_add_func("/ide/flush/nodev", test_flush_nodev
);
843 qtest_add_func("/ide/flush/retry_pci", test_pci_retry_flush
);
844 qtest_add_func("/ide/flush/retry_isa", test_isa_retry_flush
);
846 qtest_add_func("/ide/cdrom/pio", test_cdrom_pio
);
847 qtest_add_func("/ide/cdrom/pio_large", test_cdrom_pio_large
);
848 qtest_add_func("/ide/cdrom/dma", test_cdrom_dma
);