diff options
author | Andrea Righi <arighi@develer.com> | 2010-08-19 17:13:30 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-20 12:34:54 -0400 |
commit | a25effa4d265eb5028c7d4a92a0ddd9267c3c43d (patch) | |
tree | 207c392483a80d7b21fdb92289c5c1b3e49c961a /samples/kfifo/bytestream-example.c | |
parent | d83a71c4219191a9a881318ae5ca9b39aa1d0540 (diff) |
kfifo: add explicit error checking in all the examples
Provide a check in all the kfifo examples to validate the correct
execution of each testcase.
Signed-off-by: Andrea Righi <arighi@develer.com>
Acked-by: Stefani Seibold <stefani@seibold.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'samples/kfifo/bytestream-example.c')
-rw-r--r-- | samples/kfifo/bytestream-example.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c index a94e6948b30d..178061e87ffe 100644 --- a/samples/kfifo/bytestream-example.c +++ b/samples/kfifo/bytestream-example.c | |||
@@ -44,7 +44,7 @@ static struct kfifo test; | |||
44 | static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE); | 44 | static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE); |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | static unsigned char expected_result[FIFO_SIZE] = { | 47 | static const unsigned char expected_result[FIFO_SIZE] = { |
48 | 3, 4, 5, 6, 7, 8, 9, 0, | 48 | 3, 4, 5, 6, 7, 8, 9, 0, |
49 | 1, 20, 21, 22, 23, 24, 25, 26, | 49 | 1, 20, 21, 22, 23, 24, 25, 26, |
50 | 27, 28, 29, 30, 31, 32, 33, 34, | 50 | 27, 28, 29, 30, 31, 32, 33, 34, |
@@ -90,9 +90,14 @@ static int __init testfunc(void) | |||
90 | 90 | ||
91 | printk(KERN_INFO "queue len: %u\n", kfifo_len(&test)); | 91 | printk(KERN_INFO "queue len: %u\n", kfifo_len(&test)); |
92 | 92 | ||
93 | /* show the first value without removing from the fifo */ | ||
94 | if (kfifo_peek(&test, &i)) | ||
95 | printk(KERN_INFO "%d\n", i); | ||
96 | |||
93 | /* check the correctness of all values in the fifo */ | 97 | /* check the correctness of all values in the fifo */ |
94 | j = 0; | 98 | j = 0; |
95 | while (kfifo_get(&test, &i)) { | 99 | while (kfifo_get(&test, &i)) { |
100 | printk(KERN_INFO "item = %d\n", i); | ||
96 | if (i != expected_result[j++]) { | 101 | if (i != expected_result[j++]) { |
97 | printk(KERN_WARNING "value mismatch: test failed\n"); | 102 | printk(KERN_WARNING "value mismatch: test failed\n"); |
98 | return -EIO; | 103 | return -EIO; |