update copyright date to 2013
[dpdk.git] / app / test / test_cmdline_cirbuf.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include <rte_string_fns.h>
40
41 #include <cmdline_cirbuf.h>
42
43 #include "test_cmdline.h"
44
45 /* different length strings */
46 #define CIRBUF_STR_HEAD " HEAD"
47 #define CIRBUF_STR_TAIL "TAIL"
48
49 /* miscelaneous tests - they make bullseye happy */
50 static int
51 test_cirbuf_string_misc(void)
52 {
53         struct cirbuf cb;
54         char buf[CMDLINE_TEST_BUFSIZE];
55         char tmp[CMDLINE_TEST_BUFSIZE];
56
57         /* initialize buffers */
58         memset(buf, 0, sizeof(buf));
59         memset(tmp, 0, sizeof(tmp));
60
61         /*
62          * initialize circular buffer
63          */
64         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
65                 printf("Error: failed to initialize circular buffer!\n");
66                 return -1;
67         }
68
69         /*
70          * add strings to head and tail, but read only tail
71          * this results in read operation that does not transcend
72          * from buffer end to buffer beginning (in other words,
73          * strlen <= cb->maxlen - cb->end)
74          */
75
76         /* add string to head */
77         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
78                         != (sizeof(CIRBUF_STR_HEAD))) {
79                 printf("Error: failed to add string to head!\n");
80                 return -1;
81         }
82         /* add string to tail */
83         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
84                         != (sizeof(CIRBUF_STR_TAIL))) {
85                 printf("Error: failed to add string to head!\n");
86                 return -1;
87         }
88         /* read string from tail */
89         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_TAIL))
90                         != (sizeof(CIRBUF_STR_TAIL))) {
91                 printf("Error: failed to get string from tail!\n");
92                 return -1;
93         }
94         /* verify string */
95         if (strncmp(tmp, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL)) != 0) {
96                 printf("Error: tail strings do not match!\n");
97                 return -1;
98         }
99         /* clear buffers */
100         memset(tmp, 0, sizeof(tmp));
101         memset(buf, 0, sizeof(buf));
102
103
104
105         /*
106          * add a string to buffer when start/end is at end of buffer
107          */
108
109         /*
110          * reinitialize circular buffer with start at the end of cirbuf
111          */
112         if (cirbuf_init(&cb, buf, CMDLINE_TEST_BUFSIZE - 2, sizeof(buf)) < 0) {
113                 printf("Error: failed to reinitialize circular buffer!\n");
114                 return -1;
115         }
116
117
118         /* add string to tail */
119         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
120                         != (sizeof(CIRBUF_STR_TAIL))) {
121                 printf("Error: failed to add string to tail!\n");
122                 return -1;
123         }
124         /* read string from tail */
125         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_TAIL))
126                         != (sizeof(CIRBUF_STR_TAIL))) {
127                 printf("Error: failed to get string from tail!\n");
128                 return -1;
129         }
130         /* verify string */
131         if (strncmp(tmp, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL)) != 0) {
132                 printf("Error: tail strings do not match!\n");
133                 return -1;
134         }
135         /* clear tmp buffer */
136         memset(tmp, 0, sizeof(tmp));
137
138
139         /* add string to head */
140         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
141                         != (sizeof(CIRBUF_STR_HEAD))) {
142                 printf("Error: failed to add string to head!\n");
143                 return -1;
144         }
145         /* read string from tail */
146         if (cirbuf_get_buf_head(&cb, tmp, sizeof(CIRBUF_STR_HEAD))
147                         != (sizeof(CIRBUF_STR_HEAD))) {
148                 printf("Error: failed to get string from head!\n");
149                 return -1;
150         }
151         /* verify string */
152         if (strncmp(tmp, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD)) != 0) {
153                 printf("Error: headstrings do not match!\n");
154                 return -1;
155         }
156
157         return 0;
158 }
159
160 /* test adding and deleting strings */
161 static int
162 test_cirbuf_string_add_del(void)
163 {
164         struct cirbuf cb;
165         char buf[CMDLINE_TEST_BUFSIZE];
166         char tmp[CMDLINE_TEST_BUFSIZE];
167
168         /* initialize buffers */
169         memset(buf, 0, sizeof(buf));
170         memset(tmp, 0, sizeof(tmp));
171
172         /*
173          * initialize circular buffer
174          */
175         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
176                 printf("Error: failed to initialize circular buffer!\n");
177                 return -1;
178         }
179
180         /* add string to head */
181         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
182                         != (sizeof(CIRBUF_STR_HEAD))) {
183                 printf("Error: failed to add string to head!\n");
184                 return -1;
185         }
186         /* read string from head */
187         if (cirbuf_get_buf_head(&cb, tmp, sizeof(CIRBUF_STR_HEAD))
188                         != (sizeof(CIRBUF_STR_HEAD))) {
189                 printf("Error: failed to get string from head!\n");
190                 return -1;
191         }
192         /* verify string */
193         if (strncmp(tmp, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD)) != 0) {
194                 printf("Error: head strings do not match!\n");
195                 return -1;
196         }
197         /* clear tmp buffer */
198         memset(tmp, 0, sizeof(tmp));
199         /* read string from tail */
200         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_HEAD))
201                         != (sizeof(CIRBUF_STR_HEAD))) {
202                 printf("Error: failed to get string from head!\n");
203                 return -1;
204         }
205         /* verify string */
206         if (strncmp(tmp, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD)) != 0) {
207                 printf("Error: head strings do not match!\n");
208                 return -1;
209         }
210         /* delete string from head*/
211         if (cirbuf_del_buf_head(&cb, sizeof(CIRBUF_STR_HEAD)) < 0) {
212                 printf("Error: failed to delete string from head!\n");
213                 return -1;
214         }
215         /* verify string was deleted */
216         if (cirbuf_del_head_safe(&cb) == 0) {
217                 printf("Error: buffer should have been empty!\n");
218                 return -1;
219         }
220         /* clear tmp buffer */
221         memset(tmp, 0, sizeof(tmp));
222
223
224
225         /*
226          * reinitialize circular buffer
227          */
228         memset(buf, 0, sizeof(buf));
229         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
230                 printf("Error: failed to reinitialize circular buffer!\n");
231                 return -1;
232         }
233
234         /* add string to tail */
235         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
236                         != (sizeof(CIRBUF_STR_TAIL))) {
237                 printf("Error: failed to add string to tail!\n");
238                 return -1;
239         }
240         /* get string from tail */
241         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_TAIL))
242                         != (sizeof(CIRBUF_STR_TAIL))) {
243                 printf("Error: failed to get string from tail!\n");
244                 return -1;
245         }
246         /* verify string */
247         if (strncmp(tmp, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL)) != 0) {
248                 printf("Error: tail strings do not match!\n");
249                 return -1;
250         }
251         /* clear tmp buffer */
252         memset(tmp, 0, sizeof(tmp));
253         /* get string from head */
254         if (cirbuf_get_buf_head(&cb, tmp, sizeof(CIRBUF_STR_TAIL))
255                         != (sizeof(CIRBUF_STR_TAIL))) {
256                 printf("Error: failed to get string from tail!\n");
257                 return -1;
258         }
259         /* verify string */
260         if (strncmp(tmp, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL)) != 0) {
261                 printf("Error: tail strings do not match!\n");
262                 return -1;
263         }
264         /* delete string from tail */
265         if (cirbuf_del_buf_tail(&cb, sizeof(CIRBUF_STR_TAIL)) < 0) {
266                 printf("Error: failed to delete string from tail!\n");
267                 return -1;
268         }
269         /* verify string was deleted */
270         if (cirbuf_del_tail_safe(&cb) == 0) {
271                 printf("Error: buffer should have been empty!\n");
272                 return -1;
273         }
274
275         return 0;
276 }
277
278 /* test adding from head and deleting from tail, and vice versa */
279 static int
280 test_cirbuf_string_add_del_reverse(void)
281 {
282         struct cirbuf cb;
283         char buf[CMDLINE_TEST_BUFSIZE];
284         char tmp[CMDLINE_TEST_BUFSIZE];
285
286         /* initialize buffers */
287         memset(buf, 0, sizeof(buf));
288         memset(tmp, 0, sizeof(tmp));
289
290         /*
291          * initialize circular buffer
292          */
293         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
294                 printf("Error: failed to initialize circular buffer!\n");
295                 return -1;
296         }
297
298         /* add string to head */
299         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
300                         != (sizeof(CIRBUF_STR_HEAD))) {
301                 printf("Error: failed to add string to head!\n");
302                 return -1;
303         }
304         /* delete string from tail */
305         if (cirbuf_del_buf_tail(&cb, sizeof(CIRBUF_STR_HEAD)) < 0) {
306                 printf("Error: failed to delete string from tail!\n");
307                 return -1;
308         }
309         /* verify string was deleted */
310         if (cirbuf_del_tail_safe(&cb) == 0) {
311                 printf("Error: buffer should have been empty!\n");
312                 return -1;
313         }
314         /* clear tmp buffer */
315         memset(tmp, 0, sizeof(tmp));
316
317         /*
318          * reinitialize circular buffer
319          */
320         memset(buf, 0, sizeof(buf));
321         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
322                 printf("Error: failed to reinitialize circular buffer!\n");
323                 return -1;
324         }
325
326         /* add string to tail */
327         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
328                         != (sizeof(CIRBUF_STR_TAIL))) {
329                 printf("Error: failed to add string to tail!\n");
330                 return -1;
331         }
332         /* delete string from head */
333         if (cirbuf_del_buf_head(&cb, sizeof(CIRBUF_STR_TAIL)) < 0) {
334                 printf("Error: failed to delete string from head!\n");
335                 return -1;
336         }
337         /* verify string was deleted */
338         if (cirbuf_del_head_safe(&cb) == 0) {
339                 printf("Error: buffer should have been empty!\n");
340                 return -1;
341         }
342
343         return 0;
344 }
345
346 /* try to write more than available */
347 static int
348 test_cirbuf_string_add_boundaries(void)
349 {
350         struct cirbuf cb;
351         char buf[CMDLINE_TEST_BUFSIZE];
352         unsigned i;
353
354         /* initialize buffers */
355         memset(buf, 0, sizeof(buf));
356
357         /*
358          * initialize circular buffer
359          */
360         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
361                 printf("Error: failed to initialize circular buffer!\n");
362                 return -1;
363         }
364
365         /* fill the buffer from tail */
366         for (i = 0; i < CMDLINE_TEST_BUFSIZE - sizeof(CIRBUF_STR_TAIL) + 1; i++)
367                 cirbuf_add_tail_safe(&cb, 't');
368
369         /* try adding a string to tail */
370         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
371                         > 0) {
372                 printf("Error: buffer should have been full!\n");
373                 return -1;
374         }
375         /* try adding a string to head */
376         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
377                         > 0) {
378                 printf("Error: buffer should have been full!\n");
379                 return -1;
380         }
381
382         /*
383          * reinitialize circular buffer
384          */
385         memset(buf, 0, sizeof(buf));
386         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
387                 printf("Error: failed to reinitialize circular buffer!\n");
388                 return -1;
389         }
390
391         /* fill the buffer from head */
392         for (i = 0; i < CMDLINE_TEST_BUFSIZE - sizeof(CIRBUF_STR_HEAD) + 1; i++)
393                 cirbuf_add_head_safe(&cb, 'h');
394
395         /* try adding a string to head */
396         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
397                         > 0) {
398                 printf("Error: buffer should have been full!\n");
399                 return -1;
400         }
401         /* try adding a string to tail */
402         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
403                         > 0) {
404                 printf("Error: buffer should have been full!\n");
405                 return -1;
406         }
407
408         return 0;
409 }
410
411 /* try to read/delete more than written */
412 static int
413 test_cirbuf_string_get_del_boundaries(void)
414 {
415         struct cirbuf cb;
416         char buf[CMDLINE_TEST_BUFSIZE];
417         char tmp[CMDLINE_TEST_BUFSIZE];
418
419         /* initialize buffers */
420         memset(buf, 0, sizeof(buf));
421         memset(tmp, 0, sizeof(tmp));
422
423         /*
424          * initialize circular buffer
425          */
426         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
427                 printf("Error: failed to initialize circular buffer!\n");
428                 return -1;
429         }
430
431
432         /* add string to head */
433         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
434                                 != (sizeof(CIRBUF_STR_HEAD))) {
435                 printf("Error: failed to add string to head!\n");
436                 return -1;
437         }
438         /* read more than written (head) */
439         if (cirbuf_get_buf_head(&cb, tmp, sizeof(CIRBUF_STR_HEAD) + 1)
440                         != sizeof(CIRBUF_STR_HEAD)) {
441                 printf("Error: unexpected result when reading too much data!\n");
442                 return -1;
443         }
444         /* read more than written (tail) */
445         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_HEAD) + 1)
446                         != sizeof(CIRBUF_STR_HEAD)) {
447                 printf("Error: unexpected result when reading too much data!\n");
448                 return -1;
449         }
450         /* delete more than written (head) */
451         if (cirbuf_del_buf_head(&cb, sizeof(CIRBUF_STR_HEAD) + 1) == 0) {
452                 printf("Error: unexpected result when deleting too much data!\n");
453                 return -1;
454         }
455         /* delete more than written (tail) */
456         if (cirbuf_del_buf_tail(&cb, sizeof(CIRBUF_STR_HEAD) + 1) == 0) {
457                 printf("Error: unexpected result when deleting too much data!\n");
458                 return -1;
459         }
460
461         /*
462          * reinitialize circular buffer
463          */
464         memset(buf, 0, sizeof(buf));
465         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
466                 printf("Error: failed to reinitialize circular buffer!\n");
467                 return -1;
468         }
469
470         /* add string to tail */
471         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
472                                 != (sizeof(CIRBUF_STR_TAIL))) {
473                 printf("Error: failed to add string to tail!\n");
474                 return -1;
475         }
476         /* read more than written (tail) */
477         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_TAIL) + 1)
478                         != sizeof(CIRBUF_STR_TAIL)) {
479                 printf("Error: unexpected result when reading too much data!\n");
480                 return -1;
481         }
482         /* read more than written (head) */
483         if (cirbuf_get_buf_head(&cb, tmp, sizeof(CIRBUF_STR_TAIL) + 1)
484                         != sizeof(CIRBUF_STR_TAIL)) {
485                 printf("Error: unexpected result when reading too much data!\n");
486                 return -1;
487         }
488         /* delete more than written (tail) */
489         if (cirbuf_del_buf_tail(&cb, sizeof(CIRBUF_STR_TAIL) + 1) == 0) {
490                 printf("Error: unexpected result when deleting too much data!\n");
491                 return -1;
492         }
493         /* delete more than written (head) */
494         if (cirbuf_del_buf_tail(&cb, sizeof(CIRBUF_STR_TAIL) + 1) == 0) {
495                 printf("Error: unexpected result when deleting too much data!\n");
496                 return -1;
497         }
498
499         return 0;
500 }
501
502 /* try to read/delete less than written */
503 static int
504 test_cirbuf_string_get_del_partial(void)
505 {
506         struct cirbuf cb;
507         char buf[CMDLINE_TEST_BUFSIZE];
508         char tmp[CMDLINE_TEST_BUFSIZE];
509         char tmp2[CMDLINE_TEST_BUFSIZE];
510
511         /* initialize buffers */
512         memset(buf, 0, sizeof(buf));
513         memset(tmp, 0, sizeof(tmp));
514         memset(tmp2, 0, sizeof(tmp));
515
516         rte_snprintf(tmp2, sizeof(tmp2), "%s", CIRBUF_STR_HEAD);
517
518         /*
519          * initialize circular buffer
520          */
521         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
522                 printf("Error: failed to initialize circular buffer!\n");
523                 return -1;
524         }
525
526         /* add string to head */
527         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
528                                 != (sizeof(CIRBUF_STR_HEAD))) {
529                 printf("Error: failed to add string to head!\n");
530                 return -1;
531         }
532         /* read less than written (head) */
533         if (cirbuf_get_buf_head(&cb, tmp, sizeof(CIRBUF_STR_HEAD) - 1)
534                         != sizeof(CIRBUF_STR_HEAD) - 1) {
535                 printf("Error: unexpected result when reading from head!\n");
536                 return -1;
537         }
538         /* verify string */
539         if (strncmp(tmp, tmp2, sizeof(CIRBUF_STR_HEAD) - 1) != 0) {
540                 printf("Error: strings mismatch!\n");
541                 return -1;
542         }
543         memset(tmp, 0, sizeof(tmp));
544         /* read less than written (tail) */
545         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_HEAD) - 1)
546                         != sizeof(CIRBUF_STR_HEAD) - 1) {
547                 printf("Error: unexpected result when reading from tail!\n");
548                 return -1;
549         }
550         /* verify string */
551         if (strncmp(tmp, &tmp2[1], sizeof(CIRBUF_STR_HEAD) - 1) != 0) {
552                 printf("Error: strings mismatch!\n");
553                 return -1;
554         }
555
556         /*
557          * verify correct deletion
558          */
559
560         /* clear buffer */
561         memset(tmp, 0, sizeof(tmp));
562
563         /* delete less than written (head) */
564         if (cirbuf_del_buf_head(&cb, 1) != 0) {
565                 printf("Error: delete from head failed!\n");
566                 return -1;
567         }
568         /* read from head */
569         if (cirbuf_get_buf_head(&cb, tmp, sizeof(CIRBUF_STR_HEAD) - 1)
570                         != sizeof(CIRBUF_STR_HEAD) - 1) {
571                 printf("Error: unexpected result when reading from head!\n");
572                 return -1;
573         }
574         /* since we deleted from head, first char should be deleted */
575         if (strncmp(tmp, &tmp2[1], sizeof(CIRBUF_STR_HEAD) - 1) != 0) {
576                 printf("Error: strings mismatch!\n");
577                 return -1;
578         }
579         /* clear buffer */
580         memset(tmp, 0, sizeof(tmp));
581
582         /* delete less than written (tail) */
583         if (cirbuf_del_buf_tail(&cb, 1) != 0) {
584                 printf("Error: delete from tail failed!\n");
585                 return -1;
586         }
587         /* read from tail */
588         if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_HEAD) - 2)
589                         != sizeof(CIRBUF_STR_HEAD) - 2) {
590                 printf("Error: unexpected result when reading from head!\n");
591                 return -1;
592         }
593         /* since we deleted from tail, last char should be deleted */
594         if (strncmp(tmp, &tmp2[1], sizeof(CIRBUF_STR_HEAD) - 2) != 0) {
595                 printf("Error: strings mismatch!\n");
596                 return -1;
597         }
598
599         return 0;
600 }
601
602 /* test cmdline_cirbuf char add/del functions */
603 static int
604 test_cirbuf_char_add_del(void)
605 {
606         struct cirbuf cb;
607         char buf[CMDLINE_TEST_BUFSIZE];
608         char tmp[CMDLINE_TEST_BUFSIZE];
609
610         /* clear buffer */
611         memset(buf, 0, sizeof(buf));
612         memset(tmp, 0, sizeof(tmp));
613
614         /*
615          * initialize circular buffer
616          */
617         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
618                 printf("Error: failed to initialize circular buffer!\n");
619                 return -1;
620         }
621
622         /*
623          * try to delete something from cirbuf. since it's empty,
624          * these should fail.
625          */
626         if (cirbuf_del_head_safe(&cb) == 0) {
627                 printf("Error: deleting from empty cirbuf head succeeded!\n");
628                 return -1;
629         }
630         if (cirbuf_del_tail_safe(&cb) == 0) {
631                 printf("Error: deleting from empty cirbuf tail succeeded!\n");
632                 return -1;
633         }
634
635         /*
636          * add, verify and delete. these should pass.
637          */
638         if (cirbuf_add_head_safe(&cb,'h') < 0) {
639                 printf("Error: adding to cirbuf head failed!\n");
640                 return -1;
641         }
642         if (cirbuf_get_head(&cb) != 'h') {
643                 printf("Error: wrong head content!\n");
644                 return -1;
645         }
646         if (cirbuf_del_head_safe(&cb) < 0) {
647                 printf("Error: deleting from cirbuf head failed!\n");
648                 return -1;
649         }
650         if (cirbuf_add_tail_safe(&cb,'t') < 0) {
651                 printf("Error: adding to cirbuf tail failed!\n");
652                 return -1;
653         }
654         if (cirbuf_get_tail(&cb) != 't') {
655                 printf("Error: wrong tail content!\n");
656                 return -1;
657         }
658         if (cirbuf_del_tail_safe(&cb) < 0) {
659                 printf("Error: deleting from cirbuf tail failed!\n");
660                 return -1;
661         }
662         /* do the same for unsafe versions. those are void. */
663         cirbuf_add_head(&cb,'h');
664         if (cirbuf_get_head(&cb) != 'h') {
665                 printf("Error: wrong head content!\n");
666                 return -1;
667         }
668         cirbuf_del_head(&cb);
669
670         /* test if char has been deleted. we can't call cirbuf_get_head
671          * because it's unsafe, but we can call cirbuf_get_buf_head.
672          */
673         if (cirbuf_get_buf_head(&cb, tmp, 1) > 0) {
674                 printf("Error: buffer should have been empty!\n");
675                 return -1;
676         }
677
678         cirbuf_add_tail(&cb,'t');
679         if (cirbuf_get_tail(&cb) != 't') {
680                 printf("Error: wrong tail content!\n");
681                 return -1;
682         }
683         cirbuf_del_tail(&cb);
684
685         /* test if char has been deleted. we can't call cirbuf_get_tail
686          * because it's unsafe, but we can call cirbuf_get_buf_tail.
687          */
688         if (cirbuf_get_buf_tail(&cb, tmp, 1) > 0) {
689                 printf("Error: buffer should have been empty!\n");
690                 return -1;
691         }
692
693         return 0;
694 }
695
696 /* test filling up buffer with chars */
697 static int
698 test_cirbuf_char_fill(void)
699 {
700         struct cirbuf cb;
701         char buf[CMDLINE_TEST_BUFSIZE];
702         unsigned i;
703
704         /* clear buffer */
705         memset(buf, 0, sizeof(buf));
706
707         /*
708          * initialize circular buffer
709          */
710         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
711                 printf("Error: failed to initialize circular buffer!\n");
712                 return -1;
713         }
714
715         /*
716          * fill the buffer from head or tail, verify contents, test boundaries
717          * and clear the buffer
718          */
719
720         /* fill the buffer from tail */
721         for (i = 0; i < CMDLINE_TEST_BUFSIZE; i++)
722                 cirbuf_add_tail_safe(&cb, 't');
723         /* verify that contents of the buffer are what they are supposed to be */
724         for (i = 0; i < sizeof(buf); i++) {
725                 if (buf[i] != 't') {
726                         printf("Error: wrong content in buffer!\n");
727                         return -1;
728                 }
729         }
730         /* try to add to a full buffer from tail */
731         if (cirbuf_add_tail_safe(&cb, 't') == 0) {
732                 printf("Error: buffer should have been full!\n");
733                 return -1;
734         }
735         /* try to add to a full buffer from head */
736         if (cirbuf_add_head_safe(&cb, 'h') == 0) {
737                 printf("Error: buffer should have been full!\n");
738                 return -1;
739         }
740         /* delete buffer from tail */
741         for(i = 0; i < CMDLINE_TEST_BUFSIZE; i++)
742                 cirbuf_del_tail_safe(&cb);
743         /* try to delete from an empty buffer */
744         if (cirbuf_del_tail_safe(&cb) >= 0) {
745                 printf("Error: buffer should have been empty!\n");
746                 return -1;
747         }
748
749         /* fill the buffer from head */
750         for (i = 0; i < CMDLINE_TEST_BUFSIZE; i++)
751                 cirbuf_add_head_safe(&cb, 'h');
752         /* verify that contents of the buffer are what they are supposed to be */
753         for (i = 0; i < sizeof(buf); i++) {
754                 if (buf[i] != 'h') {
755                         printf("Error: wrong content in buffer!\n");
756                         return -1;
757                 }
758         }
759         /* try to add to a full buffer from head */
760         if (cirbuf_add_head_safe(&cb,'h') >= 0) {
761                 printf("Error: buffer should have been full!\n");
762                 return -1;
763         }
764         /* try to add to a full buffer from tail */
765         if (cirbuf_add_tail_safe(&cb, 't') == 0) {
766                 printf("Error: buffer should have been full!\n");
767                 return -1;
768         }
769         /* delete buffer from head */
770         for(i = 0; i < CMDLINE_TEST_BUFSIZE; i++)
771                 cirbuf_del_head_safe(&cb);
772         /* try to delete from an empty buffer */
773         if (cirbuf_del_head_safe(&cb) >= 0) {
774                 printf("Error: buffer should have been empty!\n");
775                 return -1;
776         }
777
778         /*
779          * fill the buffer from both head and tail, with alternating characters,
780          * verify contents and clear the buffer
781          */
782
783         /* fill half of buffer from tail */
784         for (i = 0; i < CMDLINE_TEST_BUFSIZE / 2; i++)
785                 cirbuf_add_tail_safe(&cb, (char) (i % 2 ? 't' : 'T'));
786         /* fill other half of the buffer from head */
787         for (i = 0; i < CMDLINE_TEST_BUFSIZE / 2; i++)
788                 cirbuf_add_head_safe(&cb, (char) (i % 2 ? 'H' : 'h')); /* added in reverse */
789
790         /* verify that contents of the buffer are what they are supposed to be */
791         for (i = 0; i < sizeof(buf) / 2; i++) {
792                 if (buf[i] != (char) (i % 2 ? 't' : 'T')) {
793                         printf("Error: wrong content in buffer at %u!\n", i);
794                         return -1;
795                 }
796         }
797         for (i = sizeof(buf) / 2; i < sizeof(buf); i++) {
798                 if (buf[i] != (char) (i % 2 ? 'h' : 'H')) {
799                         printf("Error: wrong content in buffer %u!\n", i);
800                         return -1;
801                 }
802         }
803
804         return 0;
805 }
806
807 /* test left alignment */
808 static int
809 test_cirbuf_align_left(void)
810 {
811 #define HALF_OFFSET CMDLINE_TEST_BUFSIZE / 2
812 #define SMALL_OFFSET HALF_OFFSET / 2
813 /* resulting buffer lengths for each of the test cases */
814 #define LEN1 HALF_OFFSET - SMALL_OFFSET - 1
815 #define LEN2 HALF_OFFSET + SMALL_OFFSET + 2
816 #define LEN3 HALF_OFFSET - SMALL_OFFSET
817 #define LEN4 HALF_OFFSET + SMALL_OFFSET - 1
818
819         struct cirbuf cb;
820         char buf[CMDLINE_TEST_BUFSIZE];
821         char tmp[CMDLINE_TEST_BUFSIZE];
822         unsigned i;
823
824         /*
825          * align left when start < end and start in left half
826          */
827
828         /*
829          * initialize circular buffer
830          */
831         memset(buf, 0, sizeof(buf));
832         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
833                 printf("Error: failed to initialize circular buffer!\n");
834                 return -1;
835         }
836
837         /* push end into left half */
838         for (i = 0; i < HALF_OFFSET - 1; i++)
839                 cirbuf_add_tail_safe(&cb, 't');
840
841         /* push start into left half < end */
842         for (i = 0; i < SMALL_OFFSET; i++)
843                 cirbuf_del_head_safe(&cb);
844
845         /* align */
846         if (cirbuf_align_left(&cb) < 0) {
847                 printf("Error: alignment failed!\n");
848                 return -1;
849         }
850
851         /* verify result */
852         if (cb.start != 0 || cb.len != LEN1 || cb.end != cb.len - 1) {
853                 printf("Error: buffer alignment is wrong!\n");
854                 return -1;
855         }
856
857         /*
858          * align left when start > end and start in left half
859          */
860
861         /*
862          * reinitialize circular buffer
863          */
864         memset(buf, 0, sizeof(buf));
865         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
866                 printf("Error: failed to reinitialize circular buffer!\n");
867                 return -1;
868         }
869
870         /* push start into left half */
871         for (i = 0; i < HALF_OFFSET + 2; i++)
872                 cirbuf_add_head_safe(&cb, 'h');
873
874         /* push end into left half > start */
875         for (i = 0; i < SMALL_OFFSET; i++)
876                 cirbuf_add_tail_safe(&cb, 't');
877
878         /* align */
879         if (cirbuf_align_left(&cb) < 0) {
880                 printf("Error: alignment failed!\n");
881                 return -1;
882         }
883
884         /* verify result */
885         if (cb.start != 0 || cb.len != LEN2 || cb.end != cb.len - 1) {
886                 printf("Error: buffer alignment is wrong!");
887                 return -1;
888         }
889
890         /*
891          * align left when start < end and start in right half
892          */
893
894         /*
895          * reinitialize circular buffer
896          */
897         memset(buf, 0, sizeof(buf));
898         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
899                 printf("Error: failed to reinitialize circular buffer!\n");
900                 return -1;
901         }
902
903         /* push start into the right half */
904         for (i = 0; i < HALF_OFFSET; i++)
905                 cirbuf_add_head_safe(&cb, 'h');
906
907         /* push end into left half > start */
908         for (i = 0; i < SMALL_OFFSET; i++)
909                 cirbuf_del_tail_safe(&cb);
910
911         /* align */
912         if (cirbuf_align_left(&cb) < 0) {
913                 printf("Error: alignment failed!\n");
914                 return -1;
915         }
916
917         /* verify result */
918         if (cb.start != 0 || cb.len != LEN3 || cb.end != cb.len - 1) {
919                 printf("Error: buffer alignment is wrong!");
920                 return -1;
921         }
922
923         /*
924          * align left when start > end and start in right half
925          */
926
927         /*
928          * reinitialize circular buffer
929          */
930         memset(buf, 0, sizeof(buf));
931         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
932                 printf("Error: failed to reinitialize circular buffer!\n");
933                 return -1;
934         }
935
936         /* push start into the right half */
937         for (i = 0; i < HALF_OFFSET - 1; i++)
938                 cirbuf_add_head_safe(&cb, 'h');
939
940         /* push end into left half < start */
941         for (i = 0; i < SMALL_OFFSET; i++)
942                 cirbuf_add_tail_safe(&cb, 't');
943
944         /* align */
945         if (cirbuf_align_left(&cb) < 0) {
946                 printf("Error: alignment failed!\n");
947                 return -1;
948         }
949
950         /* verify result */
951         if (cb.start != 0 || cb.len != LEN4 ||
952                         cb.end != cb.len - 1) {
953                 printf("Error: buffer alignment is wrong!");
954                 return -1;
955         }
956
957         /*
958          * Verify that alignment doesn't corrupt data
959          */
960
961         /*
962          * reinitialize circular buffer
963          */
964         memset(buf, 0, sizeof(buf));
965         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
966                 printf("Error: failed to reinitialize circular buffer!\n");
967                 return -1;
968         }
969
970         /* add string to tail and head */
971         if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD,
972                         sizeof(CIRBUF_STR_HEAD)) < 0 || cirbuf_add_buf_tail(&cb,
973                                         CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL)) < 0) {
974                 printf("Error: failed to add strings!\n");
975                 return -1;
976         }
977
978         /* align */
979         if (cirbuf_align_left(&cb) < 0) {
980                 printf("Error: alignment failed!\n");
981                 return -1;
982         }
983
984         /* get string from head */
985         if (cirbuf_get_buf_head(&cb, tmp,
986                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) < 0) {
987                 printf("Error: failed to read string from head!\n");
988                 return -1;
989         }
990
991         /* verify string */
992         if (strncmp(tmp, CIRBUF_STR_HEAD "\0" CIRBUF_STR_TAIL,
993                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) != 0) {
994                 printf("Error: strings mismatch!\n");
995                 return -1;
996         }
997
998         /* reset tmp buffer */
999         memset(tmp, 0, sizeof(tmp));
1000
1001         /* get string from tail */
1002         if (cirbuf_get_buf_tail(&cb, tmp,
1003                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) < 0) {
1004                 printf("Error: failed to read string from head!\n");
1005                 return -1;
1006         }
1007
1008         /* verify string */
1009         if (strncmp(tmp, CIRBUF_STR_HEAD "\0" CIRBUF_STR_TAIL,
1010                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) != 0) {
1011                 printf("Error: strings mismatch!\n");
1012                 return -1;
1013         }
1014
1015         return 0;
1016 }
1017
1018 /* test right alignment */
1019 static int
1020 test_cirbuf_align_right(void)
1021 {
1022 #define END_OFFSET CMDLINE_TEST_BUFSIZE - 1
1023         struct cirbuf cb;
1024         char buf[CMDLINE_TEST_BUFSIZE];
1025         char tmp[CMDLINE_TEST_BUFSIZE];
1026         unsigned i;
1027
1028
1029         /*
1030          * align right when start < end and start in left half
1031          */
1032
1033         /*
1034          * initialize circular buffer
1035          */
1036         memset(buf, 0, sizeof(buf));
1037         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
1038                 printf("Error: failed to initialize circular buffer!\n");
1039                 return -1;
1040         }
1041
1042         /* push end into left half */
1043         for (i = 0; i < HALF_OFFSET - 1; i++)
1044                 cirbuf_add_tail_safe(&cb, 't');
1045
1046         /* push start into left half < end */
1047         for (i = 0; i < SMALL_OFFSET; i++)
1048                 cirbuf_del_head_safe(&cb);
1049
1050         /* align */
1051         cirbuf_align_right(&cb);
1052
1053         /* verify result */
1054         if (cb.start != END_OFFSET || cb.len != LEN1 || cb.end != cb.len - 2) {
1055                 printf("Error: buffer alignment is wrong!\n");
1056                 return -1;
1057         }
1058
1059         /*
1060          * align right when start > end and start in left half
1061          */
1062
1063         /*
1064          * reinitialize circular buffer
1065          */
1066         memset(buf, 0, sizeof(buf));
1067         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
1068                 printf("Error: failed to reinitialize circular buffer!\n");
1069                 return -1;
1070         }
1071
1072         /* push start into left half */
1073         for (i = 0; i < HALF_OFFSET + 2; i++)
1074                 cirbuf_add_head_safe(&cb, 'h');
1075
1076         /* push end into left half > start */
1077         for (i = 0; i < SMALL_OFFSET; i++)
1078                 cirbuf_add_tail_safe(&cb, 't');
1079
1080         /* align */
1081         cirbuf_align_right(&cb);
1082
1083         /* verify result */
1084         if (cb.start != END_OFFSET || cb.len != LEN2 || cb.end != cb.len - 2) {
1085                 printf("Error: buffer alignment is wrong!");
1086                 return -1;
1087         }
1088
1089         /*
1090          * align right when start < end and start in right half
1091          */
1092
1093         /*
1094          * reinitialize circular buffer
1095          */
1096         memset(buf, 0, sizeof(buf));
1097         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
1098                 printf("Error: failed to reinitialize circular buffer!\n");
1099                 return -1;
1100         }
1101
1102         /* push start into the right half */
1103         for (i = 0; i < HALF_OFFSET; i++)
1104                 cirbuf_add_head_safe(&cb, 'h');
1105
1106         /* push end into left half > start */
1107         for (i = 0; i < SMALL_OFFSET; i++)
1108                 cirbuf_del_tail_safe(&cb);
1109
1110         /* align */
1111         cirbuf_align_right(&cb);
1112
1113         /* verify result */
1114         if (cb.end != END_OFFSET || cb.len != LEN3 || cb.start != cb.end - cb.len + 1) {
1115                 printf("Error: buffer alignment is wrong!");
1116                 return -1;
1117         }
1118
1119         /*
1120          * align right when start > end and start in right half
1121          */
1122
1123         /*
1124          * reinitialize circular buffer
1125          */
1126         memset(buf, 0, sizeof(buf));
1127         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
1128                 printf("Error: failed to reinitialize circular buffer!\n");
1129                 return -1;
1130         }
1131
1132         /* push start into the right half */
1133         for (i = 0; i < HALF_OFFSET - 1; i++)
1134                 cirbuf_add_head_safe(&cb, 'h');
1135
1136         /* push end into left half < start */
1137         for (i = 0; i < SMALL_OFFSET; i++)
1138                 cirbuf_add_tail_safe(&cb, 't');
1139
1140         /* align */
1141         cirbuf_align_right(&cb);
1142
1143         /* verify result */
1144         if (cb.end != END_OFFSET || cb.len != LEN4 || cb.start != cb.end - cb.len + 1) {
1145                 printf("Error: buffer alignment is wrong!");
1146                 return -1;
1147         }
1148
1149         /*
1150          * Verify that alignment doesn't corrupt data
1151          */
1152
1153         /*
1154          * reinitialize circular buffer
1155          */
1156         memset(buf, 0, sizeof(buf));
1157         if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
1158                 printf("Error: failed to reinitialize circular buffer!\n");
1159                 return -1;
1160         }
1161
1162         /* add string to tail and head */
1163         if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL,
1164                         sizeof(CIRBUF_STR_TAIL)) < 0 || cirbuf_add_buf_head(&cb,
1165                                         CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD)) < 0) {
1166                 printf("Error: failed to add strings!\n");
1167                 return -1;
1168         }
1169
1170         /* align */
1171         if (cirbuf_align_right(&cb) < 0) {
1172                 printf("Error: alignment failed!\n");
1173                 return -1;
1174         }
1175
1176         /* get string from head */
1177         if (cirbuf_get_buf_head(&cb, tmp,
1178                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) < 0) {
1179                 printf("Error: failed to read string from head!\n");
1180                 return -1;
1181         }
1182
1183         /* verify string */
1184         if (strncmp(tmp, CIRBUF_STR_HEAD "\0" CIRBUF_STR_TAIL,
1185                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) != 0) {
1186                 printf("Error: strings mismatch!\n");
1187                 return -1;
1188         }
1189
1190         /* reset tmp buffer */
1191         memset(tmp, 0, sizeof(tmp));
1192
1193         /* get string from tail */
1194         if (cirbuf_get_buf_tail(&cb, tmp,
1195                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) < 0) {
1196                 printf("Error: failed to read string from head!\n");
1197                 return -1;
1198         }
1199         /* verify string */
1200         if (strncmp(tmp, CIRBUF_STR_HEAD "\0" CIRBUF_STR_TAIL,
1201                         sizeof(CIRBUF_STR_HEAD) + sizeof(CIRBUF_STR_TAIL)) != 0) {
1202                 printf("Error: strings mismatch!\n");
1203                 return -1;
1204         }
1205
1206         return 0;
1207 }
1208
1209 /* call functions with invalid parameters */
1210 int
1211 test_cirbuf_invalid_param(void)
1212 {
1213         struct cirbuf cb;
1214         char buf[CMDLINE_TEST_BUFSIZE];
1215
1216         /* null cirbuf */
1217         if (cirbuf_init(0, buf, 0, sizeof(buf)) == 0)
1218                 return -1;
1219         /* null buffer */
1220         if (cirbuf_init(&cb, 0, 0, sizeof(buf)) == 0)
1221                 return -1;
1222         /* null cirbuf */
1223         if (cirbuf_add_head_safe(0, 'h') == 0)
1224                 return -1;
1225         if (cirbuf_add_tail_safe(0, 't') == 0)
1226                 return -1;
1227         if (cirbuf_del_head_safe(0) == 0)
1228                 return -1;
1229         if (cirbuf_del_tail_safe(0) == 0)
1230                 return -1;
1231         /* null buffer */
1232         if (cirbuf_add_buf_head(&cb, 0, 0) == 0)
1233                 return -1;
1234         if (cirbuf_add_buf_tail(&cb, 0, 0) == 0)
1235                 return -1;
1236         /* null cirbuf */
1237         if (cirbuf_add_buf_head(0, buf, 0) == 0)
1238                 return -1;
1239         if (cirbuf_add_buf_tail(0, buf, 0) == 0)
1240                 return -1;
1241         /* null size */
1242         if (cirbuf_add_buf_head(&cb, buf, 0) == 0)
1243                 return -1;
1244         if (cirbuf_add_buf_tail(&cb, buf, 0) == 0)
1245                 return -1;
1246         /* null cirbuf */
1247         if (cirbuf_del_buf_head(0, 0) == 0)
1248                 return -1;
1249         if (cirbuf_del_buf_tail(0, 0) == 0)
1250                 return -1;
1251         /* null size */
1252         if (cirbuf_del_buf_head(&cb, 0) == 0)
1253                 return -1;
1254         if (cirbuf_del_buf_tail(&cb, 0) == 0)
1255                 return -1;
1256         /* null cirbuf */
1257         if (cirbuf_get_buf_head(0, 0, 0) == 0)
1258                 return -1;
1259         if (cirbuf_get_buf_tail(0, 0, 0) == 0)
1260                 return -1;
1261         /* null buffer */
1262         if (cirbuf_get_buf_head(&cb, 0, 0) == 0)
1263                 return -1;
1264         if (cirbuf_get_buf_tail(&cb, 0, 0) == 0)
1265                 return -1;
1266         /* null size, this is valid but should return 0 */
1267         if (cirbuf_get_buf_head(&cb, buf, 0) != 0)
1268                 return -1;
1269         if (cirbuf_get_buf_tail(&cb, buf, 0) != 0)
1270                 return -1;
1271         /* null cirbuf */
1272         if (cirbuf_align_left(0) == 0)
1273                 return -1;
1274         if (cirbuf_align_right(0) == 0)
1275                 return -1;
1276
1277         return 0;
1278 }
1279
1280 /* test cmdline_cirbuf char functions */
1281 int
1282 test_cirbuf_char(void)
1283 {
1284         int ret;
1285
1286         ret = test_cirbuf_char_add_del();
1287         if (ret < 0)
1288                 return -1;
1289
1290         ret = test_cirbuf_char_fill();
1291         if (ret < 0)
1292                 return -1;
1293
1294         return 0;
1295 }
1296
1297 /* test cmdline_cirbuf string functions */
1298 int
1299 test_cirbuf_string(void)
1300 {
1301         if (test_cirbuf_string_add_del() < 0)
1302                 return -1;
1303
1304         if (test_cirbuf_string_add_del_reverse() < 0)
1305                 return -1;
1306
1307         if (test_cirbuf_string_add_boundaries() < 0)
1308                 return -1;
1309
1310         if (test_cirbuf_string_get_del_boundaries() < 0)
1311                 return -1;
1312
1313         if (test_cirbuf_string_get_del_partial() < 0)
1314                 return -1;
1315
1316         if (test_cirbuf_string_misc() < 0)
1317                 return -1;
1318
1319         return 0;
1320 }
1321
1322 /* test cmdline_cirbuf align functions */
1323 int
1324 test_cirbuf_align(void)
1325 {
1326         if (test_cirbuf_align_left() < 0)
1327                 return -1;
1328         if (test_cirbuf_align_right() < 0)
1329                 return -1;
1330         return 0;
1331 }