blob: 7f86ef99453878a1ab8b4bd2d48edcef960ab149 [file] [log] [blame]
markdrdd1893d2018-02-05 17:13:47 -08001#!/usr/bin/env python3
Ang Li73697b32015-12-03 00:41:53 +00002#
tturney1bdf77d2015-12-28 17:46:13 -08003# Copyright (C) 2016 The Android Open Source Project
Ang Li73697b32015-12-03 00:41:53 +00004#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17import random
18from acts.base_test import BaseTestClass
19
20CONSERVATIVE_MAX_ATTEN_VALUE = 10
21MIN_ATTEN_VALUE = 0
22
Ang Li73697b32015-12-03 00:41:53 +000023
tturney0cda4c82016-11-23 15:06:14 -080024class AttenuatorSanityTest(BaseTestClass):
Ang Li73697b32015-12-03 00:41:53 +000025 def __init__(self, controllers):
26 BaseTestClass.__init__(self, controllers)
tturney0cda4c82016-11-23 15:06:14 -080027 self.tests = ("test_attenuator_validation",
28 "test_attenuator_get_max_value", )
Ang Li73697b32015-12-03 00:41:53 +000029 self.number_of_iteration = 2
30
31 def test_attenuator_validation(self):
32 """Validate attenuator set and get APIs works fine.
33 """
34 for atten in self.attenuators:
35 self.log.info("Attenuator: {}".format(atten))
36 try:
37 atten_max_value = atten.get_max_atten()
38 except ValueError as e:
39 self.log.error(e)
40 self.log.info("Using conservative max value.")
41 atten_max_value = CONSERVATIVE_MAX_ATTEN_VALUE
42
43 atten_value_list = [MIN_ATTEN_VALUE, atten_max_value]
44 for i in range(0, self.number_of_iteration):
tturney0cda4c82016-11-23 15:06:14 -080045 atten_value_list.append(
46 int(random.uniform(0, atten_max_value)))
Ang Li73697b32015-12-03 00:41:53 +000047
48 for atten_val in atten_value_list:
49 self.log.info("Set atten to {}".format(atten_val))
50 atten.set_atten(atten_val)
51 current_atten = int(atten.get_atten())
52 self.log.info("Current atten = {}".format(current_atten))
53 assert atten_val == current_atten, "Setting attenuator failed."
54
55 return True
56
57 def test_attenuator_get_max_value(self):
58 """Validate attenuator get_max_atten APIs works fine.
59 """
60 for atten in self.attenuators:
61 try:
62 atten_max_value = atten.get_max_atten()
63 except ValueError as e:
64 self.log.error(e)
65 return False
66 return True