Пример #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");
}
Пример #2
0
static void check_guests_ram(void)
{
    /* Our ASM test will have been incrementing one byte from each page from
     * 1MB to <100MB in order.
     * This gives us a constraint that any page's byte should be equal or less
     * than the previous pages byte (mod 256); and they should all be equal
     * except for one transition at the point where we meet the incrementer.
     * (We're running this with the guest stopped).
     */
    unsigned address;
    uint8_t first_byte;
    uint8_t last_byte;
    bool hit_edge = false;
    bool bad = false;

    qtest_memread(global_qtest, start_address, &first_byte, 1);
    last_byte = first_byte;

    for (address = start_address + 4096; address < end_address; address += 4096)
    {
        uint8_t b;
        qtest_memread(global_qtest, address, &b, 1);
        if (b != last_byte) {
            if (((b + 1) % 256) == last_byte && !hit_edge) {
                /* This is OK, the guest stopped at the point of
                 * incrementing the previous page but didn't get
                 * to us yet.
                 */
                hit_edge = true;
            } else {
                fprintf(stderr, "Memory content inconsistency at %x"
                                " first_byte = %x last_byte = %x current = %x"
                                " hit_edge = %x\n",
                                address, first_byte, last_byte, b, hit_edge);
                bad = true;
            }
        }
        last_byte = b;
    }
    g_assert_false(bad);
}
Пример #3
0
static void qpci_pc_memread(QPCIBus *bus, uint32_t addr, void *buf, size_t len)
{
    qtest_memread(bus->qts, addr, buf, len);
}
Пример #4
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");
}