def test_time_since_dispatch_01(self): cpu = CPU() a_ready_pcb = self.pcbs.pop().setReady() cpu.dispatch(pcb=a_ready_pcb) SystemTimer().tick() SystemTimer().tick() self.assertEqual(cpu.time_since_dispatch, 20)
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_time_since_dispatch_02(self): """now we do 10 dispatches a 20ms""" cpu = CPU() p1 = self.pcbs.pop().setReady() p2 = self.pcbs.pop().setReady() time_0 = cpu.time_since_dispatch #let it work 10s cpu.dispatch(p1) SystemTimer().tick() time_1 = cpu.time_since_dispatch #and now 20 cpu.dispatch(p2) SystemTimer().tick() SystemTimer().tick() time_2 = cpu.time_since_dispatch self.assertEqual(time_1, 10) self.assertEqual(time_2, 20)
def test_dispatch_02(self): """ do ten dispatches and check if the last process is the running one :return: """ cpu = CPU() for pcb in self.pcbs: pcb.setReady() returning_pcb = cpu.dispatch(pcb) if isinstance(returning_pcb,PCB): returning_pcb.setInactive() else: #first process in cpu is None, because it is uninitialized pass self.assertEqual(cpu.running_process, self.pcbs[-1])
def test_dispatchCounter(self): cpu = CPU() for pcb in self.pcbs: pcb.setReady() cpu.dispatch(pcb) # dispatch ten times self.assertEqual(cpu.dispatch_counter, 10)