mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
tests/qtest: Move mkimg() and have_qemu_img() from libqos to libqtest
These two functions can be useful for other qtests beside the qos-test, too, so move them to libqtest instead. Message-Id: <20230704071655.75381-3-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
parent
5a7d4dc9f8
commit
25919c4025
4 changed files with 73 additions and 50 deletions
|
@ -137,56 +137,9 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
|
|||
migrate_allocator(&from->alloc, &to->alloc);
|
||||
}
|
||||
|
||||
bool have_qemu_img(void)
|
||||
{
|
||||
char *rpath;
|
||||
const char *path = getenv("QTEST_QEMU_IMG");
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rpath = realpath(path, NULL);
|
||||
if (!rpath) {
|
||||
return false;
|
||||
} else {
|
||||
free(rpath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void mkimg(const char *file, const char *fmt, unsigned size_mb)
|
||||
{
|
||||
gchar *cli;
|
||||
bool ret;
|
||||
int rc;
|
||||
GError *err = NULL;
|
||||
char *qemu_img_path;
|
||||
gchar *out, *out2;
|
||||
char *qemu_img_abs_path;
|
||||
|
||||
qemu_img_path = getenv("QTEST_QEMU_IMG");
|
||||
g_assert(qemu_img_path);
|
||||
qemu_img_abs_path = realpath(qemu_img_path, NULL);
|
||||
g_assert(qemu_img_abs_path);
|
||||
|
||||
cli = g_strdup_printf("%s create -f %s %s %uM", qemu_img_abs_path,
|
||||
fmt, file, size_mb);
|
||||
ret = g_spawn_command_line_sync(cli, &out, &out2, &rc, &err);
|
||||
if (err || !g_spawn_check_exit_status(rc, &err)) {
|
||||
fprintf(stderr, "%s\n", err->message);
|
||||
g_error_free(err);
|
||||
}
|
||||
g_assert(ret && !err);
|
||||
|
||||
g_free(out);
|
||||
g_free(out2);
|
||||
g_free(cli);
|
||||
free(qemu_img_abs_path);
|
||||
}
|
||||
|
||||
void mkqcow2(const char *file, unsigned size_mb)
|
||||
{
|
||||
return mkimg(file, "qcow2", size_mb);
|
||||
g_assert_true(mkimg(file, "qcow2", size_mb));
|
||||
}
|
||||
|
||||
void prepare_blkdebug_script(const char *debug_fn, const char *event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue