[Tinyos-2-commits]
CVS: tinyos-2.x-contrib/tunit/tests/tinyos-2.x/tos/lib/tunit/TestStatistics
Makefile, NONE, 1.1 SerialActiveMessageC.nc, NONE,
1.1 TestStatsC.nc, NONE, 1.1 TestStatsP.nc, NONE,
1.1 suite.properties, NONE, 1.1
David Moss
mossmoss at users.sourceforge.net
Thu Oct 25 11:06:47 PDT 2007
Update of /cvsroot/tinyos/tinyos-2.x-contrib/tunit/tests/tinyos-2.x/tos/lib/tunit/TestStatistics
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv22584
Added Files:
Makefile SerialActiveMessageC.nc TestStatsC.nc TestStatsP.nc
suite.properties
Log Message:
Creation
--- NEW FILE: Makefile ---
COMPONENT=TestStatsC
include $(MAKERULES)
--- NEW FILE: SerialActiveMessageC.nc ---
//$Id: SerialActiveMessageC.nc,v 1.1 2007/10/25 18:06:45 mossmoss Exp $
/* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
* Sending active messages over the serial port.
*
* @author Philip Levis
* @author Ben Greenstein
* @date August 7 2005
*
*/
#include "Serial.h"
configuration SerialActiveMessageC {
provides {
interface SplitControl;
interface AMSend[am_id_t id];
interface Receive[am_id_t id];
interface Packet;
interface AMPacket;
interface PacketAcknowledgements;
}
uses interface Leds;
}
implementation {
components new SerialActiveMessageP() as AM, SerialDispatcherC;
components SerialPacketInfoActiveMessageP as Info, MainC;
MainC.SoftwareInit -> SerialDispatcherC;
Leds = SerialDispatcherC;
SplitControl = SerialDispatcherC;
Receive = AM;
Packet = AM;
AMPacket = AM;
PacketAcknowledgements = AM;
/** TEST SPECIFIC MODS */
components TestStatsP;
AMSend = TestStatsP.SerialAMSend;
TestStatsP.SerialAMSubSend -> AM;
/** END OF TEST SPECIFIC MODS */
AM.SubSend -> SerialDispatcherC.Send[TOS_SERIAL_ACTIVE_MESSAGE_ID];
AM.SubReceive -> SerialDispatcherC.Receive[TOS_SERIAL_ACTIVE_MESSAGE_ID];
SerialDispatcherC.SerialPacketInfo[TOS_SERIAL_ACTIVE_MESSAGE_ID] -> Info;
}
--- NEW FILE: TestStatsC.nc ---
/**
* This test makes sure Statistics works, and demonstrates how to properly
* setup Statistics logging for your own tests.
*
* A statistics messages only has so many bytes in it, so the title of the
* statistics being logged is whatever you rename your StatisticsC instances
* as, and the units are defined within the test. This allows TUnit to
* keep track of individual characteristics over time.
*
* @author David Moss
*/
configuration TestStatsC {
}
implementation {
components TestStatsP,
new TestCaseC() as LogStatsC,
new TestCaseC() as MakeSureAllStatsWereLoggedC,
new StatisticsC() as Stats1C,
new StatisticsC() as Stats2C,
new StatisticsC() as Stats3C,
new StatisticsC() as Stats4C,
new StatisticsC() as Stats5C,
new StatisticsC() as Stats6C,
new StatisticsC() as Stats7C;
TestStatsP.LogStats -> LogStatsC;
TestStatsP.MakeSureAllStatsWereLogged -> MakeSureAllStatsWereLoggedC;
// Pick a TestCaseC instance at random and wire SetUpOneTime to it.
TestStatsP.SetUpOneTime -> LogStatsC.SetUpOneTime;
TestStatsP.Stats1 -> Stats1C;
TestStatsP.Stats2 -> Stats2C;
TestStatsP.Stats3 -> Stats3C;
TestStatsP.Stats4 -> Stats4C;
TestStatsP.Stats5 -> Stats5C;
TestStatsP.Stats6 -> Stats6C;
TestStatsP.Stats7 -> Stats7C;
components RandomC;
TestStatsP.Random -> RandomC;
components new TimerMilliC();
TestStatsP.Timer -> TimerMilliC;
}
--- NEW FILE: TestStatsP.nc ---
/**
* @author David Moss
*/
#include "TestCase.h"
#include "Statistics.h"
module TestStatsP {
provides {
interface AMSend as SerialAMSend[am_id_t amId];
}
uses {
interface TestControl as SetUpOneTime;
interface TestCase as LogStats;
interface TestCase as MakeSureAllStatsWereLogged;
interface Statistics as Stats1;
interface Statistics as Stats2;
interface Statistics as Stats3;
interface Statistics as Stats4;
interface Statistics as Stats5;
interface Statistics as Stats6;
interface Statistics as Stats7;
interface Random;
interface Timer<TMilli>;
interface AMSend as SerialAMSubSend[am_id_t amId];
}
}
implementation {
uint8_t stats1;
uint16_t stats2;
uint32_t stats3;
int8_t stats4;
int16_t stats5;
int32_t stats6;
uint8_t stats7;
uint8_t stats1Logged;
uint8_t stats2Logged;
uint8_t stats3Logged;
uint8_t stats4Logged;
uint8_t stats5Logged;
uint8_t stats6Logged;
uint8_t stats7Logged;
/**
* Runs once before the first test can begin.
*/
event void SetUpOneTime.run() {
stats1 = 255;
stats2 = call Random.rand16();
stats3 = 0x7FFFFFFF; // Maximum positive value we can log
stats4 = -5;
stats5 = -2048;
stats6 = 0x80000000; // Maximum negative value we can log
stats7 = 200;
stats1Logged = 0;
stats2Logged = 0;
stats3Logged = 0;
stats4Logged = 0;
stats5Logged = 0;
stats6Logged = 0;
stats7Logged = 0;
// BE SURE TO CALL BACK AND NOTIFY SetUpOneTime IS DONE!
call Timer.startOneShot(2048);
}
event void Timer.fired() {
call SetUpOneTime.done();
}
/**
* Log each statistic in a single-phase manner (even though stats are
* really split-phase, tunit takes care of that automatically).
*
* All stats logged in this manner should be done logging
* automatically before the next test is allowed to run.
*/
event void LogStats.run() {
assertSuccess();
call Stats1.log("255", stats1);
call Stats2.log("Random-16", stats2);
call Stats3.log("int32=uint32(0x7FFFFFFF)", stats3);
call Stats4.log("-5", stats4);
call Stats5.log("-2048", stats5);
call Stats6.log("int32=int32(0x80000000)", stats6);
call Stats7.log("200", stats7);
call LogStats.done();
}
event void MakeSureAllStatsWereLogged.run() {
assertEquals("Stats1 logs", 1, stats1Logged);
assertEquals("Stats2 logs", 1, stats2Logged);
assertEquals("Stats3 logs", 1, stats3Logged);
assertEquals("Stats4 logs", 1, stats4Logged);
assertEquals("Stats5 logs", 1, stats5Logged);
assertEquals("Stats6 logs", 1, stats6Logged);
assertEquals("Stats7 logs", 1, stats7Logged);
call MakeSureAllStatsWereLogged.done();
}
/***************** SerialAMSend Commands ****************/
command error_t SerialAMSend.send[am_id_t id](am_addr_t dest,
message_t* msg,
uint8_t len) {
StatisticsMsg *outboundStats;
if(id == AM_STATISTICSMSG) {
// Intercepted an outbound statistics message
outboundStats = (StatisticsMsg *) call SerialAMSubSend.getPayload[id](msg, TOSH_DATA_LENGTH);
switch(outboundStats->statsId) {
case 0:
stats1Logged++;
break;
case 1:
stats2Logged++;
break;
case 2:
stats3Logged++;
break;
case 3:
stats4Logged++;
break;
case 4:
stats5Logged++;
break;
case 5:
stats6Logged++;
break;
case 6:
stats7Logged++;
break;
default:
assertResultIsBelow("OOB Stats Index", 7, outboundStats->statsId);
break;
}
}
return call SerialAMSubSend.send[id](dest, msg, len);
}
command error_t SerialAMSend.cancel[am_id_t id](message_t* msg) {
return call SerialAMSubSend.cancel[id](msg);
}
command uint8_t SerialAMSend.maxPayloadLength[am_id_t id]() {
return call SerialAMSubSend.maxPayloadLength[id]();
}
command void* SerialAMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
return call SerialAMSubSend.getPayload[id](m, len);
}
/***************** SerialAMSubSend Events ****************/
event void SerialAMSubSend.sendDone[am_id_t id](message_t* msg, error_t result) {
signal SerialAMSend.sendDone[id](msg, result);
}
}
--- 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)
*/
@description Show users how to properly log statistics to characterize
some value over time.
@exactnodes 1
@assertions 10
More information about the Tinyos-2-commits
mailing list