Commit 7add78b2 authored by Eugenio Pérez's avatar Eugenio Pérez Committed by Michael S. Tsirkin

tools/virtio: Add --batch=random option

So we can test with non-deterministic batches in flight.
Signed-off-by: default avatarEugenio Pérez <eperezma@redhat.com>
Link: https://lore.kernel.org/r/20200418102217.32327-4-eperezma@redhat.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 633fae33
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <linux/virtio_ring.h> #include <linux/virtio_ring.h>
#include "../../drivers/vhost/test.h" #include "../../drivers/vhost/test.h"
#define RANDOM_BATCH -1
/* Unused */ /* Unused */
void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end; void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
...@@ -161,6 +163,7 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq, ...@@ -161,6 +163,7 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq,
int r, test = 1; int r, test = 1;
unsigned len; unsigned len;
long long spurious = 0; long long spurious = 0;
const bool random_batch = batch == RANDOM_BATCH;
r = ioctl(dev->control, VHOST_TEST_RUN, &test); r = ioctl(dev->control, VHOST_TEST_RUN, &test);
assert(r >= 0); assert(r >= 0);
for (;;) { for (;;) {
...@@ -168,6 +171,9 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq, ...@@ -168,6 +171,9 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq,
completed_before = completed; completed_before = completed;
started_before = started; started_before = started;
do { do {
if (random_batch)
batch = (random() % vq->vring.num) + 1;
while (started < bufs && while (started < bufs &&
(started - completed) < batch) { (started - completed) < batch) {
sg_init_one(&sl, dev->buf, dev->buf_size); sg_init_one(&sl, dev->buf, dev->buf_size);
...@@ -275,7 +281,7 @@ static void help(void) ...@@ -275,7 +281,7 @@ static void help(void)
" [--no-event-idx]" " [--no-event-idx]"
" [--no-virtio-1]" " [--no-virtio-1]"
" [--delayed-interrupt]" " [--delayed-interrupt]"
" [--batch=N]" " [--batch=random/N]"
"\n"); "\n");
} }
...@@ -312,9 +318,13 @@ int main(int argc, char **argv) ...@@ -312,9 +318,13 @@ int main(int argc, char **argv)
delayed = true; delayed = true;
break; break;
case 'b': case 'b':
batch = strtol(optarg, NULL, 10); if (0 == strcmp(optarg, "random")) {
assert(batch > 0); batch = RANDOM_BATCH;
assert(batch < (long)INT_MAX + 1); } else {
batch = strtol(optarg, NULL, 10);
assert(batch > 0);
assert(batch < (long)INT_MAX + 1);
}
break; break;
default: default:
assert(0); assert(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment