Exemple #1
0
def rmlSetups(*tasksets):
    for taskset in tasksets:
        policy = rmLaxityPromotions(taskset)
        setup = SimulationSetup(taskset,
                                taskset.hyperperiod,
                                schedulingPolicy=policy)
        yield setup
Exemple #2
0
def test_fileOutputNoPromo():
    taskset = Taskset(Task(1, 40), Task(4, 42), Task(1, 46), Task(10, 46),
                      Task(28, 60), Task(11, 64))

    def dpInfos():
        sortedTasks = sorted(taskset,
                             key=lambda x: (x.minimalInterArrivalTime, x.wcet))
        for i, task in enumerate(sortedTasks):
            yield task, DualPriorityTaskInfo(i + 1)

    policy = DualPrioritySchedulingPolicy(*dpInfos())
    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=policy)
    testPath = 'test_fileOutputNoPromo.txt'
    sof = DPOutputFile(testPath)
    cleanFile(testPath)
    sof.write(setup)

    expectedFileContent = ('1 40 40 40 1 1\n'
                           '4 42 42 42 2 2\n'
                           '1 46 46 46 3 3\n'
                           '10 46 46 46 4 4\n'
                           '28 60 60 60 5 5\n'
                           '11 64 64 64 6 6\n'
                           '\n')
    with open(testPath) as file:
        fileContent = file.read()
        assert fileContent == expectedFileContent
    cleanFile(testPath)
Exemple #3
0
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
Exemple #4
0
def test_readyQueueCollision2():
    t1 = Task(4, 2, FixedArrivalDistribution(2), displayName='t1')
    t2 = Task(5, 2, FixedArrivalDistribution(2), displayName='t2')
    taskset = Taskset(t1, t2)
    setup = SimulationSetup(taskset, time=5)
    run = SimulationRun(setup)
    run.execute()
Exemple #5
0
def test_simpleRun():
    t1 = Task(1, 10, FixedArrivalDistribution(10), displayName='t')
    setup = SimulationSetup(Taskset(t1), time=1000, trackHistory=True)
    setups = [setup]
    runner = simulationRunner(setups)
    runner.start()
    runner.join()
    result = runner.result(setup)
    expectedStates = [
        (10,
         SimulatorState(10, [JobState(t1, 1, lastStart=10),
                             JobState(t1, 2)], [
                                 StateCompletion(11, t1, 1),
                                 StateArrival(20, t1, 2),
                                 StateDeadline(20, t1, 1)
                             ],
                        scheduler=EDFSchedulerState((20, t1, 1)))),
        (987,
         SimulatorState(
             981, [JobState(t1, 98, 1, lastStart=981),
                   JobState(t1, 99)],
             [StateArrival(990, t1, 99),
              StateDeadline(990, t1, 98)],
             scheduler=EDFSchedulerState()))
    ]

    for time, expected in expectedStates:
        state = result.history.getLastState(time)

        logging.debug('Expected  %s', expected)
        logging.debug('Effective %s', state)
        assert (state == expected)
Exemple #6
0
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()
Exemple #7
0
def test_rmMultiple():
    t1 = Task(1, 2, FixedArrivalDistribution(2), displayName='t1')
    t2 = Task(10, 20, FixedArrivalDistribution(20), displayName='t2')
    taskset = Taskset(t1, t2)
    endTime = 25
    setup = SimulationSetup(taskset,
                            time=endTime,
                            schedulingPolicy=RMSchedulingPolicy())
    run = SimulationRun(setup)
    result = run.result()
    state = result.history[endTime]
    expected = SimulatorState(endTime,
                              [JobState(t2, 1, 2),
                               JobState(t2, 2),
                               JobState(t1, 12, 1, lastStart=25),
                               JobState(t1, 13)],
                              [StateCompletion(25, t1, 12),
                               StateDeadline(40, t2, 1),
                               StateCompletion(31, t2, 1),
                               StateArrival(26, t1, 13),
                               StateDeadline(26, t1, 12),
                               StateArrival(40, t2, 2),
                               StateCompletion(32, t2, 1)],
                              scheduler=RMSchedulerState((t1, 12), (t2, 1)))
    assert(state == expected)
Exemple #8
0
def test_setupEquality():
    taskset1 = Taskset(Task(10, 10, FixedArrivalDistribution(10), uniqueId=0))
    taskset2 = Taskset(Task(10, 10, FixedArrivalDistribution(10), uniqueId=0))
    taskset3 = Taskset(Task(9, 10, FixedArrivalDistribution(10)))
    setup1 = SimulationSetup(taskset=taskset1,
                             schedulingPolicy=SchedulerTag.EDF)
    setup2 = SimulationSetup(taskset=taskset2,
                             schedulingPolicy=SchedulerTag.EDF)
    setup3 = SimulationSetup(taskset=taskset3,
                             schedulingPolicy=SchedulerTag.EDF)

    logging.debug(hash(setup1))
    logging.debug(hash(setup2))
    logging.debug(hash(setup3))
    assert setup1 == setup2
    assert setup2 == setup1
    assert setup2 != setup3
Exemple #9
0
def test_readyQueueCollision():
    t1 = Task(1, 2, FixedArrivalDistribution(3),
              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)
    run.execute()
Exemple #10
0
def findFirstDeadlineMiss(taskset, policy):
    setup = SimulationSetup(taskset,
                            time=taskset.hyperperiod,
                            schedulingPolicy=policy,
                            deadlineMissFilter=True,
                            trackHistory=False,
                            trackPreemptions=False)
    result = SimulationRun(setup).result()
    history = result.history
    return history.firstDeadlineMiss()
Exemple #11
0
def execFunction(setup):
    taskset, policy = setup
    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=policy,
                            trackHistory=False,
                            trackPreemptions=False)
    result = SimulationRun(setup).result()
    history = result.history
    return history, policy, taskset
Exemple #12
0
def test_fileInput():
    Task.resetIdCounter()
    sif = DPInputFile('${HOME}/git/rt/tasksets/test.txt')
    setups = sif.lazyRead()
    setup1 = next(setups)
    t11 = Task(1, 5, uniqueId=0)
    t12 = Task(1, 3, uniqueId=1)
    taskset1 = Taskset(t11, t12)
    policy1 = DualPrioritySchedulingPolicy((t11, DualPriorityTaskInfo(2)),
                                           (t12, DualPriorityTaskInfo(1)))
    expected1 = SimulationSetup(taskset1,
                                taskset1.hyperperiod,
                                schedulingPolicy=policy1)
    assert setup1 == expected1

    setup2 = next(setups)
    t21 = Task(2, 12, uniqueId=2)
    t22 = Task(17, 33, uniqueId=3)
    t23 = Task(13, 57, uniqueId=4)
    taskset2 = Taskset(t21, t22, t23)
    policy2 = DualPrioritySchedulingPolicy(
        (t21, DualPriorityTaskInfo(3, 10, -3)),
        (t22, DualPriorityTaskInfo(2, 14, -2)), (t23, DualPriorityTaskInfo(1)))
    expected2 = SimulationSetup(taskset2,
                                taskset2.hyperperiod,
                                schedulingPolicy=policy2)
    assert setup2 == expected2

    setup3 = next(setups)
    t31 = Task(3, 12, uniqueId=5)
    t32 = Task(4, 16, uniqueId=6)
    t33 = Task(4, 20, uniqueId=7)
    t34 = Task(6, 20, uniqueId=8)
    taskset3 = Taskset(t31, t32, t33, t34)
    policy3 = DualPrioritySchedulingPolicy(
        (t31, DualPriorityTaskInfo(4, 12, -4)),
        (t32, DualPriorityTaskInfo(3, 9, -3)), (t33, DualPriorityTaskInfo(2)),
        (t34, DualPriorityTaskInfo(1)))
    expected3 = SimulationSetup(taskset3,
                                taskset3.hyperperiod,
                                schedulingPolicy=policy3)
    assert setup3 == expected3
Exemple #13
0
def test_executionTimeStats():
    longTask = Task(20, 50, FixedArrivalDistribution(50), displayName='long')
    shortTask = Task(1, 5, FixedArrivalDistribution(5), displayName='short')

    taskset = Taskset(longTask, shortTask)
    setup = SimulationSetup(taskset, time=29)
    run = SimulationRun(setup)
    result = run.result()
    stats = SimulationStatistics(result)
    execTime = stats.totalExecutionTime()
    assert execTime == 26
Exemple #14
0
def getHistory(taskset, policy, *stopTask):
    dmFilter = DeadlineMissFilter(False, *stopTask)

    setup = SimulationSetup(taskset,
                            time=taskset.hyperperiod,
                            deadlineMissFilter=dmFilter,
                            trackHistory=False,
                            trackPreemptions=False,
                            schedulingPolicy=policy)
    result = SimulationRun(setup).result()
    return result.history
Exemple #15
0
def test_twoTasksets():
    t1 = Task(1, 10, FixedArrivalDistribution(10), displayName='t1')
    t2 = Task(2, 5, FixedArrivalDistribution(5), displayName='t2')
    setup1 = SimulationSetup(Taskset(t1), time=1000)
    setup2 = SimulationSetup(Taskset(t1, t2), time=1000)
    tasksets = [setup1, setup2]
    runner = simulationRunner(tasksets)
    runner.start()
    runner.join()
    result2 = runner.result(setup2)
    result1 = runner.result(setup1)

    endTime = 987
    expected1 = SimulatorState(
        981, [JobState(t1, 98, 1, lastStart=981),
              JobState(t1, 99)],
        [StateArrival(990, t1, 99),
         StateDeadline(990, t1, 98)],
        scheduler=EDFSchedulerState())
    expected2 = SimulatorState(endTime, [
        JobState(t2, 198),
        JobState(t1, 98, 1, lastStart=983),
        JobState(t2, 197, 2, lastStart=987),
        JobState(t1, 99)
    ], [
        StateDeadline(990, t1, 98),
        StateDeadline(990, t2, 197),
        StateArrival(990, t1, 99),
        StateArrival(990, t2, 198)
    ],
                               scheduler=EDFSchedulerState())

    state1 = result1.history.getLastState(endTime)
    logging.debug('Expected  %s', expected1)
    logging.debug('Effective %s', state1)
    assert (state1 == expected1)

    state2 = result2.history.getLastState(endTime)
    logging.debug('Expected  %s', expected2)
    logging.debug('Effective %s', state2)
    assert (state2 == expected2)
Exemple #16
0
def test_simuDualPrio():
    t1 = Task(5, 10)
    t2 = Task(10, 20)

    policy = DualPrioritySchedulingPolicy((t1, DualPriorityTaskInfo(11, 5, 1)),
                                          (t2, DualPriorityTaskInfo(12, 10, 2)))
    taskset = Taskset(t1, t2)
    setup = SimulationSetup(taskset,
                            time=40,
                            schedulingPolicy=policy)
    run = SimulationRun(setup)
    run.execute()
Exemple #17
0
def assertGDF(taskset, success=True):
    policy = greedyDeadlineFixPolicy(taskset)
    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=policy,
                            deadlineMissFilter=True)
    result = SimulationRun(setup).result()
    history = result.history
    if success:
        assert not history.hasDeadlineMiss()
    else:
        assert history.hasDeadlineMiss()
Exemple #18
0
 def _genSetups(self, file):
     while file:
         pairs = list(self._genTasks(file))
         if not pairs:
             break
         tasks, dInfos = zip(*pairs)
         taskset = Taskset(*tasks)
         policy = DualPrioritySchedulingPolicy(*pairs)
         setup = SimulationSetup(taskset,
                                 taskset.hyperperiod,
                                 schedulingPolicy=policy)
         yield setup
Exemple #19
0
def test_saveSimulationSetup():
    t1 = Task(1, 2, FixedArrivalDistribution(3), displayName='t1')
    t2 = Task(4, 5, FixedArrivalDistribution(6), displayName='t2')
    taskset = Taskset(t1, t2)
    setup = SimulationSetup(taskset, time=200)

    with TemporaryDirectory() as testdir:
        dataEnv = FileEnv(testdir)
        key = 'test'
        dataEnv.save(setup, key)
        copy = dataEnv.load(key)
    assert(copy == setup)
Exemple #20
0
def test_executionTimeAggregator():
    longTask = Task(20, 50, FixedArrivalDistribution(50), displayName='long')
    shortTask = Task(1, 5, FixedArrivalDistribution(5), displayName='short')

    taskset = Taskset(longTask, shortTask)
    setup = SimulationSetup(taskset,
                            time=29,
                            aggregatorTags=[AggregatorTag.ExecutionTime])
    run = SimulationRun(setup)
    result = run.result()
    aggregateExecTime = result.aggregateStat(AggregatorTag.ExecutionTime)
    assert aggregateExecTime == 26
Exemple #21
0
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
Exemple #22
0
def execFunction(taskset, lpvPrep):
    policy = rmLaxityPromotions(taskset, lpvPrep=lpvPrep)
    if len(policy.promotedTasks()) > 0:
        setup = SimulationSetup(taskset,
                                taskset.hyperperiod,
                                schedulingPolicy=policy,
                                trackHistory=False,
                                trackPreemptions=False)
        result = SimulationRun(setup).result()
        history = result.history
    else:
        history = True
    return history, policy, taskset
Exemple #23
0
def test_counterExample1():
    t1 = Task(23, 40)
    t2 = Task(23, 58)
    t3 = Task(1, 60)
    taskset = Taskset(t1, t2, t3)

    dPolicy = dichotomicPromotionSearch(taskset)
    dSetup = SimulationSetup(taskset,
                             taskset.hyperperiod,
                             schedulingPolicy=dPolicy,
                             trackHistory=True,
                             trackPreemptions=False)
    dHistory = SimulationRun(dSetup).result().history
    assert not dHistory.hasDeadlineMiss()
Exemple #24
0
def test_rmMiss():
    taskset = Taskset(Task(10649, 72784, FixedArrivalDistribution(72784)),
                      Task(1868, 7242, FixedArrivalDistribution(7242)),
                      Task(8881, 30350, FixedArrivalDistribution(30350)),
                      Task(365, 2047, FixedArrivalDistribution(2047)),
                      Task(1202, 18528, FixedArrivalDistribution(18528)))
    setup = SimulationSetup(taskset,
                            time=10000000,
                            trackHistory=False,
                            deadlineMissFilter=True,
                            schedulingPolicy=RMSchedulingPolicy())
    run = SimulationRun(setup)
    result = run.result()
    assert result.history.hasDeadlineMiss()
Exemple #25
0
def test_firstT2Job1Standard():
    t1 = Task(2, 12, displayName='t1')
    t2 = Task(17, 33, displayName='t2')
    t3 = Task(13, 57, displayName='t3')
    taskset = Taskset(t1, t2, t3)

    policy = DualPrioritySchedulingPolicy(
          (t1, DualPriorityTaskInfo(3, 10, -3)),
          (t2, DualPriorityTaskInfo(2, 14, -2)),
          (t3, DualPriorityTaskInfo(1)))
    setup = SimulationSetup(taskset,
                            time=taskset.hyperperiod,
                            schedulingPolicy=policy,
                            deadlineMissFilter=True)
    result = SimulationRun(setup).result()
Exemple #26
0
def test_example7():
    t1 = Task(1, 5)
    t2 = Task(6, 39)
    t3 = Task(16, 39)
    taskset = Taskset(t1, t2, t3)

    policy = rmLaxityPromotions(taskset)
    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=policy,
                            trackHistory=True,
                            trackPreemptions=False)
    result = SimulationRun(setup).result()
    history = result.history
    assert not history.hasDeadlineMiss()
Exemple #27
0
def test_damien4():
    t1 = Task(8, 20, displayName='t1')
    t2 = Task(15, 28, displayName='t2')
    t3 = Task(8, 136, displayName='t3')
    taskset = Taskset(t1, t2, t3)

    policy = dichotomicPromotionSearch(taskset)
    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=policy,
                            trackHistory=True,
                            trackPreemptions=False)
    result = SimulationRun(setup).result()
    history = result.history
    assert not history.hasDeadlineMiss()
Exemple #28
0
def test_laurent1():
    t1 = Task(2, 11, displayName='t1')
    t2 = Task(9, 19, displayName='t2')
    t3 = Task(7, 21, displayName='t3')
    taskset = Taskset(t1, t2, t3)

    policy = rmLaxityPromotions(taskset)
    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=policy,
                            trackHistory=True,
                            trackPreemptions=False)
    result = SimulationRun(setup).result()
    history = result.history
    assert not history.hasDeadlineMiss()
Exemple #29
0
def test_dajamPromo1():
    t1 = Task(3, 6)
    t2 = Task(2, 8)
    t3 = Task(3, 12)
    taskset = Taskset(t1, t2, t3)

    policy = dajamPromotions(taskset)

    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=policy,
                            trackHistory=False,
                            trackPreemptions=False)
    history = SimulationRun(setup).result().history
    assert not history.hasDeadlineMiss()
Exemple #30
0
def test_bwPolicy1():
    t1 = Task(3, 6)
    t2 = Task(2, 8)
    t3 = Task(3, 12)
    taskset = Taskset(t1, t2, t3)

    bwPolicy = burnsWellingsPolicy(taskset)

    setup = SimulationSetup(taskset,
                            taskset.hyperperiod,
                            schedulingPolicy=bwPolicy,
                            trackHistory=True,
                            trackPreemptions=False)
    history = SimulationRun(setup).result().history
    assert not history.hasDeadlineMiss()