def test_exactSameTask(): t1 = Task(4, 2, FixedArrivalDistribution(2), displayName='t1', uniqueId=0) t2 = Task(4, 2, FixedArrivalDistribution(2), displayName='t2', uniqueId=1) taskset = Taskset(t1, t2) setup = SimulationSetup(taskset, time=5) run = SimulationRun(setup) result = run.result() testTime = 2 state = result.history[testTime] logging.debug('Effective %s', state) expected = SimulatorState(testTime, [JobState(t2, 0), JobState(t2, 1), JobState(t2, 2), JobState(t1, 0, progress=2, lastStart=2), JobState(t1, 1), JobState(t1, 2)], [StateDeadline(4, t2, 1), StateArrival(4, t2, 2), StateArrival(4, t1, 2), StateDeadline(4, t1, 1), StateCompletion(4, t1, 0)], deadlineMisses=[ DeadlineMiss(t1, 0), DeadlineMiss(t2, 0) ], scheduler=EDFSchedulerState((2, t1, 0), (2, 1, t2, 0), (4, t1, 1), (4, 1, t2, 1))) logging.debug('Expected %s', expected) assert state == expected
def test_simuManyPreemptionsFailing(): t1 = Task(1, 2, FixedArrivalDistribution(2), displayName='task1') t2 = Task(11, 20, FixedArrivalDistribution(20), displayName='task2') taskset = Taskset(t1, t2) sim = Simulation(taskset) endTime = 21 state = sim.getState(endTime) logging.debug('%s', state) expectedJobs = [JobState(t1, 9, 1, lastStart=21), JobState(t1, 11), JobState(t1, 10), JobState(t2, 1), JobState(t2, 2)] expectedEvents = [StateArrival(22, t1, 11), StateArrival(40, t2, 2), StateCompletion(21, t1, 9), StateDeadline(22, t1, 10), StateDeadline(40, t2, 1)] expectedScheduler = EDFSchedulerState((20, 1, t1, 9), (22, t1, 10), (40, t2, 1)) expected = SimulatorState(endTime, expectedJobs, expectedEvents, scheduler=expectedScheduler) assert(state == expected) expectedDeadlineMisses = {DeadlineMiss(t1, 9)} assert(sim.deadlineMisses(endTime) == expectedDeadlineMisses)
def test_simulateToDeadlineMiss(): t1 = Task(20, 50, FixedArrivalDistribution(50), displayName='t1') t2 = Task(2, 3, FixedArrivalDistribution(3), displayName='t2') taskset = (t1, t2) sim = Simulation(taskset) state = sim.firstDeadlineMiss() expected = SimulatorState(50, [JobState(t2, 16), JobState(t1, 2), JobState(t1, 0, 16, lastStart=48), JobState(t1, 1), JobState(t2, 17)], [StateArrival(100, t1, 2), StateDeadline(51, t2, 16), StateCompletion(52, t1, 0), StateArrival(51, t2, 17), StateDeadline(100, t1, 1)], deadlineMisses=[DeadlineMiss(t1, 0)], scheduler=EDFSchedulerState((50, t1, 0), (51, t2, 16), (100, t1, 1))) assert(state == expected)
def test_rmIsBad(): t1 = Task(2, 5, FixedArrivalDistribution(5), displayName='t1') t2 = Task(4, 7, FixedArrivalDistribution(7), displayName='t2') taskset = Taskset(t1, t2) setup = SimulationSetup(taskset, time=35, schedulingPolicy=RMSchedulingPolicy(), deadlineMissFilter=True) run = SimulationRun(setup) result = run.result() deadlineMiss = result.history.firstDeadlineMiss() expectedMiss = DeadlineMiss(t2, 0) assert deadlineMiss == expectedMiss
def test_deadlineMiss(): task = Task(4, 3, FixedArrivalDistribution(5), displayName='t') taskset = Taskset(task) sim = Simulation(taskset) endTime = 5 missTime = 3 sim.getState(endTime) deadlineState = sim.getState(missTime) (deadlineMissFromState,) = deadlineState.deadlineMisses history = sim.history deadlineMissFromHistory, = history.deadlineMisses(endTime, time=3, task=task) expectedMiss = DeadlineMiss(task, 0) assert(deadlineMissFromState == expectedMiss) assert(deadlineMissFromHistory == expectedMiss)
def test_dualPriorityBW3_1(): t1 = Task(4, 16) t2 = Task(5, 20) t3 = Task(11, 28) t4 = Task(6, 56) policy = DualPrioritySchedulingPolicy((t1, DualPriorityTaskInfo(4)), (t2, DualPriorityTaskInfo(5)), (t3, DualPriorityTaskInfo(6)), (t4, DualPriorityTaskInfo(7))) taskset = Taskset(t1, t2, t3, t4) hyperperiod = 560 setup = SimulationSetup(taskset, time=hyperperiod, schedulingPolicy=policy) result = SimulationRun(setup).result() expectedMiss = DeadlineMiss(t3, 0) assert result.history.firstDeadlineMiss() == expectedMiss
def test_dualPriorityBW1_1(): t1 = Task(3, 6) t2 = Task(2, 8) t3 = Task(3, 12) policy = DualPrioritySchedulingPolicy((t1, DualPriorityTaskInfo(2)), (t2, DualPriorityTaskInfo(3)), (t3, DualPriorityTaskInfo(4))) taskset = Taskset(t1, t2, t3) hyperperiod = 24 setup = SimulationSetup(taskset, time=hyperperiod, schedulingPolicy=policy) run = SimulationRun(setup) result = run.result() expectedMisses = {DeadlineMiss(t3, 0)} assert result.history.deadlineMisses(hyperperiod) == expectedMisses
def test_dualPriorityBW4_2(): t1 = Task(1, 4) t2 = Task(1, 6) t3 = Task(3, 12) t4 = Task(5, 30) t5 = Task(6, 36) policy = DualPrioritySchedulingPolicy((t1, DualPriorityTaskInfo(3)), (t2, DualPriorityTaskInfo(4)), (t3, DualPriorityTaskInfo(5)), (t4, DualPriorityTaskInfo(7)), (t5, DualPriorityTaskInfo(8, 23, 6))) taskset = Taskset(t1, t2, t3, t4, t5) hyperperiod = 180 setup = SimulationSetup(taskset, time=hyperperiod, schedulingPolicy=policy) result = SimulationRun(setup).result() expectedMiss = DeadlineMiss(t4, 4) assert result.history.firstDeadlineMiss() == expectedMiss