markdr | dd1893d | 2018-02-05 17:13:47 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 2 | # |
tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 3 | # Copyright (C) 2016 The Android Open Source Project |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 4 | # |
| 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 | |
| 17 | import random |
| 18 | from acts.base_test import BaseTestClass |
| 19 | |
| 20 | CONSERVATIVE_MAX_ATTEN_VALUE = 10 |
| 21 | MIN_ATTEN_VALUE = 0 |
| 22 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 23 | |
tturney | 0cda4c8 | 2016-11-23 15:06:14 -0800 | [diff] [blame] | 24 | class AttenuatorSanityTest(BaseTestClass): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 25 | def __init__(self, controllers): |
| 26 | BaseTestClass.__init__(self, controllers) |
tturney | 0cda4c8 | 2016-11-23 15:06:14 -0800 | [diff] [blame] | 27 | self.tests = ("test_attenuator_validation", |
| 28 | "test_attenuator_get_max_value", ) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 29 | 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): |
tturney | 0cda4c8 | 2016-11-23 15:06:14 -0800 | [diff] [blame] | 45 | atten_value_list.append( |
| 46 | int(random.uniform(0, atten_max_value))) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 47 | |
| 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 |