File: test_device.py

package info (click to toggle)
drgn 0.0.33-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,892 kB
  • sloc: python: 59,081; ansic: 51,400; awk: 423; makefile: 339; sh: 113
file content (33 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later

import os

from drgn import TypeKind
from drgn.helpers.linux.device import bus_for_each_dev, class_for_each_device, dev_name
from tests.linux_kernel import LinuxKernelTestCase


class TestDevice(LinuxKernelTestCase):
    def test_bus_for_each_dev(self):
        # This also tests dev_name() and bus_to_subsys().
        self.assertCountEqual(
            [
                dev_name(dev)
                for dev in bus_for_each_dev(self.prog["cpu_subsys"].address_of_())
            ],
            os.listdir(b"/sys/bus/cpu/devices"),
        )

    def test_class_for_each_device(self):
        # Before Linux kernel commit 7671284b6c77 ("/dev/mem: make mem_class a
        # static const structure") (in v6.5), mem_class is a pointer instead of
        # a struct.
        mem_class = self.prog["mem_class"]
        if mem_class.type_.unaliased_kind() != TypeKind.POINTER:
            mem_class = mem_class.address_of_()
        # This also tests dev_name() and class_to_subsys().
        self.assertCountEqual(
            [dev_name(dev) for dev in class_for_each_device(mem_class)],
            os.listdir(b"/sys/class/mem"),
        )