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 Integer parameter type testcases - INT8_Max 33 34 List of tested functions : 35 -------------------------- 36 - [setParameter] function 37 - [getParameter] function 38 39 Initial Settings : 40 ------------------ 41 INT8_Max : 42 - size = 8 43 - range : [-128, 127] 44 45 Test cases : 46 ------------ 47 - INT8_Max parameter min value = -128 48 - INT8_Max parameter min value out of bounds = -129 49 - INT8_Max parameter max value = 127 50 - INT8_Max parameter max value out of bounds = 128 51 - INT8_Max parameter in nominal case = 50 52 """ 53 import os 54 import commands 55 from Util.PfwUnitTestLib import PfwTestCase 56 from Util import ACTLogging 57 log=ACTLogging.Logger() 58 59 # Test of type INT8_Max - range [-128, 127] 60 class TestCases(PfwTestCase): 61 def setUp(self): 62 self.param_name = "/Test/Test/TEST_DIR/INT8_Max" 63 self.pfw.sendCmd("setTuningMode", "on") 64 65 def tearDown(self): 66 self.pfw.sendCmd("setTuningMode", "off") 67 68 def test_Nominal_Case(self): 69 """ 70 Testing INT8_Max in nominal case = 50 71 ------------------------------------- 72 Test case description : 73 ~~~~~~~~~~~~~~~~~~~~~~~ 74 - set INT8_Max parameter in nominal case = 50 75 Tested commands : 76 ~~~~~~~~~~~~~~~~~ 77 - [setParameter] function 78 Used commands : 79 ~~~~~~~~~~~~~~~ 80 - [getParameter] function 81 Expected result : 82 ~~~~~~~~~~~~~~~~~ 83 - INT8_Max parameter set to 50 84 - Blackboard and filesystem values checked 85 """ 86 print self.test_Nominal_Case.__doc__ 87 print "INFO : INT8_Max parameter in nominal case = 50" 88 value = "50" 89 hex_value = "0x32" 90 #Set parameter value 91 out, err = self.pfw.sendCmd("setParameter", self.param_name, value) 92 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 93 assert out == "Done", out 94 #Check parameter value on blackboard 95 out, err = self.pfw.sendCmd("getParameter", self.param_name, "") 96 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 97 assert out == value, "BLACKBOARD : Incorrect value for %s, expected: %s, found: %s" % (self.param_name, value, out) 98 #Check parameter value on filesystem 99 assert open(os.environ["PFW_RESULT"] + "/INT8_Max").read()[:-1] == hex_value, "FILESYSTEM : parameter update error" 100 print "INFO : test OK" 101 102 def test_TypeMin(self): 103 """ 104 Testing INT8_Max minimal value = -128 105 ------------------------------------- 106 Test case description : 107 ~~~~~~~~~~~~~~~~~~~~~~~ 108 - set INT8_Max parameter min value = -128 109 Tested commands : 110 ~~~~~~~~~~~~~~~~~ 111 - [setParameter] function 112 Used commands : 113 ~~~~~~~~~~~~~~~ 114 - [getParameter] function 115 Expected result : 116 ~~~~~~~~~~~~~~~~~ 117 - INT8_Max parameter set to -128 118 - Blackboard and filesystem values checked 119 """ 120 print self.test_TypeMin.__doc__ 121 print "INFO : INT8_Max parameter min value = -128" 122 value = "-128" 123 hex_value = "0x80" 124 #Set parameter value 125 out, err = self.pfw.sendCmd("setParameter", self.param_name, value) 126 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 127 assert out == "Done", out 128 #Check parameter value on blackboard 129 out, err = self.pfw.sendCmd("getParameter", self.param_name, "") 130 assert err == None, "PFW : Error when setting parameter %s : %s" % (self.param_name, err) 131 assert out == value, "BLACKBOARD : Incorrect value for %s, expected: %s, found: %s" % (self.param_name, value, out) 132 #Check parameter value on filesystem 133 assert open(os.environ["PFW_RESULT"] + "/INT8_Max").read()[:-1] == hex_value, "FILESYSTEM : parameter update error" 134 print "INFO : test OK" 135 136 def test_TypeMin_Overflow(self): 137 """ 138 Testing INT8_Max parameter value out of negative range 139 ------------------------------------------------------ 140 Test case description : 141 ~~~~~~~~~~~~~~~~~~~~~~~ 142 - set INT8_Max to -129 143 Tested commands : 144 ~~~~~~~~~~~~~~~~~ 145 - [setParameter] function 146 Used commands : 147 ~~~~~~~~~~~~~~~ 148 - [getParameter] function 149 Expected result : 150 ~~~~~~~~~~~~~~~~~ 151 - error detected 152 - INT8_Max parameter not updated 153 - Blackboard and filesystem values checked 154 """ 155 print self.test_TypeMin_Overflow.__doc__ 156 print "INFO : INT8_Max parameter min value out of bounds = -129" 157 value = "-129" 158 param_check = open(os.environ["PFW_RESULT"] + "/INT8_Max").read()[:-1] 159 #Set parameter value 160 out, err = self.pfw.sendCmd("setParameter", self.param_name, value, expectSuccess=False) 161 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 162 assert out != "Done", "PFW : Error not detected when setting parameter %s out of bounds" % (self.param_name) 163 #Check parameter value on filesystem 164 assert open(os.environ["PFW_RESULT"] + "/INT8_Max").read()[:-1] == param_check, "FILESYSTEM : Forbiden parameter change" 165 print "INFO : test OK" 166 167 def test_TypeMax(self): 168 """ 169 Testing INT8_Max parameter maximum value 170 ---------------------------------------- 171 Test case description : 172 ~~~~~~~~~~~~~~~~~~~~~~~ 173 - set INT8_Max to 127 174 Tested commands : 175 ~~~~~~~~~~~~~~~~~ 176 - [setParameter] function 177 Used commands : 178 ~~~~~~~~~~~~~~~ 179 - [getParameter] function 180 Expected result : 181 ~~~~~~~~~~~~~~~~~ 182 - INT8_Max parameter set to 127 183 - Blackboard and filesystem values checked 184 """ 185 print self.test_TypeMax.__doc__ 186 print "INFO : INT8_Max parameter max value = 127" 187 value = "127" 188 hex_value = "0x7f" 189 #Set parameter value 190 out, err = self.pfw.sendCmd("setParameter", self.param_name, value) 191 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 192 assert out == "Done", out 193 #Check parameter value on blackboard 194 out, err = self.pfw.sendCmd("getParameter", self.param_name, "") 195 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 196 assert out == value, "BLACKBOARD : Incorrect value for %s, expected: %s, found: %s" % (self.param_name, value, out) 197 #Check parameter value on filesystem 198 assert open(os.environ["PFW_RESULT"] + "/INT8_Max").read()[:-1] == hex_value, "FILESYSTEM : parameter update error" 199 print "INFO : test OK" 200 201 def test_TypeMax_Overflow(self): 202 """ 203 Testing INT8_Max parameter value out of positive range 204 ------------------------------------------------------ 205 Test case description : 206 ~~~~~~~~~~~~~~~~~~~~~~~ 207 - set INT8_Max to 128 208 Tested commands : 209 ~~~~~~~~~~~~~~~~~ 210 - [setParameter] function 211 Used commands : 212 ~~~~~~~~~~~~~~~ 213 - [getParameter] function 214 Expected result : 215 ~~~~~~~~~~~~~~~~~ 216 - error detected 217 - INT8_Max parameter not updated 218 - Blackboard and filesystem values checked 219 """ 220 print self.test_TypeMax_Overflow.__doc__ 221 print "INFO : INT8_Max parameter max value out of bounds = 128" 222 value = "128" 223 param_check = open(os.environ["PFW_RESULT"] + "/INT8_Max").read()[:-1] 224 #Set parameter value 225 out, err = self.pfw.sendCmd("setParameter", self.param_name, value, expectSuccess=False) 226 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 227 assert out != "Done", "PFW : Error not detected when setting parameter %s out of bounds" % (self.param_name) 228 #Check parameter value on filesystem 229 assert open(os.environ["PFW_RESULT"] + "/INT8_Max").read()[:-1] == param_check, "FILESYSTEM : Forbiden parameter change" 230 print "INFO : test OK" 231