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""" 32Element Sequence testcases 33 34List of tested functions : 35-------------------------- 36 - [setElementSequence] function 37 - [getElementSequence] function 38 39Test cases : 40------------ 41 - Testing setElementSequence errors 42 - Testing getElementSequence errors 43 - Testing nominal case 44""" 45import os 46from Util.PfwUnitTestLib import PfwTestCase 47from Util import ACTLogging 48log=ACTLogging.Logger() 49 50class 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 f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w") 111 f_ConfigElementsOrder.write(out) 112 f_ConfigElementsOrder.close() 113 f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r") 114 element_name = f_ConfigElementsOrder.readline().strip('\n') 115 assert element_name==self.elem_2_path, "ERROR : Error while modifying configuration %s elements order on domain %s" % (self.configuration) 116 element_name = f_ConfigElementsOrder.readline().strip('\n') 117 assert element_name==self.elem_0_path, "ERROR : Error while modifying configuration %s elements order on domain %s" % (self.configuration) 118 element_name = f_ConfigElementsOrder.readline().strip('\n') 119 assert element_name==self.elem_1_path, "ERROR : Error while modifying configuration %s elements order on domain %s" % (self.configuration) 120 log.I("New elements sequence order conform to expected order for configuration %s" % (self.configuration)) 121 # Closing and removing temp file 122 f_ConfigElementsOrder.close() 123 os.remove("f_ConfigElementsOrder") 124 # Removing created domain element 125 out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path)) 126 assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) 127 assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) 128 out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_2_path)) 129 assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) 130 assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) 131 132 def test_setElementSequence_errors(self): 133 """ 134 Testing setElementSequence_errors 135 --------------------------------- 136 Test case description : 137 ~~~~~~~~~~~~~~~~~~~~~~~ 138 - Setting an element not belonging to configuration 139 - Setting undefined element in sequence order 140 Tested commands : 141 ~~~~~~~~~~~~~~~~~ 142 - [setElementSequence] function 143 Expected result : 144 ~~~~~~~~~~~~~~~~~ 145 - all errors correctly detected 146 - no impact on initial sequences order 147 """ 148 log.D(self.test_setElementSequence_errors.__doc__) 149 150 # Adding a new domain element 151 log.I("Working on domain %s" % (self.domain_name)) 152 log.I("Adding a new domain element to domain %s" % (self.domain_name)) 153 out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path)) 154 assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) 155 assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) 156 log.I("New domain element %s added to domain %s" % (self.elem_1_path, self.domain_name)) 157 158 # Getting elements sequence from selected configuration 159 log.I("Getting elements sequence from configuration %s" % (self.configuration)) 160 out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) 161 assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) 162 log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out)) 163 164 # Elements sequence backup 165 f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "w") 166 f_ConfigElementsOrder_Backup.write(out) 167 f_ConfigElementsOrder_Backup.close() 168 169 # Setting an element not belonging to configuration in sequence order 170 log.I("Setting an element not belonging to configuration %s in sequence order" % (self.configuration)) 171 out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, self.elem_2_path, self.elem_0_path, self.elem_1_path) 172 assert err == None, "ERROR : command [setElementSequence] - Error while setting elements sequence for configuration %s" % (self.configuration) 173 assert out != "Done", "ERROR : command [setElementSequence] - Error not detected when setting an element not belonging to configuration" 174 175 # Setting undefined element in sequence order for selected configuration 176 log.I("Setting undefined element in sequence order for configuration %s" % (self.configuration)) 177 out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, "Wrong_Element_Name", self.elem_0_path, self.elem_1_path) 178 assert err == None, "ERROR : command [setElementSequence] - Error while setting elements sequence for configuration %s" % (self.configuration) 179 assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when setting an undefined element to configuration" 180 181 # Getting elements sequence from selected configuration for checking purpose 182 out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) 183 assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) 184 # Elements sequence backup 185 f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w") 186 f_ConfigElementsOrder.write(out) 187 f_ConfigElementsOrder.close() 188 189 # Checking new elements sequence order conformity for selected configuration 190 log.I("Checking new elements sequence order for configuration") 191 f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r") 192 f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "r") 193 new_element_name = f_ConfigElementsOrder.readline().strip('\n') 194 element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') 195 assert element_name==new_element_name, "ERROR : setElementSequence errors have affected elements order on domain %s" % (self.configuration) 196 new_element_name = f_ConfigElementsOrder.readline().strip('\n') 197 element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') 198 assert element_name==new_element_name, "ERROR : setElementSequence errors have affected elements order on domain %s" % (self.configuration) 199 log.I("Elements sequence order not affected by setElementSequence errors") 200 201 # Closing and removing temp file 202 f_ConfigElementsOrder.close() 203 f_ConfigElementsOrder_Backup.close() 204 os.remove("f_ConfigElementsOrder") 205 os.remove("f_ConfigElementsOrder_Backup") 206 # Removing created domain element 207 out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path)) 208 assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) 209 assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) 210 211 def test_getElementSequence_errors(self): 212 """ 213 Testing getElementSequence_errors 214 --------------------------------- 215 Test case description : 216 ~~~~~~~~~~~~~~~~~~~~~~~ 217 - Getting an element sequence on a wrong domain name 218 - Getting an element sequence on a wrong configuration name 219 Tested commands : 220 ~~~~~~~~~~~~~~~~~ 221 - [getElementSequence] function 222 Expected result : 223 ~~~~~~~~~~~~~~~~~ 224 - all errors correctly detected 225 - no impact on initial sequences order 226 """ 227 log.D(self.test_getElementSequence_errors.__doc__) 228 229 # Adding new domain elements 230 log.I("Adding a new domain element to domain %s" % (self.domain_name)) 231 out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path)) 232 assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) 233 assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) 234 log.I("Adding a new domain element to domain %s" % (self.domain_name)) 235 out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_2_path)) 236 assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) 237 assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) 238 log.I("New domain elements %s and %s added to domain %s" % (self.elem_1_path, self.elem_2_path, self.domain_name)) 239 240 # Getting elements sequence from selected configuration 241 log.I("Getting elements sequence from configuration %s" % (self.configuration)) 242 out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) 243 assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) 244 log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out)) 245 246 # Elements sequence backup 247 f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "w") 248 f_ConfigElementsOrder_Backup.write(out) 249 f_ConfigElementsOrder_Backup.close() 250 251 # Getting an element sequence on a wrong domain name 252 log.I("Getting an element sequence on a wrong domain name") 253 out, err = self.pfw.sendCmd("getElementSequence", "Wrong_Domain_Name", self.configuration) 254 assert err == None, "ERROR : command [getElementSequence] - Error when getting elements sequence for configuration %s" % (self.configuration) 255 assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when getting elements sequence for a wrong domain name" 256 257 # Getting an element sequence on a wrong configuration name 258 log.I("Getting an element sequence on a wrong configuration name") 259 out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, "Wrong_Configuration_Name") 260 assert err == None, "ERROR : command [getElementSequence] - Error when getting elements sequence on a wrong configuration name" 261 assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when getting elements sequence on a wrong configuration name" 262 263 # Getting elements sequence from selected configuration for checking purpose 264 out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) 265 assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) 266 # Elements sequence backup 267 f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w") 268 f_ConfigElementsOrder.write(out) 269 f_ConfigElementsOrder.close() 270 271 # Checking new elements sequence order conformity for selected configuration 272 log.I("Checking new elements sequence order for configuration") 273 f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r") 274 f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "r") 275 new_element_name = f_ConfigElementsOrder.readline().strip('\n') 276 element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') 277 assert element_name==new_element_name, "ERROR : getElementSequence errors have affected elements order on domain %s" % (self.configuration) 278 new_element_name = f_ConfigElementsOrder.readline().strip('\n') 279 element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') 280 assert element_name==new_element_name, "ERROR : getElementSequence errors have affected elements order on domain %s" % (self.configuration) 281 log.I("Elements sequence order not affected by getElementSequence errors") 282 283 # Closing and removing temp file 284 f_ConfigElementsOrder.close() 285 f_ConfigElementsOrder_Backup.close() 286 os.remove("f_ConfigElementsOrder") 287 os.remove("f_ConfigElementsOrder_Backup") 288 # Removing created domain element 289 out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path)) 290 assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) 291 assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) 292 out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_2_path)) 293 assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) 294 assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) 295