Example #1
0
class TestRRScheduler(unittest.TestCase):
    def setUp(self):
        self.store = ProcessStore()
        self.sched = RRScheduler(None, self.store)
        instList = self.init_instructions()
        proc_1 = Process(547, 'x', 10, instList, 2, 2)
        proc_2 = Process(123, 'y', 10, [], 2, 2)
        self.store.put_in_ready_queue(proc_1.get_pcb())
        self.store.put_in_ready_queue(proc_2.get_pcb())

    def init_instructions(self):
        return [
            MockInst(1, False),
            MockInst(2, False),
            MockInst(2, False),
            MockInst(3, True),
            MockInst(2, False),
            MockInst(1, False)
        ]

    def test_setNextBurst(self):
        pcb = self.sched.get_next_pcb()
        self.sched.set_next_burst(pcb)
        self.assertEqual(pcb.get_next_burst(), 1)
        pcb.set_pc(2)
        self.sched.set_next_burst(pcb)
        self.assertEqual(pcb.get_next_burst(), 2)
        pcb.set_pc(4)
        self.sched.set_next_burst(pcb)
        self.assertEqual(pcb.get_next_burst(), 2)
        pcb.set_pc(5)
        self.sched.set_next_burst(pcb)
        self.assertEqual(pcb.get_next_burst(), 1)
Example #2
0
 def setUp(self):
     self.store = ProcessStore()
     self.sched = FCFSScheduler(None, self.store)
     inst_list = self.init_instructions()
     proc_1 = Process(547, 'x', 10, inst_list, 2, 2)
     proc_2 = Process(123, 'y', 10, [], 2, 2)
     self.store.put_in_ready_queue(proc_1.get_pcb())
     self.store.put_in_ready_queue(proc_2.get_pcb())
Example #3
0
class TestScheduler(unittest.TestCase):
    '''
    This class test the abstract class Scheduler, and the FCFS Scheduling.  
    '''
    def setUp(self):
        self.store = ProcessStore()
        self.sched = FCFSScheduler(None, self.store)
        inst_list = self.init_instructions()
        proc_1 = Process(547, 'x', 10, inst_list, 2, 2)
        proc_2 = Process(123, 'y', 10, [], 2, 2)
        self.store.put_in_ready_queue(proc_1.get_pcb())
        self.store.put_in_ready_queue(proc_2.get_pcb())
        
    def init_instructions(self):
        return [MockInst(3, False), MockInst(1, False), MockInst(2, False),
                MockInst(3, True), MockInst(1, False), MockInst(9, False)]
        
    def test_getNextPCB(self):
        p1 = self.sched.get_next_pcb()
        self.assertEqual(p1.get_pid(), 547)
        p1 = self.sched.get_next_pcb()
        self.assertEqual(p1.get_pid(), 123)
        self.assertTrue(self.store.ready_queue_is_empty())
    
    def test_setNextBurst(self):
        pcb = self.sched.get_next_pcb()
        self.sched.set_next_burst(pcb)
        self.assertEqual(pcb.get_next_burst(), 6)
        pcb.set_pc(4)
        self.sched.set_next_burst(pcb)
        self.assertEqual(pcb.get_next_burst(), 10)
    
    def test_setRemainingTime(self):
        pcb = self.sched.get_next_pcb()
        self.sched.set_remaining_time(pcb)
        self.assertEqual(pcb.get_remaining_time(), 19)
        pcb.set_pc(3)
        self.sched.set_remaining_time(pcb)
        self.assertEqual(pcb.get_remaining_time(), 13)
        pcb.set_pc(6)
        self.sched.set_remaining_time(pcb)
        self.assertEqual(pcb.get_remaining_time(), 0)
Example #4
0
 def reset(self):
     self.get_parser().reset()
     store = ProcessStore()
     banker = BankersAlgorithm(self.get_total_resources())
     self.set_process_store(store)
     self.get_cpu().set_process_store(store)
     self.get_cpu().set_banker(banker)
     ProcessKiller.get_instance().set_banker(banker)
     ProcessKiller.get_instance().set_process_store(store)
     self.get_scheduler().set_process_store(store)
     self.get_lt_scheduler().set_process_store(store)
     for dev in self.get_io_devices():
         self.get_io_devices()[dev].set_process_store(store)
Example #5
0
 def __init__(self):
     ''' Constructor of OS.'''
     Memory()  #create the singleton memory
     Logger()  #initialize the logger
     self._parser = OSParser()
     self._file_manager = FileManager(False)
     self._proc_store = ProcessStore()
     self._io_devices = self.create_io_devices()
     banker = BankersAlgorithm(self.get_total_resources())
     ProcessKiller(banker, self._proc_store)
     self._cpu = CPU(banker, self._io_devices, self._proc_store)
     self._scheduler = self.create_scheduler(self._cpu, self._proc_store)
     self._lt_scheduler = LTScheduler(self._proc_store)
     self._active = False
Example #6
0
class TestProcessStore(unittest.TestCase):
    
    def setUp(self):
        self.store = ProcessStore()
        self.testPCB = Process(547, 'x', 10, [], 1, 1).get_pcb()
        
    def test_emptyWorkQueue(self):
        self.assertTrue(self.store.work_queue_is_empty())
        self.store.put_in_work_queue(self.testPCB)
        self.assertFalse(self.store.work_queue_is_empty())
    
    def test_emptyReadyQueue(self):
        self.assertTrue(self.store.ready_queue_is_empty())
        self.store.put_in_ready_queue(self.testPCB)
        self.assertFalse(self.store.ready_queue_is_empty())
    
    def test_work2ReadyQueue(self):
        self.store.put_in_work_queue(self.testPCB)
        self.assertFalse(self.store.work_queue_is_empty())
        self.assertTrue(self.store.ready_queue_is_empty())
        self.store.work_to_ready_queue(self.testPCB)
        self.assertTrue(self.store.work_queue_is_empty())
        self.assertFalse(self.store.ready_queue_is_empty())
Example #7
0
 def setUp(self):
     self.store = ProcessStore()
     self.testPCB = Process(547, 'x', 10, [], 1, 1).get_pcb()