[libvirt] [PATCH 1/3] vsh: Make self-test more robust

Michal Privoznik posted 3 patches 7 years, 5 months ago
[libvirt] [PATCH 1/3] vsh: Make self-test more robust
Posted by Michal Privoznik 7 years, 5 months ago
There are couple of limitations when it comes to option types and
flags for the options. For instance, VSH_OT_STRING cannot have
VSH_OFLAG_REQ set (commit c7543a728). For some reason this is
checked in vshCmddefHelp() but not in vshCmddefCheckInternals().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tools/vsh.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 10a65c39f..75568353d 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -363,12 +363,15 @@ vshCmddefCheckInternals(const vshCmdDef *cmd)
 
         if (i > 63)
             return -1; /* too many options */
-        if (opt->type == VSH_OT_BOOL) {
+
+        switch (opt->type) {
+        case VSH_OT_STRING:
+        case VSH_OT_BOOL:
             if (opt->flags & VSH_OFLAG_REQ)
                 return -1; /* bool options can't be mandatory */
-            continue;
-        }
-        if (opt->type == VSH_OT_ALIAS) {
+            break;
+
+        case VSH_OT_ALIAS: {
             size_t j;
             char *name = (char *)opt->help; /* cast away const */
             char *p;
@@ -391,10 +394,22 @@ vshCmddefCheckInternals(const vshCmdDef *cmd)
             }
             if (!cmd->opts[j].name)
                 return -1; /* alias option must map to a later option name */
-            continue;
         }
-        if (opt->type == VSH_OT_ARGV && cmd->opts[i + 1].name)
-            return -1; /* argv option must be listed last */
+            break;
+        case VSH_OT_ARGV:
+            if (cmd->opts[i + 1].name)
+                return -1; /* argv option must be listed last */
+            break;
+
+        case VSH_OT_DATA:
+            if (!(opt->flags & VSH_OFLAG_REQ))
+                return -1; /* OT_DATA should always be required. */
+            break;
+
+        case VSH_OT_INT:
+            /* nada */
+            break;
+        }
     }
     return 0;
 }
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] vsh: Make self-test more robust
Posted by Erik Skultety 7 years, 5 months ago
On Thu, Nov 16, 2017 at 02:49:27PM +0100, Michal Privoznik wrote:
> There are couple of limitations when it comes to option types and
> flags for the options. For instance, VSH_OT_STRING cannot have
> VSH_OFLAG_REQ set (commit c7543a728). For some reason this is
> checked in vshCmddefHelp() but not in vshCmddefCheckInternals().
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---

[...]

> -        if (opt->type == VSH_OT_ARGV && cmd->opts[i + 1].name)
> -            return -1; /* argv option must be listed last */
> +            break;
> +        case VSH_OT_ARGV:
> +            if (cmd->opts[i + 1].name)
> +                return -1; /* argv option must be listed last */
> +            break;
> +
> +        case VSH_OT_DATA:
> +            if (!(opt->flags & VSH_OFLAG_REQ))
> +                return -1; /* OT_DATA should always be required. */

This got me thinking a bit, since we're going to do the checking here, is there
a need for performing the same check within vshCmddefHelp too? My reasoning is
that virsh-self-test is part of the test suite run at make check. Not a deal
breaker though, just thinking out loud.

> +            break;
> +
> +        case VSH_OT_INT:
> +            /* nada */

please don't...

> +            break;
> +        }

Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] vsh: Make self-test more robust
Posted by Michal Privoznik 7 years, 5 months ago
On 11/21/2017 10:25 AM, Erik Skultety wrote:
> On Thu, Nov 16, 2017 at 02:49:27PM +0100, Michal Privoznik wrote:
>> There are couple of limitations when it comes to option types and
>> flags for the options. For instance, VSH_OT_STRING cannot have
>> VSH_OFLAG_REQ set (commit c7543a728). For some reason this is
>> checked in vshCmddefHelp() but not in vshCmddefCheckInternals().
>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
> 
> [...]
> 
>> -        if (opt->type == VSH_OT_ARGV && cmd->opts[i + 1].name)
>> -            return -1; /* argv option must be listed last */
>> +            break;
>> +        case VSH_OT_ARGV:
>> +            if (cmd->opts[i + 1].name)
>> +                return -1; /* argv option must be listed last */
>> +            break;
>> +
>> +        case VSH_OT_DATA:
>> +            if (!(opt->flags & VSH_OFLAG_REQ))
>> +                return -1; /* OT_DATA should always be required. */
> 
> This got me thinking a bit, since we're going to do the checking here, is there
> a need for performing the same check within vshCmddefHelp too? My reasoning is
> that virsh-self-test is part of the test suite run at make check. Not a deal
> breaker though, just thinking out loud.

Yeah, it probably doesn't. But frankly, I don't know why we have any
check at vshCmdDefHelp in the first place. Maybe it used to be a test
case? Like we ran all the commands with --help? Anyway, it doesn't make
sense now so I'll remove it.

> 
>> +            break;
>> +
>> +        case VSH_OT_INT:
>> +            /* nada */
> 
> please don't...

¿Por qué no?
	

Michal

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