Re: [PATCH 4/4] Add inputpool to storagevolxml2argvtest

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

 



<...snip...?>> diff --git a/tests/storagevolxml2argvtest.c
b/tests/storagevolxml2argvtest.c
> index b220994..3c338ce 100644
> --- a/tests/storagevolxml2argvtest.c
> +++ b/tests/storagevolxml2argvtest.c
> @@ -11,10 +11,32 @@
>  
>  const char create_tool[] = "qemu-img";
>  
> +/* createVol sets this on volume creation */
> +static void
> +testSetVolumeType(virStorageVolDefPtr vol,
> +                  virStoragePoolDefPtr pool)
> +{
> +    if (!vol)
> +        return;
> +
> +    switch (pool->type) {
> +    case VIR_STORAGE_POOL_DIR:
> +    case VIR_STORAGE_POOL_FS:
> +    case VIR_STORAGE_POOL_NETFS:
> +        vol->type = VIR_STORAGE_VOL_FILE;
> +        return;
> +
> +    case VIR_STORAGE_POOL_LOGICAL:
> +        vol->type = VIR_STORAGE_VOL_BLOCK;
> +        return;
> +    }
> +}
> +
>  static int
>  testCompareXMLToArgvFiles(bool shouldFail,
>                            const char *poolxml,
>                            const char *volxml,
> +                          const char *inputpoolxml,
>                            const char *inputvolxml,
>                            const char *cmdline,
>                            unsigned int flags,
> @@ -22,6 +44,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
>  {
>      char *volXmlData = NULL;
>      char *poolXmlData = NULL;
> +    char *inputpoolXmlData = NULL;
>      char *inputvolXmlData = NULL;
>      char *expectedCmdline = NULL;
>      char *actualCmdline = NULL;
> @@ -34,6 +57,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
>  
>      virStorageVolDefPtr vol = NULL, inputvol = NULL;
>      virStoragePoolDefPtr pool = NULL;
> +    virStoragePoolDefPtr inputpool = NULL;
>      virStoragePoolObj poolobj = {.def = NULL };
>  
>  
> @@ -53,13 +77,23 @@ testCompareXMLToArgvFiles(bool shouldFail,
>  
>      poolobj.def = pool;
>  
> +    if (inputpoolxml) {
> +        if (virtTestLoadFile(inputpoolxml, &inputpoolXmlData) < 0)
> +            goto cleanup;
> +        if (!(inputpool = virStoragePoolDefParseString(inputpoolXmlData)))
> +            goto cleanup;
> +    }
> +
>      if (!(vol = virStorageVolDefParseString(pool, volXmlData)))
>          goto cleanup;
>  
>      if (inputvolxml &&
> -        !(inputvol = virStorageVolDefParseString(pool, inputvolXmlData)))
> +        !(inputvol = virStorageVolDefParseString(inputpool, inputvolXmlData)))
>          goto cleanup;
>  
> +    testSetVolumeType(vol, pool);
> +    testSetVolumeType(inputvol, inputpool);

Coverity is grumpy (FORWARD_NULL) right here as inputpool could be NULL
since setting 'inputpool' has been based upon 'inputpoolxml' being true
up to this point

94   	    testSetVolumeType(vol, pool);

(13) Event var_deref_model: 	Passing null pointer "inputpool" to
function "testSetVolumeType(virStorageVolDefPtr, virStoragePoolDefPtr)",
which dereferences it. [details]
Also see events: 	[assign_zero]

95   	    testSetVolumeType(inputvol, inputpool);


> +
>      cmd = virStorageBackendCreateQemuImgCmd(conn, &poolobj, vol, inputvol,
>                                              flags, create_tool, imgformat);
>      if (!cmd) {
> @@ -88,11 +122,13 @@ testCompareXMLToArgvFiles(bool shouldFail,
>  
>  cleanup:
>      virStoragePoolDefFree(pool);
> +    virStoragePoolDefFree(inputpool);
>      virStorageVolDefFree(vol);
>      virStorageVolDefFree(inputvol);
>      virCommandFree(cmd);
>      VIR_FREE(actualCmdline);
>      VIR_FREE(expectedCmdline);
> +    VIR_FREE(inputpoolXmlData);
>      VIR_FREE(poolXmlData);
>      VIR_FREE(volXmlData);
>      VIR_FREE(inputvolXmlData);
> @@ -104,6 +140,7 @@ struct testInfo {
>      bool shouldFail;
>      const char *pool;
>      const char *vol;
> +    const char *inputpool;
>      const char *inputvol;
>      const char *cmdline;
>      unsigned int flags;
> @@ -116,6 +153,7 @@ testCompareXMLToArgvHelper(const void *data)
>      int result = -1;
>      const struct testInfo *info = data;
>      char *poolxml = NULL;
> +    char *inputpoolxml = NULL;
>      char *volxml = NULL;
>      char *inputvolxml = NULL;
>      char *cmdline = NULL;
> @@ -124,6 +162,10 @@ testCompareXMLToArgvHelper(const void *data)
>          virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml",
>                      abs_srcdir, info->inputvol) < 0)
>          goto cleanup;
> +    if (info->inputpool &&
> +        virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml",
> +                    abs_srcdir, info->inputpool) < 0)
> +        goto cleanup;
>      if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
>                      abs_srcdir, info->pool) < 0 ||
>          virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml",
> @@ -135,13 +177,15 @@ testCompareXMLToArgvHelper(const void *data)
>          goto cleanup;
>  
>      result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
> -                                       inputvolxml, cmdline, info->flags,
> +                                       inputpoolxml, inputvolxml,
> +                                       cmdline, info->flags,
>                                         info->imgformat);
>  
>  cleanup:
>      VIR_FREE(poolxml);
>      VIR_FREE(volxml);
>      VIR_FREE(inputvolxml);
> +    VIR_FREE(inputpoolxml);
>      VIR_FREE(cmdline);
>  
>      return result;
<...snip...>

--
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]