diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2010-10-12 11:27:20 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2010-10-12 11:27:28 -0400 |
| commit | 37eca0d64a2dbeece25969ec0698e1ff72bdcf39 (patch) | |
| tree | 54ba70f0428f586f4fe28d8b429b9f9e0799a17a /samples/kfifo/record-example.c | |
| parent | 277b199800ac90811ac86d215063df1984f51619 (diff) | |
| parent | 3c06806e690885ce978ef180c8f8b6f8c17fb4b4 (diff) | |
Merge branch 'linus' into core/locking
Reason: Pull in the semaphore related changes
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'samples/kfifo/record-example.c')
| -rw-r--r-- | samples/kfifo/record-example.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c index 32c6e0bda744..e68bd16a5da4 100644 --- a/samples/kfifo/record-example.c +++ b/samples/kfifo/record-example.c | |||
| @@ -55,6 +55,19 @@ typedef STRUCT_KFIFO_REC_1(FIFO_SIZE) mytest; | |||
| 55 | static mytest test; | 55 | static mytest test; |
| 56 | #endif | 56 | #endif |
| 57 | 57 | ||
| 58 | static const char *expected_result[] = { | ||
| 59 | "a", | ||
| 60 | "bb", | ||
| 61 | "ccc", | ||
| 62 | "dddd", | ||
| 63 | "eeeee", | ||
| 64 | "ffffff", | ||
| 65 | "ggggggg", | ||
| 66 | "hhhhhhhh", | ||
| 67 | "iiiiiiiii", | ||
| 68 | "jjjjjjjjjj", | ||
| 69 | }; | ||
| 70 | |||
| 58 | static int __init testfunc(void) | 71 | static int __init testfunc(void) |
| 59 | { | 72 | { |
| 60 | char buf[100]; | 73 | char buf[100]; |
| @@ -75,6 +88,10 @@ static int __init testfunc(void) | |||
| 75 | kfifo_in(&test, buf, i + 1); | 88 | kfifo_in(&test, buf, i + 1); |
| 76 | } | 89 | } |
| 77 | 90 | ||
| 91 | /* skip first element of the fifo */ | ||
| 92 | printk(KERN_INFO "skip 1st element\n"); | ||
| 93 | kfifo_skip(&test); | ||
| 94 | |||
| 78 | printk(KERN_INFO "fifo len: %u\n", kfifo_len(&test)); | 95 | printk(KERN_INFO "fifo len: %u\n", kfifo_len(&test)); |
| 79 | 96 | ||
| 80 | /* show the first record without removing from the fifo */ | 97 | /* show the first record without removing from the fifo */ |
| @@ -82,11 +99,22 @@ static int __init testfunc(void) | |||
| 82 | if (ret) | 99 | if (ret) |
| 83 | printk(KERN_INFO "%.*s\n", ret, buf); | 100 | printk(KERN_INFO "%.*s\n", ret, buf); |
| 84 | 101 | ||
| 85 | /* print out all records in the fifo */ | 102 | /* check the correctness of all values in the fifo */ |
| 103 | i = 0; | ||
| 86 | while (!kfifo_is_empty(&test)) { | 104 | while (!kfifo_is_empty(&test)) { |
| 87 | ret = kfifo_out(&test, buf, sizeof(buf)); | 105 | ret = kfifo_out(&test, buf, sizeof(buf)); |
| 88 | printk(KERN_INFO "%.*s\n", ret, buf); | 106 | buf[ret] = '\0'; |
| 107 | printk(KERN_INFO "item = %.*s\n", ret, buf); | ||
| 108 | if (strcmp(buf, expected_result[i++])) { | ||
| 109 | printk(KERN_WARNING "value mismatch: test failed\n"); | ||
| 110 | return -EIO; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | if (i != ARRAY_SIZE(expected_result)) { | ||
| 114 | printk(KERN_WARNING "size mismatch: test failed\n"); | ||
| 115 | return -EIO; | ||
| 89 | } | 116 | } |
| 117 | printk(KERN_INFO "test passed\n"); | ||
| 90 | 118 | ||
| 91 | return 0; | 119 | return 0; |
| 92 | } | 120 | } |
| @@ -142,7 +170,12 @@ static int __init example_init(void) | |||
| 142 | #else | 170 | #else |
| 143 | INIT_KFIFO(test); | 171 | INIT_KFIFO(test); |
| 144 | #endif | 172 | #endif |
| 145 | testfunc(); | 173 | if (testfunc() < 0) { |
| 174 | #ifdef DYNAMIC | ||
| 175 | kfifo_free(&test); | ||
| 176 | #endif | ||
| 177 | return -EIO; | ||
| 178 | } | ||
| 146 | 179 | ||
| 147 | if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { | 180 | if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { |
| 148 | #ifdef DYNAMIC | 181 | #ifdef DYNAMIC |
