Ejemplo n.º 1
0
class TestKernel(unittest.TestCase):
    def setUp(self):
        self.memory = Memory(50)
        self.scheduler = Scheduler()
        self.scheduler.set_as_fifo()
        self.a_kernel = Kernel(None)
        self.pcb_table = PCBTable()
        self.a_kernel.set_pcb_table(self.pcb_table)
        interruption_manager = InterruptionHandler(self.a_kernel.cpu)
        self.a_kernel.set_interruption_handler(interruption_manager)
        load_in_interruption_manager = Handle_Loaders()
        load_in_interruption_manager.load_handlers(self, interruption_manager)

    def write_program(self,program,memory):
        pos = 0
        for instruction in program.obtain_instructions():
            memory.put(pos,instruction)

    def load_a_instruction_in_a_program(self):
        program = Program("SIN-IO")
        instruction = Instruction("Texto")
        program.addInstruction(instruction)
        program.addInstruction(instruction)
        self.write_program(program,self.memory)
        self.setup_load_of_a_program_in_memory(2,program,2)

    def load_a_io_instruction_in_a_program(self):
        program = Program("IO")
        self.a_kernel.set_scheduler(self.scheduler)
        instruction = InstructionIO()
        program.addInstruction(instruction)
        program.addInstruction(instruction)
        self.write_program(program, self.memory)
        self.setup_load_of_a_program_in_memory(2,program,2)

    def setup_load_of_a_program_in_memory(self, amount_instructions, program, pcb_id):
        block_holder = BlockHolder(program)
        block_holder.set_representation([0,1])
        pcb = PCB(amount_instructions, pcb_id, block_holder)
        self.pcb_table.add(pcb)
        self.scheduler.policy.add_pcb(pcb)
        memory_admin = ToyMemoryAdmin(self.memory)
        self.a_kernel.cpu.set_actual_pcb(pcb)
        self.a_kernel.cpu.set_memory_manager(memory_admin)

    def test_given_pcb_when_cpu_complete_instruction_cycle_then_increments_pc(self):
        '''
        Compare the initial state of PCB's PC with final state
        '''
        self.load_a_instruction_in_a_program()
        self.assertEqual(0, self.a_kernel.cpu.actual_pcb.get_pc())
        self.a_kernel.cpu.complete_instruction_cycle()
        self.assertEqual(1, self.a_kernel.cpu.actual_pcb.get_pc())

    def test_given_pcb_when_cpu_complete_instruction_cycle_then_IO_Manager_captures_interruption_and_increments_pc(self):
        self.load_a_io_instruction_in_a_program()
        self.assertEqual(0, self.a_kernel.cpu.actual_pcb.get_pc())
        self.a_kernel.cpu.complete_instruction_cycle()
        self.assertEqual(1, self.a_kernel.cpu.actual_pcb.get_pc())
Ejemplo n.º 2
0
class Main(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.memory = Memory(50)
        self.a_kernel = Kernel(None)
        self.cpu = Cpu(self.a_kernel)
        self.scheduler = Scheduler()
        self.scheduler.set_as_fifo()
        self.clock = Clock(self.cpu)
        self.a_kernel.clock = self.clock
        self.pcb_table = PCBTable()

    def load_a_instruction_in_a_program(self):
        program = Program("SIN-IO")
        self.a_kernel.set_scheduler(self.scheduler)
        self.a_kernel.set_pcb_table(self.pcb_table)
        interruption_manager = InterruptionHandler(self.cpu)
        self.a_kernel.set_interruption_handler(interruption_manager)
        load_in_interruption_manager = Handle_Loaders()
        load_in_interruption_manager.load_handlers(interruption_manager)
        instruction = Instruction("Texto")
        program.addInstruction(instruction)
        program.addInstruction(instruction)
        self.write_program(program,self.memory)
        self.setup_load_of_a_program_in_memory(2, program, 1)

    def write_program(self,program,memory):
        pos = 0
        for instruction in program.obtain_instructions():
            memory.put(pos,instruction)


    def load_a_io_instruction_in_a_program(self):
        program = Program("IO")
        self.a_kernel.set_scheduler(self.scheduler)
        interruption_manager = InterruptionHandler(self.cpu)
        load_in_interruption_manager = Handle_Loaders()
        load_in_interruption_manager.load_handlers(interruption_manager)
        self.a_kernel.set_interruption_handler(interruption_manager)
        instruction = InstructionIO()
        program.addInstruction(instruction)
        program.addInstruction(instruction)
        self.write_program(program,self.memory)
        self.setup_load_of_a_program_in_memory(2, program, 2)

    def setup_load_of_a_program_in_memory(self, amount_instructions, program, pcb_id):
        block_holder = BlockHolder(program)
        block_holder.set_representation([0,1])
        pcb = PCB(amount_instructions, pcb_id, block_holder)
        self.scheduler.policy.add_pcb(pcb)
        memory_admin = ToyMemoryAdmin(self.memory)
        self.cpu.set_actual_pcb(pcb)
        self.pcb_table.add(self.cpu.get_actual_pcb())
        self.cpu.set_memory_manager(memory_admin)

    def run(self):
        self.load_a_instruction_in_a_program()
        self.clock.start()
Ejemplo n.º 3
0
class Helper:
    def __init__(self):
        self.memory = Memory(50)
        self.hdd = HDD(5)
        self.cpu = Cpu(None)
        self.scheduler = Scheduler()
        self.fifo = FifoPolicy(self.scheduler)
        self.pcb_table = PCBTable()
        self.memory_manager = MemoryManager()
        self.a_kernel = Kernel(self.cpu, self.memory_manager)
        self.a_kernel.set_scheduler(self.scheduler)
        self.a_kernel.set_pcb_table(self.pcb_table)
        self.a_kernel.set_hdd(self.hdd)
        self.a_kernel.hdd.generate_file_system()
        self.instruction = Instruction("Texto")
        self.instruction_io = InstructionIO("IO")

    def load_a_instruction_in_a_program(self):
        program = Program("SIN-IO")
        manager = Manager(self.scheduler, self.pcb_table, self.memory_manager)
        interruption_handler = InterruptionHandler(manager)
        self.a_kernel.set_interruption_handler(interruption_handler)
        self.cpu.kernel = self.a_kernel
        program.addInstruction(self.instruction)
        program.addInstruction(self.instruction)
        self.write_program(program,self.memory)
        self.setup_load_of_a_program_in_memory(2, program, 1)

    def load_a_io_instruction_in_a_program(self):
        program = Program("IO")
        manager = Manager(self.scheduler, self.pcb_table, self.memory_manager)
        interruption_handler = InterruptionHandler(manager)
        self.a_kernel.set_interruption_handler(interruption_handler)
        self.cpu.kernel = self.a_kernel
        program.addInstruction(self.instruction_io)
        program.addInstruction(self.instruction_io)
        self.write_program(program,self.memory)
        self.setup_load_of_a_program_in_memory(2, program, 2)

    def write_program(self,program,memory):
        pos = 0
        for instruction in program.get_instructions():
            memory.put(pos,instruction)

    def setup_load_of_a_program_in_memory(self, amount_instructions, program, pcb_id):
        page_holder = PageHolder(program)
        pcb = PCB(amount_instructions, pcb_id, page_holder)
        self.pcb_table.add(pcb)
        self.fifo.add_pcb(pcb)
        self.cpu.set_actual_pcb(pcb)
Ejemplo n.º 4
0
class Loader:

    def __init__(self,kernel=None):
        self.kernel = kernel
        kernel.set_loader(self)
        self.pcb_table = PCBTable()

    def load(self, memory_manager, pcb):
        page_holder = self.kernel.generate_page_holder()
        memory_manager.write(pcb)
        self.pcb_table.add(pcb)

    def remove(self, pcb):
        self.logical_memory.delete_program(pcb)
        self.pcb_table.remove(pcb)

    def get_instructions(self,program):
        return self.hdd.obtain_instructions(program)
Ejemplo n.º 5
0
 def __init__(self):
     Thread.__init__(self)
     self.memory = Memory(50)
     self.a_kernel = Kernel(None)
     self.cpu = Cpu(self.a_kernel)
     self.scheduler = Scheduler()
     self.scheduler.set_as_fifo()
     self.clock = Clock(self.cpu)
     self.a_kernel.clock = self.clock
     self.pcb_table = PCBTable()
Ejemplo n.º 6
0
 def setUp(self):
     self.memory = Memory(50)
     self.scheduler = Scheduler()
     self.scheduler.set_as_fifo()
     self.a_kernel = Kernel(None)
     self.pcb_table = PCBTable()
     self.a_kernel.set_pcb_table(self.pcb_table)
     interruption_manager = InterruptionHandler(self.a_kernel.cpu)
     self.a_kernel.set_interruption_handler(interruption_manager)
     load_in_interruption_manager = Handle_Loaders()
     load_in_interruption_manager.load_handlers(self, interruption_manager)
Ejemplo n.º 7
0
 def __init__(self):
     self.memory = Memory(50)
     self.hdd = HDD(5)
     self.cpu = Cpu(None)
     self.scheduler = Scheduler()
     self.fifo = FifoPolicy(self.scheduler)
     self.pcb_table = PCBTable()
     self.memory_manager = MemoryManager()
     self.a_kernel = Kernel(self.cpu, self.memory_manager)
     self.a_kernel.set_scheduler(self.scheduler)
     self.a_kernel.set_pcb_table(self.pcb_table)
     self.a_kernel.set_hdd(self.hdd)
     self.a_kernel.hdd.generate_file_system()
     self.instruction = Instruction("Texto")
     self.instruction_io = InstructionIO("IO")
Ejemplo n.º 8
0
 def __init__(self,kernel=None):
     self.kernel = kernel
     kernel.set_loader(self)
     self.pcb_table = PCBTable()