Exemple #1
0
def test_doc_examples(cpu_all_online):
    siblings = [
        CpuSiblings(context_wrap("0,2", path=SIBLINGS_PATH.format(0))),
        CpuSiblings(context_wrap("1,3", path=SIBLINGS_PATH.format(1))),
        CpuSiblings(context_wrap("0,2", path=SIBLINGS_PATH.format(2))),
        CpuSiblings(context_wrap("1,3", path=SIBLINGS_PATH.format(3)))
    ]

    env = {
        "cpu_topology": CpuTopology(cpu_all_online, siblings),
    }
    failed, total = doctest.testmod(smt, globs=env)
    assert failed == 0
Exemple #2
0
def test_without_hyperthreading_all_online_missing_cpu0_online_file():
    online = [
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(1))),
    ]
    siblings = [
        CpuSiblings(context_wrap("0", path=SIBLINGS_PATH.format(0))),
        CpuSiblings(context_wrap("1", path=SIBLINGS_PATH.format(1)))
    ]

    cpu_topology = CpuTopology(online, siblings)
    assert cpu_topology.online(0)
    assert cpu_topology.siblings(0) == [0]
    assert cpu_topology.online(1)
    assert cpu_topology.siblings(1) == [1]
    assert cpu_topology.all_solitary
Exemple #3
0
def test_cpu_siblings():
    with pytest.raises(SkipException):
        CpuSiblings(context_wrap(""))

    path = "/sys/devices/system/cpu/cpu{0}/topology/thread_siblings_list"
    p = CpuSiblings(context_wrap("0,2", path=path.format(0)))
    assert p.core_id == 0
    assert p.siblings == [0, 2]
    assert repr(p) == "[Core 0 Siblings: [0, 2]]"
    p = CpuSiblings(context_wrap("1-3", path=path.format(3)))
    assert p.core_id == 3
    assert p.siblings == [1, 2, 3]
    assert repr(p) == "[Core 3 Siblings: [1, 2, 3]]"
    p = CpuSiblings(context_wrap("1", path=path.format(1)))
    assert p.core_id == 1
    assert p.siblings == [1]
    assert repr(p) == "[Core 1 Siblings: [1]]"
Exemple #4
0
def test_without_hyperthreading_all_online(cpu_all_online):
    siblings = [
        CpuSiblings(context_wrap("0", path=SIBLINGS_PATH.format(0))),
        CpuSiblings(context_wrap("1", path=SIBLINGS_PATH.format(1))),
        CpuSiblings(context_wrap("2", path=SIBLINGS_PATH.format(2))),
        CpuSiblings(context_wrap("3", path=SIBLINGS_PATH.format(3)))
    ]

    cpu_topology = CpuTopology(cpu_all_online, siblings)
    assert cpu_topology.online(0)
    assert cpu_topology.siblings(0) == [0]
    assert cpu_topology.online(1)
    assert cpu_topology.siblings(1) == [1]
    assert cpu_topology.online(2)
    assert cpu_topology.siblings(2) == [2]
    assert cpu_topology.online(3)
    assert cpu_topology.siblings(3) == [3]
    assert cpu_topology.all_solitary
Exemple #5
0
def test_doc_examples():
    path_cpu_core_online = "/sys/devices/system/cpu/cpu0/online"
    path_cpu_siblings = "/sys/devices/system/cpu/cpu0/topology/thread_siblings_list"

    env = {
        "cpu_smt": CpuSMTActive(context_wrap("1")),
        "cpu_core": CpuCoreOnline(context_wrap("1",
                                               path=path_cpu_core_online)),
        "cpu_siblings": CpuSiblings(context_wrap("0,2",
                                                 path=path_cpu_siblings))
    }
    failed, total = doctest.testmod(smt, globs=env)
    assert failed == 0
Exemple #6
0
def test_hyperthreading_some_online():
    online = [
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(0))),
        CpuCoreOnline(context_wrap("0", path=ONLINE_PATH.format(1))),
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(2))),
        CpuCoreOnline(context_wrap("0", path=ONLINE_PATH.format(3)))
    ]
    siblings = [
        CpuSiblings(context_wrap("0,2", path=SIBLINGS_PATH.format(0))),
        CpuSiblings(context_wrap("0,2", path=SIBLINGS_PATH.format(2)))
    ]

    cpu_topology = CpuTopology(online, siblings)
    assert cpu_topology.online(0)
    assert cpu_topology.siblings(0) == [0, 2]
    assert not cpu_topology.online(1)
    assert cpu_topology.siblings(1) == []
    assert cpu_topology.online(2)
    assert cpu_topology.siblings(2) == [0, 2]
    assert not cpu_topology.online(3)
    assert cpu_topology.siblings(3) == []
    assert not cpu_topology.all_solitary
Exemple #7
0
def test_wrong_index():
    online = [
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(0))),
        CpuCoreOnline(context_wrap("0", path=ONLINE_PATH.format(1))),
        CpuCoreOnline(context_wrap("0", path=ONLINE_PATH.format(2))),
        CpuCoreOnline(context_wrap("0", path=ONLINE_PATH.format(3)))
    ]
    siblings = [
        CpuSiblings(context_wrap("0", path=SIBLINGS_PATH.format(0))),
    ]

    c = CpuTopology(online, siblings)
    assert c.online(-1) is None
    assert c.siblings(-1) is None
    assert c.online(4) is None
    assert c.siblings(4) is None