Esempio n. 1
0
    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)])
Esempio n. 2
0
    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)])
Esempio n. 3
0
class IntegrationTest(unittest.TestCase):


    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)
        

    def test_when_programLoader_loadProcessWithNoPriority_then_it_starts_the_expected_sequence(self):
        self.progLoader.loadProcess("ls")
        self.progLoader.loadProcess("pwd", 3)
        self.table = self.progLoader.getPcbTable()
        self.table.getPS()
        self.assertEqual(2, self.table.countActiveProcess())
        self.assertEquals(2 , self.readyQueue.length())
        self.assertEqual(self.cpuInstruction, self.memory.getDir(0))
Esempio n. 4
0
    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)
Esempio n. 5
0
    def setUp(self):
        self.disco = Mock()
        self.mmu = Mock()

        self.coladeprocesos = Mock()
        self.ram = RAM(65534)
        self.mmuReal = MMU(1, self.ram)
        self.mmuReal2 = MMU(2, self.ram)

        self.progLoader = ProgramLoader(self.ram, self.disco,
                                        self.coladeprocesos, self.mmu)
        self.progLoader2 = ProgramLoader(self.ram, self.disco,
                                         self.coladeprocesos, self.mmuReal)
        self.progLoader3 = ProgramLoader(self.ram, self.disco,
                                         self.coladeprocesos, self.mmuReal2)

        # Preparando un programa de dos (2) instrucciones
        self.instruccion1 = InstCPU("2+2")
        self.instruccion2 = InstIO("Leer de teclado", 2)

        self.program = Program("prog")
        self.program.addInstruction(self.instruccion1)
        self.program.addInstruction(self.instruccion2)
Esempio n. 6
0
class IntegrationTest(unittest.TestCase):
    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)

    def test_when_programLoader_loadProcessWithNoPriority_then_it_starts_the_expected_sequence(self):
        self.progLoader.loadProcess("ls")
        self.progLoader.loadProcess("pwd", 3)
        self.table = self.progLoader.getPcbTable()
        self.table.getPS()
        self.assertEqual(2, self.table.countActiveProcess())
        self.assertEquals(2, self.readyQueue.length())
        self.assertEqual(self.cpuInstruction, self.memory.getDir(0))
Esempio n. 7
0
    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)
Esempio n. 8
0
class ProgramLoaderTest(unittest.TestCase):
    def setUp(self):
        self.disco = Mock()
        self.mmu = Mock()

        self.coladeprocesos = Mock()
        self.ram = RAM(65534)
        self.mmuReal = MMU(1, self.ram)
        self.mmuReal2 = MMU(2, self.ram)

        self.progLoader = ProgramLoader(self.ram, self.disco,
                                        self.coladeprocesos, self.mmu)
        self.progLoader2 = ProgramLoader(self.ram, self.disco,
                                         self.coladeprocesos, self.mmuReal)
        self.progLoader3 = ProgramLoader(self.ram, self.disco,
                                         self.coladeprocesos, self.mmuReal2)

        # Preparando un programa de dos (2) instrucciones
        self.instruccion1 = InstCPU("2+2")
        self.instruccion2 = InstIO("Leer de teclado", 2)

        self.program = Program("prog")
        self.program.addInstruction(self.instruccion1)
        self.program.addInstruction(self.instruccion2)

    def test_load_a_program_pcb_creation(self):
        when(self.disco).getProgram("programa").thenReturn(self.program)
        when(self.mmu).getFrameSize().thenReturn(1)
        self.scope = Scope([Page(0), Page(23)], [Page(123)])
        when(self.mmu).getMemoryScope(self.program).thenReturn(self.scope)
        when(self.mmu).fromPageToAbsolutePosition(0).thenReturn(0)
        when(self.mmu).fromPageToAbsolutePosition(23).thenReturn(23)
        when(self.disco).getProgram("programa").thenReturn(self.program)

        self.progLoader.loadProcess("programa")

        self.assertEquals(self.progLoader.getNextId(), 2)
        verify(self.mmu, 1).getMemoryScope(self.program)
        self.assertEquals(self.ram.getDir(0), self.instruccion1)

    def test_load_a_program_pcb_creation_with_1_page(self):
        when(self.disco).getProgram("programa").thenReturn(self.program)
        when(self.mmu).getFrameSize().thenReturn(2)
        self.scope = Scope([Page(23)], [Page(45)])
        when(self.mmu).getMemoryScope(self.program).thenReturn(self.scope)
        when(self.mmu).fromPageToAbsolutePosition(23).thenReturn(46)
        when(self.disco).getProgram("programa").thenReturn(self.program)

        self.progLoader.loadProcess("programa")

        self.assertEquals(self.progLoader.getNextId(), 2)
        verify(self.mmu, 1).getMemoryScope(self.program)
        self.assertEquals(self.ram.getDir(46), self.instruccion1)
        self.assertEquals(self.ram.getDir(47), self.instruccion2)

    def test_load_a_program_pcb_creation_with_a_real_mmu(self):
        when(self.disco).getProgram("programa").thenReturn(self.program)
        when(self.disco).getProgram("programa").thenReturn(self.program)

        self.progLoader2.loadProcess("programa")

        self.assertEquals(self.progLoader.getNextId(), 1)
        self.assertEquals(self.ram.getDir(0), self.instruccion1)
Esempio n. 9
0
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
Esempio n. 10
0
from factories.OperativeSystemFactory import OperativeSystemFactory
from storage.RAM import RAM
from Consoles.Shell import Shell
from Consoles.MainConsoleThread import MainConsoleThread
from factories.discFactory import diskFactory
from util.FileLogger import *

if __name__ == '__main__':

    diskFc = diskFactory()
    disk = diskFc.basicHDD()
    ######
    mainConsole = MainConsoleThread()
    #####
    osFc = OperativeSystemFactory(disk, RAM(65535), 4, mainConsole)
    os = osFc.roundRobin_withPriority(2)

    loggerScreen = ScreenFileLogger("../log/screen_log", mainConsole)
    loggerPrinter = PrinterFileLogger("../log/printer_log", mainConsole)

    os.installNewDevice("printer", loggerPrinter)
    os.installNewDevice("screen", loggerScreen)
    os.startUp()
    shell = Shell(mainConsole, os)
    shell.start()
Esempio n. 11
0
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