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""" 32Save and restore configuration testcases 33 34List of tested functions : 35-------------------------- 36 - [saveConfiguration] function 37 - [restoreConfiguration] function 38 39Test cases : 40------------ 41 - Testing nominal case 42 - Testing saveConfiguration errors 43 - Testing restoreConfiguration errors 44""" 45 46from Util.PfwUnitTestLib import PfwTestCase 47from Util import ACTLogging 48log=ACTLogging.Logger() 49 50# Test of Domains - save/restore configuration 51class TestCases(PfwTestCase): 52 def setUp(self): 53 self.pfw.sendCmd("setTuningMode", "on") 54 self.domain_name = "Domain_0" 55 self.conf_1 = "Conf_0" 56 self.conf_2 = "Conf_1" 57 self.param_name = "/Test/Test/TEST_DIR/INT8" 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 - save a configuration 69 - restore a configuration 70 Tested commands : 71 ~~~~~~~~~~~~~~~~~ 72 - [saveConfiguration] function 73 - [restoreConfiguration] function 74 Expected result : 75 ~~~~~~~~~~~~~~~~~ 76 - all operations succeed 77 """ 78 log.D(self.test_Nominal_Case.__doc__) 79 80 # Saving original parameter value 81 log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) 82 out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) 83 assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) 84 assert out == "Done", out 85 out, err = self.pfw.sendCmd("getParameter", self.param_name) 86 assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) 87 Param_saved_1 = int(out) 88 log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) 89 90 # Modifying parameter value 91 log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) 92 out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) 93 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 94 log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1)) 95 96 # Saving new parameter value 97 log.I("saving configuration %s from domain %s" % (self.conf_1, self.domain_name)) 98 out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name, self.conf_1) 99 assert err == None, "Error when saving configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) 100 assert out == "Done", out 101 out, err = self.pfw.sendCmd("getParameter", self.param_name) 102 assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) 103 Param_saved_1 = int(out) 104 log.I("new saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) 105 106 # Modifying and restoring parameter value 107 log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) 108 out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) 109 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 110 out, err = self.pfw.sendCmd("getParameter", self.param_name) 111 assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) 112 Param_saved_2 = int(out) 113 log.I("new parameter %s value on %s = %s in place of %s" % (self.param_name, self.conf_1, str(Param_saved_2), Param_saved_1)) 114 log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) 115 out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) 116 assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) 117 assert out == "Done", out 118 out, err = self.pfw.sendCmd("getParameter", self.param_name) 119 assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) 120 Param_saved_2 = int(out) 121 assert Param_saved_2 == Param_saved_1, "Error when restoring configuration %s from domain %s" % (self.conf_1, self.domain_name) 122 log.I("saving and restoring configuration works fine") 123 124 def test_Save_Config_Error(self): 125 """ 126 Testing saveConfiguration error 127 ------------------------------- 128 Test case description : 129 ~~~~~~~~~~~~~~~~~~~~~~~ 130 - save a configuration with a missing argument 131 - save a configuration with a wrong domain name 132 - save a configuration with a wrong configuration name 133 Tested commands : 134 ~~~~~~~~~~~~~~~~~ 135 - [saveConfiguration] function 136 Expected result : 137 ~~~~~~~~~~~~~~~~~ 138 - errors correctly detected 139 """ 140 log.D(self.test_Save_Config_Error.__doc__) 141 # Saving original parameter value and setting a new value to parameter for testing purpose 142 log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) 143 out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) 144 assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) 145 assert out == "Done", out 146 out, err = self.pfw.sendCmd("getParameter", self.param_name) 147 assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) 148 Param_saved_1 = int(out) 149 log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) 150 log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) 151 out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) 152 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 153 log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1)) 154 155 # Configuration saving errors 156 log.I("saving configuration error test cases :") 157 log.I("saving configuration with a missing argument") 158 out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name) 159 assert err == None, "ERROR : Error when saving configuration with a missing argument" 160 assert out != "Done", "ERROR : Error not detected when saving configuration with a missing argument" 161 log.I("saving configuration with a wrong domain name") 162 out, err = self.pfw.sendCmd("saveConfiguration", "Wrong_Domain_Name", self.conf_1) 163 assert err == None, "ERROR : Error when saving configuration with a wrong domain name" 164 assert out != "Done", "ERROR : Error not detected when saving configuration with a wrong domain name" 165 log.I("saving configuration with a wrong configuration name") 166 out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name, "Wrong_Configuration_Name") 167 assert err == None, "ERROR : Error when saving configuration with a wrong configuration name" 168 assert out != "Done", "ERROR : Error not detected when saving configuration with a wrong configuration name" 169 log.I("saving configuration error test cases : errors correctly detected") 170 171 # Checking that no error has affected original configuration save 172 log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) 173 out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) 174 assert err == None, "error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) 175 assert out == "Done", out 176 out, err = self.pfw.sendCmd("getParameter", self.param_name) 177 assert err == None, "error when getting parameter %s : %s" % (self.param_name, err) 178 Param_saved_2 = int(out) 179 assert Param_saved_2 == Param_saved_1, "error when restoring configuration %s from domain %s, parameter %s affected by configuration saving error" % (self.conf_1, self.domain_name, Param_saved_1) 180 log.I("Test passed : saving errors correctly detected, no impact on previously saved configuration") 181 182 def test_Restore_Config_Error(self): 183 """ 184 Testing restoreConfiguration error 185 ---------------------------------- 186 Test case description : 187 ~~~~~~~~~~~~~~~~~~~~~~~ 188 - restore a configuration with a missing argument 189 - restore a configuration with a wrong domain name 190 - restore a configuration with a wrong configuration name 191 Tested commands : 192 ~~~~~~~~~~~~~~~~~ 193 - [restoreConfiguration] function 194 Expected result : 195 ~~~~~~~~~~~~~~~~~ 196 - errors correctly detected 197 - configuration's parameters not affected by errors 198 """ 199 200 log.D(self.test_Restore_Config_Error.__doc__) 201 # Saving original parameter value and setting a new value to parameter for testing purpose 202 log.I("restore configuration %s from domain %s" % (self.conf_1, self.domain_name)) 203 out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) 204 assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) 205 assert out == "Done", out 206 out, err = self.pfw.sendCmd("getParameter", self.param_name) 207 assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) 208 Param_saved_1 = int(out) 209 log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) 210 log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) 211 out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) 212 assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) 213 log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1)) 214 out, err = self.pfw.sendCmd("getParameter", self.param_name) 215 assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) 216 Param_saved_2 = int(out) 217 218 # Configuration restore errors 219 log.I("restoring configuration error test cases :") 220 log.I("restoring configuration with a missing argument") 221 out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name) 222 assert err == None, "ERROR : Error when restoring configuration with a missing argument" 223 assert out != "Done", "ERROR : Error not detected when restoring configuration with a missing argument" 224 log.I("restoring configuration with a wrong domain name") 225 out, err = self.pfw.sendCmd("restoreConfiguration", "Wrong_Domain_Name", self.conf_1) 226 assert err == None, "ERROR : Error when restoring configuration with a wrong domain name" 227 assert out != "Done", "ERROR : Error not detected when restoring configuration with a wrong domain name" 228 log.I("restoring configuration with a wrong configuration name") 229 out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, "Wrong_Configuration_Name") 230 assert err == None, "ERROR : Error when restoring configuration with a wrong configuration name" 231 assert out != "Done", "ERROR : Error not detected when restoring configuration with a wrong configuration name" 232 log.I("restoring configuration error test cases : errors correctly detected") 233 234 # Checking that no error has affected configuration's parameter value 235 out, err = self.pfw.sendCmd("getParameter", self.param_name) 236 assert err == None, "error when getting parameter %s : %s" % (self.param_name, err) 237 Param_saved_1 = int(out) 238 assert Param_saved_2 == Param_saved_1, "error when restoring configuration %s from domain %s, parameter %s affected by configuration restoration error" % (self.conf_1, self.domain_name, Param_saved_1) 239 log.I("Test passed : restoring errors correctly detected, no impact on previously modified configuration's parameter") 240