mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-04 15:39:53 +00:00
Support (void) as an argument list of a test function
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
096f0ca7e5
commit
47e2e8817d
@ -457,8 +457,6 @@ def parse_function_argument(arg, arg_idx, args, local_vars, args_dispatch):
|
|||||||
or None if the argument declaration is invalid.
|
or None if the argument declaration is invalid.
|
||||||
"""
|
"""
|
||||||
arg = arg.strip()
|
arg = arg.strip()
|
||||||
if arg == '':
|
|
||||||
return 0
|
|
||||||
if re.search(INT_CHECK_REGEX, arg.strip()):
|
if re.search(INT_CHECK_REGEX, arg.strip()):
|
||||||
args.append('int')
|
args.append('int')
|
||||||
args_dispatch.append('((mbedtls_test_argument_t*)params[%d])->s32' % arg_idx)
|
args_dispatch.append('((mbedtls_test_argument_t*)params[%d])->s32' % arg_idx)
|
||||||
@ -478,6 +476,7 @@ def parse_function_argument(arg, arg_idx, args, local_vars, args_dispatch):
|
|||||||
return 2
|
return 2
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
ARGUMENT_LIST_REGEX = re.compile(r'\((.*?)\)', re.S)
|
||||||
def parse_function_arguments(line):
|
def parse_function_arguments(line):
|
||||||
"""
|
"""
|
||||||
Parses test function signature for validation and generates
|
Parses test function signature for validation and generates
|
||||||
@ -489,17 +488,19 @@ def parse_function_arguments(line):
|
|||||||
:return: argument list, local variables for
|
:return: argument list, local variables for
|
||||||
wrapper function and argument dispatch code.
|
wrapper function and argument dispatch code.
|
||||||
"""
|
"""
|
||||||
args = []
|
|
||||||
local_vars = []
|
|
||||||
args_dispatch = []
|
|
||||||
arg_idx = 0
|
|
||||||
# Remove characters before arguments
|
|
||||||
line = line[line.find('(') + 1:]
|
|
||||||
# Process arguments, ex: <type> arg1, <type> arg2 )
|
# Process arguments, ex: <type> arg1, <type> arg2 )
|
||||||
# This script assumes that the argument list is terminated by ')'
|
# This script assumes that the argument list is terminated by ')'
|
||||||
# i.e. the test functions will not have a function pointer
|
# i.e. the test functions will not have a function pointer
|
||||||
# argument.
|
# argument.
|
||||||
for arg in line[:line.find(')')].split(','):
|
m = ARGUMENT_LIST_REGEX.search(line)
|
||||||
|
arg_list = m.group(1).strip()
|
||||||
|
if arg_list in ['', 'void']:
|
||||||
|
return [], '', []
|
||||||
|
args = []
|
||||||
|
local_vars = []
|
||||||
|
args_dispatch = []
|
||||||
|
arg_idx = 0
|
||||||
|
for arg in arg_list.split(','):
|
||||||
indexes = parse_function_argument(arg, arg_idx,
|
indexes = parse_function_argument(arg, arg_idx,
|
||||||
args, local_vars, args_dispatch)
|
args, local_vars, args_dispatch)
|
||||||
if indexes is None:
|
if indexes is None:
|
||||||
|
@ -513,9 +513,9 @@ class ParseFuncSignature(TestCase):
|
|||||||
line = 'void entropy_threshold( char * a, data_t * h, char result )'
|
line = 'void entropy_threshold( char * a, data_t * h, char result )'
|
||||||
self.assertRaises(ValueError, parse_function_arguments, line)
|
self.assertRaises(ValueError, parse_function_arguments, line)
|
||||||
|
|
||||||
def test_no_params(self):
|
def test_empty_params(self):
|
||||||
"""
|
"""
|
||||||
Test no parameters.
|
Test no parameters (nothing between parentheses).
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
line = 'void entropy_threshold()'
|
line = 'void entropy_threshold()'
|
||||||
@ -524,6 +524,39 @@ class ParseFuncSignature(TestCase):
|
|||||||
self.assertEqual(local, '')
|
self.assertEqual(local, '')
|
||||||
self.assertEqual(arg_dispatch, [])
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
def test_blank_params(self):
|
||||||
|
"""
|
||||||
|
Test no parameters (space between parentheses).
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
line = 'void entropy_threshold( )'
|
||||||
|
args, local, arg_dispatch = parse_function_arguments(line)
|
||||||
|
self.assertEqual(args, [])
|
||||||
|
self.assertEqual(local, '')
|
||||||
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
def test_void_params(self):
|
||||||
|
"""
|
||||||
|
Test no parameters (void keyword).
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
line = 'void entropy_threshold(void)'
|
||||||
|
args, local, arg_dispatch = parse_function_arguments(line)
|
||||||
|
self.assertEqual(args, [])
|
||||||
|
self.assertEqual(local, '')
|
||||||
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
def test_void_space_params(self):
|
||||||
|
"""
|
||||||
|
Test no parameters (void with spaces).
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
line = 'void entropy_threshold( void )'
|
||||||
|
args, local, arg_dispatch = parse_function_arguments(line)
|
||||||
|
self.assertEqual(args, [])
|
||||||
|
self.assertEqual(local, '')
|
||||||
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
|
||||||
class ParseFunctionCode(TestCase):
|
class ParseFunctionCode(TestCase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user