2006-05-09 15:35:46 +00:00
|
|
|
/*
|
|
|
|
|
* utils.c: test utils
|
|
|
|
|
*
|
2013-02-22 15:42:39 -07:00
|
|
|
* Copyright (C) 2005, 2008-2013 Red Hat, Inc.
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
2012-07-27 17:39:53 +08:00
|
|
|
* 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
|
2012-09-20 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 17:39:53 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
|
|
|
|
* Karel Zak <kzak@redhat.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __VIT_TEST_UTILS_H__
|
2010-03-09 19:22:22 +01:00
|
|
|
# define __VIT_TEST_UTILS_H__
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2010-03-09 19:22:22 +01:00
|
|
|
# include <stdio.h>
|
2012-12-12 18:06:53 +00:00
|
|
|
# include "viralloc.h"
|
2009-05-12 16:45:14 +00:00
|
|
|
|
2010-03-09 19:22:22 +01:00
|
|
|
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
2011-04-29 10:21:20 -06:00
|
|
|
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
|
|
|
|
|
|
|
|
|
extern char *progname;
|
|
|
|
|
extern char *abs_srcdir;
|
2009-12-15 09:43:29 +01:00
|
|
|
|
2008-08-20 20:48:35 +00:00
|
|
|
double virtTestCountAverage(double *items,
|
|
|
|
|
int nitems);
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2012-03-29 10:41:37 +01:00
|
|
|
void virtTestResult(const char *name, int ret, const char *msg, ...)
|
|
|
|
|
ATTRIBUTE_FMT_PRINTF(3,4);
|
2008-08-20 20:48:35 +00:00
|
|
|
int virtTestRun(const char *title,
|
|
|
|
|
int nloops,
|
|
|
|
|
int (*body)(const void *data),
|
|
|
|
|
const void *data);
|
2011-04-25 00:25:10 +02:00
|
|
|
int virtTestLoadFile(const char *file, char **buf);
|
|
|
|
|
int virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2009-05-21 14:22:51 +00:00
|
|
|
int virtTestClearLineRegex(const char *pattern,
|
|
|
|
|
char *string);
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2008-08-20 20:48:35 +00:00
|
|
|
int virtTestDifference(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *actual);
|
2010-12-06 17:03:22 +00:00
|
|
|
int virtTestDifferenceBin(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *actual,
|
|
|
|
|
size_t length);
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2009-11-30 19:01:31 +00:00
|
|
|
unsigned int virTestGetDebug(void);
|
|
|
|
|
unsigned int virTestGetVerbose(void);
|
2009-10-16 11:37:36 -04:00
|
|
|
|
2010-09-10 10:25:49 -06:00
|
|
|
char *virtTestLogContentAndReset(void);
|
|
|
|
|
|
2008-08-20 20:48:35 +00:00
|
|
|
int virtTestMain(int argc,
|
|
|
|
|
char **argv,
|
2011-04-29 10:21:20 -06:00
|
|
|
int (*func)(void));
|
2008-05-29 15:21:45 +00:00
|
|
|
|
2011-04-29 10:21:20 -06:00
|
|
|
/* Setup, then call func() */
|
|
|
|
|
# define VIRT_TEST_MAIN(func) \
|
|
|
|
|
int main(int argc, char **argv) { \
|
|
|
|
|
return virtTestMain(argc, argv, func); \
|
2008-05-29 15:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-10 14:31:14 +01:00
|
|
|
# define VIRT_TEST_MAIN_PRELOAD(func, lib) \
|
|
|
|
|
int main(int argc, char **argv) { \
|
|
|
|
|
const char *preload = getenv("LD_PRELOAD"); \
|
|
|
|
|
if (preload == NULL || strstr(preload, lib) == NULL) { \
|
|
|
|
|
char *newenv; \
|
|
|
|
|
if (virAsprintf(&newenv, "%s%s%s", preload ? preload : "", \
|
|
|
|
|
preload ? ":" : "", lib) < 0) { \
|
|
|
|
|
perror("virAsprintf"); \
|
2013-02-22 15:42:39 -07:00
|
|
|
return EXIT_FAILURE; \
|
2012-08-10 14:31:14 +01:00
|
|
|
} \
|
|
|
|
|
setenv("LD_PRELOAD", newenv, 1); \
|
|
|
|
|
execv(argv[0], argv); \
|
|
|
|
|
} \
|
|
|
|
|
return virtTestMain(argc, argv, func); \
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-09 15:35:46 +00:00
|
|
|
#endif /* __VIT_TEST_UTILS_H__ */
|