1#!/usr/bin/env python3.4 2# 3# Copyright (C) 2016 The Android Open Source Project 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 17import random 18from acts.base_test import BaseTestClass 19 20CONSERVATIVE_MAX_ATTEN_VALUE = 10 21MIN_ATTEN_VALUE = 0 22 23class AttenuatorSanityTest(BaseTestClass): 24 25 def __init__(self, controllers): 26 BaseTestClass.__init__(self, controllers) 27 self.tests = ( 28 "test_attenuator_validation", 29 "test_attenuator_get_max_value", 30 ) 31 self.number_of_iteration = 2 32 33 def test_attenuator_validation(self): 34 """Validate attenuator set and get APIs works fine. 35 """ 36 for atten in self.attenuators: 37 self.log.info("Attenuator: {}".format(atten)) 38 try: 39 atten_max_value = atten.get_max_atten() 40 except ValueError as e: 41 self.log.error(e) 42 self.log.info("Using conservative max value.") 43 atten_max_value = CONSERVATIVE_MAX_ATTEN_VALUE 44 45 atten_value_list = [MIN_ATTEN_VALUE, atten_max_value] 46 for i in range(0, self.number_of_iteration): 47 atten_value_list.append(int(random.uniform(0,atten_max_value))) 48 49 for atten_val in atten_value_list: 50 self.log.info("Set atten to {}".format(atten_val)) 51 atten.set_atten(atten_val) 52 current_atten = int(atten.get_atten()) 53 self.log.info("Current atten = {}".format(current_atten)) 54 assert atten_val == current_atten, "Setting attenuator failed." 55 56 return True 57 58 def test_attenuator_get_max_value(self): 59 """Validate attenuator get_max_atten APIs works fine. 60 """ 61 for atten in self.attenuators: 62 try: 63 atten_max_value = atten.get_max_atten() 64 except ValueError as e: 65 self.log.error(e) 66 return False 67 return True 68