def setUp(self): self._frame0 = Frame(0) self._frame1 = Frame(1) self._frame2 = Frame(2) self._frame3 = Frame(3) self._frame4 = Frame(4) self._frame5 = Frame(5) self._frame0.setPid(0) self._frame1.setPid(0) self._frame2.setPid(1) self._frame3.setPid(1) self._frame4.setPid(2) self._frame5.setPid(2) self._pcb0 = PCB(0) self._pcb1 = PCB(1) self._pcb2 = PCB(2) self._pageTable0 = PageTable(2) self._pageTable1 = PageTable(2) self._pageTable2 = PageTable(2) self._pcb0.setPages(self._pageTable0) self._pcb1.setPages(self._pageTable1) self._pcb2.setPages(self._pageTable2) self._pcbTable = PCBTable() self._pcbTable.addPCB(self._pcb0) self._pcbTable.addPCB(self._pcb1) self._pcbTable.addPCB(self._pcb2) self._pageTable0.getPage(0).setBDPhysicalMemory(self._frame0.getBD()) self._pageTable0.getPage(1).setBDPhysicalMemory(self._frame1.getBD()) self._pageTable1.getPage(0).setBDPhysicalMemory(self._frame2.getBD()) self._pageTable1.getPage(1).setBDPhysicalMemory(self._frame3.getBD()) self._pageTable2.getPage(0).setBDPhysicalMemory(self._frame4.getBD()) self._pageTable2.getPage(1).setBDPhysicalMemory(self._frame5.getBD()) self._algorithmClock = ClockPageReplacementAlgorithm()
class MyTestCase(unittest.TestCase): def setUp(self): #Se crea el pcb del primer programa self._program1 = Program("so.exe", [CPU(2), CPU(1)], 2) self._PCBProgram1 = PCB(0) self._PCBProgram1.set_priority(self._program1.get_priority()) # Se crea el pcb del segundo programa self._program2 = Program("exel.exe", [CPU(1), IO(1)], 1) self._PCBProgram2 = PCB(1) self._PCBProgram2.set_priority(self._program2.get_priority()) # Se crea el pcb del tercer programa self._program3 = Program("paint.exe", [CPU(4), IO(1)], 3) self._PCBProgram3 = PCB(2) self._PCBProgram3.set_priority(self._program3.get_priority()) # Se crea el pcb del tercer programa self._program4 = Program("word.exe", [CPU(4), IO(1)], 2) self._PCBProgram4 = PCB(3) self._PCBProgram4.set_priority(self._program4.get_priority()) # Se inicializa al SchedulerPriorityPreventive con un aging de 3 self._pcbTable = PCBTable() self._pcbTable.addPCB(self._PCBProgram1) self._pcbTable.addPCB(self._PCBProgram2) self._pcbTable.addPCB(self._PCBProgram3) self._pcbTable.addPCB(self._PCBProgram4) self._aging = 3 self._shedulerTest = SchedulerPriorityPreemptive( self._pcbTable, self._aging) # Se agregan los pid, prioridad y los primeros burst de los tres programas self._shedulerTest.add(self._PCBProgram1) self._shedulerTest.add(self._PCBProgram2) self._shedulerTest.add(self._PCBProgram3) self._shedulerTest.add(self._PCBProgram4) def testSchedulerPriorityPreventive(self): # Se comprueba que se desencola primero el pid del programa 2, porque es el de menor prioridad self.assertEqual(self._shedulerTest.pop(), self._PCBProgram2.get_pid()) # Se comprueba que se desencola el pid del programa 1, porque es siguiente de menor prioridad self.assertEqual(self._shedulerTest.pop(), self._PCBProgram1.get_pid()) # y la prioridad del programa 1 sigue siendo de 2 self.assertEqual(self._PCBProgram1.get_priority(), 2) # Se comprueba que se desencola el pid del programa 4, porque es siguiente de menor prioridad self.assertEqual(self._shedulerTest.pop(), self._PCBProgram4.get_pid()) # el aging llego a 3 # y la prioridad del programa 1 ahora es de 2 por el aging del scheduler self.assertEqual(self._PCBProgram4.get_priority(), 1) # Se comprueba que se desencola el pid del programa 3, porque es siguiente de menor prioridad self.assertEqual(self._shedulerTest.pop(), self._PCBProgram3.get_pid()) # y la prioridad del programa 1 ahora es de 2 por el aging del scheduler self.assertEqual(self._PCBProgram3.get_priority(), 2)
def setUp(self): #Se crea el pcb del primer programa self._program1 = Program("so.exe", [CPU(2), CPU(1)], 2) self._PCBProgram1 = PCB(0) self._PCBProgram1.set_priority(self._program1.get_priority()) # Se crea el pcb del segundo programa self._program2 = Program("exel.exe", [CPU(1), IO(1)], 1) self._PCBProgram2 = PCB(1) self._PCBProgram2.set_priority(self._program2.get_priority()) # Se crea el pcb del tercer programa self._program3 = Program("paint.exe", [CPU(4), IO(1)], 3) self._PCBProgram3 = PCB(2) self._PCBProgram3.set_priority(self._program3.get_priority()) # Se crea el pcb del tercer programa self._program4 = Program("word.exe", [CPU(4), IO(1)], 2) self._PCBProgram4 = PCB(3) self._PCBProgram4.set_priority(self._program4.get_priority()) # Se inicializa al SchedulerPriorityPreventive con un aging de 3 self._pcbTable = PCBTable() self._pcbTable.addPCB(self._PCBProgram1) self._pcbTable.addPCB(self._PCBProgram2) self._pcbTable.addPCB(self._PCBProgram3) self._pcbTable.addPCB(self._PCBProgram4) self._aging = 3 self._shedulerTest = SchedulerPriorityPreemptive( self._pcbTable, self._aging) # Se agregan los pid, prioridad y los primeros burst de los tres programas self._shedulerTest.add(self._PCBProgram1) self._shedulerTest.add(self._PCBProgram2) self._shedulerTest.add(self._PCBProgram3) self._shedulerTest.add(self._PCBProgram4)
def __init__(self, disco): self._disco = disco self._memory = Memory(32) self._pcbTable = PCBTable() self._intManager = IntManager() self._memoryManager = MemoryManagerContinuousAssignmentBestFit(self._memory, self._pcbTable, self._intManager, 1) self._mmu = Mmu(self._memory) self._loader = LoaderBlocks(self._memory, self._mmu, disco, self._memoryManager) self._scheduler = SchedulerSJFPreemptive() self._timer = None self._cpu = Cpu(self._mmu, self._intManager) self._dispatcher = Dispatcher(self._mmu, self._cpu) self._deviceManager = DeviceManager(self._intManager) self._intManager.setInterruptions(self._loader, self._dispatcher, self._scheduler, self._pcbTable, self._deviceManager, self._memoryManager, self._timer) self._newPrograms = NewPrograms(self._intManager) self._clock = Clock(self._cpu, self._deviceManager, self._timer, self._newPrograms)
def setUp(self): self._mm = MemoryManagerContinuousAssignmentFirstFit( Memory(100), PCBTable(), IntManager(), 4) self._block1 = Block(0, 9, 0) self._block2 = Block(10, 24, 1) self._block3 = Block(25, 44, 2) self._block4 = Block(45, 54, 3) self._block5 = Block(55, 64, 4) self._mm.getUsedBlocks().append(self._block4) self._mm.getUsedBlocks().append(self._block3) self._mm.getUsedBlocks().append(self._block1) self._mm.getUsedBlocks().append(self._block5) self._mm.getUsedBlocks().append(self._block2) self._mm.orderingUsedBlocks()
def __init__(self, disco): self._disco = disco self._pcbTable = PCBTable() self._schedulerFactory = SchedulersFactory(self._pcbTable) self._scheduler = self._schedulerFactory.getScheduler() self._intManager = IntManager() self._memoryFactory = MemoryFactory(self._pcbTable, self._intManager, disco) self._memory = self._memoryFactory.getMemory() self._memoryManager = self._memoryFactory.getMemoryManager() self._mmu = self._memoryFactory.getMmu() self._loader = self._memoryFactory.getLoader() self._timer = self._schedulerFactory.getTimer(self._intManager) self._cpu = Cpu(self._mmu, self._intManager) self._dispatcher = Dispatcher(self._mmu, self._cpu) self._deviceManager = DeviceManager(self._intManager) self._intManager.setInterruptions(self._loader, self._dispatcher, self._scheduler, self._pcbTable, self._deviceManager, self._memoryManager, self._timer) self._newPrograms = NewPrograms(self._intManager) self._clock = Clock(self._cpu, self._deviceManager, self._timer, self._newPrograms)
def __init__(self, disco): self._disco = disco self._memory = Memory(8) self._pcbTable = PCBTable() self._intManager = IntManager() sizeFrame = 4 pageReplacementAlgorithm = SecondChancePageReplacementAlgorithm() self._swap = Swap(sizeFrame) self._memoryManager = MemoryManagerPaging(self._memory, sizeFrame, self._pcbTable, self._swap, pageReplacementAlgorithm) self._mmu = MmuPages(self._memory, sizeFrame, self._intManager) self._loader = LoaderPages(self._memory, self._mmu, self._disco, self._memoryManager, self._swap) self._memoryManager.setLoader(self._loader) # Es para no hacer la interrupcion swapIN (el memoryManager y el loader se conocen mutuamente) self._scheduler = SchedulerPriorityPreemptive(self._pcbTable, 80) self._timer = None self._cpu = Cpu(self._mmu, self._intManager) self._dispatcher = Dispatcher(self._mmu, self._cpu) self._deviceManager = DeviceManager(self._intManager) self._intManager.setInterruptions(self._loader, self._dispatcher, self._scheduler, self._pcbTable, self._deviceManager, self._memoryManager, self._timer) self._newPrograms = NewPrograms(self._intManager) self._clock = Clock(self._cpu, self._deviceManager, self._timer, self._newPrograms)
class tester(unittest.TestCase): def setUp(self): self._frame0 = Frame(0) self._frame1 = Frame(1) self._frame2 = Frame(2) self._frame3 = Frame(3) self._frame4 = Frame(4) self._frame5 = Frame(5) self._frame0.setPid(0) self._frame1.setPid(0) self._frame2.setPid(1) self._frame3.setPid(1) self._frame4.setPid(2) self._frame5.setPid(2) self._pcb0 = PCB(0) self._pcb1 = PCB(1) self._pcb2 = PCB(2) self._pageTable0 = PageTable(2) self._pageTable1 = PageTable(2) self._pageTable2 = PageTable(2) self._pcb0.setPages(self._pageTable0) self._pcb1.setPages(self._pageTable1) self._pcb2.setPages(self._pageTable2) self._pcbTable = PCBTable() self._pcbTable.addPCB(self._pcb0) self._pcbTable.addPCB(self._pcb1) self._pcbTable.addPCB(self._pcb2) self._pageTable0.getPage(0).setBDPhysicalMemory(self._frame0.getBD()) self._pageTable0.getPage(1).setBDPhysicalMemory(self._frame1.getBD()) self._pageTable1.getPage(0).setBDPhysicalMemory(self._frame2.getBD()) self._pageTable1.getPage(1).setBDPhysicalMemory(self._frame3.getBD()) self._pageTable2.getPage(0).setBDPhysicalMemory(self._frame4.getBD()) self._pageTable2.getPage(1).setBDPhysicalMemory(self._frame5.getBD()) self._algorithmClock = ClockPageReplacementAlgorithm() def test000SeAgregaUnFrameAAlAlgoritmoReloj(self): self._algorithmClock.add(self._frame0) self.assertEqual(1, self._algorithmClock.getSizeFrameClock()) self.assertEqual(self._frame0, self._frame0.getNextFrameClock()) self.assertEqual(self._frame0, self._frame0.getPreviousFrameClock()) self.assertEqual(self._frame0, self._algorithmClock.getTarget()) def test001SeAgregaDosElementosYSePreguntaDondeApuntaElSegundoElemento(self): self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) self.assertEqual(self._frame0, self._frame1.getNextFrameClock()) self.assertEqual(self._frame0, self._frame1.getPreviousFrameClock()) self.assertEqual(self._frame1, self._frame0.getNextFrameClock()) self.assertEqual(self._frame1, self._frame0.getPreviousFrameClock()) self.assertEqual(2, self._algorithmClock.getSizeFrameClock()) def test002SeAgreganDosElemntosYLuegoSeBorraUnoQuedandoSOloUNo(self): self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) self._algorithmClock.removeFrame(self._frame0) self.assertEqual(1, self._algorithmClock.getSizeFrameClock()) def test003SeAgreganDosElementosYLuegoDeBorrarUnoQuedaComoTargetElFrame1(self): self._algorithmClock.add(self._frame0) self.assertEqual(self._frame0.getNextFrameClock(), self._frame0.getPreviousFrameClock()) self._algorithmClock.add(self._frame1) self.assertEqual(self._frame0.getNextFrameClock(), self._frame0.getPreviousFrameClock()) self._algorithmClock.removeFrame(self._frame0) self.assertEqual(1, self._algorithmClock.getSizeFrameClock()) self.assertEqual(self._frame1, self._algorithmClock.getTarget()) def test004DespuesDeAgregarDosElementoElTargetQuedoEnMenosUno(self): self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) self._algorithmClock.removeFrame(self._frame0) self._algorithmClock.removeFrame(self._frame1) self.assertEqual(0, self._algorithmClock.getSizeFrameClock()) self.assertEqual(-1, self._algorithmClock.getTarget()) def test005EntreDosMarcosVictimasSeleccionaAlMarcoUnoPorTenerBitReferenciaEn0(self): self._algorithmClock.add(self._frame0) self._frame0.setReferenceBit(1) self._algorithmClock.add(self._frame1) self._frame1.setReferenceBit(0) victim=self._algorithmClock.getVictim() self.assertEqual(self._frame1, victim) self.assertEqual(1, self._algorithmClock.getSizeFrameClock()) def test006EntreDosMarcosVictimasSeleccionaAlMarcoCeroPorqueLosDosFrameTenianBitReferenciaEn1YAlDarLaVueltaSeleccionaALcero(self): self._algorithmClock.add(self._frame0) self._frame0.setReferenceBit(1) self._algorithmClock.add(self._frame1) self._frame1.setReferenceBit(1) victim=self._algorithmClock.getVictim() self.assertEqual(self._frame0,victim) self.assertEqual(1, self._algorithmClock.getSizeFrameClock()) def test007ElAlgoritmoRetornaUnaListaDeLosDosFrameQueFormanPArteDelReloj(self): self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) listTest=[] listTest.append(self._frame0) listTest.append(self._frame1) self.assertEqual(2, len(self._algorithmClock.getUsedFrames())) self.assertListEqual(listTest, self._algorithmClock.getUsedFrames()) def test008ElAlgoritmoSabeBuscarUnFrame(self): self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) self._algorithmClock.add(self._frame2) self.assertEqual(self._frame0, self._algorithmClock.searchFrame(0)) self.assertEqual(3, self._algorithmClock.getSizeFrameClock()) self.assertEqual(self._frame0, self._algorithmClock.getTarget()) self.assertEqual(self._frame1, self._algorithmClock.searchFrame(1)) self.assertEqual(3, self._algorithmClock.getSizeFrameClock()) self.assertEqual(self._frame0, self._algorithmClock.getTarget()) self.assertEqual(self._frame2, self._algorithmClock.searchFrame(2)) self.assertEqual(3, self._algorithmClock.getSizeFrameClock()) self.assertEqual(self._frame0, self._algorithmClock.getTarget()) def test009ElAlgoritmoTenia3FrameConBitDeReferenciaEn0DespuesDelUpdateFrameQuedaronen1SuBitReferencia(self): self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) self._algorithmClock.add(self._frame2) self._frame0.setReferenceBit(0) self._frame1.setReferenceBit(0) self._frame2.setReferenceBit(0) self._pageTable0.getPage(0).setReferenceBit(1) self._pageTable0.getPage(1).setReferenceBit(1) self._pageTable1.getPage(0).setReferenceBit(1) self._algorithmClock.updateFrame(self._pcbTable) self.assertEqual(1,self._frame0.getReferenceBit()) self.assertEqual(1,self._frame1.getReferenceBit()) def test010SeCompruebaAgregandoTresFrames(self): self._algorithmClock.add(self._frame5) self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) self.assertEqual(3, self._algorithmClock.getSizeFrameClock()) self.assertEqual(self._frame0.getNextFrameClock(), self._frame1) self.assertEqual(self._frame0.getPreviousFrameClock(), self._frame5) self.assertEqual(self._frame5.getNextFrameClock(), self._frame0) self.assertEqual(self._frame5.getPreviousFrameClock(), self._frame1) self.assertEqual(self._frame1.getNextFrameClock(), self._frame5) self.assertEqual(self._frame1.getPreviousFrameClock(), self._frame0) def test011ClockPageReplacementAlgorithmWithCounterWithThreeFrames(self): self._algorithmClock.add(self._frame5) self._algorithmClock.add(self._frame0) self._algorithmClock.add(self._frame1) # Se lleno la memoria # usedFrames: 5 0 1 self.assertEqual(1, self._frame5.getReferenceBit()) self.assertEqual(1, self._frame0.getReferenceBit()) self.assertEqual(1, self._frame1.getReferenceBit()) # PageFault: Se agrega el 2 y sale el 5 self.assertEqual(5, self._algorithmClock.getVictim().getBD()) self._algorithmClock.add(self._frame2) # usedFrames: 0 1 2 self.assertEqual(0, self._frame0.getReferenceBit()) self.assertEqual(0, self._frame1.getReferenceBit()) self.assertEqual(1, self._frame2.getReferenceBit()) # Se accede al 0 self._pageTable0.getPage(0).setReferenceBit(1) self._algorithmClock.updateFrame(self._pcbTable) # usedFrames: 0 1 2 self.assertEqual(1, self._frame0.getReferenceBit()) self.assertEqual(0, self._frame1.getReferenceBit()) self.assertEqual(1, self._frame2.getReferenceBit()) # PageFault: Se agrega el 3 y sale el 1 self.assertEqual(1, self._algorithmClock.getVictim().getBD()) self._algorithmClock.add(self._frame3) # usedFrames: 2 0 3 self.assertEqual(1, self._frame2.getReferenceBit()) self.assertEqual(0, self._frame0.getReferenceBit()) self.assertEqual(1, self._frame3.getReferenceBit()) # PageFault: Se agrega el 4 y sale el 0 self.assertEqual(0, self._algorithmClock.getVictim().getBD()) self._algorithmClock.add(self._frame4) # usedFrames: 3 2 4 self.assertEqual(1, self._frame3.getReferenceBit()) self.assertEqual(0, self._frame2.getReferenceBit()) self.assertEqual(1, self._frame4.getReferenceBit()) # Se accede al 2 self._pageTable1.getPage(0).setReferenceBit(1) self._algorithmClock.updateFrame(self._pcbTable) # usedFrames: 3 2 4 self.assertEqual(1, self._frame3.getReferenceBit()) self.assertEqual(1, self._frame2.getReferenceBit()) self.assertEqual(1, self._frame4.getReferenceBit()) # Se accede al 3 self._pageTable1.getPage(1).setReferenceBit(1) self._algorithmClock.updateFrame(self._pcbTable) # usedFrames: 3 2 4 self.assertEqual(1, self._frame3.getReferenceBit()) self.assertEqual(1, self._frame2.getReferenceBit()) self.assertEqual(1, self._frame4.getReferenceBit()) # PageFault: Se agrega el 0 y sale el 3 self.assertEqual(3, self._algorithmClock.getVictim().getBD()) self._algorithmClock.add(self._frame0) # usedFrames: 2 4 0 self.assertEqual(0, self._frame2.getReferenceBit()) self.assertEqual(0, self._frame4.getReferenceBit()) self.assertEqual(1, self._frame0.getReferenceBit()) # PageFault: Se agrega el 3 y sale el 2 self.assertEqual(2, self._algorithmClock.getVictim().getBD()) self._algorithmClock.add(self._frame3) # usedFrames: 4 0 3 self.assertEqual(0, self._frame4.getReferenceBit()) self.assertEqual(1, self._frame0.getReferenceBit()) self.assertEqual(1, self._frame3.getReferenceBit()) # PageFault: Se agrega el 2 y sale el 4 self.assertEqual(4, self._algorithmClock.getVictim().getBD()) self._algorithmClock.add(self._frame2) # usedFrames: 0 3 2 self.assertEqual(1, self._frame0.getReferenceBit()) self.assertEqual(1, self._frame3.getReferenceBit()) self.assertEqual(1, self._frame2.getReferenceBit()) # PageFault: Se agrega el 1 y sale el 3 self.assertEqual(0, self._algorithmClock.getVictim().getBD()) self._algorithmClock.add(self._frame1) # usedFrames: 3 2 1 self.assertEqual(0, self._frame3.getReferenceBit()) self.assertEqual(0, self._frame2.getReferenceBit()) self.assertEqual(1, self._frame1.getReferenceBit())
def setUp(self): # Se crea al pcbTable self._pcbTable = PCBTable() # Se crea el pcb del primer programa self._program1 = Program("so.exe", [CPU(10)], 2) self._PCBProgram1 = PCB(0) # Se crea el pcb del segundo programa self._program2 = Program("exel.exe", [IO(1), CPU(9)], 1) self._PCBProgram2 = PCB(1) # Se crea el pcb del tercer programa self._program3 = Program("paint.exe", [CPU(10)], 3) self._PCBProgram3 = PCB(2) # Se crea el pcb del cuarto programa self._program4 = Program("word.exe", [CPU(10)], 2) self._PCBProgram4 = PCB(3) # Se crea el pcb del quint programa self._program5 = Program("pycharm.exe", [CPU(10)], 2) self._PCBProgram5 = PCB(4) # Se crea el pcb del sexto programa self._program6 = Program("pharo.exe", [CPU(60)], 2) self._PCBProgram6 = PCB(5) self._pcbTable.addPCB(self._PCBProgram1) self._pcbTable.addPCB(self._PCBProgram2) self._pcbTable.addPCB(self._PCBProgram3) self._pcbTable.addPCB(self._PCBProgram4) self._pcbTable.addPCB(self._PCBProgram5) self._pcbTable.addPCB(self._PCBProgram6) # Se inicializa la memoria self._memory = Memory(100) # Se cargan los gprogramas al disco self._disk = Disco() ls = [ self._program1, self._program2, "so.pdf", self._program3, self._program4, self._program5, self._program6 ] self._disk.add_files(ls) # Se inicializa el intManager, memoryManager, y el Loader self._intmanager = IntManager() self._memoryManager = MemoryManagerContinuousAssignmentFirstFit( self._memory, self._pcbTable, self._intmanager, 2) self._loader = LoaderBlocks(self._memory, Mmu(self._memory), self._disk, self._memoryManager) self._intmanager.setInterruptions(self._loader, mock.Mock(), mock.Mock(), self._pcbTable, mock.Mock(), self._memoryManager, mock.Mock()) # Se cargan cinco programas a memoria self._loader.load(self._PCBProgram1, self._program1.name()) self._loader.load(self._PCBProgram2, self._program2.name()) self._loader.load(self._PCBProgram3, self._program3.name()) self._loader.load(self._PCBProgram4, self._program4.name()) self._loader.load(self._PCBProgram5, self._program5.name())
class MyTestCase(unittest.TestCase): def setUp(self): # Se crea al pcbTable self._pcbTable = PCBTable() # Se crea el pcb del primer programa self._program1 = Program("so.exe", [CPU(10)], 2) self._PCBProgram1 = PCB(0) # Se crea el pcb del segundo programa self._program2 = Program("exel.exe", [IO(1), CPU(9)], 1) self._PCBProgram2 = PCB(1) # Se crea el pcb del tercer programa self._program3 = Program("paint.exe", [CPU(10)], 3) self._PCBProgram3 = PCB(2) # Se crea el pcb del cuarto programa self._program4 = Program("word.exe", [CPU(10)], 2) self._PCBProgram4 = PCB(3) # Se crea el pcb del quint programa self._program5 = Program("pycharm.exe", [CPU(10)], 2) self._PCBProgram5 = PCB(4) # Se crea el pcb del sexto programa self._program6 = Program("pharo.exe", [CPU(60)], 2) self._PCBProgram6 = PCB(5) self._pcbTable.addPCB(self._PCBProgram1) self._pcbTable.addPCB(self._PCBProgram2) self._pcbTable.addPCB(self._PCBProgram3) self._pcbTable.addPCB(self._PCBProgram4) self._pcbTable.addPCB(self._PCBProgram5) self._pcbTable.addPCB(self._PCBProgram6) # Se inicializa la memoria self._memory = Memory(100) # Se cargan los gprogramas al disco self._disk = Disco() ls = [ self._program1, self._program2, "so.pdf", self._program3, self._program4, self._program5, self._program6 ] self._disk.add_files(ls) # Se inicializa el intManager, memoryManager, y el Loader self._intmanager = IntManager() self._memoryManager = MemoryManagerContinuousAssignmentFirstFit( self._memory, self._pcbTable, self._intmanager, 2) self._loader = LoaderBlocks(self._memory, Mmu(self._memory), self._disk, self._memoryManager) self._intmanager.setInterruptions(self._loader, mock.Mock(), mock.Mock(), self._pcbTable, mock.Mock(), self._memoryManager, mock.Mock()) # Se cargan cinco programas a memoria self._loader.load(self._PCBProgram1, self._program1.name()) self._loader.load(self._PCBProgram2, self._program2.name()) self._loader.load(self._PCBProgram3, self._program3.name()) self._loader.load(self._PCBProgram4, self._program4.name()) self._loader.load(self._PCBProgram5, self._program5.name()) def testCompactacion(self): self.assertEqual(1, len(self._memoryManager.getFreeBlocks())) self.assertEqual(5, len(self._memoryManager.getUsedBlocks())) self._loader.freeMemory(self._PCBProgram1) self._loader.freeMemory(self._PCBProgram4) self.assertEqual(3, len(self._memoryManager.getFreeBlocks())) self.assertEqual(3, len(self._memoryManager.getUsedBlocks())) self.assertFalse(self._memoryManager.thereIsBlockForProgram(60)) self.assertFalse(self._memory.get(0).isIO()) self.assertEqual(67, self._memoryManager.getFree()) # compacta self._loader.load(self._PCBProgram6, self._program6.name()) self.assertTrue(self._memory.get(0).isIO()) self.assertEqual(1, len(self._memoryManager.getFreeBlocks())) self.assertEqual(4, len(self._memoryManager.getUsedBlocks())) self.assertEqual(6, self._memoryManager.getFree()) def testCompactacion2(self): self.assertEqual(5, len(self._loader.getMemoryManager().getUsedBlocks())) self.assertEquals(1, len(self._loader.getMemoryManager().getFreeBlocks())) self._loader.freeMemory(self._PCBProgram1) self._loader.freeMemory(self._PCBProgram4) sizeAntesCompac = self._memoryManager.getFree() self.assertEqual(3, len(self._memoryManager.getFreeBlocks())) self.assertEqual(3, len(self._memoryManager.getUsedBlocks())) self._memoryManager.toCompact() self.assertEqual(1, len(self._memoryManager.getFreeBlocks())) self.assertEqual(3, len(self._memoryManager.getUsedBlocks())) sizeDepuesCompac = self._memoryManager.getFree() self.assertTrue(self._memory.get(0).isIO()) self.assertEqual(sizeAntesCompac, sizeDepuesCompac)
#!/usr/bin/env python # -*- coding: utf-8 -*-s import unittest from Prototipo.pcb import PCB from Prototipo.pcbTable import PCBTable pcb1 = PCB(1) pcb2 = PCB(2) pcbt = PCBTable() pcbt.addPCB(pcb1) pcbt.addPCB(pcb2) class tester(unittest.TestCase): def test_1(self): self.assertEqual(pcb1, pcbt.lookUpPCB(1)) self.assertEqual(pcb2, pcbt.lookUpPCB(2)) def test_2(self): pcbt.removePCB(1) pcbt.removePCB(2) self.assertEqual(True, pcbt.pcbTabletIsEmpty()) if __name__ == "__main__": unittest.main()