summaryrefslogtreecommitdiffstats
path: root/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration_Backup.py
blob: 51d3d2bafe07a6d67ec08b52fc69c2ec784d3040 (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
# -*-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.

"""
Save and restore configuration testcases

List of tested functions :
--------------------------
    - [saveConfiguration]  function
    - [restoreConfiguration] function

Test cases :
------------
    - Testing nominal case
    - Testing saveConfiguration errors
    - Testing restoreConfiguration errors
"""

from Util.PfwUnitTestLib import PfwTestCase
from Util import ACTLogging
log=ACTLogging.Logger()

# Test of Domains - save/restore configuration
class TestCases(PfwTestCase):
    def setUp(self):
        self.pfw.sendCmd("setTuningMode", "on")
        self.domain_name = "Domain_0"
        self.conf_1 = "Conf_0"
        self.conf_2 = "Conf_1"
        self.param_name = "/Test/Test/TEST_DIR/INT8"

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

    def test_Nominal_Case(self):
        """
        Testing nominal case
        --------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - save a configuration
                - restore a configuration
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [saveConfiguration] function
                - [restoreConfiguration] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
            - all operations succeed
        """
        log.D(self.test_Nominal_Case.__doc__)

        # Saving original parameter value
        log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1)
        assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err)
        assert out == "Done", out
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_1 = int(out)
        log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1))

        # Modifying parameter value
        log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1))
        assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err)
        log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1))

        # Saving new parameter value
        log.I("saving configuration %s from domain %s" % (self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name, self.conf_1)
        assert err == None, "Error when saving configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err)
        assert out == "Done", out
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_1 = int(out)
        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))

        # Modifying and restoring parameter value
        log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1))
        assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err)
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_2 = int(out)
        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))
        log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1)
        assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err)
        assert out == "Done", out
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_2 = int(out)
        assert Param_saved_2 == Param_saved_1, "Error when restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)
        log.I("saving and restoring configuration works fine")

    def test_Save_Config_Error(self):
        """
        Testing saveConfiguration error
        -------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - save a configuration with a missing argument
                - save a configuration with a wrong domain name
                - save a configuration with a wrong configuration name
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [saveConfiguration] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
            - errors correctly detected
        """
        log.D(self.test_Save_Config_Error.__doc__)
        # Saving original parameter value and setting a new value to parameter for testing purpose
        log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1)
        assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err)
        assert out == "Done", out
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_1 = int(out)
        log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1))
        log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1))
        assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err)
        log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1))

        # Configuration saving errors
        log.I("saving configuration error test cases :")
        log.I("saving configuration with a missing argument")
        out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name)
        assert err == None, "ERROR : Error when saving configuration with a missing argument"
        assert out != "Done", "ERROR : Error not detected when saving configuration with a missing argument"
        log.I("saving configuration with a wrong domain name")
        out, err = self.pfw.sendCmd("saveConfiguration", "Wrong_Domain_Name", self.conf_1)
        assert err == None, "ERROR : Error when saving configuration with a wrong domain name"
        assert out != "Done", "ERROR : Error not detected when saving configuration with a wrong domain name"
        log.I("saving configuration with a wrong configuration name")
        out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name, "Wrong_Configuration_Name")
        assert err == None, "ERROR : Error when saving configuration with a wrong configuration name"
        assert out != "Done", "ERROR : Error not detected when saving configuration with a wrong configuration name"
        log.I("saving configuration error test cases : errors correctly detected")

        # Checking that no error has affected original configuration save
        log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1)
        assert err == None, "error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err)
        assert out == "Done", out
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_2 = int(out)
        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)
        log.I("Test passed : saving errors correctly detected, no impact on previously saved configuration")

    def test_Restore_Config_Error(self):
        """
        Testing restoreConfiguration error
        ----------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - restore a configuration with a missing argument
                - restore a configuration with a wrong domain name
                - restore a configuration with a wrong configuration name
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [restoreConfiguration] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
            - errors correctly detected
            - configuration's parameters not affected by errors
        """

        log.D(self.test_Restore_Config_Error.__doc__)
        # Saving original parameter value and setting a new value to parameter for testing purpose
        log.I("restore configuration %s from domain %s" % (self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1)
        assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err)
        assert out == "Done", out
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_1 = int(out)
        log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1))
        log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name))
        out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1))
        assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err)
        log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1))
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_2 = int(out)

        # Configuration restore errors
        log.I("restoring configuration error test cases :")
        log.I("restoring configuration with a missing argument")
        out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name)
        assert err == None, "ERROR : Error when restoring configuration with a missing argument"
        assert out != "Done", "ERROR : Error not detected when restoring configuration with a missing argument"
        log.I("restoring configuration with a wrong domain name")
        out, err = self.pfw.sendCmd("restoreConfiguration", "Wrong_Domain_Name", self.conf_1)
        assert err == None, "ERROR : Error when restoring configuration with a wrong domain name"
        assert out != "Done", "ERROR : Error not detected when restoring configuration with a wrong domain name"
        log.I("restoring configuration with a wrong configuration name")
        out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, "Wrong_Configuration_Name")
        assert err == None, "ERROR : Error when restoring configuration with a wrong configuration name"
        assert out != "Done", "ERROR : Error not detected when restoring configuration with a wrong configuration name"
        log.I("restoring configuration error test cases : errors correctly detected")

        # Checking that no error has affected configuration's parameter value
        out, err = self.pfw.sendCmd("getParameter", self.param_name)
        assert err == None, "error when getting parameter %s : %s" % (self.param_name, err)
        Param_saved_1 = int(out)
        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)
        log.I("Test passed : restoring errors correctly detected, no impact on previously modified configuration's parameter")