t_snprintb.c revision 1.28 1 /* $NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code was contributed to The NetBSD Foundation by Christos Zoulas and
8 * Roland Illig.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
34 The NetBSD Foundation, inc. All rights reserved.");
35 __RCSID("$NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $");
36
37 #include <stdio.h>
38 #include <string.h>
39 #include <util.h>
40 #include <vis.h>
41
42 #include <atf-c.h>
43
44 static const char *
45 vis_arr(const char *arr, size_t arrsize)
46 {
47 static char buf[6][1024];
48 static size_t i;
49
50 i = (i + 1) % (sizeof(buf) / sizeof(buf[0]));
51 buf[i][0] = '"';
52 int rv = strnvisx(buf[i] + 1, sizeof(buf[i]) - 2, arr, arrsize,
53 VIS_WHITE | VIS_OCTAL);
54 ATF_REQUIRE_MSG(rv >= 0, "strnvisx failed for size %zu", arrsize);
55 strcpy(buf[i] + 1 + rv, "\"");
56 return buf[i];
57 }
58
59 static void
60 check_snprintb_m(const char *file, size_t line,
61 size_t bufsize, const char *bitfmt, size_t bitfmtlen, uint64_t val,
62 size_t line_max,
63 int want_rv, const char *want_buf, size_t want_bufsize)
64 {
65 char buf[1024];
66
67 ATF_REQUIRE(bufsize <= sizeof(buf));
68 ATF_REQUIRE(want_bufsize <= sizeof(buf));
69 if (bitfmtlen > 2 && bitfmt[0] == '\177')
70 ATF_REQUIRE_MSG(
71 bitfmt[bitfmtlen - 1] == '\0',
72 "%s:%zu: missing trailing '\\0' in new-style bitfmt",
73 file, line);
74 if (bufsize == 0)
75 want_bufsize = 0;
76
77 memset(buf, 'Z', sizeof(buf));
78 int rv = snprintb_m(buf, bufsize, bitfmt, val, line_max);
79
80 size_t have_bufsize = sizeof(buf);
81 while (have_bufsize > 0 && buf[have_bufsize - 1] == 'Z')
82 have_bufsize--;
83 if (rv > 0 && (unsigned)rv < have_bufsize
84 && buf[rv - 1] == '\0' && buf[rv] == '\0')
85 have_bufsize = rv + 1;
86 if (rv < 0)
87 for (size_t i = have_bufsize; i >= 2; i--)
88 if (buf[i - 2] == '\0' && buf[i - 1] == '\0')
89 have_bufsize = i;
90
91 ATF_CHECK_MSG(
92 rv == want_rv
93 && memcmp(buf, want_buf, want_bufsize) == 0
94 && (line_max == 0 || have_bufsize < 2
95 || buf[have_bufsize - 2] == '\0')
96 && (have_bufsize < 1 || buf[have_bufsize - 1] == '\0'),
97 "failed:\n"
98 "\ttest case: %s:%zu\n"
99 "\tformat: %s\n"
100 "\tvalue: %#jx\n"
101 "\tline_max: %zu\n"
102 "\twant: %d bytes %s\n"
103 "\thave: %d bytes %s\n",
104 file, line,
105 vis_arr(bitfmt, bitfmtlen),
106 (uintmax_t)val,
107 line_max,
108 want_rv, vis_arr(want_buf, want_bufsize),
109 rv, vis_arr(buf, have_bufsize));
110 }
111
112 #define h_snprintb_m_len(bufsize, bitfmt, val, line_max, \
113 want_rv, want_buf) \
114 check_snprintb_m(__FILE__, __LINE__, \
115 bufsize, bitfmt, sizeof(bitfmt) - 1, val, line_max, \
116 want_rv, want_buf, sizeof(want_buf))
117
118 #define h_snprintb(bitfmt, val, want_buf) \
119 h_snprintb_m_len(1024, bitfmt, val, 0, sizeof(want_buf) - 1, want_buf)
120
121 #define h_snprintb_len(bufsize, bitfmt, val, want_rv, want_buf) \
122 h_snprintb_m_len(bufsize, bitfmt, val, 0, want_rv, want_buf)
123
124 #define h_snprintb_error(bitfmt, want_buf) \
125 h_snprintb_m_len(1024, bitfmt, 0, 0, -1, want_buf)
126
127 #define h_snprintb_m(bitfmt, val, line_max, want_buf) \
128 h_snprintb_m_len(1024, bitfmt, val, line_max, \
129 sizeof(want_buf) - 1, want_buf)
130
131 ATF_TC(snprintb);
132 ATF_TC_HEAD(snprintb, tc)
133 {
134 atf_tc_set_md_var(tc, "descr", "Checks snprintb(3)");
135 }
136 ATF_TC_BODY(snprintb, tc)
137 {
138
139 // style and number base, old style, octal, zero value
140 //
141 // The value 0 does not get a leading '0'.
142 h_snprintb(
143 "\010",
144 0,
145 "0");
146
147 // style and number base, old style, octal, nonzero value
148 //
149 // Nonzero octal values get a leading '0'.
150 h_snprintb(
151 "\010",
152 0xff,
153 "0377");
154
155 // style and number base, old style, decimal, zero value
156 h_snprintb(
157 "\012",
158 0,
159 "0");
160
161 // style and number base, old style, decimal, nonzero value
162 h_snprintb(
163 "\012",
164 0xff,
165 "255");
166
167 // style and number base, old style, hexadecimal, zero value
168 //
169 // The value 0 does not get a leading '0x'.
170 h_snprintb(
171 "\020",
172 0,
173 "0");
174
175 // style and number base, old style, hexadecimal, nonzero value
176 //
177 // Nonzero hexadecimal values get a leading '0x'.
178 h_snprintb(
179 "\177\020",
180 0xff,
181 "0xff");
182
183 // style and number base, old style, invalid base 0
184 h_snprintb_error(
185 "",
186 "#");
187
188 // style and number base, old style, invalid base 2
189 h_snprintb_error(
190 "\002",
191 "#");
192
193 // style and number base, old style, invalid base 255 or -1
194 h_snprintb_error(
195 "\377",
196 "#");
197
198 // style and number base, new style, octal, zero value
199 //
200 // The value 0 does not get a leading '0'.
201 h_snprintb(
202 "\177\010",
203 0,
204 "0");
205
206 // style and number base, new style, octal, nonzero value
207 //
208 // Nonzero octal values get a leading '0'.
209 h_snprintb(
210 "\177\010",
211 0xff,
212 "0377");
213
214 // style and number base, new style, decimal, zero value
215 h_snprintb(
216 "\177\012",
217 0,
218 "0");
219
220 // style and number base, new style, decimal, nonzero value
221 h_snprintb(
222 "\177\012",
223 0xff,
224 "255");
225
226 // style and number base, new style, hexadecimal, zero value
227 //
228 // The value 0 does not get a leading '0x'.
229 h_snprintb(
230 "\177\020",
231 0,
232 "0");
233
234 // style and number base, new style, hexadecimal, nonzero value
235 //
236 // Nonzero hexadecimal values get a leading '0x'.
237 h_snprintb(
238 "\177\020",
239 0xff,
240 "0xff");
241
242 // style and number base, new style, invalid number base 0
243 h_snprintb_error(
244 "\177",
245 "#");
246
247 // style and number base, new style, invalid number base 2
248 h_snprintb_error(
249 "\177\002",
250 "#");
251
252 // style and number base, new style, invalid number base 255 or -1
253 h_snprintb_error(
254 "\177\377",
255 "#");
256
257 // old style, from lsb to msb
258 h_snprintb(
259 "\020"
260 "\001bit1"
261 "\002bit2"
262 "\037bit31"
263 "\040bit32",
264 0xffffffff80000001,
265 "0xffffffff80000001<bit1,bit32>");
266
267 // old style, invalid bit number, at the beginning
268 h_snprintb_error(
269 "\020"
270 "\041invalid",
271 "0#");
272
273 // old style, invalid bit number, in the middle
274 //
275 // The old-style format supports only 32 bits, interpreting the
276 // \041 as part of the text belonging to bit 1.
277 h_snprintb(
278 "\020"
279 "\001bit1"
280 "\041bit33",
281 0x1,
282 "0x1<bit1!bit33>");
283
284 // old style, repeated bit numbers
285 //
286 // When a bit number is mentioned more than once,
287 // this is most likely a typo.
288 h_snprintb(
289 "\020"
290 "\001once"
291 "\001again",
292 0x1,
293 "0x1<once,again>");
294
295 // old style, non-printable description
296 //
297 // The characters ' ' and '\t' are interpreted as bit numbers,
298 // not as part of the description; the visual arrangement is
299 // misleading.
300 h_snprintb(
301 "\020"
302 "\001least significant"
303 "\002horizontal\ttab"
304 "\003\xC3\xA4",
305 0xff,
306 "0xff<least,horizontal,\xC3\xA4>");
307
308 // old style, empty description
309 //
310 // Empty descriptions result in multiple commas in a row, which is a
311 // mistake.
312 h_snprintb(
313 "\020"
314 "\001lsb"
315 "\004"
316 "\005"
317 "\010msb",
318 0xff,
319 "0xff<lsb,,,msb>");
320
321 // old style, buffer size 0
322 //
323 // With the buffer size being 0, the buffer is not modified at all.
324 h_snprintb_len(
325 0, "\020", 0,
326 1, "");
327
328 // old style, buffer size 0, null buffer
329 //
330 // If the buffer size is 0, the buffer may be NULL.
331 int null_rv_old = snprintb(NULL, 0, "\020\001lsb", 0x01);
332 ATF_CHECK_MSG(
333 null_rv_old == 8,
334 "want length 8, have %d", null_rv_old);
335
336 // old style, buffer too small for value
337 h_snprintb_len(
338 1, "\020", 0,
339 1, "");
340
341 // old style, buffer large enough for zero value
342 h_snprintb_len(
343 2, "\020", 0,
344 1, "0");
345
346 // old style, buffer larger than necessary for zero value
347 h_snprintb_len(
348 3, "\020", 0,
349 1, "0");
350
351 // old style, buffer too small for nonzero value
352 h_snprintb_len(
353 3, "\020", 7,
354 3, "0x");
355
356 // old style, buffer large enough for nonzero value
357 h_snprintb_len(
358 4, "\020", 7,
359 3, "0x7");
360
361 // old style, buffer too small for '<'
362 h_snprintb_len(
363 4, "\020\001lsb", 7,
364 8, "0x7");
365
366 // old style, buffer too small for description
367 h_snprintb_len(
368 7, "\020\001lsb", 7,
369 8, "0x7<ls");
370
371 // old style, buffer too small for '>'
372 h_snprintb_len(
373 8, "\020\001lsb", 7,
374 8, "0x7<lsb");
375
376 // old style, buffer large enough for '<'
377 h_snprintb_len(
378 9, "\020\001lsb", 7,
379 8, "0x7<lsb>");
380
381 // old style, buffer too small for second description
382 h_snprintb_len(
383 9, "\020\001one\002two", 7,
384 12, "0x7<one,");
385
386 // old style, buffer too small for second description
387 h_snprintb_len(
388 10, "\020\001one\002two", 7,
389 12, "0x7<one,t");
390
391 // old style, buffer too small for '>' after second description
392 h_snprintb_len(
393 12, "\020\001one\002two", 7,
394 12, "0x7<one,two");
395
396 // old style, buffer large enough for '>' after second description
397 h_snprintb_len(
398 13, "\020\001one\002two", 7,
399 12, "0x7<one,two>");
400
401 // new style, buffer size 0, null buffer
402 //
403 // If the buffer size is 0, the buffer may be NULL.
404 int null_rv_new = snprintb(NULL, 0, "\177\020b\000lsb\0", 0x01);
405 ATF_CHECK_MSG(
406 null_rv_new == 8,
407 "want length 8, have %d", null_rv_new);
408
409 // new style single bits
410 h_snprintb(
411 "\177\020"
412 "b\000lsb\0"
413 "b\001above-lsb\0"
414 "b\037bit31\0"
415 "b\040bit32\0"
416 "b\076below-msb\0"
417 "b\077msb\0",
418 0x8000000180000001,
419 "0x8000000180000001<lsb,bit31,bit32,msb>");
420
421 // new style single bits, duplicate bits
422 h_snprintb(
423 "\177\020"
424 "b\000lsb\0"
425 "b\000lsb\0"
426 "b\000lsb\0",
427 0xff,
428 "0xff<lsb,lsb,lsb>");
429
430 // new style single bits, empty description
431 h_snprintb(
432 "\177\020"
433 "b\000lsb\0"
434 "b\001\0"
435 "b\002\0"
436 "b\007msb\0"
437 ,
438 0xff,
439 "0xff<lsb,,,msb>");
440
441 // new style single bits, bit number too large
442 h_snprintb_error(
443 "\177\020"
444 "b\100too-high\0",
445 "0#");
446 h_snprintb_error(
447 "\177\020"
448 "b\377too-high\0",
449 "0#");
450
451 // new style single bits, non-printable description
452 //
453 // Contrary to the old-style format, the new-style format allows
454 // arbitrary characters in the description, even control characters
455 // and non-ASCII characters.
456 h_snprintb(
457 "\177\020"
458 "b\000space \t \xC3\xA4\0",
459 0x1,
460 "0x1<space \t \xC3\xA4>");
461
462 // new style named bit-field, octal
463 //
464 // The bit-field value gets a leading '0' iff it is nonzero.
465 h_snprintb(
466 "\177\010"
467 "f\000\010byte0\0"
468 "f\010\010byte1\0",
469 0x0100,
470 "0400<byte0=0,byte1=01>");
471
472 // new style named bit-field, decimal
473 h_snprintb(
474 "\177\012"
475 "f\000\010byte0\0"
476 "f\010\010byte1\0",
477 0x0100,
478 "256<byte0=0,byte1=1>");
479
480 // new style named bit-field, hexadecimal
481 h_snprintb(
482 "\177\020"
483 "f\000\010byte0\0"
484 "f\010\010byte1\0",
485 0x0100,
486 "0x100<byte0=0,byte1=0x1>");
487
488 // new style bit-field, from 0 width 0
489 h_snprintb(
490 "\177\020"
491 "f\000\000zero-width\0"
492 "=\000zero\0",
493 0xffff,
494 "0xffff<zero-width=0=zero>");
495
496 // new style bit-field, from 0 width 1
497 h_snprintb(
498 "\177\020"
499 "f\000\001lsb\0"
500 "=\000zero\0"
501 "=\001one\0",
502 0x0,
503 "0<lsb=0=zero>");
504 h_snprintb(
505 "\177\020"
506 "f\000\001lsb\0"
507 "=\000zero\0"
508 "=\001one\0",
509 0x1,
510 "0x1<lsb=0x1=one>");
511
512 // new style bit-field, from 0 width 63
513 h_snprintb(
514 "\177\020"
515 "f\000\077uint63\0"
516 "=\125match\0",
517 0xaaaa5555aaaa5555,
518 "0xaaaa5555aaaa5555<uint63=0x2aaa5555aaaa5555>");
519
520 // new style bit-field, from 0 width 64
521 h_snprintb(
522 "\177\020"
523 "f\000\100uint64\0"
524 "=\125match\0",
525 0xaaaa5555aaaa5555,
526 "0xaaaa5555aaaa5555<uint64=0xaaaa5555aaaa5555>");
527
528 // new style bit-field, from 0 width 65
529 h_snprintb_error(
530 "\177\020"
531 "f\000\101uint65\0",
532 "0#");
533
534 // new style bit-field, from 1 width 8
535 h_snprintb(
536 "\177\020"
537 "f\001\010uint8\0"
538 "=\203match\0",
539 0x0106,
540 "0x106<uint8=0x83=match>");
541
542 // new style bit-field, from 1 width 9
543 //
544 // The '=' and ':' directives can only match a bit-field value between
545 // 0 and 255, independent of the bit-field's width.
546 h_snprintb(
547 "\177\020"
548 "f\001\011uint9\0"
549 "=\203match\0"
550 "*=other-f\0"
551 "F\001\011\0"
552 ":\203match\0"
553 "*other-F\0",
554 0x0306,
555 "0x306<uint9=0x183=other-f,other-F>");
556
557 // new style bit-field, from 32 width 32
558 h_snprintb(
559 "\177\020"
560 "f\040\040uint32\0",
561 0xaaaa555500000000,
562 "0xaaaa555500000000<uint32=0xaaaa5555>");
563
564 // new style bit-field, from 60 width 4
565 h_snprintb(
566 "\177\020"
567 "f\074\004uint4\0",
568 0xf555555555555555,
569 "0xf555555555555555<uint4=0xf>");
570
571 // new style bit-field, from 60 width 5
572 //
573 // The end of the bit-field is out of bounds.
574 h_snprintb(
575 "\177\020"
576 "f\074\005uint5\0",
577 0xf555555555555555,
578 "0xf555555555555555<uint5=0xf>");
579
580 // new style bit-field, from 64 width 0
581 //
582 // The beginning of the bit-field is out of bounds, the end is fine.
583 h_snprintb_error(
584 "\177\020"
585 "f\100\000uint0\0",
586 "0#");
587
588 // new style bit-field, from 65 width 0
589 //
590 // The beginning and end of the bit-field are out of bounds.
591 h_snprintb_error(
592 "\177\020"
593 "f\101\000uint0\0",
594 "0#");
595
596 // new style bit-field, empty field description
597 //
598 // The description of a field may be empty, though this is probably a
599 // mistake, as it outputs an isolated '='.
600 h_snprintb(
601 "\177\020"
602 "f\000\004\0"
603 "=\001one\0",
604 0x1,
605 "0x1<=0x1=one>");
606
607 // new style bit-field, non-printable description
608 //
609 // Contrary to the old-style format, the new-style format allows
610 // arbitrary characters in the description, even control characters
611 // and non-ASCII characters.
612 h_snprintb(
613 "\177\020"
614 "f\000\010\t \xC3\xA4\0"
615 "=\001\t \xC3\xA4\0"
616 "F\000\010\0"
617 ":\001\t \xC3\xA4\0"
618 "F\000\010\0"
619 "*\t \xC3\xA4\0",
620 0x1,
621 "0x1<\t \xC3\xA4=0x1=\t \xC3\xA4,\t \xC3\xA4,\t \xC3\xA4>");
622
623 // new style bit-field, '=' with empty description
624 //
625 // The description of a '=' directive may be empty, though this is
626 // probably a mistake, as it outputs several '=' in a row.
627 h_snprintb(
628 "\177\020"
629 "f\000\004f\0"
630 "=\001one\0"
631 "=\001\0"
632 "=\001\0",
633 0x1,
634 "0x1<f=0x1=one==>");
635
636 // new style bit-field, 'F' followed by ':' with empty description
637 //
638 // The description of a ':' directive may be empty, though this is
639 // probably a mistake, as it leads to empty angle brackets.
640 h_snprintb(
641 "\177\020"
642 "F\000\004\0"
643 ":\001\0"
644 "*default\0",
645 0x1,
646 "0x1<>");
647
648 // new style bit-field, 'F', ':' with empty description, '*'
649 //
650 // The ':' directive could be used to suppress a following '*'
651 // directive, but this combination is probably a mistake, as a
652 // matching ':' leads to empty angle brackets.
653 h_snprintb(
654 "\177\020"
655 "F\000\004\0"
656 ":\001\0"
657 "*default\0",
658 0x2,
659 "0x2<default>");
660
661 // new style bit-field, 'f' with non-exhaustive '='
662 h_snprintb(
663 "\177\020"
664 "f\000\004Field\0"
665 "=\1one\0"
666 "=\2two\0",
667 0x3,
668 "0x3<Field=0x3>");
669
670 // new style bit-field, 'F' with non-exhaustive ':'
671 //
672 // A bit-field that does not match any values still generates empty
673 // angle brackets.
674 h_snprintb(
675 "\177\020"
676 "F\000\004\0"
677 ":\1one\0"
678 ":\2two\0",
679 0x3,
680 "0x3<>");
681
682 // new style bit-field, 'F' with non-exhaustive ':'
683 //
684 // A bit-field that does not match any values still generates empty
685 // angle brackets or adjacent commas.
686 h_snprintb(
687 "\177\020"
688 "b\000bit0\0"
689 "F\000\004\0"
690 ":\1one\0"
691 ":\2two\0"
692 "b\001bit1\0",
693 0x3,
694 "0x3<bit0,,bit1>");
695
696 // new style bit-field, '=', can never match
697 h_snprintb(
698 "\177\020"
699 "f\000\007f\0"
700 "=\200never\0"
701 "=\377never\0",
702 0xff,
703 "0xff<f=0x7f>");
704
705 // new style, two separate bit-fields
706 h_snprintb(
707 "\177\020"
708 "f\000\004f1\0"
709 "=\001one\0"
710 "=\002two\0"
711 "f\004\004f2\0"
712 "=\001one\0"
713 "=\002two\0",
714 0x12,
715 "0x12<f1=0x2=two,f2=0x1=one>");
716
717 // new style, mixed named and unnamed bit-fields
718 h_snprintb(
719 "\177\020"
720 "f\000\004f1\0"
721 "=\001one\0"
722 "=\002two\0"
723 "F\010\004\0"
724 ":\015thirteen\0"
725 "f\004\004f2\0"
726 "=\001one\0"
727 "=\002two\0",
728 0x0d12,
729 "0xd12<f1=0x2=two,thirteen,f2=0x1=one>");
730
731 // new style bit-field, overlapping
732 h_snprintb(
733 "\177\020"
734 "f\000\004lo\0"
735 "f\002\004mid\0"
736 "f\004\004hi\0"
737 "f\000\010all\0",
738 0x18,
739 "0x18<lo=0x8,mid=0x6,hi=0x1,all=0x18>");
740
741 // new style bit-field, difference between '=' and ':'
742 //
743 // The ':' directive can almost emulate the '=' directive, without the
744 // numeric output and with a different separator. It's best to use
745 // either 'f' with '=' or 'F' with ':', but not mix them.
746 h_snprintb(
747 "\177\020"
748 "f\000\004field\0"
749 "=\010value\0"
750 "F\000\000\0"
751 ":\000field\0" // Since the description of 'F' is ignored.
752 "F\000\004\0"
753 ":\010value\0",
754 0x18,
755 "0x18<field=0x8=value,field,value>");
756
757 // new style bit-field default, fixed string
758 //
759 // The 'f' directive pairs up with the '=' directive,
760 // the 'F' directive pairs up with the ':' directive,
761 // but there's only one 'default' directive for both variants,
762 // so its description should include the '=' when used with 'f' but
763 // not with 'F'.
764 h_snprintb(
765 "\177\020"
766 "f\030\010f1\0"
767 "*default\0"
768 "f\020\010f2\0"
769 "*=default\0"
770 "F\010\010\0"
771 "*default\0"
772 "F\010\010\0"
773 "*=default\0",
774 0x11223344,
775 "0x11223344<f1=0x11default,f2=0x22=default,default,=default>");
776
777 // new style bit-field default, numeric conversion specifier
778 h_snprintb(
779 "\177\020"
780 "f\010\010f\0"
781 "*=f(%ju)\0"
782 "F\000\010F\0"
783 "*F(%ju)\0",
784 0x1122,
785 "0x1122<f=0x11=f(17),F(34)>");
786
787 // new style bit-field default, can never match
788 h_snprintb(
789 "\177\020"
790 "f\010\002f\0"
791 "=\000zero\0"
792 "=\001one\0"
793 "=\002two\0"
794 "=\003three\0"
795 "*other\0",
796 0xff00,
797 "0xff00<f=0x3=three>");
798
799 // new style bit-field default, invalid conversion specifier
800 //
801 // There is no reliable way to make snprintf return an error, as such
802 // errors are defined as undefined behavior in the C standard.
803 // Instead, here's a conversion specifier that produces a literal '%'.
804 h_snprintb(
805 "\177\020"
806 "f\000\010f\0"
807 "*=%030ju%%\0",
808 0xff,
809 "0xff<f=0xff=000000000000000000000000000255%>");
810
811 // new style unknown directive
812 //
813 // Unknown directives are assumed to have a single byte argument
814 // followed by a description; they are skipped up to the next '\0'.
815 h_snprintb(
816 "\177\020"
817 "c\010ignored\0"
818 "c\000b\0"
819 "lsb\0"
820 "b\007msb\0",
821 0xff,
822 "0xff<msb>");
823
824 // new style combinations, 'b' '='
825 //
826 // A '=' directive without a preceding 'f' or 'F' directive applies to
827 // the whole value; its description may appear inside or outside the
828 // angle brackets. Having such a format is likely an error.
829 h_snprintb(
830 "\177\020"
831 "b\004bit4\0"
832 "=\000clear\0"
833 "=\001set\0"
834 "=\245complete\0"
835 "b\000bit0\0"
836 "=\000clear\0"
837 "=\001set\0"
838 "=\245complete\0",
839 0xa5,
840 "0xa5=complete<bit0=complete>");
841
842 // new style combinations, 'b' ':'
843 //
844 // A ':' directive without a preceding 'f' or 'F' directive applies to
845 // the whole value; its description may appear inside or outside the
846 // angle brackets. Having such a format is likely an error.
847 h_snprintb(
848 "\177\020"
849 "b\004bit4\0"
850 ":\000clear\0"
851 ":\001set\0"
852 ":\245complete\0"
853 "b\000bit0\0"
854 ":\000clear\0"
855 ":\001set\0"
856 ":\245complete\0",
857 0xa5,
858 "0xa5complete<bit0complete>");
859
860 // new style combinations, 'b' '*'
861 //
862 // A '*' directive without a preceding 'f' or 'F' directive is ignored.
863 h_snprintb(
864 "\177\020"
865 "b\004bit4\0"
866 "*default(%ju)\0"
867 "b\000bit0\0"
868 "*default(%ju)\0",
869 0xa5,
870 "0xa5<bit0>");
871
872 // new style combinations, 'f' 'b' '='
873 //
874 // Between an 'f' and an '=' directive, there may be unrelated 'b'
875 // directives, they do not affect the value of the "previous field".
876 // Formats like these are probably mistakes.
877 h_snprintb(
878 "\177\020"
879 "f\000\010f\0"
880 "b\005bit5\0"
881 "=\xa5match\0",
882 0xa5,
883 "0xa5<f=0xa5,bit5=match>");
884
885 // new style combinations, 'f' 'b' ':'
886 //
887 // Between an 'f' and a ':' directive, there may be unrelated 'b'
888 // directives, they do not affect the value of the "previous field".
889 // Formats like these are mistakes, as the output is garbled.
890 h_snprintb(
891 "\177\020"
892 "f\000\010f\0"
893 "b\005bit5\0"
894 ":\xa5match\0",
895 0xa5,
896 "0xa5<f=0xa5,bit5match>");
897
898 // new style combinations, 'f' ':'
899 h_snprintb(
900 "\177\20"
901 "f\000\004nibble\0"
902 ":\001one\0",
903 0x01,
904 "0x1<nibble=0x1one>");
905
906 // new style combinations, 'F' '='
907 //
908 // Combining the 'F' and '=' directives outputs an isolated '=', which
909 // doesn't look well-formed.
910 h_snprintb(
911 "\177\20"
912 "F\000\004\0"
913 "=\001one\0",
914 0x01,
915 "0x1<=one>");
916
917 // new style combinations, '='
918 //
919 // A '=' directive without a preceding 'f' or 'F' directive matches on
920 // the complete value. This is not documented in the manual page, and
921 // formats like these are probably mistakes.
922 h_snprintb(
923 "\177\020"
924 "=\xa5match\0",
925 0xa5,
926 "0xa5=match");
927
928 // new style combinations, ':'
929 //
930 // A ':' directive without a preceding 'f' or 'F' directive matches on
931 // the complete value. This is not documented in the manual page, and
932 // formats like these are probably mistakes.
933 h_snprintb(
934 "\177\020"
935 ":\xa5match\0",
936 0xa5,
937 "0xa5match");
938
939 // new style combinations, '*'
940 //
941 // A '*' directive without a preceding 'f' or 'F' is skipped. Formats
942 // like these are mistakes.
943 h_snprintb(
944 "\177\020"
945 "*match\0",
946 0xa5,
947 "0xa5");
948
949 // new style combinations, 'f' '*' '='
950 //
951 // A '*' directive may be followed by a '=' directive. Formats like
952 // this are probably a mistake.
953 h_snprintb(
954 "\177\020"
955 "f\000\010f\0"
956 "*=default\0"
957 "=\xa5match\0",
958 0xa5,
959 "0xa5<f=0xa5=default=match>");
960
961 // new style combinations, 'F' '*' ':'
962 //
963 // A '*' directive may be followed by a ':' directive. Formats like
964 // this are probably a mistake.
965 h_snprintb(
966 "\177\020"
967 "F\000\010F\0"
968 "*default\0"
969 ":\xa5-match\0",
970 0xa5,
971 "0xa5<default-match>");
972
973 // new style combinations, '*' '*'
974 //
975 // The first '*' directive matches everything, so the second '*'
976 // directive cannot match anything and is thus redundant. Formats like
977 // this are a mistake.
978 h_snprintb(
979 "\177\020"
980 "f\000\010f\0"
981 "*=default-f\0"
982 "*ignored\0"
983 "F\000\010\0"
984 "*default-F\0"
985 "*ignored\0",
986 0xa5,
987 "0xa5<f=0xa5=default-f,default-F>");
988
989 // manual page, old style octal
990 h_snprintb(
991 "\10\2BITTWO\1BITONE",
992 3,
993 "03<BITTWO,BITONE>");
994
995 // manual page, old style hexadecimal
996 h_snprintb(
997 "\20"
998 "\x10NOTBOOT" "\x0f""FPP" "\x0eSDVMA"
999 "\x0cVIDEO" "\x0bLORES" "\x0a""FPA" "\x09""DIAG"
1000 "\x07""CACHE" "\x06IOCACHE" "\x05LOOPBACK"
1001 "\x04""DBGCACHE",
1002 0xe860,
1003 "0xe860<NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE>");
1004
1005 // manual page, new style bits and fields
1006 h_snprintb(
1007 "\177\020"
1008 "b\0LSB\0" "b\1BITONE\0"
1009 "f\4\4NIBBLE2\0"
1010 "f\x10\4BURST\0" "=\4FOUR\0" "=\xf""FIFTEEN\0"
1011 "b\x1fMSB\0",
1012 0x800f0701,
1013 "0x800f0701<LSB,NIBBLE2=0,BURST=0xf=FIFTEEN,MSB>");
1014
1015 // manual page, new style mmap
1016 #define MAP_FMT \
1017 "\177\020" \
1018 "b\0" "SHARED\0" \
1019 "b\1" "PRIVATE\0" \
1020 "b\2" "COPY\0" \
1021 "b\4" "FIXED\0" \
1022 "b\5" "RENAME\0" \
1023 "b\6" "NORESERVE\0" \
1024 "b\7" "INHERIT\0" \
1025 "b\11" "HASSEMAPHORE\0" \
1026 "b\12" "TRYFIXED\0" \
1027 "b\13" "WIRED\0" \
1028 "F\14\1\0" \
1029 ":\0" "FILE\0" \
1030 ":\1" "ANONYMOUS\0" \
1031 "b\15" "STACK\0" \
1032 "F\30\010\0" \
1033 ":\000" "ALIGN=NONE\0" \
1034 ":\015" "ALIGN=8KB\0" \
1035 "*" "ALIGN=2^%ju\0"
1036 h_snprintb(
1037 MAP_FMT,
1038 0x0d001234,
1039 "0xd001234<COPY,FIXED,RENAME,HASSEMAPHORE,ANONYMOUS,ALIGN=8KB>");
1040 h_snprintb(
1041 MAP_FMT,
1042 0x2e000000,
1043 "0x2e000000<FILE,ALIGN=2^46>");
1044
1045 // It is possible but cumbersome to implement a reduced variant of
1046 // rot13 using snprintb, shown here for lowercase letters only.
1047 for (char ch = 'A'; ch <= '~'; ch++) {
1048 char rot13 = ch >= 'a' && ch <= 'm' ? ch + 13
1049 : ch >= 'n' && ch <= 'z' ? ch - 13
1050 : '?';
1051 char expected[8];
1052 ATF_REQUIRE_EQ(7,
1053 snprintf(expected, sizeof(expected), "%#x<%c>", ch, rot13));
1054 h_snprintb(
1055 "\177\020"
1056 "F\000\010\0"
1057 ":an\0:bo\0:cp\0:dq\0:er\0:fs\0:gt\0:hu\0"
1058 ":iv\0:jw\0:kx\0:ly\0:mz\0"
1059 ":na\0:ob\0:pc\0:qd\0:re\0:sf\0:tg\0:uh\0"
1060 ":vi\0:wj\0:xk\0:yl\0:zm\0"
1061 // If snprintf accepted "%jc", it would be possible to
1062 // echo the non-alphabetic characters instead of a
1063 // catchall question mark.
1064 "*?\0",
1065 ch,
1066 expected);
1067 }
1068
1069 // new style, small buffers
1070 h_snprintb_len(
1071 0, "\177\020", 0,
1072 1, "");
1073 h_snprintb_len(
1074 1, "\177\020", 0,
1075 1, "");
1076 h_snprintb_len(
1077 2, "\177\020", 0,
1078 1, "0");
1079 h_snprintb_len(
1080 3, "\177\020", 0,
1081 1, "0");
1082 h_snprintb_len(
1083 3, "\177\020", 7,
1084 3, "0x");
1085 h_snprintb_len(
1086 4, "\177\020", 7,
1087 3, "0x7");
1088 h_snprintb_len(
1089 7, "\177\020b\000lsb\0", 7,
1090 8, "0x7<ls");
1091 h_snprintb_len(
1092 8, "\177\020b\000lsb\0", 7,
1093 8, "0x7<lsb");
1094 h_snprintb_len(
1095 9, "\177\020b\000lsb\0", 7,
1096 8, "0x7<lsb>");
1097 h_snprintb_len(
1098 9, "\177\020b\000one\0b\001two\0", 7,
1099 12, "0x7<one,");
1100 h_snprintb_len(
1101 10, "\177\020b\000one\0b\001two\0", 7,
1102 12, "0x7<one,t");
1103 h_snprintb_len(
1104 12, "\177\020b\000one\0b\001two\0", 7,
1105 12, "0x7<one,two");
1106 h_snprintb_len(
1107 13, "\177\020b\000one\0b\001two\0", 7,
1108 12, "0x7<one,two>");
1109 }
1110
1111 ATF_TC(snprintb_m);
1112 ATF_TC_HEAD(snprintb_m, tc)
1113 {
1114 atf_tc_set_md_var(tc, "descr", "Checks snprintb_m(3)");
1115 }
1116 ATF_TC_BODY(snprintb_m, tc)
1117 {
1118
1119 // old style, line_max exceeded by number in line 1
1120 h_snprintb_m(
1121 "\020",
1122 0xff,
1123 1,
1124 "#\0");
1125
1126 // old style, line_max exceeded by '<' in line 1
1127 h_snprintb_m(
1128 "\020"
1129 "\001lsb",
1130 0xff,
1131 4,
1132 "0xf#\0");
1133
1134 // old style, line_max exceeded by description
1135 h_snprintb_m(
1136 "\020"
1137 "\001bit1"
1138 "\002bit2",
1139 0xff,
1140 7,
1141 "0xff<b#\0"
1142 "0xff<b#\0");
1143
1144 // old style, line_max exceeded by '>' in line 1
1145 h_snprintb_m(
1146 "\020"
1147 "\001bit1"
1148 "\0022",
1149 0xff,
1150 9,
1151 "0xff<bit#\0"
1152 "0xff<2>\0");
1153
1154 // old style, line_max exceeded by description in line 2
1155 h_snprintb_m(
1156 "\020"
1157 "\0011"
1158 "\002bit2",
1159 0xff,
1160 8,
1161 "0xff<1>\0"
1162 "0xff<bi#\0");
1163
1164 // old style, line_max exceeded by '>' in line 2
1165 h_snprintb_m(
1166 "\020"
1167 "\0011"
1168 "\002bit2",
1169 0xff,
1170 9,
1171 "0xff<1>\0"
1172 "0xff<bit#\0");
1173
1174 // old style complete
1175 h_snprintb_m(
1176 "\020"
1177 "\0011"
1178 "\002bit2",
1179 0xff,
1180 10,
1181 "0xff<1>\0"
1182 "0xff<bit2>\0");
1183
1184 // new style, line_max exceeded by value in line 1
1185 h_snprintb_m(
1186 "\177\020",
1187 0xff,
1188 1,
1189 "#\0");
1190
1191 // new style, line_max exceeded by single-bit '<' in line 1
1192 h_snprintb_m(
1193 "\177\020"
1194 "b\000bit\0",
1195 0xff,
1196 4,
1197 "0xf#\0");
1198
1199 // new style, line_max exceeded by single-bit description in line 1
1200 h_snprintb_m(
1201 "\177\020"
1202 "b\000bit0\0"
1203 "b\001two\0",
1204 0xff,
1205 8,
1206 "0xff<bi#\0"
1207 "0xff<tw#\0");
1208
1209 // new style, line_max exceeded by single-bit '>' in line 1
1210 h_snprintb_m(
1211 "\177\020"
1212 "b\000bit0\0"
1213 "b\001two\0",
1214 0xff,
1215 9,
1216 "0xff<bit#\0"
1217 "0xff<two>\0");
1218
1219 // new style, line_max exceeded by single-bit description in line 2
1220 h_snprintb_m(
1221 "\177\020"
1222 "b\000one\0"
1223 "b\001three\0",
1224 0xff,
1225 9,
1226 "0xff<one>\0"
1227 "0xff<thr#\0");
1228
1229 // new style, line_max exceeded by single-bit '>' in line 2
1230 h_snprintb_m(
1231 "\177\020"
1232 "b\000one\0"
1233 "b\001four\0",
1234 0xff,
1235 9,
1236 "0xff<one>\0"
1237 "0xff<fou#\0");
1238
1239 // new style, single-bit complete
1240 h_snprintb_m(
1241 "\177\020"
1242 "b\000one\0"
1243 "b\001three\0",
1244 0xff,
1245 11,
1246 "0xff<one>\0"
1247 "0xff<three>\0");
1248
1249 // new style, line_max exceeded by named bit-field number in line 1
1250 h_snprintb_m(
1251 "\177\020"
1252 "f\000\004lo\0",
1253 0xff,
1254 3,
1255 "0x#\0");
1256
1257 // new style, line_max exceeded by named bit-field '<' in line 1
1258 h_snprintb_m(
1259 "\177\020"
1260 "f\000\004lo\0",
1261 0xff,
1262 4,
1263 "0xf#\0");
1264
1265 // new style, line_max exceeded by named bit-field field description
1266 // in line 1
1267 h_snprintb_m(
1268 "\177\020"
1269 "f\000\004lo\0",
1270 0xff,
1271 6,
1272 "0xff<#\0");
1273
1274 // new style, line_max exceeded by named bit-field '=' in line 1
1275 h_snprintb_m(
1276 "\177\020"
1277 "f\000\004lo\0",
1278 0xff,
1279 7,
1280 "0xff<l#\0");
1281
1282 // new style, line_max exceeded by named bit-field value in line 1
1283 h_snprintb_m(
1284 "\177\020"
1285 "f\000\004lo\0",
1286 0xff,
1287 10,
1288 "0xff<lo=0#\0");
1289
1290 // new style, line_max exceeded by named bit-field '=' in line 1
1291 h_snprintb_m(
1292 "\177\020"
1293 "f\000\004lo\0"
1294 "=\017match\0",
1295 0xff,
1296 11,
1297 "0xff<lo=0x#\0");
1298
1299 // new style, line_max exceeded by named bit-field value description in
1300 // line 1
1301 h_snprintb_m(
1302 "\177\020"
1303 "f\000\004lo\0"
1304 "=\017match\0",
1305 0xff,
1306 16,
1307 "0xff<lo=0xf=mat#\0");
1308
1309 // new style, line_max exceeded by named bit-field '>' in line 1
1310 h_snprintb_m(
1311 "\177\020"
1312 "f\000\004lo\0"
1313 "=\017match\0",
1314 0xff,
1315 17,
1316 "0xff<lo=0xf=matc#\0");
1317
1318 // new style, line_max exceeded by named bit-field description in line 2
1319 h_snprintb_m(
1320 "\177\020"
1321 "f\000\004lo\0"
1322 "f\000\004low-bits\0"
1323 "=\017match\0",
1324 0xff,
1325 12,
1326 "0xff<lo=0xf>\0"
1327 "0xff<low-bi#\0");
1328
1329 // new style, line_max exceeded by named bit-field '=' in line 2
1330 h_snprintb_m(
1331 "\177\020"
1332 "f\000\004lo\0"
1333 "f\000\004low-bits\0"
1334 "=\017match\0",
1335 0xff,
1336 13,
1337 "0xff<lo=0xf>\0"
1338 "0xff<low-bit#\0");
1339
1340 // new style, line_max exceeded by named bit-field value in line 2
1341 h_snprintb_m(
1342 "\177\020"
1343 "f\000\004lo\0"
1344 "f\000\004low-bits\0"
1345 "=\017match\0",
1346 0xff,
1347 16,
1348 "0xff<lo=0xf>\0"
1349 "0xff<low-bits=0#\0");
1350
1351 // new style, line_max exceeded by named bit-field '=' in line 2
1352 h_snprintb_m(
1353 "\177\020"
1354 "f\000\004lo\0"
1355 "f\000\004low-bits\0"
1356 "=\017match\0",
1357 0xff,
1358 17,
1359 "0xff<lo=0xf>\0"
1360 "0xff<low-bits=0x#\0");
1361
1362 // new style, line_max exceeded by named bit-field value description
1363 // in line 2
1364 h_snprintb_m(
1365 "\177\020"
1366 "f\000\004lo\0"
1367 "f\000\004low-bits\0"
1368 "=\017match\0",
1369 0xff,
1370 22,
1371 "0xff<lo=0xf>\0"
1372 "0xff<low-bits=0xf=mat#\0");
1373
1374 // new style, line_max exceeded by named bit-field '>' in line 2
1375 h_snprintb_m(
1376 "\177\020"
1377 "f\000\004lo\0"
1378 "f\000\004low-bits\0"
1379 "=\017match\0",
1380 0xff,
1381 23,
1382 "0xff<lo=0xf>\0"
1383 "0xff<low-bits=0xf=matc#\0");
1384
1385 // new style, named bit-field complete
1386 h_snprintb_m(
1387 "\177\020"
1388 "f\000\004lo\0"
1389 "f\000\004low-bits\0"
1390 "=\017match\0",
1391 0xff,
1392 24,
1393 "0xff<lo=0xf>\0"
1394 "0xff<low-bits=0xf=match>\0");
1395
1396 // new style, line_max exceeded by unnamed bit-field number in line 1
1397 h_snprintb_m(
1398 "\177\020"
1399 "F\000\004\0",
1400 0xff,
1401 3,
1402 "0x#\0");
1403
1404 // new style, line_max exceeded by unnamed bit-field '<' in line 1
1405 h_snprintb_m(
1406 "\177\020"
1407 "F\000\004\0",
1408 0xff,
1409 4,
1410 "0xf#\0");
1411
1412 // new style, line_max exceeded by unnamed bit-field value description
1413 // in line 1
1414 h_snprintb_m(
1415 "\177\020"
1416 "F\000\004\0"
1417 ":\017match\0",
1418 0xff,
1419 9,
1420 "0xff<mat#\0");
1421
1422 // new style, line_max exceeded by unnamed bit-field '>' in line 1
1423 h_snprintb_m(
1424 "\177\020"
1425 "F\000\004\0"
1426 ":\017match\0",
1427 0xff,
1428 10,
1429 "0xff<matc#\0");
1430
1431 // new style, line_max exceeded by unnamed bit-field value description
1432 // in line 2
1433 h_snprintb_m(
1434 "\177\020"
1435 "F\000\004\0"
1436 ":\017m1\0"
1437 ":\017match\0",
1438 0xff,
1439 10,
1440 "0xff<m1ma#\0");
1441
1442 // new style, line_max exceeded by unnamed bit-field '>' in line 2
1443 h_snprintb_m(
1444 "\177\020"
1445 "F\000\004\0"
1446 ":\017m1\0"
1447 ":\017match\0",
1448 0xff,
1449 10,
1450 "0xff<m1ma#\0");
1451
1452 // new style unnamed bit-field complete
1453 h_snprintb_m(
1454 "\177\020"
1455 "F\000\004\0"
1456 ":\017m1\0"
1457 ":\017match\0",
1458 0xff,
1459 13,
1460 "0xff<m1match>\0");
1461
1462 // new style, line_max exceeded by bit-field default
1463 h_snprintb_m(
1464 "\177\020"
1465 "f\000\004f\0"
1466 "*=default\0",
1467 0xff,
1468 17,
1469 "0xff<f=0xf=defau#\0");
1470
1471 // new style, line_max exceeded by unmatched field value
1472 h_snprintb_m(
1473 "\177\020"
1474 "f\000\004bits\0"
1475 ":\000other\0",
1476 0xff,
1477 11,
1478 "0xff<bits=#\0");
1479
1480 // manual page, new style bits and fields
1481 h_snprintb_m(
1482 "\177\020"
1483 "b\0LSB\0"
1484 "b\1BITONE\0"
1485 "f\4\4NIBBLE2\0"
1486 "f\x10\4BURST\0"
1487 "=\4FOUR\0"
1488 "=\xf""FIFTEEN\0"
1489 "b\x1fMSB\0",
1490 0x800f0701,
1491 34,
1492 "0x800f0701<LSB,NIBBLE2=0>\0"
1493 "0x800f0701<BURST=0xf=FIFTEEN,MSB>\0");
1494
1495 // new style, buffer too small for complete number in line 2
1496 h_snprintb_m_len(
1497 15,
1498 "\177\020"
1499 "b\000lsb\0"
1500 "b\001two\0",
1501 0xff,
1502 11,
1503 20,
1504 "0xff<lsb>\0"
1505 "0xf\0" // XXX: incomplete number may be misleading
1506 );
1507
1508 // new-style format, buffer too small for '<' in line 2
1509 h_snprintb_m_len(
1510 16,
1511 "\177\020"
1512 "b\000lsb\0"
1513 "b\001two\0",
1514 0xff,
1515 11,
1516 20,
1517 "0xff<lsb>\0"
1518 "0xff\0"
1519 );
1520
1521 // new-style format, buffer too small for fallback
1522 h_snprintb_m(
1523 "\177\020"
1524 "f\000\004bits\0"
1525 "*=fallback\0"
1526 "b\0024\0",
1527 0xff,
1528 64,
1529 "0xff<bits=0xf=fallback,4>\0"
1530 );
1531
1532 // new-style format, buffer too small for numeric fallback
1533 h_snprintb_m_len(
1534 20,
1535 "\177\020"
1536 "F\000\004\0"
1537 "*fallback(%040jd)\0",
1538 0xff,
1539 64,
1540 57,
1541 "0xff<fallback(0000\0"
1542 );
1543
1544 // new-style format, buffer too small for numeric fallback past buffer
1545 h_snprintb_m_len(
1546 15,
1547 "\177\020"
1548 "F\000\004\0"
1549 "*fallback(%010jd)\0"
1550 "F\004\004\0"
1551 "*fallback(%010jd)\0",
1552 0xff,
1553 64,
1554 48,
1555 "0xff<fallback\0"
1556 );
1557
1558 // new style, bits and fields, line break between fields
1559 h_snprintb_m(
1560 "\177\020"
1561 "b\0LSB\0"
1562 "b\1_BITONE\0"
1563 "f\4\4NIBBLE2\0"
1564 "f\x10\4BURST\0"
1565 "=\04FOUR\0"
1566 "=\17FIFTEEN\0"
1567 "b\x1fMSB\0",
1568 0x800f0701,
1569 33,
1570 "0x800f0701<LSB,NIBBLE2=0>\0"
1571 "0x800f0701<BURST=0xf=FIFTEEN,MSB>\0"
1572 );
1573
1574 // new style, bits and fields, line break after field description
1575 h_snprintb_m(
1576 "\177\020"
1577 "b\0LSB\0"
1578 "b\1_BITONE\0"
1579 "f\4\4NIBBLE2\0"
1580 "f\x10\4BURST\0"
1581 "=\04FOUR\0"
1582 "=\17FIFTEEN\0"
1583 "b\x1fMSB\0",
1584 0x800f0701,
1585 32,
1586 "0x800f0701<LSB,NIBBLE2=0>\0"
1587 "0x800f0701<BURST=0xf=FIFTEEN>\0"
1588 "0x800f0701<MSB>\0");
1589 }
1590
1591 ATF_TP_ADD_TCS(tp)
1592 {
1593
1594 ATF_TP_ADD_TC(tp, snprintb);
1595 ATF_TP_ADD_TC(tp, snprintb_m);
1596
1597 return atf_no_error();
1598 }
1599