TestSegmentContext.java 3.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
// package mvd.jester.simulator.dynamicforkjoin;

// import static org.junit.jupiter.api.Assertions.assertFalse;
// import static org.junit.jupiter.api.Assertions.assertTrue;
// import static org.mockito.Mockito.mock;
// import static org.mockito.Mockito.when;
// import java.util.Optional;
// import java.util.concurrent.ThreadLocalRandom;
// import org.junit.jupiter.api.DisplayName;
// import org.junit.jupiter.api.Test;
// import mvd.jester.model.Segment;
// import mvd.jester.simulator.internals.JobContextInterface;
// import mvd.jester.simulator.internals.ProcessorContext;
// import mvd.jester.simulator.internals.dynamicforkjoin.JobContext;
// import mvd.jester.simulator.internals.dynamicforkjoin.SegmentContext;
// import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext;
// import mvd.jester.simulator.internals.dynamicforkjoin.TaskletContext;

// /**
// * TestSegmentContext
// */
// public class TestSegmentContext {

// @Test
// @DisplayName("Check if segment returns the jobs correctly.")
// void testGetNextJob() {
// for (int run = 0; run < 100; ++run) {
// long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
// long jobWcet = ThreadLocalRandom.current().nextLong(20, 50);

// Segment s = mock(Segment.class);
// when(s.getNumberOfJobs()).thenReturn(numberOfJobs);
// when(s.getJobWcet()).thenReturn(jobWcet);
// TaskContext tc = mock(TaskContext.class);

// SegmentContext sc = new SegmentContext(tc, s, 4);
// Optional<JobContextInterface> job = Optional.empty();

// when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty());

// long numJobs = numberOfJobs > 4 ? 4 : numberOfJobs;
// for (int i = 0; i < numJobs; ++i) {
// job = sc.getNextJob();
// assertTrue(job.isPresent());
// job.get().setCurrentProcessor(new ProcessorContext(i));
// }

// assertFalse(sc.getNextJob().isPresent());

// sc = new SegmentContext(tc, s, 4);

// job = sc.getNextJob();
// assertTrue(job.isPresent());
// job.get().setCurrentProcessor(new ProcessorContext(0));
// for (int i = 0; i < jobWcet * numberOfJobs; ++i) {
// job.get().updateExecution(i);
// }

// assertFalse(sc.getNextJob().isPresent());
// }
// }

// @Test
// @DisplayName("Check if SegmentContext returns the correct amount of tasklets.")
// void testGetNextTasklet() {
// for (int run = 0; run < 100; ++run) {
// long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
// long jobWcet = ThreadLocalRandom.current().nextLong(20, 50);

// Segment s = mock(Segment.class);
// when(s.getNumberOfJobs()).thenReturn(numberOfJobs);
// when(s.getJobWcet()).thenReturn(jobWcet);
// TaskContext tc = mock(TaskContext.class);
// when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty());

// SegmentContext sc = new SegmentContext(tc, s, 4);

// for (int i = 0; i < jobWcet; ++i) {
// Optional<TaskletContext> tci = sc.getNextTasklet();
// assertTrue(tci.isPresent());
// tci.get().setCurrentJob(mock(JobContext.class));
// }

// assertFalse(sc.getNextTasklet().isPresent());

// sc = new SegmentContext(tc, s, 4);

// for (int i = 0; i < jobWcet; ++i) {
// Optional<TaskletContext> tasklet = sc.getNextTasklet();
// assertTrue(tasklet.isPresent());
// tasklet.get().setCurrentJob(mock(JobContext.class));
// for (int j = 0; j < numberOfJobs; ++j) {
// tasklet.get().updateExecution(j);
// }
// }

// assertFalse(sc.getNextTasklet().isPresent());
// }
// }

// }