LEFT | RIGHT |
(no file at all) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2012 Lawrence Livermore National Laboratory | 3 * Copyright (c) 2012 Lawrence Livermore National Laboratory |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "ns3/type-id.h" | 29 #include "ns3/type-id.h" |
30 #include "ns3/test.h" | 30 #include "ns3/test.h" |
31 #include "ns3/log.h" | 31 #include "ns3/log.h" |
32 #include "ns3/unused.h" | 32 #include "ns3/unused.h" |
33 | 33 |
34 using namespace std; | 34 using namespace std; |
35 | 35 |
36 using namespace ns3; | 36 using namespace ns3; |
37 | 37 |
38 | 38 |
39 const std::string suite("type-id: "); | 39 const std::string suite("type-id: "); ///< suite name |
40 ·· | 40 ·· |
41 //---------------------------- | 41 /** |
42 // | 42 * \ingroup core-test |
43 // Test for uniqueness of all TypeIds | 43 * \ingroup tests |
44 | 44 * |
| 45 * \brief Test for uniqueness of all TypeIds |
| 46 */ |
45 class UniqueTypeIdTestCase : public TestCase | 47 class UniqueTypeIdTestCase : public TestCase |
46 { | 48 { |
47 public: | 49 public: |
48 UniqueTypeIdTestCase (); | 50 UniqueTypeIdTestCase (); |
49 virtual ~UniqueTypeIdTestCase (); | 51 virtual ~UniqueTypeIdTestCase (); |
50 private: | 52 private: |
51 virtual void DoRun (void); | 53 virtual void DoRun (void); |
| 54 /// local enum |
52 enum { HashChainFlag = 0x80000000}; | 55 enum { HashChainFlag = 0x80000000}; |
53 }; | 56 }; |
54 | 57 |
55 UniqueTypeIdTestCase::UniqueTypeIdTestCase () | 58 UniqueTypeIdTestCase::UniqueTypeIdTestCase () |
56 : TestCase ("Check uniqueness of all TypeIds") | 59 : TestCase ("Check uniqueness of all TypeIds") |
57 { | 60 { |
58 } | 61 } |
59 | 62 |
60 UniqueTypeIdTestCase::~UniqueTypeIdTestCase () | 63 UniqueTypeIdTestCase::~UniqueTypeIdTestCase () |
61 { | 64 { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 TypeId::LookupByHash (tid.GetHash ()).GetUid (), | 111 TypeId::LookupByHash (tid.GetHash ()).GetUid (), |
109 "LookupByHash returned different TypeId for " | 112 "LookupByHash returned different TypeId for " |
110 << tid.GetName ()); | 113 << tid.GetName ()); |
111 ······ | 114 ······ |
112 } | 115 } |
113 | 116 |
114 cout << suite << "<-- end TypeId list -->" << endl; | 117 cout << suite << "<-- end TypeId list -->" << endl; |
115 } | 118 } |
116 | 119 |
117 | 120 |
118 //---------------------------- | 121 /** |
119 // | 122 * \ingroup core-test |
120 // Collision test | 123 * \ingroup tests |
121 | 124 * |
| 125 * \brief Collision test |
| 126 */ |
122 class CollisionTestCase : public TestCase | 127 class CollisionTestCase : public TestCase |
123 { | 128 { |
124 public: | 129 public: |
125 CollisionTestCase (); | 130 CollisionTestCase (); |
126 virtual ~CollisionTestCase (); | 131 virtual ~CollisionTestCase (); |
127 private: | 132 private: |
128 virtual void DoRun (void); | 133 virtual void DoRun (void); |
| 134 /// local enum |
129 enum { HashChainFlag = 0x80000000}; | 135 enum { HashChainFlag = 0x80000000}; |
130 }; | 136 }; |
131 | 137 |
132 CollisionTestCase::CollisionTestCase () | 138 CollisionTestCase::CollisionTestCase () |
133 : TestCase ("Check behavior when type names collide") | 139 : TestCase ("Check behavior when type names collide") |
134 { | 140 { |
135 } | 141 } |
136 | 142 |
137 CollisionTestCase::~CollisionTestCase () | 143 CollisionTestCase::~CollisionTestCase () |
138 { | 144 { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 cout << suite << "collision: second,lesser not chained: OK" << endl; | 192 cout << suite << "collision: second,lesser not chained: OK" << endl; |
187 | 193 |
188 /** TODO Extra credit: register three types whose hashes collide | 194 /** TODO Extra credit: register three types whose hashes collide |
189 * | 195 * |
190 * None found in /usr/share/dict/web2 | 196 * None found in /usr/share/dict/web2 |
191 */ | 197 */ |
192 ·· | 198 ·· |
193 } | 199 } |
194 | 200 |
195 | 201 |
196 //---------------------------- | 202 /** |
197 // | 203 * \ingroup core-test |
198 // Deprecated Attribute test | 204 * \ingroup tests |
199 | 205 * |
| 206 * \brief Deprecated Attribute test |
| 207 */ |
200 class DeprecatedAttribute : public Object | 208 class DeprecatedAttribute : public Object |
201 { | 209 { |
202 private: | 210 private: |
203 // float m_obsAttr; // this is obsolete, no trivial forwarding | 211 // float m_obsAttr; // this is obsolete, no trivial forwarding |
204 // int m_oldAttr; // this has become m_attr | 212 // int m_oldAttr; // this has become m_attr |
205 int m_attr; | 213 int m_attr; ///< test attribute |
206 | 214 |
207 // TracedValue<int> m_obsTrace; // this is obsolete, no trivial forwarding | 215 // TracedValue<int> m_obsTrace; // this is obsolete, no trivial forwarding |
208 // TracedValue<double> m_oldTrace; // this has become m_trace | 216 // TracedValue<double> m_oldTrace; // this has become m_trace |
209 TracedValue<double> m_trace; | 217 TracedValue<double> m_trace; ///< traced value |
210 | 218 |
211 public: | 219 public: |
212 DeprecatedAttribute () : m_attr (0) { NS_UNUSED (m_attr); }; | 220 DeprecatedAttribute () : m_attr (0) { NS_UNUSED (m_attr); }; |
213 virtual ~DeprecatedAttribute () { }; | 221 virtual ~DeprecatedAttribute () { }; |
214 | 222 |
215 // Register a type with a deprecated Attribute and TraceSource | 223 /** |
| 224 * \brief Register a type with a deprecated Attribute and TraceSource |
| 225 * \return type ID |
| 226 */ |
216 static TypeId GetTypeId (void) | 227 static TypeId GetTypeId (void) |
217 { | 228 { |
218 static TypeId tid = TypeId ("DeprecatedAttribute") | 229 static TypeId tid = TypeId ("DeprecatedAttribute") |
219 .SetParent<Object> () | 230 .SetParent<Object> () |
220 ······ | 231 ······ |
221 // The new attribute | 232 // The new attribute |
222 .AddAttribute ("attribute", | 233 .AddAttribute ("attribute", |
223 "the Attribute", | 234 "the Attribute", |
224 IntegerValue (1), | 235 IntegerValue (1), |
225 MakeIntegerAccessor (&DeprecatedAttribute::m_attr), | 236 MakeIntegerAccessor (&DeprecatedAttribute::m_attr), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 "ns3::TracedValueCallback::Void", | 271 "ns3::TracedValueCallback::Void", |
261 TypeId::OBSOLETE, | 272 TypeId::OBSOLETE, |
262 "refactor to use 'trace'"); | 273 "refactor to use 'trace'"); |
263 ···· | 274 ···· |
264 return tid; | 275 return tid; |
265 } | 276 } |
266 | 277 |
267 }; | 278 }; |
268 | 279 |
269 | 280 |
| 281 /** |
| 282 * \ingroup core-test |
| 283 * \ingroup tests |
| 284 * |
| 285 * \brief Depricated attribute test |
| 286 */ |
270 class DeprecatedAttributeTestCase : public TestCase | 287 class DeprecatedAttributeTestCase : public TestCase |
271 { | 288 { |
272 public: | 289 public: |
273 DeprecatedAttributeTestCase (); | 290 DeprecatedAttributeTestCase (); |
274 virtual ~DeprecatedAttributeTestCase (); | 291 virtual ~DeprecatedAttributeTestCase (); |
275 private: | 292 private: |
276 virtual void DoRun (void); | 293 virtual void DoRun (void); |
277 | 294 |
278 }; | 295 }; |
279 | 296 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 << endl; | 336 << endl; |
320 | 337 |
321 acc = tid.LookupTraceSourceByName ("oldTrace", &tinfo); | 338 acc = tid.LookupTraceSourceByName ("oldTrace", &tinfo); |
322 NS_TEST_ASSERT_MSG_NE (acc, 0, "lookup old trace source"); | 339 NS_TEST_ASSERT_MSG_NE (acc, 0, "lookup old trace source"); |
323 cerr << suite << "lookup old trace source:" | 340 cerr << suite << "lookup old trace source:" |
324 << (tinfo.supportLevel == TypeId::DEPRECATED ? "deprecated" : "error") | 341 << (tinfo.supportLevel == TypeId::DEPRECATED ? "deprecated" : "error") |
325 << endl; | 342 << endl; |
326 } | 343 } |
327 | 344 |
328 ·· | 345 ·· |
329 //---------------------------- | 346 /** |
330 // | 347 * \ingroup core-test |
331 // Performance test | 348 * \ingroup tests |
332 | 349 * |
| 350 * \brief Performance test |
| 351 */ |
333 class LookupTimeTestCase : public TestCase | 352 class LookupTimeTestCase : public TestCase |
334 { | 353 { |
335 public: | 354 public: |
336 LookupTimeTestCase (); | 355 LookupTimeTestCase (); |
337 virtual ~LookupTimeTestCase (); | 356 virtual ~LookupTimeTestCase (); |
338 private: | 357 private: |
339 void DoRun (void); | 358 void DoRun (void); |
340 void DoSetup (void); | 359 void DoSetup (void); |
| 360 /** |
| 361 * Report function |
| 362 * \param how the string |
| 363 * \param delta |
| 364 */ |
341 void Report (const std::string how, const uint32_t delta) const ; | 365 void Report (const std::string how, const uint32_t delta) const ; |
342 | 366 |
| 367 /// local enum |
343 enum { REPETITIONS = 100000 }; | 368 enum { REPETITIONS = 100000 }; |
344 }; | 369 }; |
345 | 370 |
346 LookupTimeTestCase::LookupTimeTestCase () | 371 LookupTimeTestCase::LookupTimeTestCase () |
347 : TestCase ("Measure average lookup time") | 372 : TestCase ("Measure average lookup time") |
348 { | 373 { |
349 } | 374 } |
350 | 375 |
351 LookupTimeTestCase::~LookupTimeTestCase () | 376 LookupTimeTestCase::~LookupTimeTestCase () |
352 { | 377 { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 double per = 1E6 * double(delta) / (reps * double(CLOCKS_PER_SEC)); | 432 double per = 1E6 * double(delta) / (reps * double(CLOCKS_PER_SEC)); |
408 ·· | 433 ·· |
409 cout << suite << "Lookup time: by " << how << ": " | 434 cout << suite << "Lookup time: by " << how << ": " |
410 << "ticks: " << delta | 435 << "ticks: " << delta |
411 << "\tper: " << per | 436 << "\tper: " << per |
412 << " microsec/lookup" | 437 << " microsec/lookup" |
413 << endl;································· | 438 << endl;································· |
414 } | 439 } |
415 | 440 |
416 | 441 |
417 //---------------------------- | 442 /** |
418 // | 443 * \ingroup core-test |
419 // TypeId test suites | 444 * \ingroup tests |
420 | 445 * |
| 446 * \brief TypeId test suites |
| 447 */ |
421 class TypeIdTestSuite : public TestSuite | 448 class TypeIdTestSuite : public TestSuite |
422 { | 449 { |
423 public: | 450 public: |
424 TypeIdTestSuite (); | 451 TypeIdTestSuite (); |
425 }; | 452 }; |
426 ·· | 453 ·· |
427 TypeIdTestSuite::TypeIdTestSuite () | 454 TypeIdTestSuite::TypeIdTestSuite () |
428 : TestSuite ("type-id", UNIT) | 455 : TestSuite ("type-id", UNIT) |
429 { | 456 { |
430 // Turn on logging, so we see the result of collisions | 457 // Turn on logging, so we see the result of collisions |
431 LogComponentEnable ("TypeId", ns3::LogLevel(LOG_ERROR|LOG_PREFIX_FUNC)); | 458 LogComponentEnable ("TypeId", ns3::LogLevel(LOG_ERROR|LOG_PREFIX_FUNC)); |
432 ·· | 459 ·· |
433 // If the CollisionTestCase is performed before the | 460 // If the CollisionTestCase is performed before the |
434 // UniqueIdTestCase, the artificial collisions added by | 461 // UniqueIdTestCase, the artificial collisions added by |
435 // CollisionTestCase will show up in the list of TypeIds | 462 // CollisionTestCase will show up in the list of TypeIds |
436 // as chained. | 463 // as chained. |
437 AddTestCase (new UniqueTypeIdTestCase, QUICK); | 464 AddTestCase (new UniqueTypeIdTestCase, QUICK); |
438 AddTestCase (new CollisionTestCase, QUICK); | 465 AddTestCase (new CollisionTestCase, QUICK); |
439 AddTestCase (new DeprecatedAttributeTestCase, QUICK); | 466 AddTestCase (new DeprecatedAttributeTestCase, QUICK); |
440 } | 467 } |
441 | 468 |
442 static TypeIdTestSuite g_TypeIdTestSuite;·· | 469 static TypeIdTestSuite g_TypeIdTestSuite; ///< test suite |
443 ·· | 470 ·· |
444 | 471 |
| 472 /** |
| 473 * \ingroup core-test |
| 474 * \ingroup tests |
| 475 * |
| 476 * \brief Type ID Performance test |
| 477 */ |
445 class TypeIdPerformanceSuite : public TestSuite | 478 class TypeIdPerformanceSuite : public TestSuite |
446 { | 479 { |
447 public: | 480 public: |
448 TypeIdPerformanceSuite (); | 481 TypeIdPerformanceSuite (); |
449 }; | 482 }; |
450 ·· | 483 ·· |
451 TypeIdPerformanceSuite::TypeIdPerformanceSuite () | 484 TypeIdPerformanceSuite::TypeIdPerformanceSuite () |
452 : TestSuite ("type-id-perf", PERFORMANCE) | 485 : TestSuite ("type-id-perf", PERFORMANCE) |
453 { | 486 { |
454 AddTestCase (new LookupTimeTestCase, QUICK); | 487 AddTestCase (new LookupTimeTestCase, QUICK); |
455 } | 488 } |
456 | 489 |
457 static TypeIdPerformanceSuite g_TypeIdPerformanceSuite; | 490 static TypeIdPerformanceSuite g_TypeIdPerformanceSuite; ///< performance suite |
LEFT | RIGHT |