Blame tests/check_mem_leaks.c

Packit 0b5880
/*
Packit 0b5880
 * Check: a unit test framework for C
Packit 0b5880
 * Copyright (C) 2001, 2002 Arien Malec
Packit 0b5880
 *
Packit 0b5880
 * This library is free software; you can redistribute it and/or
Packit 0b5880
 * modify it under the terms of the GNU Lesser General Public
Packit 0b5880
 * License as published by the Free Software Foundation; either
Packit 0b5880
 * version 2.1 of the License, or (at your option) any later version.
Packit 0b5880
 *
Packit 0b5880
 * This library is distributed in the hope that it will be useful,
Packit 0b5880
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0b5880
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0b5880
 * Lesser General Public License for more details.
Packit 0b5880
 *
Packit 0b5880
 * You should have received a copy of the GNU Lesser General Public
Packit 0b5880
 * License along with this library; if not, write to the
Packit 0b5880
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
Packit 0b5880
 * MA 02110-1301, USA.
Packit 0b5880
 */
Packit 0b5880
Packit 0b5880
/**
Packit 0b5880
 * The purpose of this test is to be used by valgrind to check for
Packit 0b5880
 * memory leaks. Each public API that check exports is used at
Packit 0b5880
 * least once. Tests which use non-public API, or leak intentionally,
Packit 0b5880
 * are not included here.
Packit 0b5880
 */
Packit 0b5880
Packit 0b5880
#include <stdlib.h>
Packit 0b5880
#include <stdio.h>
Packit 0b5880
#include <string.h>
Packit 0b5880
#include <check.h>
Packit 0b5880
#include "config.h"
Packit 0b5880
#include "check_check.h"
Packit 0b5880
Packit 0b5880
int main ()
Packit 0b5880
{
Packit 0b5880
    int n;
Packit 0b5880
    SRunner *sr;
Packit 0b5880
Packit 0b5880
    /*
Packit 0b5880
     * First, the sub suite is run. This suite has failures which
Packit 0b5880
     * are intentional, as the output of the failures is checked
Packit 0b5880
     * in check_check_master.c. However, here we do not check if
Packit 0b5880
     * the failures are expected. Instead, we just want to run
Packit 0b5880
     * them and see if they leak. Because of this, the result
Packit 0b5880
     * of the suite is not checked.
Packit 0b5880
     */
Packit 0b5880
    sr = srunner_create(make_sub_suite());
Packit 0b5880
    /*
Packit 0b5880
     * Enable all logging types, just in case one of them
Packit 0b5880
     * leaks memory.
Packit 0b5880
     */
Packit 0b5880
    srunner_set_log (sr, "test_mem_leak.log");
Packit 0b5880
    srunner_set_xml (sr, "test_mem_leak.xml");
Packit 0b5880
    srunner_set_tap (sr, "test_mem_leak.tap");
Packit 0b5880
    srunner_run_all(sr, CK_NORMAL);
Packit 0b5880
    srunner_free(sr);
Packit 0b5880
Packit 0b5880
    /* Now, the other suite is run. These are all expected to pass. */
Packit 0b5880
Packit 0b5880
    /* The following setup is necessary for the fork suite */
Packit 0b5880
    fork_setup();
Packit 0b5880
Packit 0b5880
    sr = srunner_create (make_log_suite());
Packit 0b5880
    srunner_add_suite(sr, make_fork_suite());
Packit 0b5880
Packit 0b5880
#if defined(HAVE_FORK) && HAVE_FORK==1
Packit 0b5880
    srunner_add_suite(sr, make_exit_suite());
Packit 0b5880
#endif
Packit 0b5880
    srunner_add_suite(sr, make_tag_suite());
Packit 0b5880
    srunner_add_suite(sr, make_selective_suite());
Packit 0b5880
Packit 0b5880
    /*
Packit 0b5880
     * Enable all logging types, just in case one of them
Packit 0b5880
     * leaks memory.
Packit 0b5880
     */
Packit 0b5880
    srunner_set_log (sr, "test_mem_leak.log");
Packit 0b5880
    srunner_set_xml (sr, "test_mem_leak.xml");
Packit 0b5880
    srunner_set_tap (sr, "test_mem_leak.tap");
Packit 0b5880
Packit 0b5880
    srunner_run_all(sr, CK_NORMAL);
Packit 0b5880
Packit 0b5880
    /* Cleanup from the fork suite setup */
Packit 0b5880
    fork_teardown();
Packit 0b5880
Packit 0b5880
    n = srunner_ntests_failed(sr);
Packit 0b5880
    srunner_free(sr);
Packit 0b5880
    return (n == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
Packit 0b5880
}
Packit 0b5880