
On 15.09.2016 10:27, Tomáš Ryšavý wrote:
Signed-off-by: Tomáš Ryšavý <tom.rysavy.0@gmail.com> --- src/test/test_driver.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index a55519f..cf357c4 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -74,6 +74,7 @@ VIR_LOG_INIT("test.test_driver");
struct _testCell { unsigned long mem; + unsigned long freeMem; int numCpus; virCapsHostNUMACellCPU cpus[MAX_CPUS]; }; @@ -1273,6 +1274,7 @@ testOpenDefault(virConnectPtr conn) for (u = 0; u < privconn->numCells; ++u) { privconn->cells[u].numCpus = 8; privconn->cells[u].mem = (u + 1) * 2048 * 1024; + privconn->cells[u].freeMem = (u + 1) * 2048 * 512;
Quite. "* 1024" in code means that you're shifting a number to next order, e.g. making kibibytes from bytes, mebibytes from kibibytes, and so on. Therefore I suggest to halve the number one before that (which by coincidence happens to end up 1024 too).
} for (u = 0; u < 16; u++) { virBitmapPtr siblings = virBitmapNew(16); @@ -2750,6 +2752,32 @@ testNodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; }
+static unsigned long long +testNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED)
@conn is clearly used in this function, therefore ATTRIBUTE_UNUSED is not correct.
+{ + unsigned int ret = 0; + unsigned int freeMem = 0; + size_t i; + + testDriverPtr privconn = conn->privateData; + + testDriverLock(privconn); + + if (privconn->cells) { + virReportError(VIR_ERR_INVALID_ARG, + "%s", _("Range exceeds available cells")); + goto cleanup; + }
I don't quite catch your drift here. There is no range given to this function. I suggest just dropping this check completely.
+ + for (i = 0; i < privconn->numCells; i++) + freeMem += privconn->cells[i].freeMem; + ret = freeMem; + + cleanup: + testDriverUnlock(privconn); + return ret; +} + static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) { testDriverPtr privconn = domain->conn->privateData; @@ -6742,6 +6770,7 @@ static virHypervisorDriver testHypervisorDriver = { .connectGetMaxVcpus = testConnectGetMaxVcpus, /* 0.3.2 */ .nodeGetInfo = testNodeGetInfo, /* 0.1.1 */ .nodeGetCPUStats = testNodeGetCPUStats, /* 2.3.0 */ + .nodeGetFreeMemory = testNodeGetFreeMemory, /* 2.3.0 */ .connectGetCapabilities = testConnectGetCapabilities, /* 0.2.1 */ .connectGetSysinfo = testConnectGetSysinfo, /* 2.3.0 */ .connectGetType = testConnectGetType, /* 2.3.0 */
Michal