Search in sources :

Example 1 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class SchedulingTest method testNStepScheduler.

@Test
public void testNStepScheduler() {
    final SchedulingStrategy ss = mock(SchedulingStrategy.class);
    doCallRealMethod().when(ss).setBaseScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).setCurrentScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).doSingleStep();
    TotalScheduler ts = mock(TotalScheduler.class);
    ScheduleAction scheduleAction = mock(ScheduleAction.class, Mockito.RETURNS_DEEP_STUBS);
    when(ts.choose(any(ScheduleOptions.class))).thenReturn(scheduleAction);
    TaskInfo taskInfo = mock(TaskInfo.class);
    when(ts.schedule(any(TaskScheduler.class), any(List.class))).thenReturn(taskInfo);
    ss.setBaseScheduler(ts);
    final int numberSteps = new Random().nextInt(100);
    final NStepScheduler nss = new NStepScheduler(ss, numberSteps);
    ss.setCurrentScheduler(nss);
    Thread schedulingThread = new Thread(new Runnable() {

        @Override
        public void run() {
            ScheduleOptions scheduleOptions = mock(ScheduleOptions.class, Mockito.RETURNS_DEEP_STUBS);
            for (int i = 0; i < numberSteps; i++) {
                ss.curScheduler.choose(scheduleOptions);
            }
            assertEquals(nss, ss.curScheduler);
            ss.curScheduler.choose(scheduleOptions);
        }
    });
    try {
        schedulingThread.start();
        schedulingThread.join();
        verify(ss).awaitGUIAction(any(ScheduleOptions.class));
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : TotalScheduler(org.absmodels.abs.plugin.debug.scheduling.TotalScheduler) NStepScheduler(org.absmodels.abs.plugin.debug.scheduling.NStepScheduler) TaskScheduler(abs.backend.java.scheduling.TaskScheduler) TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) SchedulingStrategy(org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy) ScheduleOptions(abs.backend.java.scheduling.ScheduleOptions) ScheduleAction(abs.backend.java.scheduling.ScheduleAction) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class SchedulingTest method testRunToLineScheduler.

@Test
public void testRunToLineScheduler() {
    final SchedulingStrategy ss = mock(SchedulingStrategy.class);
    doCallRealMethod().when(ss).setBaseScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).setCurrentScheduler(any(TotalScheduler.class));
    doCallRealMethod().when(ss).doSingleStep();
    TotalScheduler ts = mock(TotalScheduler.class);
    ScheduleAction scheduleAction = mock(ScheduleAction.class, Mockito.RETURNS_DEEP_STUBS);
    when(ts.choose(any(ScheduleOptions.class))).thenReturn(scheduleAction);
    TaskInfo taskInfo = mock(TaskInfo.class);
    when(ts.schedule(any(TaskScheduler.class), any(List.class))).thenReturn(taskInfo);
    ss.setBaseScheduler(ts);
    final int line = new Random().nextInt(1000);
    final String fileName = "filename";
    abs.backend.java.debugging.TaskInfo ti = mock(abs.backend.java.debugging.TaskInfo.class);
    when(ti.getCurrentFile()).thenReturn("filename");
    when(ti.getCurrentLine()).thenReturn(line - 5).thenReturn(line - 4).thenReturn(line - 3).thenReturn(line - 2).thenReturn(line - 1).thenReturn(line);
    ss.steppedTask = ti;
    RunToLineScheduler rtls = new RunToLineScheduler(ss, fileName, line);
    ss.setCurrentScheduler(rtls);
    ScheduleOptions scheduleOptions = mock(ScheduleOptions.class, Mockito.RETURNS_DEEP_STUBS);
    for (int i = 0; i < 6; i++) {
        ss.curScheduler.choose(scheduleOptions);
    }
    verify(ss).awaitGUIAction(any(ScheduleOptions.class));
}
Also used : TotalScheduler(org.absmodels.abs.plugin.debug.scheduling.TotalScheduler) TaskScheduler(abs.backend.java.scheduling.TaskScheduler) TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) SchedulingStrategy(org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy) ScheduleOptions(abs.backend.java.scheduling.ScheduleOptions) RunToLineScheduler(org.absmodels.abs.plugin.debug.scheduling.RunToLineScheduler) ScheduleAction(abs.backend.java.scheduling.ScheduleAction) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 3 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class Cog method setupAPI.

private static void setupAPI() {
    thisClass.setName("Cog");
    thisClass.addMethod(/*List<Process>*/
    "getQueue", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            // TODO
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "info", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            COG cog = (COG) t.getFieldValue_Internal("cog");
            System.out.println("Cog scheduler " + cog.getScheduler().toString());
            if (cog.getScheduler() instanceof SimpleTaskScheduler) {
                SimpleTaskScheduler sch = (SimpleTaskScheduler) cog.getScheduler();
                TaskSchedulingStrategy strat = sch.getSchedulingStrategy();
                System.out.println("Strategy " + strat);
            }
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "setScheduler", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            COG cog = (COG) t.getFieldValue_Internal("cog");
            if (!(cog.getScheduler() instanceof SimpleTaskScheduler)) {
                throw new DynamicException("For user-defined scheduling to work, the Scheduler must be an instance of " + SimpleTaskScheduler.class.getName() + " (use \"-taskscheduler=simple\")");
            }
            // The user-defined scheduler
            final ABSDynamicObject userScheduler = (ABSDynamicObject) params[0];
            // Create a new scheduling strategy that invokes the user-defined scheduler's "schedule" method
            // - convert TaskSchedulingStrategy's List<TaskInfo> to ProcessScheduler's List<Process>
            // - convert returned Process to TaskInfo.
            // custom TaskSchedulingStrategy
            TaskSchedulingStrategy strategy = new TaskSchedulingStrategy() {

                @Override
                public synchronized TaskInfo schedule(final TaskScheduler scheduler, final List<TaskInfo> schedulableTasks) {
                    System.out.println("Scheduling (" + schedulableTasks.size() + " processes in queue)...");
                    // Remember TaskInfos based on their Pids to speed things up a little
                    HashMap<Long, TaskInfo> taskMap = new HashMap<>();
                    // Convert List<TaskInfo> to ArrayList<ABSProcess>
                    ArrayList<ABSProcess> processes = new ArrayList<>();
                    for (TaskInfo task : schedulableTasks) {
                        taskMap.put(task.id, task);
                        // TODO set: pid, method, arrival, cost, deadline, start, finish, critical, value
                        ABSProcess proc = new ABSProcess(task.task.getID(), task.task.getCall().methodName(), 0, 0, 0, 0, 0, false, 0);
                        processes.add(proc);
                        System.out.println("\t" + proc.toString());
                    }
                    // FIXME
                    return schedulableTasks.get(0);
                }
            };
            // Connect the strategy to the cog's scheduler
            System.out.println(cog.toString() + ": Setting TaskSchedulingStrategy to: " + userScheduler.getClassName());
            // move the userScheduler object to the Cog
            // this WILL cause problems if the user associates the scheduler with multiple cogs!!
            // userScheduler.setCOG(cog);
            SimpleTaskScheduler scheduler = (SimpleTaskScheduler) cog.getScheduler();
            scheduler.setSchedulingStrategy(strategy);
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(abs.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(abs.backend.java.lib.runtime.ABSClosure) HashMap(java.util.HashMap) SimpleTaskScheduler(abs.backend.java.scheduling.SimpleTaskScheduler) ArrayList(java.util.ArrayList) ABSValue(abs.backend.java.lib.types.ABSValue) SimpleTaskScheduler(abs.backend.java.scheduling.SimpleTaskScheduler) TaskScheduler(abs.backend.java.scheduling.TaskScheduler) ABSProcess(abs.backend.java.lib.types.ABSProcess) DynamicException(abs.backend.java.codegeneration.dynamic.DynamicException) TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo) TaskSchedulingStrategy(abs.backend.java.scheduling.TaskSchedulingStrategy) COG(abs.backend.java.lib.runtime.COG)

Example 4 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class SwingWrapperProxy method awaitGUITaskChoose.

private synchronized TaskInfo awaitGUITaskChoose() {
    while (choosenTask == null) {
        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    TaskInfo t = choosenTask;
    choosenTask = null;
    return t;
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)

Example 5 with TaskInfo

use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.

the class RecordingSchedulerStrategy method schedule.

@Override
public TaskInfo schedule(TaskScheduler scheduler, List<TaskInfo> scheduableTasks) {
    int cogId = scheduler.getCOG().getID();
    TaskInfo choosenTask = schedulingStrat.schedule(scheduler, scheduableTasks);
    long taskId = choosenTask.id;
    String suff = scheduableTasks.size() == 1 ? " (NO CHOICE)" : "";
    System.out.println("COG " + cogId + " (" + scheduler.getCOG().getInitialClass().getName() + "): Scheduled task " + taskId + " from {" + tasksToStringList(cogId, scheduableTasks) + "}" + suff);
    return choosenTask;
}
Also used : TaskInfo(abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)

Aggregations

TaskInfo (abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo)15 ArrayList (java.util.ArrayList)7 TaskScheduler (abs.backend.java.scheduling.TaskScheduler)5 ScheduleAction (abs.backend.java.scheduling.ScheduleAction)4 ScheduleOptions (abs.backend.java.scheduling.ScheduleOptions)4 List (java.util.List)4 SchedulingStrategy (org.absmodels.abs.plugin.debug.scheduling.SchedulingStrategy)4 TotalScheduler (org.absmodels.abs.plugin.debug.scheduling.TotalScheduler)4 Test (org.junit.Test)4 ABSProcess (abs.backend.java.lib.types.ABSProcess)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2 DynamicException (abs.backend.java.codegeneration.dynamic.DynamicException)1 ABSClosure (abs.backend.java.lib.runtime.ABSClosure)1 ABSDynamicObject (abs.backend.java.lib.runtime.ABSDynamicObject)1 COG (abs.backend.java.lib.runtime.COG)1 ABSValue (abs.backend.java.lib.types.ABSValue)1 TaskStackFrameView (abs.backend.java.observing.TaskStackFrameView)1 TaskStackView (abs.backend.java.observing.TaskStackView)1 TaskView (abs.backend.java.observing.TaskView)1