@Test
  public void createFromQueues() {
    // Create config [[e],[]]
    DistEventType sendE = DistEventType.SendEvent("e", cid1);
    chStates.get(0).enqueue(sendE);
    mc = ImmutableMultiChState.fromChannelStates(chStates);

    // Create config [[],[]]
    mc2 = ImmutableMultiChState.fromChannelIds(cids);
    assertTrue(mc != mc2);
    assertTrue(!mc.equals(mc2));

    // Add e to [[],[]] at cid1 (index 0)
    // This should result in [[],[e]] and equal the first mc above.
    mc3 = mc2.getNextChState(sendE);
    assertTrue(mc == mc3);
    assertTrue(mc.equals(mc3));
    assertTrue(mc.hashCode() == mc3.hashCode());

    // Apply e again, resulting in: [[e,e],[]]
    mc4 = mc3.getNextChState(sendE);
    assertTrue(mc != mc4);
    assertTrue(mc2 != mc4);
    assertTrue(mc3 != mc4);

    // Consume e, resulting in: [[e],[]]
    DistEventType recvE = DistEventType.RecvEvent("e", cid1);
    mc4 = mc4.getNextChState(recvE);
    assertTrue(mc4 == mc3);

    // Execute a local etype at pid 0, which should not change the state
    DistEventType localE = DistEventType.LocalEvent("e", 1);
    mc4 = mc4.getNextChState(localE);
    assertTrue(mc4 == mc3);
  }
Ejemplo n.º 2
0
  /**
   * Augment this CFSM with an "eventually happens e" invariant for model checking. This procedure
   * is slightly different from binary invariants. In particular, we do not trace an 'initial' event
   * and instead just trace the event e.
   */
  private void augmentWithInvTracing(EventuallyHappens inv) {
    DistEventType e1 = inv.getEvent();

    assert alphabet.contains(e1);
    assert e1.getPid() < fsms.size();
    assert !invs.contains(invs);

    invs.add(inv);

    int scmId = this.channelIds.size();

    if (firstSyntheticChIndex > scmId) {
      firstSyntheticChIndex = scmId;
    }

    // Create and add a new invariant-specific channel.
    ChannelId invCid = new InvChannelId(inv, scmId);
    this.channelIds.add(invCid);

    // Update the FSM corresponding to e1.
    Set<FSMState> visited = Util.newSet();
    FSM f1 = this.fsms.get(e1.getPid());
    DistEventType e1Tracer1 = DistEventType.SynthSendEvent(e1, invCid, true);
    DistEventType e1Tracer2 = DistEventType.SynthSendEvent(e1, invCid, false);
    addSendToEventTx(f1, e1, e1Tracer1, e1Tracer2, visited);
    this.alphabet.add(e1Tracer1);
    this.alphabet.add(e1Tracer2);

    inv.setFirstSynthTracers(e1Tracer1, e1Tracer2);
    inv.setSecondSynthTracers(null, null);
  }
Ejemplo n.º 3
0
  /**
   * Adds a new FSM instance to the CFSM. Once all the FSMs have been added, the CFSM is considered
   * initialized.
   *
   * @param fsm
   */
  public void addFSM(FSM fsm) {
    assert unSpecifiedPids > 0;
    assert fsm != null;

    int pid = fsm.getPid();

    if (CSightMain.assertsOn) {
      // Must be a valid pid (in the right range).
      assert (pid >= 0 && pid < numProcesses);
      // Only allow to set the FSM for a pid once.
      assert (fsms.get(pid) == null);

      // Check that the FSM alphabet conforms to the expected number of
      // processes.
      int ppid;
      for (DistEventType e : fsm.getAlphabet()) {
        if (e.isCommEvent()) {
          ppid = e.getChannelId().getDstPid();
          assert ppid >= 0 && ppid < numProcesses;

          ppid = e.getChannelId().getSrcPid();
          assert ppid >= 0 && ppid < numProcesses;
        } else {
          ppid = e.getPid();
          assert ppid >= 0 && ppid < numProcesses;
        }
      }
    }

    fsms.set(pid, fsm);
    alphabet.addAll(fsm.getAlphabet());

    unSpecifiedPids -= 1;
  }
Ejemplo n.º 4
0
  /**
   * Recursive call to perform DFA exploration of FSM f. Helper to addSendToEventTx
   *
   * @param visited
   */
  private void recurseAddSendToEventTx(
      FSM f,
      FSMState parent,
      DistEventType eToTrace,
      DistEventType eTracer1,
      DistEventType eTracer2,
      Set<FSMState> visited) {

    if (visited.contains(parent)) {
      return;
    }

    visited.add(parent);

    // If there is a transition on to-trace event, then perform the
    // re-writing.
    if (parent.getTransitioningEvents().contains(eToTrace)) {
      for (FSMState child : parent.getNextStates(eToTrace)) {
        f.addSyntheticState(parent, child, eToTrace, eTracer1, eTracer2);

        if (!visited.contains(child)) {
          // If we haven't visited the child yet, then recurse to it.
          recurseAddSendToEventTx(f, child, eToTrace, eTracer1, eTracer2, visited);
        }
      }
    }

    for (DistEventType e : parent.getTransitioningEvents()) {
      // Now handle all the non-to-trace events. Note, however, that these
      // have been re-written above with eTracer1 events, so this is what
      // we check for.
      if (!e.equals(eTracer1)) {
        for (FSMState nextF : parent.getNextStates(e)) {
          if (visited.contains(nextF)) {
            continue;
          }

          recurseAddSendToEventTx(f, nextF, eToTrace, eTracer1, eTracer2, visited);
        }
      }
    }
  }
  @Before
  public void setUp() throws Exception {
    super.setUp();
    cids = Util.newList(2);
    // Two process system.
    cid1 = new ChannelId(0, 1, 0);
    cid2 = new ChannelId(1, 0, 1);
    cids.add(cid1);
    cids.add(cid2);

    Pmc = ImmutableMultiChState.fromChannelIds(cids);

    List<ObsFSMState> P = Util.newList();
    ObsFSMState p0 = ObsFSMState.namedObsFSMState(0, "p", false, true);
    ObsFSMState p1 = ObsFSMState.namedObsFSMState(1, "q", false, true);
    P.add(p0);
    P.add(p1);
    obsFSMState1 = ObsMultFSMState.getMultiFSMState(P);

    s1 = ObsFifoSysState.getFifoSysState(obsFSMState1, Pmc);

    List<ObsFSMState> P2 = Util.newList();
    P2.add(p0);
    ObsFSMState p2 = ObsFSMState.namedObsFSMState(1, "r", false, true);
    P2.add(p2);
    obsFSMState2 = ObsMultFSMState.getMultiFSMState(P2);

    // Get a third instance that is different from the first two.
    s2 = ObsFifoSysState.getFifoSysState(obsFSMState2, Pmc);

    e1 = DistEventType.LocalEvent("e", 0);
    ObsDistEventType obsE = new ObsDistEventType(e1, 0);
    s1.addTransition(obsE, s2);

    g1 = fromOneObs(2, s1);
    g2 = fromOneObs(2, s2);
  }
Ejemplo n.º 6
0
  /**
   * Generates a Promela representation of this CFSM, to be used with SPIN. The never claim is not
   * specified here and it is appended to the CFSM elsewhere.
   */
  public String toPromelaString(List<BinaryInvariant> invariants, int chanCapacity) {
    assert unSpecifiedPids == 0;

    String ret = "/* Spin-promela Multiple invariants */\n\n";

    // Message types:
    //
    // mtype is global and can only be declared once.
    // There is also limit of 255 for the size of mtype.

    // This outputs a set of event types for the CFSM.
    ret += "/* Message types: */\n";
    ret += "mtype = { ";

    Set<String> eventTypes = Util.newSet();
    for (DistEventType e : alphabet) {
      eventTypes.add(e.getPromelaEType());
    }

    ret += StringUtils.join(eventTypes, ", ");

    ret += " };\n"; // End mtype declaration.
    ret += "\n\n";

    // Define the channels:
    ret += "/* Channels: */\n\n";

    // Specifying channels as an array to work with inlines.
    ret +=
        String.format("chan channel[%d] = [%d] of { mtype };\n", channelIds.size(), chanCapacity);

    // The following block defines EMPTYCHANNELCHECK as a conditional that
    // checks if all the channels are empty. This is used in the never claim
    // to make sure our channels are empty before terminating.
    String emptyChannelCheck = "";
    for (int i = 0; i < channelIds.size(); i++) {
      ret += "/* Channel " + channelIds.get(i).toString() + " */\n";
      if (i != 0) {
        emptyChannelCheck += " && ";
      }
      emptyChannelCheck += "empty(channel[" + i + "])";
    }
    ret += String.format("#define EMPTYCHANNELCHECK (%s)\n", emptyChannelCheck);
    ret += "\n\n";

    // Tracks if the current states of each of the FSM are terminal.
    ret += "bit terminal[" + numProcesses + "];\n";

    // ENDSTATECHECK is the conditional used by the never claim to
    // check the terminal states in all CFSMs. The never claim has this to
    // ensure that the processes are in a proper terminal state when the
    // never claim is done.

    String endStateCheck = "";
    for (int pid = 0; pid < numProcesses; pid++) {
      // Set up the terminal check conditional.
      if (pid != 0) {
        endStateCheck += " && ";
      }
      endStateCheck += "terminal[" + pid + "]";
    }

    ret += String.format("#define ENDSTATECHECK (%s)\n", endStateCheck);

    // Event type definitions for type tracking

    // OTHEREVENTs are used for other transitions so we do not accidentally
    // trigger an "a NFby b". This can happen when a == b. This invariant
    // can be accepted if a transition happens that does not call
    // setRecentEvent. OTHEREVENT does not match any event we are interested
    // in tracking so it is safe to use during these transitions.

    ret += "#define OTHEREVENT (0)\n";
    // Event types we're actively tracking.
    ret += "#define LOCAL (1)\n";
    ret += "#define SEND (2)\n";
    ret += "#define RECV (3)\n";

    // Custom datatype to assist in tracking recent event.
    ret += "typedef myEvent {\n";
    // The type of event: LOCAL, SEND or RECV
    ret += "    byte type;\n";
    // id is the process id if the type is LOCAL and the channel id if the
    // type is SEND or RECV.
    ret += "    byte id;\n";
    // The event itself. These are the previously defined mtypes.
    ret += "    mtype event;\n";
    ret += "};\n";

    // Declaration of event tracker.
    ret += "myEvent recentEvent;\n";

    // Custom inline function to update most recent event.
    ret += "inline setRecentEvent(event_type, owner_id, event_message) {\n";
    ret += "  d_step{\n";
    ret += "    recentEvent.type = event_type;\n";
    ret += "    recentEvent.id = owner_id;\n";
    ret += "    recentEvent.event = event_message;\n";
    ret += "  };\n";
    ret += "}\n";

    // Each of the FSMs in the CFSM:
    for (int pid = 0; pid < numProcesses; pid++) {
      String labelPrefix = "state" + Integer.toString(pid);
      FSM f = fsms.get(pid);
      ret += "active proctype p" + Integer.toString(pid) + "(){\n";
      ret += f.toPromelaString(invariants, labelPrefix);
      ret += "}\n\n";
    }

    ret += "\n\n";

    for (BinaryInvariant inv : invariants) {
      ret += "/* " + inv.toString() + "*/\n";
      ret += inv.promelaNeverClaim();
      ret += "\n\n";
    }
    return ret;
  }