diff options
Diffstat (limited to 'samples')
-rw-r--r-- | samples/kfifo/bytestream-example.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c index 2e3a7a8128a2..a94e6948b30d 100644 --- a/samples/kfifo/bytestream-example.c +++ b/samples/kfifo/bytestream-example.c | |||
@@ -44,10 +44,17 @@ 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] = { | ||
48 | 3, 4, 5, 6, 7, 8, 9, 0, | ||
49 | 1, 20, 21, 22, 23, 24, 25, 26, | ||
50 | 27, 28, 29, 30, 31, 32, 33, 34, | ||
51 | 35, 36, 37, 38, 39, 40, 41, 42, | ||
52 | }; | ||
53 | |||
47 | static int __init testfunc(void) | 54 | static int __init testfunc(void) |
48 | { | 55 | { |
49 | unsigned char buf[6]; | 56 | unsigned char buf[6]; |
50 | unsigned char i; | 57 | unsigned char i, j; |
51 | unsigned int ret; | 58 | unsigned int ret; |
52 | 59 | ||
53 | printk(KERN_INFO "byte stream fifo test start\n"); | 60 | printk(KERN_INFO "byte stream fifo test start\n"); |
@@ -83,10 +90,19 @@ static int __init testfunc(void) | |||
83 | 90 | ||
84 | printk(KERN_INFO "queue len: %u\n", kfifo_len(&test)); | 91 | printk(KERN_INFO "queue len: %u\n", kfifo_len(&test)); |
85 | 92 | ||
86 | /* print out all values in the fifo */ | 93 | /* check the correctness of all values in the fifo */ |
87 | while (kfifo_get(&test, &i)) | 94 | j = 0; |
88 | printk("%d ", i); | 95 | while (kfifo_get(&test, &i)) { |
89 | printk("\n"); | 96 | if (i != expected_result[j++]) { |
97 | printk(KERN_WARNING "value mismatch: test failed\n"); | ||
98 | return -EIO; | ||
99 | } | ||
100 | } | ||
101 | if (j != ARRAY_SIZE(expected_result)) { | ||
102 | printk(KERN_WARNING "size mismatch: test failed\n"); | ||
103 | return -EIO; | ||
104 | } | ||
105 | printk(KERN_INFO "test passed\n"); | ||
90 | 106 | ||
91 | return 0; | 107 | return 0; |
92 | } | 108 | } |
@@ -142,7 +158,12 @@ static int __init example_init(void) | |||
142 | #else | 158 | #else |
143 | INIT_KFIFO(test); | 159 | INIT_KFIFO(test); |
144 | #endif | 160 | #endif |
145 | testfunc(); | 161 | if (testfunc() < 0) { |
162 | #ifdef DYNAMIC | ||
163 | kfifo_free(&test); | ||
164 | #endif | ||
165 | return -EIO; | ||
166 | } | ||
146 | 167 | ||
147 | if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { | 168 | if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { |
148 | #ifdef DYNAMIC | 169 | #ifdef DYNAMIC |