priv-jobState is used to store dummy job type, and priv->jobOperation is used to store dummy job operation, they are initialized to VIR_DOMAIN_JOB_NONE and VIR_DOMAIN_JOB_OPERATION_UNKNOWN, we can just change them in other job related APIs as there is no real job in test driver. Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx> --- src/test/test_driver.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 00cc13511a..9306f0e104 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -380,6 +380,10 @@ struct _testDomainObjPrivate { /* used by get/set time APIs */ long long seconds; unsigned int nseconds; + + /* used by Job Info APIs */ + unsigned int jobState; + unsigned int jobOperation; }; @@ -396,6 +400,9 @@ testDomainObjPrivateAlloc(void *opaque) priv->seconds = 627319920; priv->nseconds = 0; + priv->jobState = VIR_DOMAIN_JOB_NONE; + priv->jobOperation = VIR_DOMAIN_JOB_OPERATION_UNKNOWN; + return priv; } @@ -2681,6 +2688,87 @@ testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED) return ret; } +static int +testDomainGetJobInfoImpl(virDomainObj *dom, + virDomainJobInfoPtr info) +{ + testDomainObjPrivate *priv = dom->privateData; + + memset(info, 0, sizeof(*info)); + + info->type = priv->jobState; + + switch (priv->jobState) { + case VIR_DOMAIN_JOB_NONE: + break; + + case VIR_DOMAIN_JOB_BOUNDED: + info->dataTotal = 30 * 1024; + info->dataProcessed = 10 * 1024; + info->dataRemaining = 20 * 1024; + info->timeRemaining = 6000; + info->timeElapsed = 4000; + info->memTotal = 3 * 1024 * 1024; + info->memProcessed = 1024 * 1024; + info->memRemaining = 2 * 1024 * 1024; + info->fileTotal = 2 * 1024 * 1024; + info->fileProcessed = 1024 * 1024 / 2; + info->fileRemaining = 3 * 1024 * 1024 / 2; + break; + + case VIR_DOMAIN_JOB_UNBOUNDED: + info->dataTotal = 30 * 1024; + info->dataProcessed = 10 * 1024; + info->dataRemaining = 20 * 1024; + info->timeElapsed = 4000; + info->memTotal = 3 * 1024 * 1024; + info->memProcessed = 1024 * 1024; + info->memRemaining = 2 * 1024 * 1024; + info->fileTotal = 2 * 1024 * 1024; + info->fileProcessed = 1024 * 1024 / 2; + info->fileRemaining = 3 * 1024 * 1024 / 2; + break; + + case VIR_DOMAIN_JOB_COMPLETED: + info->timeElapsed = 10000; + info->dataTotal = 30 * 1024; + info->dataProcessed = 30 * 1024; + info->memTotal = 3 * 1024 * 1024; + info->memProcessed = 3 * 1024 * 1024; + info->fileTotal = 2 * 1024 * 1024; + info->fileProcessed = 2 * 1024 * 1024; + break; + + case VIR_DOMAIN_JOB_FAILED: + break; + + case VIR_DOMAIN_JOB_CANCELLED: + break; + } + + return 0; +} + +static int +testDomainGetJobInfo(virDomainPtr dom, + virDomainJobInfoPtr info) +{ + virDomainObj *vm; + int ret = -1; + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + ret = testDomainGetJobInfoImpl(vm, info); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, @@ -9583,6 +9671,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */ .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */ .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ + .domainGetJobInfo = testDomainGetJobInfo, /* 7.7.0 */ .domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0