From ad74ff9682d9b430596c913b18ca937b8b6dae70 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Thu, 19 Aug 2010 14:13:29 -0700 Subject: [PATCH] --- yaml --- r: 209671 b: refs/heads/master c: 2aaf2092c168fc02df0645415f524b357ee7ec2e h: refs/heads/master i: 209669: 91348d470eec4f08ff1505abeccbad326ad7b7e1 209667: aa18855a6242daf86a517afe0331b233e3aa2c02 209663: 715826f480c9f00e542488fab23b393d17be0634 v: v3 --- [refs] | 2 +- trunk/samples/kfifo/bytestream-example.c | 33 +++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/[refs] b/[refs] index 7d92efd44b98..f845295e0ced 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 5ddf83912c8b49a24ab0841f6d77f33781dcf10f +refs/heads/master: 2aaf2092c168fc02df0645415f524b357ee7ec2e diff --git a/trunk/samples/kfifo/bytestream-example.c b/trunk/samples/kfifo/bytestream-example.c index 2e3a7a8128a2..a94e6948b30d 100644 --- a/trunk/samples/kfifo/bytestream-example.c +++ b/trunk/samples/kfifo/bytestream-example.c @@ -44,10 +44,17 @@ static struct kfifo test; static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE); #endif +static unsigned char expected_result[FIFO_SIZE] = { + 3, 4, 5, 6, 7, 8, 9, 0, + 1, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, +}; + static int __init testfunc(void) { unsigned char buf[6]; - unsigned char i; + unsigned char i, j; unsigned int ret; printk(KERN_INFO "byte stream fifo test start\n"); @@ -83,10 +90,19 @@ static int __init testfunc(void) printk(KERN_INFO "queue len: %u\n", kfifo_len(&test)); - /* print out all values in the fifo */ - while (kfifo_get(&test, &i)) - printk("%d ", i); - printk("\n"); + /* check the correctness of all values in the fifo */ + j = 0; + while (kfifo_get(&test, &i)) { + if (i != expected_result[j++]) { + printk(KERN_WARNING "value mismatch: test failed\n"); + return -EIO; + } + } + if (j != ARRAY_SIZE(expected_result)) { + printk(KERN_WARNING "size mismatch: test failed\n"); + return -EIO; + } + printk(KERN_INFO "test passed\n"); return 0; } @@ -142,7 +158,12 @@ static int __init example_init(void) #else INIT_KFIFO(test); #endif - testfunc(); + if (testfunc() < 0) { +#ifdef DYNAMIC + kfifo_free(&test); +#endif + return -EIO; + } if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { #ifdef DYNAMIC