2006-05-09 15:35:46 +00:00
|
|
|
/*
|
2014-03-07 14:38:51 +01:00
|
|
|
* testutils.h: test utils
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
|
|
2019-06-18 11:13:14 -05:00
|
|
|
#pragma once
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2019-06-18 11:13:14 -05:00
|
|
|
#include "viralloc.h"
|
|
|
|
|
#include "virfile.h"
|
|
|
|
|
#include "virstring.h"
|
|
|
|
|
#include "virjson.h"
|
|
|
|
|
#include "domain_conf.h"
|
2009-05-12 16:45:14 +00:00
|
|
|
|
2019-06-18 11:13:14 -05:00
|
|
|
#define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
|
|
|
|
#define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
2011-04-29 10:21:20 -06:00
|
|
|
|
2021-04-13 09:28:31 +02:00
|
|
|
/* Meson provides these two definitions */
|
2019-06-18 11:13:14 -05:00
|
|
|
#if !defined(abs_srcdir) || !defined(abs_builddir)
|
2021-04-13 09:28:31 +02:00
|
|
|
# error Fix build system
|
2019-06-18 11:13:14 -05:00
|
|
|
#endif
|
2009-12-15 09:43:29 +01:00
|
|
|
|
2022-05-05 15:27:14 +02:00
|
|
|
void virTestSetHostArch(virArch arch);
|
2019-11-26 17:51:22 +00:00
|
|
|
|
2016-05-26 17:01:50 +02:00
|
|
|
int virTestRun(const char *title,
|
|
|
|
|
int (*body)(const void *data),
|
|
|
|
|
const void *data);
|
2021-08-20 16:29:45 +02:00
|
|
|
void virTestRunLog(int *ret,
|
|
|
|
|
const char *title,
|
|
|
|
|
int (*body)(const void *data),
|
|
|
|
|
const void *data);
|
2016-05-26 17:01:52 +02:00
|
|
|
int virTestLoadFile(const char *file, char **buf);
|
2017-07-25 15:11:31 +02:00
|
|
|
char *virTestLoadFilePath(const char *p, ...)
|
2019-10-14 14:13:31 +02:00
|
|
|
G_GNUC_NULL_TERMINATED;
|
2021-03-11 08:16:13 +01:00
|
|
|
virJSONValue *virTestLoadFileJSON(const char *p, ...)
|
2019-10-14 14:13:31 +02:00
|
|
|
G_GNUC_NULL_TERMINATED;
|
2017-07-25 18:40:50 +02:00
|
|
|
|
2016-05-26 17:01:51 +02:00
|
|
|
int virTestDifference(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *actual);
|
2016-05-26 17:01:54 +02:00
|
|
|
int virTestDifferenceFull(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *expectName,
|
|
|
|
|
const char *actual,
|
|
|
|
|
const char *actualName);
|
2016-05-26 17:02:01 +02:00
|
|
|
int virTestDifferenceFullNoRegenerate(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *expectName,
|
|
|
|
|
const char *actual,
|
|
|
|
|
const char *actualName);
|
2016-05-26 17:02:04 +02:00
|
|
|
int virTestDifferenceBin(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *actual,
|
|
|
|
|
size_t length);
|
2021-03-31 09:18:57 +02:00
|
|
|
int virTestCompareToFileFull(const char *actual,
|
|
|
|
|
const char *filename,
|
|
|
|
|
bool unwrap);
|
2019-02-19 18:15:23 +01:00
|
|
|
int virTestCompareToFile(const char *actual,
|
2016-05-26 17:01:53 +02:00
|
|
|
const char *filename);
|
2019-02-19 18:15:23 +01:00
|
|
|
int virTestCompareToString(const char *expect,
|
|
|
|
|
const char *actual);
|
|
|
|
|
int virTestCompareToULL(unsigned long long expect,
|
|
|
|
|
unsigned long long actual);
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2009-11-30 19:01:31 +00:00
|
|
|
unsigned int virTestGetDebug(void);
|
|
|
|
|
unsigned int virTestGetVerbose(void);
|
2013-08-02 15:43:07 -06:00
|
|
|
unsigned int virTestGetExpensive(void);
|
2015-12-10 13:30:37 +01:00
|
|
|
unsigned int virTestGetRegenerate(void);
|
2019-11-19 11:52:40 +01:00
|
|
|
void virTestPropagateLibvirtError(void);
|
2009-10-16 11:37:36 -04:00
|
|
|
|
2019-05-03 10:31:02 +02:00
|
|
|
#define VIR_TEST_DEBUG(fmt, ...) \
|
2017-11-03 13:09:47 +01:00
|
|
|
do { \
|
|
|
|
|
if (virTestGetDebug()) \
|
2019-05-03 10:31:02 +02:00
|
|
|
fprintf(stderr, fmt "\n", ## __VA_ARGS__); \
|
2015-04-23 13:38:00 -04:00
|
|
|
} while (0)
|
|
|
|
|
|
2019-05-03 10:45:58 +02:00
|
|
|
#define VIR_TEST_VERBOSE(fmt, ...) \
|
2017-11-03 13:09:47 +01:00
|
|
|
do { \
|
|
|
|
|
if (virTestGetVerbose()) \
|
2019-05-03 10:45:58 +02:00
|
|
|
fprintf(stderr, fmt "\n", ## __VA_ARGS__); \
|
2015-04-23 13:38:00 -04:00
|
|
|
} while (0)
|
|
|
|
|
|
2016-05-26 17:01:58 +02:00
|
|
|
char *virTestLogContentAndReset(void);
|
2010-09-10 10:25:49 -06:00
|
|
|
|
2016-05-26 17:02:00 +02:00
|
|
|
void virTestQuiesceLibvirtErrors(bool always);
|
2013-09-17 15:20:24 +02:00
|
|
|
|
2016-05-26 17:01:57 +02:00
|
|
|
void virTestCounterReset(const char *prefix);
|
2016-05-26 17:02:06 +02:00
|
|
|
const char *virTestCounterNext(void);
|
2015-01-15 11:44:58 +01:00
|
|
|
|
2023-03-01 10:39:44 +01:00
|
|
|
char *virTestFakeRootDirInit(void);
|
|
|
|
|
void virTestFakeRootDirCleanup(char *fakerootdir);
|
|
|
|
|
|
2021-05-16 18:20:56 +02:00
|
|
|
/**
|
|
|
|
|
* The @func shall return EXIT_FAILURE or EXIT_SUCCESS or
|
|
|
|
|
* EXIT_AM_SKIP or EXIT_AM_HARDFAIL.
|
|
|
|
|
*/
|
2016-05-26 17:02:08 +02:00
|
|
|
int virTestMain(int argc,
|
|
|
|
|
char **argv,
|
|
|
|
|
int (*func)(void),
|
|
|
|
|
...);
|
2008-05-29 15:21:45 +00:00
|
|
|
|
2011-04-29 10:21:20 -06:00
|
|
|
/* Setup, then call func() */
|
2019-06-18 11:13:14 -05:00
|
|
|
#define VIR_TEST_MAIN(func) \
|
2017-11-03 13:09:47 +01:00
|
|
|
int main(int argc, char **argv) { \
|
|
|
|
|
return virTestMain(argc, argv, func, NULL); \
|
2008-05-29 15:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-21 19:13:15 +03:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
# define PRELOAD_VAR "DYLD_INSERT_LIBRARIES"
|
2019-08-21 19:13:21 +03:00
|
|
|
# define FORCE_FLAT_NAMESPACE \
|
2019-12-18 17:16:19 +00:00
|
|
|
g_setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", TRUE);
|
2019-08-21 19:13:17 +03:00
|
|
|
# define MOCK_EXT ".dylib"
|
2019-08-21 19:13:15 +03:00
|
|
|
#else
|
|
|
|
|
# define PRELOAD_VAR "LD_PRELOAD"
|
2019-08-21 19:13:21 +03:00
|
|
|
# define FORCE_FLAT_NAMESPACE
|
2019-08-21 19:13:17 +03:00
|
|
|
# define MOCK_EXT ".so"
|
2019-08-21 19:13:15 +03:00
|
|
|
#endif
|
|
|
|
|
|
2020-01-09 18:01:44 +00:00
|
|
|
#define VIR_TEST_PRELOAD(libs) \
|
2017-11-03 13:09:47 +01:00
|
|
|
do { \
|
2019-08-21 19:13:15 +03:00
|
|
|
const char *preload = getenv(PRELOAD_VAR); \
|
2020-01-09 18:01:44 +00:00
|
|
|
if (preload == NULL || strstr(preload, libs) == NULL) { \
|
2017-11-03 13:09:47 +01:00
|
|
|
char *newenv; \
|
|
|
|
|
if (!preload) { \
|
2020-01-09 18:01:44 +00:00
|
|
|
newenv = (char *) libs; \
|
2019-10-22 15:26:14 +02:00
|
|
|
} else { \
|
2020-01-09 18:01:44 +00:00
|
|
|
newenv = g_strdup_printf("%s:%s", libs, preload); \
|
2017-11-03 13:09:47 +01:00
|
|
|
} \
|
2019-12-18 17:16:19 +00:00
|
|
|
g_setenv(PRELOAD_VAR, newenv, TRUE); \
|
2019-08-21 19:13:21 +03:00
|
|
|
FORCE_FLAT_NAMESPACE \
|
2017-11-03 13:09:47 +01:00
|
|
|
execv(argv[0], argv); \
|
|
|
|
|
} \
|
2016-04-26 15:00:24 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
2019-06-18 11:13:14 -05:00
|
|
|
#define VIR_TEST_MAIN_PRELOAD(func, ...) \
|
2017-11-03 13:09:47 +01:00
|
|
|
int main(int argc, char **argv) { \
|
|
|
|
|
return virTestMain(argc, argv, func, __VA_ARGS__, NULL); \
|
2012-08-10 14:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 02:40:50 +02:00
|
|
|
#define VIR_TEST_MOCK(mock) (abs_builddir "/lib" mock "mock" MOCK_EXT)
|
2019-08-21 19:13:16 +03:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virCaps *virTestGenericCapsInit(void);
|
|
|
|
|
virCapsHostNUMA *virTestCapsBuildNUMATopology(int seq);
|
|
|
|
|
virDomainXMLOption *virTestGenericDomainXMLConfInit(void);
|
2013-11-12 11:57:56 +00:00
|
|
|
|
2016-04-08 12:04:10 -04:00
|
|
|
typedef enum {
|
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS,
|
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE,
|
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_STABILITY,
|
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_FORMAT,
|
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_COMPARE,
|
|
|
|
|
} testCompareDomXML2XMLResult;
|
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int testCompareDomXML2XMLFiles(virCaps *caps,
|
|
|
|
|
virDomainXMLOption *xmlopt,
|
2016-01-08 15:55:44 -05:00
|
|
|
const char *inxml,
|
|
|
|
|
const char *outfile,
|
2016-01-27 15:55:01 -05:00
|
|
|
bool live,
|
2016-04-08 12:04:10 -04:00
|
|
|
unsigned int parseFlags,
|
|
|
|
|
testCompareDomXML2XMLResult expectResult);
|
2021-09-07 15:31:42 +02:00
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
virTestStablePath(const char *path);
|
2021-10-20 11:30:31 +03:00
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
int virCreateAnonymousFile(const uint8_t *data, size_t len);
|
|
|
|
|
#endif
|