Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
perf-instrumentation
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
safedocs-ta2-profiling
perf-instrumentation
Commits
e2f44c06
Commit
e2f44c06
authored
2 years ago
by
pompolic
Browse files
Options
Downloads
Patches
Plain Diff
Test for .read_member() including HParsedToken* type lookup
parent
52195f66
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gdb-port/tests/unit/ast.py
+29
-5
29 additions, 5 deletions
gdb-port/tests/unit/ast.py
with
29 additions
and
5 deletions
gdb-port/tests/unit/ast.py
+
29
−
5
View file @
e2f44c06
...
@@ -47,13 +47,9 @@ class HParseResultCreation(unittest.TestCase):
...
@@ -47,13 +47,9 @@ class HParseResultCreation(unittest.TestCase):
hpr_pointer_type_patcher
=
unittest
.
mock
.
patch
.
object
(
HParseResult
,
'
HParseResult_t_p
'
,
spec
=
gdb
.
Type
)
hpr_pointer_type_patcher
=
unittest
.
mock
.
patch
.
object
(
HParseResult
,
'
HParseResult_t_p
'
,
spec
=
gdb
.
Type
)
gdbv_patcher
=
unittest
.
mock
.
patch
(
'
gdb.Value
'
,
autospec
=
True
)
gdbv_patcher
=
unittest
.
mock
.
patch
(
'
gdb.Value
'
,
autospec
=
True
)
gdb_lookup_type_patcher
=
unittest
.
mock
.
patch
.
object
(
gdb
,
'
lookup_type
'
)
gdb_lookup_type_patcher
=
unittest
.
mock
.
patch
.
object
(
gdb
,
'
lookup_type
'
)
hpr_ast_not_null_patcher
=
unittest
.
mock
.
patch
.
object
(
HParseResult
,
'
read_AST_not_null
'
,
return_value
=
True
)
hpr_make_hparsedtoken_patcher
=
unittest
.
mock
.
patch
.
object
(
HParseResult
,
'
make_HParsedToken
'
,
spec
=
HParsedToken
)
init_patcher
=
unittest
.
mock
.
patch
.
object
(
HParseResult
,
'
__init__
'
,
return_value
=
None
)
init_patcher
=
unittest
.
mock
.
patch
.
object
(
HParseResult
,
'
__init__
'
,
return_value
=
None
)
hpr_pointer_type_patcher
.
start
()
hpr_pointer_type_patcher
.
start
()
#hpr_ast_not_null_patcher.start()
#hpr_make_hparsedtoken_patcher.start()
gdbv_mock_object
=
gdbv_patcher
.
start
()
gdbv_mock_object
=
gdbv_patcher
.
start
()
gdb_lookup_type_mock_object
=
gdb_lookup_type_patcher
.
start
()
gdb_lookup_type_mock_object
=
gdb_lookup_type_patcher
.
start
()
init_patcher
.
start
()
init_patcher
.
start
()
...
@@ -62,6 +58,11 @@ class HParseResultCreation(unittest.TestCase):
...
@@ -62,6 +58,11 @@ class HParseResultCreation(unittest.TestCase):
result
.
address
=
0xdeadbeef
result
.
address
=
0xdeadbeef
member
=
result
.
read_member
(
'
ast
'
)
member
=
result
.
read_member
(
'
ast
'
)
init_patcher
.
stop
()
gdb_lookup_type_patcher
.
stop
()
gdbv_patcher
.
stop
()
hpr_pointer_type_patcher
.
stop
()
# Check that struct being indexed is at self.address
# Check that struct being indexed is at self.address
self
.
assertEqual
(
gdbv_mock_object
.
mock_calls
[
0
],
unittest
.
mock
.
call
(
0xdeadbeef
))
self
.
assertEqual
(
gdbv_mock_object
.
mock_calls
[
0
],
unittest
.
mock
.
call
(
0xdeadbeef
))
# Check that the value returned is parse_result_gdb_value['foo']
# Check that the value returned is parse_result_gdb_value['foo']
...
@@ -71,7 +72,30 @@ class HParseResultCreation(unittest.TestCase):
...
@@ -71,7 +72,30 @@ class HParseResultCreation(unittest.TestCase):
def
test_read_member_with_type_lookup
(
self
):
def
test_read_member_with_type_lookup
(
self
):
gdb_lookup_type_patcher
=
unittest
.
mock
.
patch
.
object
(
gdb
,
'
lookup_type
'
)
gdb_lookup_type_patcher
=
unittest
.
mock
.
patch
.
object
(
gdb
,
'
lookup_type
'
)
raise
Exception
(
"
Not implemented
"
)
gdbv_patcher
=
unittest
.
mock
.
patch
(
'
gdb.Value
'
,
autospec
=
True
)
init_patcher
=
unittest
.
mock
.
patch
.
object
(
HParseResult
,
'
__init__
'
,
return_value
=
None
)
# This is cached in the class the first time read_member() or read_AST_not_null() is called
# To test the case where it's not yet cached, we explicitly set it to None
HParseResult
.
HParseResult_t_p
=
None
gdb_lookup_type_mock_object
=
gdb_lookup_type_patcher
.
start
()
gdbv_mock_object
=
gdbv_patcher
.
start
()
init_patcher
.
start
()
result
=
HParseResult
(
0xdeadbeef
)
result
.
address
=
0xdeadbeef
member
=
result
.
read_member
(
'
ast
'
)
init_patcher
.
stop
()
gdbv_patcher
.
stop
()
gdb_lookup_type_patcher
.
stop
()
# Check that HParseResult* has been looked up
self
.
assertEqual
(
gdb_lookup_type_mock_object
.
mock_calls
,
[
unittest
.
mock
.
call
(
'
HParseResult
'
),
unittest
.
mock
.
call
().
pointer
()])
# Check that the struct being indexed is at self.address
self
.
assertEqual
(
gdbv_mock_object
.
mock_calls
[
0
],
unittest
.
mock
.
call
(
0xdeadbeef
))
# Check that the value returned is parse_result_gdb_value['foo']
self
.
assertEqual
(
gdbv_mock_object
.
mock_calls
[
-
1
],
unittest
.
mock
.
call
().
cast
().
__getitem__
(
'
ast
'
))
# TODO: should read_member employ a whitelist for member_name, or should this trigger an exeption?
# TODO: should read_member employ a whitelist for member_name, or should this trigger an exeption?
def
test_read_member_invalid_param
(
self
):
def
test_read_member_invalid_param
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment