• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2017 - 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_testbeds_under_test = 'testbeds_under_test'
31    key_testbed = "testbed"
32    key_testbed_name = "name"
33    # configpath is the directory. key_config_full_path is the file path.
34    key_config_path = "configpath"
35    key_config_full_path = 'config_full_path'
36    key_test_paths = "testpaths"
37    key_port = "Port"
38    key_address = "Address"
39    key_random = "random"
40    key_test_case_iterations = "test_case_iterations"
41    key_test_failure_tracebacks = "test_failure_tracebacks"
42    # Config names for controllers packaged in ACTS.
43    key_android_device = "AndroidDevice"
44    key_fuchsia_device = "FuchsiaDevice"
45    key_buds_device = "BudsDevice"
46    key_chameleon_device = "ChameleonDevice"
47    key_native_android_device = "NativeAndroidDevice"
48    key_relay_device = "RelayDevice"
49    key_access_point = "AccessPoint"
50    key_attenuator = "Attenuator"
51    key_iperf_server = "IPerfServer"
52    key_iperf_client = "IPerfClient"
53    key_packet_sender = "PacketSender"
54    key_monsoon = "Monsoon"
55    key_sniffer = "Sniffer"
56    key_arduino_wifi_dongle = "ArduinoWifiDongle"
57    key_packet_capture = "PacketCapture"
58    # Internal keys, used internally, not exposed to user's config files.
59    ikey_user_param = "user_params"
60    ikey_testbed_name = "testbed_name"
61    ikey_logger = "log"
62    ikey_logpath = "log_path"
63    ikey_summary_writer = 'summary_writer'
64    ikey_cli_args = "cli_args"
65    # module name of controllers packaged in ACTS.
66    m_key_monsoon = "monsoon"
67    m_key_android_device = "android_device"
68    m_key_fuchsia_device = "fuchsia_device"
69    m_key_buds_device = "buds_controller"
70    m_key_chameleon_device = "chameleon_controller"
71    m_key_native_android_device = "native_android_device"
72    m_key_relay_device = "relay_device_controller"
73    m_key_access_point = "access_point"
74    m_key_attenuator = "attenuator"
75    m_key_iperf_server = "iperf_server"
76    m_key_iperf_client = "iperf_client"
77    m_key_packet_sender = "packet_sender"
78    m_key_sniffer = "sniffer"
79    m_key_arduino_wifi_dongle = "arduino_wifi_dongle"
80    m_key_packet_capture = "packet_capture"
81
82    # A list of keys whose values in configs should not be passed to test
83    # classes without unpacking first.
84    reserved_keys = (key_testbed, key_log_path, key_test_paths)
85
86    # Controller names packaged with ACTS.
87    builtin_controller_names = [
88        key_android_device,
89        key_fuchsia_device,
90        key_buds_device,
91        key_native_android_device,
92        key_relay_device,
93        key_access_point,
94        key_attenuator,
95        key_iperf_server,
96        key_iperf_client,
97        key_packet_sender,
98        key_monsoon,
99        key_sniffer,
100        key_chameleon_device,
101        key_arduino_wifi_dongle,
102        key_packet_capture,
103    ]
104
105    # Keys that are file or folder paths.
106    file_path_keys = [key_relay_device]
107
108
109def get_name_by_value(value):
110    for name, member in Config.__members__.items():
111        if member.value == value:
112            return name
113    return None
114
115
116def get_module_name(name_in_config):
117    """Translates the name of a controller in config file to its module name.
118    """
119    return value_to_value(name_in_config, "m_%s")
120
121
122def value_to_value(ref_value, pattern):
123    """Translates the value of a key to the value of its corresponding key. The
124    corresponding key is chosen based on the variable name pattern.
125    """
126    ref_key_name = get_name_by_value(ref_value)
127    if not ref_key_name:
128        return None
129    target_key_name = pattern % ref_key_name
130    try:
131        return getattr(Config, target_key_name).value
132    except AttributeError:
133        return None
134