2014-07-15 16:57:06 +04:00
|
|
|
/*
|
|
|
|
* QTest testcase for the IB700 watchdog
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-02-08 21:08:51 +03:00
|
|
|
#include "qemu/osdep.h"
|
2020-08-04 21:00:40 +03:00
|
|
|
#include "libqos/libqtest.h"
|
2018-02-01 14:18:39 +03:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2015-06-12 16:01:30 +03:00
|
|
|
#include "qemu/timer.h"
|
2014-07-15 16:57:06 +04:00
|
|
|
|
2017-09-11 20:20:09 +03:00
|
|
|
static void qmp_check_no_event(QTestState *s)
|
2014-07-15 16:57:06 +04:00
|
|
|
{
|
2017-09-11 20:20:09 +03:00
|
|
|
QDict *resp = qtest_qmp(s, "{'execute':'query-status'}");
|
2014-07-15 16:57:06 +04:00
|
|
|
g_assert(qdict_haskey(resp, "return"));
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_unref(resp);
|
2014-07-15 16:57:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static QDict *ib700_program_and_wait(QTestState *s)
|
|
|
|
{
|
2017-09-11 20:19:48 +03:00
|
|
|
QDict *event, *data;
|
|
|
|
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_clock_step(s, NANOSECONDS_PER_SECOND * 40);
|
|
|
|
qmp_check_no_event(s);
|
2014-07-15 16:57:06 +04:00
|
|
|
|
|
|
|
/* 2 second limit */
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_outb(s, 0x443, 14);
|
2014-07-15 16:57:06 +04:00
|
|
|
|
|
|
|
/* Ping */
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_clock_step(s, NANOSECONDS_PER_SECOND);
|
|
|
|
qmp_check_no_event(s);
|
|
|
|
qtest_outb(s, 0x443, 14);
|
2014-07-15 16:57:06 +04:00
|
|
|
|
|
|
|
/* Disable */
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_clock_step(s, NANOSECONDS_PER_SECOND);
|
|
|
|
qmp_check_no_event(s);
|
|
|
|
qtest_outb(s, 0x441, 1);
|
|
|
|
qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
|
|
|
|
qmp_check_no_event(s);
|
2014-07-15 16:57:06 +04:00
|
|
|
|
|
|
|
/* Enable and let it fire */
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_outb(s, 0x443, 13);
|
|
|
|
qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
|
|
|
|
qmp_check_no_event(s);
|
|
|
|
qtest_clock_step(s, 2 * NANOSECONDS_PER_SECOND);
|
|
|
|
event = qtest_qmp_eventwait_ref(s, "WATCHDOG");
|
2017-09-11 20:19:48 +03:00
|
|
|
data = qdict_get_qdict(event, "data");
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_ref(data);
|
|
|
|
qobject_unref(event);
|
2017-09-11 20:19:48 +03:00
|
|
|
return data;
|
2014-07-15 16:57:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ib700_pause(void)
|
|
|
|
{
|
|
|
|
QDict *d;
|
2017-09-11 20:20:09 +03:00
|
|
|
QTestState *s = qtest_init("-watchdog-action pause -device ib700");
|
|
|
|
|
2014-07-15 16:57:06 +04:00
|
|
|
qtest_irq_intercept_in(s, "ioapic");
|
|
|
|
d = ib700_program_and_wait(s);
|
|
|
|
g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_unref(d);
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_qmp_eventwait(s, "STOP");
|
|
|
|
qtest_quit(s);
|
2014-07-15 16:57:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ib700_reset(void)
|
|
|
|
{
|
|
|
|
QDict *d;
|
2017-09-11 20:20:09 +03:00
|
|
|
QTestState *s = qtest_init("-watchdog-action reset -device ib700");
|
|
|
|
|
2014-07-15 16:57:06 +04:00
|
|
|
qtest_irq_intercept_in(s, "ioapic");
|
|
|
|
d = ib700_program_and_wait(s);
|
|
|
|
g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_unref(d);
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_qmp_eventwait(s, "RESET");
|
|
|
|
qtest_quit(s);
|
2014-07-15 16:57:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ib700_shutdown(void)
|
|
|
|
{
|
|
|
|
QDict *d;
|
2017-09-11 20:20:09 +03:00
|
|
|
QTestState *s;
|
|
|
|
|
|
|
|
s = qtest_init("-watchdog-action reset -no-reboot -device ib700");
|
2014-07-15 16:57:06 +04:00
|
|
|
qtest_irq_intercept_in(s, "ioapic");
|
|
|
|
d = ib700_program_and_wait(s);
|
|
|
|
g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_unref(d);
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_qmp_eventwait(s, "SHUTDOWN");
|
|
|
|
qtest_quit(s);
|
2014-07-15 16:57:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ib700_none(void)
|
|
|
|
{
|
|
|
|
QDict *d;
|
2017-09-11 20:20:09 +03:00
|
|
|
QTestState *s = qtest_init("-watchdog-action none -device ib700");
|
|
|
|
|
2014-07-15 16:57:06 +04:00
|
|
|
qtest_irq_intercept_in(s, "ioapic");
|
|
|
|
d = ib700_program_and_wait(s);
|
|
|
|
g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_unref(d);
|
2017-09-11 20:20:09 +03:00
|
|
|
qtest_quit(s);
|
2014-07-15 16:57:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
qtest_add_func("/wdt_ib700/pause", ib700_pause);
|
|
|
|
qtest_add_func("/wdt_ib700/reset", ib700_reset);
|
|
|
|
qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
|
|
|
|
qtest_add_func("/wdt_ib700/none", ib700_none);
|
|
|
|
|
2016-06-14 00:57:58 +03:00
|
|
|
return g_test_run();
|
2014-07-15 16:57:06 +04:00
|
|
|
}
|