Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QTest testcase for PV Panic |
| 3 | * |
| 4 | * Copyright (c) 2014 SUSE LINUX Products GmbH |
| 5 | * |
| 6 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 7 | * See the COPYING file in the top-level directory. |
| 8 | */ |
| 9 | |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 10 | #include "qemu/osdep.h" |
Peter Maydell | 681c28a | 2016-02-08 18:08:51 +0000 | [diff] [blame] | 11 | #include "libqtest.h" |
Markus Armbruster | 452fcdb | 2018-02-01 12:18:39 +0100 | [diff] [blame] | 12 | #include "qapi/qmp/qdict.h" |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 13 | |
| 14 | static void test_panic(void) |
| 15 | { |
| 16 | uint8_t val; |
Andreas Färber | 627b1a1 | 2014-02-21 21:17:17 +0100 | [diff] [blame] | 17 | QDict *response, *data; |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 18 | QTestState *qts; |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 19 | |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 20 | qts = qtest_init("-device pvpanic"); |
| 21 | |
| 22 | val = qtest_inb(qts, 0x505); |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 23 | g_assert_cmpuint(val, ==, 1); |
| 24 | |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 25 | qtest_outb(qts, 0x505, 0x1); |
Andreas Färber | 627b1a1 | 2014-02-21 21:17:17 +0100 | [diff] [blame] | 26 | |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 27 | response = qtest_qmp_receive(qts); |
Andreas Färber | 627b1a1 | 2014-02-21 21:17:17 +0100 | [diff] [blame] | 28 | g_assert(qdict_haskey(response, "event")); |
| 29 | g_assert_cmpstr(qdict_get_str(response, "event"), ==, "GUEST_PANICKED"); |
| 30 | g_assert(qdict_haskey(response, "data")); |
| 31 | data = qdict_get_qdict(response, "data"); |
| 32 | g_assert(qdict_haskey(data, "action")); |
| 33 | g_assert_cmpstr(qdict_get_str(data, "action"), ==, "pause"); |
Marc-André Lureau | cb3e7f0 | 2018-04-19 17:01:43 +0200 | [diff] [blame] | 34 | qobject_unref(response); |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 35 | |
| 36 | qtest_quit(qts); |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | int main(int argc, char **argv) |
| 40 | { |
| 41 | int ret; |
| 42 | |
| 43 | g_test_init(&argc, &argv, NULL); |
| 44 | qtest_add_func("/pvpanic/panic", test_panic); |
| 45 | |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 46 | ret = g_test_run(); |
| 47 | |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 48 | return ret; |
| 49 | } |