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/>.
21 #include "testutils.h"
25 # define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW
26 # include "vircommandpriv.h"
29 # define MODNAME "vfio-pci"
31 # define VIR_FROM_THIS VIR_FROM_NONE
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
);
43 if (virTestCompareToString(exp_cmd
, actual_cmd
) < 0) {
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
);
62 fprintf(stderr
, "Failed to load, error: %s\n", errbuf
);
66 if (checkOutput(&buf
, MODPROBE
" -b " MODNAME
"\n") < 0)
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
);
84 fprintf(stderr
, "Failed to unload, error: %s\n", errbuf
);
88 if (checkOutput(&buf
, RMMOD
" " MODNAME
"\n") < 0)
100 if (virTestRun("load", testKModLoad
, NULL
) < 0)
102 if (virTestRun("unload", testKModUnload
, NULL
) < 0)
105 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
109 VIR_TEST_MAIN(mymain
);