Home | History | Annotate | Download | only in Functions
      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 All listing and dumping function testcases.
     33 
     34 List of tested functions :
     35 --------------------------
     36     - [dumpDomains]  function
     37     - [dumpElement] function
     38 
     39 Test cases :
     40 ------------
     41     - Testing dumpDomains function on nominal case
     42     - Testing dumpElements function on nominal case
     43 """
     44 import commands, os
     45 import unittest
     46 from Util.PfwUnitTestLib import PfwTestCase
     47 from Util import ACTLogging
     48 log=ACTLogging.Logger()
     49 
     50 class TestCases(PfwTestCase):
     51 
     52     def setUp(self):
     53 
     54         self.pfw.sendCmd("setTuningMode", "on")
     55 
     56         pfw_test_tools=os.environ["PFW_TEST_TOOLS"]
     57         self.reference_dumpDomains_xml = pfw_test_tools+"/xml/XML_Test/Reference_dumpDomains.xml"
     58         self.reference_dumpDomains_file = pfw_test_tools+"/xml/XML_Test/Reference_dumpDomains"
     59         self.initial_xml = pfw_test_tools+"/xml/TestConfigurableDomains.xml"
     60 
     61         self.list_domains=[]
     62         self.list_criteria=["Crit_0", "Crit_1"]
     63         self.list_parameters=[]
     64         self.temp_file="tempfile"
     65 
     66         self.domain_name = "Domain_0"
     67         self.config_name = "Conf_0"
     68 
     69     def tearDown(self):
     70         self.pfw.sendCmd("setTuningMode", "off")
     71         if os.path.exists(self.temp_file):
     72             os.remove(self.temp_file)
     73 
     74     def test_01_dumpDomains_Case(self):
     75         """
     76         Testing dumpDomains function
     77         ----------------------------
     78             Test case description :
     79             ~~~~~~~~~~~~~~~~~~~~~~~
     80                 - import a reference XML : Reference_DumpDomains.xml
     81                 - dumpDomains
     82                 - compare out to a reference file : Reference_DumpDomains
     83             Tested commands :
     84             ~~~~~~~~~~~~~~~~~
     85                 - [dumpDomains] function
     86             Used commands :
     87             ~~~~~~~~~~~~~~~
     88                 - [importDomainsWithSettingsXML] function
     89             Expected result :
     90             ~~~~~~~~~~~~~~~~~
     91                 - string stdout due to dumpDomains is the same than string in
     92                 the reference file
     93         """
     94         log.D(self.test_01_dumpDomains_Case.__doc__)
     95 
     96         #Import a reference XML file
     97         log.I("Import Domains with settings from %s"%(self.reference_dumpDomains_xml))
     98         out, err = self.pfw.sendCmd("importDomainsWithSettingsXML",self.reference_dumpDomains_xml, "")
     99         assert err == None, log.E("Command [importDomainsWithSettingsXML %s] : %s"%(self.reference_dumpDomains_xml,err))
    100         assert out == "Done", log.F("When using function importDomainsWithSettingsXML %s]"%(self.reference_dumpDomains_xml))
    101 
    102         log.I("Command [dumpDomains]")
    103         out, err = self.pfw.sendCmd("dumpDomains","","")
    104         assert err == None, log.E("Command [dumpDomains] : %s"%(err))
    105         self.assertEqual(out.splitlines(), open(self.reference_dumpDomains_file).read().splitlines())
    106         log.I("Command [dumpDomains] - correctly executed")
    107 
    108     def test_03_help_Case(self):
    109         """
    110         Testing help function
    111         ---------------------
    112             Test case description :
    113             ~~~~~~~~~~~~~~~~~~~~~~~
    114                 - help
    115                 - check results
    116             Tested commands :
    117             ~~~~~~~~~~~~~~~~~
    118                 - [help] function
    119             Expected result :
    120             ~~~~~~~~~~~~~~~~~
    121                 - string stdout due to help is not empty
    122         """
    123         log.D(self.test_03_help_Case.__doc__)
    124         log.I("Command [help]")
    125         out, err = self.pfw.sendCmd("help","")
    126         assert err == None, log.E("Command [help] : %s"%(err))
    127         assert out != ""
    128         log.I("Command [help] - correctly executed")
    129 
    130     def test_04_status_Case(self):
    131         """
    132         Testing status function
    133         -----------------------
    134             Test case description :
    135             ~~~~~~~~~~~~~~~~~~~~~~~
    136                 - status
    137                 - check results
    138             Tested commands :
    139             ~~~~~~~~~~~~~~~~~
    140                 - [status] function
    141             Expected result :
    142             ~~~~~~~~~~~~~~~~~
    143                 - string stdout due to status is not empty
    144         """
    145         log.D(self.test_04_status_Case.__doc__)
    146         log.I("Command [status]")
    147         out, err = self.pfw.sendCmd("status","")
    148         assert err == None, log.E("Command [help] : %s"%(err))
    149         assert out != ""
    150         log.I("Command [status] - correctly executed")
    151 
    152     def test_05_listCriteria_Case(self):
    153         """
    154         Testing listCriteria function
    155         -----------------------------
    156             Test case description :
    157             ~~~~~~~~~~~~~~~~~~~~~~~
    158                 - listCriteria
    159                 - check results
    160             Tested commands :
    161             ~~~~~~~~~~~~~~~~~
    162                 - [listCriteria] function
    163             Expected result :
    164             ~~~~~~~~~~~~~~~~~
    165                 - string stdout due to listCriteria is not empty
    166         """
    167         log.D(self.test_05_listCriteria_Case.__doc__)
    168         log.I("Command [listCriteria]")
    169         out, err = self.pfw.sendCmd("listCriteria", "XML")
    170         assert err == None, log.E("Command [listCriteria] : %s"%(err))
    171         self.assertNotEqual(out, "")
    172         log.I("Command [listCriteria] - correctly executed")
    173 
    174     def test_06_listDomains_Case(self):
    175         """
    176         Testing listDomains function
    177         ----------------------------
    178             Test case description :
    179             ~~~~~~~~~~~~~~~~~~~~~~~
    180                 - listDomains
    181                 - check results
    182             Tested commands :
    183             ~~~~~~~~~~~~~~~~~
    184                 - [listDomains] function
    185             Expected result :
    186             ~~~~~~~~~~~~~~~~~
    187                 - string stdout due to listDomains is not empty
    188         """
    189         log.D(self.test_06_listDomains_Case.__doc__)
    190         log.I("Command [listDomains]")
    191         out, err = self.pfw.sendCmd("listDomains")
    192         assert err == None, log.E("Command [listDomains] : %s"%(err))
    193         assert out != ""
    194         log.I("Command [listDomains] - correctly executed")
    195 
    196     @unittest.expectedFailure
    197     def test_06_listDomainElements_Case(self):
    198         """
    199         Testing listDomains function
    200         ----------------------------
    201             Test case description :
    202             ~~~~~~~~~~~~~~~~~~~~~~~
    203                 - listDomainElements
    204                 - check results
    205             Tested commands :
    206             ~~~~~~~~~~~~~~~~~
    207                 - [listDomainElements] function
    208             Expected result :
    209             ~~~~~~~~~~~~~~~~~
    210                 - string stdout due to listDomains is not empty
    211         """
    212         log.D(self.test_06_listDomainElements_Case.__doc__)
    213         log.I("Command [listDomainElements]")
    214         out, err = self.pfw.sendCmd("listDomainElements",self.domain_name)
    215         assert err == None, log.E("Command [listDomainElements] : %s"%(err))
    216         assert out != "", log.F("Fail when listDomainElements %s: stdout is empty"%(self.domain_name))
    217         log.I("Command [listDomainElements] - correctly executed")
    218 
    219     @unittest.expectedFailure
    220     def test_07_listConfigurations_Case(self):
    221         """
    222         Testing listConfigurations function
    223         -----------------------------------
    224             Test case description :
    225             ~~~~~~~~~~~~~~~~~~~~~~~
    226                 - listConfigurations
    227                 - check results
    228             Tested commands :
    229             ~~~~~~~~~~~~~~~~~
    230                 - [listConfigurations] function
    231             Expected result :
    232             ~~~~~~~~~~~~~~~~~
    233                 - string stdout due to listConfigurations is not empty
    234         """
    235         log.D(self.test_07_listConfigurations_Case.__doc__)
    236         log.I("Command [listConfigurations]")
    237         out, err = self.pfw.sendCmd("listConfigurations",self.domain_name)
    238         assert err == None, log.E("Command [listConfigurations] : %s"%(err))
    239         assert out != "", log.F("Fail when listConfigurations %s: stdout is empty"%(self.domain_name))
    240         log.I("Command [listConfigurations] - correctly executed")
    241 
    242     def test_08_listElements_Case(self):
    243         """
    244         Testing listElements function
    245         -----------------------------
    246             Test case description :
    247             ~~~~~~~~~~~~~~~~~~~~~~~
    248                 - listElements
    249                 - check results
    250             Tested commands :
    251             ~~~~~~~~~~~~~~~~~
    252                 - [listElements] function
    253             Expected result :
    254             ~~~~~~~~~~~~~~~~~
    255                 - string stdout due to listElements is not empty
    256         """
    257         log.D(self.test_08_listElements_Case.__doc__)
    258         log.I("Command [listElements]")
    259         out, err = self.pfw.sendCmd("listElements", expectSuccess=False)
    260         assert err == None, log.E("Command [listElements] : %s"%(err))
    261         out, err = self.pfw.sendCmd("listElements","/Test/")
    262         assert err == None, log.E("Command [listElements /Test/] : %s"%(err))
    263         assert out != ""
    264         log.I("Command [listElements] - correctly executed")
    265 
    266     def test_09_listParameters_Case(self):
    267         """
    268         Testing listParameters function
    269         -------------------------------
    270             Test case description :
    271             ~~~~~~~~~~~~~~~~~~~~~~~
    272                 - listParameters
    273                 - check results
    274             Tested commands :
    275             ~~~~~~~~~~~~~~~~~
    276                 - [listParameters] function
    277             Expected result :
    278             ~~~~~~~~~~~~~~~~~
    279                 - string stdout due to listParameters is not empty
    280         """
    281         log.D(self.test_09_listParameters_Case.__doc__)
    282         log.I("Command [listParameters]")
    283         out, err = self.pfw.sendCmd("listParameters", expectSuccess=False)
    284         assert err == None, log.E("Command [listParameters] : %s"%(err))
    285         out, err = self.pfw.sendCmd("listParameters","/Test/")
    286         assert err == None, log.E("Command [listParameters /Test/] : %s"%(err))
    287         assert out != ""
    288         log.I("Command [listParameters] - correctly executed")
    289 
    290     def test_10_getElementSize_Case(self):
    291         """
    292         Testing getElementSize function
    293         -------------------------------
    294             Test case description :
    295             ~~~~~~~~~~~~~~~~~~~~~~~
    296                 - listParameters
    297                 - getElementSize for all parameters
    298                 - check results
    299             Tested commands :
    300             ~~~~~~~~~~~~~~~~~
    301                 - [getElementSize] function
    302             Used commands :
    303             ~~~~~~~~~~~~~~~
    304                 - [listParameters] function
    305             Expected result :
    306             ~~~~~~~~~~~~~~~~~
    307                 - string stdout due to getElementSize is not empty
    308         """
    309         log.D(self.test_10_getElementSize_Case.__doc__)
    310         log.I("Command [listParameters]")
    311         out, err = self.pfw.sendCmd("listParameters","/Test/")
    312         assert err == None, log.E("Command [listParameters /Test/] : %s"%(err))
    313         assert out != ""
    314         log.I("Command [listParameters] - correctly executed")
    315         # Write out in temp file
    316         f_temp_file = open(self.temp_file, "w")
    317         f_temp_file.write(out)
    318         f_temp_file.close()
    319 
    320         # Extract parameter from the temp file
    321         f_temp_file = open(self.temp_file, "r")
    322         lines = f_temp_file.readlines()
    323         f_temp_file.close()
    324 
    325         for line in lines :
    326             if not line.find("/") == -1 :
    327                 final_position_in_line= line.find("[")-1
    328                 self.list_parameters.append(line[0:final_position_in_line])
    329 
    330         for parameter in self.list_parameters :
    331             out, err = self.pfw.sendCmd("getElementSize",parameter)
    332             assert err == None, log.E("Command [getElementSize %s] : %s"%(parameter,err))
    333             assert out != ""
    334 
    335         out, err = self.pfw.sendCmd("getElementSize","/Test/")
    336         assert err == None, log.E("Command [getElementSize /Test/] : %s"%(err))
    337         assert out != ""
    338 
    339         out, err = self.pfw.sendCmd("getElementSize", expectSuccess=False)
    340         assert err == None, log.E("Command [getElementSize /Test/] : %s"%(err))
    341 
    342     def test_11_showProperties_Case(self):
    343         """
    344         Testing showProperties function
    345         -------------------------------
    346             Test case description :
    347             ~~~~~~~~~~~~~~~~~~~~~~~
    348                 - listParameters
    349                 - showProperties for all parameters
    350                 - check results
    351             Tested commands :
    352             ~~~~~~~~~~~~~~~~~
    353                 - [showProperties] function
    354             Used commands :
    355             ~~~~~~~~~~~~~~~
    356                 - [listParameters] function
    357             Expected result :
    358             ~~~~~~~~~~~~~~~~~
    359                 - string stdout due to getElementSize is not empty
    360         """
    361         log.D(self.test_11_showProperties_Case.__doc__)
    362         log.I("Command [listParameters]")
    363         out, err = self.pfw.sendCmd("listParameters","/Test/")
    364         assert err == None, log.E("Command [listParameters /Test/] : %s"%(err))
    365         assert out != ""
    366         log.I("Command [listParameters] - correctly executed")
    367         # Write out in temp file
    368         f_temp_file = open(self.temp_file, "w")
    369         f_temp_file.write(out)
    370         f_temp_file.close()
    371 
    372         # Extract parameter from the temp file
    373         f_temp_file = open(self.temp_file, "r")
    374         lines = f_temp_file.readlines()
    375         f_temp_file.close()
    376 
    377         for line in lines :
    378             if not line.find("/") == -1 :
    379                 final_position_in_line= line.find("[")-1
    380                 self.list_parameters.append(line[0:final_position_in_line])
    381 
    382         for parameter in self.list_parameters :
    383             out, err = self.pfw.sendCmd("showProperties",parameter)
    384             assert err == None, log.E("Command [showProperties %s] : %s"%(parameter,err))
    385             assert out != ""
    386 
    387         out, err = self.pfw.sendCmd("showProperties","/Test/")
    388         assert err == None, log.E("Command [showProperties /Test/] : %s"%(err))
    389         assert out != ""
    390 
    391         out, err = self.pfw.sendCmd("showProperties", expectSuccess=False)
    392         assert err == None, log.E("Command [showProperties] : %s"%(err))
    393 
    394     def test_12_listBelongingDomains_Case(self):
    395         """
    396         Testing listBelongingDomains function
    397         -------------------------------
    398             Test case description :
    399             ~~~~~~~~~~~~~~~~~~~~~~~
    400                 - listParameters
    401                 - listBelongingDomains for all parameters
    402                 - check results
    403             Tested commands :
    404             ~~~~~~~~~~~~~~~~~
    405                 - [listBelongingDomains] function
    406             Used commands :
    407             ~~~~~~~~~~~~~~~
    408                 - [listParameters] function
    409             Expected result :
    410             ~~~~~~~~~~~~~~~~~
    411                 - string stdout due to listBelongingDomains is not empty
    412         """
    413         log.D(self.test_12_listBelongingDomains_Case.__doc__)
    414         log.I("Command [listParameters]")
    415         out, err = self.pfw.sendCmd("listParameters","/Test/")
    416         assert err == None, log.E("Command [listParameters /Test/] : %s"%(err))
    417         assert out != ""
    418         log.I("Command [listParameters] - correctly executed")
    419         # Write out in temp file
    420         f_temp_file = open(self.temp_file, "w")
    421         f_temp_file.write(out)
    422         f_temp_file.close()
    423 
    424         # Extract parameter from the temp file
    425         f_temp_file = open(self.temp_file, "r")
    426         lines = f_temp_file.readlines()
    427         f_temp_file.close()
    428 
    429         for line in lines :
    430             if not line.find("/") == -1 :
    431                 final_position_in_line= line.find("[")-1
    432                 self.list_parameters.append(line[0:final_position_in_line])
    433 
    434         for parameter in self.list_parameters :
    435             out, err = self.pfw.sendCmd("listBelongingDomains",parameter)
    436             assert err == None, log.E("Command [listBelongingDomains %s] : %s"%(parameter,err))
    437 
    438         out, err = self.pfw.sendCmd("listBelongingDomains","/Test/")
    439         assert err == None, log.E("Command [listBelongingDomains /Test/] : %s"%(err))
    440 
    441         out, err = self.pfw.sendCmd("listBelongingDomains", expectSuccess=False)
    442         assert err == None, log.E("Command [listBelongingDomains] : %s"%(err))
    443 
    444     def test_13_listAssociatedDomains_Case(self):
    445         """
    446         Testing listAssociatedDomains function
    447         -------------------------------
    448             Test case description :
    449             ~~~~~~~~~~~~~~~~~~~~~~~
    450                 - listParameters
    451                 - listAssociatedDomains for all parameters
    452                 - check results
    453             Tested commands :
    454             ~~~~~~~~~~~~~~~~~
    455                 - [listAssociatedDomains] function
    456             Used commands :
    457             ~~~~~~~~~~~~~~~
    458                 - [listParameters] function
    459             Expected result :
    460             ~~~~~~~~~~~~~~~~~
    461                 - string stdout due to listBelongingDomains is not empty
    462         """
    463         log.D(self.test_13_listAssociatedDomains_Case.__doc__)
    464         log.I("Command [listParameters]")
    465         out, err = self.pfw.sendCmd("listParameters","/Test/")
    466         assert err == None, log.E("Command [listParameters /Test/] : %s"%(err))
    467         log.I("Command [listParameters] - correctly executed")
    468         # Write out in temp file
    469         f_temp_file = open(self.temp_file, "w")
    470         f_temp_file.write(out)
    471         f_temp_file.close()
    472 
    473         # Extract parameter from the temp file
    474         f_temp_file = open(self.temp_file, "r")
    475         lines = f_temp_file.readlines()
    476         f_temp_file.close()
    477 
    478         for line in lines :
    479             if not line.find("/") == -1 :
    480                 final_position_in_line= line.find("[")-1
    481                 self.list_parameters.append(line[0:final_position_in_line])
    482 
    483         for parameter in self.list_parameters :
    484             out, err = self.pfw.sendCmd("listAssociatedDomains",parameter)
    485             assert err == None, log.E("Command [listAssociatedDomains %s] : %s"%(parameter,err))
    486 
    487         out, err = self.pfw.sendCmd("listAssociatedDomains","/Test/")
    488         assert err == None, log.E("Command [listAssociatedDomains /Test/] : %s"%(err))
    489 
    490     def test_14_listAssociatedElements_Case(self):
    491         """
    492         Testing listAssociatedElements function
    493         -------------------------------
    494             Test case description :
    495             ~~~~~~~~~~~~~~~~~~~~~~~
    496                 - listAssociatedElements
    497                 - check results
    498             Tested commands :
    499             ~~~~~~~~~~~~~~~~~
    500                 - [listAssociatedElements] function
    501             Expected result :
    502             ~~~~~~~~~~~~~~~~~
    503                 - string stdout due to listAssociatedElements is not empty
    504         """
    505         log.D(self.test_14_listAssociatedElements_Case.__doc__)
    506         log.I("Command [listAssociatedElements]")
    507         out, err = self.pfw.sendCmd("listAssociatedElements")
    508         assert err == None, log.E("Command [listAssociatedElements] : %s"%(err))
    509         log.I("Command [listAssociatedElements] - correctly executed")
    510 
    511     def test_15_listConflictingElements_Case(self):
    512         """
    513         Testing listConflictingElements function
    514         -------------------------------
    515             Test case description :
    516             ~~~~~~~~~~~~~~~~~~~~~~~
    517                 - listConflictingElements
    518                 - check results
    519             Tested commands :
    520             ~~~~~~~~~~~~~~~~~
    521                 - [listConflictingElements] function
    522             Expected result :
    523             ~~~~~~~~~~~~~~~~~
    524                 - string stdout due to listConflictingElements is not empty
    525         """
    526         log.D(self.test_15_listConflictingElements_Case.__doc__)
    527         log.I("Command [listConflictingElements]")
    528         out, err = self.pfw.sendCmd("listConflictingElements")
    529         assert err == None, log.E("Command [listConflictingElements] : %s"%(err))
    530         log.I("Command [listConflictingElements] - correctly executed")
    531 
    532     def test_16_listRogueElements_Case(self):
    533         """
    534         Testing listRogueElements function
    535         -------------------------------
    536             Test case description :
    537             ~~~~~~~~~~~~~~~~~~~~~~~
    538                 - listRogueElements
    539                 - check results
    540             Tested commands :
    541             ~~~~~~~~~~~~~~~~~
    542                 - [listRogueElements] function
    543             Expected result :
    544             ~~~~~~~~~~~~~~~~~
    545                 - string stdout due to listRogueElements is not empty
    546         """
    547         log.D(self.test_16_listRogueElements_Case.__doc__)
    548         log.I("Command [listRogueElements]")
    549         out, err = self.pfw.sendCmd("listRogueElements")
    550         assert err == None, log.E("Command [listRogueElements] : %s"%(err))
    551         log.I("Command [listRogueElements] - correctly executed")
    552