1240116Smarcel/*
2240116Smarcel * Automated Testing Framework (atf)
3240116Smarcel *
4240116Smarcel * Copyright (c) 2008 The NetBSD Foundation, Inc.
5240116Smarcel * All rights reserved.
6240116Smarcel *
7240116Smarcel * Redistribution and use in source and binary forms, with or without
8240116Smarcel * modification, are permitted provided that the following conditions
9240116Smarcel * are met:
10240116Smarcel * 1. Redistributions of source code must retain the above copyright
11240116Smarcel *    notice, this list of conditions and the following disclaimer.
12240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright
13240116Smarcel *    notice, this list of conditions and the following disclaimer in the
14240116Smarcel *    documentation and/or other materials provided with the distribution.
15240116Smarcel *
16240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17240116Smarcel * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18240116Smarcel * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19240116Smarcel * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20240116Smarcel * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21240116Smarcel * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23240116Smarcel * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24240116Smarcel * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25240116Smarcel * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26240116Smarcel * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27240116Smarcel * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28240116Smarcel */
29240116Smarcel
30240116Smarcel#if defined(HAVE_CONFIG_H)
31240116Smarcel#include "bconfig.h"
32240116Smarcel#endif
33240116Smarcel
34240116Smarcel#include <err.h>
35240116Smarcel#include <stdarg.h>
36240116Smarcel#include <stdio.h>
37240116Smarcel#include <stdlib.h>
38240116Smarcel
39240116Smarcel#include "sanity.h"
40240116Smarcel
41240116Smarcelstatic
42240116Smarcelvoid
43240116Smarcelfail(const char *fmt, ...)
44240116Smarcel{
45240116Smarcel    va_list ap;
46240116Smarcel    char buf[4096];
47240116Smarcel
48240116Smarcel    va_start(ap, fmt);
49240116Smarcel    vsnprintf(buf, sizeof(buf), fmt, ap);
50240116Smarcel    va_end(ap);
51240116Smarcel    warnx("%s", buf);
52240116Smarcel    warnx("%s", "");
53240116Smarcel    warnx("This is probably a bug in this application or one of the "
54240116Smarcel          "libraries it uses.  If you believe this problem is caused "
55240116Smarcel          "by, or is related to " PACKAGE_STRING ", please report it "
56240116Smarcel          "to " PACKAGE_BUGREPORT " and provide as many detatils as "
57240116Smarcel          "possible describing how you got to this condition.");
58240116Smarcel
59240116Smarcel    abort();
60240116Smarcel}
61240116Smarcel
62240116Smarcelvoid
63240116Smarcelatf_sanity_inv(const char *file, int line, const char *cond)
64240116Smarcel{
65240116Smarcel    fail("Invariant check failed at %s:%d: %s", file, line, cond);
66240116Smarcel}
67240116Smarcel
68240116Smarcelvoid
69240116Smarcelatf_sanity_pre(const char *file, int line, const char *cond)
70240116Smarcel{
71240116Smarcel    fail("Precondition check failed at %s:%d: %s", file, line, cond);
72240116Smarcel}
73240116Smarcel
74240116Smarcelvoid
75240116Smarcelatf_sanity_post(const char *file, int line, const char *cond)
76240116Smarcel{
77240116Smarcel    fail("Postcondition check failed at %s:%d: %s", file, line, cond);
78240116Smarcel}
79