def test_suspend_active(self):
     interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
     old_process.suspend(interp)
     process_list = wrapper.scheduler(space).get_process_list(old_process.priority())
     assert process_list.first_link() is process_list.last_link()
     assert process_list.first_link() is space.w_nil
     assert old_process.my_list() is space.w_nil
     assert wrapper.scheduler(space).active_process() is process.w_self
 def new_process_consistency(self, process, old_process, interp,
                                 old_active_context, new_active_context):
     scheduler = wrapper.scheduler(space)
     assert interp.w_active_context() is new_active_context
     assert scheduler.active_process() is process.w_self
     priority_list = wrapper.scheduler(space).get_process_list(process.priority())
     assert priority_list.first_link() is priority_list.last_link()
     # activate does not remove the process from the process_list.
     # The caller of activate is responsible
     assert priority_list.first_link() is process.w_self
Beispiel #3
0
 def test_suspend_active(self):
     interp, process, old_process = self.make_processes(
         4, 2, space.w_false, space.w_true)
     old_process.suspend(interp)
     process_list = wrapper.scheduler(space).get_process_list(
         old_process.priority())
     assert process_list.first_link() is process_list.last_link()
     assert process_list.first_link() is space.w_nil
     assert old_process.my_list() is space.w_nil
     assert wrapper.scheduler(space).active_process() is process.w_self
 def test_highest_priority(self):
     py.test.raises(FatalError, wrapper.scheduler(space).highest_priority_process)
     interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
     process.put_to_sleep()
     old_process.put_to_sleep()
     highest = wrapper.scheduler(space).highest_priority_process()
     assert highest is process.w_self
     highest = wrapper.scheduler(space).highest_priority_process()
     assert highest is old_process.w_self
     py.test.raises(FatalError, wrapper.scheduler(space).highest_priority_process)
Beispiel #5
0
 def new_process_consistency(self, process, old_process, interp,
                             old_active_context, new_active_context):
     scheduler = wrapper.scheduler(space)
     assert interp.w_active_context() is new_active_context
     assert scheduler.active_process() is process.w_self
     priority_list = wrapper.scheduler(space).get_process_list(
         process.priority())
     assert priority_list.first_link() is priority_list.last_link()
     # activate does not remove the process from the process_list.
     # The caller of activate is responsible
     assert priority_list.first_link() is process.w_self
Beispiel #6
0
 def test_highest_priority(self):
     py.test.raises(FatalError,
                    wrapper.scheduler(space).highest_priority_process)
     interp, process, old_process = self.make_processes(
         4, 2, space.w_false, space.w_true)
     process.put_to_sleep()
     old_process.put_to_sleep()
     highest = wrapper.scheduler(space).highest_priority_process()
     assert highest is process.w_self
     highest = wrapper.scheduler(space).highest_priority_process()
     assert highest is old_process.w_self
     py.test.raises(FatalError,
                    wrapper.scheduler(space).highest_priority_process)
    def test_semaphore_signal_wait(self):
        semaphore = new_semaphore()
        self.space = space
        semaphore.signal(self)
        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
        semaphore.wait(interp)
        assert semaphore.is_empty_list()
        assert wrapper.scheduler(space).active_process() is old_process.w_self
        semaphore.wait(interp)
        assert semaphore.first_link() is old_process.w_self
        assert wrapper.scheduler(space).active_process() is process.w_self

        py.test.raises(FatalError, semaphore.wait, interp)
Beispiel #8
0
    def test_semaphore_signal_wait(self):
        semaphore = new_semaphore()
        self.space = space
        semaphore.signal(self)
        interp, process, old_process = self.make_processes(
            4, 2, space.w_false, space.w_true)
        semaphore.wait(interp)
        assert semaphore.is_empty_list()
        assert wrapper.scheduler(space).active_process() is old_process.w_self
        semaphore.wait(interp)
        assert semaphore.first_link() is old_process.w_self
        assert wrapper.scheduler(space).active_process() is process.w_self

        py.test.raises(FatalError, semaphore.wait, interp)
Beispiel #9
0
def test_step_forged_image():
    from pypy.lang.smalltalk import wrapper
    ap = wrapper.ProcessWrapper(space,
                                wrapper.scheduler(space).active_process())
    s_ctx = ap.suspended_context().as_context_get_shadow(space)
    assert isinstance(s_ctx, shadow.MethodContextShadow)
    assert s_ctx.top().is_same_object(space.w_true)
Beispiel #10
0
 def test_semaphore_wait(self):
     semaphore = new_semaphore()
     interp, process, old_process = self.make_processes(
         4, 2, space.w_false, space.w_true)
     semaphore.wait(interp)
     assert semaphore.first_link() is old_process.w_self
     assert wrapper.scheduler(space).active_process() is process.w_self
def test_runimage():
    py.test.skip("This method actually runs an image. Fails since no graphical primitives yet")
    from pypy.lang.smalltalk import wrapper
    ap = wrapper.ProcessWraper(wrapper.scheduler().active_process())
    s_ctx = ap.suspended_context().as_methodcontext_get_shadow()
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter()
    interp.store_w_active_context(s_ctx.w_self())
    interp.interpret()
    def make_processes(self, sleepingpriority, runningpriority,
                             sleepingcontext, runningcontext):
        interp = interpreter.Interpreter(space)
        scheduler = wrapper.scheduler(space)
        sleeping = new_process(priority=sleepingpriority,
                               w_suspended_context=sleepingcontext)
        sleeping.put_to_sleep()
        running = new_process(priority=runningpriority)
        scheduler.store_active_process(running.w_self)
        interp.store_w_active_context(runningcontext)

        return interp, sleeping, running
Beispiel #13
0
    def make_processes(self, sleepingpriority, runningpriority,
                       sleepingcontext, runningcontext):
        interp = interpreter.Interpreter(space)
        scheduler = wrapper.scheduler(space)
        sleeping = new_process(priority=sleepingpriority,
                               w_suspended_context=sleepingcontext)
        sleeping.put_to_sleep()
        running = new_process(priority=runningpriority)
        scheduler.store_active_process(running.w_self)
        interp.store_w_active_context(runningcontext)

        return interp, sleeping, running
Beispiel #14
0
def test_runimage():
    py.test.skip(
        "This method actually runs an image. Fails since no graphical primitives yet"
    )
    from pypy.lang.smalltalk import wrapper
    ap = wrapper.ProcessWraper(wrapper.scheduler().active_process())
    s_ctx = ap.suspended_context().as_methodcontext_get_shadow()
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter()
    interp.store_w_active_context(s_ctx.w_self())
    interp.interpret()
def test_step_run_something():
    from pypy.lang.smalltalk.test import test_miniimage
    setup_module(test_miniimage, filename='running-something-mini.image')
    from pypy.lang.smalltalk import wrapper
    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
    s_ctx = ap.suspended_context().as_context_get_shadow(space)
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter(space)
    interp.store_w_active_context(s_ctx.w_self())
    assert isinstance(s_ctx, shadow.MethodContextShadow)
    assert interp.s_active_context().top().is_same_object(space.w_true)
    interp.step()
    interp.step() 
    assert interp.s_active_context().top().value == 1
    interp.step() 
    assert interp.s_active_context().top().value == 2
    interp.step() 
    assert interp.s_active_context().top().value == 3
Beispiel #16
0
def test_step_run_something():
    from pypy.lang.smalltalk.test import test_miniimage
    setup_module(test_miniimage, filename='running-something-mini.image')
    from pypy.lang.smalltalk import wrapper
    ap = wrapper.ProcessWrapper(space,
                                wrapper.scheduler(space).active_process())
    s_ctx = ap.suspended_context().as_context_get_shadow(space)
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter(space)
    interp.store_w_active_context(s_ctx.w_self())
    assert isinstance(s_ctx, shadow.MethodContextShadow)
    assert interp.s_active_context().top().is_same_object(space.w_true)
    interp.step()
    interp.step()
    assert interp.s_active_context().top().value == 1
    interp.step()
    assert interp.s_active_context().top().value == 2
    interp.step()
    assert interp.s_active_context().top().value == 3
    def test_semaphore_wait_signal(self):
        semaphore = new_semaphore()
        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)

        semaphore.wait(interp)
        assert wrapper.scheduler(space).active_process() is process.w_self
        semaphore.signal(interp)
        assert wrapper.scheduler(space).active_process() is process.w_self
        process_list = wrapper.scheduler(space).get_process_list(old_process.priority())
        assert process_list.remove_first_link_of_list() is old_process.w_self

        process.write(2, space.wrap_int(1))        
        old_process.resume(interp)
        assert wrapper.scheduler(space).active_process() is old_process.w_self        
        semaphore.wait(interp)
        assert wrapper.scheduler(space).active_process() is process.w_self
        semaphore.signal(interp)
        assert wrapper.scheduler(space).active_process() is old_process.w_self        

        process_list = wrapper.scheduler(space).get_process_list(process.priority())
        assert process_list.first_link() is process.w_self
Beispiel #18
0
    def test_semaphore_wait_signal(self):
        semaphore = new_semaphore()
        interp, process, old_process = self.make_processes(
            4, 2, space.w_false, space.w_true)

        semaphore.wait(interp)
        assert wrapper.scheduler(space).active_process() is process.w_self
        semaphore.signal(interp)
        assert wrapper.scheduler(space).active_process() is process.w_self
        process_list = wrapper.scheduler(space).get_process_list(
            old_process.priority())
        assert process_list.remove_first_link_of_list() is old_process.w_self

        process.write(2, space.wrap_int(1))
        old_process.resume(interp)
        assert wrapper.scheduler(space).active_process() is old_process.w_self
        semaphore.wait(interp)
        assert wrapper.scheduler(space).active_process() is process.w_self
        semaphore.signal(interp)
        assert wrapper.scheduler(space).active_process() is old_process.w_self

        process_list = wrapper.scheduler(space).get_process_list(
            process.priority())
        assert process_list.first_link() is process.w_self
Beispiel #19
0
 def test_put_to_sleep(self):
     process = new_process(priority=2)
     process.put_to_sleep()
     process_list = wrapper.scheduler(space).get_process_list(2)
     assert process_list.first_link() is process_list.last_link()
     assert process_list.first_link() is process.w_self
Beispiel #20
0
 def old_process_consistency(self, old_process, old_process_context):
     assert old_process.suspended_context() is old_process_context
     priority_list = wrapper.scheduler(space).get_process_list(
         old_process.priority())
     assert priority_list.first_link() is old_process.w_self
 def test_semaphore_wait(self):
     semaphore = new_semaphore()
     interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
     semaphore.wait(interp)
     assert semaphore.first_link() is old_process.w_self
     assert wrapper.scheduler(space).active_process() is process.w_self
def test_step_forged_image():
    from pypy.lang.smalltalk import wrapper
    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
    s_ctx = ap.suspended_context().as_context_get_shadow(space)
    assert isinstance(s_ctx, shadow.MethodContextShadow)
    assert s_ctx.top().is_same_object(space.w_true)
 def old_process_consistency(self, old_process, old_process_context):
     assert old_process.suspended_context() is old_process_context
     priority_list = wrapper.scheduler(space).get_process_list(old_process.priority())
     assert priority_list.first_link() is old_process.w_self
 def test_put_to_sleep(self):
     process = new_process(priority=2)
     process.put_to_sleep()
     process_list = wrapper.scheduler(space).get_process_list(2)
     assert process_list.first_link() is process_list.last_link()
     assert process_list.first_link() is process.w_self