blob: 149159c8c544967b1a89d662b986f02126d23e4a [file] [log] [blame]
Azim Khanb31aa442018-07-03 11:57:54 +01001#!/usr/bin/env python3
Mohammad Azim Khan78befd92018-03-06 11:49:41 +00002# Unit test for generate_test_code.py
Azim Khanf0e42fb2017-08-02 14:47:13 +01003#
Azim Khan4084ec72018-07-05 14:20:08 +01004# Copyright (C) 2018, Arm Limited, All Rights Reserved
Azim Khanf0e42fb2017-08-02 14:47:13 +01005# SPDX-License-Identifier: Apache-2.0
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
Azim Khanb31aa442018-07-03 11:57:54 +010019# This file is part of Mbed TLS (https://tls.mbed.org)
Azim Khan4b543232017-06-30 09:35:21 +010020
21"""
Mohammad Azim Khan78befd92018-03-06 11:49:41 +000022Unit tests for generate_test_code.py
Azim Khan4b543232017-06-30 09:35:21 +010023"""
24
25
Azim Khanb31aa442018-07-03 11:57:54 +010026from StringIO import StringIO
27from unittest import TestCase, main as unittest_main
28from mock import patch
29from generate_test_code import gen_dependencies, gen_dependencies_one_line
30from generate_test_code import gen_function_wrapper, gen_dispatch
31from generate_test_code import parse_until_pattern, GeneratorInputError
32from generate_test_code import parse_suite_dependencies
33from generate_test_code import parse_function_dependencies
Azim Khanfcdf6852018-07-05 17:31:46 +010034from generate_test_code import parse_function_arguments, parse_function_code
Azim Khanb31aa442018-07-03 11:57:54 +010035from generate_test_code import parse_functions, END_HEADER_REGEX
36from generate_test_code import END_SUITE_HELPERS_REGEX, escaped_split
37from generate_test_code import parse_test_data, gen_dep_check
38from generate_test_code import gen_expression_check, write_dependencies
39from generate_test_code import write_parameters, gen_suite_dep_checks
40from generate_test_code import gen_from_test_data
41
42
Azim Khan4b543232017-06-30 09:35:21 +010043class GenDep(TestCase):
44 """
45 Test suite for function gen_dep()
46 """
47
Azim Khanb31aa442018-07-03 11:57:54 +010048 def test_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +010049 """
Azim Khanb31aa442018-07-03 11:57:54 +010050 Test that gen_dep() correctly creates dependencies for given
51 dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010052 :return:
Azim Khan4b543232017-06-30 09:35:21 +010053 """
Azim Khanb31aa442018-07-03 11:57:54 +010054 dependencies = ['DEP1', 'DEP2']
55 dep_start, dep_end = gen_dependencies(dependencies)
56 preprocessor1, preprocessor2 = dep_start.splitlines()
Azim Khan4b543232017-06-30 09:35:21 +010057 endif1, endif2 = dep_end.splitlines()
Azim Khanb31aa442018-07-03 11:57:54 +010058 self.assertEqual(preprocessor1, '#if defined(DEP1)',
59 'Preprocessor generated incorrectly')
60 self.assertEqual(preprocessor2, '#if defined(DEP2)',
61 'Preprocessor generated incorrectly')
62 self.assertEqual(endif1, '#endif /* DEP2 */',
63 'Preprocessor generated incorrectly')
64 self.assertEqual(endif2, '#endif /* DEP1 */',
65 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +010066
Azim Khanb31aa442018-07-03 11:57:54 +010067 def test_disabled_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +010068 """
Azim Khanb31aa442018-07-03 11:57:54 +010069 Test that gen_dep() correctly creates dependencies for given
70 dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010071 :return:
Azim Khan4b543232017-06-30 09:35:21 +010072 """
Azim Khanb31aa442018-07-03 11:57:54 +010073 dependencies = ['!DEP1', '!DEP2']
74 dep_start, dep_end = gen_dependencies(dependencies)
75 preprocessor1, preprocessor2 = dep_start.splitlines()
Azim Khan4b543232017-06-30 09:35:21 +010076 endif1, endif2 = dep_end.splitlines()
Azim Khanb31aa442018-07-03 11:57:54 +010077 self.assertEqual(preprocessor1, '#if !defined(DEP1)',
78 'Preprocessor generated incorrectly')
79 self.assertEqual(preprocessor2, '#if !defined(DEP2)',
80 'Preprocessor generated incorrectly')
81 self.assertEqual(endif1, '#endif /* !DEP2 */',
82 'Preprocessor generated incorrectly')
83 self.assertEqual(endif2, '#endif /* !DEP1 */',
84 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +010085
Azim Khanb31aa442018-07-03 11:57:54 +010086 def test_mixed_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +010087 """
Azim Khanb31aa442018-07-03 11:57:54 +010088 Test that gen_dep() correctly creates dependencies for given
89 dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010090 :return:
Azim Khan4b543232017-06-30 09:35:21 +010091 """
Azim Khanb31aa442018-07-03 11:57:54 +010092 dependencies = ['!DEP1', 'DEP2']
93 dep_start, dep_end = gen_dependencies(dependencies)
94 preprocessor1, preprocessor2 = dep_start.splitlines()
Azim Khan4b543232017-06-30 09:35:21 +010095 endif1, endif2 = dep_end.splitlines()
Azim Khanb31aa442018-07-03 11:57:54 +010096 self.assertEqual(preprocessor1, '#if !defined(DEP1)',
97 'Preprocessor generated incorrectly')
98 self.assertEqual(preprocessor2, '#if defined(DEP2)',
99 'Preprocessor generated incorrectly')
100 self.assertEqual(endif1, '#endif /* DEP2 */',
101 'Preprocessor generated incorrectly')
102 self.assertEqual(endif2, '#endif /* !DEP1 */',
103 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100104
Azim Khanb31aa442018-07-03 11:57:54 +0100105 def test_empty_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +0100106 """
Azim Khanb31aa442018-07-03 11:57:54 +0100107 Test that gen_dep() correctly creates dependencies for given
108 dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100109 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100110 """
Azim Khanb31aa442018-07-03 11:57:54 +0100111 dependencies = []
112 dep_start, dep_end = gen_dependencies(dependencies)
113 self.assertEqual(dep_start, '', 'Preprocessor generated incorrectly')
114 self.assertEqual(dep_end, '', 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100115
Azim Khanb31aa442018-07-03 11:57:54 +0100116 def test_large_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +0100117 """
Azim Khanb31aa442018-07-03 11:57:54 +0100118 Test that gen_dep() correctly creates dependencies for given
119 dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100120 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100121 """
Azim Khanb31aa442018-07-03 11:57:54 +0100122 dependencies = []
Azim Khan4b543232017-06-30 09:35:21 +0100123 count = 10
124 for i in range(count):
Azim Khanb31aa442018-07-03 11:57:54 +0100125 dependencies.append('DEP%d' % i)
126 dep_start, dep_end = gen_dependencies(dependencies)
127 self.assertEqual(len(dep_start.splitlines()), count,
128 'Preprocessor generated incorrectly')
129 self.assertEqual(len(dep_end.splitlines()), count,
130 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100131
132
133class GenDepOneLine(TestCase):
134 """
Azim Khanb31aa442018-07-03 11:57:54 +0100135 Test Suite for testing gen_dependencies_one_line()
Azim Khan4b543232017-06-30 09:35:21 +0100136 """
137
Azim Khanb31aa442018-07-03 11:57:54 +0100138 def test_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +0100139 """
Azim Khanb31aa442018-07-03 11:57:54 +0100140 Test that gen_dep() correctly creates dependencies for given
141 dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100142 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100143 """
Azim Khanb31aa442018-07-03 11:57:54 +0100144 dependencies = ['DEP1', 'DEP2']
145 dep_str = gen_dependencies_one_line(dependencies)
146 self.assertEqual(dep_str, '#if defined(DEP1) && defined(DEP2)',
147 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100148
Azim Khanb31aa442018-07-03 11:57:54 +0100149 def test_disabled_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +0100150 """
Azim Khanb31aa442018-07-03 11:57:54 +0100151 Test that gen_dep() correctly creates dependencies for given
152 dependency list.
Azim Khan4b543232017-06-30 09:35:21 +0100153 :return:
154 """
Azim Khanb31aa442018-07-03 11:57:54 +0100155 dependencies = ['!DEP1', '!DEP2']
156 dep_str = gen_dependencies_one_line(dependencies)
157 self.assertEqual(dep_str, '#if !defined(DEP1) && !defined(DEP2)',
158 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100159
Azim Khanb31aa442018-07-03 11:57:54 +0100160 def test_mixed_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +0100161 """
Azim Khanb31aa442018-07-03 11:57:54 +0100162 Test that gen_dep() correctly creates dependencies for given
163 dependency list.
Azim Khan4b543232017-06-30 09:35:21 +0100164 :return:
165 """
Azim Khanb31aa442018-07-03 11:57:54 +0100166 dependencies = ['!DEP1', 'DEP2']
167 dep_str = gen_dependencies_one_line(dependencies)
168 self.assertEqual(dep_str, '#if !defined(DEP1) && defined(DEP2)',
169 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100170
Azim Khanb31aa442018-07-03 11:57:54 +0100171 def test_empty_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +0100172 """
Azim Khanb31aa442018-07-03 11:57:54 +0100173 Test that gen_dep() correctly creates dependencies for given
174 dependency list.
Azim Khan4b543232017-06-30 09:35:21 +0100175 :return:
176 """
Azim Khanb31aa442018-07-03 11:57:54 +0100177 dependencies = []
178 dep_str = gen_dependencies_one_line(dependencies)
179 self.assertEqual(dep_str, '', 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100180
Azim Khanb31aa442018-07-03 11:57:54 +0100181 def test_large_dependencies_list(self):
Azim Khan4b543232017-06-30 09:35:21 +0100182 """
Azim Khanb31aa442018-07-03 11:57:54 +0100183 Test that gen_dep() correctly creates dependencies for given
184 dependency list.
Azim Khan4b543232017-06-30 09:35:21 +0100185 :return:
186 """
Azim Khanb31aa442018-07-03 11:57:54 +0100187 dependencies = []
Azim Khan4b543232017-06-30 09:35:21 +0100188 count = 10
189 for i in range(count):
Azim Khanb31aa442018-07-03 11:57:54 +0100190 dependencies.append('DEP%d' % i)
191 dep_str = gen_dependencies_one_line(dependencies)
192 expected = '#if ' + ' && '.join(['defined(%s)' %
193 x for x in dependencies])
194 self.assertEqual(dep_str, expected,
195 'Preprocessor generated incorrectly')
Azim Khan4b543232017-06-30 09:35:21 +0100196
197
198class GenFunctionWrapper(TestCase):
199 """
200 Test Suite for testing gen_function_wrapper()
201 """
202
203 def test_params_unpack(self):
204 """
205 Test that params are properly unpacked in the function call.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100206
207 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100208 """
209 code = gen_function_wrapper('test_a', '', ('a', 'b', 'c', 'd'))
210 expected = '''
211void test_a_wrapper( void ** params )
212{
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100213
Azim Khan4b543232017-06-30 09:35:21 +0100214 test_a( a, b, c, d );
215}
216'''
217 self.assertEqual(code, expected)
218
219 def test_local(self):
220 """
221 Test that params are properly unpacked in the function call.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100222
223 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100224 """
Azim Khanb31aa442018-07-03 11:57:54 +0100225 code = gen_function_wrapper('test_a',
226 'int x = 1;', ('x', 'b', 'c', 'd'))
Azim Khan4b543232017-06-30 09:35:21 +0100227 expected = '''
228void test_a_wrapper( void ** params )
229{
Azim Khan4b543232017-06-30 09:35:21 +0100230int x = 1;
231 test_a( x, b, c, d );
232}
233'''
234 self.assertEqual(code, expected)
235
236 def test_empty_params(self):
237 """
238 Test that params are properly unpacked in the function call.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100239
240 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100241 """
242 code = gen_function_wrapper('test_a', '', ())
243 expected = '''
244void test_a_wrapper( void ** params )
245{
246 (void)params;
247
248 test_a( );
249}
250'''
251 self.assertEqual(code, expected)
252
253
254class GenDispatch(TestCase):
255 """
256 Test suite for testing gen_dispatch()
257 """
258
259 def test_dispatch(self):
260 """
261 Test that dispatch table entry is generated correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100262 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100263 """
264 code = gen_dispatch('test_a', ['DEP1', 'DEP2'])
265 expected = '''
266#if defined(DEP1) && defined(DEP2)
267 test_a_wrapper,
268#else
269 NULL,
270#endif
271'''
272 self.assertEqual(code, expected)
273
Azim Khanb31aa442018-07-03 11:57:54 +0100274 def test_empty_dependencies(self):
Azim Khan4b543232017-06-30 09:35:21 +0100275 """
276 Test empty dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100277 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100278 """
279 code = gen_dispatch('test_a', [])
280 expected = '''
281 test_a_wrapper,
282'''
283 self.assertEqual(code, expected)
284
285
286class StringIOWrapper(StringIO, object):
287 """
288 file like class to mock file object in tests.
289 """
Azim Khan4084ec72018-07-05 14:20:08 +0100290 def __init__(self, file_name, data, line_no=0):
Azim Khan4b543232017-06-30 09:35:21 +0100291 """
292 Init file handle.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100293
294 :param file_name:
Azim Khan4b543232017-06-30 09:35:21 +0100295 :param data:
296 :param line_no:
297 """
298 super(StringIOWrapper, self).__init__(data)
299 self.line_no = line_no
300 self.name = file_name
301
302 def next(self):
303 """
Azim Khanb31aa442018-07-03 11:57:54 +0100304 Iterator method. This method overrides base class's
305 next method and extends the next method to count the line
306 numbers as each line is read.
Azim Khan4b543232017-06-30 09:35:21 +0100307
Azim Khanb31aa442018-07-03 11:57:54 +0100308 :return: Line read from file.
309 """
Azim Khan4084ec72018-07-05 14:20:08 +0100310 line = super(StringIOWrapper, self).next()
311 return line
Azim Khanb31aa442018-07-03 11:57:54 +0100312
313 __next__ = next
314
315 def readline(self, length=0):
Azim Khan4b543232017-06-30 09:35:21 +0100316 """
317 Wrap the base class readline.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100318
Azim Khanb31aa442018-07-03 11:57:54 +0100319 :param length:
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100320 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100321 """
322 line = super(StringIOWrapper, self).readline()
Azim Khan4084ec72018-07-05 14:20:08 +0100323 if line is not None:
Azim Khan4b543232017-06-30 09:35:21 +0100324 self.line_no += 1
325 return line
326
327
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000328class ParseUntilPattern(TestCase):
Azim Khan4b543232017-06-30 09:35:21 +0100329 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000330 Test Suite for testing parse_until_pattern().
Azim Khan4b543232017-06-30 09:35:21 +0100331 """
332
333 def test_suite_headers(self):
334 """
335 Test that suite headers are parsed correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100336
337 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100338 """
339 data = '''#include "mbedtls/ecp.h"
340
341#define ECP_PF_UNKNOWN -1
342/* END_HEADER */
343'''
344 expected = '''#line 1 "test_suite_ut.function"
345#include "mbedtls/ecp.h"
346
347#define ECP_PF_UNKNOWN -1
348'''
Azim Khanb31aa442018-07-03 11:57:54 +0100349 stream = StringIOWrapper('test_suite_ut.function', data, line_no=0)
350 headers = parse_until_pattern(stream, END_HEADER_REGEX)
Azim Khan4b543232017-06-30 09:35:21 +0100351 self.assertEqual(headers, expected)
352
353 def test_line_no(self):
354 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100355 Test that #line is set to correct line no. in source .function file.
356
357 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100358 """
359 data = '''#include "mbedtls/ecp.h"
360
361#define ECP_PF_UNKNOWN -1
362/* END_HEADER */
363'''
364 offset_line_no = 5
365 expected = '''#line %d "test_suite_ut.function"
366#include "mbedtls/ecp.h"
367
368#define ECP_PF_UNKNOWN -1
369''' % (offset_line_no + 1)
Azim Khanb31aa442018-07-03 11:57:54 +0100370 stream = StringIOWrapper('test_suite_ut.function', data,
371 offset_line_no)
372 headers = parse_until_pattern(stream, END_HEADER_REGEX)
Azim Khan4b543232017-06-30 09:35:21 +0100373 self.assertEqual(headers, expected)
374
375 def test_no_end_header_comment(self):
376 """
Azim Khanb31aa442018-07-03 11:57:54 +0100377 Test that InvalidFileFormat is raised when end header comment is
378 missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100379 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100380 """
381 data = '''#include "mbedtls/ecp.h"
382
383#define ECP_PF_UNKNOWN -1
384
385'''
Azim Khanb31aa442018-07-03 11:57:54 +0100386 stream = StringIOWrapper('test_suite_ut.function', data)
387 self.assertRaises(GeneratorInputError, parse_until_pattern, stream,
388 END_HEADER_REGEX)
Azim Khan4b543232017-06-30 09:35:21 +0100389
390
Azim Khanb31aa442018-07-03 11:57:54 +0100391class ParseSuiteDependencies(TestCase):
Azim Khan4b543232017-06-30 09:35:21 +0100392 """
Azim Khanb31aa442018-07-03 11:57:54 +0100393 Test Suite for testing parse_suite_dependencies().
Azim Khan4b543232017-06-30 09:35:21 +0100394 """
395
Azim Khanb31aa442018-07-03 11:57:54 +0100396 def test_suite_dependencies(self):
Azim Khan4b543232017-06-30 09:35:21 +0100397 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100398
399 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100400 """
401 data = '''
402 * depends_on:MBEDTLS_ECP_C
403 * END_DEPENDENCIES
404 */
405'''
406 expected = ['MBEDTLS_ECP_C']
Azim Khanb31aa442018-07-03 11:57:54 +0100407 stream = StringIOWrapper('test_suite_ut.function', data)
408 dependencies = parse_suite_dependencies(stream)
409 self.assertEqual(dependencies, expected)
Azim Khan4b543232017-06-30 09:35:21 +0100410
411 def test_no_end_dep_comment(self):
412 """
413 Test that InvalidFileFormat is raised when end dep comment is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100414 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100415 """
416 data = '''
417* depends_on:MBEDTLS_ECP_C
418'''
Azim Khanb31aa442018-07-03 11:57:54 +0100419 stream = StringIOWrapper('test_suite_ut.function', data)
420 self.assertRaises(GeneratorInputError, parse_suite_dependencies,
421 stream)
Azim Khan4b543232017-06-30 09:35:21 +0100422
Azim Khanb31aa442018-07-03 11:57:54 +0100423 def test_dependencies_split(self):
Azim Khan4b543232017-06-30 09:35:21 +0100424 """
425 Test that InvalidFileFormat is raised when end dep comment is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100426 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100427 """
428 data = '''
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100429 * depends_on:MBEDTLS_ECP_C:A:B: C : D :F : G: !H
Azim Khan4b543232017-06-30 09:35:21 +0100430 * END_DEPENDENCIES
431 */
432'''
433 expected = ['MBEDTLS_ECP_C', 'A', 'B', 'C', 'D', 'F', 'G', '!H']
Azim Khanb31aa442018-07-03 11:57:54 +0100434 stream = StringIOWrapper('test_suite_ut.function', data)
435 dependencies = parse_suite_dependencies(stream)
436 self.assertEqual(dependencies, expected)
Azim Khan4b543232017-06-30 09:35:21 +0100437
438
Azim Khanb31aa442018-07-03 11:57:54 +0100439class ParseFuncDependencies(TestCase):
Azim Khan4b543232017-06-30 09:35:21 +0100440 """
Azim Khanb31aa442018-07-03 11:57:54 +0100441 Test Suite for testing parse_function_dependencies()
Azim Khan4b543232017-06-30 09:35:21 +0100442 """
443
Azim Khanb31aa442018-07-03 11:57:54 +0100444 def test_function_dependencies(self):
Azim Khan4b543232017-06-30 09:35:21 +0100445 """
Azim Khanb31aa442018-07-03 11:57:54 +0100446 Test that parse_function_dependencies() correctly parses function
447 dependencies.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100448 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100449 """
Azim Khanb31aa442018-07-03 11:57:54 +0100450 line = '/* BEGIN_CASE ' \
451 'depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */'
Azim Khan4b543232017-06-30 09:35:21 +0100452 expected = ['MBEDTLS_ENTROPY_NV_SEED', 'MBEDTLS_FS_IO']
Azim Khanb31aa442018-07-03 11:57:54 +0100453 dependencies = parse_function_dependencies(line)
454 self.assertEqual(dependencies, expected)
Azim Khan4b543232017-06-30 09:35:21 +0100455
Azim Khanb31aa442018-07-03 11:57:54 +0100456 def test_no_dependencies(self):
Azim Khan4b543232017-06-30 09:35:21 +0100457 """
Azim Khanb31aa442018-07-03 11:57:54 +0100458 Test that parse_function_dependencies() correctly parses function
459 dependencies.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100460 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100461 """
462 line = '/* BEGIN_CASE */'
Azim Khanb31aa442018-07-03 11:57:54 +0100463 dependencies = parse_function_dependencies(line)
464 self.assertEqual(dependencies, [])
Azim Khan4b543232017-06-30 09:35:21 +0100465
Azim Khanb31aa442018-07-03 11:57:54 +0100466 def test_tolerance(self):
Azim Khan4b543232017-06-30 09:35:21 +0100467 """
Azim Khanb31aa442018-07-03 11:57:54 +0100468 Test that parse_function_dependencies() correctly parses function
469 dependencies.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100470 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100471 """
472 line = '/* BEGIN_CASE depends_on:MBEDTLS_FS_IO: A : !B:C : F*/'
Azim Khanb31aa442018-07-03 11:57:54 +0100473 dependencies = parse_function_dependencies(line)
474 self.assertEqual(dependencies, ['MBEDTLS_FS_IO', 'A', '!B', 'C', 'F'])
Azim Khan4b543232017-06-30 09:35:21 +0100475
476
477class ParseFuncSignature(TestCase):
478 """
Azim Khanfcdf6852018-07-05 17:31:46 +0100479 Test Suite for parse_function_arguments().
Azim Khan4b543232017-06-30 09:35:21 +0100480 """
481
482 def test_int_and_char_params(self):
483 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100484 Test int and char parameters parsing
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100485 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100486 """
487 line = 'void entropy_threshold( char * a, int b, int result )'
Azim Khanfcdf6852018-07-05 17:31:46 +0100488 args, local, arg_dispatch = parse_function_arguments(line)
Azim Khan4b543232017-06-30 09:35:21 +0100489 self.assertEqual(args, ['char*', 'int', 'int'])
490 self.assertEqual(local, '')
Azim Khanb31aa442018-07-03 11:57:54 +0100491 self.assertEqual(arg_dispatch, ['(char *) params[0]',
492 '*( (int *) params[1] )',
493 '*( (int *) params[2] )'])
Azim Khan4b543232017-06-30 09:35:21 +0100494
495 def test_hex_params(self):
496 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100497 Test hex parameters parsing
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100498 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100499 """
Azim Khan5fcca462018-06-29 11:05:32 +0100500 line = 'void entropy_threshold( char * a, data_t * h, int result )'
Azim Khanfcdf6852018-07-05 17:31:46 +0100501 args, local, arg_dispatch = parse_function_arguments(line)
Azim Khan4b543232017-06-30 09:35:21 +0100502 self.assertEqual(args, ['char*', 'hex', 'int'])
Azim Khanb31aa442018-07-03 11:57:54 +0100503 self.assertEqual(local,
Azim Khan4084ec72018-07-05 14:20:08 +0100504 ' data_t data1 = {(uint8_t *) params[1], '
Azim Khanb31aa442018-07-03 11:57:54 +0100505 '*( (uint32_t *) params[2] )};\n')
506 self.assertEqual(arg_dispatch, ['(char *) params[0]',
Azim Khan4084ec72018-07-05 14:20:08 +0100507 '&data1',
Azim Khanb31aa442018-07-03 11:57:54 +0100508 '*( (int *) params[3] )'])
Azim Khan4b543232017-06-30 09:35:21 +0100509
Azim Khan4b543232017-06-30 09:35:21 +0100510 def test_unsupported_arg(self):
511 """
Azim Khan5fcca462018-06-29 11:05:32 +0100512 Test unsupported arguments (not among int, char * and data_t)
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100513 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100514 """
Azim Khanfcdf6852018-07-05 17:31:46 +0100515 line = 'void entropy_threshold( char * a, data_t * h, char result )'
516 self.assertRaises(ValueError, parse_function_arguments, line)
Azim Khan4b543232017-06-30 09:35:21 +0100517
518 def test_no_params(self):
519 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100520 Test no parameters.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100521 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100522 """
523 line = 'void entropy_threshold()'
Azim Khanfcdf6852018-07-05 17:31:46 +0100524 args, local, arg_dispatch = parse_function_arguments(line)
Azim Khan4b543232017-06-30 09:35:21 +0100525 self.assertEqual(args, [])
526 self.assertEqual(local, '')
527 self.assertEqual(arg_dispatch, [])
528
529
530class ParseFunctionCode(TestCase):
531 """
532 Test suite for testing parse_function_code()
533 """
534
535 def test_no_function(self):
536 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100537 Test no test function found.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100538 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100539 """
540 data = '''
541No
542test
543function
544'''
Azim Khanb31aa442018-07-03 11:57:54 +0100545 stream = StringIOWrapper('test_suite_ut.function', data)
Azim Khanfcdf6852018-07-05 17:31:46 +0100546 err_msg = 'file: test_suite_ut.function - Test functions not found!'
547 self.assertRaisesRegexp(GeneratorInputError, err_msg,
548 parse_function_code, stream, [], [])
Azim Khan4b543232017-06-30 09:35:21 +0100549
550 def test_no_end_case_comment(self):
551 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100552 Test missing end case.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100553 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100554 """
555 data = '''
556void test_func()
557{
558}
559'''
Azim Khanb31aa442018-07-03 11:57:54 +0100560 stream = StringIOWrapper('test_suite_ut.function', data)
Azim Khanfcdf6852018-07-05 17:31:46 +0100561 err_msg = r'file: test_suite_ut.function - '\
562 'end case pattern .*? not found!'
563 self.assertRaisesRegexp(GeneratorInputError, err_msg,
564 parse_function_code, stream, [], [])
Azim Khan4b543232017-06-30 09:35:21 +0100565
Azim Khanfcdf6852018-07-05 17:31:46 +0100566 @patch("generate_test_code.parse_function_arguments")
Azim Khanb31aa442018-07-03 11:57:54 +0100567 def test_function_called(self,
Azim Khanfcdf6852018-07-05 17:31:46 +0100568 parse_function_arguments_mock):
Azim Khan4b543232017-06-30 09:35:21 +0100569 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100570 Test parse_function_code()
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100571 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100572 """
Azim Khanfcdf6852018-07-05 17:31:46 +0100573 parse_function_arguments_mock.return_value = ([], '', [])
Azim Khan4b543232017-06-30 09:35:21 +0100574 data = '''
575void test_func()
576{
577}
578'''
Azim Khanb31aa442018-07-03 11:57:54 +0100579 stream = StringIOWrapper('test_suite_ut.function', data)
580 self.assertRaises(GeneratorInputError, parse_function_code,
581 stream, [], [])
Azim Khanfcdf6852018-07-05 17:31:46 +0100582 self.assertTrue(parse_function_arguments_mock.called)
583 parse_function_arguments_mock.assert_called_with('void test_func()\n')
Azim Khan4b543232017-06-30 09:35:21 +0100584
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000585 @patch("generate_test_code.gen_dispatch")
Azim Khanb31aa442018-07-03 11:57:54 +0100586 @patch("generate_test_code.gen_dependencies")
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000587 @patch("generate_test_code.gen_function_wrapper")
Azim Khanfcdf6852018-07-05 17:31:46 +0100588 @patch("generate_test_code.parse_function_arguments")
589 def test_return(self, parse_function_arguments_mock,
Azim Khanb31aa442018-07-03 11:57:54 +0100590 gen_function_wrapper_mock,
591 gen_dependencies_mock,
592 gen_dispatch_mock):
Azim Khan4b543232017-06-30 09:35:21 +0100593 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100594 Test generated code.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100595 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100596 """
Azim Khanfcdf6852018-07-05 17:31:46 +0100597 parse_function_arguments_mock.return_value = ([], '', [])
Azim Khan4b543232017-06-30 09:35:21 +0100598 gen_function_wrapper_mock.return_value = ''
Azim Khanb31aa442018-07-03 11:57:54 +0100599 gen_dependencies_mock.side_effect = gen_dependencies
Azim Khan4b543232017-06-30 09:35:21 +0100600 gen_dispatch_mock.side_effect = gen_dispatch
601 data = '''
602void func()
603{
604 ba ba black sheep
605 have you any wool
606}
607/* END_CASE */
608'''
Azim Khanb31aa442018-07-03 11:57:54 +0100609 stream = StringIOWrapper('test_suite_ut.function', data)
610 name, arg, code, dispatch_code = parse_function_code(stream, [], [])
Azim Khan4b543232017-06-30 09:35:21 +0100611
Azim Khanfcdf6852018-07-05 17:31:46 +0100612 self.assertTrue(parse_function_arguments_mock.called)
613 parse_function_arguments_mock.assert_called_with('void func()\n')
Azim Khan4b543232017-06-30 09:35:21 +0100614 gen_function_wrapper_mock.assert_called_with('test_func', '', [])
615 self.assertEqual(name, 'test_func')
616 self.assertEqual(arg, [])
Azim Khan4084ec72018-07-05 14:20:08 +0100617 expected = '''#line 1 "test_suite_ut.function"
618
Azim Khan4b543232017-06-30 09:35:21 +0100619void test_func()
620{
621 ba ba black sheep
622 have you any wool
623exit:
Azim Khan4084ec72018-07-05 14:20:08 +0100624 ;
Azim Khan4b543232017-06-30 09:35:21 +0100625}
626'''
627 self.assertEqual(code, expected)
628 self.assertEqual(dispatch_code, "\n test_func_wrapper,\n")
629
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000630 @patch("generate_test_code.gen_dispatch")
Azim Khanb31aa442018-07-03 11:57:54 +0100631 @patch("generate_test_code.gen_dependencies")
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000632 @patch("generate_test_code.gen_function_wrapper")
Azim Khanfcdf6852018-07-05 17:31:46 +0100633 @patch("generate_test_code.parse_function_arguments")
634 def test_with_exit_label(self, parse_function_arguments_mock,
Azim Khanb31aa442018-07-03 11:57:54 +0100635 gen_function_wrapper_mock,
636 gen_dependencies_mock,
637 gen_dispatch_mock):
Azim Khan4b543232017-06-30 09:35:21 +0100638 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100639 Test when exit label is present.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100640 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100641 """
Azim Khanfcdf6852018-07-05 17:31:46 +0100642 parse_function_arguments_mock.return_value = ([], '', [])
Azim Khan4b543232017-06-30 09:35:21 +0100643 gen_function_wrapper_mock.return_value = ''
Azim Khanb31aa442018-07-03 11:57:54 +0100644 gen_dependencies_mock.side_effect = gen_dependencies
Azim Khan4b543232017-06-30 09:35:21 +0100645 gen_dispatch_mock.side_effect = gen_dispatch
646 data = '''
647void func()
648{
649 ba ba black sheep
650 have you any wool
651exit:
652 yes sir yes sir
653 3 bags full
654}
655/* END_CASE */
656'''
Azim Khanb31aa442018-07-03 11:57:54 +0100657 stream = StringIOWrapper('test_suite_ut.function', data)
658 _, _, code, _ = parse_function_code(stream, [], [])
Azim Khan4b543232017-06-30 09:35:21 +0100659
Azim Khan4084ec72018-07-05 14:20:08 +0100660 expected = '''#line 1 "test_suite_ut.function"
661
Azim Khan4b543232017-06-30 09:35:21 +0100662void test_func()
663{
664 ba ba black sheep
665 have you any wool
666exit:
667 yes sir yes sir
668 3 bags full
669}
670'''
671 self.assertEqual(code, expected)
672
Azim Khanfcdf6852018-07-05 17:31:46 +0100673 def test_non_void_function(self):
674 """
675 Test invalid signature (non void).
676 :return:
677 """
678 data = 'int entropy_threshold( char * a, data_t * h, int result )'
679 err_msg = 'file: test_suite_ut.function - Test functions not found!'
680 stream = StringIOWrapper('test_suite_ut.function', data)
681 self.assertRaisesRegexp(GeneratorInputError, err_msg,
682 parse_function_code, stream, [], [])
683
684 @patch("generate_test_code.gen_dispatch")
685 @patch("generate_test_code.gen_dependencies")
686 @patch("generate_test_code.gen_function_wrapper")
687 @patch("generate_test_code.parse_function_arguments")
688 def test_functio_name_on_newline(self, parse_function_arguments_mock,
689 gen_function_wrapper_mock,
690 gen_dependencies_mock,
691 gen_dispatch_mock):
692 """
693 Test when exit label is present.
694 :return:
695 """
696 parse_function_arguments_mock.return_value = ([], '', [])
697 gen_function_wrapper_mock.return_value = ''
698 gen_dependencies_mock.side_effect = gen_dependencies
699 gen_dispatch_mock.side_effect = gen_dispatch
700 data = '''
701void
702
703
704func()
705{
706 ba ba black sheep
707 have you any wool
708exit:
709 yes sir yes sir
710 3 bags full
711}
712/* END_CASE */
713'''
714 stream = StringIOWrapper('test_suite_ut.function', data)
715 _, _, code, _ = parse_function_code(stream, [], [])
716
717 expected = '''#line 1 "test_suite_ut.function"
718
719void
720
721
722test_func()
723{
724 ba ba black sheep
725 have you any wool
726exit:
727 yes sir yes sir
728 3 bags full
729}
730'''
731 self.assertEqual(code, expected)
732
Azim Khan4b543232017-06-30 09:35:21 +0100733
734class ParseFunction(TestCase):
735 """
736 Test Suite for testing parse_functions()
737 """
738
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000739 @patch("generate_test_code.parse_until_pattern")
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000740 def test_begin_header(self, parse_until_pattern_mock):
Azim Khan4b543232017-06-30 09:35:21 +0100741 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000742 Test that begin header is checked and parse_until_pattern() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100743 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100744 """
Azim Khanb31aa442018-07-03 11:57:54 +0100745 def stop(*_unused):
746 """Stop when parse_until_pattern is called."""
Azim Khan4b543232017-06-30 09:35:21 +0100747 raise Exception
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000748 parse_until_pattern_mock.side_effect = stop
Azim Khan4b543232017-06-30 09:35:21 +0100749 data = '''/* BEGIN_HEADER */
750#include "mbedtls/ecp.h"
751
752#define ECP_PF_UNKNOWN -1
753/* END_HEADER */
754'''
Azim Khanb31aa442018-07-03 11:57:54 +0100755 stream = StringIOWrapper('test_suite_ut.function', data)
756 self.assertRaises(Exception, parse_functions, stream)
757 parse_until_pattern_mock.assert_called_with(stream, END_HEADER_REGEX)
Azim Khan4084ec72018-07-05 14:20:08 +0100758 self.assertEqual(stream.line_no, 1)
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000759
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000760 @patch("generate_test_code.parse_until_pattern")
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000761 def test_begin_helper(self, parse_until_pattern_mock):
762 """
763 Test that begin helper is checked and parse_until_pattern() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100764 :return:
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000765 """
Azim Khanb31aa442018-07-03 11:57:54 +0100766 def stop(*_unused):
767 """Stop when parse_until_pattern is called."""
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000768 raise Exception
769 parse_until_pattern_mock.side_effect = stop
770 data = '''/* BEGIN_SUITE_HELPERS */
Azim Khanb31aa442018-07-03 11:57:54 +0100771void print_hello_world()
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000772{
Azim Khanb31aa442018-07-03 11:57:54 +0100773 printf("Hello World!\n");
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000774}
775/* END_SUITE_HELPERS */
776'''
Azim Khanb31aa442018-07-03 11:57:54 +0100777 stream = StringIOWrapper('test_suite_ut.function', data)
778 self.assertRaises(Exception, parse_functions, stream)
779 parse_until_pattern_mock.assert_called_with(stream,
780 END_SUITE_HELPERS_REGEX)
Azim Khan4084ec72018-07-05 14:20:08 +0100781 self.assertEqual(stream.line_no, 1)
Azim Khan4b543232017-06-30 09:35:21 +0100782
Azim Khanb31aa442018-07-03 11:57:54 +0100783 @patch("generate_test_code.parse_suite_dependencies")
784 def test_begin_dep(self, parse_suite_dependencies_mock):
Azim Khan4b543232017-06-30 09:35:21 +0100785 """
Azim Khanb31aa442018-07-03 11:57:54 +0100786 Test that begin dep is checked and parse_suite_dependencies() is
787 called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100788 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100789 """
Azim Khanb31aa442018-07-03 11:57:54 +0100790 def stop(*_unused):
791 """Stop when parse_until_pattern is called."""
Azim Khan4b543232017-06-30 09:35:21 +0100792 raise Exception
Azim Khanb31aa442018-07-03 11:57:54 +0100793 parse_suite_dependencies_mock.side_effect = stop
Azim Khan4b543232017-06-30 09:35:21 +0100794 data = '''/* BEGIN_DEPENDENCIES
795 * depends_on:MBEDTLS_ECP_C
796 * END_DEPENDENCIES
797 */
798'''
Azim Khanb31aa442018-07-03 11:57:54 +0100799 stream = StringIOWrapper('test_suite_ut.function', data)
800 self.assertRaises(Exception, parse_functions, stream)
801 parse_suite_dependencies_mock.assert_called_with(stream)
Azim Khan4084ec72018-07-05 14:20:08 +0100802 self.assertEqual(stream.line_no, 1)
Azim Khan4b543232017-06-30 09:35:21 +0100803
Azim Khanb31aa442018-07-03 11:57:54 +0100804 @patch("generate_test_code.parse_function_dependencies")
805 def test_begin_function_dep(self, func_mock):
Azim Khan4b543232017-06-30 09:35:21 +0100806 """
Azim Khanb31aa442018-07-03 11:57:54 +0100807 Test that begin dep is checked and parse_function_dependencies() is
808 called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100809 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100810 """
Azim Khanb31aa442018-07-03 11:57:54 +0100811 def stop(*_unused):
812 """Stop when parse_until_pattern is called."""
Azim Khan4b543232017-06-30 09:35:21 +0100813 raise Exception
Azim Khanb31aa442018-07-03 11:57:54 +0100814 func_mock.side_effect = stop
Azim Khan4b543232017-06-30 09:35:21 +0100815
Azim Khanb31aa442018-07-03 11:57:54 +0100816 dependencies_str = '/* BEGIN_CASE ' \
817 'depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */\n'
Azim Khan4b543232017-06-30 09:35:21 +0100818 data = '''%svoid test_func()
819{
820}
Azim Khanb31aa442018-07-03 11:57:54 +0100821''' % dependencies_str
822 stream = StringIOWrapper('test_suite_ut.function', data)
823 self.assertRaises(Exception, parse_functions, stream)
824 func_mock.assert_called_with(dependencies_str)
Azim Khan4084ec72018-07-05 14:20:08 +0100825 self.assertEqual(stream.line_no, 1)
Azim Khan4b543232017-06-30 09:35:21 +0100826
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000827 @patch("generate_test_code.parse_function_code")
Azim Khanb31aa442018-07-03 11:57:54 +0100828 @patch("generate_test_code.parse_function_dependencies")
829 def test_return(self, func_mock1, func_mock2):
Azim Khan4b543232017-06-30 09:35:21 +0100830 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000831 Test that begin case is checked and parse_function_code() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100832 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100833 """
Azim Khanb31aa442018-07-03 11:57:54 +0100834 func_mock1.return_value = []
835 in_func_code = '''void test_func()
Azim Khan4b543232017-06-30 09:35:21 +0100836{
837}
838'''
839 func_dispatch = '''
840 test_func_wrapper,
841'''
Azim Khanb31aa442018-07-03 11:57:54 +0100842 func_mock2.return_value = 'test_func', [],\
843 in_func_code, func_dispatch
844 dependencies_str = '/* BEGIN_CASE ' \
845 'depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */\n'
Azim Khan4b543232017-06-30 09:35:21 +0100846 data = '''%svoid test_func()
847{
848}
Azim Khanb31aa442018-07-03 11:57:54 +0100849''' % dependencies_str
850 stream = StringIOWrapper('test_suite_ut.function', data)
851 suite_dependencies, dispatch_code, func_code, func_info = \
852 parse_functions(stream)
853 func_mock1.assert_called_with(dependencies_str)
854 func_mock2.assert_called_with(stream, [], [])
855 self.assertEqual(stream.line_no, 5)
856 self.assertEqual(suite_dependencies, [])
Azim Khan4b543232017-06-30 09:35:21 +0100857 expected_dispatch_code = '''/* Function Id: 0 */
858
859 test_func_wrapper,
860'''
861 self.assertEqual(dispatch_code, expected_dispatch_code)
862 self.assertEqual(func_code, in_func_code)
863 self.assertEqual(func_info, {'test_func': (0, [])})
864
865 def test_parsing(self):
866 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000867 Test case parsing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100868 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100869 """
870 data = '''/* BEGIN_HEADER */
871#include "mbedtls/ecp.h"
872
873#define ECP_PF_UNKNOWN -1
874/* END_HEADER */
875
876/* BEGIN_DEPENDENCIES
877 * depends_on:MBEDTLS_ECP_C
878 * END_DEPENDENCIES
879 */
880
881/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
882void func1()
883{
884}
885/* END_CASE */
886
887/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
888void func2()
889{
890}
891/* END_CASE */
892'''
Azim Khanb31aa442018-07-03 11:57:54 +0100893 stream = StringIOWrapper('test_suite_ut.function', data)
894 suite_dependencies, dispatch_code, func_code, func_info = \
895 parse_functions(stream)
896 self.assertEqual(stream.line_no, 23)
897 self.assertEqual(suite_dependencies, ['MBEDTLS_ECP_C'])
Azim Khan4b543232017-06-30 09:35:21 +0100898
899 expected_dispatch_code = '''/* Function Id: 0 */
900
901#if defined(MBEDTLS_ECP_C) && defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_FS_IO)
902 test_func1_wrapper,
903#else
904 NULL,
905#endif
906/* Function Id: 1 */
907
908#if defined(MBEDTLS_ECP_C) && defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_FS_IO)
909 test_func2_wrapper,
910#else
911 NULL,
912#endif
913'''
914 self.assertEqual(dispatch_code, expected_dispatch_code)
915 expected_func_code = '''#if defined(MBEDTLS_ECP_C)
Azim Khan4084ec72018-07-05 14:20:08 +0100916#line 2 "test_suite_ut.function"
Azim Khan4b543232017-06-30 09:35:21 +0100917#include "mbedtls/ecp.h"
918
919#define ECP_PF_UNKNOWN -1
920#if defined(MBEDTLS_ENTROPY_NV_SEED)
921#if defined(MBEDTLS_FS_IO)
Azim Khan4084ec72018-07-05 14:20:08 +0100922#line 13 "test_suite_ut.function"
Azim Khan4b543232017-06-30 09:35:21 +0100923void test_func1()
924{
925exit:
Azim Khan4084ec72018-07-05 14:20:08 +0100926 ;
Azim Khan4b543232017-06-30 09:35:21 +0100927}
928
929void test_func1_wrapper( void ** params )
930{
931 (void)params;
932
933 test_func1( );
934}
935#endif /* MBEDTLS_FS_IO */
936#endif /* MBEDTLS_ENTROPY_NV_SEED */
937#if defined(MBEDTLS_ENTROPY_NV_SEED)
938#if defined(MBEDTLS_FS_IO)
Azim Khan4084ec72018-07-05 14:20:08 +0100939#line 19 "test_suite_ut.function"
Azim Khan4b543232017-06-30 09:35:21 +0100940void test_func2()
941{
942exit:
Azim Khan4084ec72018-07-05 14:20:08 +0100943 ;
Azim Khan4b543232017-06-30 09:35:21 +0100944}
945
946void test_func2_wrapper( void ** params )
947{
948 (void)params;
949
950 test_func2( );
951}
952#endif /* MBEDTLS_FS_IO */
953#endif /* MBEDTLS_ENTROPY_NV_SEED */
954#endif /* MBEDTLS_ECP_C */
955'''
956 self.assertEqual(func_code, expected_func_code)
Azim Khanb31aa442018-07-03 11:57:54 +0100957 self.assertEqual(func_info, {'test_func1': (0, []),
958 'test_func2': (1, [])})
Azim Khan4b543232017-06-30 09:35:21 +0100959
960 def test_same_function_name(self):
961 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000962 Test name conflict.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100963 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100964 """
965 data = '''/* BEGIN_HEADER */
966#include "mbedtls/ecp.h"
967
968#define ECP_PF_UNKNOWN -1
969/* END_HEADER */
970
971/* BEGIN_DEPENDENCIES
972 * depends_on:MBEDTLS_ECP_C
973 * END_DEPENDENCIES
974 */
975
976/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
977void func()
978{
979}
980/* END_CASE */
981
982/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
983void func()
984{
985}
986/* END_CASE */
987'''
Azim Khanb31aa442018-07-03 11:57:54 +0100988 stream = StringIOWrapper('test_suite_ut.function', data)
989 self.assertRaises(GeneratorInputError, parse_functions, stream)
Azim Khan4b543232017-06-30 09:35:21 +0100990
991
Azim Khanb31aa442018-07-03 11:57:54 +0100992class EscapedSplit(TestCase):
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100993 """
Azim Khan599cd242017-07-06 17:34:27 +0100994 Test suite for testing escaped_split().
Azim Khanb31aa442018-07-03 11:57:54 +0100995 Note: Since escaped_split() output is used to write back to the
996 intermediate data file. Any escape characters in the input are
997 retained in the output.
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100998 """
999
1000 def test_invalid_input(self):
1001 """
1002 Test when input split character is not a character.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001003 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001004 """
1005 self.assertRaises(ValueError, escaped_split, '', 'string')
1006
1007 def test_empty_string(self):
1008 """
Azim Khanb31aa442018-07-03 11:57:54 +01001009 Test empty string input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001010 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001011 """
1012 splits = escaped_split('', ':')
1013 self.assertEqual(splits, [])
1014
1015 def test_no_escape(self):
1016 """
Azim Khanb31aa442018-07-03 11:57:54 +01001017 Test with no escape character. The behaviour should be same as
1018 str.split()
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001019 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001020 """
Azim Khanb31aa442018-07-03 11:57:54 +01001021 test_str = 'yahoo:google'
1022 splits = escaped_split(test_str, ':')
1023 self.assertEqual(splits, test_str.split(':'))
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001024
1025 def test_escaped_input(self):
1026 """
Azim Khanb31aa442018-07-03 11:57:54 +01001027 Test input that has escaped delimiter.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001028 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001029 """
Azim Khanb31aa442018-07-03 11:57:54 +01001030 test_str = r'yahoo\:google:facebook'
1031 splits = escaped_split(test_str, ':')
1032 self.assertEqual(splits, [r'yahoo\:google', 'facebook'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001033
1034 def test_escaped_escape(self):
1035 """
Azim Khanb31aa442018-07-03 11:57:54 +01001036 Test input that has escaped delimiter.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001037 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001038 """
Azim Khan4084ec72018-07-05 14:20:08 +01001039 test_str = r'yahoo\\:google:facebook'
Azim Khanb31aa442018-07-03 11:57:54 +01001040 splits = escaped_split(test_str, ':')
Azim Khan4084ec72018-07-05 14:20:08 +01001041 self.assertEqual(splits, [r'yahoo\\', 'google', 'facebook'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001042
1043 def test_all_at_once(self):
1044 """
Azim Khanb31aa442018-07-03 11:57:54 +01001045 Test input that has escaped delimiter.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001046 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001047 """
Azim Khan4084ec72018-07-05 14:20:08 +01001048 test_str = r'yahoo\\:google:facebook\:instagram\\:bbc\\:wikipedia'
Azim Khanb31aa442018-07-03 11:57:54 +01001049 splits = escaped_split(test_str, ':')
Azim Khan4084ec72018-07-05 14:20:08 +01001050 self.assertEqual(splits, [r'yahoo\\', r'google',
1051 r'facebook\:instagram\\',
1052 r'bbc\\', r'wikipedia'])
Azim Khan599cd242017-07-06 17:34:27 +01001053
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001054
1055class ParseTestData(TestCase):
1056 """
1057 Test suite for parse test data.
1058 """
1059
1060 def test_parser(self):
1061 """
1062 Test that tests are parsed correctly from data file.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001063 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001064 """
1065 data = """
1066Diffie-Hellman full exchange #1
1067dhm_do_dhm:10:"23":10:"5"
1068
1069Diffie-Hellman full exchange #2
1070dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
1071
1072Diffie-Hellman full exchange #3
1073dhm_do_dhm:10:"9345098382739712938719287391879381271":10:"9345098792137312973297123912791271"
1074
1075Diffie-Hellman selftest
1076dhm_selftest:
1077"""
Azim Khanb31aa442018-07-03 11:57:54 +01001078 stream = StringIOWrapper('test_suite_ut.function', data)
1079 tests = [(name, test_function, dependencies, args)
1080 for name, test_function, dependencies, args in
1081 parse_test_data(stream)]
1082 test1, test2, test3, test4 = tests
1083 self.assertEqual(test1[0], 'Diffie-Hellman full exchange #1')
1084 self.assertEqual(test1[1], 'dhm_do_dhm')
1085 self.assertEqual(test1[2], [])
1086 self.assertEqual(test1[3], ['10', '"23"', '10', '"5"'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001087
Azim Khanb31aa442018-07-03 11:57:54 +01001088 self.assertEqual(test2[0], 'Diffie-Hellman full exchange #2')
1089 self.assertEqual(test2[1], 'dhm_do_dhm')
1090 self.assertEqual(test2[2], [])
1091 self.assertEqual(test2[3], ['10', '"93450983094850938450983409623"',
1092 '10', '"9345098304850938450983409622"'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001093
Azim Khanb31aa442018-07-03 11:57:54 +01001094 self.assertEqual(test3[0], 'Diffie-Hellman full exchange #3')
1095 self.assertEqual(test3[1], 'dhm_do_dhm')
1096 self.assertEqual(test3[2], [])
1097 self.assertEqual(test3[3], ['10',
1098 '"9345098382739712938719287391879381271"',
1099 '10',
1100 '"9345098792137312973297123912791271"'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001101
Azim Khanb31aa442018-07-03 11:57:54 +01001102 self.assertEqual(test4[0], 'Diffie-Hellman selftest')
1103 self.assertEqual(test4[1], 'dhm_selftest')
1104 self.assertEqual(test4[2], [])
1105 self.assertEqual(test4[3], [])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001106
1107 def test_with_dependencies(self):
1108 """
1109 Test that tests with dependencies are parsed.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001110 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001111 """
1112 data = """
1113Diffie-Hellman full exchange #1
1114depends_on:YAHOO
1115dhm_do_dhm:10:"23":10:"5"
1116
1117Diffie-Hellman full exchange #2
1118dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
1119
1120"""
Azim Khanb31aa442018-07-03 11:57:54 +01001121 stream = StringIOWrapper('test_suite_ut.function', data)
1122 tests = [(name, function_name, dependencies, args)
1123 for name, function_name, dependencies, args in
1124 parse_test_data(stream)]
1125 test1, test2 = tests
1126 self.assertEqual(test1[0], 'Diffie-Hellman full exchange #1')
1127 self.assertEqual(test1[1], 'dhm_do_dhm')
1128 self.assertEqual(test1[2], ['YAHOO'])
1129 self.assertEqual(test1[3], ['10', '"23"', '10', '"5"'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001130
Azim Khanb31aa442018-07-03 11:57:54 +01001131 self.assertEqual(test2[0], 'Diffie-Hellman full exchange #2')
1132 self.assertEqual(test2[1], 'dhm_do_dhm')
1133 self.assertEqual(test2[2], [])
1134 self.assertEqual(test2[3], ['10', '"93450983094850938450983409623"',
1135 '10', '"9345098304850938450983409622"'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001136
1137 def test_no_args(self):
1138 """
Azim Khanb31aa442018-07-03 11:57:54 +01001139 Test GeneratorInputError is raised when test function name and
1140 args line is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001141 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001142 """
1143 data = """
1144Diffie-Hellman full exchange #1
1145depends_on:YAHOO
1146
1147
1148Diffie-Hellman full exchange #2
1149dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
1150
1151"""
Azim Khanb31aa442018-07-03 11:57:54 +01001152 stream = StringIOWrapper('test_suite_ut.function', data)
1153 err = None
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001154 try:
Azim Khanb31aa442018-07-03 11:57:54 +01001155 for _, _, _, _ in parse_test_data(stream):
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001156 pass
Azim Khanb31aa442018-07-03 11:57:54 +01001157 except GeneratorInputError as err:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001158 pass
Azim Khanb31aa442018-07-03 11:57:54 +01001159 self.assertEqual(type(err), GeneratorInputError)
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001160
1161 def test_incomplete_data(self):
1162 """
Azim Khanb31aa442018-07-03 11:57:54 +01001163 Test GeneratorInputError is raised when test function name
1164 and args line is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001165 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001166 """
1167 data = """
1168Diffie-Hellman full exchange #1
1169depends_on:YAHOO
1170"""
Azim Khanb31aa442018-07-03 11:57:54 +01001171 stream = StringIOWrapper('test_suite_ut.function', data)
1172 err = None
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001173 try:
Azim Khanb31aa442018-07-03 11:57:54 +01001174 for _, _, _, _ in parse_test_data(stream):
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001175 pass
Azim Khanb31aa442018-07-03 11:57:54 +01001176 except GeneratorInputError as err:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001177 pass
Azim Khanb31aa442018-07-03 11:57:54 +01001178 self.assertEqual(type(err), GeneratorInputError)
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001179
1180
1181class GenDepCheck(TestCase):
1182 """
Azim Khanb31aa442018-07-03 11:57:54 +01001183 Test suite for gen_dep_check(). It is assumed this function is
1184 called with valid inputs.
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001185 """
1186
1187 def test_gen_dep_check(self):
1188 """
1189 Test that dependency check code generated correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001190 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001191 """
1192 expected = """
Azim Khand61b8372017-07-10 11:54:01 +01001193 case 5:
1194 {
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001195#if defined(YAHOO)
Azim Khand61b8372017-07-10 11:54:01 +01001196 ret = DEPENDENCY_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001197#else
Azim Khand61b8372017-07-10 11:54:01 +01001198 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001199#endif
Azim Khand61b8372017-07-10 11:54:01 +01001200 }
1201 break;"""
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001202 out = gen_dep_check(5, 'YAHOO')
1203 self.assertEqual(out, expected)
1204
Azim Khanb31aa442018-07-03 11:57:54 +01001205 def test_not_defined_dependency(self):
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001206 """
1207 Test dependency with !.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001208 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001209 """
1210 expected = """
Azim Khand61b8372017-07-10 11:54:01 +01001211 case 5:
1212 {
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001213#if !defined(YAHOO)
Azim Khand61b8372017-07-10 11:54:01 +01001214 ret = DEPENDENCY_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001215#else
Azim Khand61b8372017-07-10 11:54:01 +01001216 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001217#endif
Azim Khand61b8372017-07-10 11:54:01 +01001218 }
1219 break;"""
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001220 out = gen_dep_check(5, '!YAHOO')
1221 self.assertEqual(out, expected)
1222
1223 def test_empty_dependency(self):
1224 """
1225 Test invalid dependency input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001226 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001227 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001228 self.assertRaises(GeneratorInputError, gen_dep_check, 5, '!')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001229
1230 def test_negative_dep_id(self):
1231 """
1232 Test invalid dependency input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001233 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001234 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001235 self.assertRaises(GeneratorInputError, gen_dep_check, -1, 'YAHOO')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001236
1237
1238class GenExpCheck(TestCase):
1239 """
Azim Khanb31aa442018-07-03 11:57:54 +01001240 Test suite for gen_expression_check(). It is assumed this function
1241 is called with valid inputs.
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001242 """
1243
1244 def test_gen_exp_check(self):
1245 """
1246 Test that expression check code generated correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001247 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001248 """
1249 expected = """
Azim Khand61b8372017-07-10 11:54:01 +01001250 case 5:
1251 {
1252 *out_value = YAHOO;
1253 }
1254 break;"""
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001255 out = gen_expression_check(5, 'YAHOO')
1256 self.assertEqual(out, expected)
1257
1258 def test_invalid_expression(self):
1259 """
1260 Test invalid expression input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001261 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001262 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001263 self.assertRaises(GeneratorInputError, gen_expression_check, 5, '')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001264
1265 def test_negative_exp_id(self):
1266 """
1267 Test invalid expression id.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001268 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001269 """
Azim Khanb31aa442018-07-03 11:57:54 +01001270 self.assertRaises(GeneratorInputError, gen_expression_check,
1271 -1, 'YAHOO')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001272
1273
Azim Khanb31aa442018-07-03 11:57:54 +01001274class WriteDependencies(TestCase):
Azim Khan599cd242017-07-06 17:34:27 +01001275 """
Azim Khanb31aa442018-07-03 11:57:54 +01001276 Test suite for testing write_dependencies.
Azim Khan599cd242017-07-06 17:34:27 +01001277 """
1278
Azim Khanb31aa442018-07-03 11:57:54 +01001279 def test_no_test_dependencies(self):
Azim Khan599cd242017-07-06 17:34:27 +01001280 """
Azim Khanb31aa442018-07-03 11:57:54 +01001281 Test when test dependencies input is empty.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001282 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001283 """
Azim Khanb31aa442018-07-03 11:57:54 +01001284 stream = StringIOWrapper('test_suite_ut.data', '')
1285 unique_dependencies = []
1286 dep_check_code = write_dependencies(stream, [], unique_dependencies)
Azim Khan599cd242017-07-06 17:34:27 +01001287 self.assertEqual(dep_check_code, '')
Azim Khanb31aa442018-07-03 11:57:54 +01001288 self.assertEqual(len(unique_dependencies), 0)
1289 self.assertEqual(stream.getvalue(), '')
Azim Khan599cd242017-07-06 17:34:27 +01001290
1291 def test_unique_dep_ids(self):
1292 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001293
1294 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001295 """
Azim Khanb31aa442018-07-03 11:57:54 +01001296 stream = StringIOWrapper('test_suite_ut.data', '')
1297 unique_dependencies = []
1298 dep_check_code = write_dependencies(stream, ['DEP3', 'DEP2', 'DEP1'],
1299 unique_dependencies)
Azim Khan599cd242017-07-06 17:34:27 +01001300 expect_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001301 case 0:
1302 {
Azim Khan599cd242017-07-06 17:34:27 +01001303#if defined(DEP3)
Azim Khand61b8372017-07-10 11:54:01 +01001304 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001305#else
Azim Khand61b8372017-07-10 11:54:01 +01001306 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001307#endif
Azim Khand61b8372017-07-10 11:54:01 +01001308 }
1309 break;
1310 case 1:
1311 {
Azim Khan599cd242017-07-06 17:34:27 +01001312#if defined(DEP2)
Azim Khand61b8372017-07-10 11:54:01 +01001313 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001314#else
Azim Khand61b8372017-07-10 11:54:01 +01001315 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001316#endif
Azim Khand61b8372017-07-10 11:54:01 +01001317 }
1318 break;
1319 case 2:
1320 {
Azim Khan599cd242017-07-06 17:34:27 +01001321#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001322 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001323#else
Azim Khand61b8372017-07-10 11:54:01 +01001324 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001325#endif
Azim Khand61b8372017-07-10 11:54:01 +01001326 }
1327 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001328 self.assertEqual(dep_check_code, expect_dep_check_code)
Azim Khanb31aa442018-07-03 11:57:54 +01001329 self.assertEqual(len(unique_dependencies), 3)
1330 self.assertEqual(stream.getvalue(), 'depends_on:0:1:2\n')
Azim Khan599cd242017-07-06 17:34:27 +01001331
1332 def test_dep_id_repeat(self):
1333 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001334
1335 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001336 """
Azim Khanb31aa442018-07-03 11:57:54 +01001337 stream = StringIOWrapper('test_suite_ut.data', '')
1338 unique_dependencies = []
Azim Khan599cd242017-07-06 17:34:27 +01001339 dep_check_code = ''
Azim Khanb31aa442018-07-03 11:57:54 +01001340 dep_check_code += write_dependencies(stream, ['DEP3', 'DEP2'],
1341 unique_dependencies)
1342 dep_check_code += write_dependencies(stream, ['DEP2', 'DEP1'],
1343 unique_dependencies)
1344 dep_check_code += write_dependencies(stream, ['DEP1', 'DEP3'],
1345 unique_dependencies)
Azim Khan599cd242017-07-06 17:34:27 +01001346 expect_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001347 case 0:
1348 {
Azim Khan599cd242017-07-06 17:34:27 +01001349#if defined(DEP3)
Azim Khand61b8372017-07-10 11:54:01 +01001350 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001351#else
Azim Khand61b8372017-07-10 11:54:01 +01001352 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001353#endif
Azim Khand61b8372017-07-10 11:54:01 +01001354 }
1355 break;
1356 case 1:
1357 {
Azim Khan599cd242017-07-06 17:34:27 +01001358#if defined(DEP2)
Azim Khand61b8372017-07-10 11:54:01 +01001359 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001360#else
Azim Khand61b8372017-07-10 11:54:01 +01001361 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001362#endif
Azim Khand61b8372017-07-10 11:54:01 +01001363 }
1364 break;
1365 case 2:
1366 {
Azim Khan599cd242017-07-06 17:34:27 +01001367#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001368 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001369#else
Azim Khand61b8372017-07-10 11:54:01 +01001370 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001371#endif
Azim Khand61b8372017-07-10 11:54:01 +01001372 }
1373 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001374 self.assertEqual(dep_check_code, expect_dep_check_code)
Azim Khanb31aa442018-07-03 11:57:54 +01001375 self.assertEqual(len(unique_dependencies), 3)
1376 self.assertEqual(stream.getvalue(),
1377 'depends_on:0:1\ndepends_on:1:2\ndepends_on:2:0\n')
Azim Khan599cd242017-07-06 17:34:27 +01001378
1379
1380class WriteParams(TestCase):
1381 """
1382 Test Suite for testing write_parameters().
1383 """
1384
1385 def test_no_params(self):
1386 """
1387 Test with empty test_args
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001388 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001389 """
Azim Khanb31aa442018-07-03 11:57:54 +01001390 stream = StringIOWrapper('test_suite_ut.data', '')
Azim Khan599cd242017-07-06 17:34:27 +01001391 unique_expressions = []
Azim Khanb31aa442018-07-03 11:57:54 +01001392 expression_code = write_parameters(stream, [], [], unique_expressions)
Azim Khan599cd242017-07-06 17:34:27 +01001393 self.assertEqual(len(unique_expressions), 0)
1394 self.assertEqual(expression_code, '')
Azim Khanb31aa442018-07-03 11:57:54 +01001395 self.assertEqual(stream.getvalue(), '\n')
Azim Khan599cd242017-07-06 17:34:27 +01001396
1397 def test_no_exp_param(self):
1398 """
1399 Test when there is no macro or expression in the params.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001400 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001401 """
Azim Khanb31aa442018-07-03 11:57:54 +01001402 stream = StringIOWrapper('test_suite_ut.data', '')
Azim Khan599cd242017-07-06 17:34:27 +01001403 unique_expressions = []
Azim Khanb31aa442018-07-03 11:57:54 +01001404 expression_code = write_parameters(stream, ['"Yahoo"', '"abcdef00"',
1405 '0'],
1406 ['char*', 'hex', 'int'],
Azim Khan599cd242017-07-06 17:34:27 +01001407 unique_expressions)
1408 self.assertEqual(len(unique_expressions), 0)
1409 self.assertEqual(expression_code, '')
Azim Khanb31aa442018-07-03 11:57:54 +01001410 self.assertEqual(stream.getvalue(),
1411 ':char*:"Yahoo":hex:"abcdef00":int:0\n')
Azim Khan599cd242017-07-06 17:34:27 +01001412
1413 def test_hex_format_int_param(self):
1414 """
1415 Test int parameter in hex format.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001416 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001417 """
Azim Khanb31aa442018-07-03 11:57:54 +01001418 stream = StringIOWrapper('test_suite_ut.data', '')
Azim Khan599cd242017-07-06 17:34:27 +01001419 unique_expressions = []
Azim Khanb31aa442018-07-03 11:57:54 +01001420 expression_code = write_parameters(stream,
1421 ['"Yahoo"', '"abcdef00"', '0xAA'],
1422 ['char*', 'hex', 'int'],
Azim Khan599cd242017-07-06 17:34:27 +01001423 unique_expressions)
1424 self.assertEqual(len(unique_expressions), 0)
1425 self.assertEqual(expression_code, '')
Azim Khanb31aa442018-07-03 11:57:54 +01001426 self.assertEqual(stream.getvalue(),
1427 ':char*:"Yahoo":hex:"abcdef00":int:0xAA\n')
Azim Khan599cd242017-07-06 17:34:27 +01001428
1429 def test_with_exp_param(self):
1430 """
1431 Test when there is macro or expression in the params.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001432 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001433 """
Azim Khanb31aa442018-07-03 11:57:54 +01001434 stream = StringIOWrapper('test_suite_ut.data', '')
Azim Khan599cd242017-07-06 17:34:27 +01001435 unique_expressions = []
Azim Khanb31aa442018-07-03 11:57:54 +01001436 expression_code = write_parameters(stream,
1437 ['"Yahoo"', '"abcdef00"', '0',
1438 'MACRO1', 'MACRO2', 'MACRO3'],
1439 ['char*', 'hex', 'int',
1440 'int', 'int', 'int'],
Azim Khan599cd242017-07-06 17:34:27 +01001441 unique_expressions)
1442 self.assertEqual(len(unique_expressions), 3)
1443 self.assertEqual(unique_expressions, ['MACRO1', 'MACRO2', 'MACRO3'])
1444 expected_expression_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001445 case 0:
1446 {
1447 *out_value = MACRO1;
1448 }
1449 break;
1450 case 1:
1451 {
1452 *out_value = MACRO2;
1453 }
1454 break;
1455 case 2:
1456 {
1457 *out_value = MACRO3;
1458 }
1459 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001460 self.assertEqual(expression_code, expected_expression_code)
Azim Khanb31aa442018-07-03 11:57:54 +01001461 self.assertEqual(stream.getvalue(),
1462 ':char*:"Yahoo":hex:"abcdef00":int:0:exp:0:exp:1'
1463 ':exp:2\n')
Azim Khan599cd242017-07-06 17:34:27 +01001464
Azim Khanb31aa442018-07-03 11:57:54 +01001465 def test_with_repeat_calls(self):
Azim Khan599cd242017-07-06 17:34:27 +01001466 """
1467 Test when write_parameter() is called with same macro or expression.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001468 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001469 """
Azim Khanb31aa442018-07-03 11:57:54 +01001470 stream = StringIOWrapper('test_suite_ut.data', '')
Azim Khan599cd242017-07-06 17:34:27 +01001471 unique_expressions = []
1472 expression_code = ''
Azim Khanb31aa442018-07-03 11:57:54 +01001473 expression_code += write_parameters(stream,
1474 ['"Yahoo"', 'MACRO1', 'MACRO2'],
1475 ['char*', 'int', 'int'],
Azim Khan599cd242017-07-06 17:34:27 +01001476 unique_expressions)
Azim Khanb31aa442018-07-03 11:57:54 +01001477 expression_code += write_parameters(stream,
1478 ['"abcdef00"', 'MACRO2', 'MACRO3'],
1479 ['hex', 'int', 'int'],
Azim Khan599cd242017-07-06 17:34:27 +01001480 unique_expressions)
Azim Khanb31aa442018-07-03 11:57:54 +01001481 expression_code += write_parameters(stream,
1482 ['0', 'MACRO3', 'MACRO1'],
1483 ['int', 'int', 'int'],
Azim Khan599cd242017-07-06 17:34:27 +01001484 unique_expressions)
1485 self.assertEqual(len(unique_expressions), 3)
1486 self.assertEqual(unique_expressions, ['MACRO1', 'MACRO2', 'MACRO3'])
1487 expected_expression_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001488 case 0:
1489 {
1490 *out_value = MACRO1;
1491 }
1492 break;
1493 case 1:
1494 {
1495 *out_value = MACRO2;
1496 }
1497 break;
1498 case 2:
1499 {
1500 *out_value = MACRO3;
1501 }
1502 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001503 self.assertEqual(expression_code, expected_expression_code)
1504 expected_data_file = ''':char*:"Yahoo":exp:0:exp:1
1505:hex:"abcdef00":exp:1:exp:2
1506:int:0:exp:2:exp:0
1507'''
Azim Khanb31aa442018-07-03 11:57:54 +01001508 self.assertEqual(stream.getvalue(), expected_data_file)
Azim Khan599cd242017-07-06 17:34:27 +01001509
1510
Azim Khanb31aa442018-07-03 11:57:54 +01001511class GenTestSuiteDependenciesChecks(TestCase):
Azim Khan599cd242017-07-06 17:34:27 +01001512 """
Azim Khanb31aa442018-07-03 11:57:54 +01001513 Test suite for testing gen_suite_dep_checks()
Azim Khan599cd242017-07-06 17:34:27 +01001514 """
Azim Khanb31aa442018-07-03 11:57:54 +01001515 def test_empty_suite_dependencies(self):
Azim Khan599cd242017-07-06 17:34:27 +01001516 """
Azim Khanb31aa442018-07-03 11:57:54 +01001517 Test with empty suite_dependencies list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001518
1519 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001520 """
Azim Khanb31aa442018-07-03 11:57:54 +01001521 dep_check_code, expression_code = \
1522 gen_suite_dep_checks([], 'DEP_CHECK_CODE', 'EXPRESSION_CODE')
Azim Khan599cd242017-07-06 17:34:27 +01001523 self.assertEqual(dep_check_code, 'DEP_CHECK_CODE')
1524 self.assertEqual(expression_code, 'EXPRESSION_CODE')
1525
Azim Khanb31aa442018-07-03 11:57:54 +01001526 def test_suite_dependencies(self):
Azim Khan599cd242017-07-06 17:34:27 +01001527 """
Azim Khanb31aa442018-07-03 11:57:54 +01001528 Test with suite_dependencies list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001529
1530 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001531 """
Azim Khanb31aa442018-07-03 11:57:54 +01001532 dep_check_code, expression_code = \
1533 gen_suite_dep_checks(['SUITE_DEP'], 'DEP_CHECK_CODE',
1534 'EXPRESSION_CODE')
1535 expected_dep_check_code = '''
Azim Khan599cd242017-07-06 17:34:27 +01001536#if defined(SUITE_DEP)
1537DEP_CHECK_CODE
Azim Khan599cd242017-07-06 17:34:27 +01001538#endif
1539'''
1540 expected_expression_code = '''
1541#if defined(SUITE_DEP)
1542EXPRESSION_CODE
Azim Khan599cd242017-07-06 17:34:27 +01001543#endif
1544'''
Azim Khanb31aa442018-07-03 11:57:54 +01001545 self.assertEqual(dep_check_code, expected_dep_check_code)
Azim Khan599cd242017-07-06 17:34:27 +01001546 self.assertEqual(expression_code, expected_expression_code)
1547
1548 def test_no_dep_no_exp(self):
1549 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001550 Test when there are no dependency and expression code.
1551 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001552 """
Azim Khanb31aa442018-07-03 11:57:54 +01001553 dep_check_code, expression_code = gen_suite_dep_checks([], '', '')
Azim Khand61b8372017-07-10 11:54:01 +01001554 self.assertEqual(dep_check_code, '')
1555 self.assertEqual(expression_code, '')
Azim Khan599cd242017-07-06 17:34:27 +01001556
1557
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001558class GenFromTestData(TestCase):
1559 """
1560 Test suite for gen_from_test_data()
1561 """
1562
Azim Khanb31aa442018-07-03 11:57:54 +01001563 @staticmethod
1564 @patch("generate_test_code.write_dependencies")
Mohammad Azim Khan78befd92018-03-06 11:49:41 +00001565 @patch("generate_test_code.write_parameters")
Azim Khan4084ec72018-07-05 14:20:08 +01001566 @patch("generate_test_code.gen_suite_dep_checks")
Azim Khanb31aa442018-07-03 11:57:54 +01001567 def test_intermediate_data_file(func_mock1,
1568 write_parameters_mock,
1569 write_dependencies_mock):
Azim Khan599cd242017-07-06 17:34:27 +01001570 """
1571 Test that intermediate data file is written with expected data.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001572 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001573 """
1574 data = '''
1575My test
1576depends_on:DEP1
1577func1:0
1578'''
1579 data_f = StringIOWrapper('test_suite_ut.data', data)
1580 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
1581 func_info = {'test_func1': (1, ('int',))}
Azim Khanb31aa442018-07-03 11:57:54 +01001582 suite_dependencies = []
Azim Khan599cd242017-07-06 17:34:27 +01001583 write_parameters_mock.side_effect = write_parameters
Azim Khanb31aa442018-07-03 11:57:54 +01001584 write_dependencies_mock.side_effect = write_dependencies
1585 func_mock1.side_effect = gen_suite_dep_checks
1586 gen_from_test_data(data_f, out_data_f, func_info, suite_dependencies)
1587 write_dependencies_mock.assert_called_with(out_data_f,
1588 ['DEP1'], ['DEP1'])
1589 write_parameters_mock.assert_called_with(out_data_f, ['0'],
1590 ('int',), [])
Azim Khan599cd242017-07-06 17:34:27 +01001591 expected_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001592 case 0:
1593 {
Azim Khan599cd242017-07-06 17:34:27 +01001594#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001595 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001596#else
Azim Khand61b8372017-07-10 11:54:01 +01001597 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001598#endif
Azim Khand61b8372017-07-10 11:54:01 +01001599 }
1600 break;'''
Azim Khanb31aa442018-07-03 11:57:54 +01001601 func_mock1.assert_called_with(
1602 suite_dependencies, expected_dep_check_code, '')
Azim Khan599cd242017-07-06 17:34:27 +01001603
1604 def test_function_not_found(self):
1605 """
1606 Test that AssertError is raised when function info in not found.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001607 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001608 """
1609 data = '''
1610My test
1611depends_on:DEP1
1612func1:0
1613'''
1614 data_f = StringIOWrapper('test_suite_ut.data', data)
1615 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
1616 func_info = {'test_func2': (1, ('int',))}
Azim Khanb31aa442018-07-03 11:57:54 +01001617 suite_dependencies = []
1618 self.assertRaises(GeneratorInputError, gen_from_test_data,
1619 data_f, out_data_f, func_info, suite_dependencies)
Azim Khan599cd242017-07-06 17:34:27 +01001620
1621 def test_different_func_args(self):
1622 """
Azim Khanb31aa442018-07-03 11:57:54 +01001623 Test that AssertError is raised when no. of parameters and
1624 function args differ.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001625 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001626 """
1627 data = '''
1628My test
1629depends_on:DEP1
1630func1:0
1631'''
1632 data_f = StringIOWrapper('test_suite_ut.data', data)
1633 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
Azim Khanb31aa442018-07-03 11:57:54 +01001634 func_info = {'test_func2': (1, ('int', 'hex'))}
1635 suite_dependencies = []
1636 self.assertRaises(GeneratorInputError, gen_from_test_data, data_f,
1637 out_data_f, func_info, suite_dependencies)
Azim Khan599cd242017-07-06 17:34:27 +01001638
1639 def test_output(self):
1640 """
1641 Test that intermediate data file is written with expected data.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001642 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001643 """
1644 data = '''
1645My test 1
1646depends_on:DEP1
1647func1:0:0xfa:MACRO1:MACRO2
1648
1649My test 2
1650depends_on:DEP1:DEP2
1651func2:"yahoo":88:MACRO1
1652'''
1653 data_f = StringIOWrapper('test_suite_ut.data', data)
1654 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
Azim Khanb31aa442018-07-03 11:57:54 +01001655 func_info = {'test_func1': (0, ('int', 'int', 'int', 'int')),
1656 'test_func2': (1, ('char*', 'int', 'int'))}
1657 suite_dependencies = []
1658 dep_check_code, expression_code = \
1659 gen_from_test_data(data_f, out_data_f, func_info,
1660 suite_dependencies)
Azim Khan599cd242017-07-06 17:34:27 +01001661 expected_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001662 case 0:
1663 {
Azim Khan599cd242017-07-06 17:34:27 +01001664#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001665 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001666#else
Azim Khand61b8372017-07-10 11:54:01 +01001667 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001668#endif
Azim Khand61b8372017-07-10 11:54:01 +01001669 }
1670 break;
1671 case 1:
1672 {
Azim Khan599cd242017-07-06 17:34:27 +01001673#if defined(DEP2)
Azim Khand61b8372017-07-10 11:54:01 +01001674 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001675#else
Azim Khand61b8372017-07-10 11:54:01 +01001676 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001677#endif
Azim Khand61b8372017-07-10 11:54:01 +01001678 }
1679 break;'''
Azim Khanb31aa442018-07-03 11:57:54 +01001680 expected_data = '''My test 1
Azim Khan599cd242017-07-06 17:34:27 +01001681depends_on:0
16820:int:0:int:0xfa:exp:0:exp:1
1683
1684My test 2
1685depends_on:0:1
16861:char*:"yahoo":int:88:exp:0
1687
1688'''
1689 expected_expression_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001690 case 0:
1691 {
1692 *out_value = MACRO1;
1693 }
1694 break;
1695 case 1:
1696 {
1697 *out_value = MACRO2;
1698 }
1699 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001700 self.assertEqual(dep_check_code, expected_dep_check_code)
Azim Khanb31aa442018-07-03 11:57:54 +01001701 self.assertEqual(out_data_f.getvalue(), expected_data)
Azim Khan599cd242017-07-06 17:34:27 +01001702 self.assertEqual(expression_code, expected_expression_code)
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001703
1704
Azim Khanb31aa442018-07-03 11:57:54 +01001705if __name__ == '__main__':
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001706 unittest_main()