Commit 2aaf2092 authored by Andrea Righi's avatar Andrea Righi Committed by Linus Torvalds

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: default avatarAndrea Righi <arighi@develer.com>
Cc: Stefani Seibold <stefani@seibold.net>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5ddf8391
...@@ -44,10 +44,17 @@ static struct kfifo test; ...@@ -44,10 +44,17 @@ static struct kfifo test;
static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE); static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE);
#endif #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) static int __init testfunc(void)
{ {
unsigned char buf[6]; unsigned char buf[6];
unsigned char i; unsigned char i, j;
unsigned int ret; unsigned int ret;
printk(KERN_INFO "byte stream fifo test start\n"); printk(KERN_INFO "byte stream fifo test start\n");
...@@ -83,10 +90,19 @@ static int __init testfunc(void) ...@@ -83,10 +90,19 @@ static int __init testfunc(void)
printk(KERN_INFO "queue len: %u\n", kfifo_len(&test)); printk(KERN_INFO "queue len: %u\n", kfifo_len(&test));
/* print out all values in the fifo */ /* check the correctness of all values in the fifo */
while (kfifo_get(&test, &i)) j = 0;
printk("%d ", i); while (kfifo_get(&test, &i)) {
printk("\n"); 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; return 0;
} }
...@@ -142,7 +158,12 @@ static int __init example_init(void) ...@@ -142,7 +158,12 @@ static int __init example_init(void)
#else #else
INIT_KFIFO(test); INIT_KFIFO(test);
#endif #endif
testfunc(); if (testfunc() < 0) {
#ifdef DYNAMIC
kfifo_free(&test);
#endif
return -EIO;
}
if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) {
#ifdef DYNAMIC #ifdef DYNAMIC
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment