1#  Copyright (C) 2024 The Android Open Source Project
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14"""Ranging base test."""
15
16import re
17
18from lib import utils
19from mobly import base_test
20from mobly import test_runner
21from mobly.controllers import android_device
22
23
24RELEASE_ID_REGEX = re.compile(r"\w+\.\d+\.\d+")
25
26
27class RangingBaseTest(base_test.BaseTestClass):
28  """Base class for Uwb tests."""
29
30  def setup_class(self):
31    """Sets up the Android devices for Uwb test."""
32    super().setup_class()
33    self.android_devices = self.register_controller(
34        android_device, min_number=2
35    )
36    for ad in self.android_devices:
37      ad.load_snippet("ranging", "com.google.snippet.ranging")
38      utils.initialize_uwb_country_code_if_necessary(ad)
39      ad.load_snippet("uwb", "com.google.snippet.uwb")
40      ad.load_snippet("bluetooth", "com.google.snippet.bluetooth")
41
42  def setup_test(self):
43    super().setup_test()
44    for ad in self.android_devices:
45      ad.ranging.logInfo(
46          "*** TEST START: " + self.current_test_info.name + " ***"
47      )
48
49  def teardown_test(self):
50    super().teardown_test()
51    for ad in self.android_devices:
52      ad.ranging.logInfo(
53          "*** TEST END: " + self.current_test_info.name + " ***"
54      )
55
56  def teardown_class(self):
57    super().teardown_class()
58
59  def on_fail(self, record):
60    test_name = record.test_name
61    # Single device test
62    for count, ad in enumerate(self.android_devices):
63      device_name = "initiator" if not count else "responder"
64      test_device_name = test_name + "_" + device_name
65      ad.take_bug_report(
66          test_name=test_device_name,
67          destination=self.current_test_info.output_path,
68      )
69
70
71if __name__ == "__main__":
72  test_runner.main()
73