1/* Copyright (c) 2008 The NetBSD Foundation, Inc.
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25
26#include "atf-c/detail/sanity.h"
27
28#if defined(HAVE_CONFIG_H)
29#include "config.h"
30#endif
31
32#include <err.h>
33#include <stdarg.h>
34#include <stdio.h>
35#include <stdlib.h>
36
37static
38void
39fail(const char *fmt, ...)
40{
41    va_list ap;
42    char buf[4096];
43
44    va_start(ap, fmt);
45    vsnprintf(buf, sizeof(buf), fmt, ap);
46    va_end(ap);
47    warnx("%s", buf);
48    warnx("%s", "");
49    warnx("This is probably a bug in this application or one of the "
50          "libraries it uses.  If you believe this problem is caused "
51          "by, or is related to " PACKAGE_STRING ", please report it "
52          "to " PACKAGE_BUGREPORT " and provide as many details as "
53          "possible describing how you got to this condition.");
54
55    abort();
56}
57
58void
59atf_sanity_inv(const char *file, int line, const char *cond)
60{
61    fail("Invariant check failed at %s:%d: %s", file, line, cond);
62}
63
64void
65atf_sanity_pre(const char *file, int line, const char *cond)
66{
67    fail("Precondition check failed at %s:%d: %s", file, line, cond);
68}
69
70void
71atf_sanity_post(const char *file, int line, const char *cond)
72{
73    fail("Postcondition check failed at %s:%d: %s", file, line, cond);
74}
75