Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate static test functions & wrappers #23

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scripts/generate_test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def gen_function_wrapper(name, local_vars, args_dispatch):
"""
# Then create the wrapper
wrapper = '''
void {name}_wrapper( void ** params )
static void {name}_wrapper( void ** params )
{{
{unused_params}{locals}
{name}( {args} );
Expand Down Expand Up @@ -651,6 +651,9 @@ def parse_function_code(funcs_f, dependencies, suite_dependencies):
raise GeneratorInputError("file: %s - Test functions not found!" %
funcs_f.name)

# Make the test function static
code = code.replace('void', 'static void', 1)
minosgalanakis marked this conversation as resolved.
Show resolved Hide resolved

# Prefix test function name with 'test_'
code = code.replace(name, 'test_' + name, 1)
name = 'test_' + name
Expand Down
36 changes: 18 additions & 18 deletions scripts/test_generate_test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_params_unpack(self):
"""
code = gen_function_wrapper('test_a', '', ('a', 'b', 'c', 'd'))
expected = '''
void test_a_wrapper( void ** params )
static void test_a_wrapper( void ** params )
{

test_a( a, b, c, d );
Expand All @@ -211,7 +211,7 @@ def test_local(self):
code = gen_function_wrapper('test_a',
'int x = 1;', ('x', 'b', 'c', 'd'))
expected = '''
void test_a_wrapper( void ** params )
static void test_a_wrapper( void ** params )
{
int x = 1;
test_a( x, b, c, d );
Expand All @@ -227,7 +227,7 @@ def test_empty_params(self):
"""
code = gen_function_wrapper('test_a', '', ())
expected = '''
void test_a_wrapper( void ** params )
static void test_a_wrapper( void ** params )
{
(void)params;

Expand Down Expand Up @@ -635,7 +635,7 @@ def test_return(self, parse_function_arguments_mock,
self.assertEqual(arg, [])
expected = '''#line 1 "test_suite_ut.function"

void test_func(void)
static void test_func(void)
{
ba ba black sheep
have you any wool
Expand Down Expand Up @@ -678,7 +678,7 @@ def test_with_exit_label(self, parse_function_arguments_mock,

expected = '''#line 1 "test_suite_ut.function"

void test_func(void)
static void test_func(void)
{
ba ba black sheep
have you any wool
Expand Down Expand Up @@ -735,7 +735,7 @@ def test_function_name_on_newline(self, parse_function_arguments_mock,

expected = '''#line 1 "test_suite_ut.function"

void
static void


test_func(void)
Expand Down Expand Up @@ -791,7 +791,7 @@ def test_case_starting_with_comment(self, parse_function_arguments_mock,



void test_func(void)
static void test_func(void)
{
ba ba black sheep
have you any wool
Expand Down Expand Up @@ -836,7 +836,7 @@ def test_comment_in_prototype(self, parse_function_arguments_mock,

expected = '''#line 1 "test_suite_ut.function"

void test_func( int x,
static void test_func( int x,

int y )
{
Expand Down Expand Up @@ -881,7 +881,7 @@ def test_line_comment_in_block_comment(self, parse_function_arguments_mock,

expected = '''#line 1 "test_suite_ut.function"

void test_func( int x )
static void test_func( int x )
{
ba ba black sheep
have you any wool
Expand Down Expand Up @@ -926,7 +926,7 @@ def test_block_comment_in_line_comment(self, parse_function_arguments_mock,
expected = '''#line 1 "test_suite_ut.function"


void test_func( int x )
static void test_func( int x )
{
ba ba black sheep
have you any wool
Expand Down Expand Up @@ -975,7 +975,7 @@ def stop(*_unused):
raise Exception
parse_until_pattern_mock.side_effect = stop
data = '''/* BEGIN_SUITE_HELPERS */
void print_hello_world()
static void print_hello_world()
{
printf("Hello World!\n");
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@ def stop(*_unused):

dependencies_str = '/* BEGIN_CASE ' \
'depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */\n'
data = '''%svoid test_func()
data = '''%sstatic void test_func()
{
}
''' % dependencies_str
Expand All @@ -1039,7 +1039,7 @@ def test_return(self, func_mock1, func_mock2):
:return:
"""
func_mock1.return_value = []
in_func_code = '''void test_func()
in_func_code = '''static void test_func()
{
}
'''
Expand All @@ -1050,7 +1050,7 @@ def test_return(self, func_mock1, func_mock2):
in_func_code, func_dispatch
dependencies_str = '/* BEGIN_CASE ' \
'depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */\n'
data = '''%svoid test_func()
data = '''%sstatic void test_func()
{
}
''' % dependencies_str
Expand Down Expand Up @@ -1127,13 +1127,13 @@ def test_parsing(self):
#if defined(MBEDTLS_ENTROPY_NV_SEED)
#if defined(MBEDTLS_FS_IO)
#line 13 "test_suite_ut.function"
void test_func1(void)
static void test_func1(void)
{
exit:
;
}

void test_func1_wrapper( void ** params )
static void test_func1_wrapper( void ** params )
{
(void)params;

Expand All @@ -1144,13 +1144,13 @@ def test_parsing(self):
#if defined(MBEDTLS_ENTROPY_NV_SEED)
#if defined(MBEDTLS_FS_IO)
#line 19 "test_suite_ut.function"
void test_func2(void)
static void test_func2(void)
{
exit:
;
}

void test_func2_wrapper( void ** params )
static void test_func2_wrapper( void ** params )
{
(void)params;

Expand Down