Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mbedtls
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BC
public
external
mbedtls
Commits
b5229296
Commit
b5229296
authored
Feb 06, 2018
by
Mohammad Azim Khan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for per test suite helper functions
parent
05d83fa4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
21 deletions
+53
-21
.gitignore
.gitignore
+3
-0
generate_code.py
tests/scripts/generate_code.py
+14
-6
generate_code_ut.py
tests/scripts/generate_code_ut.py
+36
-15
No files found.
.gitignore
View file @
b5229296
...
...
@@ -21,5 +21,8 @@ massif-*
*.ilk
*.lib
# Python build artifacts:
*.pyc
# CMake generates *.dir/ folders for in-tree builds (used by MSVC projects), ignore all of those:
*.dir/
tests/scripts/generate_code.py
View file @
b5229296
...
...
@@ -42,6 +42,9 @@ import shutil
BEGIN_HEADER_REGEX
=
'/
\
*
\
s*BEGIN_HEADER
\
s*
\
*/'
END_HEADER_REGEX
=
'/
\
*
\
s*END_HEADER
\
s*
\
*/'
BEGIN_SUITE_HELPERS_REGEX
=
'/
\
*
\
s*BEGIN_SUITE_HELPERS
\
s*
\
*/'
END_SUITE_HELPERS_REGEX
=
'/
\
*
\
s*END_SUITE_HELPERS
\
s*
\
*/'
BEGIN_DEP_REGEX
=
'BEGIN_DEPENDENCIES'
END_DEP_REGEX
=
'END_DEPENDENCIES'
...
...
@@ -172,20 +175,21 @@ def gen_dispatch(name, deps):
return
dispatch_code
def
parse_
suite_headers
(
funcs_f
):
def
parse_
until_pattern
(
funcs_f
,
end_regex
):
"""
Parses function headers.
Parses function headers
or helper code until end pattern
.
:param funcs_f: file object for .functions file
:param end_regex: Pattern to stop parsing
:return: Test suite headers code
"""
headers
=
'#line
%
d "
%
s"
\n
'
%
(
funcs_f
.
line_no
+
1
,
funcs_f
.
name
)
for
line
in
funcs_f
:
if
re
.
search
(
END_HEADER_REGEX
,
line
):
if
re
.
search
(
end_regex
,
line
):
break
headers
+=
line
else
:
raise
InvalidFileFormat
(
"file:
%
s - end
header pattern [
%
s] not found!"
%
(
funcs_f
.
name
,
END_HEADER_REGEX
))
raise
InvalidFileFormat
(
"file:
%
s - end
pattern [
%
s] not found!"
%
(
funcs_f
.
name
,
end_regex
))
return
headers
...
...
@@ -325,6 +329,7 @@ def parse_functions(funcs_f):
a dict with function identifiers and arguments info.
"""
suite_headers
=
''
suite_helpers
=
''
suite_deps
=
[]
suite_functions
=
''
func_info
=
{}
...
...
@@ -332,8 +337,11 @@ def parse_functions(funcs_f):
dispatch_code
=
''
for
line
in
funcs_f
:
if
re
.
search
(
BEGIN_HEADER_REGEX
,
line
):
headers
=
parse_
suite_headers
(
funcs_f
)
headers
=
parse_
until_pattern
(
funcs_f
,
END_HEADER_REGEX
)
suite_headers
+=
headers
elif
re
.
search
(
BEGIN_SUITE_HELPERS_REGEX
,
line
):
helpers
=
parse_until_pattern
(
funcs_f
,
END_SUITE_HELPERS_REGEX
)
suite_helpers
+=
helpers
elif
re
.
search
(
BEGIN_DEP_REGEX
,
line
):
deps
=
parse_suite_deps
(
funcs_f
)
suite_deps
+=
deps
...
...
@@ -350,7 +358,7 @@ def parse_functions(funcs_f):
function_idx
+=
1
ifdef
,
endif
=
gen_deps
(
suite_deps
)
func_code
=
ifdef
+
suite_headers
+
suite_functions
+
endif
func_code
=
ifdef
+
suite_headers
+
suite_
helpers
+
suite_
functions
+
endif
return
suite_deps
,
dispatch_code
,
func_code
,
func_info
...
...
tests/scripts/generate_code_ut.py
View file @
b5229296
...
...
@@ -280,9 +280,9 @@ class StringIOWrapper(StringIO, object):
return
line
class
Parse
SuiteHeaders
(
TestCase
):
class
Parse
UntilPattern
(
TestCase
):
"""
Test Suite for testing parse_
suite_headers
().
Test Suite for testing parse_
until_pattern
().
"""
def
test_suite_headers
(
self
):
...
...
@@ -302,7 +302,7 @@ class ParseSuiteHeaders(TestCase):
#define ECP_PF_UNKNOWN -1
'''
s
=
StringIOWrapper
(
'test_suite_ut.function'
,
data
,
line_no
=
0
)
headers
=
parse_
suite_headers
(
s
)
headers
=
parse_
until_pattern
(
s
,
END_HEADER_REGEX
)
self
.
assertEqual
(
headers
,
expected
)
def
test_line_no
(
self
):
...
...
@@ -323,7 +323,7 @@ class ParseSuiteHeaders(TestCase):
#define ECP_PF_UNKNOWN -1
'''
%
(
offset_line_no
+
1
)
s
=
StringIOWrapper
(
'test_suite_ut.function'
,
data
,
offset_line_no
)
headers
=
parse_
suite_headers
(
s
)
headers
=
parse_
until_pattern
(
s
,
END_HEADER_REGEX
)
self
.
assertEqual
(
headers
,
expected
)
def
test_no_end_header_comment
(
self
):
...
...
@@ -337,7 +337,7 @@ class ParseSuiteHeaders(TestCase):
'''
s
=
StringIOWrapper
(
'test_suite_ut.function'
,
data
)
self
.
assertRaises
(
InvalidFileFormat
,
parse_
suite_headers
,
s
)
self
.
assertRaises
(
InvalidFileFormat
,
parse_
until_pattern
,
s
,
END_HEADER_REGEX
)
class
ParseSuiteDeps
(
TestCase
):
...
...
@@ -620,15 +620,15 @@ class ParseFunction(TestCase):
Test Suite for testing parse_functions()
"""
@
patch
(
"generate_code.parse_
suite_headers
"
)
def
test_begin_header
(
self
,
parse_
suite_headers
_mock
):
@
patch
(
"generate_code.parse_
until_pattern
"
)
def
test_begin_header
(
self
,
parse_
until_pattern
_mock
):
"""
Test that begin header is checked and parse_
suite_headers
() is called.
Test that begin header is checked and parse_
until_pattern
() is called.
:return:
"""
def
stop
(
this
):
raise
Exception
parse_
suite_headers
_mock
.
side_effect
=
stop
parse_
until_pattern
_mock
.
side_effect
=
stop
data
=
'''/* BEGIN_HEADER */
#include "mbedtls/ecp.h"
...
...
@@ -637,13 +637,34 @@ class ParseFunction(TestCase):
'''
s
=
StringIOWrapper
(
'test_suite_ut.function'
,
data
)
self
.
assertRaises
(
Exception
,
parse_functions
,
s
)
parse_suite_headers_mock
.
assert_called_with
(
s
)
parse_until_pattern_mock
.
assert_called_with
(
s
,
END_HEADER_REGEX
)
self
.
assertEqual
(
s
.
line_no
,
2
)
@
patch
(
"generate_code.parse_until_pattern"
)
def
test_begin_helper
(
self
,
parse_until_pattern_mock
):
"""
Test that begin helper is checked and parse_until_pattern() is called.
:return:
"""
def
stop
(
this
):
raise
Exception
parse_until_pattern_mock
.
side_effect
=
stop
data
=
'''/* BEGIN_SUITE_HELPERS */
void print_helloworld()
{
printf ("Hello World!
\n
");
}
/* END_SUITE_HELPERS */
'''
s
=
StringIOWrapper
(
'test_suite_ut.function'
,
data
)
self
.
assertRaises
(
Exception
,
parse_functions
,
s
)
parse_until_pattern_mock
.
assert_called_with
(
s
,
END_SUITE_HELPERS_REGEX
)
self
.
assertEqual
(
s
.
line_no
,
2
)
@
patch
(
"generate_code.parse_suite_deps"
)
def
test_begin_dep
(
self
,
parse_suite_deps_mock
):
"""
Test that begin
header is checked and parse_suite_header
s() is called.
Test that begin
dep is checked and parse_suite_dep
s() is called.
:return:
"""
def
stop
(
this
):
...
...
@@ -662,7 +683,7 @@ class ParseFunction(TestCase):
@
patch
(
"generate_code.parse_function_deps"
)
def
test_begin_function_dep
(
self
,
parse_function_deps_mock
):
"""
Test that begin
header is checked and parse_suite_header
s() is called.
Test that begin
dep is checked and parse_function_dep
s() is called.
:return:
"""
def
stop
(
this
):
...
...
@@ -683,7 +704,7 @@ class ParseFunction(TestCase):
@
patch
(
"generate_code.parse_function_deps"
)
def
test_return
(
self
,
parse_function_deps_mock
,
parse_function_code_mock
):
"""
Test that begin
header is checked and parse_suite_headers
() is called.
Test that begin
case is checked and parse_function_code
() is called.
:return:
"""
def
stop
(
this
):
...
...
@@ -718,7 +739,7 @@ class ParseFunction(TestCase):
def
test_parsing
(
self
):
"""
Test
that begin header is checked and parse_suite_headers() is called
.
Test
case parsing
.
:return:
"""
data
=
'''/* BEGIN_HEADER */
...
...
@@ -811,7 +832,7 @@ void test_func2_wrapper( void ** params )
def
test_same_function_name
(
self
):
"""
Test
that begin header is checked and parse_suite_headers() is called
.
Test
name conflict
.
:return:
"""
data
=
'''/* BEGIN_HEADER */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment