]> granicus.if.org Git - check/blob - tests/check_mem_leaks.c
Merge branch 'master' into fix-abbreviations
[check] / tests / check_mem_leaks.c
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 /**
22  * The purpose of this test is to be used by valgrind to check for
23  * memory leaks. Each public API that check exports is used at
24  * least once. Tests which use non-public API, or leak intentionally,
25  * are not included here.
26  */
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <check.h>
32 #include "config.h"
33 #include "check_check.h"
34
35 int main (void)
36 {
37     int number_failed;
38     SRunner *sr;
39
40     /*
41      * First, the sub suite is run. This suite has failures which
42      * are intentional, as the output of the failures is checked
43      * in check_check_master.c. However, here we do not check if
44      * the failures are expected. Instead, we just want to run
45      * them and see if they leak. Because of this, the result
46      * of the suite is not checked.
47      */
48     sr = srunner_create(make_sub_suite());
49     /*
50      * Enable all logging types, just in case one of them
51      * leaks memory.
52      */
53     srunner_set_log (sr, "test_mem_leak.log");
54     srunner_set_xml (sr, "test_mem_leak.xml");
55     srunner_set_tap (sr, "test_mem_leak.tap");
56     srunner_run_all(sr, CK_NORMAL);
57     srunner_free(sr);
58
59     /* Now, the other suite is run. These are all expected to pass. */
60
61     /* The following setup is necessary for the fork suite */
62     fork_setup();
63
64     sr = srunner_create (make_log_suite());
65     srunner_add_suite(sr, make_fork_suite());
66
67 #if defined(HAVE_FORK) && HAVE_FORK==1
68     srunner_add_suite(sr, make_exit_suite());
69 #endif
70     srunner_add_suite(sr, make_tag_suite());
71     srunner_add_suite(sr, make_selective_suite());
72
73     /*
74      * Enable all logging types, just in case one of them
75      * leaks memory.
76      */
77     srunner_set_log (sr, "test_mem_leak.log");
78     srunner_set_xml (sr, "test_mem_leak.xml");
79     srunner_set_tap (sr, "test_mem_leak.tap");
80
81     srunner_run_all(sr, CK_NORMAL);
82
83     /* Cleanup from the fork suite setup */
84     fork_teardown();
85
86     number_failed = srunner_ntests_failed(sr);
87     srunner_free(sr);
88     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
89 }
90