|
|
| 20 |
#include "assert.h" |
20 |
#include "assert.h" |
| 21 |
#include "abort.h" |
21 |
#include "abort.h" |
| 22 |
#include "system-path.h" |
22 |
#include "system-path.h" |
|
|
23 |
#include "log.h" |
| 23 |
#include <math.h> |
24 |
#include <math.h> |
| 24 |
#include <string.h> |
25 |
#include <string.h> |
| 25 |
#include <vector> |
26 |
#include <vector> |
| 26 |
#include <list> |
27 |
#include <list> |
| 27 |
|
28 |
|
|
|
29 |
NS_LOG_COMPONENT_DEFINE ("Test"); |
| 28 |
|
30 |
|
| 29 |
namespace ns3 { |
31 |
namespace ns3 { |
| 30 |
|
32 |
|
|
|
| 139 |
m_result (0), |
141 |
m_result (0), |
| 140 |
m_name (name) |
142 |
m_name (name) |
| 141 |
{ |
143 |
{ |
|
|
144 |
NS_LOG_FUNCTION (this << name); |
| 142 |
} |
145 |
} |
| 143 |
|
146 |
|
| 144 |
TestCase::~TestCase () |
147 |
TestCase::~TestCase () |
| 145 |
{ |
148 |
{ |
|
|
149 |
NS_LOG_FUNCTION (this); |
| 146 |
NS_ASSERT (m_runner == 0); |
150 |
NS_ASSERT (m_runner == 0); |
| 147 |
m_parent = 0; |
151 |
m_parent = 0; |
| 148 |
delete m_result; |
152 |
delete m_result; |
|
|
| 156 |
void |
160 |
void |
| 157 |
TestCase::AddTestCase (TestCase *testCase) |
161 |
TestCase::AddTestCase (TestCase *testCase) |
| 158 |
{ |
162 |
{ |
|
|
163 |
NS_LOG_FUNCTION (this); |
| 159 |
m_children.push_back (testCase); |
164 |
m_children.push_back (testCase); |
| 160 |
testCase->m_parent = this; |
165 |
testCase->m_parent = this; |
| 161 |
|
166 |
|
|
|
| 185 |
bool |
190 |
bool |
| 186 |
TestCase::IsFailed (void) const |
191 |
TestCase::IsFailed (void) const |
| 187 |
{ |
192 |
{ |
|
|
193 |
NS_LOG_FUNCTION (this); |
| 188 |
return m_result->childrenFailed || !m_result->failure.empty (); |
194 |
return m_result->childrenFailed || !m_result->failure.empty (); |
| 189 |
} |
195 |
} |
| 190 |
|
196 |
|
| 191 |
void |
197 |
void |
| 192 |
TestCase::Run (TestRunnerImpl *runner) |
198 |
TestCase::Run (TestRunnerImpl *runner) |
| 193 |
{ |
199 |
{ |
|
|
200 |
NS_LOG_FUNCTION (this); |
| 194 |
m_result = new Result (); |
201 |
m_result = new Result (); |
| 195 |
m_runner = runner; |
202 |
m_runner = runner; |
| 196 |
DoSetup (); |
203 |
DoSetup (); |
|
|
| 213 |
std::string |
220 |
std::string |
| 214 |
TestCase::GetName (void) const |
221 |
TestCase::GetName (void) const |
| 215 |
{ |
222 |
{ |
|
|
223 |
NS_LOG_FUNCTION (this); |
| 216 |
return m_name; |
224 |
return m_name; |
| 217 |
} |
225 |
} |
| 218 |
void |
226 |
void |
|
|
| 220 |
std::string limit, std::string message, |
228 |
std::string limit, std::string message, |
| 221 |
std::string file, int32_t line) |
229 |
std::string file, int32_t line) |
| 222 |
{ |
230 |
{ |
|
|
231 |
NS_LOG_FUNCTION (this); |
| 223 |
m_result->failure.push_back (TestCaseFailure (cond, actual, limit, |
232 |
m_result->failure.push_back (TestCaseFailure (cond, actual, limit, |
| 224 |
message, file, line)); |
233 |
message, file, line)); |
| 225 |
// set childrenFailed flag on parents. |
234 |
// set childrenFailed flag on parents. |
|
|
| 234 |
bool |
243 |
bool |
| 235 |
TestCase::MustAssertOnFailure (void) const |
244 |
TestCase::MustAssertOnFailure (void) const |
| 236 |
{ |
245 |
{ |
|
|
246 |
NS_LOG_FUNCTION (this); |
| 237 |
return m_runner->MustAssertOnFailure (); |
247 |
return m_runner->MustAssertOnFailure (); |
| 238 |
} |
248 |
} |
| 239 |
bool |
249 |
bool |
| 240 |
TestCase::MustContinueOnFailure (void) const |
250 |
TestCase::MustContinueOnFailure (void) const |
| 241 |
{ |
251 |
{ |
|
|
252 |
NS_LOG_FUNCTION (this); |
| 242 |
return m_runner->MustContinueOnFailure (); |
253 |
return m_runner->MustContinueOnFailure (); |
| 243 |
} |
254 |
} |
| 244 |
|
255 |
|
| 245 |
std::string |
256 |
std::string |
| 246 |
TestCase::CreateDataDirFilename (std::string filename) |
257 |
TestCase::CreateDataDirFilename (std::string filename) |
| 247 |
{ |
258 |
{ |
|
|
259 |
NS_LOG_FUNCTION (this); |
| 248 |
const TestCase *current = this; |
260 |
const TestCase *current = this; |
| 249 |
while (current->m_dataDir == "" && current != 0) |
261 |
while (current->m_dataDir == "" && current != 0) |
| 250 |
{ |
262 |
{ |
|
|
| 262 |
std::string |
274 |
std::string |
| 263 |
TestCase::CreateTempDirFilename (std::string filename) |
275 |
TestCase::CreateTempDirFilename (std::string filename) |
| 264 |
{ |
276 |
{ |
|
|
277 |
NS_LOG_FUNCTION (this); |
| 265 |
if (m_runner->MustUpdateData ()) |
278 |
if (m_runner->MustUpdateData ()) |
| 266 |
{ |
279 |
{ |
| 267 |
return CreateDataDirFilename (filename); |
280 |
return CreateDataDirFilename (filename); |
|
|
| 283 |
bool |
296 |
bool |
| 284 |
TestCase::GetErrorStatus (void) const |
297 |
TestCase::GetErrorStatus (void) const |
| 285 |
{ |
298 |
{ |
|
|
299 |
NS_LOG_FUNCTION (this); |
| 286 |
return IsStatusFailure (); |
300 |
return IsStatusFailure (); |
| 287 |
} |
301 |
} |
| 288 |
bool |
302 |
bool |
| 289 |
TestCase::IsStatusFailure (void) const |
303 |
TestCase::IsStatusFailure (void) const |
| 290 |
{ |
304 |
{ |
|
|
305 |
NS_LOG_FUNCTION (this); |
| 291 |
return !IsStatusSuccess (); |
306 |
return !IsStatusSuccess (); |
| 292 |
} |
307 |
} |
| 293 |
bool |
308 |
bool |
| 294 |
TestCase::IsStatusSuccess (void) const |
309 |
TestCase::IsStatusSuccess (void) const |
| 295 |
{ |
310 |
{ |
|
|
311 |
NS_LOG_FUNCTION (this); |
| 296 |
return m_result->failure.empty (); |
312 |
return m_result->failure.empty (); |
| 297 |
} |
313 |
} |
| 298 |
|
314 |
|
| 299 |
void |
315 |
void |
| 300 |
TestCase::SetDataDir (std::string directory) |
316 |
TestCase::SetDataDir (std::string directory) |
| 301 |
{ |
317 |
{ |
|
|
318 |
NS_LOG_FUNCTION (this); |
| 302 |
m_dataDir = directory; |
319 |
m_dataDir = directory; |
| 303 |
} |
320 |
} |
| 304 |
|
321 |
|
|
|
| 314 |
: TestCase (name), |
331 |
: TestCase (name), |
| 315 |
m_type (type) |
332 |
m_type (type) |
| 316 |
{ |
333 |
{ |
|
|
334 |
NS_LOG_FUNCTION (this); |
| 317 |
TestRunnerImpl::Instance ()->AddTestSuite (this); |
335 |
TestRunnerImpl::Instance ()->AddTestSuite (this); |
| 318 |
} |
336 |
} |
| 319 |
|
337 |
|
| 320 |
TestSuite::Type |
338 |
TestSuite::Type |
| 321 |
TestSuite::GetTestType (void) |
339 |
TestSuite::GetTestType (void) |
| 322 |
{ |
340 |
{ |
|
|
341 |
NS_LOG_FUNCTION (this); |
| 323 |
return m_type; |
342 |
return m_type; |
| 324 |
} |
343 |
} |
| 325 |
|
344 |
|
|
|
| 333 |
m_continueOnFailure (true), |
352 |
m_continueOnFailure (true), |
| 334 |
m_updateData (false) |
353 |
m_updateData (false) |
| 335 |
{ |
354 |
{ |
|
|
355 |
NS_LOG_FUNCTION (this); |
| 336 |
} |
356 |
} |
| 337 |
|
357 |
|
| 338 |
TestRunnerImpl::~TestRunnerImpl () |
358 |
TestRunnerImpl::~TestRunnerImpl () |
| 339 |
{ |
359 |
{ |
|
|
360 |
NS_LOG_FUNCTION (this); |
| 340 |
} |
361 |
} |
| 341 |
|
362 |
|
| 342 |
|
363 |
|
|
|
| 351 |
void |
372 |
void |
| 352 |
TestRunnerImpl::AddTestSuite (TestSuite *testSuite) |
373 |
TestRunnerImpl::AddTestSuite (TestSuite *testSuite) |
| 353 |
{ |
374 |
{ |
|
|
375 |
NS_LOG_FUNCTION (this); |
| 354 |
m_suites.push_back (testSuite); |
376 |
m_suites.push_back (testSuite); |
| 355 |
} |
377 |
} |
| 356 |
|
378 |
|
|
|
| 358 |
bool |
380 |
bool |
| 359 |
TestRunnerImpl::MustAssertOnFailure (void) const |
381 |
TestRunnerImpl::MustAssertOnFailure (void) const |
| 360 |
{ |
382 |
{ |
|
|
383 |
NS_LOG_FUNCTION (this); |
| 361 |
return m_assertOnFailure; |
384 |
return m_assertOnFailure; |
| 362 |
} |
385 |
} |
| 363 |
bool |
386 |
bool |
| 364 |
TestRunnerImpl::MustContinueOnFailure (void) const |
387 |
TestRunnerImpl::MustContinueOnFailure (void) const |
| 365 |
{ |
388 |
{ |
|
|
389 |
NS_LOG_FUNCTION (this); |
| 366 |
return m_continueOnFailure; |
390 |
return m_continueOnFailure; |
| 367 |
} |
391 |
} |
| 368 |
|
392 |
|
| 369 |
bool |
393 |
bool |
| 370 |
TestRunnerImpl::MustUpdateData (void) const |
394 |
TestRunnerImpl::MustUpdateData (void) const |
| 371 |
{ |
395 |
{ |
|
|
396 |
NS_LOG_FUNCTION (this); |
| 372 |
return m_updateData; |
397 |
return m_updateData; |
| 373 |
} |
398 |
} |
| 374 |
std::string |
399 |
std::string |
| 375 |
TestRunnerImpl::GetTempDir (void) const |
400 |
TestRunnerImpl::GetTempDir (void) const |
| 376 |
{ |
401 |
{ |
|
|
402 |
NS_LOG_FUNCTION (this); |
| 377 |
return m_tempDir; |
403 |
return m_tempDir; |
| 378 |
} |
404 |
} |
| 379 |
bool |
405 |
bool |
| 380 |
TestRunnerImpl::IsTopLevelSourceDir (std::string path) const |
406 |
TestRunnerImpl::IsTopLevelSourceDir (std::string path) const |
| 381 |
{ |
407 |
{ |
|
|
408 |
NS_LOG_FUNCTION (this); |
| 382 |
bool haveVersion = false; |
409 |
bool haveVersion = false; |
| 383 |
bool haveLicense = false; |
410 |
bool haveLicense = false; |
| 384 |
|
411 |
|
|
|
| 406 |
std::string |
433 |
std::string |
| 407 |
TestRunnerImpl::GetTopLevelSourceDir (void) const |
434 |
TestRunnerImpl::GetTopLevelSourceDir (void) const |
| 408 |
{ |
435 |
{ |
|
|
436 |
NS_LOG_FUNCTION (this); |
| 409 |
std::string self = SystemPath::FindSelfDirectory (); |
437 |
std::string self = SystemPath::FindSelfDirectory (); |
| 410 |
std::list<std::string> elements = SystemPath::Split (self); |
438 |
std::list<std::string> elements = SystemPath::Split (self); |
| 411 |
while (!elements.empty ()) |
439 |
while (!elements.empty ()) |
|
|
| 428 |
std::string |
456 |
std::string |
| 429 |
TestRunnerImpl::ReplaceXmlSpecialCharacters (std::string xml) const |
457 |
TestRunnerImpl::ReplaceXmlSpecialCharacters (std::string xml) const |
| 430 |
{ |
458 |
{ |
|
|
459 |
NS_LOG_FUNCTION (this); |
| 431 |
std::string specials = "<>&\"'"; |
460 |
std::string specials = "<>&\"'"; |
| 432 |
std::string replacements[] = {"<", ">", "&", "'", """}; |
461 |
std::string replacements[] = {"<", ">", "&", "'", """}; |
| 433 |
std::string result; |
462 |
std::string result; |
|
|
| 469 |
void |
498 |
void |
| 470 |
TestRunnerImpl::PrintReport (TestCase *test, std::ostream *os, bool xml, int level) |
499 |
TestRunnerImpl::PrintReport (TestCase *test, std::ostream *os, bool xml, int level) |
| 471 |
{ |
500 |
{ |
|
|
501 |
NS_LOG_FUNCTION (this); |
| 472 |
if (test->m_result == 0) |
502 |
if (test->m_result == 0) |
| 473 |
{ |
503 |
{ |
| 474 |
// Do not print reports for tests that were not run. |
504 |
// Do not print reports for tests that were not run. |
|
|
| 540 |
void |
570 |
void |
| 541 |
TestRunnerImpl::PrintHelp (const char *program_name) const |
571 |
TestRunnerImpl::PrintHelp (const char *program_name) const |
| 542 |
{ |
572 |
{ |
|
|
573 |
NS_LOG_FUNCTION (this); |
| 543 |
std::cout << "Usage: " << program_name << " [OPTIONS]" << std::endl |
574 |
std::cout << "Usage: " << program_name << " [OPTIONS]" << std::endl |
| 544 |
<< std::endl |
575 |
<< std::endl |
| 545 |
<< "Options: " |
576 |
<< "Options: " |
|
|
| 570 |
TestRunnerImpl::PrintTestNameList (std::list<TestCase *>::const_iterator begin, |
601 |
TestRunnerImpl::PrintTestNameList (std::list<TestCase *>::const_iterator begin, |
| 571 |
std::list<TestCase *>::const_iterator end) const |
602 |
std::list<TestCase *>::const_iterator end) const |
| 572 |
{ |
603 |
{ |
|
|
604 |
NS_LOG_FUNCTION (this); |
| 573 |
for (std::list<TestCase *>::const_iterator i = begin; i != end; ++i) |
605 |
for (std::list<TestCase *>::const_iterator i = begin; i != end; ++i) |
| 574 |
{ |
606 |
{ |
| 575 |
TestCase *test = *i; |
607 |
TestCase *test = *i; |
|
|
| 580 |
void |
612 |
void |
| 581 |
TestRunnerImpl::PrintTestTypeList (void) const |
613 |
TestRunnerImpl::PrintTestTypeList (void) const |
| 582 |
{ |
614 |
{ |
|
|
615 |
NS_LOG_FUNCTION (this); |
| 583 |
std::cout << " bvt: Build Verification Tests (to see if build completed successfully)" << std::endl; |
616 |
std::cout << " bvt: Build Verification Tests (to see if build completed successfully)" << std::endl; |
| 584 |
std::cout << " core: Run all TestSuite-based tests (exclude examples)" << std::endl; |
617 |
std::cout << " core: Run all TestSuite-based tests (exclude examples)" << std::endl; |
| 585 |
std::cout << " example: Examples (to see if example programs run successfully)" << std::endl; |
618 |
std::cout << " example: Examples (to see if example programs run successfully)" << std::endl; |
|
|
| 592 |
std::list<TestCase *> |
625 |
std::list<TestCase *> |
| 593 |
TestRunnerImpl::FilterTests (std::string testName, enum TestSuite::Type testType) const |
626 |
TestRunnerImpl::FilterTests (std::string testName, enum TestSuite::Type testType) const |
| 594 |
{ |
627 |
{ |
|
|
628 |
NS_LOG_FUNCTION (this); |
| 595 |
std::list<TestCase *> tests; |
629 |
std::list<TestCase *> tests; |
|
|
630 |
NS_LOG_LOGIC ("m_suites.size () : " << m_suites.size ()); |
| 596 |
for (uint32_t i = 0; i < m_suites.size (); ++i) |
631 |
for (uint32_t i = 0; i < m_suites.size (); ++i) |
| 597 |
{ |
632 |
{ |
| 598 |
TestSuite *test = m_suites[i]; |
633 |
TestSuite *test = m_suites[i]; |
| 599 |
if (testType != TestSuite::ALL && test->GetTestType () != testType) |
634 |
if (testType != TestSuite::ALL && test->GetTestType () != testType) |
| 600 |
{ |
635 |
{ |
| 601 |
// skip test |
636 |
NS_LOG_LOGIC ("skipping test " << test->GetName ()); |
| 602 |
continue; |
637 |
continue; |
| 603 |
} |
638 |
} |
| 604 |
if (testName != "" && test->GetName () != testName) |
639 |
if (testName != "" && test->GetName () != testName) |
| 605 |
{ |
640 |
{ |
| 606 |
// skip test |
641 |
NS_LOG_LOGIC ("skipping test " << test->GetName ()); |
| 607 |
continue; |
642 |
continue; |
| 608 |
} |
643 |
} |
|
|
644 |
NS_LOG_LOGIC ("considering test " << test->GetName ()); |
| 609 |
tests.push_back (test); |
645 |
tests.push_back (test); |
| 610 |
} |
646 |
} |
| 611 |
return tests; |
647 |
return tests; |
|
|
| 615 |
int |
651 |
int |
| 616 |
TestRunnerImpl::Run (int argc, char *argv[]) |
652 |
TestRunnerImpl::Run (int argc, char *argv[]) |
| 617 |
{ |
653 |
{ |
|
|
654 |
NS_LOG_FUNCTION (this); |
| 618 |
std::string testName = ""; |
655 |
std::string testName = ""; |
| 619 |
std::string testTypeString = ""; |
656 |
std::string testTypeString = ""; |
| 620 |
std::string out = ""; |
657 |
std::string out = ""; |
|
|
| 805 |
int |
842 |
int |
| 806 |
TestRunner::Run (int argc, char *argv[]) |
843 |
TestRunner::Run (int argc, char *argv[]) |
| 807 |
{ |
844 |
{ |
|
|
845 |
NS_LOG_FUNCTION_NOARGS (); |
| 808 |
return TestRunnerImpl::Instance ()->Run (argc, argv); |
846 |
return TestRunnerImpl::Instance ()->Run (argc, argv); |
| 809 |
} |
847 |
} |
| 810 |
|
848 |
|