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/>.
21 #include "testutils.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
{
41 static int testGetFilesystem(const void *opaque
)
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)
53 if (!(def
= virDomainDefParseFile(filename
, caps
, xmlopt
, NULL
, 0)))
56 fsdef
= virDomainGetFilesystemForTarget(def
,
59 if (data
->expectEntry
) {
60 fprintf(stderr
, "Expected FS for path '%s' in '%s'\n",
61 data
->path
, filename
);
65 if (!data
->expectEntry
) {
66 fprintf(stderr
, "Unexpected FS for path '%s' in '%s'\n",
67 data
->path
, filename
);
75 virDomainDefFree(def
);
85 if ((caps
= virTestGenericCapsInit()) == NULL
)
88 if (!(xmlopt
= virTestGenericDomainXMLConfInit()))
91 #define DO_TEST_GET_FS(fspath, expect) \
93 struct testGetFilesystemData data = { \
94 .filename = "getfilesystem", \
96 .expectEntry = expect, \
98 if (virTestRun("Get FS " fspath, testGetFilesystem, &data) < 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
);
111 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
114 VIR_TEST_MAIN(mymain
)