示例#1
0
 def new_process_consistency(self, process, old_process, w_active_context):
     scheduler = wrapper.scheduler(space)
     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
示例#2
0
 def new_process_consistency(self, process, old_process, w_active_context):
     scheduler = wrapper.scheduler(space)
     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
示例#3
0
 def test_highest_priority(self):
     py.test.raises(FatalError, wrapper.scheduler(space).pop_highest_priority_process)
     process, old_process = self.make_processes(4, 2, space.w_false)
     process.put_to_sleep()
     old_process.put_to_sleep()
     highest = wrapper.scheduler(space).pop_highest_priority_process()
     assert highest is process._w_self
     highest = wrapper.scheduler(space).pop_highest_priority_process()
     assert highest is old_process._w_self
     py.test.raises(FatalError, wrapper.scheduler(space).pop_highest_priority_process)
示例#4
0
 def test_suspend_active(self):
     suspended_context = new_frame()
     process, old_process = self.make_processes(4, 2, suspended_context)
     current_context = new_frame()
     with py.test.raises(interpreter.ProcessSwitch):
         old_process.suspend(current_context)
     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_nil(space)
     assert old_process.my_list().is_nil(space)
     assert old_process.suspended_context() is current_context.w_self()
     assert wrapper.scheduler(space).active_process() is process._w_self
示例#5
0
 def test_highest_priority(self):
     py.test.raises(FatalError,
                    wrapper.scheduler(space).pop_highest_priority_process)
     process, old_process = self.make_processes(4, 2, space.w_false)
     process.put_to_sleep()
     old_process.put_to_sleep()
     highest = wrapper.scheduler(space).pop_highest_priority_process()
     assert highest is process._w_self
     highest = wrapper.scheduler(space).pop_highest_priority_process()
     assert highest is old_process._w_self
     py.test.raises(FatalError,
                    wrapper.scheduler(space).pop_highest_priority_process)
示例#6
0
 def test_suspend_active(self):
     suspended_context = new_frame()
     process, old_process = self.make_processes(4, 2, suspended_context)
     current_context = new_frame()
     with py.test.raises(interpreter.ProcessSwitch):
         old_process.suspend(current_context)
     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 old_process.suspended_context() is current_context
     assert wrapper.scheduler(space).active_process() is process._w_self
示例#7
0
def test_step_forged_image():
    from spyvm 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)
示例#8
0
    def test_semaphore_signal_wait(self):
        semaphore = new_semaphore()
        self.space = space
        semaphore.signal(self)
        suspendedcontext = new_frame()
        currentcontext = new_frame()
        process, old_process = self.make_processes(4, 2, suspendedcontext)
        semaphore.wait(currentcontext)
        assert semaphore.is_empty_list()
        assert wrapper.scheduler(space).active_process() is old_process._w_self
        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.wait(currentcontext)
        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, space.w_true)
def active_context(space):
    w_active_process = wrapper.scheduler(space).active_process()
    active_process = wrapper.ProcessWrapper(space, w_active_process)
    w_active_context = active_process.suspended_context()
    assert isinstance(w_active_context, model.W_PointersObject)
    active_process.store_suspended_context(space.w_nil)
    return w_active_context.as_context_get_shadow(space)
def active_context(space):
    w_active_process = wrapper.scheduler(space).active_process()
    active_process = wrapper.ProcessWrapper(space, w_active_process)
    w_active_context = active_process.suspended_context()
    assert isinstance(w_active_context, model.W_PointersObject)
    active_process.store_suspended_context(space.w_nil)
    return w_active_context.as_context_get_shadow(space)
示例#11
0
    def test_semaphore_signal_wait(self):
        semaphore = new_semaphore()
        self.space = space
        semaphore.signal(self)
        suspendedcontext = new_frame()
        currentcontext = new_frame()
        process, old_process = self.make_processes(4, 2, suspendedcontext)
        semaphore.wait(currentcontext)
        assert semaphore.is_empty_list()
        assert wrapper.scheduler(space).active_process() is old_process._w_self
        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.wait(currentcontext)
        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, space.w_true)
示例#12
0
 def test_suspend_asleep(self):
     process, old_process = self.make_processes(4, 2, space.w_false)
     process.suspend(space.w_true)
     process_list = wrapper.scheduler(space).get_process_list(process.priority())
     assert process_list.first_link() is process_list.last_link()
     assert process_list.first_link().is_nil(space)
     assert process.my_list().is_nil(space)
示例#13
0
 def test_suspend_asleep(self):
     process, old_process = self.make_processes(4, 2, space.w_false)
     w_frame = process.suspend(space.w_true)
     process_list = wrapper.scheduler(space).get_process_list(
         process.priority())
     assert process_list.first_link() is process_list.last_link()
     assert process_list.first_link() is space.w_nil
     assert process.my_list() is space.w_nil
示例#14
0
    def test_semaphore_wait_signal(self):
        semaphore = new_semaphore()
        suspendedcontext = new_frame()
        currentcontext = new_frame()
        process, old_process = self.make_processes(4, 2, suspendedcontext)

        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.wait(currentcontext)

        assert wrapper.scheduler(space).active_process() is process._w_self
        semaphore.signal(currentcontext)
        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))
        with py.test.raises(interpreter.ProcessSwitch):
            old_process.resume(currentcontext)
        assert wrapper.scheduler(space).active_process() is old_process._w_self
        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.wait(currentcontext)
        assert wrapper.scheduler(space).active_process() is process._w_self
        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.signal(currentcontext)
        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
示例#15
0
    def test_semaphore_wait_signal(self):
        semaphore = new_semaphore()
        suspendedcontext = new_frame()
        currentcontext = new_frame()
        process, old_process = self.make_processes(4, 2, suspendedcontext)

        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.wait(currentcontext)

        assert wrapper.scheduler(space).active_process() is process._w_self
        semaphore.signal(currentcontext)
        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))
        with py.test.raises(interpreter.ProcessSwitch):
            old_process.resume(currentcontext)
        assert wrapper.scheduler(space).active_process() is old_process._w_self
        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.wait(currentcontext)
        assert wrapper.scheduler(space).active_process() is process._w_self
        with py.test.raises(interpreter.ProcessSwitch):
            semaphore.signal(currentcontext)
        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
示例#16
0
 def test_semaphore_wait(self):
     semaphore = new_semaphore()
     suspendedcontext = new_frame()
     currentcontext = new_frame()
     process, old_process = self.make_processes(4, 2, suspendedcontext)
     with py.test.raises(interpreter.ProcessSwitch):
         semaphore.wait(currentcontext)
     assert semaphore.first_link() is old_process._w_self
     assert wrapper.scheduler(space).active_process() is process._w_self
示例#17
0
 def test_semaphore_wait(self):
     semaphore = new_semaphore()
     suspendedcontext = new_frame()
     currentcontext = new_frame()
     process, old_process = self.make_processes(4, 2, suspendedcontext)
     with py.test.raises(interpreter.ProcessSwitch):
         semaphore.wait(currentcontext)
     assert semaphore.first_link() is old_process._w_self
     assert wrapper.scheduler(space).active_process() is process._w_self
示例#18
0
def test_runimage():
    py.test.skip("This method actually runs an image. Fails since no graphical primitives yet")
    from spyvm import wrapper
    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter(space)
    interp.interpret_with_w_frame(w_ctx)
def _run_image(interp):
    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    assert isinstance(w_ctx, model.W_PointersObject)
    ap.store_suspended_context(space.w_nil)
    try:
        return interp.interpret_with_w_frame(w_ctx)
    except error.Exit, e:
        print e.msg
示例#20
0
    def make_processes(self, sleepingpriority, runningpriority,
                       sleepingcontext):
        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)

        return sleeping, running
def _run_image(interp):
    ap = wrapper.ProcessWrapper(space,
                                wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    assert isinstance(w_ctx, model.W_PointersObject)
    ap.store_suspended_context(space.w_nil)
    try:
        return interp.interpret_with_w_frame(w_ctx)
    except error.Exit, e:
        print e.msg
示例#22
0
    def make_processes(self, sleepingpriority, runningpriority, sleepingcontext):
        if not isinstance(sleepingcontext, model.W_Object):
            sleepingcontext = sleepingcontext.w_self()
        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.wrapped)

        return sleeping, running
示例#23
0
    def make_processes(self, sleepingpriority, runningpriority,
                       sleepingcontext):
        if not isinstance(sleepingcontext, model.W_Object):
            sleepingcontext = sleepingcontext.w_self()
        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.wrapped)

        return sleeping, running
示例#24
0
def test_runimage():
    py.test.skip(
        "This method actually runs an image. Fails since no graphical primitives yet"
    )
    from spyvm import wrapper
    ap = wrapper.ProcessWrapper(space,
                                wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter(space)
    interp.interpret_with_w_frame(w_ctx)
示例#25
0
def test_step_run_something():
    space, interp = runningSomethingImage(cached=False)
    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    s_ctx = w_ctx.as_context_get_shadow(space)
    ap.store_suspended_context(space.w_nil)

    assert isinstance(s_ctx, storage_contexts.ContextPartShadow)
    assert s_ctx.top().is_same_object(space.w_true)
    interp.step(s_ctx)
    interp.step(s_ctx)
    assert s_ctx.top().value == 1
    interp.step(s_ctx)
    assert s_ctx.top().value == 2
    interp.step(s_ctx)
    assert s_ctx.top().value == 3
示例#26
0
def test_step_run_something():
    space, interp = runningSomethingImage(cached=False)
    ap = wrapper.ProcessWrapper(space,
                                wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    s_ctx = w_ctx.as_context_get_shadow(space)
    ap.store_suspended_context(space.w_nil)

    assert isinstance(s_ctx, storage_contexts.ContextPartShadow)
    assert s_ctx.top().is_same_object(space.w_true)
    interp.step(s_ctx)
    interp.step(s_ctx)
    assert s_ctx.top().value == 1
    interp.step(s_ctx)
    assert s_ctx.top().value == 2
    interp.step(s_ctx)
    assert s_ctx.top().value == 3
示例#27
0
def test_step_run_something():
    from spyvm.test import test_miniimage
    setup_module(test_miniimage, filename='running-something-mini.image')
    from spyvm import wrapper
    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    s_ctx = w_ctx.as_context_get_shadow(space)
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter(space)
    assert isinstance(s_ctx, shadow.MethodContextShadow)
    assert s_ctx.top().is_same_object(space.w_true)
    interp.step(s_ctx)
    interp.step(s_ctx)
    assert s_ctx.top().value == 1
    interp.step(s_ctx)
    assert s_ctx.top().value == 2
    interp.step(s_ctx)
    assert s_ctx.top().value == 3
def create_process(interp, s_frame):
    space = interp.space
    w_active_process = wrapper.scheduler(space).active_process()
    assert isinstance(w_active_process, model.W_PointersObject)
    w_benchmark_proc = model.W_PointersObject(
        space, w_active_process.getclass(space), w_active_process.size()
    )
    if interp.image.version.has_closures:
        # Priorities below 10 are not allowed in newer versions of Squeak.
        active_priority = space.unwrap_int(w_active_process.fetch(space, 2))
        priority = active_priority / 2 + 1
        priority = max(11, priority)
    else:
        priority = 7
    w_benchmark_proc.store(space, 1, s_frame.w_self())
    w_benchmark_proc.store(space, 2, space.wrap_int(priority))

    # Make process eligible for scheduling
    wrapper.ProcessWrapper(space, w_benchmark_proc).put_to_sleep()
示例#29
0
def create_process(interp, s_frame):
    space = interp.space
    w_active_process = wrapper.scheduler(space).active_process()
    assert isinstance(w_active_process, model.W_PointersObject)
    w_benchmark_proc = model.W_PointersObject(
        space, w_active_process.getclass(space), w_active_process.size()
    )
    if interp.image.version.has_closures:
        # Priorities below 10 are not allowed in newer versions of Squeak.
        active_priority = space.unwrap_int(w_active_process.fetch(space, 2))
        priority = active_priority / 2 + 1
        priority = max(11, priority)
    else:
        priority = 7
    w_benchmark_proc.store(space, 1, s_frame.w_self())
    w_benchmark_proc.store(space, 2, space.wrap_int(priority))

    # Make process eligible for scheduling
    wrapper.ProcessWrapper(space, w_benchmark_proc).put_to_sleep()
示例#30
0
def test_step_run_something():
    from spyvm.test import test_miniimage
    setup_module(test_miniimage, filename='running-something-mini.image')
    from spyvm import wrapper
    ap = wrapper.ProcessWrapper(space,
                                wrapper.scheduler(space).active_process())
    w_ctx = ap.suspended_context()
    s_ctx = w_ctx.as_context_get_shadow(space)
    ap.store_suspended_context(space.w_nil)

    interp = interpreter.Interpreter(space)
    assert isinstance(s_ctx, shadow.MethodContextShadow)
    assert s_ctx.top().is_same_object(space.w_true)
    interp.step(s_ctx)
    interp.step(s_ctx)
    assert s_ctx.top().value == 1
    interp.step(s_ctx)
    assert s_ctx.top().value == 2
    interp.step(s_ctx)
    assert s_ctx.top().value == 3
def _run_benchmark(interp, number, benchmark, arg):
    from spyvm.plugins.vmdebugging import stop_ui_process
    stop_ui_process()

    scheduler = wrapper.scheduler(interp.space)
    w_hpp = scheduler.active_process()
    if space.unwrap_int(scheduler.active_process().fetch(space, 2)) > space.unwrap_int(w_hpp.fetch(space, 2)):
        w_hpp = scheduler.active_process()
    assert isinstance(w_hpp, model.W_PointersObject)
    w_benchmark_proc = model.W_PointersObject(
        interp.space,
        w_hpp.getclass(interp.space),
        len(w_hpp._vars)
    )

    s_frame = context_for(interp, number, benchmark, arg)
    # second variable is suspended context
    w_benchmark_proc.store(space, 1, s_frame.w_self())

    # third variable is priority
    priority = space.unwrap_int(w_hpp.fetch(space, 2)) / 2 + 1
    # Priorities below 10 are not allowed in newer versions of Squeak.
    if interp.image.version.has_closures:
        priority = max(11, priority)
    else:
        priority = 7
    w_benchmark_proc.store(space, 2, space.wrap_int(priority))

    # make process eligible for scheduling
    wrapper.ProcessWrapper(interp.space, w_benchmark_proc).put_to_sleep()

    t1 = time.time()
    w_result = _run_image(interp)
    t2 = time.time()
    if w_result:
        if isinstance(w_result, model.W_BytesObject):
            print w_result.as_string().replace('\r', '\n')
        print "took %s seconds" % (t2 - t1)
        return 0
    return -1
def _run_benchmark(interp, number, benchmark, arg):
    from spyvm.plugins.vmdebugging import stop_ui_process
    stop_ui_process()

    scheduler = wrapper.scheduler(interp.space)
    w_hpp = scheduler.active_process()
    if space.unwrap_int(scheduler.active_process().fetch(
            space, 2)) > space.unwrap_int(w_hpp.fetch(space, 2)):
        w_hpp = scheduler.active_process()
    assert isinstance(w_hpp, model.W_PointersObject)
    w_benchmark_proc = model.W_PointersObject(interp.space,
                                              w_hpp.getclass(interp.space),
                                              len(w_hpp._vars))

    s_frame = context_for(interp, number, benchmark, arg)
    # second variable is suspended context
    w_benchmark_proc.store(space, 1, s_frame.w_self())

    # third variable is priority
    priority = space.unwrap_int(w_hpp.fetch(space, 2)) / 2 + 1
    # Priorities below 10 are not allowed in newer versions of Squeak.
    if interp.image.version.has_closures:
        priority = max(11, priority)
    else:
        priority = 7
    w_benchmark_proc.store(space, 2, space.wrap_int(priority))

    # make process eligible for scheduling
    wrapper.ProcessWrapper(interp.space, w_benchmark_proc).put_to_sleep()

    t1 = time.time()
    w_result = _run_image(interp)
    t2 = time.time()
    if w_result:
        if isinstance(w_result, model.W_BytesObject):
            print w_result.as_string().replace('\r', '\n')
        print "took %s seconds" % (t2 - t1)
        return 0
    return -1
示例#33
0
 def old_process_consistency(self, old_process, old_process_context):
     assert old_process.suspended_context() is old_process_context.w_self()
     priority_list = wrapper.scheduler(space).get_process_list(old_process.priority())
     assert priority_list.first_link() is old_process._w_self
示例#34
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
示例#35
0
def test_step_forged_image():
    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
    s_ctx = ap.suspended_context().as_context_get_shadow(space)
    assert isinstance(s_ctx, storage_contexts.ContextPartShadow)
    assert s_ctx.top().is_same_object(space.w_true)
示例#36
0
def test_step_forged_image():
    from spyvm 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)
示例#37
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
示例#38
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
示例#39
0
def test_step_forged_image():
    ap = wrapper.ProcessWrapper(space,
                                wrapper.scheduler(space).active_process())
    s_ctx = ap.suspended_context().as_context_get_shadow(space)
    assert isinstance(s_ctx, storage_contexts.ContextPartShadow)
    assert s_ctx.top().is_same_object(space.w_true)