コード例 #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))
コード例 #2
0
 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])
コード例 #3
0
ファイル: test_state.py プロジェクト: c7h/process_scheduler
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)