tests: add pxe e1000 and virtio-pci tests
The test is based on bios-tables-test.c. It creates a file with the boot sector image and loads it into a guest using PXE and TFTP functionality. Cc: Jason Wang <jasowang@redhat.com> Signed-off-by: Victor Kaplansky <victork@redhat.com> Suggested-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
		
							parent
							
								
									e1e4bf2252
								
							
						
					
					
						commit
						4e082566a9
					
				@ -173,6 +173,7 @@ check-qtest-i386-y += tests/hd-geo-test$(EXESUF)
 | 
				
			|||||||
gcov-files-i386-y += hw/block/hd-geometry.c
 | 
					gcov-files-i386-y += hw/block/hd-geometry.c
 | 
				
			||||||
check-qtest-i386-y += tests/boot-order-test$(EXESUF)
 | 
					check-qtest-i386-y += tests/boot-order-test$(EXESUF)
 | 
				
			||||||
check-qtest-i386-y += tests/bios-tables-test$(EXESUF)
 | 
					check-qtest-i386-y += tests/bios-tables-test$(EXESUF)
 | 
				
			||||||
 | 
					check-qtest-i386-y += tests/pxe-test$(EXESUF)
 | 
				
			||||||
check-qtest-i386-y += tests/rtc-test$(EXESUF)
 | 
					check-qtest-i386-y += tests/rtc-test$(EXESUF)
 | 
				
			||||||
check-qtest-i386-y += tests/ipmi-kcs-test$(EXESUF)
 | 
					check-qtest-i386-y += tests/ipmi-kcs-test$(EXESUF)
 | 
				
			||||||
check-qtest-i386-y += tests/ipmi-bt-test$(EXESUF)
 | 
					check-qtest-i386-y += tests/ipmi-bt-test$(EXESUF)
 | 
				
			||||||
@ -518,7 +519,9 @@ tests/ipmi-kcs-test$(EXESUF): tests/ipmi-kcs-test.o
 | 
				
			|||||||
tests/ipmi-bt-test$(EXESUF): tests/ipmi-bt-test.o
 | 
					tests/ipmi-bt-test$(EXESUF): tests/ipmi-bt-test.o
 | 
				
			||||||
tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 | 
					tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 | 
				
			||||||
tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
 | 
					tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
 | 
				
			||||||
tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o $(libqos-obj-y)
 | 
					tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
 | 
				
			||||||
 | 
						tests/boot-sector.o $(libqos-obj-y)
 | 
				
			||||||
 | 
					tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y)
 | 
				
			||||||
tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
 | 
					tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
 | 
				
			||||||
tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
 | 
					tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
 | 
				
			||||||
tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
 | 
					tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,7 @@
 | 
				
			|||||||
#include "hw/acpi/acpi-defs.h"
 | 
					#include "hw/acpi/acpi-defs.h"
 | 
				
			||||||
#include "hw/smbios/smbios.h"
 | 
					#include "hw/smbios/smbios.h"
 | 
				
			||||||
#include "qemu/bitmap.h"
 | 
					#include "qemu/bitmap.h"
 | 
				
			||||||
 | 
					#include "boot-sector.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MACHINE_PC "pc"
 | 
					#define MACHINE_PC "pc"
 | 
				
			||||||
#define MACHINE_Q35 "q35"
 | 
					#define MACHINE_Q35 "q35"
 | 
				
			||||||
@ -53,13 +54,6 @@ typedef struct {
 | 
				
			|||||||
    struct smbios_21_entry_point smbios_ep_table;
 | 
					    struct smbios_21_entry_point smbios_ep_table;
 | 
				
			||||||
} test_data;
 | 
					} test_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define LOW(x) ((x) & 0xff)
 | 
					 | 
				
			||||||
#define HIGH(x) ((x) >> 8)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define SIGNATURE 0xdead
 | 
					 | 
				
			||||||
#define SIGNATURE_OFFSET 0x10
 | 
					 | 
				
			||||||
#define BOOT_SECTOR_ADDRESS 0x7c00
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ACPI_READ_FIELD(field, addr)           \
 | 
					#define ACPI_READ_FIELD(field, addr)           \
 | 
				
			||||||
    do {                                       \
 | 
					    do {                                       \
 | 
				
			||||||
        switch (sizeof(field)) {               \
 | 
					        switch (sizeof(field)) {               \
 | 
				
			||||||
@ -119,35 +113,6 @@ typedef struct {
 | 
				
			|||||||
    g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
 | 
					    g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
 | 
				
			||||||
} while (0)
 | 
					} while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Boot sector code: write SIGNATURE into memory,
 | 
					 | 
				
			||||||
 * then halt.
 | 
					 | 
				
			||||||
 * Q35 machine requires a minimum 0x7e000 bytes disk.
 | 
					 | 
				
			||||||
 * (bug or feature?)
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static uint8_t boot_sector[0x7e000] = {
 | 
					 | 
				
			||||||
    /* 7c00: mov $0xdead,%ax */
 | 
					 | 
				
			||||||
    [0x00] = 0xb8,
 | 
					 | 
				
			||||||
    [0x01] = LOW(SIGNATURE),
 | 
					 | 
				
			||||||
    [0x02] = HIGH(SIGNATURE),
 | 
					 | 
				
			||||||
    /* 7c03:  mov %ax,0x7c10 */
 | 
					 | 
				
			||||||
    [0x03] = 0xa3,
 | 
					 | 
				
			||||||
    [0x04] = LOW(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
 | 
					 | 
				
			||||||
    [0x05] = HIGH(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
 | 
					 | 
				
			||||||
    /* 7c06: cli */
 | 
					 | 
				
			||||||
    [0x06] = 0xfa,
 | 
					 | 
				
			||||||
    /* 7c07: hlt */
 | 
					 | 
				
			||||||
    [0x07] = 0xf4,
 | 
					 | 
				
			||||||
    /* 7c08: jmp 0x7c07=0x7c0a-3 */
 | 
					 | 
				
			||||||
    [0x08] = 0xeb,
 | 
					 | 
				
			||||||
    [0x09] = LOW(-3),
 | 
					 | 
				
			||||||
    /* We mov 0xdead here: set value to make debugging easier */
 | 
					 | 
				
			||||||
    [SIGNATURE_OFFSET] = LOW(0xface),
 | 
					 | 
				
			||||||
    [SIGNATURE_OFFSET + 1] = HIGH(0xface),
 | 
					 | 
				
			||||||
    /* End of boot sector marker */
 | 
					 | 
				
			||||||
    [0x1FE] = 0x55,
 | 
					 | 
				
			||||||
    [0x1FF] = 0xAA,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const char *disk = "tests/acpi-test-disk.raw";
 | 
					static const char *disk = "tests/acpi-test-disk.raw";
 | 
				
			||||||
static const char *data_dir = "tests/acpi-test-data";
 | 
					static const char *data_dir = "tests/acpi-test-data";
 | 
				
			||||||
#ifdef CONFIG_IASL
 | 
					#ifdef CONFIG_IASL
 | 
				
			||||||
@ -739,10 +704,6 @@ static void test_smbios_structs(test_data *data)
 | 
				
			|||||||
static void test_acpi_one(const char *params, test_data *data)
 | 
					static void test_acpi_one(const char *params, test_data *data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    char *args;
 | 
					    char *args;
 | 
				
			||||||
    uint8_t signature_low;
 | 
					 | 
				
			||||||
    uint8_t signature_high;
 | 
					 | 
				
			||||||
    uint16_t signature;
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    args = g_strdup_printf("-net none -display none %s "
 | 
					    args = g_strdup_printf("-net none -display none %s "
 | 
				
			||||||
                           "-drive id=hd0,if=none,file=%s,format=raw "
 | 
					                           "-drive id=hd0,if=none,file=%s,format=raw "
 | 
				
			||||||
@ -751,24 +712,7 @@ static void test_acpi_one(const char *params, test_data *data)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    qtest_start(args);
 | 
					    qtest_start(args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* Wait at most 1 minute */
 | 
					    boot_sector_test();
 | 
				
			||||||
#define TEST_DELAY (1 * G_USEC_PER_SEC / 10)
 | 
					 | 
				
			||||||
#define TEST_CYCLES MAX((60 * G_USEC_PER_SEC / TEST_DELAY), 1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Poll until code has run and modified memory.  Once it has we know BIOS
 | 
					 | 
				
			||||||
     * initialization is done.  TODO: check that IP reached the halt
 | 
					 | 
				
			||||||
     * instruction.
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    for (i = 0; i < TEST_CYCLES; ++i) {
 | 
					 | 
				
			||||||
        signature_low = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET);
 | 
					 | 
				
			||||||
        signature_high = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
 | 
					 | 
				
			||||||
        signature = (signature_high << 8) | signature_low;
 | 
					 | 
				
			||||||
        if (signature == SIGNATURE) {
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        g_usleep(TEST_DELAY);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    g_assert_cmphex(signature, ==, SIGNATURE);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    test_acpi_rsdp_address(data);
 | 
					    test_acpi_rsdp_address(data);
 | 
				
			||||||
    test_acpi_rsdp_table(data);
 | 
					    test_acpi_rsdp_table(data);
 | 
				
			||||||
@ -842,15 +786,11 @@ static void test_acpi_q35_tcg_bridge(void)
 | 
				
			|||||||
int main(int argc, char *argv[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    const char *arch = qtest_get_arch();
 | 
					    const char *arch = qtest_get_arch();
 | 
				
			||||||
    FILE *f = fopen(disk, "w");
 | 
					 | 
				
			||||||
    int ret;
 | 
					    int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!f) {
 | 
					    ret = boot_sector_init(disk);
 | 
				
			||||||
        fprintf(stderr, "Couldn't open \"%s\": %s", disk, strerror(errno));
 | 
					    if(ret)
 | 
				
			||||||
        return 1;
 | 
					        return ret;
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    fwrite(boot_sector, 1, sizeof boot_sector, f);
 | 
					 | 
				
			||||||
    fclose(f);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_test_init(&argc, &argv, NULL);
 | 
					    g_test_init(&argc, &argv, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -861,6 +801,6 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
        qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge);
 | 
					        qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    ret = g_test_run();
 | 
					    ret = g_test_run();
 | 
				
			||||||
    unlink(disk);
 | 
					    boot_sector_cleanup(disk);
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										119
									
								
								tests/boot-sector.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								tests/boot-sector.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,119 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * QEMU boot sector testing helpers.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (c) 2016 Red Hat Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Authors:
 | 
				
			||||||
 | 
					 *  Michael S. Tsirkin <mst@redhat.com>
 | 
				
			||||||
 | 
					 *  Victor Kaplansky <victork@redhat.com>    
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 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 "boot-sector.h"
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include "qemu-common.h"
 | 
				
			||||||
 | 
					#include "libqtest.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOW(x) ((x) & 0xff)
 | 
				
			||||||
 | 
					#define HIGH(x) ((x) >> 8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define SIGNATURE 0xdead
 | 
				
			||||||
 | 
					#define SIGNATURE_OFFSET 0x10
 | 
				
			||||||
 | 
					#define BOOT_SECTOR_ADDRESS 0x7c00
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Boot sector code: write SIGNATURE into memory,
 | 
				
			||||||
 | 
					 * then halt.
 | 
				
			||||||
 | 
					 * Q35 machine requires a minimum 0x7e000 bytes disk.
 | 
				
			||||||
 | 
					 * (bug or feature?)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static uint8_t boot_sector[0x7e000] = {
 | 
				
			||||||
 | 
					    /* The first sector will be placed at RAM address 00007C00, and
 | 
				
			||||||
 | 
					     * the BIOS transfers control to 00007C00
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Data Segment register should be initialized, since pxe
 | 
				
			||||||
 | 
					     * boot loader can leave it dirty.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* 7c00: move $0000,%ax */
 | 
				
			||||||
 | 
					    [0x00] = 0xb8,
 | 
				
			||||||
 | 
					    [0x01] = 0x00,
 | 
				
			||||||
 | 
					    [0x02] = 0x00,
 | 
				
			||||||
 | 
					    /* 7c03: move %ax,%ds */
 | 
				
			||||||
 | 
					    [0x03] = 0x8e,
 | 
				
			||||||
 | 
					    [0x04] = 0xd8,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* 7c05: mov $0xdead,%ax */
 | 
				
			||||||
 | 
					    [0x05] = 0xb8,
 | 
				
			||||||
 | 
					    [0x06] = LOW(SIGNATURE),
 | 
				
			||||||
 | 
					    [0x07] = HIGH(SIGNATURE),
 | 
				
			||||||
 | 
					    /* 7c08:  mov %ax,0x7c10 */
 | 
				
			||||||
 | 
					    [0x08] = 0xa3,
 | 
				
			||||||
 | 
					    [0x09] = LOW(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
 | 
				
			||||||
 | 
					    [0x0a] = HIGH(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* 7c0b cli */
 | 
				
			||||||
 | 
					    [0x0b] = 0xfa,
 | 
				
			||||||
 | 
					    /* 7c0c: hlt */
 | 
				
			||||||
 | 
					    [0x0c] = 0xf4,
 | 
				
			||||||
 | 
					    /* 7c0e: jmp 0x7c07=0x7c0f-3 */
 | 
				
			||||||
 | 
					    [0x0d] = 0xeb,
 | 
				
			||||||
 | 
					    [0x0e] = LOW(-3),
 | 
				
			||||||
 | 
					    /* We mov 0xdead here: set value to make debugging easier */
 | 
				
			||||||
 | 
					    [SIGNATURE_OFFSET] = LOW(0xface),
 | 
				
			||||||
 | 
					    [SIGNATURE_OFFSET + 1] = HIGH(0xface),
 | 
				
			||||||
 | 
					    /* End of boot sector marker */
 | 
				
			||||||
 | 
					    [0x1FE] = 0x55,
 | 
				
			||||||
 | 
					    [0x1FF] = 0xAA,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Create boot disk file.  */
 | 
				
			||||||
 | 
					int boot_sector_init(const char *fname)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    FILE *f = fopen(fname, "w");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!f) {
 | 
				
			||||||
 | 
					        fprintf(stderr, "Couldn't open \"%s\": %s", fname, strerror(errno));
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    fwrite(boot_sector, 1, sizeof boot_sector, f);
 | 
				
			||||||
 | 
					    fclose(f);
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Loop until signature in memory is OK.  */
 | 
				
			||||||
 | 
					void boot_sector_test(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uint8_t signature_low;
 | 
				
			||||||
 | 
					    uint8_t signature_high;
 | 
				
			||||||
 | 
					    uint16_t signature;
 | 
				
			||||||
 | 
					    int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   /* Wait at most 1 minute */
 | 
				
			||||||
 | 
					#define TEST_DELAY (1 * G_USEC_PER_SEC / 10)
 | 
				
			||||||
 | 
					#define TEST_CYCLES MAX((60 * G_USEC_PER_SEC / TEST_DELAY), 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Poll until code has run and modified memory.  Once it has we know BIOS
 | 
				
			||||||
 | 
					     * initialization is done.  TODO: check that IP reached the halt
 | 
				
			||||||
 | 
					     * instruction.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    for (i = 0; i < TEST_CYCLES; ++i) {
 | 
				
			||||||
 | 
					        signature_low = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET);
 | 
				
			||||||
 | 
					        signature_high = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
 | 
				
			||||||
 | 
					        signature = (signature_high << 8) | signature_low;
 | 
				
			||||||
 | 
					        if (signature == SIGNATURE) {
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        g_usleep(TEST_DELAY);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    g_assert_cmphex(signature, ==, SIGNATURE);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* unlink boot disk file.  */
 | 
				
			||||||
 | 
					void boot_sector_cleanup(const char *fname)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unlink(fname);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										26
									
								
								tests/boot-sector.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								tests/boot-sector.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * QEMU boot sector testing helpers.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (c) 2016 Red Hat Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Authors:
 | 
				
			||||||
 | 
					 *  Michael S. Tsirkin <mst@redhat.com>
 | 
				
			||||||
 | 
					 *  Victor Kaplansky <victork@redhat.com>    
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 | 
				
			||||||
 | 
					 * See the COPYING file in the top-level directory.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef TEST_BOOT_SECTOR
 | 
				
			||||||
 | 
					#define TEST_BOOT_SECTOR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Create boot disk file.  */
 | 
				
			||||||
 | 
					int boot_sector_init(const char *fname);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Loop until signature in memory is OK.  */
 | 
				
			||||||
 | 
					void boot_sector_test(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* unlink boot disk file.  */
 | 
				
			||||||
 | 
					void boot_sector_cleanup(const char *fname);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* TEST_BOOT_SECTOR */
 | 
				
			||||||
							
								
								
									
										69
									
								
								tests/pxe-test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								tests/pxe-test.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * PXE test cases.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (c) 2016 Red Hat Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Authors:
 | 
				
			||||||
 | 
					 *  Michael S. Tsirkin <mst@redhat.com>,
 | 
				
			||||||
 | 
					 *  Victor Kaplansky <victork@redhat.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 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 <string.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <glib.h>
 | 
				
			||||||
 | 
					#include <glib/gstdio.h>
 | 
				
			||||||
 | 
					#include "qemu-common.h"
 | 
				
			||||||
 | 
					#include "libqtest.h"
 | 
				
			||||||
 | 
					#include "boot-sector.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define NETNAME "net0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char *disk = "tests/pxe-test-disk.raw";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_pxe_one(const char *params)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char *args;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    args = g_strdup_printf("-machine accel=tcg "
 | 
				
			||||||
 | 
					                           "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s "
 | 
				
			||||||
 | 
					                           "%s ",
 | 
				
			||||||
 | 
					                           disk, params);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    qtest_start(args);
 | 
				
			||||||
 | 
					    boot_sector_test();
 | 
				
			||||||
 | 
					    qtest_quit(global_qtest);
 | 
				
			||||||
 | 
					    g_free(args);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_pxe_e1000(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    test_pxe_one("-device e1000,netdev=" NETNAME);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_pxe_virtio_pci(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    test_pxe_one("-device virtio-net-pci,netdev=" NETNAME);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int ret;
 | 
				
			||||||
 | 
					    const char *arch = qtest_get_arch();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = boot_sector_init(disk);
 | 
				
			||||||
 | 
					    if(ret)
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    g_test_init(&argc, &argv, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
 | 
				
			||||||
 | 
					        qtest_add_func("pxe/e1000", test_pxe_e1000);
 | 
				
			||||||
 | 
					        qtest_add_func("pxe/virtio", test_pxe_virtio_pci);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ret = g_test_run();
 | 
				
			||||||
 | 
					    boot_sector_cleanup(disk);
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user