mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
tests: Add ptimer tests
Ptimer is a generic countdown timer helper that is used by many timer device models as well as by the QEMU core. Add QTests for the ptimer. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Message-id: 1de89fe6e1ccaf6c8071ee3469e1a844df948359.1473252818.git.digetx@gmail.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
committed by
Peter Maydell
parent
2a8b58703e
commit
5b262bb697
@@ -3,6 +3,11 @@
|
||||
#include "migration/vmstate.h"
|
||||
|
||||
const VMStateDescription vmstate_dummy = {};
|
||||
const VMStateInfo vmstate_info_uint8;
|
||||
const VMStateInfo vmstate_info_uint32;
|
||||
const VMStateInfo vmstate_info_uint64;
|
||||
const VMStateInfo vmstate_info_int64;
|
||||
const VMStateInfo vmstate_info_timer;
|
||||
|
||||
int vmstate_register_with_alias_id(DeviceState *dev,
|
||||
int instance_id,
|
||||
|
||||
@@ -296,6 +296,7 @@ check-qtest-xtensaeb-y = $(check-qtest-xtensa-y)
|
||||
check-qtest-s390x-y = tests/boot-serial-test$(EXESUF)
|
||||
|
||||
check-qtest-generic-y += tests/qom-test$(EXESUF)
|
||||
check-qtest-generic-y += tests/ptimer-test$(EXESUF)
|
||||
|
||||
qapi-schema += alternate-any.json
|
||||
qapi-schema += alternate-array.json
|
||||
@@ -658,6 +659,7 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y)
|
||||
tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-obj-y)
|
||||
tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y)
|
||||
tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
|
||||
tests/ptimer-test$(EXESUF): tests/ptimer-test.o tests/ptimer-test-stubs.o hw/core/ptimer.o
|
||||
|
||||
tests/migration/stress$(EXESUF): tests/migration/stress.o
|
||||
$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ," LINK $(TARGET_DIR)$@")
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Stubs for the ptimer-test
|
||||
*
|
||||
* Author: Dmitry Osipenko <digetx@gmail.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "sysemu/replay.h"
|
||||
|
||||
#include "ptimer-test.h"
|
||||
|
||||
struct QEMUBH {
|
||||
QEMUBHFunc *cb;
|
||||
void *opaque;
|
||||
};
|
||||
|
||||
QEMUTimerListGroup main_loop_tlg;
|
||||
|
||||
int64_t ptimer_test_time_ns;
|
||||
|
||||
void timer_init_tl(QEMUTimer *ts,
|
||||
QEMUTimerList *timer_list, int scale,
|
||||
QEMUTimerCB *cb, void *opaque)
|
||||
{
|
||||
ts->timer_list = timer_list;
|
||||
ts->cb = cb;
|
||||
ts->opaque = opaque;
|
||||
ts->scale = scale;
|
||||
ts->expire_time = -1;
|
||||
}
|
||||
|
||||
void timer_mod(QEMUTimer *ts, int64_t expire_time)
|
||||
{
|
||||
QEMUTimerList *timer_list = ts->timer_list;
|
||||
QEMUTimer *t = &timer_list->active_timers;
|
||||
|
||||
while (t->next != NULL) {
|
||||
if (t->next == ts) {
|
||||
break;
|
||||
}
|
||||
|
||||
t = t->next;
|
||||
}
|
||||
|
||||
ts->expire_time = MAX(expire_time * ts->scale, 0);
|
||||
ts->next = NULL;
|
||||
t->next = ts;
|
||||
}
|
||||
|
||||
void timer_del(QEMUTimer *ts)
|
||||
{
|
||||
QEMUTimerList *timer_list = ts->timer_list;
|
||||
QEMUTimer *t = &timer_list->active_timers;
|
||||
|
||||
while (t->next != NULL) {
|
||||
if (t->next == ts) {
|
||||
t->next = ts->next;
|
||||
return;
|
||||
}
|
||||
|
||||
t = t->next;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t qemu_clock_get_ns(QEMUClockType type)
|
||||
{
|
||||
return ptimer_test_time_ns;
|
||||
}
|
||||
|
||||
int64_t qemu_clock_deadline_ns_all(QEMUClockType type)
|
||||
{
|
||||
QEMUTimerList *timer_list = main_loop_tlg.tl[type];
|
||||
QEMUTimer *t = timer_list->active_timers.next;
|
||||
int64_t deadline = -1;
|
||||
|
||||
while (t != NULL) {
|
||||
if (deadline == -1) {
|
||||
deadline = t->expire_time;
|
||||
} else {
|
||||
deadline = MIN(deadline, t->expire_time);
|
||||
}
|
||||
|
||||
t = t->next;
|
||||
}
|
||||
|
||||
return deadline;
|
||||
}
|
||||
|
||||
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
|
||||
{
|
||||
QEMUBH *bh = g_new(QEMUBH, 1);
|
||||
|
||||
bh->cb = cb;
|
||||
bh->opaque = opaque;
|
||||
|
||||
return bh;
|
||||
}
|
||||
|
||||
void replay_bh_schedule_event(QEMUBH *bh)
|
||||
{
|
||||
bh->cb(bh->opaque);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* QTest testcase for the ptimer
|
||||
*
|
||||
* Author: Dmitry Osipenko <digetx@gmail.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PTIMER_TEST_H
|
||||
#define PTIMER_TEST_H
|
||||
|
||||
extern bool qtest_allowed;
|
||||
|
||||
extern int64_t ptimer_test_time_ns;
|
||||
|
||||
struct QEMUTimerList {
|
||||
QEMUTimer active_timers;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user