| 1 |
# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
from drgn import FaultError |
| 5 |
from drgn.helpers.linux.cpumask import for_each_online_cpu |
| 6 |
from drgn.helpers.linux.percpu import per_cpu |
| 7 |
from drgn.helpers.linux.timer import hrtimer_clock_base_for_each, timer_base_for_each |
| 8 |
from tests.linux_kernel import LinuxKernelTestCase, skip_unless_have_test_kmod |
| 9 |
|
| 10 |
|
| 11 |
@skip_unless_have_test_kmod |
| 12 |
class TestTimer(LinuxKernelTestCase): |
| 13 |
def test_timer_base_for_each_timer(self): |
| 14 |
timer = self.prog["drgn_test_timer"].address_of_() |
| 15 |
# We can race with the kernel modifying the list and either fault or |
| 16 |
# miss our timer, so retry a few times. |
| 17 |
for _ in range(10): |
| 18 |
for cpu in for_each_online_cpu(self.prog): |
| 19 |
for base in per_cpu(self.prog["timer_bases"], cpu): |
| 20 |
try: |
| 21 |
if timer in timer_base_for_each(base): |
| 22 |
return |
| 23 |
except FaultError: |
| 24 |
pass |
| 25 |
self.fail("timer not found") |
| 26 |
|
| 27 |
def test_hrtimer_clock_base_for_each_hrtimer(self): |
| 28 |
hrtimer = self.prog["drgn_test_hrtimer"].address_of_() |
| 29 |
# We can race with the kernel modifying the rbtree and either fault or |
| 30 |
# miss our timer, so retry a few times. |
| 31 |
for _ in range(10): |
| 32 |
for cpu in for_each_online_cpu(self.prog): |
| 33 |
for clock_base in per_cpu(self.prog["hrtimer_bases"], cpu).clock_base: |
| 34 |
try: |
| 35 |
if hrtimer in hrtimer_clock_base_for_each( |
| 36 |
clock_base.address_of_() |
| 37 |
): |
| 38 |
return |
| 39 |
except FaultError: |
| 40 |
pass |
| 41 |
self.fail("hrtimer not found") |