示例#1
0
  public static void main(String[] args) {
    String props;
    ProtocolTester t;
    Harness h;

    if (args.length < 1 || args.length > 2) {
      System.out.println("ProtocolTester <protocol stack spec> [-trace]");
      return;
    }
    props = args[0];

    try {
      h = new Harness();
      t = new ProtocolTester(props, h);
      System.out.println("protocol specification is " + t.getProtocolSpec());
      h.down(new Event(Event.BECOME_SERVER));
      for (int i = 0; i < 5; i++) {
        System.out.println("Sending msg #" + i);
        h.down(new Event(Event.MSG, new Message(null, null, "Hello world #" + i)));
      }
      Util.sleep(500);
      t.stop();
    } catch (Exception ex) {
      System.err.println(ex);
    }
  }
示例#2
0
 /**
  * Call this method whenever a violation of requirements is detected. Warnings are automatically
  * tracked and summarized at the end of the test.
  *
  * @param warning A string describing the violation that occurred.
  */
 protected final void warning(String warning) {
   // System.err.format("[" + name + "] @%4.9f: WARNING:  %s", Harness.getTime().getFracSeconds(),
   // warning);
   // System.err.println();
   Harness.log(name, "WARNING:  " + warning);
   warningCount++;
 }
 /**
  * @param dropPercentage A value in the range [0,100] that indicates how many messages should be
  *     dropped.
  */
 public DropMessagesFaultModel(double dropPercentage) {
   super("DropMessageFaultModel");
   if (dropPercentage < 0 || dropPercentage > 100) {
     throw new RuntimeException("Drop percentage out of range [0,100]: " + dropPercentage);
   }
   this.dropPercentage = dropPercentage / 100; // store as a value in the range [0.1]
   this.random = Harness.getRandomSource().getRandom();
 }
  // check for deadlocks
  @Test(timeout = 4000L)
  public void scan_LOGBACK_474() throws JoranException, IOException, InterruptedException {
    loggerContext.setName("scan_LOGBACK_474");
    File file = new File(SCAN_LOGBACK_474_FILE_AS_STR);
    // StatusListenerConfigHelper.addOnConsoleListenerInstance(loggerContext, new
    // OnConsoleStatusListener());
    configure(file);

    // ReconfigureOnChangeTask roct = waitForReconfigureOnChangeTaskToRun();

    int expectedResets = 2;
    Harness harness = new Harness(expectedResets);

    RunnableWithCounterAndDone[] runnableArray = buildRunnableArray(file, UpdateType.TOUCH);
    harness.execute(runnableArray);

    loggerContext.getStatusManager().add(new InfoStatus("end of execution ", this));
    StatusPrinter.print(loggerContext);
    checkResetCount(expectedResets);
  }
示例#5
0
  /**
   * Gets the assembly instruction at the specified virtual address.
   *
   * @param address a virtual address
   * @return the assembly instruction at the specified address
   */
  public final Instruction getInstruction(AbsoluteAddress address) {

    Instruction instr = assemblyMap.get(address);
    if (instr != null) {
      return instr;
    } else {
      // No real instructions in prologue/epilogue
      if (harness.contains(address) || isStub(address)) return null;

      ExecutableImage module = getModule(address);

      long fp = -1;
      if (module == null) {
        logger.error("No module for address " + address + ". Cannot disassemble instruction!");
      } else {
        fp = module.getFilePointer(address);
        // Also check whether fp is out of the int range, since the X86Disassembler actually
        // performs this cast in its implementation.
        if (fp < 0 || (int) fp < 0) {
          logger.error("Requested instruction outside of file area: " + address);
        } else {
          if (!module.isCodeArea(address)) {
            logger.error("Requested instruction outside code section: " + address);
            return null;
          }
          instr = module.getDisassembler().decodeInstruction(fp);
          if (instr == null) {
            logger.error("Instruction could not be disassembled at: " + address);
          }
        }
      }

      if (instr != null) putInstruction(address, instr);
      return instr;
    }
  }
示例#6
0
 /**
  * Install a harness that sets up the symbolic environment before calling main and provides a
  * return point with a termination statement.
  *
  * @param harness the harness object to install
  */
 public void installHarness(Harness harness) {
   this.harness = harness;
   harness.install(this);
 }
示例#7
0
/**
 * This class provides a basic framework for implementing runtime monitors. This class is to be used
 * for monitoring only. No class that instantiates a descendent of RuntimeMonitor or contains a
 * descendent of Runtime Monitor may modify the system state in any way! That means that no
 * controller may contain a RuntimeMonitor class.
 *
 * <p>The RuntimeMonitor class provides event triggered access to the elevator system so that you
 * can detect physical events and record information based on those events. Physical objects are the
 * Payload objects. For replicated objects, arrays of payload objects are created. The monitor
 * instantiates an object even for parts of the elevator that don't exist (like calls and atFloors
 * at non-existent landings) so you do not need to worry about null values in the arrays and maps
 *
 * <p>You can also receive network messages with the canInterface object
 *
 * <p>Whenever a payload object is updated, the appropriate receive(ReadablePayload) method is
 * called. You can override these methods to do something when the event occurs. See the
 * documentation for Networkable for more information.
 *
 * <p>You must implement the abstract method summarize(). This method is called at the end of the
 * acceptance test and allows you to report summary statistics. In particular, you will use this
 * when reporting performance information (Proj 7).
 *
 * <p>If you are using the monitor for verification of high level requirements (Proj 12), you will
 * need to use the warning() method whenever a violation is detected. Warnings are automatically
 * counted and summarized at the end of the test, so you do not need to include warning information
 * in your summary() method.
 *
 * <p>If you wish to receive timer callbacks in your monitor, be sure to use SystemTimer, not the
 * regular Timer object. SystemTimer events execute outside the randomized timing behavior of the
 * simulator. If you fail to do this and use a regular Timer class, the elevator will behave
 * differently depending on whether or not the Monitor is instantiated.
 *
 * @author Justin Ray
 */
public abstract class RuntimeMonitor extends Networkable implements TimeSensitive {

  protected final CanConnection canInterface = Harness.getCANNetwork().getCanConnection();
  private final Connection physicalInterface =
      Harness.getPhysicalNetwork().getFrameworkConnection(this);
  // data structures
  protected final ReadableDoorMotorPayload[][] doorMotors = new ReadableDoorMotorPayload[2][2];
  protected final ReadableDoorOpenPayload[][] doorOpeneds = new ReadableDoorOpenPayload[2][2];
  protected final ReadableDoorClosedPayload[][] doorCloseds = new ReadableDoorClosedPayload[2][2];
  protected final ReadableDoorReversalPayload[][] doorReversals =
      new ReadableDoorReversalPayload[2][2];
  protected final ReadableAtFloorPayload[][] atFloors =
      new ReadableAtFloorPayload[Elevator.numFloors][2];
  protected final ReadableCarCallPayload[][] carCalls =
      new ReadableCarCallPayload[Elevator.numFloors][2];
  protected final ReadableCarLightPayload[][] carLights =
      new ReadableCarLightPayload[Elevator.numFloors][2];
  protected final ReadableHallCallPayload[][][] hallCalls =
      new ReadableHallCallPayload[Elevator.numFloors][2][2];
  protected final ReadableHallLightPayload[][][] hallLights =
      new ReadableHallLightPayload[Elevator.numFloors][2][2];
  protected final ReadableCarLanternPayload[] carLanterns = new ReadableCarLanternPayload[2];
  protected final ReadableCarLevelPositionPayload carLevelPosition;
  protected final ReadableCarPositionIndicatorPayload carPositionIndicator;
  protected final ReadableCarWeightPayload carWeightPayload;
  protected final ReadableCarWeightAlarmPayload carWeightAlarmPayload;
  protected final ReadableDriveSpeedPayload driveActualSpeed;
  protected final ReadableDrivePayload driveCommandedSpeed;
  protected final ReadableEmergencyBrakePayload emergencyBrake;
  protected final DesiredFloorCanPayloadTranslator mDesiredFloor;
  protected final SystemTimer systemTimer = new SystemTimer(this);
  private int warningCount = 0;
  private String name;

  public RuntimeMonitor() {
    this.name = "RuntimeMonitor";

    // set up network inputs
    mDesiredFloor =
        new DesiredFloorCanPayloadTranslator(
            CanMailbox.getReadableCanMailbox(MessageDictionary.DESIRED_FLOOR_CAN_ID));
    canInterface.registerTimeTriggered(mDesiredFloor.getReadablePayload());
    // dummy calls to make sure the translator has the methods needed for monitoring.
    int dummyFloor = mDesiredFloor.getFloor();
    Hallway dummyHallway = mDesiredFloor.getHallway();
    Direction dummyDirection = mDesiredFloor.getDirection();

    // drive and car info (unreplicated)
    carLevelPosition = CarLevelPositionPayload.getReadablePayload();
    physicalInterface.registerEventTriggered(carLevelPosition);

    carPositionIndicator = CarPositionIndicatorPayload.getReadablePayload();
    physicalInterface.registerEventTriggered(carPositionIndicator);

    carWeightPayload = CarWeightPayload.getReadablePayload();
    physicalInterface.registerEventTriggered(carWeightPayload);

    carWeightAlarmPayload = CarWeightAlarmPayload.getReadablePayload();
    physicalInterface.registerEventTriggered(carWeightAlarmPayload);

    driveCommandedSpeed = DrivePayload.getReadablePayload();
    physicalInterface.registerEventTriggered(driveCommandedSpeed);

    driveActualSpeed = DriveSpeedPayload.getReadablePayload();
    physicalInterface.registerEventTriggered(driveActualSpeed);

    emergencyBrake = EmergencyBrakePayload.getReadablePayload();
    physicalInterface.registerEventTriggered(emergencyBrake);

    // car lanterns
    // hoistway limits
    for (Direction d : Direction.replicationValues) {
      carLanterns[d.ordinal()] = CarLanternPayload.getReadablePayload(d);
      physicalInterface.registerEventTriggered(carLanterns[d.ordinal()]);
    }

    // door values
    for (Hallway h : Hallway.replicationValues) {
      for (Side s : Side.values()) {
        int index = ReplicationComputer.computeReplicationId(h, s);

        doorMotors[h.ordinal()][s.ordinal()] = DoorMotorPayload.getReadablePayload(h, s);
        physicalInterface.registerEventTriggered(doorMotors[h.ordinal()][s.ordinal()]);

        doorOpeneds[h.ordinal()][s.ordinal()] = DoorOpenPayload.getReadablePayload(h, s);
        physicalInterface.registerEventTriggered(doorOpeneds[h.ordinal()][s.ordinal()]);

        doorCloseds[h.ordinal()][s.ordinal()] = DoorClosedPayload.getReadablePayload(h, s);
        physicalInterface.registerEventTriggered(doorCloseds[h.ordinal()][s.ordinal()]);

        doorReversals[h.ordinal()][s.ordinal()] = DoorReversalPayload.getReadablePayload(h, s);
        physicalInterface.registerEventTriggered(doorReversals[h.ordinal()][s.ordinal()]);
      }
    }

    // landing values
    for (int i = 0; i < Elevator.numFloors; ++i) {
      for (Hallway h : Hallway.replicationValues) {
        int floor = i + 1;
        atFloors[i][h.ordinal()] = AtFloorPayload.getReadablePayload(floor, h);
        physicalInterface.registerEventTriggered(atFloors[i][h.ordinal()]);

        carCalls[i][h.ordinal()] = CarCallPayload.getReadablePayload(floor, h);
        physicalInterface.registerEventTriggered(carCalls[i][h.ordinal()]);

        carLights[i][h.ordinal()] = CarLightPayload.getReadablePayload(floor, h);
        physicalInterface.registerEventTriggered(carLights[i][h.ordinal()]);

        for (Direction d : Direction.replicationValues) {
          hallCalls[i][h.ordinal()][d.ordinal()] = HallCallPayload.getReadablePayload(floor, h, d);
          physicalInterface.registerEventTriggered(hallCalls[i][h.ordinal()][d.ordinal()]);

          hallLights[i][h.ordinal()][d.ordinal()] =
              HallLightPayload.getReadablePayload(floor, h, d);
          physicalInterface.registerEventTriggered(hallLights[i][h.ordinal()][d.ordinal()]);
        }
      }
    }
  }

  /**
   * Override this method to report summary statistics at the end of the acceptance tests.
   *
   * @return An array of strings containing summary information.
   */
  protected abstract String[] summarize();

  /** @return the number of warning() calls that have occurred. */
  public final int getWarningCount() {
    return warningCount;
  }

  /** @return a string containing the warning stats */
  public final String getWarningStats() {
    return name + " generated " + warningCount + " warnings.";
  }

  public final String[] getSummaryStats() {
    String[] stats = summarize();
    String[] newArr = new String[stats.length];
    for (int i = 0; i < stats.length; i++) {
      newArr[i] = name + ":  " + stats[i];
    }
    return newArr;
  }

  /** @return name of the monitor */
  public final String getName() {
    return name;
  }

  private final void setName(String name) {
    this.name = name;
  }

  /**
   * Use this method to print informational messages to the output
   *
   * @param message Message to be printed.
   */
  protected final void message(String message) {
    Harness.log(name, message);
  }

  /**
   * Call this method whenever a violation of requirements is detected. Warnings are automatically
   * tracked and summarized at the end of the test.
   *
   * @param warning A string describing the violation that occurred.
   */
  protected final void warning(String warning) {
    // System.err.format("[" + name + "] @%4.9f: WARNING:  %s", Harness.getTime().getFracSeconds(),
    // warning);
    // System.err.println();
    Harness.log(name, "WARNING:  " + warning);
    warningCount++;
  }

  @Override
  public void receive(ReadableAtFloorPayload msg) {}

  @Override
  public void receive(ReadableCarCallPayload msg) {}

  @Override
  public void receive(ReadableCarLanternPayload msg) {}

  @Override
  public void receive(ReadableCarLevelPositionPayload msg) {}

  @Override
  public void receive(ReadableCarLightPayload msg) {}

  @Override
  public void receive(ReadableCarPositionIndicatorPayload msg) {}

  @Override
  public void receive(ReadableDoorClosedPayload msg) {}

  @Override
  public void receive(ReadableDoorMotorPayload msg) {}

  @Override
  public void receive(ReadableDoorOpenPayload msg) {}

  @Override
  public void receive(ReadableCarWeightPayload msg) {}

  @Override
  public void receive(ReadableCarWeightAlarmPayload msg) {}

  @Override
  public void receive(ReadableDoorReversalPayload msg) {}

  @Override
  public void receive(ReadableDrivePayload msg) {}

  @Override
  public void receive(ReadableDriveSpeedPayload msg) {}

  @Override
  public void receive(ReadableEmergencyBrakePayload msg) {}

  @Override
  public void receive(ReadableHallCallPayload msg) {}

  @Override
  public void receive(ReadableHallLightPayload msg) {}

  /**
   * Use reflection to create and return a monitor class of the specified name. Note that the
   * monitor must have a default (no arguments) constructor.
   *
   * @param monitorName
   * @return
   */
  public static final RuntimeMonitor createMonitor(String monitorName) {
    ReflectionFactory rf = new ReflectionFactory();

    List<String> packagePath = new ArrayList<String>();
    packagePath.add("simulator.elevatorcontrol.");
    packagePath.add("simulator.elevatormodules.");

    RuntimeMonitor monitor = null;
    try {
      monitor = (RuntimeMonitor) rf.createObject(monitorName, packagePath);
    } catch (Exception ex) {
      throw new RuntimeException("Exception while creating runtime monitor: " + ex, ex);
    }
    return monitor;
  }
}
示例#8
0
 /**
  * Use this method to print informational messages to the output
  *
  * @param message Message to be printed.
  */
 protected final void message(String message) {
   Harness.log(name, message);
 }