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