testutils.h 2.3 KB
Newer Older
K
Karel Zak 已提交
1 2 3
/*
 * utils.c: test utils
 *
4
 * Copyright (C) 2005, 2008-2012 Red Hat, Inc.
K
Karel Zak 已提交
5
 *
O
Osier Yang 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;  If not, see
 * <http://www.gnu.org/licenses/>.
K
Karel Zak 已提交
19 20 21 22 23
 *
 * Karel Zak <kzak@redhat.com>
 */

#ifndef __VIT_TEST_UTILS_H__
24
# define __VIT_TEST_UTILS_H__
K
Karel Zak 已提交
25

26
# include <stdio.h>
27
# include "memory.h"
28

29
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
E
Eric Blake 已提交
30 31 32 33
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */

extern char *progname;
extern char *abs_srcdir;
34

35 36
double virtTestCountAverage(double *items,
                            int nitems);
K
Karel Zak 已提交
37

38 39
void virtTestResult(const char *name, int ret, const char *msg, ...)
    ATTRIBUTE_FMT_PRINTF(3,4);
40 41 42 43
int virtTestRun(const char *title,
                int nloops,
                int (*body)(const void *data),
                const void *data);
44 45
int virtTestLoadFile(const char *file, char **buf);
int virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
46

47 48
int virtTestClearLineRegex(const char *pattern,
                           char *string);
K
Karel Zak 已提交
49

50 51 52
int virtTestDifference(FILE *stream,
                       const char *expect,
                       const char *actual);
53 54 55 56
int virtTestDifferenceBin(FILE *stream,
                          const char *expect,
                          const char *actual,
                          size_t length);
K
Karel Zak 已提交
57

58 59
unsigned int virTestGetDebug(void);
unsigned int virTestGetVerbose(void);
60

61 62
char *virtTestLogContentAndReset(void);

63 64
int virtTestMain(int argc,
                 char **argv,
E
Eric Blake 已提交
65
                 int (*func)(void));
66

E
Eric Blake 已提交
67 68 69 70
/* Setup, then call func() */
# define VIRT_TEST_MAIN(func)                   \
    int main(int argc, char **argv) {           \
        return virtTestMain(argc, argv, func);  \
71 72
    }

K
Karel Zak 已提交
73
#endif /* __VIT_TEST_UTILS_H__ */