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" |
Marc-André Lureau | 907b510 | 2022-03-30 13:39:05 +0400 | [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 | |
Alejandro Jimenez | c9ca89a | 2020-12-11 11:52:44 -0500 | [diff] [blame] | 14 | static void test_panic_nopause(void) |
| 15 | { |
| 16 | uint8_t val; |
| 17 | QDict *response, *data; |
| 18 | QTestState *qts; |
| 19 | |
| 20 | qts = qtest_init("-device pvpanic -action panic=none"); |
| 21 | |
| 22 | val = qtest_inb(qts, 0x505); |
| 23 | g_assert_cmpuint(val, ==, 3); |
| 24 | |
| 25 | qtest_outb(qts, 0x505, 0x1); |
| 26 | |
| 27 | response = qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED"); |
| 28 | g_assert(qdict_haskey(response, "data")); |
| 29 | data = qdict_get_qdict(response, "data"); |
| 30 | g_assert(qdict_haskey(data, "action")); |
| 31 | g_assert_cmpstr(qdict_get_str(data, "action"), ==, "run"); |
| 32 | qobject_unref(response); |
| 33 | |
| 34 | qtest_quit(qts); |
| 35 | } |
| 36 | |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 37 | static void test_panic(void) |
| 38 | { |
| 39 | uint8_t val; |
Andreas Färber | 627b1a1 | 2014-02-21 21:17:17 +0100 | [diff] [blame] | 40 | QDict *response, *data; |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 41 | QTestState *qts; |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 42 | |
Alejandro Jimenez | c9ca89a | 2020-12-11 11:52:44 -0500 | [diff] [blame] | 43 | qts = qtest_init("-device pvpanic -action panic=pause"); |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 44 | |
| 45 | val = qtest_inb(qts, 0x505); |
Paolo Bonzini | b1b0393 | 2020-11-09 08:53:04 -0500 | [diff] [blame] | 46 | g_assert_cmpuint(val, ==, 3); |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 47 | |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 48 | qtest_outb(qts, 0x505, 0x1); |
Andreas Färber | 627b1a1 | 2014-02-21 21:17:17 +0100 | [diff] [blame] | 49 | |
Maxim Levitsky | bb1a5b9 | 2020-10-06 15:38:53 +0300 | [diff] [blame] | 50 | response = qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED"); |
Andreas Färber | 627b1a1 | 2014-02-21 21:17:17 +0100 | [diff] [blame] | 51 | g_assert(qdict_haskey(response, "data")); |
| 52 | data = qdict_get_qdict(response, "data"); |
| 53 | g_assert(qdict_haskey(data, "action")); |
| 54 | g_assert_cmpstr(qdict_get_str(data, "action"), ==, "pause"); |
Marc-André Lureau | cb3e7f0 | 2018-04-19 17:01:43 +0200 | [diff] [blame] | 55 | qobject_unref(response); |
Thomas Huth | 791a289 | 2018-11-05 16:30:43 +0100 | [diff] [blame] | 56 | |
| 57 | qtest_quit(qts); |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | int main(int argc, char **argv) |
| 61 | { |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 62 | g_test_init(&argc, &argv, NULL); |
| 63 | qtest_add_func("/pvpanic/panic", test_panic); |
Alejandro Jimenez | c9ca89a | 2020-12-11 11:52:44 -0500 | [diff] [blame] | 64 | qtest_add_func("/pvpanic/panic-nopause", test_panic_nopause); |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 65 | |
Markus Armbruster | 66997c4 | 2022-11-22 14:49:16 +0100 | [diff] [blame] | 66 | return g_test_run(); |
Andreas Färber | abc5373 | 2014-02-21 20:38:48 +0100 | [diff] [blame] | 67 | } |