• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17import enum
18"""This module has the global key values that are used across framework
19modules.
20"""
21
22
23class Config(enum.Enum):
24    """Enum values for test config related lookups.
25    """
26    # Keys used to look up values from test config files.
27    # These keys define the wording of test configs and their internal
28    # references.
29    key_log_path = "logpath"
30    key_testbed = "testbed"
31    key_testbed_name = "name"
32    key_config_path = "configpath"
33    key_test_paths = "testpaths"
34    key_port = "Port"
35    key_address = "Address"
36    key_random = "random"
37    key_test_case_iterations = "test_case_iterations"
38    # Config names for controllers packaged in ACTS.
39    key_android_device = "AndroidDevice"
40    key_native_android_device = "NativeAndroidDevice"
41    key_relay_device = "RelayDevice"
42    key_access_point = "AccessPoint"
43    key_attenuator = "Attenuator"
44    key_iperf_server = "IPerfServer"
45    key_monsoon = "Monsoon"
46    key_sniffer = "Sniffer"
47    # Internal keys, used internally, not exposed to user's config files.
48    ikey_user_param = "user_params"
49    ikey_testbed_name = "testbed_name"
50    ikey_logger = "log"
51    ikey_logpath = "log_path"
52    ikey_cli_args = "cli_args"
53    # module name of controllers packaged in ACTS.
54    m_key_monsoon = "monsoon"
55    m_key_android_device = "android_device"
56    m_key_native_android_device = "native_android_device"
57    m_key_relay_device = "relay_device_controller"
58    m_key_access_point = "access_point"
59    m_key_attenuator = "attenuator"
60    m_key_iperf_server = "iperf_server"
61    m_key_sniffer = "sniffer"
62
63    # A list of keys whose values in configs should not be passed to test
64    # classes without unpacking first.
65    reserved_keys = (key_testbed, key_log_path, key_test_paths)
66
67    # Controller names packaged with ACTS.
68    builtin_controller_names = [
69        key_android_device, key_native_android_device, key_relay_device,
70        key_access_point, key_attenuator, key_iperf_server, key_monsoon,
71        key_sniffer
72    ]
73
74
75def get_name_by_value(value):
76    for name, member in Config.__members__.items():
77        if member.value == value:
78            return name
79    return None
80
81
82def get_internal_value(external_value):
83    """Translates the value of an external key to the value of its
84    corresponding internal key.
85    """
86    return value_to_value(external_value, "i%s")
87
88
89def get_module_name(name_in_config):
90    """Translates the name of a controller in config file to its module name.
91    """
92    return value_to_value(name_in_config, "m_%s")
93
94
95def value_to_value(ref_value, pattern):
96    """Translates the value of a key to the value of its corresponding key. The
97    corresponding key is chosen based on the variable name pattern.
98    """
99    ref_key_name = get_name_by_value(ref_value)
100    if not ref_key_name:
101        return None
102    target_key_name = pattern % ref_key_name
103    try:
104        return getattr(Config, target_key_name).value
105    except AttributeError:
106        return None
107