def test_get_child():
    """Test getting child of a sysctl definition."""
    source = KernelSourceTree("kernel/linux-3.10.0-957.el7",
                              KernelLlvmSourceBuilder)
    kernel_module = source.get_module_for_symbol("sysctl_base_table")
    sysctl_module = LlvmSysctlModule(kernel_module, "sysctl_base_table")
    assert sysctl_module.get_child("vm").name == "vm_table"
Exemple #2
0
def mod():
    """
    Build LlvmSysctlModule for net.core.* sysctl options shared among tests.
    """
    source = KernelSource("kernel/linux-3.10.0-862.el7", True)
    kernel_module = source.get_module_from_source("net/core/sysctl_net_core.c")
    yield LlvmSysctlModule(kernel_module, "net_core_table")
    source.finalize()
def mod():
    """
    Build LlvmSysctlModule for net.core.* sysctl options shared among tests.
    """
    source = KernelSourceTree("kernel/linux-3.10.0-957.el7",
                              KernelLlvmSourceBuilder)
    kernel_module = source.get_module_for_symbol("net_core_table")
    yield LlvmSysctlModule(kernel_module, "net_core_table")
    source.finalize()
    def get_sysctl_module(self, sysctl):
        """
        Get the LLVM module containing the definition of a sysctl option.
        :param sysctl: sysctl option to search for
        :return: Instance of LlvmSysctlModule.
        """
        # The sysctl is composed of entries separated by dots. Entries form
        # a hierarchy - each entry is a child of its predecessor (i.e. all
        # entries except the last one point to sysctl tables). We follow
        # the hierarchy and build the source containing the parent table of
        # the last entry.
        entries = sysctl.split(".")
        if entries[0] in ["kernel", "vm", "fs", "debug", "dev"]:
            src = "kernel/sysctl.c"
            table = "sysctl_base_table"
        elif entries[0] == "net":
            if entries[1] == "ipv4":
                if entries[2] == "conf":
                    src = "net/ipv4/devinet.c"
                    table = "devinet_sysctl.1"
                    entries = entries[4:]
                else:
                    src = "net/ipv4/sysctl_net_ipv4.c"
                    table = "ipv4_table"
                    entries = entries[2:]
            elif entries[1] == "core":
                src = "net/core/sysctl_net_core.c"
                table = "net_core_table"
                entries = entries[2:]
            else:
                raise SourceNotFoundException(sysctl)
        else:
            raise SourceNotFoundException(sysctl)

        for (i, entry) in enumerate(entries):
            # Build the file normally and then create a corresponding
            # LlvmSysctlModule with the obtained sysctl table.
            kernel_mod = self.get_module_from_source(src)
            sysctl_mod = LlvmSysctlModule(kernel_mod, table)

            if i == len(entries) - 1:
                return sysctl_mod
            table = sysctl_mod.get_child(entry).name
            src = self.find_srcs_with_symbol_def(table)[0]
        raise SourceNotFoundException(sysctl)
Exemple #5
0
def test_get_child():
    """Test getting child of a sysctl definition."""
    source = KernelSource("kernel/linux-3.10.0-862.el7", True)
    kernel_module = source.get_module_from_source("kernel/sysctl.c")
    sysctl_module = LlvmSysctlModule(kernel_module, "sysctl_base_table")
    assert sysctl_module.get_child("vm").name == "vm_table"