libqos: add qemu-img presence check
To allow tests to optionally exercise additional tests that require the qemu-img tool that may not be present in all builds. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 1447439479-16775-3-git-send-email-jsnow@redhat.com
This commit is contained in:
parent
b236b61056
commit
cb11e7b2f3
@ -147,6 +147,23 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
|
|||||||
set_context(to);
|
set_context(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
void mkimg(const char *file, const char *fmt, unsigned size_mb)
|
||||||
{
|
{
|
||||||
gchar *cli;
|
gchar *cli;
|
||||||
@ -155,13 +172,14 @@ void mkimg(const char *file, const char *fmt, unsigned size_mb)
|
|||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
char *qemu_img_path;
|
char *qemu_img_path;
|
||||||
gchar *out, *out2;
|
gchar *out, *out2;
|
||||||
char *abs_path;
|
char *qemu_img_abs_path;
|
||||||
|
|
||||||
qemu_img_path = getenv("QTEST_QEMU_IMG");
|
qemu_img_path = getenv("QTEST_QEMU_IMG");
|
||||||
abs_path = realpath(qemu_img_path, NULL);
|
g_assert(qemu_img_path);
|
||||||
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", abs_path,
|
cli = g_strdup_printf("%s create -f %s %s %uM", qemu_img_abs_path,
|
||||||
fmt, file, size_mb);
|
fmt, file, size_mb);
|
||||||
ret = g_spawn_command_line_sync(cli, &out, &out2, &rc, &err);
|
ret = g_spawn_command_line_sync(cli, &out, &out2, &rc, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -183,7 +201,7 @@ void mkimg(const char *file, const char *fmt, unsigned size_mb)
|
|||||||
g_free(out);
|
g_free(out);
|
||||||
g_free(out2);
|
g_free(out2);
|
||||||
g_free(cli);
|
g_free(cli);
|
||||||
free(abs_path);
|
free(qemu_img_abs_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mkqcow2(const char *file, unsigned size_mb)
|
void mkqcow2(const char *file, unsigned size_mb)
|
||||||
|
@ -19,6 +19,7 @@ typedef struct QOSState {
|
|||||||
QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap);
|
QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap);
|
||||||
QOSState *qtest_boot(QOSOps *ops, const char *cmdline_fmt, ...);
|
QOSState *qtest_boot(QOSOps *ops, const char *cmdline_fmt, ...);
|
||||||
void qtest_shutdown(QOSState *qs);
|
void qtest_shutdown(QOSState *qs);
|
||||||
|
bool have_qemu_img(void);
|
||||||
void mkimg(const char *file, const char *fmt, unsigned size_mb);
|
void mkimg(const char *file, const char *fmt, unsigned size_mb);
|
||||||
void mkqcow2(const char *file, unsigned size_mb);
|
void mkqcow2(const char *file, unsigned size_mb);
|
||||||
void set_context(QOSState *s);
|
void set_context(QOSState *s);
|
||||||
|
Loading…
Reference in New Issue
Block a user