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 Element Sequence testcases
     33 
     34 List of tested functions :
     35 --------------------------
     36     - [setElementSequence]  function
     37     - [getElementSequence] function
     38 
     39 Test cases :
     40 ------------
     41     - Testing setElementSequence errors
     42     - Testing getElementSequence errors
     43     - Testing nominal case
     44 """
     45 import os
     46 from Util.PfwUnitTestLib import PfwTestCase
     47 from Util import ACTLogging
     48 log=ACTLogging.Logger()
     49 
     50 class TestCases(PfwTestCase):
     51     def setUp(self):
     52         self.pfw.sendCmd("setTuningMode", "on")
     53         self.domain_name = "Domain_0"
     54         self.elem_0_path = "/Test/Test/TEST_DIR"
     55         self.elem_1_path = "/Test/Test/TEST_DOMAIN_0"
     56         self.elem_2_path = "/Test/Test/TEST_DOMAIN_1"
     57         self.configuration = "Conf_0"
     58 
     59     def tearDown(self):
     60         self.pfw.sendCmd("setTuningMode", "off")
     61 
     62     def test_Nominal_Case(self):
     63         """
     64         Testing nominal case
     65         --------------------
     66             Test case description :
     67             ~~~~~~~~~~~~~~~~~~~~~~~
     68                 - set a new sequences order for a selected configuration
     69             Tested commands :
     70             ~~~~~~~~~~~~~~~~~
     71                 - [setElementSequence] function
     72                 - [getElementSequence] function
     73             Expected result :
     74             ~~~~~~~~~~~~~~~~~
     75                 - all operations succeed
     76                 - new sequences order conform to expected order
     77         """
     78         log.D(self.test_Nominal_Case.__doc__)
     79 
     80         # Adding new domain elements
     81         log.I("Working on domain %s" % (self.domain_name))
     82         log.I("Adding a new domain element to domain %s" % (self.domain_name))
     83         out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path))
     84         assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path)
     85         assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path)
     86         log.I("Adding a new domain element to domain %s" % (self.domain_name))
     87         out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_2_path))
     88         assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path)
     89         assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path)
     90         log.I("New domain elements %s and %s added to domain %s" % (self.elem_1_path, self.elem_2_path, self.domain_name))
     91 
     92         # Getting elements sequence from selected configuration
     93         log.I("Getting elements sequence from configuration %s" % (self.configuration))
     94         out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration)
     95         assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration)
     96         log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out))
     97 
     98         # Setting new elements sequence order for selected configuration
     99         log.I("Setting new elements sequence order for configuration %s" % (self.configuration))
    100         out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, self.elem_2_path, self.elem_0_path, self.elem_1_path)
    101         assert err == None, "ERROR : command [setElementSequence] - Error while setting new elements sequence for configuration %s" % (self.configuration)
    102         assert out == "Done", "ERROR : command [setElementSequence] - Error while setting new elements sequence for configuration %s" % (self.configuration)
    103         log.I("Setting new elements sequence for configuration %s correctly executed")
    104         out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration)
    105         assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration)
    106         log.I("New elements sequence for configuration %s :\n%s" % (self.configuration, out))
    107 
    108         # Checking new elements sequence order conformity for selected configuration
    109         log.I("Checking new elements sequence order for configuration")
    110         expected = [self.elem_2_path, self.elem_0_path, self.elem_1_path]
    111         # Only check the element reordered
    112         configElementOrder = out.strip('\r\n').splitlines()[:len(expected)]
    113         assert configElementOrder == expected, "ERROR : Error while modifying configuration %s elements order on domain %s, expected %s, found %s" % (self.configuration, self.domain_name, expected, configElementOrder)
    114         log.I("New elements sequence order conform to expected order for configuration %s" % (self.configuration))
    115         # Removing created domain element
    116         out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path))
    117         assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path)
    118         assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path)
    119         out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_2_path))
    120         assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path)
    121         assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path)
    122 
    123     def test_setElementSequence_errors(self):
    124         """
    125         Testing setElementSequence_errors
    126         ---------------------------------
    127             Test case description :
    128             ~~~~~~~~~~~~~~~~~~~~~~~
    129                 - Setting an element not belonging to configuration
    130                 - Setting undefined element in sequence order
    131             Tested commands :
    132             ~~~~~~~~~~~~~~~~~
    133                 - [setElementSequence] function
    134             Expected result :
    135             ~~~~~~~~~~~~~~~~~
    136                 - all errors correctly detected
    137                 - no impact on initial sequences order
    138         """
    139         log.D(self.test_setElementSequence_errors.__doc__)
    140 
    141         # Adding a new domain element
    142         log.I("Working on domain %s" % (self.domain_name))
    143         log.I("Adding a new domain element to domain %s" % (self.domain_name))
    144         out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path))
    145         assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path)
    146         assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path)
    147         log.I("New domain element %s added to domain %s" % (self.elem_1_path, self.domain_name))
    148 
    149         # Getting elements sequence from selected configuration
    150         log.I("Getting elements sequence from configuration %s" % (self.configuration))
    151         out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration)
    152         assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration)
    153         log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out))
    154 
    155         # Elements sequence backup
    156         f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "w")
    157         f_ConfigElementsOrder_Backup.write(out)
    158         f_ConfigElementsOrder_Backup.close()
    159 
    160         # Setting an element not belonging to configuration in sequence order
    161         log.I("Setting an element not belonging to configuration %s in sequence order" % (self.configuration))
    162         out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, self.elem_2_path, self.elem_0_path, self.elem_1_path, expectSuccess=False)
    163         assert err == None, "ERROR : command [setElementSequence] - Error while setting elements sequence for configuration %s" % (self.configuration)
    164         assert out != "Done", "ERROR : command [setElementSequence] - Error not detected when setting an element not belonging to configuration"
    165 
    166         # Setting undefined element in sequence order for selected configuration
    167         log.I("Setting undefined element in sequence order for configuration %s" % (self.configuration))
    168         out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, "Wrong_Element_Name", self.elem_0_path, self.elem_1_path, expectSuccess=False)
    169         assert err == None, "ERROR : command [setElementSequence] - Error while setting elements sequence for configuration %s" % (self.configuration)
    170         assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when setting an undefined element to configuration"
    171 
    172         # Getting elements sequence from selected configuration for checking purpose
    173         out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration)
    174         assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration)
    175         # Elements sequence backup
    176         f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w")
    177         f_ConfigElementsOrder.write(out)
    178         f_ConfigElementsOrder.close()
    179 
    180         # Checking new elements sequence order conformity for selected configuration
    181         log.I("Checking new elements sequence order for configuration")
    182         f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r")
    183         f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "r")
    184         new_element_name = f_ConfigElementsOrder.read().splitlines()
    185         element_name = f_ConfigElementsOrder_Backup.read().splitlines()
    186         assert element_name==new_element_name, "ERROR : setElementSequence errors have affected elements order on domain %s" % (self.configuration)
    187         log.I("Elements sequence order not affected by setElementSequence errors")
    188 
    189         # Closing and removing temp file
    190         f_ConfigElementsOrder.close()
    191         f_ConfigElementsOrder_Backup.close()
    192         os.remove("f_ConfigElementsOrder")
    193         os.remove("f_ConfigElementsOrder_Backup")
    194         # Removing created domain element
    195         out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path))
    196         assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path)
    197         assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path)
    198 
    199     def test_getElementSequence_errors(self):
    200         """
    201         Testing getElementSequence_errors
    202         ---------------------------------
    203             Test case description :
    204             ~~~~~~~~~~~~~~~~~~~~~~~
    205                 - Getting an element sequence on a wrong domain name
    206                 - Getting an element sequence on a wrong configuration name
    207             Tested commands :
    208            ~~~~~~~~~~~~~~~~~
    209                 - [getElementSequence] function
    210             Expected result :
    211             ~~~~~~~~~~~~~~~~~
    212                 - all errors correctly detected
    213                 - no impact on initial sequences order
    214         """
    215         log.D(self.test_getElementSequence_errors.__doc__)
    216 
    217         # Adding new domain elements
    218         log.I("Adding a new domain element to domain %s" % (self.domain_name))
    219         out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path))
    220         assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path)
    221         assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s: %s" % (self.elem_1_path, out)
    222         log.I("Adding a new domain element to domain %s" % (self.domain_name))
    223         out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_2_path))
    224         assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path)
    225         assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s: %s" % (self.elem_2_path, out)
    226         log.I("New domain elements %s and %s added to domain %s" % (self.elem_1_path, self.elem_2_path, self.domain_name))
    227 
    228         # Getting elements sequence from selected configuration
    229         log.I("Getting elements sequence from configuration %s" % (self.configuration))
    230         out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration)
    231         assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration)
    232         log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out))
    233 
    234         # Elements sequence backup
    235         f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "w")
    236         f_ConfigElementsOrder_Backup.write(out)
    237         f_ConfigElementsOrder_Backup.close()
    238 
    239         # Getting an element sequence on a wrong domain name
    240         log.I("Getting an element sequence on a wrong domain name")
    241         out, err = self.pfw.sendCmd("getElementSequence", "Wrong_Domain_Name", self.configuration, expectSuccess=False)
    242         assert err == None, "ERROR : command [getElementSequence] - Error when getting elements sequence for configuration %s" % (self.configuration)
    243         assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when getting elements sequence for a wrong domain name"
    244 
    245         # Getting an element sequence on a wrong configuration name
    246         log.I("Getting an element sequence on a wrong configuration name")
    247         out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, "Wrong_Configuration_Name", expectSuccess=False)
    248         assert err == None, "ERROR : command [getElementSequence] - Error when getting elements sequence on a wrong configuration name"
    249         assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when getting elements sequence on a wrong configuration name"
    250 
    251         # Getting elements sequence from selected configuration for checking purpose
    252         out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration)
    253         assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration)
    254         # Elements sequence backup
    255         f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w")
    256         f_ConfigElementsOrder.write(out)
    257         f_ConfigElementsOrder.close()
    258 
    259         # Checking new elements sequence order conformity for selected configuration
    260         log.I("Checking new elements sequence order for configuration")
    261         f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r")
    262         f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "r")
    263         new_element_names = f_ConfigElementsOrder.read().splitlines()
    264         element_name = f_ConfigElementsOrder_Backup.read().splitlines()
    265         assert element_name==new_element_names, "ERROR : getElementSequence errors have affected elements order on domain %s" % (self.configuration)
    266         log.I("Elements sequence order not affected by getElementSequence errors")
    267 
    268         # Closing and removing temp file
    269         f_ConfigElementsOrder.close()
    270         f_ConfigElementsOrder_Backup.close()
    271         os.remove("f_ConfigElementsOrder")
    272         os.remove("f_ConfigElementsOrder_Backup")
    273         # Removing created domain element
    274         out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path))
    275         assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path)
    276         assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path)
    277         out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_2_path))
    278         assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path)
    279         assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path)
    280