Ejemplo n.º 1
0
def test_platform_util_wmic_parsing(platform_mock, subprocess_mock, os_mock):
    """
    Verifies that platform_utils gives us the proper values that we expect
    based on the wmic_output string provided.
    """
    platform_mock.return_value = "Windows"
    os_mock.return_value = True
    subprocess_mock.return_value = platform_config.WMIC_OUTPUT
    platform_util = PlatformUtil(MagicMock(verbose=True))
    platform_util.windows_init()
    assert platform_util.num_cpu_sockets == 2
    assert platform_util.num_cores_per_socket == 28
    assert platform_util.num_threads_per_core == 28
    assert platform_util.num_logical_cpus == 56
    assert platform_util.num_numa_nodes == 0
def test_platform_util_lscpu_parsing(platform_mock, subprocess_mock, os_mock):
    """
    Verifies that platform_utils gives us the proper values that we expect
    based on the lscpu_output string provided.
    """
    platform_mock.return_value = platform_config.SYSTEM_TYPE
    os_mock.return_value = True
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    platform_util = PlatformUtil(MagicMock(verbose=True))
    platform_util.linux_init()
    assert platform_util.num_cpu_sockets == 2
    assert platform_util.num_cores_per_socket == 28
    assert platform_util.num_threads_per_core == 2
    assert platform_util.num_logical_cpus == 112
    assert platform_util.num_numa_nodes == 2
Ejemplo n.º 3
0
def test_platform_utils_num_sockets_with_cpuset(get_cpuset_mock, platform_mock,
                                                subprocess_mock, os_mock,
                                                cpuset_range,
                                                expected_num_sockets):
    """
    Checks that the number of sockets in platform_utils reflects the proper value based on
    the cpuset. If the cores being used by the container in the cpuset are all on one socket,
    then the num_cpu_sockets should be 1, even if the system itself has 2 sockets (since the
    container only has access to 1).
    """
    platform_mock.return_value = platform_config.SYSTEM_TYPE
    os_mock.return_value = True
    get_cpuset_mock.return_value = cpuset_range
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    platform_util = PlatformUtil(MagicMock(verbose=True))
    platform_util.linux_init()
    assert platform_util.num_cpu_sockets == expected_num_sockets
def test_platform_util_unsupported_os(platform_mock, subprocess_mock, os_mock):
    """
    Verifies that platform_utils gives us the proper values that we expect
    based on the lscpu_output string provided.
    """
    os_mock.return_value = True
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    # Mac is not supported yet
    platform_mock.return_value = "Mac"
    with pytest.raises(NotImplementedError) as e:
        PlatformUtil(MagicMock(verbose=True))
    assert "Mac Support not yet implemented" in str(e)
    # Windows is not supported yet
    platform_mock.return_value = "Windows"
    with pytest.raises(NotImplementedError) as e:
        PlatformUtil(MagicMock(verbose=False))
    assert "Windows Support not yet implemented" in str(e)
Ejemplo n.º 5
0
def test_platform_util_with_no_args(platform_mock, subprocess_mock):
    """
    Verifies that PlatformUtil object can be created with an empty string, as needed
    by the performance Jupyter notebooks.
    """
    platform_mock.return_value = platform_config.SYSTEM_TYPE
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    platform_util = PlatformUtil("")
    assert platform_util.num_logical_cpus == 112
Ejemplo n.º 6
0
def test_get_list_from_string_ranges(
    get_cpuset_mock,
    platform_mock,
    subprocess_mock,
    os_mock,
    cpuset_range,
    expected_list,
):
    """
    Tests the PlatformUtils _get_list_from_string_ranges function that converts string
    number ranges to an integer list.
    """
    platform_mock.return_value = platform_config.SYSTEM_TYPE
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    get_cpuset_mock.return_value = cpuset_range
    os_mock.return_value = True
    platform_util = PlatformUtil(MagicMock())
    result = platform_util._get_list_from_string_ranges(cpuset_range)
    assert result == expected_list
Ejemplo n.º 7
0
def test_numa_cpu_core_list(subprocess_mock, subprocess_popen_mock, platform_mock, os_mock):
    """ Test the platform utils to ensure that we are getting the proper core lists """
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    subprocess_popen_mock.return_value.stdout.readlines.return_value = platform_config.NUMA_CORES_OUTPUT
    platform_mock.return_value = platform_config.SYSTEM_TYPE
    os_mock.return_value = True
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    platform_util = PlatformUtil(MagicMock(verbose=True))

    # ensure there are 2 items in the list since there are 2 sockets
    assert len(platform_util.cpu_core_list) == 2

    # ensure each list of cores has the length of the number of cores per socket
    for core_list in platform_util.cpu_core_list:
        assert len(core_list) == platform_util.num_cores_per_socket
Ejemplo n.º 8
0
def test_platform_util_lscpu_parsing(platform_mock, subprocess_mock, os_mock):
    """
    Verifies that platform_utils gives us the proper values that we expect
    based on the lscpu_output string provided.
    """
    platform_mock.return_value = platform_config.SYSTEM_TYPE
    os_mock.return_value = True
    subprocess_mock.side_effect = [
        platform_config.LSCPU_PATH, platform_config.LSCPU_OUTPUT
    ]
    platform_util = PlatformUtil()
    assert platform_util.num_cpu_sockets() == 2
    assert platform_util.num_cores_per_socket() == 28
    assert platform_util.num_threads_per_core() == 2
    assert platform_util.num_logical_cpus() == 112
    assert platform_util.num_numa_nodes() == 2
Ejemplo n.º 9
0
def test_numa_cpu_core_list_cpuset(path_exists_mock, subprocess_mock,
                                   subprocess_popen_mock, platform_mock,
                                   os_mock, cpuset_range, expected_core_list):
    """ Test the platform utils to ensure that we are getting the proper core lists """
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    subprocess_popen_mock.return_value.stdout.readlines.return_value = platform_config.NUMA_CORES_OUTPUT
    platform_mock.return_value = platform_config.SYSTEM_TYPE
    os_mock.return_value = True
    subprocess_mock.return_value = platform_config.LSCPU_OUTPUT
    path_exists_mock.return_value = True
    cpuset_mock = mock_open(read_data=cpuset_range)
    with patch("builtins.open", cpuset_mock):
        platform_util = PlatformUtil(
            MagicMock(verbose=True, numa_cores_per_instance=4))

    # ensure there are 2 items in the list since there are 2 sockets
    assert len(platform_util.cpu_core_list) == 2

    # Check that the core list matches the ranges defined for the cpuset file read
    assert platform_util.cpu_core_list == expected_core_list