From: <jsa...@us...> - 2009-02-17 18:59:37
|
Revision: 143 http://flexotask.svn.sourceforge.net/flexotask/?rev=143&view=rev Author: jsauerbach Date: 2009-02-17 18:59:33 +0000 (Tue, 17 Feb 2009) Log Message: ----------- Add test for new scheduler diagnostic support. Modified Paths: -------------- trunk/flexotask-functiontest/src/alltests/Testcases.java Added Paths: ----------- trunk/flexotask-functiontest/src/badscheduler/ trunk/flexotask-functiontest/src/badscheduler/BadScheduler.java trunk/flexotask-functiontest/src/badscheduler/BadSchedulerRunnable.java trunk/flexotask-functiontest/src/badscheduler/Main.java Modified: trunk/flexotask-functiontest/src/alltests/Testcases.java =================================================================== --- trunk/flexotask-functiontest/src/alltests/Testcases.java 2009-02-17 18:59:04 UTC (rev 142) +++ trunk/flexotask-functiontest/src/alltests/Testcases.java 2009-02-17 18:59:33 UTC (rev 143) @@ -75,6 +75,12 @@ nativeio.Main.main(new String[0]); } + @Test + public void testBadScheduler() throws FlexotaskValidationException + { + badscheduler.Main.main(new String[0]); + } + /** * Method to test in a non-eclipse environment (e.g. a realtime VM) */ Added: trunk/flexotask-functiontest/src/badscheduler/BadScheduler.java =================================================================== --- trunk/flexotask-functiontest/src/badscheduler/BadScheduler.java (rev 0) +++ trunk/flexotask-functiontest/src/badscheduler/BadScheduler.java 2009-02-17 18:59:33 UTC (rev 143) @@ -0,0 +1,68 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package badscheduler; + +import java.util.Collections; +import java.util.Map; + +import com.ibm.realtime.flexotask.FlexotaskRunner; +import com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler; +import com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulingData; +import com.ibm.realtime.flexotask.scheduling.FlexotaskSingleThreadRunner; +import com.ibm.realtime.flexotask.scheduling.FlexotaskThreadFactory; +import com.ibm.realtime.flexotask.template.FlexotaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; + +/** + * A scheduler designed to misbehave in various ways to test scheduler diagnostics + */ +public class BadScheduler implements FlexotaskScheduler +{ + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler#getHeapSizes(com.ibm.realtime.flexotask.template.FlexotaskTemplate, com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulingData) + */ + @SuppressWarnings("unchecked") + public Map getHeapSizes(FlexotaskTemplate toSchedule, FlexotaskSchedulingData schedulingData) + throws FlexotaskValidationException + { + return Collections.EMPTY_MAP; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler#getRejectionReason() + */ + public String getRejectionReason() { + return ""; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler#isSchedulable(com.ibm.realtime.flexotask.template.FlexotaskTemplate, com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulingData) + */ + public boolean isSchedulable(FlexotaskTemplate toSchedule, FlexotaskSchedulingData schedulingData) { + return true; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler#schedule(com.ibm.realtime.flexotask.template.FlexotaskTemplate, java.util.Map, com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulingData, com.ibm.realtime.flexotask.scheduling.FlexotaskThreadFactory, java.util.Map) + */ + @SuppressWarnings("unchecked") + public FlexotaskRunner schedule(FlexotaskTemplate toSchedule, Map instantiationMap, FlexotaskSchedulingData schedulingData, + FlexotaskThreadFactory threadFactory, Map initializationMap) throws FlexotaskValidationException + { + int[] mode = (int[]) initializationMap.get("only"); + Runnable toRun = (Runnable) instantiationMap.get(toSchedule.getTasks().iterator().next()); + BadSchedulerRunnable runnable = new BadSchedulerRunnable(toRun, mode[0]); + return FlexotaskSingleThreadRunner.cloneAndStartThread(runnable, threadFactory); + } +} Property changes on: trunk/flexotask-functiontest/src/badscheduler/BadScheduler.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/badscheduler/BadSchedulerRunnable.java =================================================================== --- trunk/flexotask-functiontest/src/badscheduler/BadSchedulerRunnable.java (rev 0) +++ trunk/flexotask-functiontest/src/badscheduler/BadSchedulerRunnable.java 2009-02-17 18:59:33 UTC (rev 143) @@ -0,0 +1,57 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package badscheduler; + +import com.ibm.realtime.flexotask.scheduling.FlexotaskSingleThreadRunner; + +/** + * The SchedulerRunnable for BadScheduler + */ +public class BadSchedulerRunnable extends FlexotaskSingleThreadRunner +{ + private int mode; + private Runnable toRun; + + /** + * Make a new BadSchedulerRunnable + * @param toRun the Runnable to run a few times before failing + * @param mode the failure mode (see Main or read code for meanings) + */ + public BadSchedulerRunnable(Runnable toRun, int mode) { + this.toRun = toRun; + this.mode = mode; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.scheduling.FlexotaskSingleThreadRunner#runFlexotasks(boolean) + */ + public boolean runFlexotasks(boolean freshRun) { + int count = 5; + while (count-- > 0) { + toRun.run(); + nanosleep(nanoTime() + 100 * 1000 * 1000); // 100ms + } + switch (mode) { + case 0: + return true; + case 1: + int i = ((int[]) null).length; + case 2: + throw new IllegalArgumentException("voila"); + case 3: + long l = new Long(6); + } + return false; + } +} Property changes on: trunk/flexotask-functiontest/src/badscheduler/BadSchedulerRunnable.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/badscheduler/Main.java =================================================================== --- trunk/flexotask-functiontest/src/badscheduler/Main.java (rev 0) +++ trunk/flexotask-functiontest/src/badscheduler/Main.java 2009-02-17 18:59:33 UTC (rev 143) @@ -0,0 +1,141 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package badscheduler; + +import java.util.HashMap; +import java.util.Map; + +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskGraph; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; +import com.ibm.realtime.flexotask.FlexotaskRunner; +import com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler; +import com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulerFactory; +import com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulerRegistry; +import com.ibm.realtime.flexotask.template.FlexotaskTaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.util.SimulationSupport; + +/** + * Tests latest support for diagnosing schedulers that fail. + */ +public class Main +{ + public static void main(String[] args) throws FlexotaskValidationException { + /* Set up bad scheduler factory */ + FlexotaskSchedulerRegistry.registerScheduler(new FlexotaskSchedulerFactory(){ + public String getName() { + return "bad"; + } + public FlexotaskScheduler getSchedulerInstance() { + return new BadScheduler(); + } + }); + /* Make single task template for testing */ + FlexotaskTemplate template = new FlexotaskTemplate(); + FlexotaskTaskTemplate task = new FlexotaskTaskTemplate(); + task.setName("only"); + task.setImplementationClass(NullFlexotask.class.getName()); + template.getTasks().add(task); + /* Set up to run the same template successively in different failure modes. The mode is indicated to the scheduler + * via the parameter passed to the only task + */ + int[] mode = new int[1]; + Map<String,Object> parameters = new HashMap<String,Object>(); + parameters.put("only", mode); + /* In mode 0, the scheduler runs the task for a few seconds but doesn't fail */ + FlexotaskGraph graph = template.validate("bad", parameters); + graph.getRunner().start(); + try { Thread.sleep(2000); } catch(InterruptedException e) {} + FlexotaskRunner runner = graph.getRunner(); + if (runner != null) { + graph.getRunner().shutdown(); + } + if (graph.getException() != null) { + throw new IllegalStateException("Unexpected exception in mode 0", graph.getException()); + } + /* In mode 1, the scheduler fails with a NullPointerException, simulating some programming mistake */ + mode[0] = 1; + graph = template.validate("bad", parameters); + graph.getRunner().start(); + try { Thread.sleep(2000); } catch(InterruptedException e) {} + runner = graph.getRunner(); + if (runner != null) { + graph.getRunner().shutdown(); + } + Throwable ex = graph.getException(); + if (ex == null) { + throw new IllegalStateException("Scheduler failed to fail in mode 1"); + } + if (!(ex instanceof NullPointerException)) { + throw new IllegalStateException("Unexpected exception type " + ex.getClass().getName() + " in mode 1"); + } + /* In mode 2, the scheduler throws IllegalArgumentException with message "voila", simulating the scheduler finding some + * terminal violation of its assumptions */ + mode[0] = 2; + graph = template.validate("bad", parameters); + graph.getRunner().start(); + try { Thread.sleep(2000); } catch(InterruptedException e) {} + runner = graph.getRunner(); + if (runner != null) { + graph.getRunner().shutdown(); + } + ex = graph.getException(); + if (ex == null) { + throw new IllegalStateException("Scheduler failed to fail in mode 2"); + } + if (!(ex instanceof IllegalArgumentException)) { + throw new IllegalStateException("Unexpected exception type " + ex.getClass().getName() + " in mode 2"); + } + if (!"voila".equals(ex.getMessage())) { + throw new IllegalStateException("Unexpected exception message '" + ex.getMessage() + "' in mode 2"); + } + /* In mode 3, the scheduler "accidentally" allocates something, causing an IllegalStateException to be issued + * from a controller or driver at the next memory switch. The bad class should be java.lang.Long. */ + if (SimulationSupport.isSimulating()) { + System.err.println("Skipping mode 3 test because not running in a real time VM"); + return; + } + mode[0] = 3; + graph = template.validate("bad", parameters); + graph.getRunner().start(); + try { Thread.sleep(2000); } catch(InterruptedException e) {} + runner = graph.getRunner(); + if (runner != null) { + graph.getRunner().shutdown(); + } + ex = graph.getException(); + if (ex == null) { + throw new IllegalStateException("Scheduler failed to fail in mode 3"); + } + if (!(ex instanceof IllegalStateException)) { + throw new IllegalStateException("Unexpected exception type " + ex.getClass().getName() + " in mode 3"); + } + String msg = ex.getMessage(); + if (msg.indexOf(Long.class.getName()) == -1) { + throw new IllegalStateException("Unexpected exception message '" + msg + "' in mode 3"); + } + } + + public static class NullFlexotask implements Flexotask + { + public void execute() {} + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputPorts, FlexotaskOutputPort[] outputPorts, Object parameter) { + } + } + +} Property changes on: trunk/flexotask-functiontest/src/badscheduler/Main.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |