PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/gold/testsuite/test.cc

https://bitbucket.org/zlwu/cegcc-binutils
C++ | 107 lines | 53 code | 29 blank | 25 comment | 4 complexity | 92a2f788eba64b331755cc0579f783c2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, BSD-3-Clause, GPL-3.0, LGPL-2.1
  1. // test.cc -- simplistic test framework for gold.
  2. // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. #include "gold.h"
  18. #include <cstdio>
  19. #include "test.h"
  20. namespace gold_testsuite
  21. {
  22. // Test_framework methods.
  23. // The current test being run.
  24. Test_report* Test_framework::current_report;
  25. // Run a test.
  26. void
  27. Test_framework::run(const char *name, bool (*pfn)(Test_report*))
  28. {
  29. this->testname_ = name;
  30. this->current_fail_ = false;
  31. Test_report tr(this);
  32. Test_framework::current_report = &tr;
  33. if ((*pfn)(&tr) && !this->current_fail_)
  34. {
  35. printf("PASS: %s\n", name);
  36. ++this->passes_;
  37. }
  38. else
  39. {
  40. printf("FAIL: %s\n", name);
  41. ++this->failures_;
  42. }
  43. Test_framework::current_report = NULL;
  44. this->testname_ = NULL;
  45. }
  46. // Report a failure.
  47. void
  48. Test_framework::fail(const char* filename, int lineno)
  49. {
  50. printf("FAIL: %s: %s: %d\n", this->testname_, filename, lineno);
  51. this->current_fail_ = true;
  52. }
  53. // Let a test report an error.
  54. void
  55. Test_framework::error(const char* message)
  56. {
  57. printf("ERROR: %s: %s\n", this->testname_, message);
  58. this->current_fail_ = true;
  59. }
  60. // Register_test methods.
  61. // Linked list of all registered tests.
  62. Register_test* Register_test::all_tests;
  63. // Register a test.
  64. Register_test::Register_test(const char* name, bool (*pfn)(Test_report*))
  65. : name_(name), pfn_(pfn), next_(Register_test::all_tests)
  66. {
  67. Register_test::all_tests = this;
  68. }
  69. // Run all registered tests.
  70. void
  71. Register_test::run_tests(Test_framework* tf)
  72. {
  73. for (Register_test* p = Register_test::all_tests;
  74. p != NULL;
  75. p = p->next_)
  76. tf->run(p->name_, p->pfn_);
  77. }
  78. } // End namespace gold_testsuite.