2014-03-17 15:19:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 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"
|
2019-03-06 17:21:31 +00:00
|
|
|
#include "testutilsqemu.h"
|
2014-03-17 15:19:46 +00:00
|
|
|
#include "qemu/qemu_capabilities.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _testQemuData testQemuData;
|
|
|
|
typedef testQemuData *testQemuDataPtr;
|
|
|
|
struct _testQemuData {
|
2019-03-07 13:33:20 +00:00
|
|
|
const char *inputDir;
|
|
|
|
const char *outputDir;
|
2019-10-22 14:08:10 +00:00
|
|
|
const char *prefix;
|
|
|
|
const char *version;
|
2018-09-13 16:06:20 +00:00
|
|
|
const char *archName;
|
2019-10-22 13:44:37 +00:00
|
|
|
const char *suffix;
|
2019-03-07 13:24:14 +00:00
|
|
|
int ret;
|
2014-03-17 15:19:46 +00:00
|
|
|
};
|
|
|
|
|
2019-03-07 13:22:37 +00:00
|
|
|
static int
|
2019-03-07 13:24:14 +00:00
|
|
|
testQemuDataInit(testQemuDataPtr data)
|
2019-03-07 13:22:37 +00:00
|
|
|
{
|
2019-03-07 13:33:20 +00:00
|
|
|
data->outputDir = abs_srcdir "/qemucaps2xmloutdata";
|
|
|
|
|
2019-03-07 13:24:14 +00:00
|
|
|
data->ret = 0;
|
|
|
|
|
2019-03-07 13:22:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-17 15:19:46 +00:00
|
|
|
static virQEMUCapsPtr
|
|
|
|
testQemuGetCaps(char *caps)
|
|
|
|
{
|
|
|
|
virQEMUCapsPtr qemuCaps = NULL;
|
|
|
|
xmlDocPtr xml;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
ssize_t i, n;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree xmlNodePtr *nodes = NULL;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
|
|
|
if (!(xml = virXMLParseStringCtxt(caps, "(test caps)", &ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("/qemuCaps/flag", ctxt, &nodes)) < 0) {
|
|
|
|
fprintf(stderr, "failed to parse qemu capabilities flags");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(qemuCaps = virQEMUCapsNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *str = virXMLPropString(nodes[i], "name");
|
2014-03-17 15:19:46 +00:00
|
|
|
if (str) {
|
|
|
|
int flag = virQEMUCapsTypeFromString(str);
|
|
|
|
if (flag < 0) {
|
|
|
|
fprintf(stderr, "Unknown qemu capabilities flag %s", str);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virQEMUCapsSet(qemuCaps, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return qemuCaps;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(qemuCaps);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virCapsPtr
|
|
|
|
testGetCaps(char *capsData, const testQemuData *data)
|
|
|
|
{
|
2020-07-28 19:58:18 +00:00
|
|
|
g_autoptr(virQEMUCaps) qemuCaps = NULL;
|
2014-03-17 15:19:46 +00:00
|
|
|
virCapsPtr caps = NULL;
|
2018-09-13 16:06:20 +00:00
|
|
|
virArch arch = virArchFromString(data->archName);
|
2019-10-15 13:16:31 +00:00
|
|
|
g_autofree char *binary = NULL;
|
2018-09-13 16:06:20 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
binary = g_strdup_printf("/usr/bin/qemu-system-%s", data->archName);
|
2014-03-17 15:19:46 +00:00
|
|
|
|
|
|
|
if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) {
|
|
|
|
fprintf(stderr, "failed to parse qemu capabilities flags");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:06:20 +00:00
|
|
|
if ((caps = virCapabilitiesNew(arch, false, false)) == NULL) {
|
2014-03-17 15:19:46 +00:00
|
|
|
fprintf(stderr, "failed to create the fake capabilities");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virQEMUCapsInitGuestFromBinary(caps,
|
2018-09-13 16:06:20 +00:00
|
|
|
binary,
|
2014-03-17 15:19:46 +00:00
|
|
|
qemuCaps,
|
2018-09-13 16:06:20 +00:00
|
|
|
arch) < 0) {
|
2014-03-17 15:19:46 +00:00
|
|
|
fprintf(stderr, "failed to create the capabilities from qemu");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
error:
|
2015-09-08 11:12:52 +00:00
|
|
|
virObjectUnref(caps);
|
2014-03-17 15:19:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testQemuCapsXML(const void *opaque)
|
|
|
|
{
|
|
|
|
const testQemuData *data = opaque;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *capsFile = NULL;
|
|
|
|
g_autofree char *xmlFile = NULL;
|
|
|
|
g_autofree char *capsData = NULL;
|
|
|
|
g_autofree char *capsXml = NULL;
|
2020-07-28 19:58:18 +00:00
|
|
|
g_autoptr(virCaps) capsProvided = NULL;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
xmlFile = g_strdup_printf("%s/caps.%s.xml", data->outputDir, data->archName);
|
2014-03-17 15:19:46 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
capsFile = g_strdup_printf("%s/%s_%s.%s.%s",
|
|
|
|
data->inputDir, data->prefix, data->version,
|
|
|
|
data->archName, data->suffix);
|
2014-03-17 15:19:46 +00:00
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(capsFile, &capsData) < 0)
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
|
|
|
if (!(capsProvided = testGetCaps(capsData, data)))
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
|
|
|
capsXml = virCapabilitiesFormatXML(capsProvided);
|
|
|
|
if (!capsXml)
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(capsXml, xmlFile) < 0)
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
2020-07-28 21:17:02 +00:00
|
|
|
return 0;
|
2014-03-17 15:19:46 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 13:53:18 +00:00
|
|
|
static int
|
2019-10-22 13:34:10 +00:00
|
|
|
doCapsTest(const char *inputDir,
|
2019-10-22 14:08:10 +00:00
|
|
|
const char *prefix,
|
|
|
|
const char *version,
|
2019-03-07 13:53:18 +00:00
|
|
|
const char *archName,
|
2019-10-22 13:44:37 +00:00
|
|
|
const char *suffix,
|
2019-03-07 15:02:37 +00:00
|
|
|
void *opaque)
|
2019-03-07 13:53:18 +00:00
|
|
|
{
|
2019-03-07 15:02:37 +00:00
|
|
|
testQemuDataPtr data = (testQemuDataPtr) opaque;
|
2019-10-15 13:16:31 +00:00
|
|
|
g_autofree char *title = NULL;
|
2019-03-07 13:53:18 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
title = g_strdup_printf("%s (%s)", version, archName);
|
2019-03-07 13:53:18 +00:00
|
|
|
|
2019-10-22 13:34:10 +00:00
|
|
|
data->inputDir = inputDir;
|
2019-10-22 14:08:10 +00:00
|
|
|
data->prefix = prefix;
|
|
|
|
data->version = version;
|
2019-03-07 13:53:18 +00:00
|
|
|
data->archName = archName;
|
2019-10-22 13:44:37 +00:00
|
|
|
data->suffix = suffix;
|
2019-03-07 13:53:18 +00:00
|
|
|
|
|
|
|
if (virTestRun(title, testQemuCapsXML, data) < 0)
|
|
|
|
data->ret = -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-17 15:19:46 +00:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
testQemuData data;
|
|
|
|
|
|
|
|
virEventRegisterDefaultImpl();
|
|
|
|
|
2019-03-07 13:22:37 +00:00
|
|
|
if (testQemuDataInit(&data) < 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2019-04-16 10:33:14 +00:00
|
|
|
if (testQemuCapsIterate(".xml", doCapsTest, &data) < 0)
|
2019-03-07 15:02:37 +00:00
|
|
|
return EXIT_FAILURE;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
2019-03-07 13:24:14 +00:00
|
|
|
return (data.ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
2014-03-17 15:19:46 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 16:13:16 +00:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("qemucaps2xml"))
|