Debian Codegraph @

tests/linux_kernel/crash_commands/test_timer.py

raw
1 # Copyright (c) Meta Platforms, Inc. and affiliates.
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 import re
5
6 from drgn import Object
7 from tests.linux_kernel import online_cpus, skip_unless_have_test_kmod
8 from tests.linux_kernel.crash_commands import CrashCommandTestCase
9
10
11 @skip_unless_have_test_kmod
12 class TestTimer(CrashCommandTestCase):
13 def test_timer(self):
14 cmd = self.check_crash_command("timer")
15 self.assertIn("<drgn_test_timer_fn", cmd.stdout)
16 self.assertIn("timer_base_for_each(", cmd.drgn_option.stdout)
17 self.assertTrue(cmd.drgn_option.globals["name"], "BASE_")
18 for variable in (
19 "jiffies",
20 "base",
21 "timer",
22 "expires",
23 "tte",
24 "function",
25 ):
26 self.assertIsInstance(cmd.drgn_option.globals[variable], Object)
27
28 def test_timer_cpu(self):
29 cpu = min(online_cpus())
30 cmd = self.check_crash_command(f"timer -C {cpu}")
31 self.assertEqual(
32 set(re.findall(r"TIMER_BASES\[([0-9]+)\]", cmd.stdout)), {str(cpu)}
33 )
34 self.assertEqual(cmd.drgn_option.globals["base"].cpu, cpu)
35
36 def test_hrtimer(self):
37 cmd = self.check_crash_command("timer -r")
38 self.assertIn("<drgn_test_hrtimer_fn>", cmd.stdout)
39 self.assertIn("hrtimer_clock_base_for_each(", cmd.drgn_option.stdout)
40 for variable in (
41 "cpu_base",
42 "clock_base",
43 "clock",
44 "current",
45 "hrtimer",
46 "softexpires",
47 "expires",
48 "tte",
49 "function",
50 ):
51 self.assertIsInstance(cmd.drgn_option.globals[variable], Object)
52
53 def test_hrtimer_cpu(self):
54 cpu = min(online_cpus())
55 cmd = self.check_crash_command(f"timer -r -C {cpu}")
56 self.assertEqual(set(re.findall(r"CPU: ([0-9]+)", cmd.stdout)), {str(cpu)})
57 self.assertEqual(cmd.drgn_option.globals["clock_base"].cpu_base.cpu, cpu)