Exemplo n.º 1
0
 def testRun_01(self):
     scheduler = Scheduler(FiFoStubStrategy())
     scheduler.initialize("A")
     print 'run normal run 1...'
     scheduler.run()
     process = ProcessManager().getProcessByName("A")
     self.assertEqual(process.state, State.I)
class FiFoStrateyTestCase(BaseScenario):
    """
    expected result:
    Foo|----
    Bar|  | --
       0  10  30
    """

    def setUp(self):
        super(FiFoStrateyTestCase, self).setUp()
        strategy = FiFo()
        self.scheduler = Scheduler(strategy=strategy)
        self.scheduler.initialize("FOO")

    def test_function01(self):
        self.scheduler.run()
Exemplo n.º 3
0
    def setUp(self):
        process2 = Process('02')
        process2.workplan = Workplan().work(90)
        self.pcb2 = PCB(process2, state=State.I)

        process1 = Process('01')
        process1.workplan = Workplan().launch('02').wait(20).work(10)

        self.pcb1 = PCB(process1, state=State.B)

        self.scheduler = Scheduler(FiFoStubStrategy())
Exemplo n.º 4
0
    def test_get_from_ready_queue(self):
        scheduler = Scheduler(FiFoStubStrategy())
        scheduler.addToReadyQueue(self.pcb2)

        process = scheduler.popFromReadyQueue()
        self.assertEqual(id(process), id(self.pcb2))
Exemplo n.º 5
0
    def test_append_to_queue(self):
        scheduler = Scheduler(FiFoStubStrategy())
        scheduler.addToReadyQueue(self.pcb1)  # process form state inactive get's ready
        scheduler.addToReadyQueue(self.pcb2)  # and now process 2

        self.assertListEqual([self.pcb1, self.pcb2], scheduler.ready_queue)
Exemplo n.º 6
0
 def test_scheduler_02(self):
     """Scheduling terminates at 110ms"""
     scheduler = Scheduler(FiFoStubStrategy())
     scheduler.initialize('01')
     scheduler.run()
     self.assertEqual(SystemTimer().timecounter, 110)
Exemplo n.º 7
0
 def test_scheduler_01(self):
     """If we schedule PCB02 only, it should terminate after 90ms"""
     scheduler = Scheduler(FiFoStubStrategy())
     scheduler.initialize('02')
     scheduler.run()
     self.assertEqual(SystemTimer().timecounter, 90)
Exemplo n.º 8
0
class SchedulerNewTestCase(unittest.TestCase):
    def setUp(self):
        process2 = Process('02')
        process2.workplan = Workplan().work(90)
        self.pcb2 = PCB(process2, state=State.I)

        process1 = Process('01')
        process1.workplan = Workplan().launch('02').wait(20).work(10)

        self.pcb1 = PCB(process1, state=State.B)

        self.scheduler = Scheduler(FiFoStubStrategy())

    def test_append_to_matching_queue_01(self):
        # test the processed get added to the right queues.
        self.pcb2.process.name = 'test_q_02'
        self.scheduler.addToMatchingQueue(self.pcb2)
        self.assertListEqual(self.scheduler.ready_queue, [self.pcb2])  # process should be in ready queue

    def test_append_to_matching_queue_02(self):
        # this time with launch section:
        self.scheduler.addToMatchingQueue(self.pcb1)  # first section is a launch(pcb2), add pcb2 to ready_queue
        self.assertListEqual(self.scheduler.ready_queue, [self.pcb2])

    def test_append_to_matching_queue_03(self):
        # process with empty workplan
        pcbX = PCB(Process("X"))
        self.assertRaises(IndexError, self.scheduler.addToMatchingQueue, pcbX)

    def test_append_to_matching_queue_04(self):
        # waiting section
        pcbX = PCB(Process("Wa_pro"))
        pcbX.process.workplan = Workplan().work(15).wait(20)
        pcbX.setReady()
        pcbX.process.doWork(15)  # get rid of work section       <--------|
        pcbX.setRunning()  # <- this should be done during scheduling --|
        self.scheduler.addToMatchingQueue(pcbX)
        self.assertListEqual(self.scheduler.ea_queues[0].queue, [pcbX])

    def test_scheduler_initialize_01(self):
        self.scheduler.initialize('01')
        self.scheduler.run()
        self.assertEqual(self.scheduler.cpu.running_process, None)
        # p1 section 1 is launch(02): should launch 02

    def test_scheduler_run_01(self):
        self.scheduler.initialize(self.pcb1.process.name)
        self.scheduler.run()

    def tearDown(self):
        ProcessManager._drop()
        SystemTimer._drop()
Exemplo n.º 9
0
 def test_time_since_last_dispatch(self):
     scheduler = Scheduler(FiFoStubStrategy())
     scheduler.addToReadyQueue(self.pcb2)
Exemplo n.º 10
0
 def test_MLsndFiFo_01(self):
     strategy = MLsecondFiFo()
     scheduler = Scheduler(strategy=strategy)
     scheduler.initialize("A")
     scheduler.run()
     pass
Exemplo n.º 11
0
 def run_scheduler(self):
     strategy = ShortesJobFirst()
     scheduler = Scheduler(strategy=strategy)
     scheduler.initialize("FOO")
     scheduler.run()
Exemplo n.º 12
0
 def _run_rr(self, quantum, timeslice):
     strategy = RoundRobin(quantum=quantum, timeslice=timeslice)
     scheduler = Scheduler(strategy=strategy)
     scheduler.initialize("FOO")
     scheduler.run()
Exemplo n.º 13
0
 def setUp(self):
     super(FiFoStrateyTestCase, self).setUp()
     strategy = FiFo()
     self.scheduler = Scheduler(strategy=strategy)
     self.scheduler.initialize("FOO")