Exemplo n.º 1
0
class Main:
    def __init__(self):

        self.program1 = Program(range(0, 10), "Word")
        self.program2 = Program(range(0, 50), "Excel")
        self.program3 = Program(range(0, 20), "Powerpoint")

        self.hdd = HDD(50)

        self.file_system = self.hdd.generate_file_system()
        self.file_system.add_file("Word", self.program1)
        self.file_system.add_file("Excel", self.program1)
        self.file_system.add_file("Powerpoint", self.program1)

        self.hdd.serialize_file_system(self.file_system)

        self.memory_manager = MemoryManager(self.hdd)

    def run_example_1(self):
        self.scheduler_policy = PriorityScheduler()
        self.continuous_assignment_policy = BestFit()
        self.memory_policy = ContinuousAssignment(self.memory_manager.get_memory(), self.continuous_assignment_policy)
        self.kernel = Kernel(self.scheduler_policy, self.hdd, self.memory_policy)
        self.kernel.run("Word")
        self.kernel.run("Excel")
        self.kernel.run("Powerpoint")

    def run_example_2(self):
        self.scheduler_policy = RoundRobinScheduler(3)
        self.memory_policy = Paging(self.memory_manager.get_memory(), 2, self.hdd)
        self.kernel = Kernel(self.scheduler_policy, self.hdd, self.memory_policy)
        self.kernel.run("Word")
        self.kernel.run("Excel")
        self.kernel.run("Powerpoint")
Exemplo n.º 2
0
 def setUp(self):
     self.hdd = HDD(10)
     self.fs = self.hdd.generate_file_system()
     self.instruction1 = InstructionIO()
     self.instruction2 = InstructionCPU()
     self.instructionList1 = [self.instruction1, self.instruction2]
     self.program1 = Program(self.instructionList1, "AProgram")
     self.fs.add_file("AProgram", self.program1)
     self.file1 = self.fs.get_program("AProgram")
     self.pcb = PCB(0, 2, BlockHolder(self.file1))
     self.mm = MemoryManager()
     self.mm.set_as_ca(FirstFit())
     self.mm.write(self.pcb)
Exemplo n.º 3
0
class PCBTest(unittest.TestCase):

    #Arrange
    def setUp(self):
        self.hdd = HDD(10)
        self.fs = self.hdd.generate_file_system()
        self.instruction1 = InstructionIO()
        self.instruction2 = InstructionCPU()
        self.instructionList1 = [self.instruction1, self.instruction2]
        self.program1 = Program(self.instructionList1, "AProgram")
        self.fs.add_file("AProgram", self.program1)
        self.file1 = self.fs.get_program("AProgram")
        self.pcb = PCB(0, 2, BlockHolder(self.file1))
        self.mm = MemoryManager()
        self.mm.set_as_ca(FirstFit())
        self.mm.write(self.pcb)

    def test_whenIHaveAPCBAndItsIncremented_thenIHaveAPCBWithOneMoreInstructionIndex(self):
        self.pcb.increment()
        self.assertEqual(self.pcb.get_pc(), 3)

    def test_whenIHaveAPCBAndItsPriorityItsChanged_thenItsDifferent(self):
        self.pcb.set_priority(PCBPriorities().getPriorities().LOW)
        self.pcb.increase_priority()
        self.assertEqual(self.pcb._priority, PCBPriorities().getPriorities().MEDIUM)
Exemplo n.º 4
0
    def __init__(self):

        self.program1 = Program(range(0, 10), "Word")
        self.program2 = Program(range(0, 50), "Excel")
        self.program3 = Program(range(0, 20), "Powerpoint")

        self.hdd = HDD(50)

        self.file_system = self.hdd.generate_file_system()
        self.file_system.add_file("Word", self.program1)
        self.file_system.add_file("Excel", self.program1)
        self.file_system.add_file("Powerpoint", self.program1)

        self.hdd.serialize_file_system(self.file_system)

        self.memory_manager = MemoryManager(self.hdd)
Exemplo n.º 5
0
class MemoryManagerTest(unittest.TestCase):

    #Arrange
    def setUp(self):
        self.hdd = HDD(10)
        self.fs = self.hdd.generate_file_system()
        self.instruction1 = InstructionIO()
        self.instruction2 = InstructionCPU()
        self.instruction3 = InstructionIO()
        self.instructionList1 = [self.instruction1, self.instruction2]
        self.instructionList2 = [self.instruction1, self.instruction2, self.instruction3]
        self.program1 = Program(self.instructionList1, "AProgram")
        self.program2 = Program(self.instructionList2, "BProgram")
        self.fs.add_file("AProgram", self.program1)
        self.fs.add_file("BProgram", self.program2)
        self.file1 = self.fs.get_program("AProgram")
        self.file2 = self.fs.get_program("BProgram")
        self.pcb1 = PCB(0, 2, BlockHolder(self.file1))
        self.pcb2 = PCB(0, 3 , BlockHolder(self.file2))
        self.memoryManager = MemoryManager()
        self.memoryManager.set_as_ca(FirstFit())

    def test_whenTheMemoryManagerAddsTwoProgramsAndIAskForThe6thPosition_thenIShouldGetException(self):
        self.memoryManager.write(self.pcb1)
        self.memoryManager.write(self.pcb2)
Exemplo n.º 6
0
class PCBTest(unittest.TestCase):

    #Arrange
    def setUp(self):
        self.hdd = HDD(10)
        self.fs = self.hdd.generate_file_system()
        self.instruction1 = InstructionIO()
        self.instruction2 = InstructionCPU()
        self.instructionList1 = [self.instruction1, self.instruction2]
        self.program1 = Program(self.instructionList1, "AProgram")
        self.fs.add_file("AProgram", self.program1)
        self.file1 = self.fs.get_program("AProgram")
        self.pcb = PCB(0, 2, BlockHolder(self.file1))
        self.mm = MemoryManager()
        self.mm.set_as_ca(FirstFit())
        self.mm.write(self.pcb)

    def test_whenIHaveAPCBAndItsIncremented_thenIHaveAPCBWithOneMoreInstructionIndex(
            self):
        self.pcb.increment()
        self.assertEqual(self.pcb.get_pc(), 3)

    def test_whenIHaveAPCBAndItsPriorityItsChanged_thenItsDifferent(self):
        self.pcb.set_priority(PCBPriorities().getPriorities().LOW)
        self.pcb.increase_priority()
        self.assertEqual(self.pcb._priority,
                         PCBPriorities().getPriorities().MEDIUM)
Exemplo n.º 7
0
class MemoryManagerTest(unittest.TestCase):

    #Arrange
    def setUp(self):
        self.hdd = HDD(10)
        self.fs = self.hdd.generate_file_system()
        self.instruction1 = InstructionIO()
        self.instruction2 = InstructionCPU()
        self.instruction3 = InstructionIO()
        self.instructionList1 = [self.instruction1, self.instruction2]
        self.instructionList2 = [
            self.instruction1, self.instruction2, self.instruction3
        ]
        self.program1 = Program(self.instructionList1, "AProgram")
        self.program2 = Program(self.instructionList2, "BProgram")
        self.fs.add_file("AProgram", self.program1)
        self.fs.add_file("BProgram", self.program2)
        self.file1 = self.fs.get_program("AProgram")
        self.file2 = self.fs.get_program("BProgram")
        self.pcb1 = PCB(0, 2, BlockHolder(self.file1))
        self.pcb2 = PCB(0, 3, BlockHolder(self.file2))
        self.memoryManager = MemoryManager()
        self.memoryManager.set_as_ca(FirstFit())

    def test_whenTheMemoryManagerAddsTwoProgramsAndIAskForThe6thPosition_thenIShouldGetException(
            self):
        self.memoryManager.write(self.pcb1)
        self.memoryManager.write(self.pcb2)
Exemplo n.º 8
0
 def setUp(self):
     self.hdd = HDD(10)
     self.fs = self.hdd.generate_file_system()
     self.instruction1 = InstructionIO()
     self.instruction2 = InstructionCPU()
     self.instruction3 = InstructionIO()
     self.instructionList1 = [self.instruction1, self.instruction2]
     self.instructionList2 = [
         self.instruction1, self.instruction2, self.instruction3
     ]
     self.program1 = Program(self.instructionList1, "AProgram")
     self.program2 = Program(self.instructionList2, "BProgram")
     self.fs.add_file("AProgram", self.program1)
     self.fs.add_file("BProgram", self.program2)
     self.file1 = self.fs.get_program("AProgram")
     self.file2 = self.fs.get_program("BProgram")
     self.pcb1 = PCB(0, 2, BlockHolder(self.file1))
     self.pcb2 = PCB(0, 3, BlockHolder(self.file2))
     self.memoryManager = MemoryManager()
     self.memoryManager.set_as_ca(FirstFit())
Exemplo n.º 9
0
 def setUp(self):
     self.hdd = HDD(10)
     self.fs = self.hdd.generate_file_system()
     self.instruction1 = InstructionIO()
     self.instruction2 = InstructionCPU()
     self.instructionList1 = [self.instruction1, self.instruction2]
     self.program1 = Program(self.instructionList1, "AProgram")
     self.fs.add_file("AProgram", self.program1)
     self.file1 = self.fs.get_program("AProgram")
     self.pcb = PCB(0, 2, BlockHolder(self.file1))
     self.mm = MemoryManager()
     self.mm.set_as_ca(FirstFit())
     self.mm.write(self.pcb)
Exemplo n.º 10
0
class Main:
    def __init__(self):

        self.program1 = Program(range(0, 10), "Word")
        self.program2 = Program(range(0, 50), "Excel")
        self.program3 = Program(range(0, 20), "Powerpoint")

        self.hdd = HDD(50)

        self.file_system = self.hdd.generate_file_system()
        self.file_system.add_file("Word", self.program1)
        self.file_system.add_file("Excel", self.program1)
        self.file_system.add_file("Powerpoint", self.program1)

        self.hdd.serialize_file_system(self.file_system)

        self.memory_manager = MemoryManager(self.hdd)

    def run_example_1(self):
        self.scheduler_policy = PriorityScheduler()
        self.continuous_assignment_policy = BestFit()
        self.memory_policy = ContinuousAssignment(
            self.memory_manager.get_memory(),
            self.continuous_assignment_policy)
        self.kernel = Kernel(self.scheduler_policy, self.hdd,
                             self.memory_policy)
        self.kernel.run("Word")
        self.kernel.run("Excel")
        self.kernel.run("Powerpoint")

    def run_example_2(self):
        self.scheduler_policy = RoundRobinScheduler(3)
        self.memory_policy = Paging(self.memory_manager.get_memory(), 2,
                                    self.hdd)
        self.kernel = Kernel(self.scheduler_policy, self.hdd,
                             self.memory_policy)
        self.kernel.run("Word")
        self.kernel.run("Excel")
        self.kernel.run("Powerpoint")
Exemplo n.º 11
0
    def __init__(self):

        self.program1 = Program(range(0, 10), "Word")
        self.program2 = Program(range(0, 50), "Excel")
        self.program3 = Program(range(0, 20), "Powerpoint")

        self.hdd = HDD(50)

        self.file_system = self.hdd.generate_file_system()
        self.file_system.add_file("Word", self.program1)
        self.file_system.add_file("Excel", self.program1)
        self.file_system.add_file("Powerpoint", self.program1)

        self.hdd.serialize_file_system(self.file_system)

        self.memory_manager = MemoryManager(self.hdd)
Exemplo n.º 12
0
 def setUp(self):
     self.hdd = HDD(10)
     self.fs = self.hdd.generate_file_system()
     self.instruction1 = InstructionIO()
     self.instruction2 = InstructionCPU()
     self.instruction3 = InstructionIO()
     self.instructionList1 = [self.instruction1, self.instruction2]
     self.instructionList2 = [self.instruction1, self.instruction2, self.instruction3]
     self.program1 = Program(self.instructionList1, "AProgram")
     self.program2 = Program(self.instructionList2, "BProgram")
     self.fs.add_file("AProgram", self.program1)
     self.fs.add_file("BProgram", self.program2)
     self.file1 = self.fs.get_program("AProgram")
     self.file2 = self.fs.get_program("BProgram")
     self.pcb1 = PCB(0, 2, BlockHolder(self.file1))
     self.pcb2 = PCB(0, 3 , BlockHolder(self.file2))
     self.memoryManager = MemoryManager()
     self.memoryManager.set_as_ca(FirstFit())