summaryrefslogtreecommitdiffstats
path: root/test/functional-tests/PfwTestCase/Functions/tFunction_Sync.py
blob: 1b8013ca95cc19edf3aaeec51d19528460a87dd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# -*-coding:utf-8 -*

# Copyright (c) 2011-2015, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
synchronization functions testcases

List of tested functions :
--------------------------
    - [getAutoSync]  function
    - [setAutoSync]  function
    - [sync]  function

Test cases :
------------
    - Testing getAutoSync nominal case
    - Testing setAutoSync nominal case
    - Testing sync nominal case
    - Testing errors
"""
import commands, os
import unittest
from Util.PfwUnitTestLib import PfwTestCase
from Util import ACTLogging
log=ACTLogging.Logger()

class TestCases(PfwTestCase):

    def setUp(self):

        pfw_filesystem=os.getenv("PFW_FILESYSTEM")

        self.pfw.sendCmd("setTuningMode", "on")
        self.param_name_01 = "/Test/Test/TEST_DIR/BOOL"
        self.filesystem_01 = pfw_filesystem+"/BOOL"
        self.param_name_02 = "/Test/Test/TEST_DIR/INT16"
        self.filesystem_02 = pfw_filesystem+"/INT16"
        self.param_name_03 = "/Test/Test/TEST_DIR/UINT32"
        self.filesystem_03 = pfw_filesystem+"/UINT32"

    def tearDown(self):
        self.pfw.sendCmd("setTuningMode", "off")

    def test_01_getAutoSync_Case(self):
        """
        Testing getAutoSync nominal case
        ----------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - enable autosync
                - get autosync state
                - disable autosync
                - get autosync state
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setAutoSync] function
                - [getAutoSync] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - getAutoSync return expected state
        """
        log.D(self.test_01_getAutoSync_Case.__doc__)
        value = "on"
        log.I("Enable autosync")
        out,err = self.pfw.sendCmd("setAutoSync", value)
        assert err == None, log.E("When enabling autosync : %s" % (err))
        assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out))
        log.I("Check autosync state")
        out, err = self.pfw.sendCmd("getAutoSync","")
        assert err == None, log.E("When getting autosync state : %s" % (err))
        assert out == value, log.F("setAutoSync - expected : %s , found : %s" % (value,out))
        value = "off"
        log.I("Disable autosync")
        out,err = self.pfw.sendCmd("setAutoSync", value)
        assert err == None, log.E("When enabling autosync : %s" % (err))
        assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out))
        log.I("Check autosync state")
        out, err = self.pfw.sendCmd("getAutoSync","")
        assert err == None, log.E("When getting autosync state : %s" % (err))
        assert out == value, log.F("setAutoSync - expected : %s , found : %s" % (value,out))

    def test_02_setAutoSync_Case(self):
        """
        Testing getAutoSync nominal case
        -------------------------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - enable autosync
                - set differents parameters
                - check the value on the filesystem
                - disable autosync
                - set differents parameters
                - check the value on the filesystem
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setAutoSync] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getAutoSync] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - When autosync is enabled, the filesystem is automatically
                synchronized with the blackboard.
        """
        log.D(self.test_02_setAutoSync_Case.__doc__)
        #Check the initial parameter value
        init_value_01, err = self.pfw.sendCmd("getParameter", self.param_name_01, "")
        init_value_02, err = self.pfw.sendCmd("getParameter", self.param_name_02, "")
        init_value_03, err = self.pfw.sendCmd("getParameter", self.param_name_03, "")
        init_filesystem_01 = commands.getoutput("cat %s"%(self.filesystem_01))
        init_filesystem_02 = commands.getoutput("cat %s"%(self.filesystem_02))
        init_filesystem_03 = commands.getoutput("cat %s"%(self.filesystem_03))
        #Implement a new value
        if int(init_value_01)==0 :
            new_value_01 = "1"
        else :
            new_value_01 = "0"
        new_value_02 = str(int(init_value_02)+1)
        new_value_03 = str(int(init_value_03)+1)
        #Enable the autosync
        value = "on"
        log.I("Enable autosync")
        out,err = self.pfw.sendCmd("setAutoSync", value)
        assert err == None, log.E("When enabling autosync : %s" % (err))
        assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out))
        #Set the new parameter value
        self.pfw.sendCmd("setParameter", self.param_name_01, new_value_01)
        self.pfw.sendCmd("setParameter", self.param_name_02, new_value_02)
        self.pfw.sendCmd("setParameter", self.param_name_03, new_value_03)
        #Check the filesystem values
        #BOOL
        assert commands.getoutput("cat %s"%(self.filesystem_01)) != init_filesystem_01, log.F("FILESYSTEM : parameter %s update error"%self.param_name_01)
        #INT16
        assert commands.getoutput("cat %s"%(self.filesystem_02)) != init_filesystem_02, log.F("FILESYSTEM : parameter %s update error"%self.param_name_02)
        #UINT32
        assert commands.getoutput("cat %s"%(self.filesystem_03)) != init_filesystem_03, log.F("FILESYSTEM : parameter %s update error"%self.param_name_03)
        log.I("test setAutoSync %s : OK"%(value))
        #Enable the autosync
        value = "off"
        log.I("Disable autosync")
        out,err = self.pfw.sendCmd("setAutoSync", value)
        assert err == None, log.E("When enabling autosync : %s" % (err))
        assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out))
        #Set the new parameter value
        self.pfw.sendCmd("setParameter", self.param_name_01, init_value_01)
        self.pfw.sendCmd("setParameter", self.param_name_02, init_value_02)
        self.pfw.sendCmd("setParameter", self.param_name_03, init_value_03)
        #Check the filesystem values
        #BOOL
        assert commands.getoutput("cat %s"%(self.filesystem_01)) != init_filesystem_01, log.F("FILESYSTEM : parameter %s  is updated, autosync is still enabled"%self.param_name_01)
        #INT16
        assert commands.getoutput("cat %s"%(self.filesystem_02)) != init_filesystem_02, log.F("FILESYSTEM : parameter %s  is updated, autosync is still enabled"%self.param_name_02)
        #UINT32
        assert commands.getoutput("cat %s"%(self.filesystem_03)) != init_filesystem_03, log.F("FILESYSTEM : parameter %s  is updated, autosync is still enabled"%self.param_name_03)
        log.I("test setAutoSync %s : OK"%(value))


    @unittest.expectedFailure
    def test_03_Manual_Sync_Case(self):
        """
        Testing getAutoSync nominal case
        -------------------------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - disable autosync
                - set differents parameters
                - check the value on the filesystem
                - sync
                - check the value on the filesystem
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [sync] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [setAutoSync] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - sync should synchronized filessystem with blackboard
        """
        log.D(self.test_03_Manual_Sync_Case.__doc__)
        #Check the initial parameter value
        init_value_01, err = self.pfw.sendCmd("getParameter", self.param_name_01, "")
        init_value_02, err = self.pfw.sendCmd("getParameter", self.param_name_02, "")
        init_value_03, err = self.pfw.sendCmd("getParameter", self.param_name_03, "")
        init_filesystem_01 = commands.getoutput("cat %s"%(self.filesystem_01))
        init_filesystem_02 = commands.getoutput("cat %s"%(self.filesystem_02))
        init_filesystem_03 = commands.getoutput("cat %s"%(self.filesystem_03))
        #Implement a new value
        if int(init_value_01)==0 :
            new_value_01 = "1"
        else :
            new_value_01 = "0"
        new_value_02 = str(int(init_value_02)+1)
        new_value_03 = str(int(init_value_03)+1)
        #Enable the autosync
        value = "off"
        log.I("Disable autosync")
        out,err = self.pfw.sendCmd("setAutoSync", value)
        assert err == None, log.E("When enabling autosync : %s" % (err))
        assert out == "Done", log.F("setAutoSync - expected : Done , found : %s" % (out))
        #Set the new parameter value
        self.pfw.sendCmd("setParameter", self.param_name_01, new_value_01)
        self.pfw.sendCmd("setParameter", self.param_name_02, new_value_02)
        self.pfw.sendCmd("setParameter", self.param_name_03, new_value_03)
        #Check the filesystem values, must not changed
        #BOOL
        assert commands.getoutput("cat %s"%(self.filesystem_01)) == init_filesystem_01, log.F("FILESYSTEM : parameter %s update error"%self.param_name_01)
        #INT16
        assert commands.getoutput("cat %s"%(self.filesystem_02)) == init_filesystem_02, log.F("FILESYSTEM : parameter %s update error"%self.param_name_02)
        #UINT32
        assert commands.getoutput("cat %s"%(self.filesystem_03)) == init_filesystem_03, log.F("FILESYSTEM : parameter %s update error"%self.param_name_03)
        log.I("test setAutoSync %s : OK"%(value))
        log.I("Sync")
        out,err = self.pfw.sendCmd("sync", "")
        assert err == None, log.E("When syncing : %s" % (err))
        assert out == "Done", log.F("Sync - expected : Done , found : %s" % (out))
        #Check the filesystem values
        #BOOL
        assert commands.getoutput("cat %s"%(self.filesystem_01)) != init_filesystem_01, log.F("FILESYSTEM : parameter %s  is updated, autosync is still enabled"%self.param_name_01)
        #INT16
        assert commands.getoutput("cat %s"%(self.filesystem_02)) != init_filesystem_02, log.F("FILESYSTEM : parameter %s  is updated, autosync is still enabled"%self.param_name_02)
        #UINT32
        assert commands.getoutput("cat %s"%(self.filesystem_03)) != init_filesystem_03, log.F("FILESYSTEM : parameter %s  is updated, autosync is still enabled"%self.param_name_03)
        log.I("test setAutoSync %s : OK"%(value))