qemu-ga patch queue
* add unit tests for guest-exec command set -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJXVzH1AAoJEDNTyc7xCLWEFuMH/2J8tYX27EMC8yET9SdoSZ/F N4RzF88rc3A4L2SU9MvXjSvMpd8N1nWPLnCbcL+OGftVEjzlYXJL6kCysewXIV5X b6AE9DheVg4woxeazRyc7bk0iYjjjsXubfMop274nWpSGtoHP1tv7EQPEiN8fplL +i/dBsZ2CCXp8is3cgoT4w7uZM0kwwbgB3yLs3gBApV3luNTZIHhmYk6yzEtho53 Dl4aHCEcHaNb2764pSg6W1OQ8EKOM6dDpMkMo6GCJP1ohgwR9pYbdW6FBO50u0xi Pog7YiWFKXkEQ/vTq6Dc567xwMhs2jBluteDB7w5HKXZFkgOTEEc3SCAAy4seKw= =nOlG -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2016-07-07-tag' into staging qemu-ga patch queue * add unit tests for guest-exec command set # gpg: Signature made Tue 07 Jun 2016 21:43:33 BST # gpg: using RSA key 0x3353C9CEF108B584 # gpg: Good signature from "Michael Roth <flukshun@gmail.com>" # gpg: aka "Michael Roth <mdroth@utexas.edu>" # gpg: aka "Michael Roth <mdroth@linux.vnet.ibm.com>" * remotes/mdroth/tags/qga-pull-2016-07-07-tag: tests: start a /qga/guest-exec test Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
c1a3b8b745
|
@ -822,6 +822,84 @@ static void test_qga_fsfreeze_and_thaw(gconstpointer fix)
|
|||
QDECREF(ret);
|
||||
}
|
||||
|
||||
static void test_qga_guest_exec(gconstpointer fix)
|
||||
{
|
||||
const TestFixture *fixture = fix;
|
||||
QDict *ret, *val;
|
||||
const gchar *out;
|
||||
guchar *decoded;
|
||||
int64_t pid, now, exitcode;
|
||||
gsize len;
|
||||
bool exited;
|
||||
|
||||
/* exec 'echo foo bar' */
|
||||
ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {"
|
||||
" 'path': '/bin/echo', 'arg': [ '-n', '\" test_str \"' ],"
|
||||
" 'capture-output': true } }");
|
||||
g_assert_nonnull(ret);
|
||||
qmp_assert_no_error(ret);
|
||||
val = qdict_get_qdict(ret, "return");
|
||||
pid = qdict_get_int(val, "pid");
|
||||
g_assert_cmpint(pid, >, 0);
|
||||
QDECREF(ret);
|
||||
|
||||
/* wait for completion */
|
||||
now = g_get_monotonic_time();
|
||||
do {
|
||||
ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status',"
|
||||
" 'arguments': { 'pid': %" PRId64 " } }", pid);
|
||||
g_assert_nonnull(ret);
|
||||
val = qdict_get_qdict(ret, "return");
|
||||
exited = qdict_get_bool(val, "exited");
|
||||
if (!exited) {
|
||||
QDECREF(ret);
|
||||
}
|
||||
} while (!exited &&
|
||||
g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND);
|
||||
g_assert(exited);
|
||||
|
||||
/* check stdout */
|
||||
exitcode = qdict_get_int(val, "exitcode");
|
||||
g_assert_cmpint(exitcode, ==, 0);
|
||||
out = qdict_get_str(val, "out-data");
|
||||
decoded = g_base64_decode(out, &len);
|
||||
g_assert_cmpint(len, ==, 12);
|
||||
g_assert_cmpstr((char *)decoded, ==, "\" test_str \"");
|
||||
g_free(decoded);
|
||||
QDECREF(ret);
|
||||
}
|
||||
|
||||
static void test_qga_guest_exec_invalid(gconstpointer fix)
|
||||
{
|
||||
const TestFixture *fixture = fix;
|
||||
QDict *ret, *error;
|
||||
const gchar *class, *desc;
|
||||
|
||||
/* invalid command */
|
||||
ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {"
|
||||
" 'path': '/bin/invalid-cmd42' } }");
|
||||
g_assert_nonnull(ret);
|
||||
error = qdict_get_qdict(ret, "error");
|
||||
g_assert_nonnull(error);
|
||||
class = qdict_get_str(error, "class");
|
||||
desc = qdict_get_str(error, "desc");
|
||||
g_assert_cmpstr(class, ==, "GenericError");
|
||||
g_assert_cmpint(strlen(desc), >, 0);
|
||||
QDECREF(ret);
|
||||
|
||||
/* invalid pid */
|
||||
ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status',"
|
||||
" 'arguments': { 'pid': 0 } }");
|
||||
g_assert_nonnull(ret);
|
||||
error = qdict_get_qdict(ret, "error");
|
||||
g_assert_nonnull(error);
|
||||
class = qdict_get_str(error, "class");
|
||||
desc = qdict_get_str(error, "desc");
|
||||
g_assert_cmpstr(class, ==, "GenericError");
|
||||
g_assert_cmpint(strlen(desc), >, 0);
|
||||
QDECREF(ret);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
TestFixture fix;
|
||||
|
@ -852,6 +930,9 @@ int main(int argc, char **argv)
|
|||
|
||||
g_test_add_data_func("/qga/blacklist", NULL, test_qga_blacklist);
|
||||
g_test_add_data_func("/qga/config", NULL, test_qga_config);
|
||||
g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec);
|
||||
g_test_add_data_func("/qga/guest-exec-invalid", &fix,
|
||||
test_qga_guest_exec_invalid);
|
||||
|
||||
if (g_getenv("QGA_TEST_SIDE_EFFECTING")) {
|
||||
g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix,
|
||||
|
|
Loading…
Reference in a new issue