10#include "ns3/integer.h"
12#include "ns3/object.h"
14#include "ns3/traced-value.h"
15#include "ns3/type-id.h"
24const std::string
suite(
"type-id: ");
49 void DoRun()
override;
56 :
TestCase(
"Check uniqueness of all TypeIds")
67 std::cout <<
suite << std::endl;
75 std::cout <<
suite <<
"UniqueTypeIdTestCase: nids: " << nids << std::endl;
76 std::cout <<
suite <<
"TypeId list:" << std::endl;
77 std::cout <<
suite <<
"TypeId Chain hash Name" << std::endl;
79 for (uint16_t i = 0; i < nids; ++i)
82 std::cout <<
suite <<
"" << std::setw(6) << tid.
GetUid();
85 std::cout <<
" chain";
91 std::cout <<
" 0x" << std::setfill(
'0') << std::hex << std::setw(8) << tid.
GetHash()
92 << std::dec << std::setfill(
' ') <<
" " << tid.
GetName() << std::endl;
96 "LookupByName returned different TypeId for " << tid.
GetName());
101 "TypeId .hash and Hash32 (.name) unequal for " << tid.
GetName());
105 "LookupByHash returned different TypeId for " << tid.
GetName());
108 std::cout <<
suite <<
"<-- end TypeId list -->" << std::endl;
123 void DoRun()
override;
130 :
TestCase(
"Check behavior when type names collide")
141 std::cout <<
suite << std::endl;
146 std::string t1Name =
"daemon";
147 std::string t2Name =
"unerring";
148 std::cout <<
suite <<
"creating colliding types "
149 <<
"'" << t1Name <<
"', '" << t2Name <<
"'"
150 <<
" in alphabetical order:" << std::endl;
157 "First and lesser TypeId has HASH_CHAIN_FLAG set");
158 std::cout <<
suite <<
"collision: first,lesser not chained: OK" << std::endl;
162 "Second and greater TypeId does not have HASH_CHAIN_FLAG set");
163 std::cout <<
suite <<
"collision: second,greater chained: OK" << std::endl;
167 std::string t3Name =
"trigonon";
168 std::string t4Name =
"seriation";
169 std::cout <<
suite <<
"creating colliding types "
170 <<
"'" << t3Name <<
"', '" << t4Name <<
"'"
171 <<
" in reverse alphabetical order:" << std::endl;
178 "First and greater TypeId does not have HASH_CHAIN_FLAG set");
179 std::cout <<
suite <<
"collision: first,greater chained: OK" << std::endl;
183 "Second and lesser TypeId has HASH_CHAIN_FLAG set");
184 std::cout <<
suite <<
"collision: second,lesser not chained: OK" << std::endl;
225 TypeId(
"DeprecatedAttribute")
229 .AddAttribute(
"attribute",
235 .AddAttribute(
"oldAttribute",
241 "use 'attribute' instead")
243 .AddAttribute(
"obsoleteAttribute",
244 "the obsolete attribute",
249 "refactor to use 'attribute'")
252 .AddTraceSource(
"trace",
255 "ns3::TracedValueCallback::Double")
257 .AddTraceSource(
"oldTrace",
258 "the old trace source",
260 "ns3::TracedValueCallback::Double",
262 "use 'trace' instead")
264 .AddTraceSource(
"obsoleteTraceSource",
265 "the obsolete trace source",
267 "ns3::TracedValueCallback::Void",
269 "refactor to use 'trace'");
287 void DoRun()
override;
291 :
TestCase(
"Check deprecated Attributes and TraceSources")
302 std::cerr <<
suite << std::endl;
306 std::cerr <<
suite <<
"DeprecatedAttribute TypeId: " << tid.
GetUid() << std::endl;
312 "lookup new attribute");
313 std::cerr <<
suite <<
"lookup new attribute:"
318 "lookup old attribute");
319 std::cerr <<
suite <<
"lookup old attribute:"
326 std::cerr <<
suite <<
"lookup new trace source:"
327 << (tinfo.supportLevel ==
TypeId::SUPPORTED ?
"supported" :
"error") << std::endl;
331 std::cerr <<
suite <<
"lookup old trace source:"
347 void DoRun()
override;
361 :
TestCase(
"Measure average lookup time")
372 std::cout <<
suite << std::endl;
380 for (uint16_t i = 0; i < nids; ++i)
387 Report(
"name", stop - start);
392 for (uint16_t i = 0; i < nids; ++i)
399 Report(
"hash", stop - start);
407 std::cout <<
suite <<
"Lookup time: reps: " <<
REPETITIONS <<
", num TypeId's: " << nids
417 double per = 1E6 *
double(delta) / (reps *
double(CLOCKS_PER_SEC));
419 std::cout <<
suite <<
"Lookup time: by " << how <<
": "
420 <<
"ticks: " << delta <<
"\tper: " << per <<
" microsec/lookup" << std::endl;
void DoRun() override
Implementation to actually run this TestCase.
~CollisionTestCase() override
static constexpr auto HASH_CHAIN_FLAG
Hash chaining flag, copied from type-id.cc:IidManager.
Class used to test deprecated Attributes.
int m_attr
An attribute to test deprecation.
static TypeId GetTypeId()
Get the type ID.
~DeprecatedAttribute() override
TracedValue< double > m_trace
A TracedValue to test deprecation.
Check deprecated Attributes and TraceSources.
void DoRun() override
Implementation to actually run this TestCase.
~DeprecatedAttributeTestCase() override
DeprecatedAttributeTestCase()
Performance test: measure average lookup time.
static constexpr uint32_t REPETITIONS
Number of repetitions.
void Report(const std::string how, const uint32_t delta) const
Report the performance test results.
~LookupTimeTestCase() override
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
Test for uniqueness of all TypeIds.
static constexpr auto HASH_CHAIN_FLAG
Hash chaining flag, copied from type-id.cc:IidManager.
void DoRun() override
Implementation to actually run this TestCase.
~UniqueTypeIdTestCase() override
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()
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, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
std::string GetName() const
Trace classes with value semantics.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
hash_t GetHash() const
Get the hash.
static uint16_t GetRegisteredN()
Get the number of registered TypeIds.
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
uint16_t GetUid() const
Get the internal id of this TypeId.
bool LookupAttributeByName(std::string name, AttributeInformation *info, bool permissive=false) const
Find an Attribute by name, retrieving the associated AttributeInformation.
@ SUPPORTED
Attribute or trace source is currently used.
@ OBSOLETE
Attribute or trace source is not used anymore; simulation fails.
@ DEPRECATED
Attribute or trace source is deprecated; user is warned.
std::string GetName() const
Get the name.
static Ptr< AttributeChecker > MakeEmptyAttributeChecker()
Create an empty AttributeChecker.
static Ptr< const AttributeAccessor > MakeEmptyAttributeAccessor()
Create an empty AttributeAccessor.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#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.
Ptr< const AttributeChecker > MakeIntegerChecker()
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
LogLevel
Logging severity classes and levels.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_ERROR
Serious error messages only.
const std::string suite("type-id: ")
static TypeIdTestSuite g_TypeIdTestSuite
Static variable for test initialization.
static TypeIdPerformanceSuite g_TypeIdPerformanceSuite
Static variable for test initialization.