TestEarliestDeadlineFirst.java 2.59 KB
Newer Older
1 2
package mvd.jester.priority;

3
import static org.junit.jupiter.api.Assertions.assertFalse;
4
import static org.junit.jupiter.api.Assertions.assertTrue;
5 6
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
7 8
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
9
import mvd.jester.model.SynchronousTask;
Michael Schmid committed
10
import mvd.jester.model.SystemManager;
11 12 13 14 15 16
import mvd.jester.simulator.DynamicForkJoin;
import mvd.jester.simulator.ParallelSynchronous;
import mvd.jester.simulator.internals.parallelsynchronous.TaskContext;
import mvd.jester.tests.ChwaLee;
import mvd.jester.tests.MaiaBertogna;
import mvd.jester.tests.SchmidMottok;
Michael Schmid committed
17
import mvd.jester.tests.TypeFunction;
18 19 20 21 22 23 24 25 26 27 28

/**
 * TestEarliestDeadlineFirst
 */
public class TestEarliestDeadlineFirst {

    @Test
    @DisplayName("Test if priority manager returns the correct priority.")
    public void testPriority() {
        EarliestDeadlineFirst edf = new EarliestDeadlineFirst();

29 30
        SynchronousTask t1 = mock(SynchronousTask.class);
        SynchronousTask t2 = mock(SynchronousTask.class);
31 32 33 34 35 36 37
        when(t1.getDeadline()).thenReturn((long) 100);
        when(t2.getDeadline()).thenReturn((long) 200);

        TaskContext tc1 = mock(TaskContext.class);
        TaskContext tc2 = mock(TaskContext.class);
        when(tc1.getDeadline()).thenReturn((long) 100);
        when(tc2.getDeadline()).thenReturn((long) 200);
38

39
        assertTrue(edf.compare(t1, t2) < 0);
40
        assertTrue(edf.compare(tc1, tc2) < 0);
41 42 43 44
        assertTrue(edf.compare(t1, t1) == 0);
        assertTrue(edf.compare(tc1, tc1) == 0);
        assertTrue(edf.compare(t2, t1) > 0);
        assertTrue(edf.compare(tc2, tc1) > 0);
45
    }
46 47 48 49 50 51


    @Test
    @DisplayName("Check Getters, Tests and Simulators.")
    void testGettersTestsAndSimulators() {
        EarliestDeadlineFirst edf = new EarliestDeadlineFirst();
Michael Schmid committed
52
        SystemManager manager = new SystemManager(4);
53 54 55 56 57 58
        assertTrue(edf.hasTest(ChwaLee.class));
        assertFalse(edf.hasTest(MaiaBertogna.class));
        assertFalse(edf.hasTest(SchmidMottok.class));
        assertTrue(edf.hasSimulator(ParallelSynchronous.class));
        assertTrue(edf.hasSimulator(DynamicForkJoin.class));

Michael Schmid committed
59
        assertTrue(edf.hasTest(new ChwaLee(manager)));
Michael Schmid committed
60
        assertFalse(edf.hasTest(new SchmidMottok(new TypeFunction.KownStructure(), manager)));
Michael Schmid committed
61
        assertFalse(edf.hasTest(new MaiaBertogna(manager)));
62 63
        // assertTrue(edf.hasSimulator(new ParallelSynchronous(mock(SystemSetup.class))));
        // assertTrue(edf.hasSimulator(new DynamicForkJoin(mock(SystemSetup.class))));
64 65 66 67

        assertTrue(edf.getName().equals("EDF"));
    }

68
}