timer and timeStamp added to misc. copyright and license info added

This commit is contained in:
Marty Kraimer
2010-11-23 07:30:13 -05:00
parent 28aad96b34
commit 9db054cc54
100 changed files with 1376 additions and 7236 deletions

View File

@@ -2,6 +2,10 @@ TOP=../..
include $(TOP)/configure/CONFIG
PROD_HOST += testTimeStamp
testTimeStamp_SRCS += testTimeStamp.cpp
testTimeStamp_LIBS += pvMisc Com
PROD_HOST += testLinkedList
testLinkedList_SRCS += testLinkedList.cpp
testLinkedList_LIBS += pvMisc Com
@@ -10,6 +14,10 @@ PROD_HOST += testThread
testThread_SRCS += testThread.cpp
testThread_LIBS += pvMisc Com
PROD_HOST += testTimer
testTimer_SRCS += testTimer.cpp
testTimer_LIBS += pvMisc Com
PROD_HOST += testBitSet
testBitSet_SRCS += testBitSet.cpp
testBitSet_LIBS += pvMisc Com

View File

@@ -1,4 +1,9 @@
/* testBaseException.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/* Author: Matej Sekoranja Date: 2010.10.18 */
#include <stddef.h>

View File

@@ -1,4 +1,9 @@
/* testBitSet.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/* Author: Matej Sekoranja Date: 2010.10.18 */
#include <stddef.h>

View File

@@ -1,3 +1,8 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/*
* testByteBuffer.cpp
*

View File

@@ -1,3 +1,8 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/*
* testLinkedList.cpp
*
@@ -270,8 +275,8 @@ static void testOrderedQueue(FILE * fd ) {
}
static void testTime(FILE *auxFd) {
TimeStamp startTime(0,0);
TimeStamp endTime(0,0);
TimeStamp startTime;
TimeStamp endTime;
int numNodes = 1000;
LinkedList<Basic> *basicList = new BasicList();
@@ -288,7 +293,7 @@ static void testTime(FILE *auxFd) {
while(basicNode!=0) basicNode = basicList->removeHead();
}
endTime.getCurrent();
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
double diff = TimeStamp::diff(endTime,startTime);
diff /= 1000.0;
fprintf(auxFd,"diff %f milliSeconds\n",diff);
diff = diff/1000.0; // convert from milliseconds to seconds
@@ -303,8 +308,8 @@ static void testTime(FILE *auxFd) {
}
static void testTimeLocked(FILE *auxFd) {
TimeStamp startTime(0,0);
TimeStamp endTime(0,0);
TimeStamp startTime;
TimeStamp endTime;
Mutex *mutex = new Mutex();
int numNodes = 1000;
@@ -332,7 +337,7 @@ static void testTimeLocked(FILE *auxFd) {
}
}
endTime.getCurrent();
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
double diff = TimeStamp::diff(endTime,startTime);
diff *= 1000.0;
fprintf(auxFd,"diff %f milliSeconds\n",diff);
diff = diff/1000.0; // convert from milliseconds to seconds
@@ -348,8 +353,8 @@ static void testTimeLocked(FILE *auxFd) {
typedef std::list<Basic *> stdList;
static void testArrayListTime(FILE *auxFd) {
TimeStamp startTime(0,0);
TimeStamp endTime(0,0);
TimeStamp startTime;
TimeStamp endTime;
int numNodes = 1000;
stdList basicList;
@@ -368,7 +373,7 @@ static void testArrayListTime(FILE *auxFd) {
}
}
endTime.getCurrent();
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
double diff = TimeStamp::diff(endTime,startTime);
diff *= 1000.0;
fprintf(auxFd,"diff %f milliSeconds\n",diff);
diff = diff/1000.0; // convert from milliseconds to seconds
@@ -381,8 +386,8 @@ static void testArrayListTime(FILE *auxFd) {
}
static void testArrayListTimeLocked(FILE *auxFd) {
TimeStamp startTime(0,0);
TimeStamp endTime(0,0);
TimeStamp startTime;
TimeStamp endTime;
int numNodes = 1000;
Mutex *mutex = new Mutex();
@@ -406,7 +411,7 @@ static void testArrayListTimeLocked(FILE *auxFd) {
}
}
endTime.getCurrent();
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
double diff = TimeStamp::diff(endTime,startTime);
diff *= 1000.0;
fprintf(auxFd,"diff %f milliSeconds\n",diff);
diff = diff/1000.0; // convert from milliseconds to seconds

View File

@@ -1,3 +1,8 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/*
* testSerialization.cpp
*

View File

@@ -1,3 +1,8 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/*
* testThread.cpp
*
@@ -60,7 +65,7 @@ void Basic::command()
static void testBasic(FILE *fd) {
Executor *executor = new Executor(String("basic"),middlePriority);
Executor *executor = Executor::create(String("basic"),middlePriority);
Basic *basic = new Basic(executor);
basic->run();
delete basic;
@@ -84,7 +89,7 @@ private:
};
static void testThreadContext(FILE *fd,FILE *auxFd) {
Executor *executor = new Executor(String("basic"),middlePriority);
Executor *executor = Executor::create(String("basic"),middlePriority);
Basic *basic = new Basic(executor);
MyFunc myFunc(basic);
TimeFunction timeFunction(&myFunc);

View File

@@ -0,0 +1,114 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/*
* testTimeStamp.cpp
*
* Created on: 2010.11
* Author: Marty Kraimer
*/
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstdio>
#include <list>
#include <epicsAssert.h>
#include "timeStamp.h"
using namespace epics::pvData;
void testTimeStamp(FILE *fd,FILE *auxfd)
{
assert(nanoSecPerSec==1000000000);
TimeStamp current;
current.getCurrent();
fprintf(auxfd,"current %lli %i milliSec %lli\n",
current.getSecondsPastEpoch(),
current.getNanoSeconds(),
current.getMilliseconds());
TimeStamp right;
TimeStamp left;
right.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
double diff;
diff = TimeStamp::diff(left,right);
fprintf(fd,"diff %e\n",diff);
assert(diff==0.0);
assert((left==right));
assert(!(left!=right));
assert((left<=right));
assert(!(left<right));
assert((left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch()+1,current.getNanoSeconds());
diff = TimeStamp::diff(left,right);
fprintf(fd,"diff %e\n",diff);
assert(!(left==right));
assert((left!=right));
assert(!(left<=right));
assert(!(left<right));
assert((left>=right));
assert((left>right));
left.put(current.getSecondsPastEpoch()-1,current.getNanoSeconds());
diff = TimeStamp::diff(left,right);
fprintf(fd,"diff %e\n",diff);
assert(diff==-1.0);
assert(!(left==right));
assert((left!=right));
assert((left<=right));
assert((left<right));
assert(!(left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-nanoSecPerSec);
diff = TimeStamp::diff(left,right);
fprintf(fd,"diff %e\n",diff);
assert(diff==-1.0);
assert(!(left==right));
assert((left!=right));
assert((left<=right));
assert((left<right));
assert(!(left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-1);
diff = TimeStamp::diff(left,right);
fprintf(fd,"diff %e\n",diff);
assert(diff<0.0);
assert(!(left==right));
assert((left!=right));
assert((left<=right));
assert((left<right));
assert(!(left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
left += .1;
diff = TimeStamp::diff(left,right);
fprintf(fd,"diff %e\n",diff);
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
int64 inc = -1;
left += inc;
diff = TimeStamp::diff(left,right);
assert(diff==-1.0);
}
int main(int argc, char *argv[]) {
char *fileName = 0;
if(argc>1) fileName = argv[1];
FILE * fd = stdout;
if(fileName!=0 && fileName[0]!=0) {
fd = fopen(fileName,"w+");
}
char *auxFileName = 0;
if(argc>2) auxFileName = argv[2];
FILE *auxfd = stdout;
if(auxFileName!=0 && auxFileName[0]!=0) {
auxfd = fopen(auxFileName,"w+");
}
testTimeStamp(fd,auxfd);
return (0);
}

View File

@@ -0,0 +1,117 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/*
* testTimer.cpp
*
* Created on: 2010.11
* Author: Marty Kraimer
*/
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstdio>
#include <epicsAssert.h>
#include "timeStamp.h"
#include "event.h"
#include "timer.h"
#include "thread.h"
#include "showConstructDestruct.h"
using namespace epics::pvData;
static TimeStamp currentTimeStamp;
static double oneDelay = 4.0;
static double twoDelay = 2.0;
class MyCallback : public TimerCallback {
public:
MyCallback(String name,FILE *fd,FILE *auxfd,Event *wait)
: name(name),fd(fd),auxfd(auxfd),wait(wait),
timerNode(TimerNode::create(this)),timeStamp(TimeStamp())
{
}
~MyCallback()
{
timerNode->destroy();
}
virtual void callback()
{
timeStamp.getCurrent();
wait->signal();
}
virtual void timerStopped()
{
fprintf(fd,"timerStopped %s\n",name.c_str());
}
TimerNode *getTimerNode() { return timerNode;}
TimeStamp &getTimeStamp() { return timeStamp;}
private:
String name;
FILE *fd;
FILE *auxfd;
Event *wait;
TimerNode *timerNode;
TimeStamp timeStamp;
};
static void testBasic(FILE *fd, FILE *auxfd)
{
String one("one");
String two("two");
Event *eventOne = new Event(eventEmpty);
Event *eventTwo = new Event(eventEmpty);
Timer *timer = Timer::create(String("timer"),middlePriority);
MyCallback *callbackOne = new MyCallback(
one,fd,auxfd,eventOne);
MyCallback *callbackTwo = new MyCallback(
two,fd,auxfd,eventTwo);
currentTimeStamp.getCurrent();
timer->scheduleAfterDelay(callbackOne->getTimerNode(),oneDelay);
timer->scheduleAfterDelay(callbackTwo->getTimerNode(),twoDelay);
eventOne->wait();
eventTwo->wait();
double diff;
diff = TimeStamp::diff(
callbackOne->getTimeStamp(),currentTimeStamp);
fprintf(auxfd,"one requested %f diff %f seconds\n",oneDelay,diff);
diff = TimeStamp::diff(
callbackTwo->getTimeStamp(),currentTimeStamp);
fprintf(auxfd,"two requested %f diff %f seconds\n",twoDelay,diff);
timer->destroy();
delete callbackOne;
delete callbackTwo;
delete eventOne;
delete eventTwo;
}
int main(int argc, char *argv[]) {
char *fileName = 0;
if(argc>1) fileName = argv[1];
FILE * fd = stdout;
if(fileName!=0 && fileName[0]!=0) {
fd = fopen(fileName,"w+");
}
char *auxFileName = 0;
if(argc>2) auxFileName = argv[2];
FILE *auxfd = stdout;
if(auxFileName!=0 && auxFileName[0]!=0) {
auxfd = fopen(auxFileName,"w+");
}
oneDelay = .4;
twoDelay = .2;
testBasic(fd,auxfd);
oneDelay = .2;
twoDelay = .4;
testBasic(fd,auxfd);
oneDelay = .0;
twoDelay = .0;
testBasic(fd,auxfd);
getShowConstructDestruct()->constuctDestructTotals(fd);
return (0);
}