Esempio n. 1
0
 def setUp(self):
     #SystemTimer._drop() # just to be sure there is no old timer instance left
     self.st = SystemTimer(10)
     self.queue = EAQueue()
     self.pcbs = (
         PCB(Process("A"), state=State.L), #they need to be in state L or W
         PCB(Process("B"), state=State.W)
     )
Esempio n. 2
0
class EAQueueTestCase(unittest.TestCase):
    def setUp(self):
        #SystemTimer._drop() # just to be sure there is no old timer instance left
        self.st = SystemTimer(10)
        self.queue = EAQueue()
        self.pcbs = (
            PCB(Process("A"), state=State.L), #they need to be in state L or W
            PCB(Process("B"), state=State.W)
        )

    def test_appendToQueue(self):
        """
        append processes and check status after appending:
        """
        for p in self.pcbs:
            self.queue.append(p)

        processes = self.queue.processes
        for i in processes:
            #every process should be in state B
            self.assertTrue(i.state, State.B)

    def test_work_in_append_queue(self):
        """
        after a schedule step is done, we decrease the wait time on every waiting section
        """
        p = PCB(Process("P"), state=State.L)
        p.process.workplan = Workplan().work(10).wait(20)
        p.process.doWork() # get rid of the work section
        self.queue.append(p)

        #and now tick
        st = SystemTimer(timeunit=10)
        st.tick() # tick will trigger a process.work() on every waiting process
        #p.process.work(10)
        for p in self.queue:
            # 10 waits should be left...
            self.assertEqual(p.process.workplan.pop().duration, 10)

    def test_notify(self):
        p = PCB(Process("Res_notify"), state=State.L)
        print ProcessManager().jobs

        p.process.workplan = Workplan().work(20).wait(15).work(25)
        p.process.doWork(20) # get rid of work section
        p.setWaiting()

        #wait(15) in queue
        self.queue.append(p)

        st = SystemTimer(timeunit=10)
        st.tick() #wait(5) left
        self.assertListEqual(self.queue.pickup_ready_processes(), [])
        st.tick() #should tick 5
        # process should be in queue
        ready_p_from_queue = self.queue.pickup_ready_processes()
        self.assertListEqual(ready_p_from_queue, [p])

    def test_notify_finishProcess(self):
        p = PCB(Process("Wait_finish"), state=State.L)

        p.process.workplan = Workplan().work(20).wait(10)
        p.process.doWork(20)  # get rid of work section
        print p.process.name, "ist nun", p.process.workplan
        self.queue.append(p)  # should also set p to waiting state
        print "Warteschlange:", self.queue
        self.assertRaises(ProcessTerminatedMessage, p.process.doWork, 15)
        print "Warteschlange:", self.queue


    def tearDown(self):
        ProcessManager._drop()
        SystemTimer._drop()