예제 #1
0
static void test_a_boot_order(const char *machine,
                              const char *test_args,
                              uint64_t (*read_boot_order)(void),
                              uint64_t expected_boot,
                              uint64_t expected_reboot)
{
    char *args;
    uint64_t actual;

    args = g_strdup_printf("-nodefaults -display none%s%s %s",
                           machine ? " -M " : "",
                           machine ?: "",
                           test_args);
    qtest_start(args);
    actual = read_boot_order();
    g_assert_cmphex(actual, ==, expected_boot);
    qmp_discard_response("{ 'execute': 'system_reset' }");
    /*
     * system_reset only requests reset.  We get a RESET event after
     * the actual reset completes.  Need to wait for that.
     */
    qmp_discard_response("");   /* HACK: wait for event */
    actual = read_boot_order();
    g_assert_cmphex(actual, ==, expected_reboot);
    qtest_quit(global_qtest);
    g_free(args);
}
예제 #2
0
int main(int argc, char **argv)
{
    const char *arch = qtest_get_arch();
    char *cmdline;
    int ret;

    /* Check architecture */
    if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
        g_test_message("Skipping test for non-x86\n");
        return 0;
    }

    open_socket();

    /* Run the tests */
    g_test_init(&argc, &argv, NULL);

    cmdline = g_strdup_printf(
          " -chardev socket,id=ipmi0,host=localhost,port=%d,reconnect=10"
          " -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0"
          " -device isa-ipmi-bt,bmc=bmc0", emu_port);
    qtest_start(cmdline);
    qtest_irq_intercept_in(global_qtest, "ioapic");
    qtest_add_func("/ipmi/extern/connect", test_connect);
    qtest_add_func("/ipmi/extern/bt_base", test_bt_base);
    qtest_add_func("/ipmi/extern/bt_enable_irq", test_enable_irq);
    qtest_add_func("/ipmi/extern/bt_base_irq", test_bt_base);
    ret = g_test_run();
    qtest_quit(global_qtest);

    return ret;
}
예제 #3
0
static void test_plug_with_device_add_x86(gconstpointer data)
{
    const PlugTestData *td = data;
    char *args;
    unsigned int s, c, t;

    args = g_strdup_printf("-machine %s -cpu %s "
                           "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
                           td->machine, td->cpu_model,
                           td->sockets, td->cores, td->threads, td->maxcpus);
    qtest_start(args);

    for (s = 1; s < td->sockets; s++) {
        for (c = 0; c < td->cores; c++) {
            for (t = 0; t < td->threads; t++) {
                char *id = g_strdup_printf("id-%i-%i-%i", s, c, t);
                qtest_qmp_device_add(td->device_model, id,
                                     "{'socket-id':%u, 'core-id':%u,"
                                     " 'thread-id':%u}",
                                     s, c, t);
                g_free(id);
            }
        }
    }

    qtest_end();
    g_free(args);
}
예제 #4
0
int main(int argc, char **argv)
{
    int ret;
    char *args;
    const char *devstr = "e1000";

    if (g_str_equal(qtest_get_arch(), "s390x")) {
        devstr = "virtio-net-ccw";
    }

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/netfilter/addremove_one", add_one_netfilter);
    qtest_add_func("/netfilter/remove_netdev_one",
                   remove_netdev_with_one_netfilter);
    qtest_add_func("/netfilter/addremove_multi", add_multi_netfilter);
    qtest_add_func("/netfilter/remove_netdev_multi",
                   remove_netdev_with_multi_netfilter);

    args = g_strdup_printf("-netdev user,id=qtest-bn0 "
                           "-device %s,netdev=qtest-bn0", devstr);
    qtest_start(args);
    ret = g_test_run();

    qtest_end();
    g_free(args);

    return ret;
}
예제 #5
0
static void test_drive_add_empty(void)
{
    QDict *response;
    const char *response_return;

    /* Start with an empty drive */
    qtest_start("-drive if=none,id=drive0");

    /* Delete the drive */
    response = qmp("{\"execute\": \"human-monitor-command\","
                   " \"arguments\": {"
                   "   \"command-line\": \"drive_del drive0\""
                   "}}");
    g_assert(response);
    response_return = qdict_get_try_str(response, "return");
    g_assert(response_return);
    g_assert(strcmp(response_return, "") == 0);
    QDECREF(response);

    /* Ensure re-adding the drive works - there should be no duplicate ID error
     * because the old drive must be gone.
     */
    response = qmp("{\"execute\": \"human-monitor-command\","
                   " \"arguments\": {"
                   "   \"command-line\": \"drive_add 0 if=none,id=drive0\""
                   "}}");
    g_assert(response);
    response_return = qdict_get_try_str(response, "return");
    g_assert(response_return);
    g_assert(strcmp(response_return, "OK\r\n") == 0);
    QDECREF(response);

    qtest_end();
}
예제 #6
0
static void test_read_guest_mem(const void *arg)
{
    enum test_memfd memfd = GPOINTER_TO_INT(arg);
    TestServer *server = NULL;
    char *qemu_cmd = NULL;
    QTestState *s = NULL;

    server = test_server_new(memfd == TEST_MEMFD_YES ?
                             "read-guest-memfd" : "read-guest-mem");
    test_server_listen(server);

    qemu_cmd = get_qemu_cmd(server, 512, memfd, root, "", "");

    s = qtest_start(qemu_cmd);
    g_free(qemu_cmd);

    init_virtio_dev(global_qtest, server, 1u << VIRTIO_NET_F_MAC);

    if (!wait_for_fds(server)) {
        goto exit;
    }

    read_guest_mem_server(global_qtest, server);

exit:
    uninit_virtio_dev(server);

    qtest_quit(s);
    test_server_free(server);
}
예제 #7
0
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/ehci/pci/init", pci_init);
    qtest_add_func("/ehci/pci/uhci-port-1", pci_uhci_port_1);
    qtest_add_func("/ehci/pci/ehci-port-1", pci_ehci_port_1);
    qtest_add_func("/ehci/pci/ehci-config", pci_ehci_config);
    qtest_add_func("/ehci/pci/uhci-port-2", pci_uhci_port_2);
    qtest_add_func("/ehci/pci/ehci-port-2", pci_ehci_port_2);
    qtest_add_func("/ehci/pci/ehci-port-3-hotplug", pci_ehci_port_hotplug);

    qtest_start("-machine q35 -device ich9-usb-ehci1,bus=pcie.0,addr=1d.7,"
                "multifunction=on,id=ich9-ehci-1 "
                "-device ich9-usb-uhci1,bus=pcie.0,addr=1d.0,"
                "multifunction=on,masterbus=ich9-ehci-1.0,firstport=0 "
                "-device ich9-usb-uhci2,bus=pcie.0,addr=1d.1,"
                "multifunction=on,masterbus=ich9-ehci-1.0,firstport=2 "
                "-device ich9-usb-uhci3,bus=pcie.0,addr=1d.2,"
                "multifunction=on,masterbus=ich9-ehci-1.0,firstport=4 "
                "-drive if=none,id=usbcdrom,media=cdrom "
                "-device usb-tablet,bus=ich9-ehci-1.0,port=1,usb_version=1 "
                "-device usb-storage,bus=ich9-ehci-1.0,port=2,drive=usbcdrom ");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #8
0
static void add_pc_test_cases(void)
{
    QDict *response, *minfo;
    QList *list;
    const QListEntry *p;
    QObject *qobj;
    QString *qstr;
    const char *mname, *path;
    PCTestData *data;

    qtest_start("-machine none");
    response = qmp("{ 'execute': 'query-machines' }");
    g_assert(response);
    list = qdict_get_qlist(response, "return");
    g_assert(list);

    for (p = qlist_first(list); p; p = qlist_next(p)) {
        minfo = qobject_to_qdict(qlist_entry_obj(p));
        g_assert(minfo);
        qobj = qdict_get(minfo, "name");
        g_assert(qobj);
        qstr = qobject_to_qstring(qobj);
        g_assert(qstr);
        mname = qstring_get_str(qstr);
        if (!g_str_has_prefix(mname, "pc-")) {
            continue;
        }
        data = g_malloc(sizeof(PCTestData));
        data->machine = mname;
        data->cpu_model = "Haswell"; /* 1.3+ theoretically */
        data->sockets = 1;
        data->cores = 3;
        data->threads = 2;
        data->maxcpus = data->sockets * data->cores * data->threads * 2;
        if (g_str_has_suffix(mname, "-1.4") ||
            (strcmp(mname, "pc-1.3") == 0) ||
            (strcmp(mname, "pc-1.2") == 0) ||
            (strcmp(mname, "pc-1.1") == 0) ||
            (strcmp(mname, "pc-1.0") == 0) ||
            (strcmp(mname, "pc-0.15") == 0) ||
            (strcmp(mname, "pc-0.14") == 0) ||
            (strcmp(mname, "pc-0.13") == 0) ||
            (strcmp(mname, "pc-0.12") == 0) ||
            (strcmp(mname, "pc-0.11") == 0) ||
            (strcmp(mname, "pc-0.10") == 0)) {
            path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
                                   mname, data->sockets, data->cores,
                                   data->threads, data->maxcpus);
            qtest_add_data_func(path, data, test_pc_without_cpu_add);
        } else {
            path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
                                   mname, data->sockets, data->cores,
                                   data->threads, data->maxcpus);
            qtest_add_data_func(path, data, test_pc_with_cpu_add);
        }
    }
    qtest_end();
}
예제 #9
0
static QPCIBus *pci_test_start(int socket)
{
    char *cmdline;

    cmdline = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
                              "virtio-net-pci,netdev=hs0", socket);
    qtest_start(cmdline);
    g_free(cmdline);

    return qpci_init_pc();
}
예제 #10
0
static void test_deprecated(void)
{
    QTestState *from;

    from = qtest_start("");

    deprecated_set_downtime(from, 0.12345);
    deprecated_set_speed(from, "12345");

    qtest_quit(from);
}
예제 #11
0
int main(int argc, char **argv)
{
    QTestState *s = NULL;
    CharDriverState *chr = NULL;
    const char *hugefs = 0;
    char *socket_path = 0;
    char *qemu_cmd = 0;
    char *chr_path = 0;
    int ret;

    g_test_init(&argc, &argv, NULL);

    module_call_init(MODULE_INIT_QOM);

    hugefs = init_hugepagefs();
    if (!hugefs) {
        return 0;
    }

    socket_path = g_strdup_printf("/tmp/vhost-%d.sock", getpid());

    /* create char dev and add read handlers */
    qemu_add_opts(&qemu_chardev_opts);
    chr_path = g_strdup_printf("unix:%s,server,nowait", socket_path);
    chr = qemu_chr_new("chr0", chr_path, NULL);
    g_free(chr_path);
    qemu_chr_add_handlers(chr, chr_can_read, chr_read, NULL, chr);

    /* run the main loop thread so the chardev may operate */
    data_mutex = _mutex_new();
    data_cond = _cond_new();
    _thread_new(NULL, thread_function, NULL);

    qemu_cmd = g_strdup_printf(QEMU_CMD, hugefs, socket_path);
    s = qtest_start(qemu_cmd);
    g_free(qemu_cmd);

    qtest_add_func("/vhost-user/read-guest-mem", read_guest_mem);

    ret = g_test_run();

    if (s) {
        qtest_quit(s);
    }

    /* cleanup */
    unlink(socket_path);
    g_free(socket_path);
    _cond_free(data_cond);
    _mutex_free(data_mutex);

    return ret;
}
예제 #12
0
static void test_machine(const void *machine)
{
    char *args;

    args = g_strdup_printf("-M %s,accel=tcg -prom-env 'boot-command=%x %x l!'",
                           (const char *)machine, MAGIC, ADDRESS);

    qtest_start(args);
    check_guest_memory();
    qtest_quit(global_qtest);

    g_free(args);
}
예제 #13
0
static void test_nop(gconstpointer data)
{
    QTestState *s;
    const char *machine = data;
    char *args;

    args = g_strdup_printf("-machine %s", machine);
    s = qtest_start(args);
    if (s) {
        qtest_quit(s);
    }
    g_free(args);
}
예제 #14
0
static void ide_test_start(const char *cmdline_fmt, ...)
{
    va_list ap;
    char *cmdline;

    va_start(ap, cmdline_fmt);
    cmdline = g_strdup_vprintf(cmdline_fmt, ap);
    va_end(ap);

    qtest_start(cmdline);
    qtest_irq_intercept_in(global_qtest, "ioapic");
    guest_malloc = pc_alloc_init();
}
예제 #15
0
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/pvpanic/panic", test_panic);

    qtest_start("-device pvpanic");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #16
0
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/ne2000/pci/nop", pci_nop);

    qtest_start("-device ne2k_pci");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #17
0
파일: ide-test.c 프로젝트: novokrest/QemuRK
static void ide_test_start(const char *cmdline_fmt, ...)
{
    va_list ap;
    char *cmdline;

    va_start(ap, cmdline_fmt);
    cmdline = g_strdup_vprintf(cmdline_fmt, ap);
    va_end(ap);

    qtest_start(cmdline);
    guest_malloc = pc_alloc_init();

    g_free(cmdline);
}
예제 #18
0
파일: ipoctal232-test.c 프로젝트: 8tab/qemu
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/ipoctal232/tpci200/nop", nop);

    qtest_start("-device tpci200,id=ipack0 -device ipoctal232,bus=ipack0.0");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #19
0
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/rtl8139/nop", nop);

    qtest_start("-device rtl8139");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #20
0
파일: pxe-test.c 프로젝트: 01org/qemu-lite
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);
}
예제 #21
0
파일: e1000-test.c 프로젝트: 8tab/qemu
/* Tests only initialization so far. TODO: Replace with functional tests */
static void test_device(gconstpointer data)
{
    const char *model = data;
    QTestState *s;
    char *args;

    args = g_strdup_printf("-device %s", model);
    s = qtest_start(args);

    if (s) {
        qtest_quit(s);
    }
    g_free(args);
}
예제 #22
0
int main(int argc, char **argv)
{
    const char *arch = qtest_get_arch();
    char *cmdline;
    int fd;
    int ret;

    /* Check architecture */
    if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
        g_test_message("Skipping test for non-x86\n");
        return 0;
    }

    /* Create a temporary raw image */
    fd = mkstemp(test_image);
    g_assert(fd >= 0);
    ret = ftruncate(fd, TEST_IMAGE_SIZE);
    g_assert(ret == 0);
    close(fd);

    /* Run the tests */
    g_test_init(&argc, &argv, NULL);

    cmdline = g_strdup_printf("-vnc none ");

    qtest_start(cmdline);
    qtest_irq_intercept_in(global_qtest, "ioapic");
    qtest_add_func("/fdc/cmos", test_cmos);
    qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
    qtest_add_func("/fdc/read_without_media", test_read_without_media);
    qtest_add_func("/fdc/media_change", test_media_change);
    qtest_add_func("/fdc/sense_interrupt", test_sense_interrupt);
    qtest_add_func("/fdc/relative_seek", test_relative_seek);
    qtest_add_func("/fdc/read_id", test_read_id);
    qtest_add_func("/fdc/verify", test_verify);
    qtest_add_func("/fdc/media_insert", test_media_insert);
    qtest_add_func("/fdc/read_no_dma_1", test_read_no_dma_1);
    qtest_add_func("/fdc/read_no_dma_18", test_read_no_dma_18);
    qtest_add_func("/fdc/read_no_dma_19", test_read_no_dma_19);
    qtest_add_func("/fdc/fuzz-registers", fuzz_registers);

    ret = g_test_run();

    /* Cleanup */
    qtest_end();
    unlink(test_image);

    return ret;
}
예제 #23
0
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);

    qtest_add_func("/ohci/pci/init", test_ohci_init);
    qtest_add_func("/ohci/pci/hotplug", test_ohci_hotplug);

    qtest_start("-device pci-ohci,id=ohci");
    ret = g_test_run();
    qtest_end();

    return ret;
}
예제 #24
0
파일: nvme-test.c 프로젝트: 01org/qemu-lite
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/nvme/nop", nop);

    qtest_start("-drive id=drv0,if=none,file=/dev/null,format=raw "
                "-device nvme,drive=drv0,serial=foo");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #25
0
static void test_device_intro_list(void)
{
    QList *types;
    char *help;

    qtest_start(common_args);

    types = device_type_list(true);
    QDECREF(types);

    help = hmp("device_add help");
    g_free(help);

    qtest_end();
}
예제 #26
0
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/virtio/serial/pci/nop", pci_nop);
    qtest_add_func("/virtio/serial/pci/hotplug", hotplug);

    qtest_start("-device virtio-serial-pci");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #27
0
파일: ivshmem-test.c 프로젝트: gkurz/qemu
static void test_ivshmem_hotplug(void)
{
    const char *arch = qtest_get_arch();

    qtest_start("-object memory-backend-ram,size=1M,id=mb1");

    qtest_qmp_device_add("ivshmem-plain", "iv1",
                         "{'addr': %s, 'memdev': 'mb1'}",
                         stringify(PCI_SLOT_HP));
    if (strcmp(arch, "ppc64") != 0) {
        qpci_unplug_acpi_device_test("iv1", PCI_SLOT_HP);
    }

    qtest_end();
}
예제 #28
0
파일: ioh3420-test.c 프로젝트: 8tab/qemu
int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    qtest_add_func("/ioh3420/nop", nop);

    qtest_start("-machine q35 -device ioh3420,bus=pcie.0,addr=1c.0,port=1,"
                "chassis=1,multifunction=on");
    ret = g_test_run();

    qtest_end();

    return ret;
}
예제 #29
0
static void test_device_intro_concrete(void)
{
    QList *types;
    QListEntry *entry;
    const char *type;

    qtest_start(common_args);
    types = device_type_list(false);

    QLIST_FOREACH_ENTRY(types, entry) {
        type = qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry)),
                                "name");
        g_assert(type);
        test_one_device(type);
    }
예제 #30
0
파일: test-hmp.c 프로젝트: twnkl/qemu
static void test_machine(gconstpointer data)
{
    const char *machine = data;
    char *args;

    args = g_strdup_printf("-S -M %s", machine);
    qtest_start(args);

    test_info_commands();
    test_commands();

    qtest_end();
    g_free(args);
    g_free((void *)data);
}