aboutsummaryrefslogtreecommitdiffstats
path: root/examples/custom-class/commandline/set-led.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/custom-class/commandline/set-led.c')
-rw-r--r--examples/custom-class/commandline/set-led.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/examples/custom-class/commandline/set-led.c b/examples/custom-class/commandline/set-led.c
index 07ba094..807adac 100644
--- a/examples/custom-class/commandline/set-led.c
+++ b/examples/custom-class/commandline/set-led.c
@@ -33,6 +33,9 @@ static void usage(char *name)
fprintf(stderr, " %s on ....... turn on LED\n", name);
fprintf(stderr, " %s off ...... turn off LED\n", name);
fprintf(stderr, " %s status ... ask current status of LED\n", name);
+#if HAVE_TEST
+ fprintf(stderr, " %s test ..... run driver reliability test\n", name);
+#endif
}
int main(int argc, char **argv)
@@ -40,7 +43,7 @@ int main(int argc, char **argv)
usb_dev_handle *handle = NULL;
const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
-char buffer[1];
+char buffer[4];
int cnt, vid, pid, isOn;
usb_init();
@@ -75,6 +78,35 @@ int cnt, vid, pid, isOn;
if(cnt < 0){
fprintf(stderr, "USB error: %s\n", usb_strerror());
}
+#if HAVE_TEST
+ }else if(strcasecmp(argv[1], "test") == 0){
+ int i;
+ srandomdev();
+ for(i = 0; i < 5000; i++){
+ int value = random() & 0xffff, index = random() & 0xffff;
+ int rxValue, rxIndex;
+ if((i+1) % 100 == 0){
+ fprintf(stderr, "\r%04d", i+1);
+ fflush(stderr);
+ }
+ cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_ECHO, value, index, buffer, sizeof(buffer), 5000);
+ if(cnt < 0){
+ fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
+ break;
+ }else if(cnt != 4){
+ fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of 4\n", i, cnt);
+ break;
+ }
+ rxValue = ((int)buffer[0] & 0xff) | (((int)buffer[1] & 0xff) << 8);
+ rxIndex = ((int)buffer[2] & 0xff) | (((int)buffer[3] & 0xff) << 8);
+ if(rxValue != value || rxIndex != index){
+ fprintf(stderr, "\ndata error in iteration %d:\n", i);
+ fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, value);
+ fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, index);
+ }
+ }
+ fprintf(stderr, "\nTest completed.\n");
+#endif
}else{
usage(argv[0]);
exit(1);