summaryrefslogtreecommitdiffstats
path: root/test/functional-tests/PfwTestCase/Types/tUINT8_ARRAY.py
blob: 9f82a360a5fe82f4a695adbb64c48f36df8af90a (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/python2
# -*-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.

"""
Array parameter type testcases : UINT8 Array

List of tested functions :
--------------------------
    - [setParameter]  function
    - [getParameter] function

Initial Settings :
------------------
    UINT8 Array = 8bits unsigned int array :
        - Array size : 5
        - values range : [0, 15]

Test cases :
------------
    - Testing nominal case
    - Testing minimum
    - Testing minimum overflow
    - Testing maximum
    - Testing maximum overflow
    - Testing array index out of bounds
    - Testing value format error
"""
import commands
from Util.PfwUnitTestLib import PfwTestCase
from Util import ACTLogging
log=ACTLogging.Logger()

from ctypes import c_uint16


class TestCases(PfwTestCase):

    def setUp(self):
        self.param_name = "/Test/Test/TEST_DIR/UINT8_ARRAY"
        self.param_short_name = "$PFW_FILESYSTEM/UINT8_ARRAY"
        print '\r'
        self.pfw.sendCmd("setTuningMode", "on")
        print '\r'
        self.array_size = 5
        self.array_min = 0
        self.array_max = 15

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

    def test_Nominal_Case(self):
        """
        Testing UINT8_ARRAY Nominal Case
        --------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Set every UINT8_ARRAY elements to autorized values
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setParameter] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getParameter] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - UINT8_ARRAY array elements correctly recorded
                - Blackboard and filesystem values checked
        """
        log.D(self.test_Nominal_Case.__doc__)

        for index in range (self.array_size):
            indexed_array_value = index + self.array_min
            if indexed_array_value>self.array_max:
                indexed_array_value=self.array_max
            hex_indexed_array_value = hex(c_uint16(indexed_array_value).value)
            #Check parameter value setting
            indexed_array_value_path = "".join([self.param_name, "/", str(index)])
            out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
            assert err == None, log.E("when setting parameter %s[%s]: %s"
                                      % (self.param_name, str(index), err))
            assert out == "Done", log.F("when setting parameter %s[%s]: %s"
                                        % (self.param_name, str(index), out))
            #Check parameter value on blackboard
            out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "")
            assert err == None, log.E("when setting parameter %s[%s] : %s"
                                      % (self.param_name, str(index), err))
            assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s"
                                                          % (self.param_name, str(index), str(indexed_array_value), out))
            #Check parameter value on filesystem
            files_system_check = "awk -v ligne="+str(index)+" 'NR == ligne+1 { print $0}' "+self.param_short_name
            indexed_files_system_array_value = commands.getoutput(files_system_check)
            assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error"
                                                                                      % (self.param_name, str(index)))

    def test_Min_Value(self):
        """
        Testing UINT8_ARRAY minimum value
        ---------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Set every UINT8_ARRAY elements to minimum values : 0
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setParameter] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getParameter] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - UINT8_ARRAY array elements correctly recorded
                - Blackboard and filesystem values checked
        """
        log.D(self.test_Min_Value.__doc__)
        index = 0
        indexed_array_value = self.array_min
        indexed_array_value_path = "".join([self.param_name, "/", str(index)])
        hex_indexed_array_value = hex(c_uint16(indexed_array_value).value)
        #Check parameter value setting
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), err))
        assert out == "Done", log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), out))
        #Check parameter value on blackboard
        out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "")
        assert err == None, log.E("when setting parameter %s[%s] : %s"
                                  % (self.param_name, str(index), err))
        assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s"
                                                      % (self.param_name, str(index), str(indexed_array_value), out))
        #Check parameter value on filesystem
        files_system_check = "awk -v ligne="+str(index)+" 'NR == ligne+1 { print $0}' "+self.param_short_name
        indexed_files_system_array_value = commands.getoutput(files_system_check)
        assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error"
                                                                                  % (self.param_name, str(index)))

    def test_Min_Value_Overflow(self):
        """
        Testing UINT8_ARRAY parameter values out of negative range
        ----------------------------------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Set every UINT8_ARRAY elements to -1
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setParameter] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getParameter] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - UINT8_ARRAY array elements not recorded
                - Error correctly detected
        """
        log.D(self.test_Min_Value_Overflow.__doc__)
        index = 0
        indexed_array_value = self.array_min
        indexed_array_value_path = "".join([self.param_name, "/", str(index)])
        #Check initial parameter value setting
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), err))
        assert out == "Done", log.F("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), out))
        files_system_check = "awk -v ligne="+str(index)+" 'NR == ligne+1 { print $0}' "+self.param_short_name
        param_check = commands.getoutput(files_system_check)
        #Check final parameter value setting
        indexed_array_value = indexed_array_value - 1
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), err))
        assert out != "Done", log.F("Error not detected when setting parameter %s[%s] out of bounds"
                                    % (self.param_name, str(index)))
        #Check parameter value on filesystem
        indexed_files_system_array_value = commands.getoutput(files_system_check)
        assert indexed_files_system_array_value == param_check, log.F("FILESSYSTEM : %s[%s] forbiden update"
                                                                      % (self.param_name, str(index)))

    def test_Max_Value(self):
        """
        Testing UINT8_ARRAY maximum value
        ---------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Set every UINT8_ARRAY elements to maximum values : 15
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setParameter] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getParameter] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - UINT8_ARRAY array elements correctly recorded
                - Blackboard and filesystem values checked
        """
        log.D(self.test_Max_Value.__doc__)
        index = 0
        indexed_array_value = self.array_max
        indexed_array_value_path = "".join([self.param_name, "/", str(index)])
        hex_indexed_array_value = hex(c_uint16(indexed_array_value).value)
        #Check parameter value setting
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), err))
        assert out == "Done", log.F("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), out))
        #Check parameter value on blackboard
        out, err = self.pfw.sendCmd("getParameter", str(indexed_array_value_path), "")
        assert err == None, log.E("when setting parameter %s[%s] : %s"
                                  % (self.param_name, str(index), err))
        assert out == str(indexed_array_value), log.F("BLACKBOARD : Incorrect value for %s[%s], expected: %s, found: %s"
                                                      % (self.param_name, str(index), str(indexed_array_value), out))
        #Check parameter value on filesystem
        files_system_check = "awk -v ligne="+str(index)+" 'NR == ligne+1 { print $0}' "+self.param_short_name
        indexed_files_system_array_value = commands.getoutput(files_system_check)
        assert indexed_files_system_array_value == hex_indexed_array_value, log.F("FILESSYSTEM : %s[%s] update error"
                                                                                  % (self.param_name, str(index)))

    def test_Max_Value_Overflow(self):
        """
        Testing UINT8_ARRAY parameter values out of positive range
        ----------------------------------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Set every UINT8_ARRAY elements to 16
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setParameter] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getParameter] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - UINT8_ARRAY array elements not recorded
                - Error correctly detected
        """
        log.D(self.test_Max_Value_Overflow.__doc__)
        index = 0
        indexed_array_value = self.array_max
        indexed_array_value_path = "".join([self.param_name, "/", str(index)])
        #Check initial parameter value setting
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), err))
        assert out == "Done", log.F("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), out))
        files_system_check = "awk -v ligne="+str(index)+" 'NR == ligne+1 { print $0}' "+self.param_short_name
        param_check = commands.getoutput(files_system_check)
        #Check final parameter value setting
        indexed_array_value = indexed_array_value + 1
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), err))
        assert out != "Done", log.F("Error not detected when setting parameter %s[%s] out of bounds"
                                    % (self.param_name, str(index)))
        #Check parameter value on filesystem
        indexed_files_system_array_value = commands.getoutput(files_system_check)
        assert indexed_files_system_array_value == param_check, log.F("FILESSYSTEM : %s[%s] forbiden update"
                                                                      % (self.param_name, str(index)))

    def test_Array_Index_Overflow(self):
        """
        Testing Array index out of bounds
        ---------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Set an out of bounds array indexed element
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setParameter] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getParameter] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - UINT8_ARRAY array elements not recorded
                - Error correctly detected
        """
        log.D(self.test_Array_Index_Overflow.__doc__)
        index_values = (self.array_size-1, self.array_size+1, -1)
        for index in index_values:
            print index
            indexed_array_value = self.array_max
            indexed_array_value_path = "".join([self.param_name, "/", str(index)])
            #Check parameter value setting
            out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path), str(indexed_array_value))
            if index in [0, self.array_size-1]:
                assert err == None, log.E("when setting parameter %s[%s]: %s"
                                          % (self.param_name, str(index), err))
                assert out == "Done", log.F("when setting parameter %s[%s]: %s"
                                          % (self.param_name, str(index), out))
            else:
                assert err == None, log.E("when setting parameter %s[%s]: %s"
                                          % (self.param_name, str(index), err))
                assert out != "Done", log.F("Error not detected when setting array %s index out of bounds"
                                            % (self.param_name))

    def test_Value_Format_Error(self):
        """
        Testing Array value format error
        --------------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Trying to write an int16 into an 8 bits array element
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [setParameter] function
            Used commands :
            ~~~~~~~~~~~~~~~
                - [getParameter] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - UINT8_ARRAY array elements not recorded
                - Error correctly detected
        """
        log.D(self.test_Value_Format_Error.__doc__)
        index = 0
        var_uint16 = c_uint16(5).value
        indexed_array_value_1 = 0
        indexed_array_value_2 = 10
        indexed_array_value_path_1 = "".join([self.param_name, "/", str(index)])
        indexed_array_value_path_2 = "".join([self.param_name, "/", str(index+1)])
        #Check initial parameter value setting
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path_1), str(indexed_array_value_1))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), err))
        assert out == "Done", log.F("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index), out))
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path_2), str(indexed_array_value_2))
        assert err == None, log.E("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index+1), err))
        assert out == "Done", log.F("when setting parameter %s[%s]: %s"
                                  % (self.param_name, str(index+1), out))
        files_system_check_1 = "awk -v ligne="+str(index)+" 'NR == ligne+1 { print $0}' "+self.param_short_name
        param_check_1 = commands.getoutput(files_system_check_1)
        files_system_check_2 = "awk -v ligne="+str(index+1)+" 'NR == ligne+1 { print $0}' "+self.param_short_name
        param_check_2 = commands.getoutput(files_system_check_2)
        #Check final parameter value setting (!= or == ?)
        out, err = self.pfw.sendCmd("setParameter", str(indexed_array_value_path_1), str(var_uint16))
        assert err == None, log.E("Error when setting parameter %s[%s]: %s"
                           % (self.param_name, str(index), err))
        ### TBC : check expected result ###
        assert out == "Done", log.F("Error not detected when setting parameter %s[%s] out of bounds"
                             % (self.param_name, str(index)))
        #Check parameter value on filesystem
        indexed_files_system_array_value_2 = commands.getoutput(files_system_check_2)
        assert indexed_files_system_array_value_2 == param_check_2, log.F("FILESSYSTEM : %s[%s] forbiden update"
                                                                          % (self.param_name, str(index)))