libqtest: Replace qtest_startf() by qtest_initf()

qtest_init() creates a new QTestState, and leaves @global_qtest alone.
qtest_start() additionally assigns it to @global_qtest, but
qtest_startf() additionally assigns NULL to @global_qtest.  This makes
no sense.  Replace it by qtest_initf() that works like qtest_init(),
i.e. leaves @global_qtest alone.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180806065344.7103-23-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2018-08-06 08:53:43 +02:00
parent e3dc93be1a
commit 88b988c895
23 changed files with 80 additions and 82 deletions

View File

@ -33,7 +33,7 @@ static void test_a_boot_order(const char *machine,
{
uint64_t actual;
global_qtest = qtest_startf("-nodefaults%s%s %s",
global_qtest = qtest_initf("-nodefaults%s%s %s",
machine ? " -M " : "",
machine ?: "",
test_args);

View File

@ -172,7 +172,7 @@ static void test_machine(const void *data)
* Make sure that this test uses tcg if available: It is used as a
* fast-enough smoketest for that.
*/
global_qtest = qtest_startf("%s %s -M %s,accel=tcg:kvm "
global_qtest = qtest_initf("%s %s -M %s,accel=tcg:kvm "
"-chardev file,id=serial0,path=%s "
"-no-shutdown -serial chardev:serial0 %s",
codeparam, code ? codetmp : "",

View File

@ -99,7 +99,7 @@ static void test_cdrom_param(gconstpointer data)
QTestState *qts;
char *resp;
qts = qtest_startf("-M %s -cdrom %s", (const char *)data, isoimage);
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);
@ -120,7 +120,7 @@ static void test_cdboot(gconstpointer data)
{
QTestState *qts;
qts = qtest_startf("-accel kvm:tcg -no-shutdown %s%s", (const char *)data,
qts = qtest_initf("-accel kvm:tcg -no-shutdown %s%s", (const char *)data,
isoimage);
boot_sector_test(qts);
qtest_quit(qts);

View File

@ -115,7 +115,7 @@ static void test_endianness(gconstpointer data)
{
const TestCase *test = data;
global_qtest = qtest_startf("-M %s%s%s -device pc-testdev",
global_qtest = qtest_initf("-M %s%s%s -device pc-testdev",
test->machine,
test->superio ? " -device " : "",
test->superio ?: "");
@ -187,7 +187,7 @@ static void test_endianness_split(gconstpointer data)
{
const TestCase *test = data;
global_qtest = qtest_startf("-M %s%s%s -device pc-testdev",
global_qtest = qtest_initf("-M %s%s%s -device pc-testdev",
test->machine,
test->superio ? " -device " : "",
test->superio ?: "");
@ -231,7 +231,7 @@ static void test_endianness_combine(gconstpointer data)
{
const TestCase *test = data;
global_qtest = qtest_startf("-M %s%s%s -device pc-testdev",
global_qtest = qtest_initf("-M %s%s%s -device pc-testdev",
test->machine,
test->superio ? " -device " : "",
test->superio ?: "");

View File

@ -414,7 +414,7 @@ int main(int argc, char **argv)
/* Run the tests */
g_test_init(&argc, &argv, NULL);
global_qtest = qtest_startf(
global_qtest = qtest_initf(
" -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);

View File

@ -259,24 +259,23 @@ QTestState *qtest_init(const char *extra_args)
return s;
}
QTestState *qtest_vstartf(const char *fmt, va_list ap)
QTestState *qtest_vinitf(const char *fmt, va_list ap)
{
char *args = g_strdup_vprintf(fmt, ap);
QTestState *s;
s = qtest_start(args);
s = qtest_init(args);
g_free(args);
global_qtest = NULL;
return s;
}
QTestState *qtest_startf(const char *fmt, ...)
QTestState *qtest_initf(const char *fmt, ...)
{
va_list ap;
QTestState *s;
va_start(ap, fmt);
s = qtest_vstartf(fmt, ap);
s = qtest_vinitf(fmt, ap);
va_end(ap);
return s;
}

View File

@ -22,33 +22,32 @@ typedef struct QTestState QTestState;
extern QTestState *global_qtest;
/**
* qtest_startf:
* qtest_initf:
* @fmt...: Format for creating other arguments to pass to QEMU, formatted
* like sprintf().
*
* Start QEMU and return the resulting #QTestState (but unlike qtest_start(),
* #global_qtest is left at NULL).
* Convenience wrapper around qtest_start().
*
* Returns: #QTestState instance.
*/
QTestState *qtest_startf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
QTestState *qtest_initf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
/**
* qtest_vstartf:
* qtest_vinitf:
* @fmt: Format for creating other arguments to pass to QEMU, formatted
* like vsprintf().
* @ap: Format arguments.
*
* Start QEMU and return the resulting #QTestState (but unlike qtest_start(),
* #global_qtest is left at NULL).
* Convenience wrapper around qtest_start().
*
* Returns: #QTestState instance.
*/
QTestState *qtest_vstartf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
QTestState *qtest_vinitf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
/**
* qtest_init:
* @extra_args: other arguments to pass to QEMU.
* @extra_args: other arguments to pass to QEMU. CAUTION: these
* arguments are subject to word splitting and shell evaluation.
*
* Returns: #QTestState instance.
*/

View File

@ -363,7 +363,7 @@ int main(int argc, char **argv)
g_assert(ret == 0);
close(fd);
global_qtest = qtest_startf("-m 256 -machine palmetto-bmc "
global_qtest = qtest_initf("-m 256 -machine palmetto-bmc "
"-drive file=%s,format=raw,if=mtd",
tmp_path);

View File

@ -146,7 +146,7 @@ static void cmos_get_date_time(QTestState *s, struct tm *date)
static QTestState *m48t59_qtest_start(void)
{
return qtest_startf("-M %s -rtc clock=vm", base_machine);
return qtest_initf("-M %s -rtc clock=vm", base_machine);
}
static void bcd_check_time(void)

View File

@ -84,7 +84,7 @@ static void test_machine_cpu_cli(void)
}
return; /* TODO: die here to force all targets have a test */
}
global_qtest = qtest_startf("-machine none -cpu '%s'", cpu_model);
global_qtest = qtest_initf("-machine none -cpu '%s'", cpu_model);
response = qmp("{ 'execute': 'quit' }");
g_assert(qdict_haskey(response, "return"));

View File

@ -267,8 +267,8 @@ static void pc_dynamic_cpu_cfg(const void *data)
QList *cpus;
QTestState *qs;
qs = qtest_startf("%s %s", data ? (char *)data : "",
"-nodefaults --preconfig -smp 2");
qs = qtest_initf("%s -nodefaults --preconfig -smp 2",
data ? (char *)data : "");
/* create 2 numa nodes */
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node',"

View File

@ -79,7 +79,7 @@ static void test_cfam_id(const void *data)
{
const PnvChip *chip = data;
global_qtest = qtest_startf("-M powernv,accel=tcg -cpu %s",
global_qtest = qtest_initf("-M powernv,accel=tcg -cpu %s",
chip->cpu_model);
test_xscom_cfam_id(chip);
qtest_quit(global_qtest);
@ -114,7 +114,7 @@ static void test_core(const void *data)
{
const PnvChip *chip = data;
global_qtest = qtest_startf("-M powernv,accel=tcg -cpu %s",
global_qtest = qtest_initf("-M powernv,accel=tcg -cpu %s",
chip->cpu_model);
test_xscom_core(chip);
qtest_quit(global_qtest);

View File

@ -49,7 +49,7 @@ static void test_machine(const void *machine)
/* The pseries firmware boots much faster without the default devices */
extra_args = strcmp(machine, "pseries") == 0 ? "-nodefaults" : "";
global_qtest = qtest_startf("-M %s,accel=tcg %s "
global_qtest = qtest_initf("-M %s,accel=tcg %s "
"-prom-env 'use-nvramrc?=true' "
"-prom-env 'nvramrc=%x %x l!' ",
(const char *)machine, extra_args,

View File

@ -436,7 +436,7 @@ static void add_query_tests(QmpSchema *schema)
static void test_qmp_preconfig(void)
{
QDict *rsp, *ret;
QTestState *qs = qtest_startf("%s --preconfig", common_args);
QTestState *qs = qtest_initf("%s --preconfig", common_args);
/* preconfig state */
/* enabled commands, no error expected */

View File

@ -184,7 +184,7 @@ static QSDHCI *machine_start(const struct sdhci_t *test)
uint16_t vendor_id, device_id;
uint64_t barsize;
global_qtest = qtest_startf("-machine %s -device sdhci-pci",
global_qtest = qtest_initf("-machine %s -device sdhci-pci",
test->machine);
s->pci.bus = qpci_init_pc(global_qtest, NULL);
@ -200,7 +200,7 @@ static QSDHCI *machine_start(const struct sdhci_t *test)
qpci_device_enable(s->pci.dev);
} else {
/* SysBus */
global_qtest = qtest_startf("-machine %s", test->machine);
global_qtest = qtest_initf("-machine %s", test->machine);
s->addr = test->sdhci.addr;
}

View File

@ -58,7 +58,7 @@ static void test_init(TestData *d)
{
QTestState *qs;
qs = qtest_startf("-machine q35 %s %s",
qs = qtest_initf("-machine q35 %s %s",
d->noreboot ? "" : "-global ICH9-LPC.noreboot=false",
!d->args ? "" : d->args);
global_qtest = qs;

View File

@ -40,7 +40,7 @@ static void test_mirror(void)
ret = mkstemp(sock_path);
g_assert_cmpint(ret, !=, -1);
global_qtest = qtest_startf(
global_qtest = qtest_initf(
"-netdev socket,id=qtest-bn0,fd=%d "
"-device %s,netdev=qtest-bn0,id=qtest-e0 "
"-chardev socket,id=mirror0,path=%s,server,nowait "

View File

@ -90,7 +90,7 @@ static void test_redirector_tx(void)
ret = mkstemp(sock_path1);
g_assert_cmpint(ret, !=, -1);
global_qtest = qtest_startf(
global_qtest = qtest_initf(
"-netdev socket,id=qtest-bn0,fd=%d "
"-device %s,netdev=qtest-bn0,id=qtest-e0 "
"-chardev socket,id=redirector0,path=%s,server,nowait "
@ -159,7 +159,7 @@ static void test_redirector_rx(void)
ret = mkstemp(sock_path1);
g_assert_cmpint(ret, !=, -1);
global_qtest = qtest_startf(
global_qtest = qtest_initf(
"-netdev socket,id=qtest-bn0,fd=%d "
"-device %s,netdev=qtest-bn0,id=qtest-e0 "
"-chardev socket,id=redirector0,path=%s,server,nowait "

View File

@ -23,7 +23,7 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
qtest_add_func("/virtio/balloon/nop", balloon_nop);
global_qtest = qtest_startf("-device virtio-balloon-%s",
global_qtest = qtest_initf("-device virtio-balloon-%s",
qvirtio_get_dev_type());
ret = g_test_run();

View File

@ -93,7 +93,7 @@ static void arm_test_start(void)
tmp_path = drive_create();
global_qtest = qtest_startf("-machine virt "
global_qtest = qtest_initf("-machine virt "
"-drive if=none,id=drive0,file=%s,format=raw "
"-device virtio-blk-device,drive=drive0",
tmp_path);

View File

@ -14,7 +14,7 @@
/* Tests only initialization so far. TODO: Replace with functional tests */
static void console_nop(void)
{
global_qtest = qtest_startf("-device virtio-serial-%s,id=vser0 "
global_qtest = qtest_initf("-device virtio-serial-%s,id=vser0 "
"-device virtconsole,bus=vser0.0",
qvirtio_get_dev_type());
qtest_end();
@ -22,7 +22,7 @@ static void console_nop(void)
static void serialport_nop(void)
{
global_qtest = qtest_startf("-device virtio-serial-%s,id=vser0 "
global_qtest = qtest_initf("-device virtio-serial-%s,id=vser0 "
"-device virtserialport,bus=vser0.0",
qvirtio_get_dev_type());
qtest_end();

View File

@ -31,7 +31,7 @@ int main(int argc, char **argv)
qtest_add_func("/virtio/serial/nop", virtio_serial_nop);
qtest_add_func("/virtio/serial/hotplug", hotplug);
global_qtest = qtest_startf("-device virtio-serial-%s",
global_qtest = qtest_initf("-device virtio-serial-%s",
qvirtio_get_dev_type());
ret = g_test_run();

View File

@ -142,7 +142,7 @@ static void vmgenid_set_guid_test(void)
g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
global_qtest = qtest_startf(GUID_CMD(VGID_GUID));
global_qtest = qtest_initf(GUID_CMD(VGID_GUID));
/* Read the GUID from accessing guest memory */
read_guid_from_memory(&measured);
@ -155,7 +155,7 @@ static void vmgenid_set_guid_auto_test(void)
{
QemuUUID measured;
global_qtest = qtest_startf(GUID_CMD("auto"));
global_qtest = qtest_initf(GUID_CMD("auto"));
read_guid_from_memory(&measured);
@ -171,7 +171,7 @@ static void vmgenid_query_monitor_test(void)
g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
global_qtest = qtest_startf(GUID_CMD(VGID_GUID));
global_qtest = qtest_initf(GUID_CMD(VGID_GUID));
/* Read the GUID via the monitor */
read_guid_from_monitor(&measured);