diff mbox series

[for,3.1,3/4] virtio-net-test: accept variable length argument in pci_test_start()

Message ID 20181129031230.31082-4-jasowang@redhat.com
State New
Headers show
Series Fix possible OOB during queuing packets | expand

Commit Message

Jason Wang Nov. 29, 2018, 3:12 a.m. UTC
This allows flexibility to be reused for all kinds of command line
used by other tests.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 tests/virtio-net-test.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Thomas Huth Nov. 29, 2018, 6:16 a.m. UTC | #1
On 2018-11-29 04:12, Jason Wang wrote:
> This allows flexibility to be reused for all kinds of command line
> used by other tests.
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  tests/virtio-net-test.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
> index 231e7c767e..33d26ab079 100644
> --- a/tests/virtio-net-test.c
> +++ b/tests/virtio-net-test.c
> @@ -51,17 +51,20 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
>      return dev;
>  }
>  
> -static QOSState *pci_test_start(int socket)
> +static QOSState *pci_test_start(const char *cmd, ...)
>  {
>      QOSState *qs;
> +    va_list ap;
>      const char *arch = qtest_get_arch();
> -    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
> -                      "virtio-net-pci,netdev=hs0";
>  
>      if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
> -        qs = qtest_pc_boot(cmd, socket);
> +        va_start(ap, cmd);
> +        qs = qtest_pc_vboot(cmd, ap);
> +        va_end(ap);
>      } else if (strcmp(arch, "ppc64") == 0) {
> -        qs = qtest_spapr_boot(cmd, socket);
> +        va_start(ap, cmd);
> +        qs = qtest_spapr_vboot(cmd, ap);
> +        va_end(ap);
>      } else {
>          g_printerr("virtio-net tests are only available on x86 or ppc64\n");
>          exit(EXIT_FAILURE);
> @@ -218,11 +221,13 @@ static void pci_basic(gconstpointer data)
>                    QVirtQueue *tvq,
>                    int socket) = data;
>      int sv[2], ret;
> +    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
> +                      "virtio-net-pci,netdev=hs0";
>  
>      ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
>      g_assert_cmpint(ret, !=, -1);
>  
> -    qs = pci_test_start(sv[1]);
> +    qs = pci_test_start(cmd, sv[1]);
>      dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT);
>  
>      rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>
Eric Blake Nov. 30, 2018, 3:02 p.m. UTC | #2
On 11/28/18 9:12 PM, Jason Wang wrote:
> This allows flexibility to be reused for all kinds of command line
> used by other tests.
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>   tests/virtio-net-test.c | 17 +++++++++++------
>   1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
> index 231e7c767e..33d26ab079 100644
> --- a/tests/virtio-net-test.c
> +++ b/tests/virtio-net-test.c
> @@ -51,17 +51,20 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
>       return dev;
>   }
>   
> -static QOSState *pci_test_start(int socket)
> +static QOSState *pci_test_start(const char *cmd, ...)

This should probably be tagged with GCC_FMT_ATTR(1, 2).


> @@ -218,11 +221,13 @@ static void pci_basic(gconstpointer data)
>                     QVirtQueue *tvq,
>                     int socket) = data;
>       int sv[2], ret;
> +    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
> +                      "virtio-net-pci,netdev=hs0";
>   
>       ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
>       g_assert_cmpint(ret, !=, -1);
>   
> -    qs = pci_test_start(sv[1]);
> +    qs = pci_test_start(cmd, sv[1]);

Do you really need an intermediate 'cmd' variable, or can you just 
inline the string constant command at the point of the call? 
-Wformat=non-literal may warn if you don't inline.
Jason Wang Dec. 3, 2018, 10:08 a.m. UTC | #3
On 2018/11/30 下午11:02, Eric Blake wrote:
> On 11/28/18 9:12 PM, Jason Wang wrote:
>> This allows flexibility to be reused for all kinds of command line
>> used by other tests.
>>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>>   tests/virtio-net-test.c | 17 +++++++++++------
>>   1 file changed, 11 insertions(+), 6 deletions(-)
>>
>> diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
>> index 231e7c767e..33d26ab079 100644
>> --- a/tests/virtio-net-test.c
>> +++ b/tests/virtio-net-test.c
>> @@ -51,17 +51,20 @@ static QVirtioPCIDevice 
>> *virtio_net_pci_init(QPCIBus *bus, int slot)
>>       return dev;
>>   }
>>   -static QOSState *pci_test_start(int socket)
>> +static QOSState *pci_test_start(const char *cmd, ...)
>
> This should probably be tagged with GCC_FMT_ATTR(1, 2).


Ok.


>
>
>> @@ -218,11 +221,13 @@ static void pci_basic(gconstpointer data)
>>                     QVirtQueue *tvq,
>>                     int socket) = data;
>>       int sv[2], ret;
>> +    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
>> +                      "virtio-net-pci,netdev=hs0";
>>         ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
>>       g_assert_cmpint(ret, !=, -1);
>>   -    qs = pci_test_start(sv[1]);
>> +    qs = pci_test_start(cmd, sv[1]);
>
> Do you really need an intermediate 'cmd' variable, or can you just 
> inline the string constant command at the point of the call? 
> -Wformat=non-literal may warn if you don't inline.
>

Fixed and post V4.

Thanks
diff mbox series

Patch

diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 231e7c767e..33d26ab079 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -51,17 +51,20 @@  static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
     return dev;
 }
 
-static QOSState *pci_test_start(int socket)
+static QOSState *pci_test_start(const char *cmd, ...)
 {
     QOSState *qs;
+    va_list ap;
     const char *arch = qtest_get_arch();
-    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
-                      "virtio-net-pci,netdev=hs0";
 
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        qs = qtest_pc_boot(cmd, socket);
+        va_start(ap, cmd);
+        qs = qtest_pc_vboot(cmd, ap);
+        va_end(ap);
     } else if (strcmp(arch, "ppc64") == 0) {
-        qs = qtest_spapr_boot(cmd, socket);
+        va_start(ap, cmd);
+        qs = qtest_spapr_vboot(cmd, ap);
+        va_end(ap);
     } else {
         g_printerr("virtio-net tests are only available on x86 or ppc64\n");
         exit(EXIT_FAILURE);
@@ -218,11 +221,13 @@  static void pci_basic(gconstpointer data)
                   QVirtQueue *tvq,
                   int socket) = data;
     int sv[2], ret;
+    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
+                      "virtio-net-pci,netdev=hs0";
 
     ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
     g_assert_cmpint(ret, !=, -1);
 
-    qs = pci_test_start(sv[1]);
+    qs = pci_test_start(cmd, sv[1]);
     dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT);
 
     rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);