docs: Reword virDomainGetEmulatorPinInfo description
[libvirt.git] / tests / virkmodtest.c
blobec28ef12826be505964278870d6a5fee35fcfc71
1 /*
2 * Copyright (C) 2014 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"
23 #ifdef __linux__
25 # define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW
26 # include "vircommandpriv.h"
27 # include "virkmod.h"
29 # define MODNAME "vfio-pci"
31 # define VIR_FROM_THIS VIR_FROM_NONE
33 static int
34 checkOutput(virBuffer *buf, const char *exp_cmd)
36 g_autofree char *actual_cmd = NULL;
38 if (!(actual_cmd = virBufferContentAndReset(buf))) {
39 fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd);
40 return -1;
43 if (virTestCompareToString(exp_cmd, actual_cmd) < 0) {
44 return -1;
47 return 0;
51 static int
52 testKModLoad(const void *args G_GNUC_UNUSED)
54 g_autofree char *errbuf = NULL;
55 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
56 g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
58 virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL);
60 errbuf = virKModLoad(MODNAME);
61 if (errbuf) {
62 fprintf(stderr, "Failed to load, error: %s\n", errbuf);
63 return -1;
66 if (checkOutput(&buf, MODPROBE " -b " MODNAME "\n") < 0)
67 return -1;
69 return 0;
73 static int
74 testKModUnload(const void *args G_GNUC_UNUSED)
76 g_autofree char *errbuf = NULL;
77 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
78 g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
80 virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL);
82 errbuf = virKModUnload(MODNAME);
83 if (errbuf) {
84 fprintf(stderr, "Failed to unload, error: %s\n", errbuf);
85 return -1;
88 if (checkOutput(&buf, RMMOD " " MODNAME "\n") < 0)
89 return -1;
91 return 0;
95 static int
96 mymain(void)
98 int ret = 0;
100 if (virTestRun("load", testKModLoad, NULL) < 0)
101 ret = -1;
102 if (virTestRun("unload", testKModUnload, NULL) < 0)
103 ret = -1;
105 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
109 VIR_TEST_MAIN(mymain);
110 #else
112 main(void)
114 return EXIT_AM_SKIP;
116 #endif