* [PATCH] tools/virtio: virtio_test -h,--help should return directly
@ 2023-02-24 14:30 Rong Tao
2023-03-08 14:17 ` Stefano Garzarella
0 siblings, 1 reply; 7+ messages in thread
From: Rong Tao @ 2023-02-24 14:30 UTC (permalink / raw)
To: mst
Cc: Rong Tao, Jason Wang, open list:VIRTIO CORE AND NET DRIVERS, open list
From: Rong Tao <rongtao@cestc.cn>
When we get help information, we should return directly, and we should not
execute test cases. At the same time, the code indentation issue was fixed
and virtio-trace/trace-agent was added to .gitignore.
Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
tools/virtio/.gitignore | 1 +
tools/virtio/virtio_test.c | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/virtio/.gitignore b/tools/virtio/.gitignore
index 075588c4da08..9934d48d9a55 100644
--- a/tools/virtio/.gitignore
+++ b/tools/virtio/.gitignore
@@ -2,3 +2,4 @@
*.d
virtio_test
vringh_test
+virtio-trace/trace-agent
diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
index 120062f94590..6370cdada396 100644
--- a/tools/virtio/virtio_test.c
+++ b/tools/virtio/virtio_test.c
@@ -134,7 +134,7 @@ static void vdev_info_init(struct vdev_info* dev, unsigned long long features)
dev->buf_size = 1024;
dev->buf = malloc(dev->buf_size);
assert(dev->buf);
- dev->control = open("/dev/vhost-test", O_RDWR);
+ dev->control = open("/dev/vhost-test", O_RDWR);
assert(dev->control >= 0);
r = ioctl(dev->control, VHOST_SET_OWNER, NULL);
assert(r >= 0);
@@ -142,7 +142,7 @@ static void vdev_info_init(struct vdev_info* dev, unsigned long long features)
sizeof dev->mem->regions[0]);
assert(dev->mem);
memset(dev->mem, 0, offsetof(struct vhost_memory, regions) +
- sizeof dev->mem->regions[0]);
+ sizeof dev->mem->regions[0]);
dev->mem->nregions = 1;
dev->mem->regions[0].guest_phys_addr = (long)dev->buf;
dev->mem->regions[0].userspace_addr = (long)dev->buf;
@@ -361,7 +361,7 @@ int main(int argc, char **argv)
break;
case 'h':
help();
- goto done;
+ exit(0);
case 'i':
features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
break;
--
2.39.2
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] tools/virtio: virtio_test -h,--help should return directly
2023-02-24 14:30 [PATCH] tools/virtio: virtio_test -h,--help should return directly Rong Tao
@ 2023-03-08 14:17 ` Stefano Garzarella
2023-03-09 6:17 ` Rong Tao
0 siblings, 1 reply; 7+ messages in thread
From: Stefano Garzarella @ 2023-03-08 14:17 UTC (permalink / raw)
To: Rong Tao
Cc: mst, Rong Tao, Jason Wang, open list:VIRTIO CORE AND NET DRIVERS,
open list
On Fri, Feb 24, 2023 at 10:30:30PM +0800, Rong Tao wrote:
>From: Rong Tao <rongtao@cestc.cn>
>
>When we get help information, we should return directly, and we should not
>execute test cases. At the same time, the code indentation issue was fixed
>and virtio-trace/trace-agent was added to .gitignore.
Thanks for this cleanup, but you mentioned 3 independent things that
this patch does, so it would be better to split it into 3 separate
patches.
>
>Signed-off-by: Rong Tao <rongtao@cestc.cn>
>---
> tools/virtio/.gitignore | 1 +
> tools/virtio/virtio_test.c | 6 +++---
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
>diff --git a/tools/virtio/.gitignore b/tools/virtio/.gitignore
>index 075588c4da08..9934d48d9a55 100644
>--- a/tools/virtio/.gitignore
>+++ b/tools/virtio/.gitignore
>@@ -2,3 +2,4 @@
> *.d
> virtio_test
> vringh_test
>+virtio-trace/trace-agent
>diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
>index 120062f94590..6370cdada396 100644
>--- a/tools/virtio/virtio_test.c
>+++ b/tools/virtio/virtio_test.c
>@@ -134,7 +134,7 @@ static void vdev_info_init(struct vdev_info* dev, unsigned long long features)
> dev->buf_size = 1024;
> dev->buf = malloc(dev->buf_size);
> assert(dev->buf);
>- dev->control = open("/dev/vhost-test", O_RDWR);
>+ dev->control = open("/dev/vhost-test", O_RDWR);
> assert(dev->control >= 0);
> r = ioctl(dev->control, VHOST_SET_OWNER, NULL);
> assert(r >= 0);
>@@ -142,7 +142,7 @@ static void vdev_info_init(struct vdev_info* dev, unsigned long long features)
> sizeof dev->mem->regions[0]);
> assert(dev->mem);
> memset(dev->mem, 0, offsetof(struct vhost_memory, regions) +
>- sizeof dev->mem->regions[0]);
>+ sizeof dev->mem->regions[0]);
This did not seem to me to be an indentation issue, there are 2 tabs and
1 space to line it up with the opening of the parenthesis of the line
above.
> dev->mem->nregions = 1;
> dev->mem->regions[0].guest_phys_addr = (long)dev->buf;
> dev->mem->regions[0].userspace_addr = (long)dev->buf;
>@@ -361,7 +361,7 @@ int main(int argc, char **argv)
> break;
> case 'h':
> help();
>- goto done;
>+ exit(0);
Maybe we can move the exit() directly into the help() function and
remove it from case '?'.
I would return a value different from 0 (like in the case '?').
Thanks,
Stefano
> case 'i':
> features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
> break;
>--
>2.39.2
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] tools/virtio: virtio_test -h,--help should return directly
@ 2023-03-09 6:13 Rong Tao
2023-03-09 8:31 ` Stefano Garzarella
0 siblings, 1 reply; 7+ messages in thread
From: Rong Tao @ 2023-03-09 6:13 UTC (permalink / raw)
To: sgarzare, mst
Cc: Rong Tao, Jason Wang, open list:VIRTIO CORE AND NET DRIVERS, open list
From: Rong Tao <rongtao@cestc.cn>
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 <rongtao@cestc.cn>
---
tools/virtio/virtio_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
index 120062f94590..6e348fbdc5d8 100644
--- a/tools/virtio/virtio_test.c
+++ b/tools/virtio/virtio_test.c
@@ -337,6 +337,8 @@ static void help(void)
" [--batch=random/N]"
" [--reset=N]"
"\n");
+
+ exit(0);
}
int main(int argc, char **argv)
@@ -354,14 +356,12 @@ int main(int argc, char **argv)
case -1:
goto done;
case '?':
- help();
exit(2);
case 'e':
features &= ~(1ULL << VIRTIO_RING_F_EVENT_IDX);
break;
case 'h':
help();
- goto done;
case 'i':
features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
break;
--
2.39.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] tools/virtio: virtio_test -h,--help should return directly
2023-03-09 6:13 Rong Tao
@ 2023-03-09 8:31 ` Stefano Garzarella
0 siblings, 0 replies; 7+ messages in thread
From: Stefano Garzarella @ 2023-03-09 8:31 UTC (permalink / raw)
To: Rong Tao
Cc: mst, Rong Tao, Jason Wang, open list:VIRTIO CORE AND NET DRIVERS,
open list
On Thu, Mar 09, 2023 at 02:13:13PM +0800, Rong Tao wrote:
>From: Rong Tao <rongtao@cestc.cn>
>
>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 <rongtao@cestc.cn>
>---
> tools/virtio/virtio_test.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
>index 120062f94590..6e348fbdc5d8 100644
>--- a/tools/virtio/virtio_test.c
>+++ b/tools/virtio/virtio_test.c
>@@ -337,6 +337,8 @@ static void help(void)
> " [--batch=random/N]"
> " [--reset=N]"
> "\n");
>+
>+ exit(0);
Please exit with a value different from 0 (e.g. 2).
> }
>
> int main(int argc, char **argv)
>@@ -354,14 +356,12 @@ int main(int argc, char **argv)
> case -1:
> goto done;
> case '?':
>- help();
> exit(2);
Sorry, I meant the opposite, remove exit(2) and leave help().
Thanks,
Stefano
> case 'e':
> features &= ~(1ULL << VIRTIO_RING_F_EVENT_IDX);
> break;
> case 'h':
> help();
>- goto done;
> case 'i':
> features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
> break;
>--
>2.39.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] tools/virtio: virtio_test -h,--help should return directly
@ 2023-03-09 8:49 Stefano Garzarella
2023-03-09 8:56 ` [PATCH] " Rong Tao
0 siblings, 1 reply; 7+ messages in thread
From: Stefano Garzarella @ 2023-03-09 8:49 UTC (permalink / raw)
To: Rong Tao
Cc: Rong Tao, Michael S. Tsirkin, Jason Wang,
open list:VIRTIO CORE AND NET DRIVERS, open list
On Thu, Mar 09, 2023 at 04:42:50PM +0800, Rong Tao wrote:
>From: Rong Tao <rongtao@cestc.cn>
>
>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 <rongtao@cestc.cn>
>---
>v2: help(): exit with a value different from 0 (e.g. 2).
>v1: https://lore.kernel.org/lkml/tencent_4B5122C4158323A1D1ACA04B3295F1579207@qq.com/
>---
> 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
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] tools/virtio: virtio_test -h,--help should return directly
2023-03-09 8:49 [PATCH v2] " Stefano Garzarella
@ 2023-03-09 8:56 ` Rong Tao
2023-03-09 9:08 ` Stefano Garzarella
0 siblings, 1 reply; 7+ messages in thread
From: Rong Tao @ 2023-03-09 8:56 UTC (permalink / raw)
To: sgarzare; +Cc: jasowang, linux-kernel, mst, rongtao, rtoax, virtualization
Hi, Stefano.
I'm wondering, does '-h,--help' help() should 'exit(0)'? Is '-h' considered
a successful run and returns '0'.
Best wishes,
Rong
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] tools/virtio: virtio_test -h,--help should return directly
2023-03-09 8:56 ` [PATCH] " Rong Tao
@ 2023-03-09 9:08 ` Stefano Garzarella
0 siblings, 0 replies; 7+ messages in thread
From: Stefano Garzarella @ 2023-03-09 9:08 UTC (permalink / raw)
To: Rong Tao; +Cc: jasowang, linux-kernel, mst, rongtao, virtualization
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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-03-09 9:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 14:30 [PATCH] tools/virtio: virtio_test -h,--help should return directly Rong Tao
2023-03-08 14:17 ` Stefano Garzarella
2023-03-09 6:17 ` Rong Tao
2023-03-09 6:13 Rong Tao
2023-03-09 8:31 ` Stefano Garzarella
2023-03-09 8:49 [PATCH v2] " Stefano Garzarella
2023-03-09 8:56 ` [PATCH] " Rong Tao
2023-03-09 9:08 ` Stefano Garzarella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®