summaryrefslogtreecommitdiff
path: root/tests/domainconftest.c
blob: b483e1221ad6774784e6d9031bc78a742ec8a05b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * 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/>.
 */

#include <config.h>

#include "testutils.h"
#include "virlog.h"

#include "domain_conf.h"

#define VIR_FROM_THIS VIR_FROM_NONE

VIR_LOG_INIT("tests.domainconftest");

static virCaps *caps;
static virDomainXMLOption *xmlopt;

struct testGetFilesystemData {
    const char *filename;
    const char *path;
    bool expectEntry;
};

static int testGetFilesystem(const void *opaque)
{
    g_autoptr(virDomainDef) def = NULL;
    g_autofree char *filename = NULL;
    const struct testGetFilesystemData *data = opaque;
    virDomainFSDef *fsdef;

    filename = g_strdup_printf("%s/domainconfdata/%s.xml", abs_srcdir,
                               data->filename);

    if (!(def = virDomainDefParseFile(filename, xmlopt, NULL, 0)))
        return -1;

    fsdef = virDomainGetFilesystemForTarget(def,
                                            data->path);
    if (!fsdef) {
        if (data->expectEntry) {
            fprintf(stderr, "Expected FS for path '%s' in '%s'\n",
                    data->path, filename);
            return -1;
        }
    } else {
        if (!data->expectEntry) {
            fprintf(stderr, "Unexpected FS for path '%s' in '%s'\n",
                    data->path, filename);
            return -1;
        }
    }

    return 0;
}

static int
mymain(void)
{
    int ret = 0;

    if ((caps = virTestGenericCapsInit()) == NULL)
        return EXIT_FAILURE;

    if (!(xmlopt = virTestGenericDomainXMLConfInit()))
        return EXIT_FAILURE;

#define DO_TEST_GET_FS(fspath, expect) \
    do { \
        struct testGetFilesystemData data = { \
            .filename = "getfilesystem", \
            .path = fspath, \
            .expectEntry = expect, \
        }; \
        if (virTestRun("Get FS " fspath, testGetFilesystem, &data) < 0) \
            ret = -1; \
    } while (0)

    DO_TEST_GET_FS("/", true);
    DO_TEST_GET_FS("/dev", true);
    DO_TEST_GET_FS("/dev/pts", false);
    DO_TEST_GET_FS("/doesnotexist", false);

    virObjectUnref(caps);
    virObjectUnref(xmlopt);

    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

VIR_TEST_MAIN(mymain)