Beispiel #1
0
def cpu_all_online():
    return [
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(0))),
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(1))),
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(2))),
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(3)))
    ]
Beispiel #2
0
def test_cpu_core_online():
    with pytest.raises(SkipException):
        CpuCoreOnline(context_wrap(""))

    path = "/sys/devices/system/cpu/cpu{0}/online"
    p = CpuCoreOnline(context_wrap("0", path=path.format(0)))
    assert p.core_id == 0
    assert not p.on
    assert repr(p) == "[Core 0: Offline]"
    p = CpuCoreOnline(context_wrap("1", path=path.format(1)))
    assert p.core_id == 1
    assert p.on
    assert repr(p) == "[Core 1: Online]"
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
def test_without_hyperthreading_some_online():
    online = [
        CpuCoreOnline(context_wrap("1", path=ONLINE_PATH.format(0))),
        CpuCoreOnline(context_wrap("1", 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))),
        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 not cpu_topology.online(2)
    assert cpu_topology.siblings(2) == []
    assert not cpu_topology.online(3)
    assert cpu_topology.siblings(3) == []
    assert cpu_topology.all_solitary