TestEarliestDeadlineFirst.java 2.52 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;
17 18 19 20 21 22 23 24 25 26 27

/**
 * TestEarliestDeadlineFirst
 */
public class TestEarliestDeadlineFirst {

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

28 29
        SynchronousTask t1 = mock(SynchronousTask.class);
        SynchronousTask t2 = mock(SynchronousTask.class);
30 31 32 33 34 35 36
        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);
37

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


    @Test
    @DisplayName("Check Getters, Tests and Simulators.")
    void testGettersTestsAndSimulators() {
        EarliestDeadlineFirst edf = new EarliestDeadlineFirst();
Michael Schmid committed
51
        SystemManager manager = new SystemManager(4);
52 53 54 55 56 57
        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
58 59 60
        assertTrue(edf.hasTest(new ChwaLee(manager)));
        assertFalse(edf.hasTest(new SchmidMottok(manager)));
        assertFalse(edf.hasTest(new MaiaBertogna(manager)));
61 62
        // assertTrue(edf.hasSimulator(new ParallelSynchronous(mock(SystemSetup.class))));
        // assertTrue(edf.hasSimulator(new DynamicForkJoin(mock(SystemSetup.class))));
63 64 65 66

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

67
}