25 #include "ns3/integer.h"
26 #include "ns3/double.h"
27 #include "ns3/object.h"
28 #include "ns3/traced-value.h"
29 #include "ns3/type-id.h"
38 const std::string
suite (
"type-id: ");
63 virtual void DoRun (
void);
66 HashChainFlag = 0x80000000
71 :
TestCase (
"Check uniqueness of all TypeIds")
80 cout <<
suite << endl;
86 uint32_t nids = TypeId::GetRegisteredN ();
88 cout <<
suite <<
"UniqueTypeIdTestCase: nids: " << nids << endl;
89 cout <<
suite <<
"TypeId list:" << endl;
90 cout <<
suite <<
"TypeId Chain hash Name" << endl;
92 for (uint16_t i = 0; i < nids; ++i)
94 const TypeId tid = TypeId::GetRegistered (i);
95 cout <<
suite <<
"" << std::setw (6) << tid.
GetUid ();
104 cout <<
" 0x" << std::setfill (
'0') << std::hex << std::setw (8)
105 << tid.
GetHash () << std::dec << std::setfill (
' ')
110 TypeId::LookupByName (tid.
GetName ()).GetUid (),
111 "LookupByName returned different TypeId for "
117 "TypeId .hash and Hash32 (.name) unequal for "
121 TypeId::LookupByHash (tid.
GetHash ()).GetUid (),
122 "LookupByHash returned different TypeId for "
127 cout <<
suite <<
"<-- end TypeId list -->" << endl;
143 virtual void DoRun (
void);
151 :
TestCase (
"Check behavior when type names collide")
160 cout <<
suite << endl;
165 string t1Name =
"daemon";
166 string t2Name =
"unerring";
167 cout <<
suite <<
"creating colliding types "
168 <<
"'" << t1Name <<
"', '" << t2Name <<
"'"
169 <<
" in alphabetical order:"
176 "First and lesser TypeId has HashChainFlag set");
177 cout <<
suite <<
"collision: first,lesser not chained: OK" << endl;
180 "Second and greater TypeId does not have HashChainFlag set");
181 cout <<
suite <<
"collision: second,greater chained: OK" << endl;
186 string t3Name =
"trigonon";
187 string t4Name =
"seriation";
188 cout <<
suite <<
"creating colliding types "
189 <<
"'" << t3Name <<
"', '" << t4Name <<
"'"
190 <<
" in reverse alphabetical order:"
192 TypeId t3 (t3Name.c_str ());
193 TypeId t4 (t4Name.c_str ());
197 "First and greater TypeId does not have HashChainFlag set");
198 cout <<
suite <<
"collision: first,greater chained: OK" << endl;
201 "Second and lesser TypeId has HashChainFlag set");
202 cout <<
suite <<
"collision: second,lesser not chained: OK" << endl;
246 .AddAttribute (
"attribute",
250 MakeIntegerChecker<int> ())
252 .AddAttribute (
"oldAttribute",
256 MakeIntegerChecker<int> (),
258 "use 'attribute' instead")
260 .AddAttribute (
"obsoleteAttribute",
261 "the obsolete attribute",
266 "refactor to use 'attribute'")
269 .AddTraceSource (
"trace",
272 "ns3::TracedValueCallback::Double")
274 .AddTraceSource (
"oldTrace",
275 "the old trace source",
277 "ns3::TracedValueCallback::Double",
279 "use 'trace' instead")
281 .AddTraceSource (
"obsoleteTraceSource",
282 "the obsolete trace source",
284 "ns3::TracedValueCallback::Void",
286 "refactor to use 'trace'");
306 virtual void DoRun (
void);
311 :
TestCase (
"Check deprecated Attributes and TraceSources")
320 cerr <<
suite << endl;
324 cerr <<
suite <<
"DeprecatedAttribute TypeId: " << tid.
GetUid () << endl;
329 "lookup new attribute");
330 cerr <<
suite <<
"lookup new attribute:"
331 << (ainfo.
supportLevel == TypeId::SUPPORTED ?
"supported" :
"error")
335 "lookup old attribute");
336 cerr <<
suite <<
"lookup old attribute:"
337 << (ainfo.
supportLevel == TypeId::DEPRECATED ?
"deprecated" :
"error")
345 cerr <<
suite <<
"lookup new trace source:"
346 << (tinfo.
supportLevel == TypeId::SUPPORTED ?
"supported" :
"error")
351 cerr <<
suite <<
"lookup old trace source:"
352 << (tinfo.
supportLevel == TypeId::DEPRECATED ?
"deprecated" :
"error")
376 void Report (
const std::string how,
const uint32_t delta)
const;
385 :
TestCase (
"Measure average lookup time")
394 cout <<
suite << endl;
397 uint32_t nids = TypeId::GetRegisteredN ();
399 int start = clock ();
402 for (uint16_t i = 0; i < nids; ++i)
404 const TypeId tid = TypeId::GetRegistered (i);
414 for (uint16_t i = 0; i < nids; ++i)
416 const TypeId tid = TypeId::GetRegistered (i);
428 uint32_t nids = TypeId::GetRegisteredN ();
431 <<
", num TypeId's: " << nids
438 const uint32_t delta)
const
440 double nids = TypeId::GetRegisteredN ();
443 double per = 1E6 * double(delta) / (reps * double(CLOCKS_PER_SEC));
445 cout <<
suite <<
"Lookup time: by " << how <<
": "
446 <<
"ticks: " << delta
448 <<
" microsec/lookup"
495 :
TestSuite (
"type-id-perf", PERFORMANCE)
virtual ~CollisionTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
Class used to test deprecated Attributes.
virtual ~DeprecatedAttribute()
static TypeId GetTypeId(void)
Get the type ID.
int m_attr
An attribute to test deprecation.
TracedValue< double > m_trace
A TracedValue to test deprecation.
Check deprecated Attributes and TraceSources.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~DeprecatedAttributeTestCase()
DeprecatedAttributeTestCase()
Performance test: measure average lookup time.
virtual ~LookupTimeTestCase()
void DoSetup(void)
Implementation to do any local setup required for this TestCase.
void Report(const std::string how, const uint32_t delta) const
Report the performance test results.
void DoRun(void)
Implementation to actually run this TestCase.
Test for uniqueness of all TypeIds.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~UniqueTypeIdTestCase()
A class for an empty attribute value.
Generic Hash function interface.
uint32_t GetHash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer.
Hasher & clear(void)
Restore initial state.
Hold a signed integer type.
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
std::string GetName(void) const
a unique identifier for an interface.
uint16_t GetUid(void) const
Get the internal id of this TypeId.
hash_t GetHash(void) const
Get the hash.
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName(void) const
Get the name.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static Ptr< AttributeChecker > MakeEmptyAttributeChecker()
Create an empty AttributeChecker.
static Ptr< const AttributeAccessor > MakeEmptyAttributeAccessor()
Create an empty AttributeAccessor.
#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.
#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.
static Ptr< const TraceSourceAccessor > MakeEmptyTraceSourceAccessor()
Create an empty TraceSourceAccessor.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LogLevel
Logging severity classes and levels.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_ERROR
Serious error messages only.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
const std::string suite("type-id: ")
Const string used to build the test name.
static TypeIdTestSuite g_TypeIdTestSuite
Static variable for test initialization.
static TypeIdPerformanceSuite g_TypeIdPerformanceSuite
Static variable for test initialization.