def testReadStat(self): stat_ret = thrash_protect.ProcessSelector().readStat('/proc/10/stat') assert_equal(stat_ret.cmd, 'cat') assert_equal(stat_ret.state, 'R') assert_equal(stat_ret.majflt, 321) assert_equal(stat_ret.ppid, 9) stat_ret2 = thrash_protect.ProcessSelector().readStat(10) assert_equal(stat_ret, stat_ret2)
def testCheckParents(self): assert_equal(thrash_protect.ProcessSelector().checkParents(9), (9, )) assert_equal(thrash_protect.ProcessSelector().checkParents(9, 16077), (9, )) assert_equal(thrash_protect.ProcessSelector().checkParents(10), (9, 10)) assert_equal(thrash_protect.ProcessSelector().checkParents(10, 9), (9, 10))
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()