2012-12-14 15:08:25 +00:00
|
|
|
/*
|
|
|
|
* sysinfotest.c: Testcase(s) for virSysinfoRead
|
|
|
|
*
|
2013-11-19 22:50:56 +00:00
|
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
2012-12-14 15:08:25 +00:00
|
|
|
* Copyright IBM Corp. 2012
|
|
|
|
*
|
|
|
|
* 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 <unistd.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-13 15:31:53 +00:00
|
|
|
#include "virsysinfo.h"
|
2012-12-14 15:08:25 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
#include "virfile.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2012-12-14 15:08:25 +00:00
|
|
|
|
2018-12-13 14:53:50 +00:00
|
|
|
#define LIBVIRT_VIRSYSINFOPRIV_H_ALLOW
|
2017-03-06 14:25:07 +00:00
|
|
|
#include "virsysinfopriv.h"
|
|
|
|
|
2013-06-07 15:10:28 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2012-12-14 15:08:25 +00:00
|
|
|
struct testSysinfoData {
|
2017-03-06 14:56:46 +00:00
|
|
|
virSysinfoDefPtr (*func)(void); /* sysinfo gathering function */
|
2012-12-14 15:08:25 +00:00
|
|
|
char *decoder; /* name of dmi decoder binary/script */
|
|
|
|
char *sysinfo; /* name of /proc/sysinfo substitute file */
|
|
|
|
char *cpuinfo; /* name of /proc/cpuinfo substitute file */
|
|
|
|
char *expected; /* (required) file containing output of virSysinfoFormat */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testSysinfo(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const char *sysfsActualData;
|
|
|
|
virSysinfoDefPtr ret = NULL;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
const struct testSysinfoData *testdata = data;
|
|
|
|
|
|
|
|
virSysinfoSetup(testdata->decoder, testdata->sysinfo, testdata->cpuinfo);
|
|
|
|
|
|
|
|
if (!testdata->expected ||
|
2017-03-06 14:56:46 +00:00
|
|
|
!(ret = testdata->func()))
|
2012-12-14 15:08:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-11-19 22:50:56 +00:00
|
|
|
if (virSysinfoFormat(&buf, ret) < 0)
|
2012-12-14 15:08:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(sysfsActualData = virBufferCurrentContent(&buf)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(sysfsActualData, testdata->expected) < 0)
|
2012-12-14 15:08:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-12-14 15:08:25 +00:00
|
|
|
virSysinfoDefFree(ret);
|
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysinfotest_run(const char *test,
|
2017-03-06 14:56:46 +00:00
|
|
|
virSysinfoDefPtr (*func)(void),
|
2012-12-14 15:08:25 +00:00
|
|
|
const char *decoder,
|
|
|
|
const char *sysinfo,
|
|
|
|
const char *cpuinfo,
|
|
|
|
const char *expected)
|
|
|
|
{
|
2018-03-11 15:27:22 +00:00
|
|
|
struct testSysinfoData testdata = { 0 };
|
2012-12-14 15:08:25 +00:00
|
|
|
int ret = EXIT_FAILURE;
|
|
|
|
|
2017-03-06 14:56:46 +00:00
|
|
|
testdata.func = func;
|
|
|
|
|
2012-12-14 15:08:25 +00:00
|
|
|
if ((decoder &&
|
|
|
|
virAsprintf(&testdata.decoder, "%s/%s", abs_srcdir, decoder) < 0) ||
|
|
|
|
(sysinfo &&
|
|
|
|
virAsprintf(&testdata.sysinfo, "%s/%s", abs_srcdir, sysinfo) < 0) ||
|
|
|
|
(cpuinfo &&
|
|
|
|
virAsprintf(&testdata.cpuinfo, "%s/%s", abs_srcdir, cpuinfo) < 0) ||
|
|
|
|
(expected &&
|
|
|
|
virAsprintf(&testdata.expected, "%s/%s", abs_srcdir, expected) < 0)) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun(test, testSysinfo, &testdata) < 0)
|
2012-12-14 15:08:25 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
ret = EXIT_SUCCESS;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
error:
|
2012-12-14 15:08:25 +00:00
|
|
|
VIR_FREE(testdata.decoder);
|
|
|
|
VIR_FREE(testdata.sysinfo);
|
|
|
|
VIR_FREE(testdata.cpuinfo);
|
|
|
|
VIR_FREE(testdata.expected);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-06 14:56:46 +00:00
|
|
|
#define TEST_FULL(name, func, decoder) \
|
|
|
|
if (sysinfotest_run(name " sysinfo", func, decoder, \
|
|
|
|
"/sysinfodata/" name "sysinfo.data", \
|
|
|
|
"/sysinfodata/" name "cpuinfo.data", \
|
|
|
|
"/sysinfodata/" name "sysinfo.expect") != EXIT_SUCCESS) \
|
|
|
|
ret = EXIT_FAILURE
|
2012-12-14 15:08:25 +00:00
|
|
|
|
|
|
|
|
2017-03-06 14:56:46 +00:00
|
|
|
#define TEST(name, func) \
|
|
|
|
TEST_FULL(name, func, NULL)
|
2012-12-14 15:08:25 +00:00
|
|
|
|
2013-04-03 17:58:50 +00:00
|
|
|
static int
|
2017-03-06 14:56:46 +00:00
|
|
|
mymain(void)
|
2013-04-03 17:58:50 +00:00
|
|
|
{
|
2015-05-12 16:21:18 +00:00
|
|
|
int ret = EXIT_SUCCESS;
|
|
|
|
|
2017-03-06 14:56:46 +00:00
|
|
|
TEST("s390", virSysinfoReadS390);
|
2018-01-12 11:38:02 +00:00
|
|
|
TEST("s390-freq", virSysinfoReadS390);
|
2017-03-06 14:56:46 +00:00
|
|
|
TEST("ppc", virSysinfoReadPPC);
|
|
|
|
TEST_FULL("x86", virSysinfoReadX86, "/sysinfodata/dmidecode.sh");
|
|
|
|
TEST("arm", virSysinfoReadARM);
|
|
|
|
TEST("arm-rpi2", virSysinfoReadARM);
|
|
|
|
TEST("aarch64", virSysinfoReadARM);
|
2017-03-06 15:20:25 +00:00
|
|
|
TEST("aarch64-moonshot", virSysinfoReadARM);
|
2015-05-12 16:21:18 +00:00
|
|
|
|
|
|
|
return ret;
|
2013-04-03 17:58:50 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 14:56:46 +00:00
|
|
|
#undef TEST
|
|
|
|
#undef TEST_FULL
|
2013-10-08 13:49:09 +00:00
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|