|
reSIProcate/stack
9694
|
#include <iostream>#include <unistd.h>#include <limits.h>#include <signal.h>#include <sys/fcntl.h>#include "rutil/Logger.hxx"#include "resip/stack/HeaderTypes.hxx"#include "resip/stack/ParameterTypeEnums.hxx"#include "resip/stack/ParameterTypes.hxx"#include "resip/stack/MethodTypes.hxx"
Go to the source code of this file.
Defines | |
| #define | RESIPROCATE_SUBSYSTEM resip::Subsystem::TEST |
Functions | |
| void | tick (int sig) |
| unsigned int | InitHeaderInfo () |
| bool | checkMethods () |
| bool | checkParameters () |
| unsigned short | randomUShort () |
| int | main () |
Variables | |
| volatile bool | signalled = false |
| struct { | |
| char * keyword | |
| Headers::Type type | |
| int len | |
| } | headerInfo [(int)(Headers::MAX_HEADERS)] |
Definition at line 18 of file testHash.cxx.
| bool checkMethods | ( | ) |
Definition at line 61 of file testHash.cxx.
References resip::Data::data(), DebugLog, and resip::Data::size().
Referenced by main().
{
int i = static_cast<int>(resip::UNKNOWN)+1;
int max = static_cast<int>(resip::MAX_METHODS);
bool failure = false;
for( ; i < max ; ++i)
{
MethodTypes t = static_cast<MethodTypes>(i);
const Data& d(resip::getMethodName(t));
MethodTypes nt = resip::getMethodType(d.data(),d.size());
bool ok = nt == t;
// DebugLog(<<resip::MethodNames[t]<<" : " << (ok ? "OK":"FAIL"));
DebugLog(<< (ok ? " " : "***" ) << ' '
<< t << ' ' << resip::getMethodName(t)
<< '(' << d << ')'
<< " -> "
<< nt << ' ' << resip::getMethodName(nt));
// if (!ok) ErrLog(<<resip::getMethodName(t) << " : HASH FAILURE");
failure |= !ok;
}
return !failure;
}

| bool checkParameters | ( | ) |
Definition at line 85 of file testHash.cxx.
References resip::Data::data(), DebugLog, resip::ParameterTypes::getType(), resip::ParameterTypes::MAX_PARAMETER, resip::ParameterTypes::ParameterNames, resip::Data::size(), and resip::ParameterTypes::UNKNOWN.
Referenced by main().
{
int i = static_cast<int>(ParameterTypes::UNKNOWN)+1;
int max = static_cast<int>(ParameterTypes::MAX_PARAMETER);
bool failure = false;
for( ; i < max ; ++i)
{
ParameterTypes::Type t = static_cast<ParameterTypes::Type>(i);
Data& d = ParameterTypes::ParameterNames[t];
bool ok = ParameterTypes::getType(d.data(),d.size()) == t;
DebugLog(<<ParameterTypes::ParameterNames[t]<<" : " << (ok?"OK":"FAIL"));
failure |= !ok;
}
return !failure;
}

| unsigned int InitHeaderInfo | ( | ) |
Definition at line 36 of file testHash.cxx.
References DebugLog, resip::Headers::getHeaderName(), headerInfo, keyword, resip::Headers::MAX_HEADERS, resip::Data::size(), type, and resip::Headers::UNKNOWN.
Referenced by main().
{
int i = static_cast<int>(Headers::UNKNOWN)+1;
int max = static_cast<int>(Headers::MAX_HEADERS);
for( ;
i < max;
++i)
{
Headers::Type t = static_cast<Headers::Type>(i);
char* p = strdup(resip::Headers::getHeaderName(i).c_str());
headerInfo[i].len = Headers::getHeaderName(i).size();
headerInfo[i].keyword = p;
headerInfo[i].type = t;
DebugLog(<< headerInfo[i].keyword << " ["
<< headerInfo[i].type <<"]");
}
return i;
}

| int main | ( | void | ) |
Definition at line 131 of file testHash.cxx.
References checkMethods(), checkParameters(), CritLog, ErrLog, resip::Headers::getHeaderName(), resip::Headers::getType(), headerInfo, InfoLog, InitHeaderInfo(), keyword, len, randomUShort(), signalled, tick(), and type.
{
bool failure = false;
register unsigned int i = 0;
// Load up the main table
unsigned short nKeywords = InitHeaderInfo();
// Verify that the hash function works.
InfoLog(<<"Checking that hash function works for all known headers");
for(i=0;i<nKeywords;i++)
{
Headers::Type t = Headers::getType(headerInfo[i].keyword,
headerInfo[i].len);
bool ok = headerInfo[i].type == t;
InfoLog(<< headerInfo[i].keyword << " " << (ok?"OK":"FAIL"));
if (!ok)
{
ErrLog(<<headerInfo[i].keyword << "["
<<headerInfo[i].type << "] hashed to "
<< t << " ["
<< Headers::getHeaderName(i) << "]");
}
}
InfoLog(<<"Checking methods.");
bool p = checkMethods();
InfoLog(<<" methods: " << (p?"OK":"FAIL"));
p = checkParameters();
InfoLog(<<" parameters: " << (p?"OK":"FAIL"));
#if defined (TIME_HASH_TEST)
int randomList[100*1024];
// Make a large random list so we don't take a hit with
// random() calcs during the hash.
unsigned int nRandom = sizeof(randomList)/sizeof(*randomList);
InfoLog(<< "Pre-loading random list of " << nRandom << " entries");
for(i = 0; i < nRandom ; i++)
{
short r = randomUShort()%nKeywords;
randomList[i] = r;
}
i=0;
InfoLog(<<"Starting timing loop");
register int totalTime=30;
register int interval=5;
register int timer=totalTime;
register int elapsed=0;
signal(SIGALRM, tick);
register unsigned long long counter = 0;
assert(totalTime/interval*interval == totalTime);
while (timer>0)
{
alarm(interval);
while (!signalled)
{
volatile register Headers::Type hdr =
Headers::getType(headerInfo[randomList[i]].keyword,
headerInfo[randomList[i]].len);
counter++;
i++;
if (i >= nRandom) i = 0;
}
timer-=interval;
elapsed+=interval;
InfoLog(<< timer <<" sec rem: "
<< counter << " hashes "
<< counter/elapsed << " h/sec");
signalled=false;
}
#endif
if (failure) CritLog(<<"Problems in hashes. See above");
return failure?1:0;
}

| unsigned short randomUShort | ( | ) |
Definition at line 102 of file testHash.cxx.
Referenced by main().
{
static int fd = 0;
static bool init = false;
if (!init)
{
fd = open("/dev/urandom",O_RDONLY);
if (fd < 0)
{
cerr << "randomShort(): unable to open /dev/urandom -- degraded mode"
<< endl;
}
init = true;
}
if (init && fd >= 0)
{
unsigned short r;
int n = 0;
if ((n=read(fd,&r,sizeof(r))) == sizeof(r))
{
return r;
}
}
// degraded mode
return (unsigned short)((USHRT_MAX + 1.0) * rand() / (RAND_MAX+1.0));
}
| void tick | ( | int | sig | ) |
Definition at line 22 of file testHash.cxx.
References signalled.
Referenced by main().
{
signalled = true;
}
struct { ... } MAX_HEADERS)] [static] |
Referenced by InitHeaderInfo(), and main().
| char* keyword |
Definition at line 30 of file testHash.cxx.
Referenced by InitHeaderInfo(), and main().
| int len |
Definition at line 32 of file testHash.cxx.
| volatile bool signalled = false |
Definition at line 20 of file testHash.cxx.
Definition at line 31 of file testHash.cxx.
Referenced by resip::GenericUri::createParam(), resip::Auth::createParam(), resip::UInt32Category::createParam(), resip::ExpiresCategory::createParam(), resip::CallID::createParam(), resip::Via::createParam(), resip::Token::createParam(), resip::NameAddr::createParam(), resip::Uri::createParam(), resip::ParserCategory::encodeParameters(), resip::SipMessage::encodeSingleHeader(), resip::SipMessage::ensureHeader(), resip::SipMessage::ensureHeaders(), findRlmi(), resip::SipMessage::getContents(), resip::ParserCategory::getParameterByEnum(), resip::ExternalBodyContents::getStaticType(), resip::MultipartAlternativeContents::getStaticType(), resip::MultipartRelatedContents::getStaticType(), resip::InvalidContents::getStaticType(), resip::Rlmi::getStaticType(), resip::PlainContents::getStaticType(), resip::X509Contents::getStaticType(), resip::Pkcs8Contents::getStaticType(), resip::Pkcs7Contents::getStaticType(), resip::CpimContents::getStaticType(), resip::MultipartSignedContents::getStaticType(), resip::OctetContents::getStaticType(), resip::ApplicationSip::getStaticType(), resip::MultipartMixedContents::getStaticType(), resip::SipFrag::getStaticType(), resip::MessageWaitingContents::getStaticType(), resip::Pidf::getStaticType(), resip::Pkcs7SignedContents::getStaticType(), resip::SdpContents::getStaticType(), resip::TestDnsHandler::handle(), InitHeaderInfo(), leakCheck(), main(), resip::SipMessage::makeParserContainer(), resip::Tuple::makeTupleFromBinaryToken(), resip::Auth::parseAuthParameters(), resip::ParserCategory::parseParameters(), resip::Contents::preParseHeaders(), resip::SipMessage::remove(), resip::ParserCategory::removeParameterByEnum(), and resip::Tuple::setType().
1.7.5.1