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 
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()
def test_case0(self)
Definition: test_Guard.py:52


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34