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""" 32synchronization functions testcases 33 34List of tested functions : 35-------------------------- 36 - [getAutoSync] function 37 - [setAutoSync] function 38 - [sync] function 39 40Test cases : 41------------ 42 - Testing getAutoSync nominal case 43 - Testing setAutoSync nominal case 44 - Testing sync nominal case 45 - Testing errors 46""" 47import commands, os 48import unittest 49from Util.PfwUnitTestLib import PfwTestCase 50from Util import ACTLogging 51log=ACTLogging.Logger() 52 53class TestCases(PfwTestCase): 54 55 def setUp(self): 56 57 pfw_filesystem=os.environ["PFW_RESULT"] 58 59 self.pfw.sendCmd("setTuningMode", "on") 60 self.param_name_01 = "/Test/Test/TEST_DIR/BOOL" 61 self.filesystem_01 = pfw_filesystem+"/BOOL" 62 self.param_name_02 = "/Test/Test/TEST_DIR/INT16" 63 self.filesystem_02 = pfw_filesystem+"/INT16" 64 self.param_name_03 = "/Test/Test/TEST_DIR/UINT32" 65 self.filesystem_03 = pfw_filesystem+"/UINT32" 66 67 def tearDown(self): 68 self.pfw.sendCmd("setTuningMode", "off") 69 70 def test_01_getAutoSync_Case(self): 71 """ 72 Testing getAutoSync nominal case 73 ---------------------------- 74 Test case description : 75 ~~~~~~~~~~~~~~~~~~~~~~~ 76 - enable autosync 77 - get autosync state 78 - disable autosync 79 - get autosync state 80 Tested commands : 81 ~~~~~~~~~~~~~~~~~ 82 - [setAutoSync] function 83 - [getAutoSync] function 84 Expected result : 85 ~~~~~~~~~~~~~~~~~ 86 - getAutoSync return expected state 87 """ 88 log.D(self.test_01_getAutoSync_Case.__doc__) 89 value = "on" 90 log.I("Enable autosync") 91 out,err = self.pfw.sendCmd("setAutoSync", value) 92 assert err == None, log.E("When enabling autosync : %s" % (err)) 93 assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out)) 94 log.I("Check autosync state") 95 out, err = self.pfw.sendCmd("getAutoSync","") 96 assert err == None, log.E("When getting autosync state : %s" % (err)) 97 assert out == value, log.F("setAutoSync - expected : %s , found : %s" % (value,out)) 98 value = "off" 99 log.I("Disable autosync") 100 out,err = self.pfw.sendCmd("setAutoSync", value) 101 assert err == None, log.E("When enabling autosync : %s" % (err)) 102 assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out)) 103 log.I("Check autosync state") 104 out, err = self.pfw.sendCmd("getAutoSync","") 105 assert err == None, log.E("When getting autosync state : %s" % (err)) 106 assert out == value, log.F("setAutoSync - expected : %s , found : %s" % (value,out)) 107 108 def test_02_setAutoSync_Case(self): 109 """ 110 Testing getAutoSync nominal case 111 ------------------------------------------------- 112 Test case description : 113 ~~~~~~~~~~~~~~~~~~~~~~~ 114 - enable autosync 115 - set differents parameters 116 - check the value on the filesystem 117 - disable autosync 118 - set differents parameters 119 - check the value on the filesystem 120 Tested commands : 121 ~~~~~~~~~~~~~~~~~ 122 - [setAutoSync] function 123 Used commands : 124 ~~~~~~~~~~~~~~~ 125 - [getAutoSync] function 126 Expected result : 127 ~~~~~~~~~~~~~~~~~ 128 - When autosync is enabled, the filesystem is automatically 129 synchronized with the blackboard. 130 """ 131 log.D(self.test_02_setAutoSync_Case.__doc__) 132 #Check the initial parameter value 133 init_value_01, err = self.pfw.sendCmd("getParameter", self.param_name_01, "") 134 init_value_02, err = self.pfw.sendCmd("getParameter", self.param_name_02, "") 135 init_value_03, err = self.pfw.sendCmd("getParameter", self.param_name_03, "") 136 init_filesystem_01 = open(self.filesystem_01).read()[:-1] 137 init_filesystem_02 = open(self.filesystem_02).read()[:-1] 138 init_filesystem_03 = open(self.filesystem_03).read()[:-1] 139 #Implement a new value 140 if int(init_value_01)==0 : 141 new_value_01 = "1" 142 else : 143 new_value_01 = "0" 144 new_value_02 = str(int(init_value_02)+1) 145 new_value_03 = str(int(init_value_03)+1) 146 #Enable the autosync 147 value = "on" 148 log.I("Enable autosync") 149 out,err = self.pfw.sendCmd("setAutoSync", value) 150 assert err == None, log.E("When enabling autosync : %s" % (err)) 151 assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out)) 152 #Set the new parameter value 153 self.pfw.sendCmd("setParameter", self.param_name_01, new_value_01) 154 self.pfw.sendCmd("setParameter", self.param_name_02, new_value_02) 155 self.pfw.sendCmd("setParameter", self.param_name_03, new_value_03) 156 #Check the filesystem values 157 #BOOL 158 assert open(self.filesystem_01).read()[:-1] != init_filesystem_01, log.F("FILESYSTEM : parameter %s update error"%self.param_name_01) 159 #INT16 160 assert open(self.filesystem_02).read()[:-1] != init_filesystem_02, log.F("FILESYSTEM : parameter %s update error"%self.param_name_02) 161 #UINT32 162 assert open(self.filesystem_03).read()[:-1] != init_filesystem_03, log.F("FILESYSTEM : parameter %s update error"%self.param_name_03) 163 log.I("test setAutoSync %s : OK"%(value)) 164 #Enable the autosync 165 value = "off" 166 log.I("Disable autosync") 167 out,err = self.pfw.sendCmd("setAutoSync", value) 168 assert err == None, log.E("When enabling autosync : %s" % (err)) 169 assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out)) 170 #Set the new parameter value 171 self.pfw.sendCmd("setParameter", self.param_name_01, init_value_01) 172 self.pfw.sendCmd("setParameter", self.param_name_02, init_value_02) 173 self.pfw.sendCmd("setParameter", self.param_name_03, init_value_03) 174 #Check the filesystem values 175 #BOOL 176 assert open(self.filesystem_01).read()[:-1] != init_filesystem_01, log.F("FILESYSTEM : parameter %s is updated, autosync is still enabled"%self.param_name_01) 177 #INT16 178 assert open(self.filesystem_02).read()[:-1] != init_filesystem_02, log.F("FILESYSTEM : parameter %s is updated, autosync is still enabled"%self.param_name_02) 179 #UINT32 180 assert open(self.filesystem_03).read()[:-1] != init_filesystem_03, log.F("FILESYSTEM : parameter %s is updated, autosync is still enabled"%self.param_name_03) 181 log.I("test setAutoSync %s : OK"%(value)) 182 183 184 @unittest.expectedFailure 185 def test_03_Manual_Sync_Case(self): 186 """ 187 Testing getAutoSync nominal case 188 ------------------------------------------------- 189 Test case description : 190 ~~~~~~~~~~~~~~~~~~~~~~~ 191 - disable autosync 192 - set differents parameters 193 - check the value on the filesystem 194 - sync 195 - check the value on the filesystem 196 Tested commands : 197 ~~~~~~~~~~~~~~~~~ 198 - [sync] function 199 Used commands : 200 ~~~~~~~~~~~~~~~ 201 - [setAutoSync] function 202 Expected result : 203 ~~~~~~~~~~~~~~~~~ 204 - sync should synchronized filessystem with blackboard 205 """ 206 log.D(self.test_03_Manual_Sync_Case.__doc__) 207 #Check the initial parameter value 208 init_value_01, err = self.pfw.sendCmd("getParameter", self.param_name_01, "") 209 init_value_02, err = self.pfw.sendCmd("getParameter", self.param_name_02, "") 210 init_value_03, err = self.pfw.sendCmd("getParameter", self.param_name_03, "") 211 init_filesystem_01 = open(self.filesystem_01).read()[:-1] 212 init_filesystem_02 = open(self.filesystem_02).read()[:-1] 213 init_filesystem_03 = open(self.filesystem_03).read()[:-1] 214 #Implement a new value 215 if int(init_value_01)==0 : 216 new_value_01 = "1" 217 else : 218 new_value_01 = "0" 219 new_value_02 = str(int(init_value_02)+1) 220 new_value_03 = str(int(init_value_03)+1) 221 #Enable the autosync 222 value = "off" 223 log.I("Disable autosync") 224 out,err = self.pfw.sendCmd("setAutoSync", value) 225 assert err == None, log.E("When enabling autosync : %s" % (err)) 226 assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out)) 227 #Set the new parameter value 228 self.pfw.sendCmd("setParameter", self.param_name_01, new_value_01) 229 self.pfw.sendCmd("setParameter", self.param_name_02, new_value_02) 230 self.pfw.sendCmd("setParameter", self.param_name_03, new_value_03) 231 #Check the filesystem values, must not changed 232 #BOOL 233 assert open(self.filesystem_01).read()[:-1] == init_filesystem_01, log.F("FILESYSTEM : parameter %s update error"%self.param_name_01) 234 #INT16 235 assert open(self.filesystem_02).read()[:-1] == init_filesystem_02, log.F("FILESYSTEM : parameter %s update error"%self.param_name_02) 236 #UINT32 237 assert open(self.filesystem_03).read()[:-1] == init_filesystem_03, log.F("FILESYSTEM : parameter %s update error"%self.param_name_03) 238 log.I("test setAutoSync %s : OK"%(value)) 239 log.I("Sync") 240 out,err = self.pfw.sendCmd("sync", "") 241 assert err == None, log.E("When syncing : %s" % (err)) 242 assert out == "Done", log.F("Sync - expected : Done , found : %s" % (out)) 243 #Check the filesystem values 244 #BOOL 245 assert open(self.filesystem_01).read()[:-1] != init_filesystem_01, log.F("FILESYSTEM : parameter %s is updated, autosync is still enabled"%self.param_name_01) 246 #INT16 247 assert open(self.filesystem_02).read()[:-1] != init_filesystem_02, log.F("FILESYSTEM : parameter %s is updated, autosync is still enabled"%self.param_name_02) 248 #UINT32 249 assert open(self.filesystem_03).read()[:-1] != init_filesystem_03, log.F("FILESYSTEM : parameter %s is updated, autosync is still enabled"%self.param_name_03) 250 log.I("test setAutoSync %s : OK"%(value)) 251