Esempio n. 1
0
 def test_dispatch_01(self):
     p1 = PCB(Process())
     cpu = CPU()
     p1.setReady() # change state from inactive to ready
     old_process = cpu.dispatch(p1)
     # because p1 is our first process, we assume that the old process is none
     self.assertIsInstance(old_process, type(None))
 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])
Esempio n. 3
0
    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])
Esempio n. 4
0
 def test_decrease_quantum_01(self):
     p = PCB(self.processes.pop(), quantum=10)
     p.decrease_quantum(10)
     self.assertEqual(p.quantum, 0)
Esempio n. 5
0
 def test_set_state_01(self):
     lp = PCB(Process('Laufender Prozess'))
     lp.state = State.B
     self.assertEqual(lp.state, State.B)
Esempio n. 6
0
 def setUp(self):
     ProcessManager().jobs = [] # make sure the manager is clean
     self.pcb = PCB(Process('state-test'))
Esempio n. 7
0
class StateMachineCase(unittest.TestCase):
    """
    See Abb.2.2 bachelors thesis Christoph Gerneth 2015 for process state model
    """
    def setUp(self):
        ProcessManager().jobs = [] # make sure the manager is clean
        self.pcb = PCB(Process('state-test'))

    def test_pcb_states_IB(self):
        #process is in state I by default
        self.pcb.setReady()
        pass

    def test_pcb_states_BL(self):
        self.pcb.state = State.B # initialize process
        self.pcb.setRunning()
        pass

    def test_valid_states(self):
        """
        covering all edges of the graph.
        """
        self.pcb.state = State.I # we start with an inactive state
        self.pcb.setReady()   # I -> B
        self.pcb.setRunning() # B -> L
        self.pcb.setWaiting() # L -> W
        self.pcb.setReady()   # W -> B
        self.pcb.setRunning() # B -> L (this needs to be done twice, sorry)
        self.pcb.setInactive()# L -> I

        self.assertIs(self.pcb.state, State.I)

    def test_valid_states_02(self):
        """
        should do nothing...
        """
        self.pcb.state = State.I
        self.pcb.setInactive()
        pass


    def test_invalid_01(self):
        self.pcb.state = State.I
        self.assertRaises(RuntimeError, self.pcb.setRunning)