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])
Beispiel #2
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)