[Tinyos-2-commits] CVS: tinyos-2.x-contrib/tunit/tests/tinyos-2.x/tos/chips/cc2420/TestLplDefaultPeriodicDelivery Makefile, NONE, 1.1 TestRadioC.nc, NONE, 1.1 TestRadioP.nc, NONE, 1.1 suite.properties, NONE, 1.1

David Moss mossmoss at users.sourceforge.net
Sat Jul 21 22:31:52 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x-contrib/tunit/tests/tinyos-2.x/tos/chips/cc2420/TestLplDefaultPeriodicDelivery
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv19699/TestLplDefaultPeriodicDelivery

Added Files:
	Makefile TestRadioC.nc TestRadioP.nc suite.properties 
Log Message:
Moved from a flat directory structure to a project-oriented directory structure

--- NEW FILE: Makefile ---
COMPONENT=TestRadioC
CFLAGS += -DLOW_POWER_LISTENING
CFLAGS += -DMAX_TUNIT_QUEUE=25
include $(MAKERULES)


--- NEW FILE: TestRadioC.nc ---

#include "TestCase.h"

/**
 * @author David Moss
 */
configuration TestRadioC {
}

implementation {
  components
      new TestCaseC() as TestPeriodicDeliveryC,
      new StatisticsC() as AveragePktStatsC,
      new StatisticsC() as DetectRateStatsC;
      
  components TestRadioP,
      ActiveMessageC,
      CC2420ActiveMessageC,
      CC2420CsmaC,
      ActiveMessageAddressC,
      new AMSenderC(4),
      new AMReceiverC(4),
      new TimerMilliC(),
      new TimerMilliC() as WaitTimerC,
      new StateC(),
      LedsC;

  TestRadioP.SetUpOneTime -> TestPeriodicDeliveryC.SetUpOneTime;
  TestRadioP.TestPeriodicDelivery -> TestPeriodicDeliveryC;
  TestRadioP.TearDownOneTime -> TestPeriodicDeliveryC.TearDownOneTime;
  TestRadioP.AveragePktStats -> AveragePktStatsC;
  TestRadioP.DetectRateStats -> DetectRateStatsC;
  
  TestRadioP.LowPowerListening -> CC2420ActiveMessageC;
  TestRadioP.RadioPowerControl -> CC2420CsmaC.SplitControl;
  TestRadioP.ActiveMessageAddress -> ActiveMessageAddressC;
  TestRadioP.SplitControl -> ActiveMessageC;
  TestRadioP.PacketAcknowledgements -> ActiveMessageC;
  TestRadioP.AMSend -> AMSenderC;
  TestRadioP.AMPacket -> ActiveMessageC;
  TestRadioP.Receive -> AMReceiverC;
  TestRadioP.Timer -> TimerMilliC;
  TestRadioP.WaitTimer -> WaitTimerC;
  TestRadioP.State -> StateC;
  TestRadioP.Leds -> LedsC;

}

--- NEW FILE: TestRadioP.nc ---

#include "TestCase.h"

/**
 * @author David Moss
 */
module TestRadioP {
  uses {
    interface TestControl as SetUpOneTime;
    interface TestControl as TearDownOneTime;
    interface Statistics as AveragePktStats;
    interface Statistics as DetectRateStats;
    
    interface TestCase as TestPeriodicDelivery;
    interface LowPowerListening;
    interface SplitControl;
    interface PacketAcknowledgements;
    interface ActiveMessageAddress;
    interface AMSend;
    interface AMPacket;
    interface Receive;
    interface Timer<TMilli>;
    interface Timer<TMilli> as WaitTimer;
    interface SplitControl as RadioPowerControl;
    interface State;
    interface Leds;
  }
}

implementation {

  enum {
    MAX_NODES = 20,
    RUN_TIME = 92160, // 1.5 minutes
    SLEEP_INTERVAL = 512,
  };
  
  
  /** The message transmitter nodes send */
  message_t myMsg;
  
  /** True if this is the transmitter, any node above the driving node */
  bool transmitter;
  
  /** A count of how many times each other node has gotten a message through */
  uint32_t received[MAX_NODES];
  
  /** Total number of other nodes in the area we've seen */
  uint8_t totalSources;
  
  /** Total number of times the radio was physically flipped on */
  uint16_t attempts;
  
  /** Total number of times a packet was detected/received after turning on */
  uint16_t detects;
  
  /** True if the radio physically just turned on and we're waiting for rx */
  bool attempting;
  
  enum {
    S_IDLE,
    S_SETUPONETIME,
    S_RUNNING,
  };

  

  /***************** Prototypes ****************/
  task void send();
  
  /***************** TestControl Events ****************/
  event void SetUpOneTime.run() {
    totalSources = 0;

    transmitter = (call ActiveMessageAddress.amAddress() > 0);
    call LowPowerListening.setRxSleepInterval(&myMsg, SLEEP_INTERVAL);
    call State.forceState(S_SETUPONETIME);
    call LowPowerListening.setLocalSleepInterval(SLEEP_INTERVAL);
    call SplitControl.start();
  }
  
  event void TearDownOneTime.run() {
    call State.toIdle();
    call AMSend.cancel(&myMsg);
    call SplitControl.stop();
  }
  
  /***************** SplitControl Events ****************/
  event void SplitControl.startDone(error_t error) {
    if(transmitter) { 
      call Leds.led1On();
      call State.forceState(S_RUNNING);
      post send();
    }
    call SetUpOneTime.done();
  }
  
  event void SplitControl.stopDone(error_t error) {
    call TearDownOneTime.done();
  }
  
  /***************** Tests ****************/
  event void TestPeriodicDelivery.run() {
    int i;
    for(i = 0; i < MAX_NODES; i++) {
      received[i] = 0;
    }
    attempting = FALSE;
    detects = 0;
    attempts = 0;
    call State.forceState(S_RUNNING);
    call Timer.startOneShot(RUN_TIME);
  }
    
  /***************** AMSend Events ****************/
  event void AMSend.sendDone(message_t *msg, error_t error) {
    call Leds.led2Off();
    if(call State.isState(S_RUNNING)) {
      // Send another
      call WaitTimer.startOneShot(256);
    }
  }
  
  /***************** RadioPowerControl Events *****************/
  event void RadioPowerControl.startDone(error_t error) {
    if(call State.isState(S_RUNNING)) {
      attempting = TRUE;
      attempts++;
    }
  }
  
  event void RadioPowerControl.stopDone(error_t error) {
  }
  
  /***************** Receive Events ****************/
  event message_t *Receive.receive(message_t *msg, void *payload, uint8_t len) {
    int sourceAddr = call AMPacket.source(msg);
    call Leds.led0Toggle();
    if(call State.isState(S_RUNNING)) {
      if(attempting) {
        // First packet received after the radio turned on.
        attempting = FALSE;
        detects++;
      }
    
      if(received[sourceAddr-1] == 0) {
        totalSources++;
      }
    
      received[sourceAddr-1]++;
    }
    return msg;
  }
  
  /***************** Timer Events ****************/
  event void Timer.fired() {
    float average = 0;
    int i;
    bool pass;
    call State.toIdle();
    
    assertResultIsAbove("No sources detected", 0, totalSources);
    assertResultIsAbove("Unreliable detections", (float) attempts - ((float) 0.05 * (float) attempts), (float) detects);

    for(i = 0; i < totalSources; i++) {
      average += (float) received[i];
    }
    average /= (float) totalSources;
    
    for(i = 0; i < totalSources; i++) {
      pass = TRUE;
      if(average + ((float) 0.1 * average) < received[i]) {
        pass = FALSE;
        assertResultIsBelow("Source is 10% over avg", average + ((float) 0.1 * average), received[i]);
        assertEquals("Previous source was ...", 0, i+1);
      }
      
      if(average - ((float) 0.1 * average) > received[i]) {
        pass = FALSE;
        assertResultIsAbove("Source is 10% below avg", average - ((float) 0.1 * average), received[i]);
        assertEquals("Previous source was ...", 0, i+1);
      }
      
      if(pass) {
        assertSuccess();
      }
    }
    
    call AveragePktStats.log("[Avg # Pkt Rx]", average);
    call TestPeriodicDelivery.done();
  }
  
  event void WaitTimer.fired() {
    post send();
  }
  
  
  /***************** Other Events ****************/
  event void AveragePktStats.logDone() {
    call DetectRateStats.log("[Detects/Attempts %]", (float) (((float) (detects * 100)) / (float) attempts));
  }
  
  event void DetectRateStats.logDone() {
  }
  
  async event void ActiveMessageAddress.changed() {
  }
  
  /***************** Tasks ****************/
  task void send() {
    call Leds.led2On();
    if(call AMSend.send(0, &myMsg, TOSH_DATA_LENGTH) != SUCCESS) {
      post send();
    }
  }
  
}

--- NEW FILE: suite.properties ---
/**
 * Valid keywords are:
 *  @author <optional author(s)>  (multiple)
 *  @testname <optional testname>  (once)
 *  @description <optional, multiline description>  (once)
 *  @extra <any build/install extras> (multiple)
 *  @ignore <single target>  (multiple)
 *  @only <single target> (multiple)
 *  @minnodes <# nodes>  (once)
 *  @maxnodes <# nodes>  (once)
 *  @exactnodes <# of exact nodes>  (once)
 *  @mintargets <# of minimum targets for heterogeneous network testing>  (once)
 *  @timeout <timeout duration of the test in minutes, default is 1 min.>
 *  @skip  (once)
 */

@testname Test Periodic LPL Deliveries
@author David Moss
@description Each node sends a unicast and waits.  The receiver (0) collects.
    As each transmitter sends, the receiver keeps track of how many transmitters
    there are out there.  Then we average up the number of received messages
    across all transmitters after a minute.  We should theoretically see the
    channel being shared fairly.  The test fails if any transmitter gets more
    or less than 10% of the average packets through.  Also, we analyze whether
    or not our detection strategy is effective.  Each attempt should result in
    a detect for the most part.
@maxnodes 19
@minnodes 2
@timeout 2
@ignore mica2
@ignore mica2dot



More information about the Tinyos-2-commits mailing list