def setUp(self): self.memory = RAM(65535) self.mmu = MMU(1, self.memory) self.scheduler = Mock() self.hdd = Mock() self.queue = Mock() self.interruptor2 = Mock() self.interruptor = Mock() self.logger = Mock() self.semaphore = RLock() self.cpu = CPU(self.memory, self.interruptor, self.semaphore, self.mmu) self.cpu.setLogger(self.logger) self.clock = Clock(self.cpu) self.mov = InstCPU("Matar a Flanders") self.Instruction2 = InstCPU("Y Tambien A Selma") self.instructionIO = InstIO("Soy de IO", 0) self.memory.putDir(0, self.mov) self.memory.putDir(1, self.Instruction2) self.memory.putDir(2, self.instructionIO) page0 = Page(0) page1 = Page(1) page2 = Page(2) page0.changeMemoryFlag() page1.changeMemoryFlag() page2.changeMemoryFlag() self.aPcb = PCB(0, [page0, page1, page2], 3, 4, 1, [Page(123)])
def fifo(self): ''' @return: a FIFO kernel ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.queue = OwnQueue(self.condition) self.scheduler = Scheduler(self.cpu, self.queue, -1, self.condition) return self.__build(self.queue, self.scheduler)
def withPriority(self): ''' @return: a Priority kernel ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.func = lambda pcb1, pcb2: pcb1.getPriority() >= pcb2.getPriority() self.queue = OwnHeap(self.condition, self.func) self.scheduler = Scheduler(self.cpu, self.queue, -1, self.condition) return self.__build(self.queue, self.scheduler)
def roundRobin(self, quantum): ''' @return: given a <quantum>, returns a Round Robbin configured kernel, with quantum <quantum> ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.queue = OwnQueue(self.condition) self.scheduler = Scheduler(self.cpu, self.queue, quantum, self.condition) return self.__build(self.queue, self.scheduler)
def roundRobin_withPriority(self, quantum): ''' @return: given a <quantum> it returns a Priority-RR kernel with quantum <quantum> ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.func = lambda pcb1, pcb2: pcb1.getPriority() >= pcb2.getPriority() self.queue = OwnHeap(self.condition, self.func) self.scheduler = Scheduler(self.cpu, self.queue, quantum, self.condition) return self.__build(self.queue, self.scheduler)
def setUp(self): self.memory = RAM(65535) self.mmu = MMU(1,self.memory) self.scheduler = Mock() self.hdd = Mock() self.queue = Mock() self.interruptor2 = Mock() self.interruptor = Mock() self.logger = Mock() self.semaphore = RLock() self.cpu = CPU(self.memory,self.interruptor, self.semaphore,self.mmu) self.cpu.setLogger(self.logger) self.clock = Clock(self.cpu) self.mov = InstCPU("Matar a Flanders") self.Instruction2 = InstCPU("Y Tambien A Selma") self.instructionIO = InstIO("Soy de IO", 0) self.memory.putDir(0, self.mov) self.memory.putDir(1, self.Instruction2) self.memory.putDir(2, self.instructionIO) page0 = Page(0) page1 = Page(1) page2 = Page(2) page0.changeMemoryFlag() page1.changeMemoryFlag() page2.changeMemoryFlag() self.aPcb = PCB(0,[page0,page1,page2],3,4,1,[Page(123)])
def setUp(self): # miscellaneous self.semaphore = Condition() self.disk = HardDisk() self.comparator = lambda pcb1, pcb2: pcb1.getPriority() > pcb2.getPriority() # the greater, the better self.readyQueue = OwnHeap(self.semaphore, self.comparator) # hardware self.memory = RAM(1000) self.mmu = MMU(1,self.memory) self.ioDelivery = IODelivery() self.progLoader = ProgramLoader(self.memory, self.disk, self.readyQueue,self.mmu) self.imanager = InterruptorManager() self.cpu = CPU(self.memory, self.imanager, self.semaphore,self.mmu) self.scheduler = Scheduler(self.cpu, self.readyQueue , 5, self.semaphore) # devices self.spooler = Device('printer', self.imanager) self.screen = Device('screen', self.imanager) self.ioDelivery.newDevice(self.spooler) self.ioDelivery.newDevice(self.screen) # im self.imanager.setScheduler(self.scheduler) self.imanager.setDisk(self.disk) self.imanager.setMmu(self.mmu) self.imanager.setIODelivery(self.ioDelivery) # loading programs self.ioInstruction = InstIO('directory', 0) self.cpuInstruction = InstCPU('1+1') self.prog1 = Program('ls') self.prog2 = Program('pwd') self.prog1.addInstruction(self.cpuInstruction) self.prog2.addInstruction(self.ioInstruction) self.disk.setProgram(self.prog1) self.disk.setProgram(self.prog2)
class CPUTest(unittest.TestCase): def setUp(self): self.memory = RAM(65535) self.mmu = MMU(1,self.memory) self.scheduler = Mock() self.hdd = Mock() self.queue = Mock() self.interruptor2 = Mock() self.interruptor = Mock() self.logger = Mock() self.semaphore = RLock() self.cpu = CPU(self.memory,self.interruptor, self.semaphore,self.mmu) self.cpu.setLogger(self.logger) self.clock = Clock(self.cpu) self.mov = InstCPU("Matar a Flanders") self.Instruction2 = InstCPU("Y Tambien A Selma") self.instructionIO = InstIO("Soy de IO", 0) self.memory.putDir(0, self.mov) self.memory.putDir(1, self.Instruction2) self.memory.putDir(2, self.instructionIO) page0 = Page(0) page1 = Page(1) page2 = Page(2) page0.changeMemoryFlag() page1.changeMemoryFlag() page2.changeMemoryFlag() self.aPcb = PCB(0,[page0,page1,page2],3,4,1,[Page(123)]) def test_when_fetch_then_instruction_valid(self): self.expected = self.mov # Arrange self.cpu.setPCB(self.aPcb) self.value = self.cpu.fetch() # Act self.assertEquals(self.value , self.expected) # Assert def test_when_fetching_third_intruction_then_IO_interruption(self): self.aPcb.runing() self.cpu.setPCB(self.aPcb) self.data = [self.aPcb , self.instructionIO] self.cod = 0 # Arrange self.cpu.tick() self.cpu.tick() # Act self.cpu.tick() verify(self.interruptor).ioQueue(self.data, self.cod) # Assert def test_when_fetching_last_instruction_then_pcbEnd_interruption(self): page0 = Page(0) page1 = Page(1) page0.changeMemoryFlag() page1.changeMemoryFlag() self.anotherPcb = PCB(0,[page0,page1],2,4,1,[123]) #The difference with aPcb, are their sizes... Arrange self.anotherPcb.runing() self.cpu.setPCB(self.anotherPcb) self.cpu.tick() # Act self.cpu.tick() self.cpu.tick() verify(self.interruptor, 1).kill(self.anotherPcb.getPid()) # Assert
class OperativeSystemFactory: ''' @summary: useful for some components's abstraction. Returns different kernels, for multiple purposes ''' def __init__(self, disk, ram, frameSize, mainConsole): ''' @param HardDiskDrive: an HDD with some programs loaded. @param MemoryRam @param frameSize ''' self.disk = disk self.ram = ram self.condition = Condition() self.mmu = MMU(frameSize, ram) self.console = mainConsole ##################### # TIPOS DE SCHEDULERS# ##################### def roundRobin(self, quantum): ''' @return: given a <quantum>, returns a Round Robbin configured kernel, with quantum <quantum> ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.queue = OwnQueue(self.condition) self.scheduler = Scheduler(self.cpu, self.queue, quantum, self.condition) return self.__build(self.queue, self.scheduler) def fifo(self): ''' @return: a FIFO kernel ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.queue = OwnQueue(self.condition) self.scheduler = Scheduler(self.cpu, self.queue, -1, self.condition) return self.__build(self.queue, self.scheduler) def withPriority(self): ''' @return: a Priority kernel ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.func = lambda pcb1, pcb2: pcb1.getPriority() >= pcb2.getPriority() self.queue = OwnHeap(self.condition, self.func) self.scheduler = Scheduler(self.cpu, self.queue, -1, self.condition) return self.__build(self.queue, self.scheduler) def roundRobin_withPriority(self, quantum): ''' @return: given a <quantum> it returns a Priority-RR kernel with quantum <quantum> ''' self.imanager = InterruptorManager() self.cpu = CPU(self.ram, self.imanager, self.condition, self.mmu) self.func = lambda pcb1, pcb2: pcb1.getPriority() >= pcb2.getPriority() self.queue = OwnHeap(self.condition, self.func) self.scheduler = Scheduler(self.cpu, self.queue, quantum, self.condition) return self.__build(self.queue, self.scheduler) def __build(self, queue, scheduler): # miscellaneous self.ioDelivery = IODelivery() #hardware self.progLoader = ProgramLoader(self.ram, self.disk, queue, self.mmu) # InterruptorManager self.imanager.setScheduler(scheduler) self.imanager.setDisk(self.disk) self.imanager.setMmu(self.mmu) self.imanager.setIODelivery(self.ioDelivery) self.imanager.setSemaphore(self.condition) self.imanager.setPcbTable(self.progLoader.getPcbTable()) self.imanager.setProgramLoader(self.progLoader) self.loggerCpu = CpuFileLogger("../log/cpu_log", self.console) self.cpu.setLogger(self.loggerCpu) self.clock = Clock(self.cpu) return Kernel(self.clock, self.progLoader, self.imanager, self.ioDelivery)
class CPUTest(unittest.TestCase): def setUp(self): self.memory = RAM(65535) self.mmu = MMU(1, self.memory) self.scheduler = Mock() self.hdd = Mock() self.queue = Mock() self.interruptor2 = Mock() self.interruptor = Mock() self.logger = Mock() self.semaphore = RLock() self.cpu = CPU(self.memory, self.interruptor, self.semaphore, self.mmu) self.cpu.setLogger(self.logger) self.clock = Clock(self.cpu) self.mov = InstCPU("Matar a Flanders") self.Instruction2 = InstCPU("Y Tambien A Selma") self.instructionIO = InstIO("Soy de IO", 0) self.memory.putDir(0, self.mov) self.memory.putDir(1, self.Instruction2) self.memory.putDir(2, self.instructionIO) page0 = Page(0) page1 = Page(1) page2 = Page(2) page0.changeMemoryFlag() page1.changeMemoryFlag() page2.changeMemoryFlag() self.aPcb = PCB(0, [page0, page1, page2], 3, 4, 1, [Page(123)]) def test_when_fetch_then_instruction_valid(self): self.expected = self.mov # Arrange self.cpu.setPCB(self.aPcb) self.value = self.cpu.fetch() # Act self.assertEquals(self.value, self.expected) # Assert def test_when_fetching_third_intruction_then_IO_interruption(self): self.aPcb.runing() self.cpu.setPCB(self.aPcb) self.data = [self.aPcb, self.instructionIO] self.cod = 0 # Arrange self.cpu.tick() self.cpu.tick() # Act self.cpu.tick() verify(self.interruptor).ioQueue(self.data, self.cod) # Assert def test_when_fetching_last_instruction_then_pcbEnd_interruption(self): page0 = Page(0) page1 = Page(1) page0.changeMemoryFlag() page1.changeMemoryFlag() self.anotherPcb = PCB( 0, [page0, page1], 2, 4, 1, [123]) #The difference with aPcb, are their sizes... Arrange self.anotherPcb.runing() self.cpu.setPCB(self.anotherPcb) self.cpu.tick() # Act self.cpu.tick() self.cpu.tick() verify(self.interruptor, 1).kill(self.anotherPcb.getPid()) # Assert