backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / domainconftest.c
blobe7bdc994387f61aeea8db41bad8e7b14bc0f9ef8
1 /*
2 * Copyright (C) 2013 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
19 #include <config.h>
21 #include "testutils.h"
22 #include "virerror.h"
23 #include "viralloc.h"
24 #include "virlog.h"
26 #include "domain_conf.h"
28 #define VIR_FROM_THIS VIR_FROM_NONE
30 VIR_LOG_INIT("tests.domainconftest");
32 static virCapsPtr caps;
33 static virDomainXMLOptionPtr xmlopt;
35 struct testGetFilesystemData {
36 const char *filename;
37 const char *path;
38 bool expectEntry;
41 static int testGetFilesystem(const void *opaque)
43 int ret = -1;
44 virDomainDefPtr def = NULL;
45 char *filename = NULL;
46 const struct testGetFilesystemData *data = opaque;
47 virDomainFSDefPtr fsdef;
49 if (virAsprintf(&filename, "%s/domainconfdata/%s.xml",
50 abs_srcdir, data->filename) < 0)
51 goto cleanup;
53 if (!(def = virDomainDefParseFile(filename, caps, xmlopt, NULL, 0)))
54 goto cleanup;
56 fsdef = virDomainGetFilesystemForTarget(def,
57 data->path);
58 if (!fsdef) {
59 if (data->expectEntry) {
60 fprintf(stderr, "Expected FS for path '%s' in '%s'\n",
61 data->path, filename);
62 goto cleanup;
64 } else {
65 if (!data->expectEntry) {
66 fprintf(stderr, "Unexpected FS for path '%s' in '%s'\n",
67 data->path, filename);
68 goto cleanup;
72 ret = 0;
74 cleanup:
75 virDomainDefFree(def);
76 VIR_FREE(filename);
77 return ret;
80 static int
81 mymain(void)
83 int ret = 0;
85 if ((caps = virTestGenericCapsInit()) == NULL)
86 goto cleanup;
88 if (!(xmlopt = virTestGenericDomainXMLConfInit()))
89 goto cleanup;
91 #define DO_TEST_GET_FS(fspath, expect) \
92 do { \
93 struct testGetFilesystemData data = { \
94 .filename = "getfilesystem", \
95 .path = fspath, \
96 .expectEntry = expect, \
97 }; \
98 if (virTestRun("Get FS " fspath, testGetFilesystem, &data) < 0) \
99 ret = -1; \
100 } while (0)
102 DO_TEST_GET_FS("/", true);
103 DO_TEST_GET_FS("/dev", true);
104 DO_TEST_GET_FS("/dev/pts", false);
105 DO_TEST_GET_FS("/doesnotexist", false);
107 virObjectUnref(caps);
108 virObjectUnref(xmlopt);
110 cleanup:
111 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
114 VIR_TEST_MAIN(mymain)