Esempio n. 1
0
static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
{
    unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;

    qtest_quit(from);

    if (test_dest) {
        qtest_memread(to, start_address, &dest_byte_a, 1);

        /* Destination still running, wait for a byte to change */
        do {
            qtest_memread(to, start_address, &dest_byte_b, 1);
            usleep(1000 * 10);
        } while (dest_byte_a == dest_byte_b);

        qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}");

        /* With it stopped, check nothing changes */
        qtest_memread(to, start_address, &dest_byte_c, 1);
        usleep(1000 * 200);
        qtest_memread(to, start_address, &dest_byte_d, 1);
        g_assert_cmpint(dest_byte_c, ==, dest_byte_d);

        check_guests_ram(to);
    }

    qtest_quit(to);

    cleanup("bootsect");
    cleanup("migsocket");
    cleanup("src_serial");
    cleanup("dest_serial");
}
Esempio n. 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;
}
Esempio n. 3
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);
}
Esempio n. 4
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);
}
Esempio n. 5
0
static void test_cdboot(gconstpointer data)
{
    QTestState *qts;

    qts = qtest_initf("-accel kvm:tcg -no-shutdown %s%s", (const char *)data,
                      isoimage);
    boot_sector_test(qts);
    qtest_quit(qts);
}
Esempio n. 6
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);
}
Esempio n. 7
0
/**
 * Check that at least the -cdrom parameter is basically working, i.e. we can
 * see the filename of the ISO image in the output of "info block" afterwards
 */
static void test_cdrom_param(gconstpointer data)
{
    QTestState *qts;
    char *resp;

    qts = qtest_initf("-M %s -cdrom %s", (const char *)data, isoimage);
    resp = qtest_hmp(qts, "info block");
    g_assert(strstr(resp, isoimage) != 0);
    g_free(resp);
    qtest_quit(qts);
}
Esempio n. 8
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;
}
Esempio n. 9
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);
}
Esempio n. 10
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);
}
Esempio n. 11
0
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);
}
Esempio n. 12
0
/* 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);
}
Esempio n. 13
0
File: libqos.c Progetto: stweil/qemu
/**
 * Tear down the QEMU instance.
 */
void qtest_common_shutdown(QOSState *qs)
{
    if (qs->ops) {
        if (qs->pcibus && qs->ops->qpci_free) {
            qs->ops->qpci_free(qs->pcibus);
            qs->pcibus = NULL;
        }
        if (qs->alloc && qs->ops->uninit_allocator) {
            qs->ops->uninit_allocator(qs->alloc);
            qs->alloc = NULL;
        }
    }
    qtest_quit(qs->qts);
    g_free(qs);
}
Esempio n. 14
0
int main(int argc, char **argv)
{
    QTestState *s = NULL;
    int ret;

    g_test_init(&argc, &argv, NULL);

    s = qtest_start("-display none -machine n800");
    i2c = omap_i2c_create(OMAP2_I2C_1_BASE);
    addr = N8X0_ADDR;

    qtest_add_func("/tmp105/tx-rx", send_and_receive);

    ret = g_test_run();

    if (s) {
        qtest_quit(s);
    }
    g_free(i2c);

    return ret;
}
Esempio n. 15
0
static void test_read_guest_mem(void)
{
    TestServer *server = NULL;
    char *qemu_cmd = NULL;
    QTestState *s = NULL;

    server = test_server_new("test");
    test_server_listen(server);

    qemu_cmd = GET_QEMU_CMD(server);

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

    init_virtio_dev(server, 1u << VIRTIO_NET_F_MAC);

    read_guest_mem_server(server);

    uninit_virtio_dev(server);

    qtest_quit(s);
    test_server_free(server);
}
Esempio n. 16
0
static void test_machine(const void *data)
{
    const testdef_t *test = data;
    char *args;
    char tmpname[] = "/tmp/qtest-boot-serial-XXXXXX";
    int fd;

    fd = mkstemp(tmpname);
    g_assert(fd != -1);

    args = g_strdup_printf("-M %s,accel=tcg -chardev file,id=serial0,path=%s"
                           " -no-shutdown -serial chardev:serial0 %s",
                           test->machine, tmpname, test->extra);

    qtest_start(args);
    unlink(tmpname);

    check_guest_output(test, fd);
    qtest_quit(global_qtest);

    g_free(args);
    close(fd);
}
Esempio n. 17
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)
{
    uint64_t actual;

    global_qtest = qtest_startf("-nodefaults%s%s %s",
                                machine ? " -M " : "",
                                machine ?: "",
                                test_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_eventwait("RESET");
    actual = read_boot_order();
    g_assert_cmphex(actual, ==, expected_reboot);
    qtest_quit(global_qtest);
}
Esempio n. 18
0
static void test_machine(const void *data)
{
    const testdef_t *test = data;
    char tmpname[] = "/tmp/qtest-boot-serial-XXXXXX";
    int fd;

    fd = mkstemp(tmpname);
    g_assert(fd != -1);

    /*
     * Make sure that this test uses tcg if available: It is used as a
     * fast-enough smoketest for that.
     */
    global_qtest = qtest_startf("-M %s,accel=tcg:kvm "
                                "-chardev file,id=serial0,path=%s "
                                "-no-shutdown -serial chardev:serial0 %s",
                                test->machine, tmpname, test->extra);
    unlink(tmpname);

    check_guest_output(test, fd);
    qtest_quit(global_qtest);

    close(fd);
}
Esempio n. 19
0
static void test_migrate(void)
{
    char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
    QTestState *global = global_qtest, *from, *to;
    unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
    gchar *cmd, *cmd_src, *cmd_dst;
    QDict *rsp;

    char *bootpath = g_strdup_printf("%s/bootsect", tmpfs);
    const char *arch = qtest_get_arch();

    got_stop = false;

    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
        init_bootfile_x86(bootpath);
        cmd_src = g_strdup_printf("-machine accel=kvm:tcg -m 150M"
                                  " -name pcsource,debug-threads=on"
                                  " -serial file:%s/src_serial"
                                  " -drive file=%s,format=raw",
                                  tmpfs, bootpath);
        cmd_dst = g_strdup_printf("-machine accel=kvm:tcg -m 150M"
                                  " -name pcdest,debug-threads=on"
                                  " -serial file:%s/dest_serial"
                                  " -drive file=%s,format=raw"
                                  " -incoming %s",
                                  tmpfs, bootpath, uri);
    } else if (strcmp(arch, "ppc64") == 0) {
        init_bootfile_ppc(bootpath);
        cmd_src = g_strdup_printf("-machine accel=kvm:tcg -m 256M"
                                  " -name pcsource,debug-threads=on"
                                  " -serial file:%s/src_serial"
                                  " -drive file=%s,if=pflash,format=raw",
                                  tmpfs, bootpath);
        cmd_dst = g_strdup_printf("-machine accel=kvm:tcg -m 256M"
                                  " -name pcdest,debug-threads=on"
                                  " -serial file:%s/dest_serial"
                                  " -incoming %s",
                                  tmpfs, uri);
    } else {
        g_assert_not_reached();
    }

    g_free(bootpath);

    from = qtest_start(cmd_src);
    g_free(cmd_src);

    to = qtest_init(cmd_dst);
    g_free(cmd_dst);

    global_qtest = from;
    rsp = qmp("{ 'execute': 'migrate-set-capabilities',"
                  "'arguments': { "
                      "'capabilities': [ {"
                          "'capability': 'postcopy-ram',"
                          "'state': true } ] } }");
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    global_qtest = to;
    rsp = qmp("{ 'execute': 'migrate-set-capabilities',"
                  "'arguments': { "
                      "'capabilities': [ {"
                          "'capability': 'postcopy-ram',"
                          "'state': true } ] } }");
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    /* We want to pick a speed slow enough that the test completes
     * quickly, but that it doesn't complete precopy even on a slow
     * machine, so also set the downtime.
     */
    global_qtest = from;
    rsp = qmp("{ 'execute': 'migrate_set_speed',"
              "'arguments': { 'value': 100000000 } }");
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    /* 1ms downtime - it should never finish precopy */
    rsp = qmp("{ 'execute': 'migrate_set_downtime',"
              "'arguments': { 'value': 0.001 } }");
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);


    /* Wait for the first serial output from the source */
    wait_for_serial("src_serial");

    cmd = g_strdup_printf("{ 'execute': 'migrate',"
                          "'arguments': { 'uri': '%s' } }",
                          uri);
    rsp = qmp(cmd);
    g_free(cmd);
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    wait_for_migration_pass();

    rsp = return_or_event(qmp("{ 'execute': 'migrate-start-postcopy' }"));
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    if (!got_stop) {
        qmp_eventwait("STOP");
    }

    global_qtest = to;
    qmp_eventwait("RESUME");

    wait_for_serial("dest_serial");
    global_qtest = from;
    wait_for_migration_complete();

    qtest_quit(from);

    global_qtest = to;

    qtest_memread(to, start_address, &dest_byte_a, 1);

    /* Destination still running, wait for a byte to change */
    do {
        qtest_memread(to, start_address, &dest_byte_b, 1);
        usleep(10 * 1000);
    } while (dest_byte_a == dest_byte_b);

    qmp("{ 'execute' : 'stop'}");
    /* With it stopped, check nothing changes */
    qtest_memread(to, start_address, &dest_byte_c, 1);
    sleep(1);
    qtest_memread(to, start_address, &dest_byte_d, 1);
    g_assert_cmpint(dest_byte_c, ==, dest_byte_d);

    check_guests_ram();

    qtest_quit(to);
    g_free(uri);

    global_qtest = global;

    cleanup("bootsect");
    cleanup("migsocket");
    cleanup("src_serial");
    cleanup("dest_serial");
}
Esempio n. 20
0
static void test_migrate(void)
{
    TestServer *s = test_server_new("src");
    TestServer *dest = test_server_new("dest");
    char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path);
    QTestState *global = global_qtest, *from, *to;
    GSource *source;
    gchar *cmd;
    QDict *rsp;
    guint8 *log;
    guint64 size;

    test_server_listen(s);
    test_server_listen(dest);

    cmd = GET_QEMU_CMDE(s, 2, "", "");
    from = qtest_start(cmd);
    g_free(cmd);

    init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC);
    wait_for_fds(s);
    size = get_log_size(s);
    g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));

    cmd = GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri);
    to = qtest_init(cmd);
    g_free(cmd);

    source = g_source_new(&test_migrate_source_funcs,
                          sizeof(TestMigrateSource));
    ((TestMigrateSource *)source)->src = s;
    ((TestMigrateSource *)source)->dest = dest;
    g_source_attach(source, NULL);

    /* slow down migration to have time to fiddle with log */
    /* TODO: qtest could learn to break on some places */
    rsp = qmp("{ 'execute': 'migrate_set_speed',"
              "'arguments': { 'value': 10 } }");
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    cmd = g_strdup_printf("{ 'execute': 'migrate',"
                          "'arguments': { 'uri': '%s' } }",
                          uri);
    rsp = qmp(cmd);
    g_free(cmd);
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    wait_for_log_fd(s);

    log = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, s->log_fd, 0);
    g_assert(log != MAP_FAILED);

    /* modify first page */
    write_guest_mem(s, 0x42);
    log[0] = 1;
    munmap(log, size);

    /* speed things up */
    rsp = qmp("{ 'execute': 'migrate_set_speed',"
              "'arguments': { 'value': 0 } }");
    g_assert(qdict_haskey(rsp, "return"));
    QDECREF(rsp);

    qmp_eventwait("STOP");

    global_qtest = to;
    qmp_eventwait("RESUME");

    read_guest_mem_server(dest);

    uninit_virtio_dev(s);

    g_source_destroy(source);
    g_source_unref(source);

    qtest_quit(to);
    test_server_free(dest);
    qtest_quit(from);
    test_server_free(s);
    g_free(uri);

    global_qtest = global;
}