Guest User

Untitled

a guest
Jun 18th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. Index: repy/tests/rz_restrictions.oneevent_initandexitareevents.py
  2. ===================================================================
  3. --- repy/tests/rz_restrictions.oneevent_initandexitareevents.py (revision 0)
  4. +++ repy/tests/rz_restrictions.oneevent_initandexitareevents.py (revision 0)
  5. @@ -0,0 +1,11 @@
  6. +# a test to see if the event used by the initialize thread is counted
  7. +
  8. +# One thread for this code
  9. +if callfunc == 'initialize':
  10. + # One event is fine
  11. + pass
  12. +
  13. +if callfunc == 'exit':
  14. + # Exit code should be ok, because exit and initialize don't run at the
  15. + # same time
  16. + pass
  17. Index: repy/tests/re_restrictions.oneevent_eventsarelimitedinit.py
  18. ===================================================================
  19. --- repy/tests/re_restrictions.oneevent_eventsarelimitedinit.py (revision 0)
  20. +++ repy/tests/re_restrictions.oneevent_eventsarelimitedinit.py (revision 0)
  21. @@ -0,0 +1,11 @@
  22. +# More than one event is not allowed:
  23. +
  24. +def foo():
  25. + pass
  26. +
  27. +def do_some_stuff():
  28. + pass
  29. +
  30. +if callfunc == 'initialize':
  31. + settimer(1,foo,[])
  32. + do_some_stuff()
  33. Index: repy/tests/restrictions.oneevent
  34. ===================================================================
  35. --- repy/tests/restrictions.oneevent (revision 0)
  36. +++ repy/tests/restrictions.oneevent (revision 0)
  37. @@ -0,0 +1,54 @@
  38. +resource cpu .50
  39. +resource memory 15000000 # 15 Million bytes
  40. +resource diskused 10000000 # 10 MB
  41. +resource events 1
  42. +resource filewrite 10000
  43. +resource fileread 10000
  44. +resource filesopened 5
  45. +resource insockets 5
  46. +resource outsockets 5
  47. +resource netsend 10000
  48. +resource netrecv 10000
  49. +resource loopsend 1000000
  50. +resource looprecv 1000000
  51. +resource lograte 1000
  52. +resource messport 12345
  53. +resource messport 12346
  54. +resource messport 12347
  55. +resource connport 12345
  56. +resource connport 12346
  57. +resource connport 12347
  58. +
  59. +call gethostbyname_ex allow
  60. +call sendmess allow
  61. +call stopcomm allow # it doesn't make sense to restrict
  62. +call recvmess allow
  63. +call openconn allow
  64. +call waitforconn allow
  65. +call socket.close allow # let's not restrict
  66. +call socket.send allow # let's not restrict
  67. +call socket.recv allow # let's not restrict
  68. +# open and file.__init__ both have built in restrictions...
  69. +call open arg 0 is junk_test.out allow # can write to junk_test.out
  70. +call open arg 1 is r allow # allow an explicit read
  71. +call open noargs is 1 allow # allow an implicit read
  72. +call file.__init__ arg 0 is junk_test.out allow # can write to junk_test.out
  73. +call file.__init__ arg 1 is r allow # allow an explicit read
  74. +call file.__init__ noargs is 1 allow # allow an implicit read
  75. +call file.close allow # shouldn't restrict
  76. +call file.flush allow # they are free to use
  77. +call file.next allow # free to use as well...
  78. +call file.read allow # allow read
  79. +call file.readline allow # shouldn't restrict
  80. +call file.readlines allow # shouldn't restrict
  81. +call file.seek allow # seek doesn't restrict
  82. +call file.write allow # shouldn't restrict (open restricts)
  83. +call file.writelines allow # shouldn't restrict (open restricts)
  84. +call sleep allow # harmless
  85. +call settimer allow # we can't really do anything smart
  86. +call canceltimer allow # should be okay
  87. +call exitall allow # should be harmless
  88. +
  89. +call log.write allow
  90. +call log.writelines allow
  91. +call getmyip allow
  92.  
  93. Property changes on: repy/tests/restrictions.oneevent
  94. ___________________________________________________________________
  95. Added: svn:executable
  96. + *
  97.  
  98. Index: repy/tests/re_restrictions.oneevent_eventsarelimitedexit.py
  99. ===================================================================
  100. --- repy/tests/re_restrictions.oneevent_eventsarelimitedexit.py (revision 0)
  101. +++ repy/tests/re_restrictions.oneevent_eventsarelimitedexit.py (revision 0)
  102. @@ -0,0 +1,11 @@
  103. +# More than one event is not allowed:
  104. +
  105. +def foo():
  106. + pass
  107. +
  108. +def do_some_stuff():
  109. + pass
  110. +
  111. +if callfunc == 'exit':
  112. + settimer(1,foo,[])
  113. + do_some_stuff()
  114. Index: repy/repy.py
  115. ===================================================================
  116. --- repy/repy.py (revision 2186)
  117. +++ repy/repy.py (working copy)
  118. @@ -49,6 +49,8 @@
  119. import emultimer
  120. import emulcomm
  121. import emulmisc
  122. +import idhelper
  123. +import nanny
  124. import restrictions
  125. import time
  126. import threading
  127. @@ -198,7 +200,17 @@
  128. # call the initialize function
  129. usercontext['callfunc'] = 'initialize'
  130. usercontext['callargs'] = args[:]
  131. +
  132. try:
  133. + initialize_id = idhelper.getuniqueid()
  134. + nanny.tattle_add_item('events', initialize_id)
  135. + except Exception, e:
  136. + print "Failed to allocate event for 'initialize' callfunc"
  137. + print "Failure:"
  138. + print e
  139. + tracebackrepy.handle_exception()
  140. +
  141. + try:
  142. safe.safe_exec(usercode,usercontext)
  143. except SystemExit:
  144. raise
  145. @@ -206,7 +218,10 @@
  146. # I think it makes sense to exit if their code throws an exception...
  147. tracebackrepy.handle_exception()
  148. nonportable.harshexit(6)
  149. + finally:
  150. + nanny.tattle_remove_item('events', initialize_id)
  151.  
  152. +
  153. # I've changed to the threading library, so this should increase if there are
  154. # pending events
  155. while threading.activeCount() > idlethreadcount:
  156. @@ -220,7 +235,17 @@
  157. # call the user program to notify them that we are exiting...
  158. usercontext['callfunc'] = 'exit'
  159. usercontext['callargs'] = (None,)
  160. +
  161. try:
  162. + exit_id = idhelper.getuniqueid()
  163. + nanny.tattle_add_item('events', exit_id)
  164. + except Exception, e:
  165. + print "Failed to allocate event for 'exit' callfunc"
  166. + print "Failure:"
  167. + print e
  168. + tracebackrepy.handle_exception()
  169. +
  170. + try:
  171. safe.safe_exec(usercode,usercontext)
  172. except SystemExit:
  173. raise
  174. @@ -228,6 +253,8 @@
  175. # I think it makes sense to exit if their code throws an exception...
  176. tracebackrepy.handle_exception()
  177. nonportable.harshexit(7)
  178. + finally:
  179. + nanny.tattle_remove_item('events', exit_id)
  180.  
  181. # normal exit...
  182. nonportable.harshexit(0)
Add Comment
Please, Sign In to add comment