Home | History | Annotate | Download | only in Domains
      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 """
     32 Effect of criteria changes on configuration testcases
     33 
     34 List of tested functions :
     35 --------------------------
     36     - [applyConfigurations] function
     37     - [setCriterionState] function
     38 
     39 Test cases :
     40 ------------
     41     - test_Combinatorial_Criteria
     42 """
     43 import os
     44 from Util.PfwUnitTestLib import PfwTestCase
     45 from Util import ACTLogging
     46 log=ACTLogging.Logger()
     47 
     48 class TestCases(PfwTestCase):
     49 
     50     def setUp(self):
     51         self.pfw.sendCmd("setTuningMode", "on")
     52         self.reference_xml = "$PFW_TEST_TOOLS/xml/XML_Test/Reference_Criteria.xml"
     53         self.temp_domain="f_Domains_Backup"
     54         self.temp_status="f_Config_Status"
     55         # Expected results are defined by Reference_Criteria.xml configuration settings
     56         self.expected_result = [["Conf_1_1", "<none>",   "Conf_3_0"] ,
     57                                 ["Conf_1_1", "Conf_2_1", "Conf_3_1"] ,
     58                                 ["Conf_1_1", "Conf_2_1", "Conf_3_0"] ,
     59                                 ["Conf_1_1", "Conf_2_0", "Conf_3_0"] ,
     60                                 ["Conf_1_0", "Conf_2_0", "Conf_3_0"] ,
     61                                 ["Conf_1_1", "Conf_2_0", "Conf_3_0"] ,
     62                                 ["Conf_1_1", "Conf_2_0", "Conf_3_1"]]
     63         self.criterion_setup = [["0x2", "1"] ,
     64                                 ["0x2", "0"] ,
     65                                 ["0x1", "0"] ,
     66                                 ["0x1", "1"] ,
     67                                 ["0x3", "4"] ,
     68                                 ["0x0", "1"]]
     69         # names used in this test refer to names used in Reference_Criteria.xml
     70         self.new_domain_name = "Domain"
     71         self.crit_change_iteration = 6
     72 
     73     def tearDown(self):
     74         self.pfw.sendCmd("setTuningMode", "off")
     75 
     76     def test_Combinatorial_Criteria(self):
     77         """
     78         Testing combinatorial criteria
     79         ------------------------------
     80             Test case description :
     81             ~~~~~~~~~~~~~~~~~~~~~~~
     82                 Checking that PFW behaviour is in line with expectations when setting criteria states.
     83                     - Test of all combinatorial of criteria and possible errors
     84                         - nominal case in configuration selection
     85                         - conflict in configuration selection
     86                         - no configuration selected
     87                         - error in criterion setting
     88                     - test of compound rules : All / Any
     89                     - test of matches cases  : Is / IsNot / Include / Exclude
     90                     - test of criteria types : Inclusive / Exclusive
     91             Tested commands :
     92             ~~~~~~~~~~~~~~~~~
     93                 - [applyConfigurations] function
     94                 - [setCriterionState] function
     95             Expected result :
     96             ~~~~~~~~~~~~~~~~~
     97                 - Configurations setting conform to expected behavior
     98         """
     99         log.D(self.test_Combinatorial_Criteria.__doc__)
    100 
    101         # Import a reference XML file
    102         log.I("Import Domains with settings from %s"%(self.reference_xml))
    103         out, err = self.pfw.sendCmd("importDomainsWithSettingsXML",self.reference_xml, "")
    104         assert err == None, log.E("Command [importDomainsWithSettingsXML %s] : %s"%(self.reference_xml,err))
    105         assert out == "Done", log.F("When using function importDomainsWithSettingsXML %s]"%(self.reference_xml))
    106 
    107         # Check number of domain
    108         log.I("Current domains listing")
    109         log.I("Command [listDomains]")
    110         out, err = self.pfw.sendCmd("listDomains","","")
    111         assert err == None, log.E("Command [listDomains] : %s"%(err))
    112         log.I("Command [listDomains] : correctly executed")
    113 
    114         # Domains listing backup
    115         f_Domains_Backup = open(self.temp_domain, "w")
    116         f_Domains_Backup.write(out)
    117         f_Domains_Backup.close()
    118         f_Domains_Backup = open(self.temp_domain, "r")
    119         domains_nbr = 0
    120         line=f_Domains_Backup.readline()
    121         while line!="":
    122             line=f_Domains_Backup.readline()
    123             domains_nbr+=1
    124         f_Domains_Backup.close()
    125 
    126         # Applying default configurations
    127         out, err = self.pfw.sendCmd("setTuningMode", "off")
    128         assert err == None, log.E("Command [setTuningMode]")
    129         out, err = self.hal.sendCmd("applyConfigurations")
    130         assert err == None, log.E("Command HAL [applyConfigurations]")
    131 
    132         # Saving default status
    133         out, err = self.pfw.sendCmd("status")
    134         f_Config_Status = open(self.temp_status, "w")
    135         f_Config_Status.write(out)
    136         f_Config_Status.close()
    137 
    138         # Test cases iterations
    139         for iteration in range (self.crit_change_iteration+1):
    140 
    141             # Criteria settings
    142             # No criteria are set at the first iteration for testing default configurations
    143             if iteration != 0:
    144                 log.I("Setting criterion %s to %s" % ("Crit_0", str(self.criterion_setup[iteration-1][0])))
    145                 state = str(self.criterion_setup[iteration-1][0])
    146                 out, err = self.hal.sendCmd("setCriterionState", "Crit_0", state)
    147                 assert err == None, log.E("Command HAL [setCriterionState]")
    148                 log.I("Setting criterion %s to %s" % ("Crit_1", str(self.criterion_setup[iteration-1][1])))
    149                 state = str(self.criterion_setup[iteration-1][1])
    150                 out, err = self.hal.sendCmd("setCriterionState", "Crit_1", state)
    151                 assert err == None, log.E("Command HAL [setCriterionState]")
    152                 log.I("Applaying new configurations")
    153                 out, err = self.hal.sendCmd("applyConfigurations")
    154                 assert err == None, log.E("Command HAL [applyConfigurations]")
    155                 out, err = self.pfw.sendCmd("status")
    156                 assert err == None, log.E("Command [status]")
    157                 os.remove(self.temp_status)
    158                 f_Config_Status = open(self.temp_status, "w")
    159                 f_Config_Status.write(out)
    160                 f_Config_Status.close()
    161             else :
    162                 log.I("Default Configurations - no criteria are set :")
    163                 out, err = self.pfw.sendCmd("status")
    164                 os.remove(self.temp_status)
    165                 f_Config_Status = open(self.temp_status, "w")
    166                 f_Config_Status.write(out)
    167                 f_Config_Status.close()
    168 
    169             # Configurations checking
    170             for domain in range (domains_nbr):
    171                 domain_name = "".join([self.new_domain_name, "_", str(domain+1), "[<none>]"])
    172                 config = str(self.expected_result[iteration][domain])
    173                 log.I("Checking that domain %s is set to configuration : %s" % (domain_name,config))
    174                 for line in open(self.temp_status, "r"):
    175                     if domain_name in line:
    176                         line = line.replace(domain_name,'')
    177                         line = line.replace(":","")
    178                         line = line.replace(' ','')
    179                         line = line.replace("\n","")
    180                         assert line == config, log.F("Domain %s - Expected configuration : %s, found : %s" % (domain_name,config,line))
    181                         log.I("Domain %s - configuration correctly set to %s" % (domain_name,line))
    182 
    183         # Temporary files deletion
    184         os.remove(self.temp_domain)
    185         os.remove(self.temp_status)
    186