Exemplo 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)])
Exemplo n.º 2
0
    def loadProcess(self, program, priority=0, args=[]):
        """
        @note: this method load a program into the ram
        
        @param program: the next program to load
               priority: the priority of the program
               args: the program will be loaded with this args
        @return: the program id
        """

        self.myProgram = self.hdd.getProgram(program)
        self.myProgram.initializePreValues(args)
        self.scope = self.mmu.getMemoryScope(self.myProgram)
        self.pages = self.scope.getListInstructionPages()
        self.dataScope = self.scope.getListDataPages()
        self.miPCB = PCB(self.getNextId(), self.pages, self.myProgram.size(),
                         priority, self.mmu.getFrameSize(), self.dataScope)
        self.instructions = self.myProgram.getInstructions()
        current = 0
        for slipping in xrange(self.mmu.getFrameSize()):
            if current >= len(self.instructions): break
            self.memory.putDir(
                self.mmu.fromPageToAbsolutePosition(
                    self.pages[0].getPageNumber()) + slipping,
                self.instructions[current])
            current = current + 1
        self.pages[0].changeMemoryFlag()
        self.miPCB.toReady()
        self.processQueue.put(self.miPCB)
        self.pcbTable.addPCB(self.miPCB, self.myProgram.getName())
        return self.pids
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 def test_when_size_isEquals_to_pc_then_it_is_Finished(self):
     self.sut = PCB(0, [0], 5)
     self.sut.runing()
     self.repeat(self.sut.incrementPc, 6)
     self.assertTrue(self.sut.finished())
Exemplo n.º 5
0
 def test_when_PCB_has_size_N_getSize_returns_N(self):
     self.sut = PCB(0, [0], 5)
     self.assertEqual(5, self.sut.getSize())
Exemplo n.º 6
0
 def test_when_PCB_isRuning_incrementPC_sums_one_to_the_pc(self):
     self.sut = PCB(0, [0], 1)
     self.sut.runing()
     self.sut.incrementPc()
     self.assertEqual(1, self.sut.getPc())
Exemplo n.º 7
0
 def test_when_baseDir_is_N_incrementPc_plus_getPC_returns_N_Because_PCBReady_shuldnt_increment_pc(
         self):
     self.sut = PCB(0, [0], 1)
     self.sut.incrementPc()
     self.assertEqual(0, self.sut.getPc())
Exemplo n.º 8
0
 def test_when_baseDir_is_N_getBaseDir_returns_N(self):
     self.sut = PCB(0, [0], 1, 0, 1, [1])
     self.assertEqual(0, self.sut.getCurrentPage())
Exemplo n.º 9
0
 def setUp(self):
     self.pcb1 = PCB(1, 1, 1, 8)
     self.pcb2 = PCB(2, 4, 3, 9)
     self.pcb3 = PCB(3, 7, 6, 13)
     self.pcb4 = PCB(4, 9, 8, 17)