File: test_nodemask.py

package info (click to toggle)
drgn 0.0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,956 kB
  • sloc: ansic: 49,446; python: 45,054; awk: 423; makefile: 339; sh: 114
file content (42 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (3)
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
34
35
36
37
38
39
40
41
42
# Copyright (c) ByteDance, Inc. and its affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later

from pathlib import Path
import unittest

from drgn.helpers.linux.nodemask import for_each_node, for_each_online_node, node_state
from tests.linux_kernel import LinuxKernelTestCase, parse_range_list

NODE_PATH = Path("/sys/devices/system/node")


@unittest.skipUnless(NODE_PATH.exists(), "kernel does not support NUMA")
class TestNodeMask(LinuxKernelTestCase):
    @staticmethod
    def _parse_node_list(name):
        return parse_range_list((NODE_PATH / name).read_text())

    def _test_for_each_node(self, func, name):
        self.assertEqual(list(func(self.prog)), sorted(self._parse_node_list(name)))

    def test_for_each_node(self):
        self._test_for_each_node(for_each_node, "possible")

    def test_for_each_online_node(self):
        self._test_for_each_node(for_each_online_node, "online")

    def _test_node_state(self, state_name, file_name):
        possible = self._parse_node_list("possible")
        expected = self._parse_node_list(file_name)
        state = self.prog[state_name]
        for node in possible:
            self.assertEqual(node_state(node, state), node in expected)

    def test_node_state(self):
        self._test_node_state("N_NORMAL_MEMORY", "has_normal_memory")
        # N_GENERIC_INITIATOR was added in Linux kernel commit 894c26a1c274
        # ("ACPI: Support Generic Initiator only domains") (in v5.10). Most of
        # the time it is unset, so if it exists we can use it to test the unset
        # case.
        if (NODE_PATH / "has_generic_initiator").exists():
            self._test_node_state("N_GENERIC_INITIATOR", "has_generic_initiator")