Skip to content

Commit d65c890

Browse files
berrangephilmd
authored andcommitted
tests/qtest: add test for querying balloon guest stats
This test would have identified the crash caused by the addition of new balloon stats fields. Signed-off-by: Daniel P. Berrangé <[email protected]> Reviewed-by: Fabiano Rosas <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
1 parent 8460459 commit d65c890

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/qtest/virtio-balloon-test.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "qemu/osdep.h"
1010
#include "libqtest.h"
11+
#include "standard-headers/linux/virtio_balloon.h"
1112

1213
/*
1314
* https://gitlab.com/qemu-project/qemu/-/issues/2576
@@ -26,11 +27,30 @@ static void oss_fuzz_71649(void)
2627
qtest_quit(s);
2728
}
2829

30+
static void query_stats(void)
31+
{
32+
QTestState *s = qtest_init("-device virtio-balloon,id=balloon"
33+
" -nodefaults");
34+
QDict *ret = qtest_qmp_assert_success_ref(
35+
s,
36+
"{ 'execute': 'qom-get', 'arguments': " \
37+
"{ 'path': '/machine/peripheral/balloon', " \
38+
" 'property': 'guest-stats' } }");
39+
QDict *stats = qdict_get_qdict(ret, "stats");
40+
41+
/* We expect 1 entry in the dict for each known kernel stat */
42+
assert(qdict_size(stats) == VIRTIO_BALLOON_S_NR);
43+
44+
qobject_unref(ret);
45+
qtest_quit(s);
46+
}
47+
2948
int main(int argc, char **argv)
3049
{
3150
g_test_init(&argc, &argv, NULL);
3251

3352
qtest_add_func("virtio-balloon/oss_fuzz_71649", oss_fuzz_71649);
53+
qtest_add_func("virtio-balloon/query-stats", query_stats);
3454

3555
return g_test_run();
3656
}

0 commit comments

Comments
 (0)