check_mem_leaks.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Check: a unit test framework for C
  3. * Copyright (C) 2001, 2002 Arien Malec
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. /**
  21. * The purpose of this test is to be used by valgrind to check for
  22. * memory leaks. Each public API that check exports is used at
  23. * least once. Tests which use non-public API, or leak intentionally,
  24. * are not included here.
  25. */
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <check.h>
  30. #include "config.h"
  31. #include "check_check.h"
  32. int main (void)
  33. {
  34. int number_failed;
  35. SRunner *sr;
  36. /*
  37. * First, the sub suite is run. This suite has failures which
  38. * are intentional, as the output of the failures is checked
  39. * in check_check_master.c. However, here we do not check if
  40. * the failures are expected. Instead, we just want to run
  41. * them and see if they leak. Because of this, the result
  42. * of the suite is not checked.
  43. */
  44. sr = srunner_create(make_sub_suite());
  45. /*
  46. * Enable all logging types, just in case one of them
  47. * leaks memory.
  48. */
  49. srunner_set_log (sr, "test_mem_leak.log");
  50. srunner_set_xml (sr, "test_mem_leak.xml");
  51. srunner_set_tap (sr, "test_mem_leak.tap");
  52. srunner_run_all(sr, CK_NORMAL);
  53. srunner_free(sr);
  54. /* Now, the other suite is run. These are all expected to pass. */
  55. /* The following setup is necessary for the fork suite */
  56. fork_setup();
  57. sr = srunner_create (make_log_suite());
  58. srunner_add_suite(sr, make_fork_suite());
  59. #if defined(HAVE_FORK) && HAVE_FORK==1
  60. srunner_add_suite(sr, make_exit_suite());
  61. #endif
  62. srunner_add_suite(sr, make_tag_suite());
  63. srunner_add_suite(sr, make_selective_suite());
  64. /*
  65. * Enable all logging types, just in case one of them
  66. * leaks memory.
  67. */
  68. srunner_set_log (sr, "test_mem_leak.log");
  69. srunner_set_xml (sr, "test_mem_leak.xml");
  70. srunner_set_tap (sr, "test_mem_leak.tap");
  71. srunner_run_all(sr, CK_NORMAL);
  72. /* Cleanup from the fork suite setup */
  73. fork_teardown();
  74. number_failed = srunner_ntests_failed(sr);
  75. srunner_free(sr);
  76. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  77. }