Re: [PATCH 5/8] test driver: Implement testNodeGetCPUStats

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 15.09.2016 10:27, Tomáš Ryšavý wrote:
> Signed-off-by: Tomáš Ryšavý <tom.rysavy.0@xxxxxxxxx>
> ---
>  src/test/test_driver.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index 811bbeb..a55519f 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -63,6 +63,7 @@
>  #include "virauth.h"
>  #include "viratomic.h"
>  #include "virdomainobjlist.h"
> +#include "virhostcpu.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_TEST
>  
> @@ -2710,6 +2711,44 @@ static int testNodeGetCellsFreeMemory(virConnectPtr conn,
>      return ret;
>  }
>  
> +#define TEST_NB_CPU_STATS 4
> +
> +static int
> +testNodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
> +                    int cpuNum ATTRIBUTE_UNUSED,
> +                    virNodeCPUStatsPtr params,
> +                    int *nparams,
> +                    unsigned int flags)
> +{
> +    size_t i = 0;
> +
> +    virCheckFlags(0, -1);
> +
> +    if (params == NULL) {
> +        *nparams = TEST_NB_CPU_STATS;
> +        return 0;
> +    }
> +
> +    for (i = 0; i < *nparams && i < 4; i++) {
> +        switch (i) {
> +        case 0:
> +            virHostCPUStatsAssign(&params[0], VIR_NODE_CPU_STATS_USER, 9797400000);

You need to check for the return value of this function ^^. For instance
like this:

  if (virHostCPUStatsAssign(&params[i], VIR_NODE_CPU_STATS_USER,
9797400000) < 0)
    return -1;


> +            break;
> +        case 1:
> +            virHostCPUStatsAssign(&params[1], VIR_NODE_CPU_STATS_KERNEL, 34678723400000);
> +            break;
> +        case 2:
> +            virHostCPUStatsAssign(&params[2], VIR_NODE_CPU_STATS_IDLE, 87264900000);
> +            break;
> +        case 3:
> +            virHostCPUStatsAssign(&params[3], VIR_NODE_CPU_STATS_IOWAIT, 763600000);
> +            break;
> +        }
> +    }
> +
> +    *nparams = i;
> +    return 0;
> +}
>  
>  static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
>  {
> @@ -6702,6 +6741,7 @@ static virHypervisorDriver testHypervisorDriver = {
>      .connectGetHostname = testConnectGetHostname, /* 0.6.3 */
>      .connectGetMaxVcpus = testConnectGetMaxVcpus, /* 0.3.2 */
>      .nodeGetInfo = testNodeGetInfo, /* 0.1.1 */
> +    .nodeGetCPUStats = testNodeGetCPUStats, /* 2.3.0 */
>      .connectGetCapabilities = testConnectGetCapabilities, /* 0.2.1 */
>      .connectGetSysinfo = testConnectGetSysinfo, /* 2.3.0 */
>      .connectGetType = testConnectGetType, /* 2.3.0 */
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]