summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/loongarch/arch_timer.c
diff options
context:
space:
mode:
authorBibo Mao <maobibo@loongson.cn>2025-11-28 14:49:48 +0800
committerHuacai Chen <chenhuacai@loongson.cn>2025-11-28 14:49:48 +0800
commit0f90fa6e2e9d98349492d9968c11ceaf2f958c98 (patch)
tree6492a70e3f0c693e1ee448b4ec83cd0612f8f169 /tools/testing/selftests/kvm/loongarch/arch_timer.c
parent4e8824094069b04e3b3583d855c975ccb6a9bec5 (diff)
KVM: LoongArch: selftests: Add time counter test case
With time counter test, it is to verify that time count starts from 0 and always grows up then. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Diffstat (limited to 'tools/testing/selftests/kvm/loongarch/arch_timer.c')
-rw-r--r--tools/testing/selftests/kvm/loongarch/arch_timer.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/loongarch/arch_timer.c b/tools/testing/selftests/kvm/loongarch/arch_timer.c
index baa30fd296f5..355ecac30954 100644
--- a/tools/testing/selftests/kvm/loongarch/arch_timer.c
+++ b/tools/testing/selftests/kvm/loongarch/arch_timer.c
@@ -136,10 +136,40 @@ static void guest_test_emulate_timer(uint32_t cpu)
local_irq_enable();
}
+static void guest_time_count_test(uint32_t cpu)
+{
+ uint32_t config_iter;
+ unsigned long start, end, prev, us;
+
+ /* Assuming that test case starts to run in 1 second */
+ start = timer_get_cycles();
+ us = msec_to_cycles(1000);
+ __GUEST_ASSERT(start <= us,
+ "start = 0x%lx, us = 0x%lx.\n",
+ start, us);
+
+ us = msec_to_cycles(test_args.timer_period_ms);
+ for (config_iter = 0; config_iter < test_args.nr_iter; config_iter++) {
+ start = timer_get_cycles();
+ end = start + us;
+ /* test time count growing up always */
+ while (start < end) {
+ prev = start;
+ start = timer_get_cycles();
+ __GUEST_ASSERT(prev <= start,
+ "prev = 0x%lx, start = 0x%lx.\n",
+ prev, start);
+ }
+ }
+}
+
static void guest_code(void)
{
uint32_t cpu = guest_get_vcpuid();
+ /* must run at first */
+ guest_time_count_test(cpu);
+
timer_irq_enable();
local_irq_enable();
guest_test_period_timer(cpu);