1# -*-coding:utf-8 -* 2 3# Copyright (c) 2011-2015, Intel Corporation 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without modification, 7# are permitted provided that the following conditions are met: 8# 9# 1. Redistributions of source code must retain the above copyright notice, this 10# list of conditions and the following disclaimer. 11# 12# 2. Redistributions in binary form must reproduce the above copyright notice, 13# this list of conditions and the following disclaimer in the documentation and/or 14# other materials provided with the distribution. 15# 16# 3. Neither the name of the copyright holder nor the names of its contributors 17# may be used to endorse or promote products derived from this software without 18# specific prior written permission. 19# 20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31""" 32Effect of criteria changes on configuration testcases 33 34List of tested functions : 35-------------------------- 36 - [applyConfigurations] function 37 - [setCriterionState] function 38 39Test cases : 40------------ 41 - test_Combinatorial_Criteria 42""" 43import os 44from Util.PfwUnitTestLib import PfwTestCase 45from Util import ACTLogging 46log=ACTLogging.Logger() 47 48class TestCases(PfwTestCase): 49 50 def setUp(self): 51 self.pfw.sendCmd("setTuningMode", "on") 52 self.reference_xml = os.environ["PFW_TEST_TOOLS"] + "/xml/XML_Test/Reference_Criteria.xml" 53 self.temp_status="f_Config_Status" 54 # Expected results are defined by Reference_Criteria.xml configuration settings 55 self.expected_result = [["Conf_1_1", "<none>", "Conf_3_0"] , 56 ["Conf_1_1", "Conf_2_1", "Conf_3_1"] , 57 ["Conf_1_1", "Conf_2_1", "Conf_3_0"] , 58 ["Conf_1_1", "Conf_2_0", "Conf_3_0"] , 59 ["Conf_1_0", "Conf_2_0", "Conf_3_0"] , 60 ["Conf_1_1", "Conf_2_0", "Conf_3_0"] , 61 ["Conf_1_1", "Conf_2_0", "Conf_3_1"]] 62 self.criterion_setup = [["0x2", "1"] , 63 ["0x2", "0"] , 64 ["0x1", "0"] , 65 ["0x1", "1"] , 66 ["0x3", "4"] , 67 ["0x0", "1"]] 68 # names used in this test refer to names used in Reference_Criteria.xml 69 self.new_domain_name = "Domain" 70 self.crit_change_iteration = 6 71 72 def tearDown(self): 73 self.pfw.sendCmd("setTuningMode", "off", expectSuccess=False) 74 75 def test_Combinatorial_Criteria(self): 76 """ 77 Testing combinatorial criteria 78 ------------------------------ 79 Test case description : 80 ~~~~~~~~~~~~~~~~~~~~~~~ 81 Checking that PFW behaviour is in line with expectations when setting criteria states. 82 - Test of all combinatorial of criteria and possible errors 83 - nominal case in configuration selection 84 - conflict in configuration selection 85 - no configuration selected 86 - error in criterion setting 87 - test of compound rules : All / Any 88 - test of matches cases : Is / IsNot / Include / Exclude 89 - test of criteria types : Inclusive / Exclusive 90 Tested commands : 91 ~~~~~~~~~~~~~~~~~ 92 - [applyConfigurations] function 93 - [setCriterionState] function 94 Expected result : 95 ~~~~~~~~~~~~~~~~~ 96 - Configurations setting conform to expected behavior 97 """ 98 log.D(self.test_Combinatorial_Criteria.__doc__) 99 100 # Import a reference XML file 101 log.I("Import Domains with settings from %s"%(self.reference_xml)) 102 out, err = self.pfw.sendCmd("importDomainsWithSettingsXML",self.reference_xml, "") 103 assert err == None, log.E("Command [importDomainsWithSettingsXML %s] : %s"%(self.reference_xml,err)) 104 assert out == "Done", log.F("When using function importDomainsWithSettingsXML %s]"%(self.reference_xml)) 105 106 # Check number of domain 107 log.I("Current domains listing") 108 log.I("Command [listDomains]") 109 out, err = self.pfw.sendCmd("listDomains","","") 110 assert err == None, log.E("Command [listDomains] : %s"%(err)) 111 log.I("Command [listDomains] : correctly executed") 112 113 # Applying default configurations 114 out, err = self.pfw.sendCmd("setTuningMode", "off") 115 assert err == None, log.E("Command [setTuningMode]") 116 out, err = self.hal.sendCmd("applyConfigurations") 117 assert err == None, log.E("Command HAL [applyConfigurations]") 118 119 # Saving default status 120 out, err = self.pfw.sendCmd("status") 121 f_Config_Status = open(self.temp_status, "w") 122 f_Config_Status.write(out) 123 f_Config_Status.close() 124 125 # Test cases iterations 126 for iteration in range (self.crit_change_iteration+1): 127 128 # Criteria settings 129 # No criteria are set at the first iteration for testing default configurations 130 if iteration != 0: 131 log.I("Setting criterion %s to %s" % ("Crit_0", str(self.criterion_setup[iteration-1][0]))) 132 state = str(self.criterion_setup[iteration-1][0]) 133 out, err = self.hal.sendCmd("setCriterionState", "Crit_0", state) 134 assert err == None, log.E("Command HAL [setCriterionState]") 135 log.I("Setting criterion %s to %s" % ("Crit_1", str(self.criterion_setup[iteration-1][1]))) 136 state = str(self.criterion_setup[iteration-1][1]) 137 out, err = self.hal.sendCmd("setCriterionState", "Crit_1", state) 138 assert err == None, log.E("Command HAL [setCriterionState]") 139 log.I("Applaying new configurations") 140 out, err = self.hal.sendCmd("applyConfigurations") 141 assert err == None, log.E("Command HAL [applyConfigurations]") 142 out, err = self.pfw.sendCmd("status") 143 assert err == None, log.E("Command [status]") 144 os.remove(self.temp_status) 145 f_Config_Status = open(self.temp_status, "w") 146 f_Config_Status.write(out) 147 f_Config_Status.close() 148 else : 149 log.I("Default Configurations - no criteria are set :") 150 out, err = self.pfw.sendCmd("status") 151 os.remove(self.temp_status) 152 f_Config_Status = open(self.temp_status, "w") 153 f_Config_Status.write(out) 154 f_Config_Status.close() 155 156 # Configurations checking 157 for domain in range (len(self.expected_result[0])): 158 domain_name = "".join([self.new_domain_name, "_", str(domain+1), "[<none>]"]) 159 config = str(self.expected_result[iteration][domain]) 160 log.I("Checking that domain %s is set to configuration : %s" % (domain_name,config)) 161 for line in open(self.temp_status, "r"): 162 if domain_name in line: 163 line = line.replace(domain_name,'') 164 line = line.replace(":","") 165 line = line.replace(' ','') 166 line = line.replace("\n","") 167 assert line == config, log.F("Domain %s - Expected configuration : %s, found : %s" % (domain_name,config,line)) 168 log.I("Domain %s - configuration correctly set to %s" % (domain_name,line)) 169 170 # Temporary files deletion 171 os.remove(self.temp_status) 172