Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: repy/tests/rz_restrictions.oneevent_initandexitareevents.py
- ===================================================================
- --- repy/tests/rz_restrictions.oneevent_initandexitareevents.py (revision 0)
- +++ repy/tests/rz_restrictions.oneevent_initandexitareevents.py (revision 0)
- @@ -0,0 +1,11 @@
- +# a test to see if the event used by the initialize thread is counted
- +
- +# One thread for this code
- +if callfunc == 'initialize':
- + # One event is fine
- + pass
- +
- +if callfunc == 'exit':
- + # Exit code should be ok, because exit and initialize don't run at the
- + # same time
- + pass
- Index: repy/tests/re_restrictions.oneevent_eventsarelimitedinit.py
- ===================================================================
- --- repy/tests/re_restrictions.oneevent_eventsarelimitedinit.py (revision 0)
- +++ repy/tests/re_restrictions.oneevent_eventsarelimitedinit.py (revision 0)
- @@ -0,0 +1,11 @@
- +# More than one event is not allowed:
- +
- +def foo():
- + pass
- +
- +def do_some_stuff():
- + pass
- +
- +if callfunc == 'initialize':
- + settimer(1,foo,[])
- + do_some_stuff()
- Index: repy/tests/restrictions.oneevent
- ===================================================================
- --- repy/tests/restrictions.oneevent (revision 0)
- +++ repy/tests/restrictions.oneevent (revision 0)
- @@ -0,0 +1,54 @@
- +resource cpu .50
- +resource memory 15000000 # 15 Million bytes
- +resource diskused 10000000 # 10 MB
- +resource events 1
- +resource filewrite 10000
- +resource fileread 10000
- +resource filesopened 5
- +resource insockets 5
- +resource outsockets 5
- +resource netsend 10000
- +resource netrecv 10000
- +resource loopsend 1000000
- +resource looprecv 1000000
- +resource lograte 1000
- +resource messport 12345
- +resource messport 12346
- +resource messport 12347
- +resource connport 12345
- +resource connport 12346
- +resource connport 12347
- +
- +call gethostbyname_ex allow
- +call sendmess allow
- +call stopcomm allow # it doesn't make sense to restrict
- +call recvmess allow
- +call openconn allow
- +call waitforconn allow
- +call socket.close allow # let's not restrict
- +call socket.send allow # let's not restrict
- +call socket.recv allow # let's not restrict
- +# open and file.__init__ both have built in restrictions...
- +call open arg 0 is junk_test.out allow # can write to junk_test.out
- +call open arg 1 is r allow # allow an explicit read
- +call open noargs is 1 allow # allow an implicit read
- +call file.__init__ arg 0 is junk_test.out allow # can write to junk_test.out
- +call file.__init__ arg 1 is r allow # allow an explicit read
- +call file.__init__ noargs is 1 allow # allow an implicit read
- +call file.close allow # shouldn't restrict
- +call file.flush allow # they are free to use
- +call file.next allow # free to use as well...
- +call file.read allow # allow read
- +call file.readline allow # shouldn't restrict
- +call file.readlines allow # shouldn't restrict
- +call file.seek allow # seek doesn't restrict
- +call file.write allow # shouldn't restrict (open restricts)
- +call file.writelines allow # shouldn't restrict (open restricts)
- +call sleep allow # harmless
- +call settimer allow # we can't really do anything smart
- +call canceltimer allow # should be okay
- +call exitall allow # should be harmless
- +
- +call log.write allow
- +call log.writelines allow
- +call getmyip allow
- Property changes on: repy/tests/restrictions.oneevent
- ___________________________________________________________________
- Added: svn:executable
- + *
- Index: repy/tests/re_restrictions.oneevent_eventsarelimitedexit.py
- ===================================================================
- --- repy/tests/re_restrictions.oneevent_eventsarelimitedexit.py (revision 0)
- +++ repy/tests/re_restrictions.oneevent_eventsarelimitedexit.py (revision 0)
- @@ -0,0 +1,11 @@
- +# More than one event is not allowed:
- +
- +def foo():
- + pass
- +
- +def do_some_stuff():
- + pass
- +
- +if callfunc == 'exit':
- + settimer(1,foo,[])
- + do_some_stuff()
- Index: repy/repy.py
- ===================================================================
- --- repy/repy.py (revision 2186)
- +++ repy/repy.py (working copy)
- @@ -49,6 +49,8 @@
- import emultimer
- import emulcomm
- import emulmisc
- +import idhelper
- +import nanny
- import restrictions
- import time
- import threading
- @@ -198,7 +200,17 @@
- # call the initialize function
- usercontext['callfunc'] = 'initialize'
- usercontext['callargs'] = args[:]
- +
- try:
- + initialize_id = idhelper.getuniqueid()
- + nanny.tattle_add_item('events', initialize_id)
- + except Exception, e:
- + print "Failed to allocate event for 'initialize' callfunc"
- + print "Failure:"
- + print e
- + tracebackrepy.handle_exception()
- +
- + try:
- safe.safe_exec(usercode,usercontext)
- except SystemExit:
- raise
- @@ -206,7 +218,10 @@
- # I think it makes sense to exit if their code throws an exception...
- tracebackrepy.handle_exception()
- nonportable.harshexit(6)
- + finally:
- + nanny.tattle_remove_item('events', initialize_id)
- +
- # I've changed to the threading library, so this should increase if there are
- # pending events
- while threading.activeCount() > idlethreadcount:
- @@ -220,7 +235,17 @@
- # call the user program to notify them that we are exiting...
- usercontext['callfunc'] = 'exit'
- usercontext['callargs'] = (None,)
- +
- try:
- + exit_id = idhelper.getuniqueid()
- + nanny.tattle_add_item('events', exit_id)
- + except Exception, e:
- + print "Failed to allocate event for 'exit' callfunc"
- + print "Failure:"
- + print e
- + tracebackrepy.handle_exception()
- +
- + try:
- safe.safe_exec(usercode,usercontext)
- except SystemExit:
- raise
- @@ -228,6 +253,8 @@
- # I think it makes sense to exit if their code throws an exception...
- tracebackrepy.handle_exception()
- nonportable.harshexit(7)
- + finally:
- + nanny.tattle_remove_item('events', exit_id)
- # normal exit...
- nonportable.harshexit(0)
Add Comment
Please, Sign In to add comment