1 #!/usr/bin/python2 2 # -*-coding:utf-8 -* 3 4 # Copyright (c) 2011-2015, Intel Corporation 5 # All rights reserved. 6 # 7 # Redistribution and use in source and binary forms, with or without modification, 8 # are permitted provided that the following conditions are met: 9 # 10 # 1. Redistributions of source code must retain the above copyright notice, this 11 # list of conditions and the following disclaimer. 12 # 13 # 2. Redistributions in binary form must reproduce the above copyright notice, 14 # this list of conditions and the following disclaimer in the documentation and/or 15 # other materials provided with the distribution. 16 # 17 # 3. Neither the name of the copyright holder nor the names of its contributors 18 # may be used to endorse or promote products derived from this software without 19 # specific prior written permission. 20 # 21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32 """ 33 Array parameter type testcases : UINT32 Array 34 35 List of tested functions : 36 -------------------------- 37 - [setParameter] function 38 - [getParameter] function 39 40 Initial Settings : 41 ------------------ 42 UINT8 Array = 32bits unsigned int array : 43 - Array size : 10 44 - values range : [0, 100] 45 46 Test cases : 47 ------------ 48 - Testing nominal case 49 - Testing minimum 50 - Testing minimum overflow 51 - Testing maximum 52 - Testing maximum overflow 53 - Testing array index out of bounds 54 - Testing value format error 55 """ 56 import os 57 import commands 58 from Util.PfwUnitTestLib import PfwTestCase 59 from Util import ACTLogging 60 log=ACTLogging.Logger() 61 62 from ctypes import c_uint16 63 64 65 class TestCases(PfwTestCase): 66 67 def setUp(self): 68 self.param_name = "/Test/Test/TEST_DIR/UINT32_ARRAY" 69 self.param_short_name = os.environ["PFW_RESULT"] + "/UINT32_ARRAY" 70 print '\r' 71 self.pfw.sendCmd("setTuningMode", "on") 72 print '\r' 73 self.array_size = 100 74 self.array_min = 0 75 self.array_max = 100 76 77 def tearDown(self): 78 self.pfw.sendCmd("setTuningMode", "off") 79 80 def test_Nominal_Case(self): 81 """ 82 Testing UINT32_ARRAY Nominal Case 83 --------------------------------- 84 Test case description : 85 ~~~~~~~~~~~~~~~~~~~~~~~ 86 - Set every UINT32_ARRAY elements to autorized values 87 Tested commands : 88 ~~~~~~~~~~~~~~~~~ 89 - [setParameter] function 90 Used commands : 91 ~~~~~~~~~~~~~~~ 92 - [getParameter] function 93 Expected result : 94 ~~~~~~~~~~~~~~~~~ 95 - UINT32_ARRAY array elements correctly recorded 96 - Blackboard and filesystem values checked 97 """ 98 log.D(self.test_Nominal_Case.__doc__) 99 100 for index in range (self.array_size): 101 indexed_array_value = index + self.array_min 102 if indexed_array_value>self.array_max: 103 indexed_array_value=self.array_max 104 hex_indexed_array_value = hex(c_uint16(indexed_array_value).value) 105 #Check parameter value setting 106 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 107 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 108 assert err == None, log.E("when setting parameter %s[%s]: %s" 109 % (self.param_name, str(index), err)) 110 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 111 % (self.param_name, str(index), out)) 112 #Check parameter value on blackboard 113 out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "") 114 assert err == None, log.E("when setting parameter %s[%s] : %s" 115 % (self.param_name, str(index), err)) 116 assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s" 117 % (self.param_name, str(index), str(indexed_array_value), out)) 118 #Check parameter value on filesystem 119 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 120 assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error" 121 % (self.param_name, str(index))) 122 123 def test_Min_Value(self): 124 """ 125 Testing UINT32_ARRAY minimum value 126 ---------------------------------- 127 Test case description : 128 ~~~~~~~~~~~~~~~~~~~~~~~ 129 - Set every UINT32_ARRAY elements to minimum values : 0 130 Tested commands : 131 ~~~~~~~~~~~~~~~~~ 132 - [setParameter] function 133 Used commands : 134 ~~~~~~~~~~~~~~~ 135 - [getParameter] function 136 Expected result : 137 ~~~~~~~~~~~~~~~~~ 138 - UINT32_ARRAY array elements correctly recorded 139 - Blackboard and filesystem values checked 140 """ 141 log.D(self.test_Min_Value.__doc__) 142 index = 0 143 indexed_array_value = self.array_min 144 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 145 hex_indexed_array_value = hex(c_uint16(indexed_array_value).value) 146 #Check parameter value setting 147 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 148 assert err == None, log.E("when setting parameter %s[%s]: %s" 149 % (self.param_name, str(index), err)) 150 assert out == "Done", log.E("when setting parameter %s[%s]: %s" 151 % (self.param_name, str(index), out)) 152 #Check parameter value on blackboard 153 out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "") 154 assert err == None, log.E("when setting parameter %s[%s] : %s" 155 % (self.param_name, str(index), err)) 156 assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s" 157 % (self.param_name, str(index), str(indexed_array_value), out)) 158 #Check parameter value on filesystem 159 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 160 assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error" 161 % (self.param_name, str(index))) 162 163 def test_Min_Value_Overflow(self): 164 """ 165 Testing UINT32_ARRAY parameter values out of negative range 166 ----------------------------------------------------------- 167 Test case description : 168 ~~~~~~~~~~~~~~~~~~~~~~~ 169 - Set every UINT32_ARRAY elements to -1 170 Tested commands : 171 ~~~~~~~~~~~~~~~~~ 172 - [setParameter] function 173 Used commands : 174 ~~~~~~~~~~~~~~~ 175 - [getParameter] function 176 Expected result : 177 ~~~~~~~~~~~~~~~~~ 178 - UINT32_ARRAY array elements not recorded 179 - Error correctly detected 180 """ 181 log.D(self.test_Min_Value_Overflow.__doc__) 182 index = 0 183 indexed_array_value = self.array_min 184 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 185 #Check initial parameter value setting 186 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 187 assert err == None, log.E("when setting parameter %s[%s]: %s" 188 % (self.param_name, str(index), err)) 189 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 190 % (self.param_name, str(index), out)) 191 param_check = open(self.param_short_name).read().splitlines()[index] 192 #Check final parameter value setting 193 indexed_array_value = indexed_array_value - 1 194 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value), expectSuccess=False) 195 assert err == None, log.E("when setting parameter %s[%s]: %s" 196 % (self.param_name, str(index), err)) 197 assert out != "Done", log.F("Error not detected when setting parameter %s[%s] out of bounds" 198 % (self.param_name, str(index))) 199 #Check parameter value on filesystem 200 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 201 assert indexed_files_system_array_value == param_check, log.F("FILESSYSTEM : %s[%s] forbiden update" 202 % (self.param_name, str(index))) 203 204 def test_Max_Value(self): 205 """ 206 Testing UINT32_ARRAY maximum value 207 ---------------------------------- 208 Test case description : 209 ~~~~~~~~~~~~~~~~~~~~~~~ 210 - Set every UINT32_ARRAY elements to maximum values : 15 211 Tested commands : 212 ~~~~~~~~~~~~~~~~~ 213 - [setParameter] function 214 Used commands : 215 ~~~~~~~~~~~~~~~ 216 - [getParameter] function 217 Expected result : 218 ~~~~~~~~~~~~~~~~~ 219 - UINT32_ARRAY array elements correctly recorded 220 - Blackboard and filesystem values checked 221 """ 222 log.D(self.test_Max_Value.__doc__) 223 index = 0 224 indexed_array_value = self.array_max 225 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 226 hex_indexed_array_value = hex(c_uint16(indexed_array_value).value) 227 #Check parameter value setting 228 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 229 assert err == None, log.E("when setting parameter %s[%s]: %s" 230 % (self.param_name, str(index), err)) 231 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 232 % (self.param_name, str(index), out)) 233 #Check parameter value on blackboard 234 out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "") 235 assert err == None, log.E("when setting parameter %s[%s] : %s" 236 % (self.param_name, str(index), err)) 237 assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s" 238 % (self.param_name, str(index), str(indexed_array_value), out)) 239 #Check parameter value on filesystem 240 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 241 assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error" 242 % (self.param_name, str(index))) 243 244 def test_Max_Value_Overflow(self): 245 """ 246 Testing UINT32_ARRAY parameter values out of positive range 247 ----------------------------------------------------------- 248 Test case description : 249 ~~~~~~~~~~~~~~~~~~~~~~~ 250 - Set every UINT32_ARRAY elements to 16 251 Tested commands : 252 ~~~~~~~~~~~~~~~~~ 253 - [setParameter] function 254 Used commands : 255 ~~~~~~~~~~~~~~~ 256 - [getParameter] function 257 Expected result : 258 ~~~~~~~~~~~~~~~~~ 259 - UINT32_ARRAY array elements not recorded 260 - Error correctly detected 261 """ 262 log.D(self.test_Max_Value_Overflow.__doc__) 263 index = 0 264 indexed_array_value = self.array_max 265 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 266 #Check initial parameter value setting 267 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 268 assert err == None, log.E("when setting parameter %s[%s]: %s" 269 % (self.param_name, str(index), err)) 270 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 271 % (self.param_name, str(index), out)) 272 param_check = open(self.param_short_name).read().splitlines()[index] 273 #Check final parameter value setting 274 indexed_array_value = indexed_array_value + 1 275 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value), expectSuccess=False) 276 assert err == None, log.E("when setting parameter %s[%s]: %s" 277 % (self.param_name, str(index), err)) 278 assert out != "Done", log.F("Error not detected when setting parameter %s[%s] out of bounds" 279 % (self.param_name, str(index))) 280 #Check parameter value on filesystem 281 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 282 assert indexed_files_system_array_value == param_check, log.F("FILESSYSTEM : %s[%s] forbiden update" 283 % (self.param_name, str(index))) 284 285 def test_Array_Index_Overflow(self): 286 """ 287 Testing Array index out of bounds 288 --------------------------------- 289 Test case description : 290 ~~~~~~~~~~~~~~~~~~~~~~~ 291 - Set an out of bounds array indexed element 292 Tested commands : 293 ~~~~~~~~~~~~~~~~~ 294 - [setParameter] function 295 Used commands : 296 ~~~~~~~~~~~~~~~ 297 - [getParameter] function 298 Expected result : 299 ~~~~~~~~~~~~~~~~~ 300 - UINT32_ARRAY array elements not recorded 301 - Error correctly detected 302 """ 303 log.D(self.test_Array_Index_Overflow.__doc__) 304 index_values = (self.array_size-1, self.array_size+1, -1) 305 for index in index_values: 306 print index 307 indexed_array_value = self.array_max 308 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 309 #Check parameter value setting 310 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value), expectSuccess=None) 311 if index in [0, self.array_size-1]: 312 assert err == None, log.E("when setting parameter %s[%s]: %s" 313 % (self.param_name, str(index), err)) 314 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 315 % (self.param_name, str(index), out)) 316 else: 317 assert err == None, log.E("when setting parameter %s[%s]: %s" 318 % (self.param_name, str(index), err)) 319 assert out != "Done", log.F("Error not detected when setting array %s index out of bounds" 320 % (self.param_name)) 321