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
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 #3
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())