2023-03-09 08:49:11

by Rong Tao

[permalink] [raw]
Subject: [PATCH v2] tools/virtio: virtio_test -h,--help should return directly

From: Rong Tao <[email protected]>

When we get help information, we should return directly, and we should not
execute test cases. Move the exit() directly into the help() function and
remove it from case '?'.

Signed-off-by: Rong Tao <[email protected]>
---
v2: help(): exit with a value different from 0 (e.g. 2).
v1: https://lore.kernel.org/lkml/[email protected]/
---
tools/virtio/virtio_test.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
index 120062f94590..33e17307441f 100644
--- a/tools/virtio/virtio_test.c
+++ b/tools/virtio/virtio_test.c
@@ -327,7 +327,7 @@ const struct option longopts[] = {
}
};

-static void help(void)
+static void help(int status)
{
fprintf(stderr, "Usage: virtio_test [--help]"
" [--no-indirect]"
@@ -337,6 +337,8 @@ static void help(void)
" [--batch=random/N]"
" [--reset=N]"
"\n");
+
+ exit(status);
}

int main(int argc, char **argv)
@@ -354,14 +356,12 @@ int main(int argc, char **argv)
case -1:
goto done;
case '?':
- help();
- exit(2);
+ help(2);
case 'e':
features &= ~(1ULL << VIRTIO_RING_F_EVENT_IDX);
break;
case 'h':
- help();
- goto done;
+ help(0);
case 'i':
features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
break;
--
2.39.1



2023-03-09 08:50:17

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [PATCH v2] tools/virtio: virtio_test -h,--help should return directly

On Thu, Mar 09, 2023 at 04:42:50PM +0800, Rong Tao wrote:
>From: Rong Tao <[email protected]>
>
>When we get help information, we should return directly, and we should not
>execute test cases. Move the exit() directly into the help() function and
>remove it from case '?'.
>
>Signed-off-by: Rong Tao <[email protected]>
>---
>v2: help(): exit with a value different from 0 (e.g. 2).
>v1: https://lore.kernel.org/lkml/[email protected]/
>---
> tools/virtio/virtio_test.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
>diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
>index 120062f94590..33e17307441f 100644
>--- a/tools/virtio/virtio_test.c
>+++ b/tools/virtio/virtio_test.c
>@@ -327,7 +327,7 @@ const struct option longopts[] = {
> }
> };
>
>-static void help(void)
>+static void help(int status)
> {
> fprintf(stderr, "Usage: virtio_test [--help]"
> " [--no-indirect]"
>@@ -337,6 +337,8 @@ static void help(void)
> " [--batch=random/N]"
> " [--reset=N]"
> "\n");
>+
>+ exit(status);

Sorry, I meant you can put exit(2) here, and remove the `int status`
parameter of help().

> }
>
> int main(int argc, char **argv)
>@@ -354,14 +356,12 @@ int main(int argc, char **argv)
> case -1:
> goto done;
> case '?':
>- help();
>- exit(2);
>+ help(2);

Here you can use help()

> case 'e':
> features &= ~(1ULL << VIRTIO_RING_F_EVENT_IDX);
> break;
> case 'h':
>- help();
>- goto done;
>+ help(0);

And also here you can use help()

I'm sure you're learning the process, so as a suggestion for the future,
if some thing is not clear, better to ask before sending another
version.

Thanks,
Stefano

> case 'i':
> features &= ~(1ULL <<
> VIRTIO_RING_F_INDIRECT_DESC);
> break;
>--
>2.39.1
>


2023-03-09 09:03:35

by Rong Tao

[permalink] [raw]
Subject: Re: [PATCH] tools/virtio: virtio_test -h,--help should return directly

Hi, Stefano.

I'm wondering, does '-h,--help' help() should 'exit(0)'? Is '-h' considered
a successful run and returns '0'.

Best wishes,
Rong

2023-03-09 09:10:34

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [PATCH] tools/virtio: virtio_test -h,--help should return directly

On Thu, Mar 09, 2023 at 04:56:09PM +0800, Rong Tao wrote:
>Hi, Stefano.
>
>I'm wondering, does '-h,--help' help() should 'exit(0)'? Is '-h' considered
>a successful run and returns '0'.

You're right.
I thought -h would return an error, but that's not the case, so I guess
this patch is fine!

Thanks,
Stefano

>
>Best wishes,
>Rong
>


2023-03-09 09:10:49

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [PATCH v2] tools/virtio: virtio_test -h,--help should return directly

On Thu, Mar 09, 2023 at 04:42:50PM +0800, Rong Tao wrote:
>From: Rong Tao <[email protected]>
>
>When we get help information, we should return directly, and we should not
>execute test cases. Move the exit() directly into the help() function and
>remove it from case '?'.
>
>Signed-off-by: Rong Tao <[email protected]>
>---
>v2: help(): exit with a value different from 0 (e.g. 2).
>v1: https://lore.kernel.org/lkml/[email protected]/
>---
> tools/virtio/virtio_test.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)

Acked-by: Stefano Garzarella <[email protected]>