示例#1
0
def test_init_success1(monkeypatch):
    # Set the procfs environment variable.
    monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok"))

    sockets = topology.Platform({0: quad_core()})

    with patch('intel.topology.parse', MagicMock(return_value=sockets)):
        temp_dir = tempfile.mkdtemp()
        init.init(os.path.join(temp_dir, "init"), 2, 1, "vertical", "vertical")
        c = config.Config(os.path.join(temp_dir, "init"))
        pools = c.pools()
        assert len(pools) == 3
        assert "controlplane" in pools
        assert "dataplane" in pools
        assert "infra" in pools
        cldp = pools["dataplane"].cpu_lists()
        clcp = pools["controlplane"].cpu_lists()
        clinfra = pools["infra"].cpu_lists()
        assert not pools["controlplane"].exclusive()
        assert pools["dataplane"].exclusive()
        assert not pools["infra"].exclusive()
        assert "0,4" in cldp
        assert "1,5" in cldp
        assert "2,6" in clcp
        assert "3,7" in clinfra
示例#2
0
def test_init_success1(monkeypatch):
    # Set the procfs environment variable.
    monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok"))

    sockets = topology.Platform({0: quad_core()})

    with patch(TOPOLOGY_PARSE, MagicMock(return_value=sockets)):
        temp_dir = tempfile.mkdtemp()
        init.init(os.path.join(temp_dir, "init"), 2, 1, "vertical", "vertical",
                  "-1")
        c = config.Config(os.path.join(temp_dir, "init"))
        pools = c.pools()
        assert len(pools) == 3
        assert "shared" in pools
        assert "exclusive" in pools
        assert "infra" in pools
        cl_exclusive = pools["exclusive"].cpu_lists()
        cl_shared = pools["shared"].cpu_lists()
        cl_infra = pools["infra"].cpu_lists()
        assert not pools["shared"].exclusive()
        assert pools["exclusive"].exclusive()
        assert not pools["infra"].exclusive()
        assert "0,4" in cl_exclusive
        assert "1,5" in cl_exclusive
        assert "2,6" in cl_shared
        assert "3,7" in cl_infra
示例#3
0
def test_init_failure3(monkeypatch):
    # Set the procfs environment variable.
    monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok"))

    sockets = topology.Platform({
        0: topology.Socket(0, {
            0: topology.Core(0, {
                0: topology.CPU(0),
                4: topology.CPU(4)
            }),
            1: topology.Core(1, {
                1: topology.CPU(1),
                5: topology.CPU(5)
            }),
            2: topology.Core(2, {
                2: topology.CPU(2),
                6: topology.CPU(6)
            })
        })
    })

    with patch('intel.topology.parse', MagicMock(return_value=sockets)):
        temp_dir = tempfile.mkdtemp()
        with pytest.raises(RuntimeError) as err:
            init.init(os.path.join(temp_dir, "init"), 2, 1, "vertical",
                      "vertical")
        assert err is not None
        expected_msg = "No more free cores left to assign for infra"
        assert err.value.args[0] == expected_msg
def return_fake_platform():
    sockets = dict()
    sockets["0"] = topology.Socket("0")
    sockets["1"] = topology.Socket("1")

    core0 = topology.Core("0")
    core0.pool = "exclusive"
    cpu0 = topology.CPU("0")
    cpu0.isolated = True
    cpu3 = topology.CPU("3")
    cpu3.isolated = True
    core0.cpus["0"] = cpu0
    core0.cpus["3"] = cpu3
    sockets["0"].cores["0"] = core0

    core1 = topology.Core("1")
    core1.pool = "shared"
    cpu1 = topology.CPU("1")
    cpu1.isolated = True
    cpu4 = topology.CPU("4")
    cpu4.isolated = True
    core1.cpus["1"] = cpu1
    core1.cpus["4"] = cpu4
    sockets["0"].cores["1"] = core1

    core2 = topology.Core("2")
    core2.pool = "shared"
    cpu2 = topology.CPU("2")
    cpu5 = topology.CPU("5")
    core2.cpus["2"] = cpu2
    core2.cpus["5"] = cpu5
    sockets["0"].cores["2"] = core2

    return topology.Platform(sockets)
def test_init_failure2(monkeypatch):
    # Set the procfs environment variable.
    monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok"))

    sockets = topology.Platform({
        0:
        topology.Socket(
            0, {
                0: topology.Core(0, {
                    0: topology.CPU(0),
                    4: topology.CPU(4)
                }),
                1: topology.Core(1, {
                    1: topology.CPU(1),
                    5: topology.CPU(5)
                })
            })
    })

    with patch('intel.topology.parse', MagicMock(return_value=sockets)):
        with pytest.raises(RuntimeError) as err:
            init.init(2, 1, "vertical", "vertical", "-1", "fake-namespace")
        assert err is not None
        expected_msg = "No more free cores left to assign for shared"
        assert err.value.args[0] == expected_msg
def return_cores():
    sockets = topology.Socket(
        0, {
            0: topology.Core(0, {
                0: topology.CPU(0),
                4: topology.CPU(4)
            }),
            1: topology.Core(1, {
                1: topology.CPU(1),
                5: topology.CPU(5)
            }),
            2: topology.Core(2, {
                2: topology.CPU(2),
                6: topology.CPU(6)
            }),
            3: topology.Core(3, {
                3: topology.CPU(3),
                7: topology.CPU(7)
            }),
            4: topology.Core(4, {
                4: topology.CPU(4),
                8: topology.CPU(8)
            })
        })

    return topology.Platform({0: sockets})
示例#7
0
def test_init_config_exists_error(monkeypatch, caplog):
    # Set the procfs environment variable.
    monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok"))

    sockets = topology.Platform({0: quad_core()})

    with patch('intel.topology.parse', MagicMock(return_value=sockets)):
        temp_dir = tempfile.mkdtemp()
        # Init
        init.init(os.path.join(temp_dir, "init"), 2, 1, "vertical", "vertical")

        # Try to init again, configuration should already exist
        init.init(os.path.join(temp_dir, "init"), 2, 1, "vertical", "vertical")

        caplog_tuple = caplog.record_tuples
        assert caplog_tuple[-1][2] == "Configuration directory already exists."
示例#8
0
def test_init_failure1(monkeypatch):
    # Set the procfs environment variable.
    monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok"))

    sockets = topology.Platform({
        0: topology.Socket(0, {
            0: topology.Core(0, {
                0: topology.CPU(0),
                2: topology.CPU(2)
            }),
            1: topology.Core(1, {
                1: topology.CPU(1),
                3: topology.CPU(3)
            })
        })
    })

    with patch('intel.topology.parse', MagicMock(return_value=sockets)):
        temp_dir = tempfile.mkdtemp()
        with pytest.raises(RuntimeError):
            init.init(os.path.join(temp_dir, "init"), 2, 1, "vertical",
                      "vertical")