def test_simuError1(): taskset = Taskset( Task(45, 6588, FixedArrivalDistribution(6588), LogPreemptionCost(3, 0.1)), Task(1, 1036, FixedArrivalDistribution(1036), LogPreemptionCost(3, 0.1)), Task(278, 1037, FixedArrivalDistribution(1037), LogPreemptionCost(3, 0.1)), Task(371, 4148, FixedArrivalDistribution(4148), LogPreemptionCost(3, 0.1)), Task(1412, 2680, FixedArrivalDistribution(2680), LogPreemptionCost(3, 0.1)), ) setup = SimulationSetup(taskset, time=1000000, trackHistory=False, trackPreemptions=False, deadlineMissFilter=True, schedulingPolicy=EDFSchedulingPolicy(), aggregatorTags=[AggregatorTag.PreemptionTime, AggregatorTag.PreemptionCount]) run = SimulationRun(setup, errorHandling=False) run.execute()
def test_simuError2(): taskset = Taskset(Task(103, 1950, FixedArrivalDistribution(1950), LogPreemptionCost(3, 0.1)), Task(109, 1287, FixedArrivalDistribution(1287), LogPreemptionCost(3, 0.1)), Task(13, 4976, FixedArrivalDistribution(4976), LogPreemptionCost(3, 0.1)), Task(380, 1925, FixedArrivalDistribution(1925), LogPreemptionCost(3, 0.1)), Task(817, 1292, FixedArrivalDistribution(1292), LogPreemptionCost(3, 0.1))) setup = SimulationSetup(taskset, time=1000000, trackHistory=False, trackPreemptions=False, deadlineMissFilter=True, schedulingPolicy=EDFSchedulingPolicy()) run = SimulationRun(setup, errorHandling=False) run.execute()
def test_saveTaskset(): t1 = Task(1, 2, FixedArrivalDistribution(3), LogPreemptionCost(1, 0.1)) t2 = Task(4, 5, PoissonArrivalDistribution(6, 2), FixedPreemptionCost(3)) taskset = Taskset(t1, t2) with TemporaryDirectory() as testdir: dataEnv = FileEnv(testdir) tasksetKey = 'testtaskset' dataEnv.save(taskset, tasksetKey) copy = dataEnv.load(tasksetKey) assert(copy == taskset)
def test_simuLogPreemptionCostTwoTasks(): longTask = Task(20, 50, FixedArrivalDistribution(50), LogPreemptionCost(0, 0.2), displayName='long') shortTask = Task(1, 9, FixedArrivalDistribution(9), displayName='short') taskset = Taskset(longTask, shortTask) sim = Simulation(taskset) endTime = 50 debtTime = 10 state1 = sim.getState(debtTime) expectedJobs1 = [JobState(shortTask, 1, 1, lastStart=10), JobState(shortTask, 2), JobState(longTask, 1), JobState(longTask, 0, 8, preemptionDebt=2)] expectedEvents1 = [StateDeadline(50, longTask, 0), StateDeadline(18, shortTask, 1), StateCompletion(10, shortTask, 1), StateCompletion(21, longTask, 0), StateArrival(18, shortTask, 2), StateArrival(50, longTask, 1)] expectedScheduler1 = EDFSchedulerState((18, shortTask, 1), (50, longTask, 0)) expected1 = SimulatorState(debtTime, expectedJobs1, expectedEvents1, scheduler=expectedScheduler1) logging.debug(state1) logging.debug(expected1) assert(state1 == expected1) state2 = sim.getState(endTime) expectedJobs2 = [JobState(shortTask, 5, 1, lastStart=46), JobState(shortTask, 6), JobState(longTask, 0, 20, lastStart=27), JobState(longTask, 1)] expectedEvents2 = [StateDeadline(50, longTask, 0), StateArrival(54, shortTask, 6), StateArrival(50, longTask, 1), StateDeadline(54, shortTask, 5)] expected2 = SimulatorState(endTime, expectedJobs2, expectedEvents2) logging.debug(state2) assert(sim.noDeadlineMiss(endTime)) assert(state2 == expected2)
def test_simulationResult(): t1 = Task(1, 2, FixedArrivalDistribution(3), LogPreemptionCost(1, 0.1), displayName='t1') t2 = Task(4, 5, PoissonArrivalDistribution(6, 2), FixedPreemptionCost(3), displayName='t2') taskset = Taskset(t1, t2) setup = SimulationSetup(taskset, time=200) run = SimulationRun(setup) result = run.result() with TemporaryDirectory() as testdir: dataEnv = FileEnv(testdir) key = 'test' dataEnv.save(result, key) copy = dataEnv.load(key) assert(copy == result)
def genSetups(nbTasksets, aggregators): preemptionCost = RandomValue(generator=lambda: LogPreemptionCost(3, 0.1)) gen = TasksetGenerator(seed=1337, scale=100, nbTasks=RandomValue(value=5), period=RandomValue(logRange=(10, 1000)), preemptionCost=preemptionCost, utilization=RandomValue(floatrange=(0.6, 1))) tasksets = [gen() for _ in range(nbTasksets)] for taskset in tasksets: yield SimulationSetup(taskset, time=10000000, trackHistory=False, trackPreemptions=False, deadlineMissFilter=True, aggregatorTags=aggregators)
def test_memoryEnv(): t1 = Task(1, 2, FixedArrivalDistribution(3), LogPreemptionCost(1, 0.1)) t2 = Task(4, 5, PoissonArrivalDistribution(6, 2), FixedPreemptionCost(3)) taskset = Taskset(t1, t2) state = SimulatorState(82000, [JobState(t1, 55, preemptionDebt=1515), JobState(t2, 66, lastStart=42)], [StateDeadline(77, t1, 2), StateArrival(88, t2, 3), StateCompletion(99, t1, 4)], scheduler=EDFSchedulerState((1043, t1, 1001), (1042, t2, 1002))) dataEnv = MemoryEnv() stateKey = 'teststate' tasksetKey = 'testtaskset' dataEnv.save(state, stateKey) dataEnv.save(taskset, tasksetKey) stateCopy = dataEnv.load(stateKey) tasksetCopy = dataEnv.load(tasksetKey) assert(state == stateCopy) assert(taskset == tasksetCopy)
def test_logPreemptionsTotals(): longTask = Task(2000, 5000, FixedArrivalDistribution(5000), LogPreemptionCost(1, 0.1), displayName='long') shortTask = Task(100, 500, FixedArrivalDistribution(500), displayName='short') taskset = Taskset(longTask, shortTask) setup = SimulationSetup(taskset, time=5000, trackPreemptions=True) run = SimulationRun(setup) result = run.result() stats = SimulationStatistics(result) nbPreemptions = stats.nbOfPreemptions expectedNbPreemptions = 6 preemptionCost = stats.totalPreemptionTime expectedPreemptionCost = 685 assert nbPreemptions == expectedNbPreemptions assert preemptionCost == expectedPreemptionCost
def test_createTaskWithLogPreemptionCost(): task = Task(2, 3, FixedArrivalDistribution(6), LogPreemptionCost(0, 0.1)) assert(task.wcet == 2) assert(task.deadline == 3) assert(task.arrivalDistribution == FixedArrivalDistribution(6)) assert(task.preemptionCost == LogPreemptionCost(0, 0.1))