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