Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kfifo: add explicit error checking in byte stream example

Provide a static array of expected items that kfifo should contain at the
end of the test to validate it.

Signed-off-by: Andrea Righi <arighi@develer.com>
Cc: Stefani Seibold <stefani@seibold.net>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andrea Righi and committed by
Linus Torvalds
2aaf2092 5ddf8391

+27 -6
+27 -6
samples/kfifo/bytestream-example.c
··· 44 44 static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE); 45 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 54 static int __init testfunc(void) 48 55 { 49 56 unsigned char buf[6]; 50 - unsigned char i; 57 + unsigned char i, j; 51 58 unsigned int ret; 52 59 53 60 printk(KERN_INFO "byte stream fifo test start\n"); ··· 90 83 91 84 printk(KERN_INFO "queue len: %u\n", kfifo_len(&test)); 92 85 93 - /* print out all values in the fifo */ 94 - while (kfifo_get(&test, &i)) 95 - printk("%d ", i); 96 - printk("\n"); 86 + /* check the correctness of all values in the fifo */ 87 + j = 0; 88 + while (kfifo_get(&test, &i)) { 89 + if (i != expected_result[j++]) { 90 + printk(KERN_WARNING "value mismatch: test failed\n"); 91 + return -EIO; 92 + } 93 + } 94 + if (j != ARRAY_SIZE(expected_result)) { 95 + printk(KERN_WARNING "size mismatch: test failed\n"); 96 + return -EIO; 97 + } 98 + printk(KERN_INFO "test passed\n"); 97 99 98 100 return 0; 99 101 } ··· 158 142 #else 159 143 INIT_KFIFO(test); 160 144 #endif 161 - testfunc(); 145 + if (testfunc() < 0) { 146 + #ifdef DYNAMIC 147 + kfifo_free(&test); 148 + #endif 149 + return -EIO; 150 + } 162 151 163 152 if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { 164 153 #ifdef DYNAMIC