25 #include "ns3/type-id.h"
34 const std::string
suite(
"type-id: ");
46 virtual void DoRun (
void);
47 enum { HashChainFlag = 0x80000000};
50 UniqueTypeIdTestCase::UniqueTypeIdTestCase ()
51 :
TestCase (
"Check uniqueness of all TypeIds")
62 cout <<
suite << endl;
70 cout <<
suite <<
"UniqueTypeIdTestCase: nids: " << nids << endl;
71 cout <<
suite <<
"TypeId list:" << endl;
72 cout <<
suite <<
"TypeId Chain hash Name" << endl;
74 for (uint32_t i = 0; i < nids; ++i)
77 cout <<
suite <<
"" << std::setw(6) << tid.
GetUid ();
86 cout <<
" 0x" << std::setfill (
'0') << std::hex << std::setw (8)
87 << tid.
GetHash () << std::dec << std::setfill (
' ')
93 "LookupByName returned different TypeId for "
99 "TypeId .hash and Hash32 (.name) unequal for "
104 "LookupByHash returned different TypeId for "
109 cout <<
suite <<
"<-- end TypeId list -->" << endl;
123 virtual void DoRun (
void);
128 :
TestCase (
"Check behavour when type names collide")
139 cout <<
suite << endl;
144 string t1Name =
"daemon";
145 string t2Name =
"unerring";
146 cout <<
suite <<
"creating colliding types "
147 <<
"'" << t1Name <<
"', '" << t2Name <<
"'"
148 <<
" in alphabetical order:"
150 TypeId t1 (t1Name.c_str ());
151 TypeId t2 (t2Name.c_str ());
155 "First and lesser TypeId has HashChainFlag set");
156 cout <<
suite <<
"collision: first,lesser not chained: OK" << endl;
159 "Second and greater TypeId does not have HashChainFlag set");
160 cout <<
suite <<
"collision: second,greater chained: OK" << endl;
165 string t3Name =
"trigonon";
166 string t4Name =
"seriation";
167 cout <<
suite <<
"creating colliding types "
168 <<
"'" << t3Name <<
"', '" << t4Name <<
"'"
169 <<
" in reverse alphabetical order:"
171 TypeId t3 (t3Name.c_str ());
172 TypeId t4 (t4Name.c_str ());
176 "First and greater TypeId does not have HashChainFlag set");
177 cout <<
suite <<
"collision: first,greater chained: OK" << endl;
180 "Second and lesser TypeId has HashChainFlag set");
181 cout <<
suite <<
"collision: second,lesser not chained: OK" << endl;
203 void Report (
const std::string how,
const uint32_t delta)
const ;
209 :
TestCase (
"Measure average lookup time")
220 cout <<
suite << endl;
225 int start = clock ();
228 for (uint32_t i = 0; i < nids; ++i)
235 Report (
"name", stop - start);
240 for (uint32_t i = 0; i < nids; ++i)
247 Report (
"hash", stop - start);
257 <<
", num TypeId's: " << nids
264 const uint32_t delta)
const
269 double per = 1E6 * double(delta) / (reps * double(CLOCKS_PER_SEC));
271 cout <<
suite <<
"Lookup time: by " << how <<
": "
272 <<
"ticks: " << delta
274 <<
" microsec/lookup"
313 :
TestSuite (
"type-id-perf", PERFORMANCE)
void DoRun(void)
Implementation to actually run this TestCase.
static TypeId LookupByHash(hash_t hash)
virtual void DoRun(void)
Implementation to actually run this TestCase.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not...
virtual void DoRun(void)
Implementation to actually run this TestCase.
static TypeIdPerformanceSuite g_TypeIdPerformanceSuite
static uint32_t GetRegisteredN(void)
void DoSetup(void)
Implementation to do any local setup required for this TestCase.
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
static TypeId GetRegistered(uint32_t i)
virtual ~CollisionTestCase()
Hasher & clear(void)
Restore initial state.
std::string GetName(void) const
uint16_t GetUid(void) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
hash_t GetHash(void) const
virtual ~UniqueTypeIdTestCase()
void Report(const std::string how, const uint32_t delta) const
LogLevel
Logging severity classes and levels.
static TypeIdTestSuite g_TypeIdTestSuite
const std::string suite("type-id: ")
virtual ~LookupTimeTestCase()
std::string GetName(void) const
a unique identifier for an interface.
Generic Hash function interface.
void LogComponentEnable(char const *name, enum LogLevel level)
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
static TypeId LookupByName(std::string name)