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 Array parameter type testcases : INT16 Array 33 34 List of tested functions : 35 -------------------------- 36 - [setParameter] function 37 - [getParameter] function 38 39 Initial Settings : 40 ------------------ 41 UINT16 Array = 16bits signed int array : 42 - Array size : 5 43 - values range : [-50, 50] 44 45 Test cases : 46 ------------ 47 - Testing nominal case 48 - Testing minimum 49 - Testing minimum overflow 50 - Testing maximum 51 - Testing maximum overflow 52 - Testing array index out of bounds 53 """ 54 import os 55 import commands 56 from Util.PfwUnitTestLib import PfwTestCase 57 from Util import ACTLogging 58 log=ACTLogging.Logger() 59 60 61 from ctypes import c_uint16 62 63 64 class TestCases(PfwTestCase): 65 66 def setUp(self): 67 self.param_name = "/Test/Test/TEST_DIR/INT16_ARRAY" 68 self.param_short_name = os.environ["PFW_RESULT"] + "/INT16_ARRAY" 69 print '\r' 70 self.pfw.sendCmd("setTuningMode", "on") 71 print '\r' 72 self.array_size = 5 73 self.array_min = -50 74 self.array_max = 50 75 76 def tearDown(self): 77 self.pfw.sendCmd("setTuningMode", "off") 78 79 def test_Nominal_Case(self): 80 """ 81 Testing INT16_ARRAY Nominal Case 82 -------------------------------- 83 Test case description : 84 ~~~~~~~~~~~~~~~~~~~~~~~ 85 - Set every INT16_ARRAY elements to autorized values 86 Tested commands : 87 ~~~~~~~~~~~~~~~~~ 88 - [setParameter] function 89 Used commands : 90 ~~~~~~~~~~~~~~~ 91 - [getParameter] function 92 Expected result : 93 ~~~~~~~~~~~~~~~~~ 94 - INT16_ARRAY array elements correctly recorded 95 - Blackboard and filesystem values checked 96 """ 97 log.D(self.test_Nominal_Case.__doc__) 98 99 for index in range (self.array_size): 100 indexed_array_value = index + self.array_min 101 if indexed_array_value>self.array_max: 102 indexed_array_value=self.array_max 103 hex_indexed_array_value = hex(c_uint16(indexed_array_value).value) 104 #Check parameter value setting 105 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 106 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 107 assert err == None, log.E("when setting parameter %s[%s]: %s" 108 % (self.param_name, str(index), err)) 109 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 110 % (self.param_name, str(index), out)) 111 #Check parameter value on blackboard 112 out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "") 113 assert err == None, log.E("when setting parameter %s[%s] : %s" 114 % (self.param_name, str(index), err)) 115 assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s" 116 % (self.param_name, str(index), str(indexed_array_value), out)) 117 #Check parameter value on filesystem 118 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 119 assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error" 120 % (self.param_name, str(index))) 121 122 def test_Min_Value(self): 123 """ 124 Testing INT16_ARRAY minimum value 125 --------------------------------- 126 Test case description : 127 ~~~~~~~~~~~~~~~~~~~~~~~ 128 - Set every INT16_ARRAY elements to minimum values : 0 129 Tested commands : 130 ~~~~~~~~~~~~~~~~~ 131 - [setParameter] function 132 Used commands : 133 ~~~~~~~~~~~~~~~ 134 - [getParameter] function 135 Expected result : 136 ~~~~~~~~~~~~~~~~~ 137 - INT16_ARRAY array elements correctly recorded 138 - Blackboard and filesystem values checked 139 """ 140 log.D(self.test_Min_Value.__doc__) 141 index = 0 142 indexed_array_value = self.array_min 143 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 144 hex_indexed_array_value = hex(c_uint16(indexed_array_value).value) 145 #Check parameter value setting 146 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 147 assert err == None, log.E("when setting parameter %s[%s]: %s" 148 % (self.param_name, str(index), err)) 149 assert out == "Done", log.E("when setting parameter %s[%s]: %s" 150 % (self.param_name, str(index), out)) 151 #Check parameter value on blackboard 152 out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "") 153 assert err == None, log.E("when setting parameter %s[%s] : %s" 154 % (self.param_name, str(index), err)) 155 assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s" 156 % (self.param_name, str(index), str(indexed_array_value), out)) 157 #Check parameter value on filesystem 158 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 159 assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error" 160 % (self.param_name, str(index))) 161 162 def test_Min_Value_Overflow(self): 163 """ 164 Testing INT16_ARRAY parameter values out of negative range 165 ---------------------------------------------------------- 166 Test case description : 167 ~~~~~~~~~~~~~~~~~~~~~~~ 168 - Set every INT16_ARRAY elements to -1 169 Tested commands : 170 ~~~~~~~~~~~~~~~~~ 171 - [setParameter] function 172 Used commands : 173 ~~~~~~~~~~~~~~~ 174 - [getParameter] function 175 Expected result : 176 ~~~~~~~~~~~~~~~~~ 177 - INT16_ARRAY array elements not recorded 178 - Error correctly detected 179 """ 180 log.D(self.test_Min_Value_Overflow.__doc__) 181 index = 0 182 indexed_array_value = self.array_min 183 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 184 #Check initial parameter value setting 185 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 186 assert err == None, log.E("when setting parameter %s[%s]: %s" 187 % (self.param_name, str(index), err)) 188 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 189 % (self.param_name, str(index), out)) 190 param_check = open(self.param_short_name).read().splitlines()[index] 191 #Check final parameter value setting 192 indexed_array_value = indexed_array_value - 1 193 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value), expectSuccess=False) 194 assert err == None, log.E("when setting parameter %s[%s]: %s" 195 % (self.param_name, str(index), err)) 196 assert out != "Done", log.F("Error not detected when setting parameter %s[%s] out of bounds" 197 % (self.param_name, str(index))) 198 #Check parameter value on filesystem 199 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 200 assert indexed_files_system_array_value == param_check, log.F("FILESSYSTEM : %s[%s] forbiden update" 201 % (self.param_name, str(index))) 202 203 def test_Max_Value(self): 204 """ 205 Testing INT16_ARRAY maximum value 206 --------------------------------- 207 Test case description : 208 ~~~~~~~~~~~~~~~~~~~~~~~ 209 - Set every INT16_ARRAY elements to maximum values : 15 210 Tested commands : 211 ~~~~~~~~~~~~~~~~~ 212 - [setParameter] function 213 Used commands : 214 ~~~~~~~~~~~~~~~ 215 - [getParameter] function 216 Expected result : 217 ~~~~~~~~~~~~~~~~~ 218 - INT16_ARRAY array elements correctly recorded 219 - Blackboard and filesystem values checked 220 """ 221 log.D(self.test_Max_Value.__doc__) 222 index = 0 223 indexed_array_value = self.array_max 224 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 225 hex_indexed_array_value = hex(c_uint16(indexed_array_value).value) 226 #Check parameter value setting 227 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 228 assert err == None, log.E("when setting parameter %s[%s]: %s" 229 % (self.param_name, str(index), err)) 230 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 231 % (self.param_name, str(index), out)) 232 #Check parameter value on blackboard 233 out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "") 234 assert err == None, log.E("when setting parameter %s[%s] : %s" 235 % (self.param_name, str(index), err)) 236 assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s" 237 % (self.param_name, str(index), str(indexed_array_value), out)) 238 #Check parameter value on filesystem 239 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 240 assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error" 241 % (self.param_name, str(index))) 242 243 def test_Max_Value_Overflow(self): 244 """ 245 Testing INT16_ARRAY parameter values out of positive range 246 ---------------------------------------------------------- 247 Test case description : 248 ~~~~~~~~~~~~~~~~~~~~~~~ 249 - Set every INT16_ARRAY elements to 16 250 Tested commands : 251 ~~~~~~~~~~~~~~~~~ 252 - [setParameter] function 253 Used commands : 254 ~~~~~~~~~~~~~~~ 255 - [getParameter] function 256 Expected result : 257 ~~~~~~~~~~~~~~~~~ 258 - INT16_ARRAY array elements not recorded 259 - Error correctly detected 260 """ 261 log.D(self.test_Max_Value_Overflow.__doc__) 262 index = 0 263 indexed_array_value = self.array_max 264 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 265 #Check initial parameter value setting 266 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value)) 267 assert err == None, log.E("when setting parameter %s[%s]: %s" 268 % (self.param_name, str(index), err)) 269 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 270 % (self.param_name, str(index), out)) 271 param_check = open(self.param_short_name).read().splitlines()[index] 272 #Check final parameter value setting 273 indexed_array_value = indexed_array_value + 1 274 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value), expectSuccess=False) 275 assert err == None, log.E("when setting parameter %s[%s]: %s" 276 % (self.param_name, str(index), err)) 277 assert out != "Done", log.F("Error not detected when setting parameter %s[%s] out of bounds" 278 % (self.param_name, str(index))) 279 #Check parameter value on filesystem 280 indexed_files_system_array_value = open(self.param_short_name).read().splitlines()[index] 281 assert indexed_files_system_array_value == param_check, log.F("FILESSYSTEM : %s[%s] forbiden update" 282 % (self.param_name, str(index))) 283 284 def test_Array_Index_Overflow(self): 285 """ 286 Testing Array index out of bounds 287 --------------------------------- 288 Test case description : 289 ~~~~~~~~~~~~~~~~~~~~~~~ 290 - Set an out of bounds array indexed element 291 Tested commands : 292 ~~~~~~~~~~~~~~~~~ 293 - [setParameter] function 294 Used commands : 295 ~~~~~~~~~~~~~~~ 296 - [getParameter] function 297 Expected result : 298 ~~~~~~~~~~~~~~~~~ 299 - INT16_ARRAY array elements not recorded 300 - Error correctly detected 301 """ 302 log.D(self.test_Array_Index_Overflow.__doc__) 303 index_values = (self.array_size-1, self.array_size+1, -1) 304 for index in index_values: 305 print index 306 indexed_array_value = self.array_max 307 indexed_array_value_path = "".join([self.param_name, "/", str(index)]) 308 #Check parameter value setting 309 out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value), expectSuccess=None) 310 if index in [0, self.array_size-1]: 311 assert err == None, log.E("when setting parameter %s[%s]: %s" 312 % (self.param_name, str(index), err)) 313 assert out == "Done", log.F("when setting parameter %s[%s]: %s" 314 % (self.param_name, str(index), out)) 315 else: 316 assert err == None, log.E("when setting parameter %s[%s]: %s" 317 % (self.param_name, str(index), err)) 318 assert out != "Done", log.F("Error not detected when setting array %s index out of bounds" 319 % (self.param_name)) 320