2018-07-04 15:39:44 +01:00
|
|
|
# Copyright 2018 ARM Limited
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
2017-03-06 17:29:15 +00:00
|
|
|
import unittest
|
|
|
|
from nose.tools import assert_equal
|
|
|
|
from mock.mock import Mock
|
|
|
|
|
|
|
|
from wa.utils.misc import resolve_cpus, resolve_unique_domain_cpus
|
|
|
|
|
|
|
|
class TestRuntimeParameterUtils(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_resolve_cpu(self):
|
|
|
|
# Set up a mock target
|
|
|
|
mock = Mock()
|
|
|
|
mock.big_core = "A72"
|
|
|
|
mock.little_core = "A53"
|
|
|
|
mock.core_names = ['A72', 'A72', 'A53', 'A53']
|
|
|
|
mock.number_of_cpus = 4
|
|
|
|
def mock_core_cpus(core):
|
|
|
|
return [i for i, c in enumerate(mock.core_names) if c == core]
|
|
|
|
def mock_online_cpus():
|
|
|
|
return [0, 1, 2]
|
|
|
|
def mock_offline_cpus():
|
|
|
|
return [3]
|
2017-12-06 15:11:32 +00:00
|
|
|
def mock_related_cpus(core):
|
2017-03-06 17:29:15 +00:00
|
|
|
if core in [0, 1]:
|
|
|
|
return [0, 1]
|
|
|
|
elif core in [2, 3]:
|
|
|
|
return [2, 3]
|
|
|
|
|
|
|
|
mock.list_online_cpus = mock_online_cpus
|
|
|
|
mock.list_offline_cpus = mock_offline_cpus
|
|
|
|
mock.core_cpus = mock_core_cpus
|
|
|
|
mock.core_cpus = mock_core_cpus
|
2017-12-06 15:11:32 +00:00
|
|
|
mock.cpufreq.get_related_cpus = mock_related_cpus
|
2017-03-06 17:29:15 +00:00
|
|
|
|
|
|
|
# Check retrieving cpus from a given prefix
|
|
|
|
assert_equal(resolve_cpus('A72', mock), [0, 1])
|
|
|
|
assert_equal(resolve_cpus('A53', mock), [2, 3])
|
|
|
|
assert_equal(resolve_cpus('big', mock), [0, 1])
|
|
|
|
assert_equal(resolve_cpus('little', mock), [2, 3])
|
|
|
|
assert_equal(resolve_cpus('', mock), [0, 1, 2, 3])
|
|
|
|
assert_equal(resolve_cpus('cpu0', mock), [0])
|
|
|
|
assert_equal(resolve_cpus('cpu3', mock), [3])
|
|
|
|
|
|
|
|
# Check get unique domain cpus
|
|
|
|
assert_equal(resolve_unique_domain_cpus('A72', mock), [0])
|
|
|
|
assert_equal(resolve_unique_domain_cpus('A53', mock), [2])
|
|
|
|
assert_equal(resolve_unique_domain_cpus('big', mock), [0])
|
|
|
|
assert_equal(resolve_unique_domain_cpus('little', mock), [2])
|
|
|
|
assert_equal(resolve_unique_domain_cpus('', mock), [0, 2])
|
|
|
|
assert_equal(resolve_unique_domain_cpus('cpu0', mock), [0])
|
|
|
|
assert_equal(resolve_unique_domain_cpus('cpu3', mock), [2])
|