def testTupleFreezeUnfreeze(self, open, kill, getsid, getpgid):
     """
     In some cases the parent pid does not like the child to be suspended (processes implementing job control, like an interactive bash session).  To cater for this, we'll need to make sure the parent is suspended before the child, and that the child is resumed before the parent.  Such pairs (or even longer chains) should be handled as tuples.
     """
     thrash_protect.freeze_something((10, 20, 30))
     thrash_protect.unfreeze_something()
     
     assert_equal(kill.call_args_list, [
         ((10, signal.SIGSTOP),), ((20, signal.SIGSTOP),), ((30, signal.SIGSTOP),),
         ((30, signal.SIGCONT),), ((20, signal.SIGCONT),), ((10, signal.SIGCONT),)])
Exemplo n.º 2
0
    def testTupleFreezeUnfreeze(self, open, kill, getsid, getpgid):
        """
        In some cases the parent pid does not like the child to be suspended (processes implementing job control, like an interactive bash session).  To cater for this, we'll need to make sure the parent is suspended before the child, and that the child is resumed before the parent.  Such pairs (or even longer chains) should be handled as tuples.
        """
        thrash_protect.freeze_something((10, 20, 30))
        thrash_protect.unfreeze_something()

        assert_equal(kill.call_args_list, [((10, signal.SIGSTOP), ),
                                           ((20, signal.SIGSTOP), ),
                                           ((30, signal.SIGSTOP), ),
                                           ((30, signal.SIGCONT), ),
                                           ((20, signal.SIGCONT), ),
                                           ((10, signal.SIGCONT), )])
    def testSimpleFreezeUnfreeze(self, log_unfrozen, log_frozen):
        """This test should assert that os.kill is called appropriately when
        freezing and unfreezing pids.  We'll keep it there as for now.
        Pure unit test, no side effects or system calls should be done
        here.
        """
        prev=thrash_protect.SystemState()
        time.sleep(1)
        current=thrash_protect.SystemState()
        thrash_protect.global_process_selector.update(prev, current)
        ## Freezing something 6 times (to make sure we pass the default
        ## unfreeze_pop_ratio)
        my_frozen_pids = []
        for i in range(0,6):
            my_frozen_pids.append(thrash_protect.freeze_something())

        frozen_calls = log_frozen.call_args_list
        assert(len(frozen_calls) >= 6)

        my_frozen_pids = [x for x in my_frozen_pids if x]
        assert(my_frozen_pids)

        for pids in my_frozen_pids:
            for pid in pids:
                assert_equal(thrash_protect.ProcessSelector().readStat(pid).state, 'T')

        ## Unfreeze
        for i in range(0,6):
            thrash_protect.unfreeze_something()

        assert_equal(log_frozen.call_args_list, frozen_calls)
        assert_equal(len(log_unfrozen.call_args_list), len(log_frozen.call_args_list))
        
        thrash_protect.global_process_selector.update(current, thrash_protect.SystemState())

        ## once again, to make sure the "unfreeze_last_frozen" also gets excersised
        for i in range(0,6):
            my_frozen_pids.append(thrash_protect.freeze_something())
        my_frozen_pids = [x for x in my_frozen_pids if x]
        assert(my_frozen_pids)
        ## Unfreeze
        for i in range(0,6):
            thrash_protect.unfreeze_something()
Exemplo n.º 4
0
    def testSimpleFreezeUnfreeze(self, log_unfrozen, log_frozen):
        """This test should assert that suspension and resuming works.
        """
        prev = thrash_protect.SystemState()
        time.sleep(1)
        current = thrash_protect.SystemState()
        thrash_protect.global_process_selector.update(prev, current)
        ## Freezing something 6 times (to make sure we pass the default
        ## unfreeze_pop_ratio)
        my_frozen_pids = []
        for i in range(0, 6):
            my_frozen_pids.append(thrash_protect.freeze_something())

        frozen_calls = log_frozen.call_args_list
        assert (len(frozen_calls) >= 6)

        my_frozen_pids = [x for x in my_frozen_pids if x]
        assert (my_frozen_pids)

        for pids in my_frozen_pids:
            for pid in pids:
                assert_equal(
                    thrash_protect.ProcessSelector().readStat(pid).state, 'T')

        ## Unfreeze
        for i in range(0, 6):
            thrash_protect.unfreeze_something()

        assert_equal(log_frozen.call_args_list, frozen_calls)
        assert_equal(len(log_unfrozen.call_args_list),
                     len(log_frozen.call_args_list))

        thrash_protect.global_process_selector.update(
            current, thrash_protect.SystemState())

        ## once again, to make sure the "unfreeze_last_frozen" also gets excersised
        for i in range(0, 6):
            my_frozen_pids.append(thrash_protect.freeze_something())
        my_frozen_pids = [x for x in my_frozen_pids if x]
        assert (my_frozen_pids)
        ## Unfreeze
        for i in range(0, 6):
            thrash_protect.unfreeze_something()
Exemplo n.º 5
0
    def testSimpleFreezeUnfreeze(self, log_unfrozen, log_frozen):
        """This test should assert that suspension and resuming works.
        """
        prev=thrash_protect.SystemState()
        time.sleep(1)
        current=thrash_protect.SystemState()
        thrash_protect.global_process_selector.update(prev, current)
        ## Freezing something 6 times (to make sure we pass the default
        ## unfreeze_pop_ratio)
        my_frozen_pids = []
        for i in range(0,6):
            my_frozen_pids.append(thrash_protect.freeze_something())

        frozen_calls = log_frozen.call_args_list
        assert(len(frozen_calls) >= 6)

        my_frozen_pids = [x for x in my_frozen_pids if x]
        assert(my_frozen_pids)

        for pids in my_frozen_pids:
            for pid in pids:
                assert_equal(thrash_protect.ProcessSelector().readStat(pid).state, 'T')

        ## Unfreeze
        for i in range(0,6):
            thrash_protect.unfreeze_something()

        assert_equal(log_frozen.call_args_list, frozen_calls)
        assert_equal(len(log_unfrozen.call_args_list), len(log_frozen.call_args_list))
        
        thrash_protect.global_process_selector.update(current, thrash_protect.SystemState())

        ## once again, to make sure the "unfreeze_last_frozen" also gets excersised
        for i in range(0,6):
            my_frozen_pids.append(thrash_protect.freeze_something())
        my_frozen_pids = [x for x in my_frozen_pids if x]
        assert(my_frozen_pids)
        ## Unfreeze
        for i in range(0,6):
            thrash_protect.unfreeze_something()
    def testSimpleFreezeUnfreeze(self, open, kill, getsid, getpgid):
        """This test should assert that os.kill is called appropriately when
        freezing and unfreezing pids.  We'll keep it there as for now.
        Pure unit test, no side effects or system calls should be done
        here.
        """
        ## Freezing something 6 times (to make sure we pass the default
        ## unfreeze_pop_ratio)
        for i in range(1,7):
            thrash_protect.freeze_something(i*10)

        assert_equal(kill.call_args_list, [((i*10, signal.SIGSTOP),) for i in range(1,7)])

        ## Unfreeze
        for i in range(0,6):
            thrash_protect.unfreeze_something()

        ## we do no asserts of in which order the pids were reanimated.
        call_list = kill.call_args_list
        assert_equal(len(call_list), 12)
        for i in range(1,7):
            assert ((i*10, signal.SIGSTOP),) in call_list
Exemplo n.º 7
0
    def testSimpleFreezeUnfreeze(self, open, kill, getsid, getpgid):
        """This test should assert that os.kill is called appropriately when
        freezing and unfreezing pids.  We'll keep it there as for now.
        Pure unit test, no side effects or system calls should be done
        here.
        """
        ## Freezing something 6 times (to make sure we pass the default
        ## unfreeze_pop_ratio)
        for i in range(1, 7):
            thrash_protect.freeze_something(i * 10)

        assert_equal(kill.call_args_list,
                     [((i * 10, signal.SIGSTOP), ) for i in range(1, 7)])

        ## Unfreeze
        for i in range(0, 6):
            thrash_protect.unfreeze_something()

        ## we do no asserts of in which order the pids were reanimated.
        call_list = kill.call_args_list
        assert_equal(len(call_list), 12)
        for i in range(1, 7):
            assert ((i * 10, signal.SIGSTOP), ) in call_list