blob: f1088a32a88e74ad8d0c03846e174700f8fe0fa2 [file] [log] [blame]
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001#!/usr/bin/env python
Mohammad Azim Khan78befd92018-03-06 11:49:41 +00002# Unit test for generate_test_code.py
Azim Khanf0e42fb2017-08-02 14:47:13 +01003#
Mohammad Azim Khan78befd92018-03-06 11:49:41 +00004# 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#
19# This file is part of mbed TLS (https://tls.mbed.org)
Azim Khan4b543232017-06-30 09:35:21 +010020
Azim Khan4b543232017-06-30 09:35:21 +010021from StringIO import StringIO
22from unittest import TestCase, main as unittest_main
23from mock import patch
Mohammad Azim Khan78befd92018-03-06 11:49:41 +000024from generate_test_code import *
Azim Khan4b543232017-06-30 09:35:21 +010025
26
27"""
Mohammad Azim Khan78befd92018-03-06 11:49:41 +000028Unit tests for generate_test_code.py
Azim Khan4b543232017-06-30 09:35:21 +010029"""
30
31
32class GenDep(TestCase):
33 """
34 Test suite for function gen_dep()
35 """
36
37 def test_deps_list(self):
38 """
39 Test that gen_dep() correctly creates deps for given dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010040 :return:
Azim Khan4b543232017-06-30 09:35:21 +010041 """
42 deps = ['DEP1', 'DEP2']
43 dep_start, dep_end = gen_deps(deps)
44 ifdef1, ifdef2 = dep_start.splitlines()
45 endif1, endif2 = dep_end.splitlines()
46 self.assertEqual(ifdef1, '#if defined(DEP1)', 'ifdef generated incorrectly')
47 self.assertEqual(ifdef2, '#if defined(DEP2)', 'ifdef generated incorrectly')
48 self.assertEqual(endif1, '#endif /* DEP2 */', 'endif generated incorrectly')
49 self.assertEqual(endif2, '#endif /* DEP1 */', 'endif generated incorrectly')
50
51 def test_disabled_deps_list(self):
52 """
53 Test that gen_dep() correctly creates deps for given dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010054 :return:
Azim Khan4b543232017-06-30 09:35:21 +010055 """
56 deps = ['!DEP1', '!DEP2']
57 dep_start, dep_end = gen_deps(deps)
58 ifdef1, ifdef2 = dep_start.splitlines()
59 endif1, endif2 = dep_end.splitlines()
60 self.assertEqual(ifdef1, '#if !defined(DEP1)', 'ifdef generated incorrectly')
61 self.assertEqual(ifdef2, '#if !defined(DEP2)', 'ifdef generated incorrectly')
62 self.assertEqual(endif1, '#endif /* !DEP2 */', 'endif generated incorrectly')
63 self.assertEqual(endif2, '#endif /* !DEP1 */', 'endif generated incorrectly')
64
65 def test_mixed_deps_list(self):
66 """
67 Test that gen_dep() correctly creates deps for given dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010068 :return:
Azim Khan4b543232017-06-30 09:35:21 +010069 """
70 deps = ['!DEP1', 'DEP2']
71 dep_start, dep_end = gen_deps(deps)
72 ifdef1, ifdef2 = dep_start.splitlines()
73 endif1, endif2 = dep_end.splitlines()
74 self.assertEqual(ifdef1, '#if !defined(DEP1)', 'ifdef generated incorrectly')
75 self.assertEqual(ifdef2, '#if defined(DEP2)', 'ifdef generated incorrectly')
76 self.assertEqual(endif1, '#endif /* DEP2 */', 'endif generated incorrectly')
77 self.assertEqual(endif2, '#endif /* !DEP1 */', 'endif generated incorrectly')
78
79 def test_empty_deps_list(self):
80 """
81 Test that gen_dep() correctly creates deps for given dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010082 :return:
Azim Khan4b543232017-06-30 09:35:21 +010083 """
84 deps = []
85 dep_start, dep_end = gen_deps(deps)
86 self.assertEqual(dep_start, '', 'ifdef generated incorrectly')
87 self.assertEqual(dep_end, '', 'ifdef generated incorrectly')
88
89 def test_large_deps_list(self):
90 """
91 Test that gen_dep() correctly creates deps for given dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +010092 :return:
Azim Khan4b543232017-06-30 09:35:21 +010093 """
94 deps = []
95 count = 10
96 for i in range(count):
97 deps.append('DEP%d' % i)
98 dep_start, dep_end = gen_deps(deps)
99 self.assertEqual(len(dep_start.splitlines()), count, 'ifdef generated incorrectly')
100 self.assertEqual(len(dep_end.splitlines()), count, 'ifdef generated incorrectly')
101
102
103class GenDepOneLine(TestCase):
104 """
105 Test Suite for testing gen_deps_one_line()
106 """
107
108 def test_deps_list(self):
109 """
110 Test that gen_dep() correctly creates deps for given dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100111 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100112 """
113 deps = ['DEP1', 'DEP2']
114 dep_str = gen_deps_one_line(deps)
115 self.assertEqual(dep_str, '#if defined(DEP1) && defined(DEP2)', 'ifdef generated incorrectly')
116
117 def test_disabled_deps_list(self):
118 """
119 Test that gen_dep() correctly creates deps for given dependency list.
120 :return:
121 """
122 deps = ['!DEP1', '!DEP2']
123 dep_str = gen_deps_one_line(deps)
124 self.assertEqual(dep_str, '#if !defined(DEP1) && !defined(DEP2)', 'ifdef generated incorrectly')
125
126 def test_mixed_deps_list(self):
127 """
128 Test that gen_dep() correctly creates deps for given dependency list.
129 :return:
130 """
131 deps = ['!DEP1', 'DEP2']
132 dep_str = gen_deps_one_line(deps)
133 self.assertEqual(dep_str, '#if !defined(DEP1) && defined(DEP2)', 'ifdef generated incorrectly')
134
135 def test_empty_deps_list(self):
136 """
137 Test that gen_dep() correctly creates deps for given dependency list.
138 :return:
139 """
140 deps = []
141 dep_str = gen_deps_one_line(deps)
142 self.assertEqual(dep_str, '', 'ifdef generated incorrectly')
143
144 def test_large_deps_list(self):
145 """
146 Test that gen_dep() correctly creates deps for given dependency list.
147 :return:
148 """
149 deps = []
150 count = 10
151 for i in range(count):
152 deps.append('DEP%d' % i)
153 dep_str = gen_deps_one_line(deps)
154 expected = '#if ' + ' && '.join(['defined(%s)' % x for x in deps])
155 self.assertEqual(dep_str, expected, 'ifdef generated incorrectly')
156
157
158class GenFunctionWrapper(TestCase):
159 """
160 Test Suite for testing gen_function_wrapper()
161 """
162
163 def test_params_unpack(self):
164 """
165 Test that params are properly unpacked in the function call.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100166
167 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100168 """
169 code = gen_function_wrapper('test_a', '', ('a', 'b', 'c', 'd'))
170 expected = '''
171void test_a_wrapper( void ** params )
172{
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100173
Azim Khan4b543232017-06-30 09:35:21 +0100174 test_a( a, b, c, d );
175}
176'''
177 self.assertEqual(code, expected)
178
179 def test_local(self):
180 """
181 Test that params are properly unpacked in the function call.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100182
183 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100184 """
185 code = gen_function_wrapper('test_a', 'int x = 1;', ('x', 'b', 'c', 'd'))
186 expected = '''
187void test_a_wrapper( void ** params )
188{
Azim Khan4b543232017-06-30 09:35:21 +0100189int x = 1;
190 test_a( x, b, c, d );
191}
192'''
193 self.assertEqual(code, expected)
194
195 def test_empty_params(self):
196 """
197 Test that params are properly unpacked in the function call.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100198
199 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100200 """
201 code = gen_function_wrapper('test_a', '', ())
202 expected = '''
203void test_a_wrapper( void ** params )
204{
205 (void)params;
206
207 test_a( );
208}
209'''
210 self.assertEqual(code, expected)
211
212
213class GenDispatch(TestCase):
214 """
215 Test suite for testing gen_dispatch()
216 """
217
218 def test_dispatch(self):
219 """
220 Test that dispatch table entry is generated correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100221 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100222 """
223 code = gen_dispatch('test_a', ['DEP1', 'DEP2'])
224 expected = '''
225#if defined(DEP1) && defined(DEP2)
226 test_a_wrapper,
227#else
228 NULL,
229#endif
230'''
231 self.assertEqual(code, expected)
232
233 def test_empty_deps(self):
234 """
235 Test empty dependency list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100236 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100237 """
238 code = gen_dispatch('test_a', [])
239 expected = '''
240 test_a_wrapper,
241'''
242 self.assertEqual(code, expected)
243
244
245class StringIOWrapper(StringIO, object):
246 """
247 file like class to mock file object in tests.
248 """
249 def __init__(self, file_name, data, line_no = 1):
250 """
251 Init file handle.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100252
253 :param file_name:
Azim Khan4b543232017-06-30 09:35:21 +0100254 :param data:
255 :param line_no:
256 """
257 super(StringIOWrapper, self).__init__(data)
258 self.line_no = line_no
259 self.name = file_name
260
261 def next(self):
262 """
263 Iterator return impl.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100264 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100265 """
266 line = super(StringIOWrapper, self).next()
267 return line
268
269 def readline(self, limit=0):
270 """
271 Wrap the base class readline.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100272
273 :param limit:
274 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100275 """
276 line = super(StringIOWrapper, self).readline()
277 if line:
278 self.line_no += 1
279 return line
280
281
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000282class ParseUntilPattern(TestCase):
Azim Khan4b543232017-06-30 09:35:21 +0100283 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000284 Test Suite for testing parse_until_pattern().
Azim Khan4b543232017-06-30 09:35:21 +0100285 """
286
287 def test_suite_headers(self):
288 """
289 Test that suite headers are parsed correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100290
291 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100292 """
293 data = '''#include "mbedtls/ecp.h"
294
295#define ECP_PF_UNKNOWN -1
296/* END_HEADER */
297'''
298 expected = '''#line 1 "test_suite_ut.function"
299#include "mbedtls/ecp.h"
300
301#define ECP_PF_UNKNOWN -1
302'''
303 s = StringIOWrapper('test_suite_ut.function', data, line_no=0)
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000304 headers = parse_until_pattern(s, END_HEADER_REGEX)
Azim Khan4b543232017-06-30 09:35:21 +0100305 self.assertEqual(headers, expected)
306
307 def test_line_no(self):
308 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100309 Test that #line is set to correct line no. in source .function file.
310
311 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100312 """
313 data = '''#include "mbedtls/ecp.h"
314
315#define ECP_PF_UNKNOWN -1
316/* END_HEADER */
317'''
318 offset_line_no = 5
319 expected = '''#line %d "test_suite_ut.function"
320#include "mbedtls/ecp.h"
321
322#define ECP_PF_UNKNOWN -1
323''' % (offset_line_no + 1)
324 s = StringIOWrapper('test_suite_ut.function', data, offset_line_no)
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000325 headers = parse_until_pattern(s, END_HEADER_REGEX)
Azim Khan4b543232017-06-30 09:35:21 +0100326 self.assertEqual(headers, expected)
327
328 def test_no_end_header_comment(self):
329 """
330 Test that InvalidFileFormat is raised when end header comment is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100331 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100332 """
333 data = '''#include "mbedtls/ecp.h"
334
335#define ECP_PF_UNKNOWN -1
336
337'''
338 s = StringIOWrapper('test_suite_ut.function', data)
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000339 self.assertRaises(InvalidFileFormat, parse_until_pattern, s, END_HEADER_REGEX)
Azim Khan4b543232017-06-30 09:35:21 +0100340
341
342class ParseSuiteDeps(TestCase):
343 """
344 Test Suite for testing parse_suite_deps().
345 """
346
347 def test_suite_deps(self):
348 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100349
350 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100351 """
352 data = '''
353 * depends_on:MBEDTLS_ECP_C
354 * END_DEPENDENCIES
355 */
356'''
357 expected = ['MBEDTLS_ECP_C']
358 s = StringIOWrapper('test_suite_ut.function', data)
359 deps = parse_suite_deps(s)
360 self.assertEqual(deps, expected)
361
362 def test_no_end_dep_comment(self):
363 """
364 Test that InvalidFileFormat is raised when end dep comment is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100365 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100366 """
367 data = '''
368* depends_on:MBEDTLS_ECP_C
369'''
370 s = StringIOWrapper('test_suite_ut.function', data)
371 self.assertRaises(InvalidFileFormat, parse_suite_deps, s)
372
373 def test_deps_split(self):
374 """
375 Test that InvalidFileFormat is raised when end dep comment is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100376 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100377 """
378 data = '''
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100379 * depends_on:MBEDTLS_ECP_C:A:B: C : D :F : G: !H
Azim Khan4b543232017-06-30 09:35:21 +0100380 * END_DEPENDENCIES
381 */
382'''
383 expected = ['MBEDTLS_ECP_C', 'A', 'B', 'C', 'D', 'F', 'G', '!H']
384 s = StringIOWrapper('test_suite_ut.function', data)
385 deps = parse_suite_deps(s)
386 self.assertEqual(deps, expected)
387
388
389class ParseFuncDeps(TestCase):
390 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100391 Test Suite for testing parse_function_deps()
Azim Khan4b543232017-06-30 09:35:21 +0100392 """
393
394 def test_function_deps(self):
395 """
396 Test that parse_function_deps() correctly parses function dependencies.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100397 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100398 """
399 line = '/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */'
400 expected = ['MBEDTLS_ENTROPY_NV_SEED', 'MBEDTLS_FS_IO']
401 deps = parse_function_deps(line)
402 self.assertEqual(deps, expected)
403
404 def test_no_deps(self):
405 """
406 Test that parse_function_deps() correctly parses function dependencies.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100407 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100408 """
409 line = '/* BEGIN_CASE */'
410 deps = parse_function_deps(line)
411 self.assertEqual(deps, [])
412
413 def test_poorly_defined_deps(self):
414 """
415 Test that parse_function_deps() correctly parses function dependencies.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100416 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100417 """
418 line = '/* BEGIN_CASE depends_on:MBEDTLS_FS_IO: A : !B:C : F*/'
419 deps = parse_function_deps(line)
420 self.assertEqual(deps, ['MBEDTLS_FS_IO', 'A', '!B', 'C', 'F'])
421
422
423class ParseFuncSignature(TestCase):
424 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100425 Test Suite for parse_function_signature().
Azim Khan4b543232017-06-30 09:35:21 +0100426 """
427
428 def test_int_and_char_params(self):
429 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100430 Test int and char parameters parsing
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100431 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100432 """
433 line = 'void entropy_threshold( char * a, int b, int result )'
434 name, args, local, arg_dispatch = parse_function_signature(line)
435 self.assertEqual(name, 'entropy_threshold')
436 self.assertEqual(args, ['char*', 'int', 'int'])
437 self.assertEqual(local, '')
438 self.assertEqual(arg_dispatch, ['(char *) params[0]', '*( (int *) params[1] )', '*( (int *) params[2] )'])
439
440 def test_hex_params(self):
441 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100442 Test hex parameters parsing
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100443 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100444 """
Azim Khan5fcca462018-06-29 11:05:32 +0100445 line = 'void entropy_threshold( char * a, data_t * h, int result )'
Azim Khan4b543232017-06-30 09:35:21 +0100446 name, args, local, arg_dispatch = parse_function_signature(line)
447 self.assertEqual(name, 'entropy_threshold')
448 self.assertEqual(args, ['char*', 'hex', 'int'])
Azim Khan5fcca462018-06-29 11:05:32 +0100449 self.assertEqual(local, ' data_t hex1 = {(uint8_t *) params[1], *( (uint32_t *) params[2] )};\n')
Azim Khan4b543232017-06-30 09:35:21 +0100450 self.assertEqual(arg_dispatch, ['(char *) params[0]', '&hex1', '*( (int *) params[3] )'])
451
452 def test_non_void_function(self):
453 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100454 Test invalid signature (non void).
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100455 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100456 """
Azim Khan5fcca462018-06-29 11:05:32 +0100457 line = 'int entropy_threshold( char * a, data_t * h, int result )'
Azim Khan4b543232017-06-30 09:35:21 +0100458 self.assertRaises(ValueError, parse_function_signature, line)
459
460 def test_unsupported_arg(self):
461 """
Azim Khan5fcca462018-06-29 11:05:32 +0100462 Test unsupported arguments (not among int, char * and data_t)
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100463 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100464 """
Azim Khan5fcca462018-06-29 11:05:32 +0100465 line = 'int entropy_threshold( char * a, data_t * h, int * result )'
Azim Khan4b543232017-06-30 09:35:21 +0100466 self.assertRaises(ValueError, parse_function_signature, line)
467
468 def test_no_params(self):
469 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100470 Test no parameters.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100471 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100472 """
473 line = 'void entropy_threshold()'
474 name, args, local, arg_dispatch = parse_function_signature(line)
475 self.assertEqual(name, 'entropy_threshold')
476 self.assertEqual(args, [])
477 self.assertEqual(local, '')
478 self.assertEqual(arg_dispatch, [])
479
480
481class ParseFunctionCode(TestCase):
482 """
483 Test suite for testing parse_function_code()
484 """
485
486 def test_no_function(self):
487 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100488 Test no test function found.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100489 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100490 """
491 data = '''
492No
493test
494function
495'''
496 s = StringIOWrapper('test_suite_ut.function', data)
497 self.assertRaises(InvalidFileFormat, parse_function_code, s, [], [])
498
499 def test_no_end_case_comment(self):
500 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100501 Test missing end case.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100502 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100503 """
504 data = '''
505void test_func()
506{
507}
508'''
509 s = StringIOWrapper('test_suite_ut.function', data)
510 self.assertRaises(InvalidFileFormat, parse_function_code, s, [], [])
511
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000512 @patch("generate_test_code.parse_function_signature")
Azim Khan4b543232017-06-30 09:35:21 +0100513 def test_parse_function_signature_called(self, parse_function_signature_mock):
514 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100515 Test parse_function_code()
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100516 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100517 """
518 parse_function_signature_mock.return_value = ('test_func', [], '', [])
519 data = '''
520void test_func()
521{
522}
523'''
524 s = StringIOWrapper('test_suite_ut.function', data)
525 self.assertRaises(InvalidFileFormat, parse_function_code, s, [], [])
526 self.assertTrue(parse_function_signature_mock.called)
527 parse_function_signature_mock.assert_called_with('void test_func()\n')
528
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000529 @patch("generate_test_code.gen_dispatch")
530 @patch("generate_test_code.gen_deps")
531 @patch("generate_test_code.gen_function_wrapper")
532 @patch("generate_test_code.parse_function_signature")
Azim Khan4b543232017-06-30 09:35:21 +0100533 def test_return(self, parse_function_signature_mock,
534 gen_function_wrapper_mock,
535 gen_deps_mock,
536 gen_dispatch_mock):
537 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100538 Test generated code.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100539 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100540 """
541 parse_function_signature_mock.return_value = ('func', [], '', [])
542 gen_function_wrapper_mock.return_value = ''
543 gen_deps_mock.side_effect = gen_deps
544 gen_dispatch_mock.side_effect = gen_dispatch
545 data = '''
546void func()
547{
548 ba ba black sheep
549 have you any wool
550}
551/* END_CASE */
552'''
553 s = StringIOWrapper('test_suite_ut.function', data)
554 name, arg, code, dispatch_code = parse_function_code(s, [], [])
555
556 #self.assertRaises(InvalidFileFormat, parse_function_code, s, [], [])
557 self.assertTrue(parse_function_signature_mock.called)
558 parse_function_signature_mock.assert_called_with('void func()\n')
559 gen_function_wrapper_mock.assert_called_with('test_func', '', [])
560 self.assertEqual(name, 'test_func')
561 self.assertEqual(arg, [])
562 expected = '''#line 2 "test_suite_ut.function"
563void test_func()
564{
565 ba ba black sheep
566 have you any wool
567exit:
568 ;;
569}
570'''
571 self.assertEqual(code, expected)
572 self.assertEqual(dispatch_code, "\n test_func_wrapper,\n")
573
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000574 @patch("generate_test_code.gen_dispatch")
575 @patch("generate_test_code.gen_deps")
576 @patch("generate_test_code.gen_function_wrapper")
577 @patch("generate_test_code.parse_function_signature")
Azim Khan4b543232017-06-30 09:35:21 +0100578 def test_with_exit_label(self, parse_function_signature_mock,
579 gen_function_wrapper_mock,
580 gen_deps_mock,
581 gen_dispatch_mock):
582 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100583 Test when exit label is present.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100584 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100585 """
586 parse_function_signature_mock.return_value = ('func', [], '', [])
587 gen_function_wrapper_mock.return_value = ''
588 gen_deps_mock.side_effect = gen_deps
589 gen_dispatch_mock.side_effect = gen_dispatch
590 data = '''
591void func()
592{
593 ba ba black sheep
594 have you any wool
595exit:
596 yes sir yes sir
597 3 bags full
598}
599/* END_CASE */
600'''
601 s = StringIOWrapper('test_suite_ut.function', data)
602 name, arg, code, dispatch_code = parse_function_code(s, [], [])
603
604 expected = '''#line 2 "test_suite_ut.function"
605void test_func()
606{
607 ba ba black sheep
608 have you any wool
609exit:
610 yes sir yes sir
611 3 bags full
612}
613'''
614 self.assertEqual(code, expected)
615
616
617class ParseFunction(TestCase):
618 """
619 Test Suite for testing parse_functions()
620 """
621
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000622 @patch("generate_test_code.parse_until_pattern")
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000623 def test_begin_header(self, parse_until_pattern_mock):
Azim Khan4b543232017-06-30 09:35:21 +0100624 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000625 Test that begin header is checked and parse_until_pattern() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100626 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100627 """
628 def stop(this):
629 raise Exception
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000630 parse_until_pattern_mock.side_effect = stop
Azim Khan4b543232017-06-30 09:35:21 +0100631 data = '''/* BEGIN_HEADER */
632#include "mbedtls/ecp.h"
633
634#define ECP_PF_UNKNOWN -1
635/* END_HEADER */
636'''
637 s = StringIOWrapper('test_suite_ut.function', data)
638 self.assertRaises(Exception, parse_functions, s)
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000639 parse_until_pattern_mock.assert_called_with(s, END_HEADER_REGEX)
640 self.assertEqual(s.line_no, 2)
641
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000642 @patch("generate_test_code.parse_until_pattern")
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000643 def test_begin_helper(self, parse_until_pattern_mock):
644 """
645 Test that begin helper is checked and parse_until_pattern() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100646 :return:
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000647 """
648 def stop(this):
649 raise Exception
650 parse_until_pattern_mock.side_effect = stop
651 data = '''/* BEGIN_SUITE_HELPERS */
652void print_helloworld()
653{
654 printf ("Hello World!\n");
655}
656/* END_SUITE_HELPERS */
657'''
658 s = StringIOWrapper('test_suite_ut.function', data)
659 self.assertRaises(Exception, parse_functions, s)
660 parse_until_pattern_mock.assert_called_with(s, END_SUITE_HELPERS_REGEX)
Azim Khan4b543232017-06-30 09:35:21 +0100661 self.assertEqual(s.line_no, 2)
662
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000663 @patch("generate_test_code.parse_suite_deps")
Azim Khan4b543232017-06-30 09:35:21 +0100664 def test_begin_dep(self, parse_suite_deps_mock):
665 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000666 Test that begin dep is checked and parse_suite_deps() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100667 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100668 """
669 def stop(this):
670 raise Exception
671 parse_suite_deps_mock.side_effect = stop
672 data = '''/* BEGIN_DEPENDENCIES
673 * depends_on:MBEDTLS_ECP_C
674 * END_DEPENDENCIES
675 */
676'''
677 s = StringIOWrapper('test_suite_ut.function', data)
678 self.assertRaises(Exception, parse_functions, s)
679 parse_suite_deps_mock.assert_called_with(s)
680 self.assertEqual(s.line_no, 2)
681
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000682 @patch("generate_test_code.parse_function_deps")
Azim Khan4b543232017-06-30 09:35:21 +0100683 def test_begin_function_dep(self, parse_function_deps_mock):
684 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000685 Test that begin dep is checked and parse_function_deps() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100686 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100687 """
688 def stop(this):
689 raise Exception
690 parse_function_deps_mock.side_effect = stop
691
692 deps_str = '/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */\n'
693 data = '''%svoid test_func()
694{
695}
696''' % deps_str
697 s = StringIOWrapper('test_suite_ut.function', data)
698 self.assertRaises(Exception, parse_functions, s)
699 parse_function_deps_mock.assert_called_with(deps_str)
700 self.assertEqual(s.line_no, 2)
701
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000702 @patch("generate_test_code.parse_function_code")
703 @patch("generate_test_code.parse_function_deps")
Azim Khan4b543232017-06-30 09:35:21 +0100704 def test_return(self, parse_function_deps_mock, parse_function_code_mock):
705 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000706 Test that begin case is checked and parse_function_code() is called.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100707 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100708 """
709 def stop(this):
710 raise Exception
711 parse_function_deps_mock.return_value = []
712 in_func_code= '''void test_func()
713{
714}
715'''
716 func_dispatch = '''
717 test_func_wrapper,
718'''
719 parse_function_code_mock.return_value = 'test_func', [], in_func_code, func_dispatch
720 deps_str = '/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */\n'
721 data = '''%svoid test_func()
722{
723}
724''' % deps_str
725 s = StringIOWrapper('test_suite_ut.function', data)
726 suite_deps, dispatch_code, func_code, func_info = parse_functions(s)
727 parse_function_deps_mock.assert_called_with(deps_str)
728 parse_function_code_mock.assert_called_with(s, [], [])
729 self.assertEqual(s.line_no, 5)
730 self.assertEqual(suite_deps, [])
731 expected_dispatch_code = '''/* Function Id: 0 */
732
733 test_func_wrapper,
734'''
735 self.assertEqual(dispatch_code, expected_dispatch_code)
736 self.assertEqual(func_code, in_func_code)
737 self.assertEqual(func_info, {'test_func': (0, [])})
738
739 def test_parsing(self):
740 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000741 Test case parsing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100742 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100743 """
744 data = '''/* BEGIN_HEADER */
745#include "mbedtls/ecp.h"
746
747#define ECP_PF_UNKNOWN -1
748/* END_HEADER */
749
750/* BEGIN_DEPENDENCIES
751 * depends_on:MBEDTLS_ECP_C
752 * END_DEPENDENCIES
753 */
754
755/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
756void func1()
757{
758}
759/* END_CASE */
760
761/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
762void func2()
763{
764}
765/* END_CASE */
766'''
767 s = StringIOWrapper('test_suite_ut.function', data)
768 suite_deps, dispatch_code, func_code, func_info = parse_functions(s)
769 self.assertEqual(s.line_no, 23)
770 self.assertEqual(suite_deps, ['MBEDTLS_ECP_C'])
771
772 expected_dispatch_code = '''/* Function Id: 0 */
773
774#if defined(MBEDTLS_ECP_C) && defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_FS_IO)
775 test_func1_wrapper,
776#else
777 NULL,
778#endif
779/* Function Id: 1 */
780
781#if defined(MBEDTLS_ECP_C) && defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_FS_IO)
782 test_func2_wrapper,
783#else
784 NULL,
785#endif
786'''
787 self.assertEqual(dispatch_code, expected_dispatch_code)
788 expected_func_code = '''#if defined(MBEDTLS_ECP_C)
789#line 3 "test_suite_ut.function"
790#include "mbedtls/ecp.h"
791
792#define ECP_PF_UNKNOWN -1
793#if defined(MBEDTLS_ENTROPY_NV_SEED)
794#if defined(MBEDTLS_FS_IO)
795#line 14 "test_suite_ut.function"
796void test_func1()
797{
798exit:
799 ;;
800}
801
802void test_func1_wrapper( void ** params )
803{
804 (void)params;
805
806 test_func1( );
807}
808#endif /* MBEDTLS_FS_IO */
809#endif /* MBEDTLS_ENTROPY_NV_SEED */
810#if defined(MBEDTLS_ENTROPY_NV_SEED)
811#if defined(MBEDTLS_FS_IO)
812#line 20 "test_suite_ut.function"
813void test_func2()
814{
815exit:
816 ;;
817}
818
819void test_func2_wrapper( void ** params )
820{
821 (void)params;
822
823 test_func2( );
824}
825#endif /* MBEDTLS_FS_IO */
826#endif /* MBEDTLS_ENTROPY_NV_SEED */
827#endif /* MBEDTLS_ECP_C */
828'''
829 self.assertEqual(func_code, expected_func_code)
830 self.assertEqual(func_info, {'test_func1': (0, []), 'test_func2': (1, [])})
831
832 def test_same_function_name(self):
833 """
Mohammad Azim Khanb5229292018-02-06 13:08:01 +0000834 Test name conflict.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100835 :return:
Azim Khan4b543232017-06-30 09:35:21 +0100836 """
837 data = '''/* BEGIN_HEADER */
838#include "mbedtls/ecp.h"
839
840#define ECP_PF_UNKNOWN -1
841/* END_HEADER */
842
843/* BEGIN_DEPENDENCIES
844 * depends_on:MBEDTLS_ECP_C
845 * END_DEPENDENCIES
846 */
847
848/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
849void func()
850{
851}
852/* END_CASE */
853
854/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
855void func()
856{
857}
858/* END_CASE */
859'''
860 s = StringIOWrapper('test_suite_ut.function', data)
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +0100861 self.assertRaises(GeneratorInputError, parse_functions, s)
Azim Khan4b543232017-06-30 09:35:21 +0100862
863
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100864class ExcapedSplit(TestCase):
865 """
Azim Khan599cd242017-07-06 17:34:27 +0100866 Test suite for testing escaped_split().
867 Note: Since escaped_split() output is used to write back to the intermediate data file. Any escape characters
868 in the input are retained in the output.
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100869 """
870
871 def test_invalid_input(self):
872 """
873 Test when input split character is not a character.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100874 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100875 """
876 self.assertRaises(ValueError, escaped_split, '', 'string')
877
878 def test_empty_string(self):
879 """
880 Test empty strig input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100881 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100882 """
883 splits = escaped_split('', ':')
884 self.assertEqual(splits, [])
885
886 def test_no_escape(self):
887 """
888 Test with no escape character. The behaviour should be same as str.split()
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100889 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100890 """
891 s = 'yahoo:google'
892 splits = escaped_split(s, ':')
893 self.assertEqual(splits, s.split(':'))
894
895 def test_escaped_input(self):
896 """
897 Test imput that has escaped delimiter.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100898 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100899 """
900 s = 'yahoo\:google:facebook'
901 splits = escaped_split(s, ':')
Azim Khan599cd242017-07-06 17:34:27 +0100902 self.assertEqual(splits, ['yahoo\:google', 'facebook'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100903
904 def test_escaped_escape(self):
905 """
906 Test imput that has escaped delimiter.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100907 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100908 """
909 s = 'yahoo\\\:google:facebook'
910 splits = escaped_split(s, ':')
Azim Khan599cd242017-07-06 17:34:27 +0100911 self.assertEqual(splits, ['yahoo\\\\', 'google', 'facebook'])
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100912
913 def test_all_at_once(self):
914 """
915 Test imput that has escaped delimiter.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100916 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100917 """
918 s = 'yahoo\\\:google:facebook\:instagram\\\:bbc\\\\:wikipedia'
919 splits = escaped_split(s, ':')
Azim Khan599cd242017-07-06 17:34:27 +0100920 self.assertEqual(splits, ['yahoo\\\\', 'google', 'facebook\:instagram\\\\', 'bbc\\\\', 'wikipedia'])
921
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100922
923class ParseTestData(TestCase):
924 """
925 Test suite for parse test data.
926 """
927
928 def test_parser(self):
929 """
930 Test that tests are parsed correctly from data file.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100931 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100932 """
933 data = """
934Diffie-Hellman full exchange #1
935dhm_do_dhm:10:"23":10:"5"
936
937Diffie-Hellman full exchange #2
938dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
939
940Diffie-Hellman full exchange #3
941dhm_do_dhm:10:"9345098382739712938719287391879381271":10:"9345098792137312973297123912791271"
942
943Diffie-Hellman selftest
944dhm_selftest:
945"""
946 s = StringIOWrapper('test_suite_ut.function', data)
947 tests = [(name, function, deps, args) for name, function, deps, args in parse_test_data(s)]
948 t1, t2, t3, t4 = tests
949 self.assertEqual(t1[0], 'Diffie-Hellman full exchange #1')
950 self.assertEqual(t1[1], 'dhm_do_dhm')
951 self.assertEqual(t1[2], [])
952 self.assertEqual(t1[3], ['10', '"23"', '10', '"5"'])
953
954 self.assertEqual(t2[0], 'Diffie-Hellman full exchange #2')
955 self.assertEqual(t2[1], 'dhm_do_dhm')
956 self.assertEqual(t2[2], [])
957 self.assertEqual(t2[3], ['10', '"93450983094850938450983409623"', '10', '"9345098304850938450983409622"'])
958
959 self.assertEqual(t3[0], 'Diffie-Hellman full exchange #3')
960 self.assertEqual(t3[1], 'dhm_do_dhm')
961 self.assertEqual(t3[2], [])
962 self.assertEqual(t3[3], ['10', '"9345098382739712938719287391879381271"', '10', '"9345098792137312973297123912791271"'])
963
964 self.assertEqual(t4[0], 'Diffie-Hellman selftest')
965 self.assertEqual(t4[1], 'dhm_selftest')
966 self.assertEqual(t4[2], [])
967 self.assertEqual(t4[3], [])
968
969 def test_with_dependencies(self):
970 """
971 Test that tests with dependencies are parsed.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100972 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +0100973 """
974 data = """
975Diffie-Hellman full exchange #1
976depends_on:YAHOO
977dhm_do_dhm:10:"23":10:"5"
978
979Diffie-Hellman full exchange #2
980dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
981
982"""
983 s = StringIOWrapper('test_suite_ut.function', data)
984 tests = [(name, function, deps, args) for name, function, deps, args in parse_test_data(s)]
985 t1, t2 = tests
986 self.assertEqual(t1[0], 'Diffie-Hellman full exchange #1')
987 self.assertEqual(t1[1], 'dhm_do_dhm')
988 self.assertEqual(t1[2], ['YAHOO'])
989 self.assertEqual(t1[3], ['10', '"23"', '10', '"5"'])
990
991 self.assertEqual(t2[0], 'Diffie-Hellman full exchange #2')
992 self.assertEqual(t2[1], 'dhm_do_dhm')
993 self.assertEqual(t2[2], [])
994 self.assertEqual(t2[3], ['10', '"93450983094850938450983409623"', '10', '"9345098304850938450983409622"'])
995
996 def test_no_args(self):
997 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +0100998 Test GeneratorInputError is raised when test function name and args line is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +0100999 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001000 """
1001 data = """
1002Diffie-Hellman full exchange #1
1003depends_on:YAHOO
1004
1005
1006Diffie-Hellman full exchange #2
1007dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
1008
1009"""
1010 s = StringIOWrapper('test_suite_ut.function', data)
1011 e = None
1012 try:
1013 for x, y, z, a in parse_test_data(s):
1014 pass
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001015 except GeneratorInputError as e:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001016 pass
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001017 self.assertEqual(type(e), GeneratorInputError)
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001018
1019 def test_incomplete_data(self):
1020 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001021 Test GeneratorInputError is raised when test function name and args line is missing.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001022 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001023 """
1024 data = """
1025Diffie-Hellman full exchange #1
1026depends_on:YAHOO
1027"""
1028 s = StringIOWrapper('test_suite_ut.function', data)
1029 e = None
1030 try:
1031 for x, y, z, a in parse_test_data(s):
1032 pass
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001033 except GeneratorInputError as e:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001034 pass
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001035 self.assertEqual(type(e), GeneratorInputError)
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001036
1037
1038class GenDepCheck(TestCase):
1039 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001040 Test suite for gen_dep_check(). It is assumed this function is called with valid inputs.
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001041 """
1042
1043 def test_gen_dep_check(self):
1044 """
1045 Test that dependency check code generated correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001046 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001047 """
1048 expected = """
Azim Khand61b8372017-07-10 11:54:01 +01001049 case 5:
1050 {
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001051#if defined(YAHOO)
Azim Khand61b8372017-07-10 11:54:01 +01001052 ret = DEPENDENCY_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001053#else
Azim Khand61b8372017-07-10 11:54:01 +01001054 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001055#endif
Azim Khand61b8372017-07-10 11:54:01 +01001056 }
1057 break;"""
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001058 out = gen_dep_check(5, 'YAHOO')
1059 self.assertEqual(out, expected)
1060
1061 def test_noT(self):
1062 """
1063 Test dependency with !.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001064 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001065 """
1066 expected = """
Azim Khand61b8372017-07-10 11:54:01 +01001067 case 5:
1068 {
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001069#if !defined(YAHOO)
Azim Khand61b8372017-07-10 11:54:01 +01001070 ret = DEPENDENCY_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001071#else
Azim Khand61b8372017-07-10 11:54:01 +01001072 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001073#endif
Azim Khand61b8372017-07-10 11:54:01 +01001074 }
1075 break;"""
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001076 out = gen_dep_check(5, '!YAHOO')
1077 self.assertEqual(out, expected)
1078
1079 def test_empty_dependency(self):
1080 """
1081 Test invalid dependency input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001082 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001083 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001084 self.assertRaises(GeneratorInputError, gen_dep_check, 5, '!')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001085
1086 def test_negative_dep_id(self):
1087 """
1088 Test invalid dependency input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001089 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001090 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001091 self.assertRaises(GeneratorInputError, gen_dep_check, -1, 'YAHOO')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001092
1093
1094class GenExpCheck(TestCase):
1095 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001096 Test suite for gen_expression_check(). It is assumed this function is called with valid inputs.
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001097 """
1098
1099 def test_gen_exp_check(self):
1100 """
1101 Test that expression check code generated correctly.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001102 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001103 """
1104 expected = """
Azim Khand61b8372017-07-10 11:54:01 +01001105 case 5:
1106 {
1107 *out_value = YAHOO;
1108 }
1109 break;"""
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001110 out = gen_expression_check(5, 'YAHOO')
1111 self.assertEqual(out, expected)
1112
1113 def test_invalid_expression(self):
1114 """
1115 Test invalid expression input.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001116 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001117 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001118 self.assertRaises(GeneratorInputError, gen_expression_check, 5, '')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001119
1120 def test_negative_exp_id(self):
1121 """
1122 Test invalid expression id.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001123 :return:
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001124 """
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001125 self.assertRaises(GeneratorInputError, gen_expression_check, -1, 'YAHOO')
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001126
1127
Azim Khan599cd242017-07-06 17:34:27 +01001128class WriteDeps(TestCase):
1129 """
1130 Test suite for testing write_deps.
1131 """
1132
1133 def test_no_test_deps(self):
1134 """
1135 Test when test_deps is empty.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001136 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001137 """
1138 s = StringIOWrapper('test_suite_ut.data', '')
1139 unique_deps = []
1140 dep_check_code = write_deps(s, [], unique_deps)
1141 self.assertEqual(dep_check_code, '')
1142 self.assertEqual(len(unique_deps), 0)
1143 self.assertEqual(s.getvalue(), '')
1144
1145 def test_unique_dep_ids(self):
1146 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001147
1148 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001149 """
1150 s = StringIOWrapper('test_suite_ut.data', '')
1151 unique_deps = []
1152 dep_check_code = write_deps(s, ['DEP3', 'DEP2', 'DEP1'], unique_deps)
1153 expect_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001154 case 0:
1155 {
Azim Khan599cd242017-07-06 17:34:27 +01001156#if defined(DEP3)
Azim Khand61b8372017-07-10 11:54:01 +01001157 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001158#else
Azim Khand61b8372017-07-10 11:54:01 +01001159 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001160#endif
Azim Khand61b8372017-07-10 11:54:01 +01001161 }
1162 break;
1163 case 1:
1164 {
Azim Khan599cd242017-07-06 17:34:27 +01001165#if defined(DEP2)
Azim Khand61b8372017-07-10 11:54:01 +01001166 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001167#else
Azim Khand61b8372017-07-10 11:54:01 +01001168 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001169#endif
Azim Khand61b8372017-07-10 11:54:01 +01001170 }
1171 break;
1172 case 2:
1173 {
Azim Khan599cd242017-07-06 17:34:27 +01001174#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001175 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001176#else
Azim Khand61b8372017-07-10 11:54:01 +01001177 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001178#endif
Azim Khand61b8372017-07-10 11:54:01 +01001179 }
1180 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001181 self.assertEqual(dep_check_code, expect_dep_check_code)
1182 self.assertEqual(len(unique_deps), 3)
1183 self.assertEqual(s.getvalue(), 'depends_on:0:1:2\n')
1184
1185 def test_dep_id_repeat(self):
1186 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001187
1188 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001189 """
1190 s = StringIOWrapper('test_suite_ut.data', '')
1191 unique_deps = []
1192 dep_check_code = ''
1193 dep_check_code += write_deps(s, ['DEP3', 'DEP2'], unique_deps)
1194 dep_check_code += write_deps(s, ['DEP2', 'DEP1'], unique_deps)
1195 dep_check_code += write_deps(s, ['DEP1', 'DEP3'], unique_deps)
1196 expect_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001197 case 0:
1198 {
Azim Khan599cd242017-07-06 17:34:27 +01001199#if defined(DEP3)
Azim Khand61b8372017-07-10 11:54:01 +01001200 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001201#else
Azim Khand61b8372017-07-10 11:54:01 +01001202 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001203#endif
Azim Khand61b8372017-07-10 11:54:01 +01001204 }
1205 break;
1206 case 1:
1207 {
Azim Khan599cd242017-07-06 17:34:27 +01001208#if defined(DEP2)
Azim Khand61b8372017-07-10 11:54:01 +01001209 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001210#else
Azim Khand61b8372017-07-10 11:54:01 +01001211 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001212#endif
Azim Khand61b8372017-07-10 11:54:01 +01001213 }
1214 break;
1215 case 2:
1216 {
Azim Khan599cd242017-07-06 17:34:27 +01001217#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001218 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001219#else
Azim Khand61b8372017-07-10 11:54:01 +01001220 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001221#endif
Azim Khand61b8372017-07-10 11:54:01 +01001222 }
1223 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001224 self.assertEqual(dep_check_code, expect_dep_check_code)
1225 self.assertEqual(len(unique_deps), 3)
1226 self.assertEqual(s.getvalue(), 'depends_on:0:1\ndepends_on:1:2\ndepends_on:2:0\n')
1227
1228
1229class WriteParams(TestCase):
1230 """
1231 Test Suite for testing write_parameters().
1232 """
1233
1234 def test_no_params(self):
1235 """
1236 Test with empty test_args
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001237 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001238 """
1239 s = StringIOWrapper('test_suite_ut.data', '')
1240 unique_expressions = []
1241 expression_code = write_parameters(s, [], [], unique_expressions)
1242 self.assertEqual(len(unique_expressions), 0)
1243 self.assertEqual(expression_code, '')
1244 self.assertEqual(s.getvalue(), '\n')
1245
1246 def test_no_exp_param(self):
1247 """
1248 Test when there is no macro or expression in the params.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001249 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001250 """
1251 s = StringIOWrapper('test_suite_ut.data', '')
1252 unique_expressions = []
1253 expression_code = write_parameters(s, ['"Yahoo"', '"abcdef00"', '0'], ['char*', 'hex', 'int'],
1254 unique_expressions)
1255 self.assertEqual(len(unique_expressions), 0)
1256 self.assertEqual(expression_code, '')
1257 self.assertEqual(s.getvalue(), ':char*:"Yahoo":hex:"abcdef00":int:0\n')
1258
1259 def test_hex_format_int_param(self):
1260 """
1261 Test int parameter in hex format.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001262 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001263 """
1264 s = StringIOWrapper('test_suite_ut.data', '')
1265 unique_expressions = []
1266 expression_code = write_parameters(s, ['"Yahoo"', '"abcdef00"', '0xAA'], ['char*', 'hex', 'int'],
1267 unique_expressions)
1268 self.assertEqual(len(unique_expressions), 0)
1269 self.assertEqual(expression_code, '')
1270 self.assertEqual(s.getvalue(), ':char*:"Yahoo":hex:"abcdef00":int:0xAA\n')
1271
1272 def test_with_exp_param(self):
1273 """
1274 Test when there is macro or expression in the params.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001275 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001276 """
1277 s = StringIOWrapper('test_suite_ut.data', '')
1278 unique_expressions = []
1279 expression_code = write_parameters(s, ['"Yahoo"', '"abcdef00"', '0', 'MACRO1', 'MACRO2', 'MACRO3'],
1280 ['char*', 'hex', 'int', 'int', 'int', 'int'],
1281 unique_expressions)
1282 self.assertEqual(len(unique_expressions), 3)
1283 self.assertEqual(unique_expressions, ['MACRO1', 'MACRO2', 'MACRO3'])
1284 expected_expression_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001285 case 0:
1286 {
1287 *out_value = MACRO1;
1288 }
1289 break;
1290 case 1:
1291 {
1292 *out_value = MACRO2;
1293 }
1294 break;
1295 case 2:
1296 {
1297 *out_value = MACRO3;
1298 }
1299 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001300 self.assertEqual(expression_code, expected_expression_code)
1301 self.assertEqual(s.getvalue(), ':char*:"Yahoo":hex:"abcdef00":int:0:exp:0:exp:1:exp:2\n')
1302
1303 def test_with_repeate_calls(self):
1304 """
1305 Test when write_parameter() is called with same macro or expression.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001306 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001307 """
1308 s = StringIOWrapper('test_suite_ut.data', '')
1309 unique_expressions = []
1310 expression_code = ''
1311 expression_code += write_parameters(s, ['"Yahoo"', 'MACRO1', 'MACRO2'], ['char*', 'int', 'int'],
1312 unique_expressions)
1313 expression_code += write_parameters(s, ['"abcdef00"', 'MACRO2', 'MACRO3'], ['hex', 'int', 'int'],
1314 unique_expressions)
1315 expression_code += write_parameters(s, ['0', 'MACRO3', 'MACRO1'], ['int', 'int', 'int'],
1316 unique_expressions)
1317 self.assertEqual(len(unique_expressions), 3)
1318 self.assertEqual(unique_expressions, ['MACRO1', 'MACRO2', 'MACRO3'])
1319 expected_expression_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001320 case 0:
1321 {
1322 *out_value = MACRO1;
1323 }
1324 break;
1325 case 1:
1326 {
1327 *out_value = MACRO2;
1328 }
1329 break;
1330 case 2:
1331 {
1332 *out_value = MACRO3;
1333 }
1334 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001335 self.assertEqual(expression_code, expected_expression_code)
1336 expected_data_file = ''':char*:"Yahoo":exp:0:exp:1
1337:hex:"abcdef00":exp:1:exp:2
1338:int:0:exp:2:exp:0
1339'''
1340 self.assertEqual(s.getvalue(), expected_data_file)
1341
1342
1343class GenTestSuiteDepsChecks(TestCase):
1344 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001345
Azim Khan599cd242017-07-06 17:34:27 +01001346 """
1347 def test_empty_suite_deps(self):
1348 """
1349 Test with empty suite_deps list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001350
1351 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001352 """
1353 dep_check_code, expression_code = gen_suite_deps_checks([], 'DEP_CHECK_CODE', 'EXPRESSION_CODE')
1354 self.assertEqual(dep_check_code, 'DEP_CHECK_CODE')
1355 self.assertEqual(expression_code, 'EXPRESSION_CODE')
1356
1357 def test_suite_deps(self):
1358 """
1359 Test with suite_deps list.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001360
1361 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001362 """
1363 dep_check_code, expression_code = gen_suite_deps_checks(['SUITE_DEP'], 'DEP_CHECK_CODE', 'EXPRESSION_CODE')
1364 exprectd_dep_check_code = '''
1365#if defined(SUITE_DEP)
1366DEP_CHECK_CODE
Azim Khan599cd242017-07-06 17:34:27 +01001367#endif
1368'''
1369 expected_expression_code = '''
1370#if defined(SUITE_DEP)
1371EXPRESSION_CODE
Azim Khan599cd242017-07-06 17:34:27 +01001372#endif
1373'''
1374 self.assertEqual(dep_check_code, exprectd_dep_check_code)
1375 self.assertEqual(expression_code, expected_expression_code)
1376
1377 def test_no_dep_no_exp(self):
1378 """
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001379 Test when there are no dependency and expression code.
1380 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001381 """
1382 dep_check_code, expression_code = gen_suite_deps_checks([], '', '')
Azim Khand61b8372017-07-10 11:54:01 +01001383 self.assertEqual(dep_check_code, '')
1384 self.assertEqual(expression_code, '')
Azim Khan599cd242017-07-06 17:34:27 +01001385
1386
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001387class GenFromTestData(TestCase):
1388 """
1389 Test suite for gen_from_test_data()
1390 """
1391
Mohammad Azim Khan78befd92018-03-06 11:49:41 +00001392 @patch("generate_test_code.write_deps")
1393 @patch("generate_test_code.write_parameters")
1394 @patch("generate_test_code.gen_suite_deps_checks")
Azim Khan599cd242017-07-06 17:34:27 +01001395 def test_intermediate_data_file(self, gen_suite_deps_checks_mock, write_parameters_mock, write_deps_mock):
1396 """
1397 Test that intermediate data file is written with expected data.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001398 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001399 """
1400 data = '''
1401My test
1402depends_on:DEP1
1403func1:0
1404'''
1405 data_f = StringIOWrapper('test_suite_ut.data', data)
1406 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
1407 func_info = {'test_func1': (1, ('int',))}
1408 suite_deps = []
1409 write_parameters_mock.side_effect = write_parameters
1410 write_deps_mock.side_effect = write_deps
1411 gen_suite_deps_checks_mock.side_effect = gen_suite_deps_checks
1412 gen_from_test_data(data_f, out_data_f, func_info, suite_deps)
1413 write_deps_mock.assert_called_with(out_data_f, ['DEP1'], ['DEP1'])
1414 write_parameters_mock.assert_called_with(out_data_f, ['0'], ('int',), [])
1415 expected_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001416 case 0:
1417 {
Azim Khan599cd242017-07-06 17:34:27 +01001418#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001419 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001420#else
Azim Khand61b8372017-07-10 11:54:01 +01001421 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001422#endif
Azim Khand61b8372017-07-10 11:54:01 +01001423 }
1424 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001425 gen_suite_deps_checks_mock.assert_called_with(suite_deps, expected_dep_check_code, '')
1426
1427 def test_function_not_found(self):
1428 """
1429 Test that AssertError is raised when function info in not found.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001430 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001431 """
1432 data = '''
1433My test
1434depends_on:DEP1
1435func1:0
1436'''
1437 data_f = StringIOWrapper('test_suite_ut.data', data)
1438 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
1439 func_info = {'test_func2': (1, ('int',))}
1440 suite_deps = []
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001441 self.assertRaises(GeneratorInputError, gen_from_test_data, data_f, out_data_f, func_info, suite_deps)
Azim Khan599cd242017-07-06 17:34:27 +01001442
1443 def test_different_func_args(self):
1444 """
1445 Test that AssertError is raised when no. of parameters and function args differ.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001446 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001447 """
1448 data = '''
1449My test
1450depends_on:DEP1
1451func1:0
1452'''
1453 data_f = StringIOWrapper('test_suite_ut.data', data)
1454 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
1455 func_info = {'test_func2': (1, ('int','hex'))}
1456 suite_deps = []
Mohammad Azim Khan3b06f222018-06-26 14:35:25 +01001457 self.assertRaises(GeneratorInputError, gen_from_test_data, data_f, out_data_f, func_info, suite_deps)
Azim Khan599cd242017-07-06 17:34:27 +01001458
1459 def test_output(self):
1460 """
1461 Test that intermediate data file is written with expected data.
Mohammad Azim Khanb73159d2018-06-13 16:31:26 +01001462 :return:
Azim Khan599cd242017-07-06 17:34:27 +01001463 """
1464 data = '''
1465My test 1
1466depends_on:DEP1
1467func1:0:0xfa:MACRO1:MACRO2
1468
1469My test 2
1470depends_on:DEP1:DEP2
1471func2:"yahoo":88:MACRO1
1472'''
1473 data_f = StringIOWrapper('test_suite_ut.data', data)
1474 out_data_f = StringIOWrapper('test_suite_ut.datax', '')
1475 func_info = {'test_func1': (0, ('int', 'int', 'int', 'int')), 'test_func2': (1, ('char*', 'int', 'int'))}
1476 suite_deps = []
1477 dep_check_code, expression_code = gen_from_test_data(data_f, out_data_f, func_info, suite_deps)
1478 expected_dep_check_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001479 case 0:
1480 {
Azim Khan599cd242017-07-06 17:34:27 +01001481#if defined(DEP1)
Azim Khand61b8372017-07-10 11:54:01 +01001482 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001483#else
Azim Khand61b8372017-07-10 11:54:01 +01001484 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001485#endif
Azim Khand61b8372017-07-10 11:54:01 +01001486 }
1487 break;
1488 case 1:
1489 {
Azim Khan599cd242017-07-06 17:34:27 +01001490#if defined(DEP2)
Azim Khand61b8372017-07-10 11:54:01 +01001491 ret = DEPENDENCY_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001492#else
Azim Khand61b8372017-07-10 11:54:01 +01001493 ret = DEPENDENCY_NOT_SUPPORTED;
Azim Khan599cd242017-07-06 17:34:27 +01001494#endif
Azim Khand61b8372017-07-10 11:54:01 +01001495 }
1496 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001497 expecrted_data = '''My test 1
1498depends_on:0
14990:int:0:int:0xfa:exp:0:exp:1
1500
1501My test 2
1502depends_on:0:1
15031:char*:"yahoo":int:88:exp:0
1504
1505'''
1506 expected_expression_code = '''
Azim Khand61b8372017-07-10 11:54:01 +01001507 case 0:
1508 {
1509 *out_value = MACRO1;
1510 }
1511 break;
1512 case 1:
1513 {
1514 *out_value = MACRO2;
1515 }
1516 break;'''
Azim Khan599cd242017-07-06 17:34:27 +01001517 self.assertEqual(dep_check_code, expected_dep_check_code)
1518 self.assertEqual(out_data_f.getvalue(), expecrted_data)
1519 self.assertEqual(expression_code, expected_expression_code)
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001520
1521
Azim Khan4b543232017-06-30 09:35:21 +01001522if __name__=='__main__':
Azim Khan5e2ac1f2017-07-03 13:58:20 +01001523 unittest_main()