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 || !(ret = testdata->func())) goto cleanup; if (virSysinfoFormat(&buf, ret) < 0) goto cleanup; if (!(sysfsActualData = virBufferCurrentContent(&buf))) goto cleanup; if (virTestCompareToFile(sysfsActualData, testdata->expected) < 0) goto cleanup; result = 0; cleanup: virSysinfoDefFree(ret); virBufferFreeAndReset(&buf); return result; }
virSysinfoDefPtr virSysinfoRead(void) { char *path; virSysinfoDefPtr ret = NULL; char *outbuf = NULL; virCommandPtr cmd; path = virFindFileInPath(SYSINFO_SMBIOS_DECODER); if (path == NULL) { virSmbiosReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to find path for %s binary"), SYSINFO_SMBIOS_DECODER); return NULL; } cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4,17", NULL); VIR_FREE(path); virCommandSetOutputBuffer(cmd, &outbuf); if (virCommandRun(cmd, NULL) < 0) { virSmbiosReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to execute command %s"), path); goto cleanup; } if (VIR_ALLOC(ret) < 0) goto no_memory; ret->type = VIR_SYSINFO_SMBIOS; if (virSysinfoParseBIOS(outbuf, ret) < 0) goto no_memory; if (virSysinfoParseSystem(outbuf, ret) < 0) goto no_memory; ret->nprocessor = 0; ret->processor = NULL; if (virSysinfoParseProcessor(outbuf, ret) < 0) goto no_memory; ret->nmemory = 0; ret->memory = NULL; if (virSysinfoParseMemory(outbuf, ret) < 0) goto no_memory; cleanup: VIR_FREE(outbuf); virCommandFree(cmd); return ret; no_memory: virReportOOMError(); virSysinfoDefFree(ret); ret = NULL; goto cleanup; }
/* virSysinfoRead for s390x * Gathers sysinfo data from /proc/sysinfo and /proc/cpuinfo */ virSysinfoDefPtr virSysinfoRead(void) { virSysinfoDefPtr ret = NULL; char *outbuf = NULL; if (VIR_ALLOC(ret) < 0) goto no_memory; /* Gather info from /proc/cpuinfo */ if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); return NULL; } ret->nprocessor = 0; ret->processor = NULL; if (virSysinfoParseProcessor(outbuf, ret) < 0) goto no_memory; /* Free buffer before reading next file */ VIR_FREE(outbuf); /* Gather info from /proc/sysinfo */ if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), SYSINFO); return NULL; } if (virSysinfoParseSystem(outbuf, &ret->system) < 0) goto no_memory; return ret; no_memory: virSysinfoDefFree(ret); VIR_FREE(outbuf); return NULL; }
static int testSysinfo(const void *data) { int result = -1; char *sysfsExpectData = NULL; 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 || virtTestLoadFile(testdata->expected, &sysfsExpectData) < 0 || !(ret = virSysinfoRead())) { goto cleanup; } if (virSysinfoFormat(&buf,ret) < 0) goto cleanup; if (!(sysfsActualData = virBufferCurrentContent(&buf))) goto cleanup; if (STRNEQ(sysfsActualData, sysfsExpectData)) { virtTestDifference(stderr, sysfsActualData, sysfsExpectData); goto cleanup; } result = 0; cleanup: VIR_FREE(sysfsExpectData); virSysinfoDefFree(ret); virBufferFreeAndReset(&buf); return result; }