Пример #1
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))
Пример #2
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))
Пример #3
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)
Пример #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)
Пример #5
0
class diskFactory(object):
    def __init__(self):
        pass

    def basicHDD(self):
        '''
        @return: an HDD with 4 programs, 2 simple programs, and 2 "real programs", factorial n and summatory n
        '''
        self.manSublime = Manual("sublimeText", "make something in I/O")
        self.sbl = Program("sublimeText")
        self.instr1 = InstIO("ioDePrinter", 1)
        self.instr10 = InstIO("io De screen", 0)
        self.instr01 = InstIO("io De screen", 0)
        self.instr111 = InstIO("ioDePrinter", 1)
        self.instr2 = InstCPU("sblm cpu")
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr2)
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr10)
        self.sbl.addInstruction(self.instr01)
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr111)
        self.sbl.addManual(self.manSublime)

        self.manVim = Manual("vim", "have too many instructions")
        self.vim = Program("vim", self.manVim)
        self.instrVim1 = InstCPU("vim 1")
        self.instrVim2 = InstCPU("vim 2")
        self.instrVim3 = InstCPU("vim 3")
        self.instrVim4 = InstCPU("vim 4")
        self.instrVim5 = InstCPU("vim 5")
        self.instrVim6 = InstCPU("vim 6")
        self.vim.addInstruction(self.instrVim1)
        self.vim.addInstruction(self.instrVim2)
        self.vim.addInstruction(self.instrVim3)
        self.vim.addInstruction(self.instrVim4)
        self.vim.addInstruction(self.instrVim5)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instr111)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instr111)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)

        self.manMultiplatory = Manual("factorial", "factorial(n)")
        self.multiplatory = Program("factorial", self.manMultiplatory)
        self.multiplatory.variableSize = 3
        # the relative position 0 has the n
        self.multiplatory.addInstruction(MovLiteral(1, 1))
        self.multiplatory.addInstruction(MovLiteral(2, 2))
        self.multiplatory.addInstruction(CmpLiteral(0, 1))
        self.multiplatory.addInstruction(Jle(4))
        self.multiplatory.addInstruction(Mul(1, 2))
        self.multiplatory.addInstruction(AddLiteral(2, 1))
        self.multiplatory.addInstruction(AddLiteral(0, -1))
        self.multiplatory.addInstruction(Jmp(3))
        self.multiplatory.addInstruction(ScreenPrintValue(1))

        self.sumatoryManual = Manual("summatory", "summatory(n)")
        self.sumatory = Program("summatory", self.sumatoryManual)
        self.sumatory.variableSize = 3
        self.sumatory.addInstruction(MovLiteral(1, 0))
        self.sumatory.addInstruction(MovLiteral(2, 1))
        self.sumatory.addInstruction(CmpLiteral(0, 0))
        self.sumatory.addInstruction(Jle(4))
        self.sumatory.addInstruction(Add(1, 2))
        self.sumatory.addInstruction(AddLiteral(2, 1))
        self.sumatory.addInstruction(AddLiteral(0, -1))
        self.sumatory.addInstruction(Jmp(3))
        self.sumatory.addInstruction(ScreenPrintValue(1))

        self.hdd = HardDisk()
        self.hdd.setProgram(self.vim)
        self.hdd.setProgram(self.sbl)
        self.hdd.setProgram(self.multiplatory)
        self.hdd.setProgram(self.sumatory)

        return self.hdd
Пример #6
0
class diskFactory(object):
    


    def __init__(self):
        pass
    
    def basicHDD(self):
        '''
        @return: an HDD with 4 programs, 2 simple programs, and 2 "real programs", factorial n and summatory n
        '''
        self.manSublime = Manual("sublimeText", "make something in I/O")
        self.sbl = Program("sublimeText")
        self.instr1 = InstIO("ioDePrinter", 1)
        self.instr10 = InstIO("io De screen", 0)
        self.instr01 = InstIO("io De screen", 0)
        self.instr111 = InstIO("ioDePrinter", 1)
        self.instr2 = InstCPU("sblm cpu")
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr2)
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr10)
        self.sbl.addInstruction(self.instr01)
        self.sbl.addInstruction(self.instr1)
        self.sbl.addInstruction(self.instr111)
        self.sbl.addManual(self.manSublime)
        
        self.manVim = Manual("vim", "have too many instructions")
        self.vim = Program("vim", self.manVim)
        self.instrVim1 = InstCPU("vim 1")
        self.instrVim2 = InstCPU("vim 2")
        self.instrVim3 = InstCPU("vim 3")
        self.instrVim4 = InstCPU("vim 4")
        self.instrVim5 = InstCPU("vim 5")
        self.instrVim6 = InstCPU("vim 6")
        self.vim.addInstruction(self.instrVim1)
        self.vim.addInstruction(self.instrVim2)
        self.vim.addInstruction(self.instrVim3)
        self.vim.addInstruction(self.instrVim4)
        self.vim.addInstruction(self.instrVim5)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instr111)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instr111)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        self.vim.addInstruction(self.instrVim6)
        
        self.manMultiplatory = Manual("factorial", "factorial(n)")
        self.multiplatory = Program("factorial", self.manMultiplatory)
        self.multiplatory.variableSize = 3
        # the relative position 0 has the n
        self.multiplatory.addInstruction(MovLiteral(1, 1))
        self.multiplatory.addInstruction(MovLiteral(2, 2))
        self.multiplatory.addInstruction(CmpLiteral(0, 1))
        self.multiplatory.addInstruction(Jle(4))
        self.multiplatory.addInstruction(Mul(1, 2))
        self.multiplatory.addInstruction(AddLiteral(2, 1))
        self.multiplatory.addInstruction(AddLiteral(0, -1))
        self.multiplatory.addInstruction(Jmp(3))
        self.multiplatory.addInstruction(ScreenPrintValue(1))
        
        
        
        self.sumatoryManual = Manual("summatory", "summatory(n)")
        self.sumatory = Program("summatory", self.sumatoryManual)
        self.sumatory.variableSize = 3
        self.sumatory.addInstruction(MovLiteral(1, 0))
        self.sumatory.addInstruction(MovLiteral(2, 1))
        self.sumatory.addInstruction(CmpLiteral(0, 0))
        self.sumatory.addInstruction(Jle(4))
        self.sumatory.addInstruction(Add(1, 2))
        self.sumatory.addInstruction(AddLiteral(2, 1))
        self.sumatory.addInstruction(AddLiteral(0, -1))
        self.sumatory.addInstruction(Jmp(3))
        self.sumatory.addInstruction(ScreenPrintValue(1))
        
        self.hdd = HardDisk()
        self.hdd.setProgram(self.vim)
        self.hdd.setProgram(self.sbl)
        self.hdd.setProgram(self.multiplatory)
        self.hdd.setProgram(self.sumatory)
        
        return self.hdd