Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
efe6982b
Commit
efe6982b
authored
Jul 09, 2019
by
gsamain
Committed by
Xavier Thompson
Aug 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Checklock unit test
parent
09802d7a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
+109
-0
tests/errors/cypclass_lock_error.pyx
tests/errors/cypclass_lock_error.pyx
+35
-0
tests/run/cypclass_lock.pyx
tests/run/cypclass_lock.pyx
+74
-0
No files found.
tests/errors/cypclass_lock_error.pyx
0 → 100644
View file @
efe6982b
# mode: error
# tag: cpp, cpp11, pthread
# cython: experimental_cpp_class_def=True, language_level=2
cdef
cypclass
A
checklock
:
int
a
int
getter
(
self
)
const
:
return
self
.
a
void
setter
(
self
,
int
a
):
self
.
a
=
a
cdef
void
take_write_locked
(
A
obj
):
pass
cdef
int
take_read_locked
(
const
A
obj
):
return
3
def
incorrect_locks
():
obj
=
A
()
obj
.
a
=
3
obj
.
getter
()
with
rlocked
obj
:
obj
.
setter
(
42
)
take_write_locked
(
obj
)
obj
.
a
take_read_locked
(
obj
)
_ERRORS
=
u"""
20:4: This expression is not correctly locked (write lock needed)
21:4: This expression is not correctly locked (read lock needed)
23:8: This expression is not correctly locked (write lock needed)
24:26: This expression is not correctly locked (write lock needed)
25:4: This expression is not correctly locked (read lock needed)
26:21: This expression is not correctly locked (read lock needed)
"""
tests/run/cypclass_lock.pyx
0 → 100644
View file @
efe6982b
# mode: run
# tag: cpp, cpp11, pthread
# cython: experimental_cpp_class_def=True, language_level=2
cdef
cypclass
A
checklock
:
int
a
__init__
(
self
):
self
.
a
=
0
int
getter
(
self
)
const
:
return
self
.
a
void
setter
(
self
,
int
a
):
self
.
a
=
a
def
test_basic_locking
():
"""
>>> test_basic_locking()
0
"""
obj
=
A
()
with
rlocked
obj
:
print
obj
.
getter
()
cdef
argument_recursivity
(
A
obj
,
int
arg
):
if
arg
>
0
:
obj
.
setter
(
obj
.
getter
()
+
1
)
argument_recursivity
(
obj
,
arg
-
1
)
def
test_argument_recursivity
(
n
):
"""
>>> test_argument_recursivity(42)
42
"""
obj
=
A
()
with
wlocked
obj
:
argument_recursivity
(
obj
,
n
)
print
obj
.
a
cdef
A
global_cyobject
cdef
init_global_cyobject
():
global
global_cyobject
global_cyobject
=
A
()
cdef
void
recursive_lock_taking
(
int
arg
):
global
global_cyobject
if
arg
>
0
:
with
wlocked
global_cyobject
:
global_cyobject
.
setter
(
global_cyobject
.
getter
()
+
1
)
recursive_lock_taking
(
arg
-
1
)
def
test_recursive_side_effect_locking
(
n
):
"""
>>> test_recursive_side_effect_locking(42)
42
"""
init_global_cyobject
()
recursive_lock_taking
(
42
)
with
rlocked
global_cyobject
:
print
global_cyobject
.
getter
()
cdef
cypclass
Container
:
A
object
__init__
(
self
):
self
.
object
=
A
()
def
test_lock_traversal
(
n
):
"""
>>> test_lock_traversal(42)
42
"""
container
=
Container
()
with
rlocked
container
,
wlocked
container
.
object
:
argument_recursivity
(
container
.
object
,
n
)
print
container
.
object
.
getter
()
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