diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d38006f59c8147a6a108a7b16ab0fd0745b2e384..213a9a12189b6ce281ed0aa9a7eda4af75072ca0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2518,6 +2518,60 @@ static int testDomainPinVcpu(virDomainPtr domain, return ret; } +static int +testDomainGetVcpuPinInfo(virDomainPtr dom, + int ncpumaps, + unsigned char *cpumaps, + int maplen, + unsigned int flags) +{ + testDriverPtr privconn = dom->conn->privateData; + virDomainObjPtr privdom; + virDomainDefPtr def; + int ret = -1, hostcpus, vcpu; + virBitmapPtr allcpumap = NULL; + + if (!(privdom = testDomObjFromDomain(dom))) + return -1; + + if (!(def = virDomainObjGetOneDef(privdom, flags))) + goto cleanup; + + hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo); + + if (!(allcpumap = virBitmapNew(hostcpus))) + goto cleanup; + + virBitmapSetAll(allcpumap); + + /* Clamp to actual number of vcpus */ + if (ncpumaps > def->vcpus) + ncpumaps = def->vcpus; + + for (vcpu = 0; vcpu < ncpumaps; vcpu++) { + virDomainPinDefPtr pininfo; + virBitmapPtr bitmap = NULL; + + pininfo = virDomainPinFind(def->cputune.vcpupin, + def->cputune.nvcpupin, + vcpu); + + if (pininfo && pininfo->cpumask) + bitmap = pininfo->cpumask; + else + bitmap = allcpumap; + + virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen); + } + + ret = ncpumaps; + + cleanup: + virBitmapFree(allcpumap); + virDomainObjEndAPI(&privdom); + return ret; +} + static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) { virDomainDefPtr def; @@ -6598,6 +6652,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetVcpusFlags = testDomainGetVcpusFlags, /* 0.8.5 */ .domainPinVcpu = testDomainPinVcpu, /* 0.7.3 */ .domainGetVcpus = testDomainGetVcpus, /* 0.7.3 */ + .domainGetVcpuPinInfo = testDomainGetVcpuPinInfo, /* 1.2.18 */ .domainGetMaxVcpus = testDomainGetMaxVcpus, /* 0.7.3 */ .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */ .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */ diff --git a/tests/vcpupin b/tests/vcpupin index b6b8b31ee5003093ed7d81cf4d75eaf7d6b05faa..213db9357f06f3f94df1fc464400561c2deae29b 100755 --- a/tests/vcpupin +++ b/tests/vcpupin @@ -66,12 +66,38 @@ error: vcpupin: Missing vCPU number in pin mode. EOF compare exp out || fail=1 -# without arguments. This should succeed but the backend function in the -# test driver isn't implemented -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test > out 2>&1 +# An out-of-range vCPU number when get information with live flag +$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 --live > out 2>&1 test $? = 1 || fail=1 cat <<\EOF > exp || fail=1 -error: this function is not supported by the connection driver: virDomainGetVcpuPinInfo +error: vcpu 100 is out of range of live cpu count 2 + +EOF +compare exp out || fail=1 + +# An out-of-range vCPU number when get information without flag +$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 > out 2>&1 +test $? = 1 || fail=1 +cat <<\EOF > exp || fail=1 +error: vcpu 100 is out of range of live cpu count 2 + +EOF +compare exp out || fail=1 + +# An out-of-range vCPU number when get information with config flag +$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 --config > out 2>&1 +test $? = 1 || fail=1 +cat <<\EOF > exp || fail=1 +error: vcpu 100 is out of range of persistent cpu count 2 + +EOF +compare exp out || fail=1 + +# An out-of-range vCPU number when get information with current flag +$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 --current > out 2>&1 +test $? = 1 || fail=1 +cat <<\EOF > exp || fail=1 +error: vcpu 100 is out of range of live cpu count 2 EOF compare exp out || fail=1