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"
|
|
|
|
|
2018-12-13 14:53:50 +00:00
|
|
|
#define LIBVIRT_VIRSYSINFOPRIV_H_ALLOW
|
2017-03-06 14:25:07 +00:00
|
|
|
#include "virsysinfopriv.h"
|
|
|
|
|
2020-06-08 10:51:07 +00:00
|
|
|
#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW
|
|
|
|
#include "vircommandpriv.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 {
|
2020-06-08 10:32:52 +00:00
|
|
|
const char *name; /* test name, also base name for result files */
|
2021-03-11 07:16:13 +00:00
|
|
|
virSysinfoDef *(*func)(void); /* sysinfo gathering function */
|
2012-12-14 15:08:25 +00:00
|
|
|
};
|
|
|
|
|
2020-06-08 10:51:07 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
testDMIDecodeDryRun(const char *const*args G_GNUC_UNUSED,
|
|
|
|
const char *const*env G_GNUC_UNUSED,
|
|
|
|
const char *input G_GNUC_UNUSED,
|
|
|
|
char **output,
|
|
|
|
char **error,
|
|
|
|
int *status,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
const char *sysinfo = opaque;
|
|
|
|
|
2020-06-02 08:15:38 +00:00
|
|
|
if (STREQ_NULLABLE(args[1], "--dump") &&
|
|
|
|
STREQ_NULLABLE(args[2], "--oem-string")) {
|
|
|
|
if (!args[3]) {
|
|
|
|
*error = g_strdup("dmidecode: option '--oem-string' requires an argument");
|
|
|
|
*status = EXIT_FAILURE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-18 13:09:22 +00:00
|
|
|
if (STREQ(args[3], "2")) {
|
|
|
|
*output = g_strdup("Some valid OEM string\n");
|
|
|
|
*error = g_strdup_printf("No OEM string number %s", args[3]);
|
|
|
|
return;
|
|
|
|
} else if (STREQ(args[3], "3")) {
|
2020-06-02 08:15:38 +00:00
|
|
|
*output = g_strdup("Ha ha ha try parsing\\n\n"
|
|
|
|
" String 3: this correctly\n"
|
2024-07-18 13:13:30 +00:00
|
|
|
" String 4:then\n");
|
2020-06-02 08:15:38 +00:00
|
|
|
} else {
|
|
|
|
*error = g_strdup_printf("No OEM string number %s", args[3]);
|
|
|
|
*status = EXIT_FAILURE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virFileReadAll(sysinfo, 10 * 1024 * 1024, output) < 0) {
|
|
|
|
*error = g_strdup(virGetLastErrorMessage());
|
|
|
|
*status = EXIT_FAILURE;
|
|
|
|
return;
|
|
|
|
}
|
2020-06-08 10:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*error = g_strdup("");
|
|
|
|
*status = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-14 15:08:25 +00:00
|
|
|
static int
|
|
|
|
testSysinfo(const void *data)
|
|
|
|
{
|
2020-06-08 10:32:52 +00:00
|
|
|
const struct testSysinfoData *testdata = data;
|
2012-12-14 15:08:25 +00:00
|
|
|
const char *sysfsActualData;
|
2021-03-11 05:17:07 +00:00
|
|
|
g_autoptr(virSysinfoDef) ret = NULL;
|
2020-06-08 09:56:45 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2020-06-08 10:32:52 +00:00
|
|
|
g_autofree char *sysinfo = NULL;
|
|
|
|
g_autofree char *cpuinfo = NULL;
|
|
|
|
g_autofree char *expected = NULL;
|
2021-04-01 15:54:09 +00:00
|
|
|
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
|
2020-06-08 10:32:52 +00:00
|
|
|
|
|
|
|
sysinfo = g_strdup_printf("%s/sysinfodata/%ssysinfo.data", abs_srcdir, testdata->name);
|
|
|
|
cpuinfo = g_strdup_printf("%s/sysinfodata/%scpuinfo.data", abs_srcdir, testdata->name);
|
|
|
|
expected = g_strdup_printf("%s/sysinfodata/%ssysinfo.expect", abs_srcdir, testdata->name);
|
|
|
|
|
2021-04-06 08:56:23 +00:00
|
|
|
virCommandSetDryRun(dryRunToken, NULL, false, false, testDMIDecodeDryRun, sysinfo);
|
2020-06-08 10:51:07 +00:00
|
|
|
|
2020-06-08 10:53:04 +00:00
|
|
|
virSysinfoSetup(sysinfo, cpuinfo);
|
2012-12-14 15:08:25 +00:00
|
|
|
|
2020-06-08 10:51:07 +00:00
|
|
|
ret = testdata->func();
|
2012-12-14 15:08:25 +00:00
|
|
|
|
2020-06-08 10:51:07 +00:00
|
|
|
if (!ret)
|
2020-06-08 09:56:45 +00:00
|
|
|
return -1;
|
2012-12-14 15:08:25 +00:00
|
|
|
|
2013-11-19 22:50:56 +00:00
|
|
|
if (virSysinfoFormat(&buf, ret) < 0)
|
2020-06-08 09:56:45 +00:00
|
|
|
return -1;
|
2012-12-14 15:08:25 +00:00
|
|
|
|
|
|
|
if (!(sysfsActualData = virBufferCurrentContent(&buf)))
|
2020-06-08 09:56:45 +00:00
|
|
|
return -1;
|
2012-12-14 15:08:25 +00:00
|
|
|
|
2020-06-08 10:32:52 +00:00
|
|
|
return virTestCompareToFile(sysfsActualData, expected);
|
2012-12-14 15:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 10:51:07 +00:00
|
|
|
#define TEST(name, func) \
|
2020-06-08 10:32:52 +00:00
|
|
|
do { \
|
2020-06-08 10:51:07 +00:00
|
|
|
struct testSysinfoData data = { name, func }; \
|
2020-06-08 10:32:52 +00:00
|
|
|
if (virTestRun(name " sysinfo", testSysinfo, &data) < 0) \
|
|
|
|
ret = EXIT_FAILURE; \
|
|
|
|
} while (0)
|
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);
|
2020-06-08 10:51:07 +00:00
|
|
|
TEST("x86", virSysinfoReadDMI);
|
2017-03-06 14:56:46 +00:00
|
|
|
TEST("arm", virSysinfoReadARM);
|
|
|
|
TEST("arm-rpi2", virSysinfoReadARM);
|
|
|
|
TEST("aarch64", virSysinfoReadARM);
|
2017-03-06 15:20:25 +00:00
|
|
|
TEST("aarch64-moonshot", virSysinfoReadARM);
|
2020-06-08 10:51:07 +00:00
|
|
|
TEST("aarch64-gigabyte", virSysinfoReadARM);
|
2024-07-18 06:22:27 +00:00
|
|
|
TEST("aarch64-hpe-apollo", 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)
|