Commit 9da2150f authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

[PATCH] usbtest: report errors in iso tests

This patch (as693b) makes the usbtest driver report errors in the
isochronous bulk transfer tests instead of always returning 0.  As an
arbitrary cutoff, an error is returned if more than 10% of the packet
transfers fail.  It also stops a test immediately upon receiving an URB
submission error.

For a test harness, it's especially important to report when errors occur!
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 0ae4ea80
...@@ -1337,7 +1337,9 @@ struct iso_context { ...@@ -1337,7 +1337,9 @@ struct iso_context {
unsigned pending; unsigned pending;
spinlock_t lock; spinlock_t lock;
struct completion done; struct completion done;
int submit_error;
unsigned long errors; unsigned long errors;
unsigned long packet_count;
struct usbtest_dev *dev; struct usbtest_dev *dev;
}; };
...@@ -1348,10 +1350,14 @@ static void iso_callback (struct urb *urb, struct pt_regs *regs) ...@@ -1348,10 +1350,14 @@ static void iso_callback (struct urb *urb, struct pt_regs *regs)
spin_lock(&ctx->lock); spin_lock(&ctx->lock);
ctx->count--; ctx->count--;
ctx->packet_count += urb->number_of_packets;
if (urb->error_count > 0) if (urb->error_count > 0)
ctx->errors += urb->error_count; ctx->errors += urb->error_count;
else if (urb->status != 0)
ctx->errors += urb->number_of_packets;
if (urb->status == 0 && ctx->count > (ctx->pending - 1)) { if (urb->status == 0 && ctx->count > (ctx->pending - 1)
&& !ctx->submit_error) {
int status = usb_submit_urb (urb, GFP_ATOMIC); int status = usb_submit_urb (urb, GFP_ATOMIC);
switch (status) { switch (status) {
case 0: case 0:
...@@ -1362,6 +1368,8 @@ static void iso_callback (struct urb *urb, struct pt_regs *regs) ...@@ -1362,6 +1368,8 @@ static void iso_callback (struct urb *urb, struct pt_regs *regs)
status); status);
/* FALLTHROUGH */ /* FALLTHROUGH */
case -ENODEV: /* disconnected */ case -ENODEV: /* disconnected */
case -ESHUTDOWN: /* endpoint disabled */
ctx->submit_error = 1;
break; break;
} }
} }
...@@ -1371,8 +1379,8 @@ static void iso_callback (struct urb *urb, struct pt_regs *regs) ...@@ -1371,8 +1379,8 @@ static void iso_callback (struct urb *urb, struct pt_regs *regs)
if (ctx->pending == 0) { if (ctx->pending == 0) {
if (ctx->errors) if (ctx->errors)
dev_dbg (&ctx->dev->intf->dev, dev_dbg (&ctx->dev->intf->dev,
"iso test, %lu errors\n", "iso test, %lu errors out of %lu\n",
ctx->errors); ctx->errors, ctx->packet_count);
complete (&ctx->done); complete (&ctx->done);
} }
done: done:
...@@ -1433,15 +1441,14 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param, ...@@ -1433,15 +1441,14 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
struct usb_device *udev; struct usb_device *udev;
unsigned i; unsigned i;
unsigned long packets = 0; unsigned long packets = 0;
int status; int status = 0;
struct urb *urbs[10]; /* FIXME no limit */ struct urb *urbs[10]; /* FIXME no limit */
if (param->sglen > 10) if (param->sglen > 10)
return -EDOM; return -EDOM;
memset(&context, 0, sizeof context);
context.count = param->iterations * param->sglen; context.count = param->iterations * param->sglen;
context.pending = param->sglen;
context.errors = 0;
context.dev = dev; context.dev = dev;
init_completion (&context.done); init_completion (&context.done);
spin_lock_init (&context.lock); spin_lock_init (&context.lock);
...@@ -1473,6 +1480,7 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param, ...@@ -1473,6 +1480,7 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
spin_lock_irq (&context.lock); spin_lock_irq (&context.lock);
for (i = 0; i < param->sglen; i++) { for (i = 0; i < param->sglen; i++) {
++context.pending;
status = usb_submit_urb (urbs [i], SLAB_ATOMIC); status = usb_submit_urb (urbs [i], SLAB_ATOMIC);
if (status < 0) { if (status < 0) {
ERROR (dev, "submit iso[%d], error %d\n", i, status); ERROR (dev, "submit iso[%d], error %d\n", i, status);
...@@ -1483,12 +1491,26 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param, ...@@ -1483,12 +1491,26 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
simple_free_urb (urbs [i]); simple_free_urb (urbs [i]);
context.pending--; context.pending--;
context.submit_error = 1;
break;
} }
} }
spin_unlock_irq (&context.lock); spin_unlock_irq (&context.lock);
wait_for_completion (&context.done); wait_for_completion (&context.done);
return 0;
/*
* Isochronous transfers are expected to fail sometimes. As an
* arbitrary limit, we will report an error if any submissions
* fail or if the transfer failure rate is > 10%.
*/
if (status != 0)
;
else if (context.submit_error)
status = -EACCES;
else if (context.errors > context.packet_count / 10)
status = -EIO;
return status;
fail: fail:
for (i = 0; i < param->sglen; i++) { for (i = 0; i < param->sglen; i++) {
......
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