Main Page
Namespaces
Classes
Files
File List
OpenRTM_aist
test
test_Guard.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# -*- Python -*-
3
4
#
5
# \file test_Guard.py
6
# \brief test for Guard class
7
# \date $Date: 2007/09/18 $
8
# \author Shinji Kurihara
9
#
10
# Copyright (C) 2006
11
# Task-intelligence Research Group,
12
# Intelligent Systems Research Institute,
13
# National Institute of
14
# Advanced Industrial Science and Technology (AIST), Japan
15
# All rights reserved.
16
#
17
18
import
sys, time
19
sys.path.insert(1,
"../"
)
20
21
import
unittest
22
import
threading
23
from
Guard
import
*
24
from
Task
import
*
25
26
ShareCount = 0
27
28
class
TestGuardTask
(
Task
):
29
def
__init__
(self):
30
global
ShareCount
31
self.
ShareCount
= 1
32
Task.__init__(self)
33
self.
flag
=
False
34
self.
_mutex
= threading.RLock()
35
36
def
svc
(self):
37
global
ShareCount
38
guard = ScopedLock(self.
_mutex
)
39
for
i
in
range(100):
40
ShareCount += 1
41
time.sleep(0.1)
42
self.
ShareCount
= ShareCount
43
return
44
45
def
getShareCount
(self):
46
return
self.
ShareCount
47
48
class
TestGuard
(unittest.TestCase):
49
def
setUp
(self):
50
return
51
52
def
test_case0
(self):
53
task1 =
TestGuardTask
()
54
task2 =
TestGuardTask
()
55
task1.activate()
56
task2.activate()
57
task1.wait()
58
task2.wait()
59
count = task1.getShareCount()
60
self.assertEqual(count, 200)
61
count = task2.getShareCount()
62
self.assertEqual(count, 200)
63
task2.finalize()
64
task1.finalize()
65
return
66
67
68
69
############### test #################
70
if
__name__ ==
'__main__'
:
71
unittest.main()
test_Guard.TestGuard
Definition:
test_Guard.py:48
Task
test_Guard.TestGuardTask.getShareCount
def getShareCount(self)
Definition:
test_Guard.py:45
test_Guard.TestGuard.test_case0
def test_case0(self)
Definition:
test_Guard.py:52
test_Guard.TestGuardTask
Definition:
test_Guard.py:28
test_Guard.TestGuardTask._mutex
_mutex
Definition:
test_Guard.py:34
test_Guard.TestGuardTask.__init__
def __init__(self)
Definition:
test_Guard.py:29
test_Guard.TestGuardTask.ShareCount
ShareCount
Definition:
test_Guard.py:31
test_Guard.TestGuardTask.svc
def svc(self)
Definition:
test_Guard.py:36
test_Guard.TestGuardTask.flag
flag
Definition:
test_Guard.py:33
test_Guard.TestGuard.setUp
def setUp(self)
Definition:
test_Guard.py:49
openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34