class RRStrategyTestCase(BaseScenario): def setUp(self): super(RRStrategyTestCase, self).setUp() self.se = StrategyEvaluator() self.pe = ProcessEvaluator() def _run_rr(self, quantum, timeslice): strategy = RoundRobin(quantum=quantum, timeslice=timeslice) scheduler = Scheduler(strategy=strategy) scheduler.initialize("FOO") scheduler.run() def test_RR_t10_q1(self): self._run_rr(quantum=1, timeslice=10) start, end = self.pe.getPeriodForPCB("FOO") self.assertEqual(end, 30) # work(10),launch(BAR),ready(10),work(10) -> 30 def test_RR_t10_q2(self): self._run_rr(quantum=2, timeslice=10) start, end = self.pe.getPeriodForPCB("FOO") self.assertEqual(end, 20) # work(10),launch(BAR),work(10) -> 20 def test_RR_t5_q1(self): self._run_rr(quantum=1, timeslice=5) start, end = self.pe.getPeriodForPCB("BAR") self.assertTupleEqual((10, 25), (start, end)) def test_RR_t5_q2(self): self._run_rr(quantum=2, timeslice=5) start, end = self.pe.getPeriodForPCB("FOO") self.assertTupleEqual((0, 30), (start, end))
def __calculate_left_work(self, pcb): """ we have to find out how much cpu-time is left in the workplan :param pcb: the PCB of the target Process :return: int. left service time """ pe = ProcessEvaluator() # we 'abuse' the process evaluator # @TODO: change this. The evaluator module is not meant to be used this way service_time = pe.getServiceTime(pcb) return service_time
def setUp(self): super(ProcessEvaluatorTestCase, self).setUp() scheduler = SchedulerFactory.getScheduler("FiFo", timeslice=10) scheduler.initialize("A") scheduler.run() self.evaluator = ProcessEvaluator()
class SJFStrategyTestCase(BaseScenario): def setUp(self): super(SJFStrategyTestCase, self).setUp() self.pe = ProcessEvaluator() def run_scheduler(self): strategy = ShortesJobFirst() scheduler = Scheduler(strategy=strategy) scheduler.initialize("FOO") scheduler.run() def test_SJF_01(self): self.run_scheduler() start, end = self.pe.getPeriodForPCB("FOO") self.assertTupleEqual((0,20), (start, end))
class ProcessEvaluatorComplexTestCase(FiFoScenario2): def setUp(self): super(ProcessEvaluatorComplexTestCase, self).setUp() scheduler = SchedulerFactory.getScheduler("FiFo", timeslice=10) scheduler.initialize("A") scheduler.run() self.evaluator = ProcessEvaluator() def test_getReadySectionsForPCB_01(self): # process A got a ready section at 30 - 35 after wait # and another at the beginning with duration 0 (process got active) ready_secs = self.evaluator._getReadySectionsForPCB("A") self.assertListEqual(ready_secs, [Ready(0), Ready(5)]) def test_getReadySectionsForPCB_02(self): # process B got a ready section at 10-20 after launch ready_secs = self.evaluator._getReadySectionsForPCB("B") self.assertEqual(len(ready_secs), 1) def test_geResponseTime_01(self): response_time = self.evaluator.getResponseTime("A") self.assertListEqual([0, 5], response_time) def test_geResponseTime_02(self): response_time = self.evaluator.getResponseTime("B") self.assertListEqual([10], response_time) def test_getTurnaroundTime_01(self): turnaroundtime = self.evaluator.getTurnaroundTime("A") self.assertEqual(turnaroundtime, 35) def test_getTurnaroundTime_02(self): turnaroundtime = self.evaluator.getTurnaroundTime("B") self.assertEqual(turnaroundtime, 15) def test_getWaitTime_01(self): waittime = self.evaluator.getWaitTime("A") self.assertEqual(waittime, 15) def test_getWaitTime_02(self): waittime = self.evaluator.getWaitTime("B") self.assertEqual(waittime, 10)
class ProcessEvaluatorTestCase(SimpleFiFoScenario): def setUp(self): super(ProcessEvaluatorTestCase, self).setUp() scheduler = SchedulerFactory.getScheduler("FiFo", timeslice=10) scheduler.initialize("A") scheduler.run() self.evaluator = ProcessEvaluator() def test_getPeriodForPCB_01(self): # test get pcb by name period_B = self.evaluator.getPeriodForPCB("B") self.assertTupleEqual(period_B, (10, 20)) def test_getPeriodForPCB_02(self): period_A = self.evaluator.getPeriodForPCB("A") self.assertTupleEqual(period_A, (0, 35)) def test_getPeriodForPCB_03(self): # test get pcb by reference period_B = self.evaluator.getPeriodForPCB(self.pcb2) self.assertTupleEqual(period_B, (10, 20)) def test_getServiceTime_01(self): service_time = self.evaluator.getServiceTime("A") self.assertEqual(service_time, 20) def test_getServiceTime_02(self): service_time = self.evaluator.getServiceTime("B") self.assertEqual(service_time, 10) def test_getWaitTime_01(self): wait_time = self.evaluator.getWaitTime("A") self.assertEqual(wait_time, 15) def test_getWaitTime_02(self): wait_time = self.evaluator.getWaitTime("B") self.assertEqual(wait_time, 0)
def setUp(self): super(SJFStrategyTestCase, self).setUp() self.pe = ProcessEvaluator()