#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_snprintb.c,v 1.42 2026/03/14 14:25:46 rillig Exp $");
#include <stdio.h>
#include <string.h>
#include <util.h>
#include <vis.h>
#include <atf-c.h>
static const char *
vis_arr(char *buf, size_t bufsize, const char *arr, size_t arrsize)
{
ATF_REQUIRE(bufsize >= 2);
int rv = strnvisx(buf + 1, bufsize - 2, arr, arrsize,
VIS_WHITE | VIS_OCTAL);
ATF_REQUIRE_MSG(rv >= 0, "buffer too small for size %zu", arrsize);
buf[0] = '"';
buf[1 + rv] = '"';
buf[1 + rv + 1] = '\0';
return buf;
}
static void
check_snprintb_m(const char *file, size_t line,
size_t bufsize, const char *bitfmt, size_t bitfmtlen,
uint64_t val, const char *val_str,
size_t line_max,
int want_rv, const char *want_buf, size_t want_bufsize)
{
char buf_with_padding[1026], vis_bitfmt[1024], vis_want_buf[1024], vis_buf[1024];
ATF_REQUIRE(bufsize <= sizeof(buf_with_padding) - 2);
ATF_REQUIRE(want_bufsize <= sizeof(buf_with_padding) - 2);
if (bitfmtlen > 2 && bitfmt[0] == '\177')
ATF_REQUIRE_MSG(
bitfmt[bitfmtlen - 1] == '\0',
"%s:%zu: missing trailing '\\0' in new-style bitfmt",
file, line);
ATF_CHECK_MSG(
strncmp(val_str, "0x", 2) == 0 || strcmp(val_str, "ch") == 0,
"%s:%zu: value \"%s\" must be hexadecimal", file, line, val_str);
ATF_CHECK_MSG(
((strlen(val_str) - 2) & (strlen(val_str) - 3)) == 0,
"%s:%zu: the number of digits in value \"%s\" must be a power of two", file, line, val_str);
if (bufsize == 0)
want_bufsize = 0;
memset(buf_with_padding, 0x5a, sizeof(buf_with_padding));
char *buf = buf_with_padding + 1;
int rv = snprintb_m(buf, bufsize, bitfmt, val, line_max);
size_t have_bufsize = sizeof(buf_with_padding) - 2;
while (have_bufsize > 0 && buf[have_bufsize - 1] == 0x5a)
have_bufsize--;
if (rv > 0 && (unsigned)rv < have_bufsize
&& buf[rv - 1] == '\0' && buf[rv] == '\0')
have_bufsize = rv + 1;
if (rv < 0)
for (size_t i = have_bufsize; i >= 2; i--)
if (buf[i - 2] == '\0' && buf[i - 1] == '\0')
have_bufsize = i;
ATF_CHECK_MSG(
buf_with_padding[0] == 0x5a,
"failed:\n"
"\ttest case: %s:%zu\n"
"\tout-of-bounds write before: %02x\n",
file, line,
(unsigned char)buf_with_padding[0]);
ATF_CHECK_MSG(
buf_with_padding[sizeof(buf_with_padding) - 1] == 0x5a,
"failed:\n"
"\ttest case: %s:%zu\n"
"\tout-of-bounds write after: %02x\n",
file, line,
(unsigned char)buf_with_padding[sizeof(buf_with_padding) - 1]);
ATF_CHECK_MSG(
rv == want_rv
&& memcmp(buf, want_buf, want_bufsize) == 0
&& (line_max == 0 || have_bufsize < 2
|| buf[have_bufsize - 2] == '\0')
&& (have_bufsize < 1 || buf[have_bufsize - 1] == '\0'),
"failed:\n"
"\ttest case: %s:%zu\n"
"\tformat: %s\n"
"\tvalue: %#jx\n"
"\tline_max: %zu\n"
"\twant: %d bytes %s\n"
"\thave: %d bytes %s\n",
file, line,
vis_arr(vis_bitfmt, sizeof(vis_bitfmt), bitfmt, bitfmtlen),
(uintmax_t)val,
line_max,
want_rv, vis_arr(vis_want_buf, sizeof(vis_want_buf),
want_buf, want_bufsize),
rv, vis_arr(vis_buf, sizeof(vis_buf), buf, have_bufsize));
}
#define h_snprintb_m_len(bufsize, bitfmt, val, line_max, \
want_rv, want_buf) \
check_snprintb_m(__FILE__, __LINE__, \
bufsize, bitfmt, sizeof(bitfmt) - 1, val, #val, line_max, \
want_rv, want_buf, sizeof(want_buf))
#define h_snprintb(bitfmt, val, want_buf) \
h_snprintb_m_len(1024, bitfmt, val, 0, sizeof(want_buf) - 1, want_buf)
#define h_snprintb_len(bufsize, bitfmt, val, want_rv, want_buf) \
h_snprintb_m_len(bufsize, bitfmt, val, 0, want_rv, want_buf)
#define h_snprintb_error(bitfmt, want_buf) \
h_snprintb_m_len(1024, bitfmt, 0x00, 0, -1, want_buf)
#define h_snprintb_val_error(bitfmt, val, want_buf) \
h_snprintb_m_len(1024, bitfmt, val, 0, -1, want_buf)
#define h_snprintb_m(bitfmt, val, line_max, want_buf) \
h_snprintb_m_len(1024, bitfmt, val, line_max, \
sizeof(want_buf) - 1, want_buf)
ATF_TC(snprintb);
ATF_TC_HEAD(snprintb, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks snprintb(3)");
}
ATF_TC_BODY(snprintb, tc)
{
h_snprintb(
"\010",
0x00,
"0");
h_snprintb(
"\010",
0xff,
"0377");
h_snprintb(
"\012",
0x00,
"0");
h_snprintb(
"\012",
0xff,
"255");
h_snprintb(
"\020",
0x00,
"0");
h_snprintb(
"\177\020",
0xff,
"0xff");
h_snprintb_error(
"",
"#");
h_snprintb_error(
"\002",
"#");
h_snprintb_error(
"\377",
"#");
h_snprintb(
"\177\010",
0x00,
"0");
h_snprintb(
"\177\010",
0xff,
"0377");
h_snprintb(
"\177\012",
0x00,
"0");
h_snprintb(
"\177\012",
0xff,
"255");
h_snprintb(
"\177\020",
0x00,
"0");
h_snprintb(
"\177\020",
0xff,
"0xff");
h_snprintb_error(
"\177",
"#");
h_snprintb_error(
"\177\002",
"#");
h_snprintb_error(
"\177\377",
"#");
h_snprintb(
"\020"
"\001bit1"
"\002bit2"
"\037bit31"
"\040bit32",
0xffffffff80000001,
"0xffffffff80000001<bit1,bit32>");
h_snprintb_error(
"\020"
"\041invalid",
"0#");
h_snprintb(
"\020"
"\001bit1"
"\041bit33",
0x01,
"0x1<bit1!bit33>");
h_snprintb(
"\020"
"\001once"
"\001again",
0x01,
"0x1<once,again>");
h_snprintb(
"\020"
"\001least significant"
"\002horizontal\ttab"
"\003\xC3\xA4",
0xff,
"0xff<least,horizontal,\xC3\xA4>");
h_snprintb_val_error(
"\020"
"\001lsb"
"\004"
"\005"
"\010msb",
0xff,
"0xff<lsb#");
int null_rv_old = snprintb(NULL, 0, "\020\001lsb", 0x01);
ATF_CHECK_MSG(
null_rv_old == 8,
"want length 8, have %d", null_rv_old);
h_snprintb_len(
1, "\020", 0x00,
1, "");
h_snprintb_len(
2, "\020", 0x00,
1, "0");
h_snprintb_len(
3, "\020", 0x07,
3, "0#");
h_snprintb_len(
4, "\020", 0x07,
3, "0x7");
h_snprintb_len(
4, "\020\001lsb", 0x07,
8, "0x#");
h_snprintb_len(
7, "\020\001lsb", 0x07,
8, "0x7<l#");
h_snprintb_len(
8, "\020\001lsb", 0x07,
8, "0x7<ls#");
h_snprintb_len(
9, "\020\001lsb", 0x07,
8, "0x7<lsb>");
h_snprintb_len(
9, "\020\001one\002two", 0x07,
12, "0x7<one#");
h_snprintb_len(
10, "\020\001one\002two", 0x07,
12, "0x7<one,#");
h_snprintb_len(
12, "\020\001one\002two", 0x07,
12, "0x7<one,tw#");
h_snprintb_len(
13, "\020\001one\002two", 0x07,
12, "0x7<one,two>");
int null_rv_new = snprintb(NULL, 0, "\177\020b\000lsb\0", 0x01);
ATF_CHECK_MSG(
null_rv_new == 8,
"want length 8, have %d", null_rv_new);
h_snprintb(
"\177\020"
"b\000lsb\0"
"b\001above-lsb\0"
"b\037bit31\0"
"b\040bit32\0"
"b\076below-msb\0"
"b\077msb\0",
0x8000000180000001,
"0x8000000180000001<lsb,bit31,bit32,msb>");
h_snprintb(
"\177\020"
"b\000lsb\0"
"b\000lsb\0"
"b\000lsb\0",
0xff,
"0xff<lsb,lsb,lsb>");
h_snprintb_val_error(
"\177\020"
"b\000lsb\0"
"b\001\0"
"b\002\0"
"b\007msb\0",
0xff,
"0xff<lsb#");
h_snprintb_error(
"\177\020"
"b\100too-high\0",
"0#");
h_snprintb_error(
"\177\020"
"b\377too-high\0",
"0#");
h_snprintb(
"\177\020"
"b\000space \t \xC3\xA4\0",
0x1,
"0x1<space \t \xC3\xA4>");
h_snprintb(
"\177\010"
"f\000\010byte0\0"
"f\010\010byte1\0",
0x0100,
"0400<byte0=0,byte1=01>");
h_snprintb(
"\177\012"
"f\000\010byte0\0"
"f\010\010byte1\0",
0x0100,
"256<byte0=0,byte1=1>");
h_snprintb(
"\177\020"
"f\000\010byte0\0"
"f\010\010byte1\0",
0x0100,
"0x100<byte0=0,byte1=0x1>");
h_snprintb(
"\177\020"
"f\000\000zero-width\0"
"=\000zero\0",
0xffff,
"0xffff<zero-width=0=zero>");
h_snprintb(
"\177\020"
"f\000\001lsb\0"
"=\000zero\0"
"=\001one\0",
0x0,
"0<lsb=0=zero>");
h_snprintb(
"\177\020"
"f\000\001lsb\0"
"=\000zero\0"
"=\001one\0",
0x1,
"0x1<lsb=0x1=one>");
h_snprintb(
"\177\020"
"f\000\077uint63\0"
"=\125match\0",
0xaaaa5555aaaa5555,
"0xaaaa5555aaaa5555<uint63=0x2aaa5555aaaa5555>");
h_snprintb(
"\177\020"
"f\000\100uint64\0"
"=\125match\0",
0xaaaa5555aaaa5555,
"0xaaaa5555aaaa5555<uint64=0xaaaa5555aaaa5555>");
h_snprintb_error(
"\177\020"
"f\000\101uint65\0",
"0#");
h_snprintb(
"\177\020"
"f\001\010uint8\0"
"=\203match\0",
0x0106,
"0x106<uint8=0x83=match>");
h_snprintb(
"\177\020"
"f\001\011uint9\0"
"=\203match\0"
"*=default-f\0"
"F\001\011\0"
":\203match\0"
"*default-F\0",
0x0306,
"0x306<uint9=0x183=default-f,default-F>");
h_snprintb(
"\177\020"
"f\030\040uint32\0",
0xaaaa555500000000,
"0xaaaa555500000000<uint32=0xaa555500>");
h_snprintb(
"\177\020"
"f\074\004uint4\0",
0xf555555555555555,
"0xf555555555555555<uint4=0xf>");
h_snprintb(
"\177\020"
"f\074\005uint5\0",
0xf555555555555555,
"0xf555555555555555<uint5=0xf>");
h_snprintb_error(
"\177\020"
"f\100\000uint0\0",
"0#");
h_snprintb_error(
"\177\020"
"f\101\000uint0\0",
"0#");
h_snprintb_val_error(
"\177\020"
"f\000\004\0"
"=\001one\0",
0x1,
"0x1#");
h_snprintb(
"\177\020"
"f\000\010\t \xC3\xA4\0"
"=\001\t \xC3\xA4\0"
"F\000\010\0"
":\001\t \xC3\xA4\0"
"F\000\010\0"
"*\t \xC3\xA4\0",
0x1,
"0x1<\t \xC3\xA4=0x1=\t \xC3\xA4,\t \xC3\xA4,\t \xC3\xA4>");
h_snprintb_val_error(
"\177\020"
"f\000\004f\0"
"=\001one\0"
"=\001\0"
"=\001\0",
0x1,
"0x1<f=0x1=one#");
h_snprintb_val_error(
"\177\020"
"F\000\004\0"
":\001\0"
"*default\0",
0x1,
"0x1<#");
h_snprintb_val_error(
"\177\020"
"F\000\004\0"
":\001\0"
"*default\0",
0x2,
"0x2<#");
h_snprintb(
"\177\020"
"f\000\004Field\0"
"=\1one\0"
"=\2two\0",
0x3,
"0x3<Field=0x3>");
h_snprintb(
"\177\020"
"F\000\004\0"
":\1one\0"
":\2two\0",
0x3,
"0x3<>");
h_snprintb(
"\177\020"
"b\000bit0\0"
"F\000\004\0"
":\1one\0"
":\2two\0"
"b\001bit1\0",
0x3,
"0x3<bit0,,bit1>");
h_snprintb(
"\177\020"
"F\000\004\0"
":\017m1\0"
":\017match\0",
0xff,
"0xff<m1match>");
h_snprintb(
"\177\020"
"f\000\007f\0"
"=\200never\0"
"=\377never\0",
0xff,
"0xff<f=0x7f>");
h_snprintb(
"\177\020"
"f\000\004f1\0"
"=\001one\0"
"=\002two\0"
"f\004\004f2\0"
"=\001one\0"
"=\002two\0",
0x12,
"0x12<f1=0x2=two,f2=0x1=one>");
h_snprintb(
"\177\020"
"f\000\004f1\0"
"=\001one\0"
"=\002two\0"
"F\010\004\0"
":\015thirteen\0"
"f\004\004f2\0"
"=\001one\0"
"=\002two\0",
0x0d12,
"0xd12<f1=0x2=two,thirteen,f2=0x1=one>");
h_snprintb(
"\177\020"
"f\000\004lo\0"
"f\002\004mid\0"
"f\004\004hi\0"
"f\000\010all\0",
0x18,
"0x18<lo=0x8,mid=0x6,hi=0x1,all=0x18>");
h_snprintb(
"\177\020"
"f\000\004field\0"
"=\010f-value\0"
"F\000\000\0"
":\000separator\0"
"F\000\004\0"
":\010F-value\0",
0x18,
"0x18<field=0x8=f-value,separator,F-value>");
h_snprintb(
"\177\020"
"f\030\010f1\0"
"*default-f\0"
"f\020\010f2\0"
"*=default-f\0"
"F\010\010\0"
"*default-F\0"
"F\010\010\0"
"*=default-F\0",
0x11223344,
"0x11223344<f1=0x11default-f,f2=0x22=default-f,default-F,=default-F>");
h_snprintb(
"\177\020"
"f\010\010f\0"
"*=f(%ju)\0"
"F\000\010F\0"
"*F(%ju)\0",
0x1122,
"0x1122<f=0x11=f(17),F(34)>");
h_snprintb(
"\177\020"
"f\010\002f\0"
"=\000zero\0"
"=\001one\0"
"=\002two\0"
"=\003three\0"
"*default\0",
0xff00,
"0xff00<f=0x3=three>");
h_snprintb(
"\177\020"
"f\000\010f\0"
"*=%030ju%%\0",
0xff,
"0xff<f=0xff=000000000000000000000000000255%>");
h_snprintb_val_error(
"\177\020"
"unknown\0",
0xff,
"0xff#");
h_snprintb_val_error(
"\177\020"
"b\007msb\0"
"unknown\0",
0xff,
"0xff<msb#");
h_snprintb_val_error(
"\177\020"
"b\004bit4\0"
"=\000clear\0"
"=\001set\0"
"=\245complete\0"
"b\000bit0\0"
"=\000clear\0"
"=\001set\0"
"=\245complete\0",
0xa5,
"0xa5#");
h_snprintb_val_error(
"\177\020"
"b\004bit4\0"
":\000clear\0"
":\001set\0"
":\245complete\0"
"b\000bit0\0"
":\000clear\0"
":\001set\0"
":\245complete\0",
0xa5,
"0xa5#");
h_snprintb_val_error(
"\177\020"
"b\004bit4\0"
"*default(%ju)\0"
"b\000bit0\0"
"*default(%ju)\0",
0xa5,
"0xa5#");
h_snprintb_val_error(
"\177\020"
"f\000\010f\0"
"b\005bit5\0"
"=\245match\0",
0xa5,
"0xa5<f=0xa5,bit5#");
h_snprintb_val_error(
"\177\020"
"F\000\010f\0"
"b\005bit5\0"
":\245match\0",
0xa5,
"0xa5<,bit5#");
h_snprintb(
"\177\20"
"f\000\004nibble\0"
":\001one\0",
0x01,
"0x1<nibble=0x1one>");
h_snprintb(
"\177\20"
"f\000\002field\0" ":\0(zero)\0"
"f\000\002field\0" "*(catch-all)\0",
0x0000,
"0<field=0(zero),field=0(catch-all)>");
h_snprintb(
"\177\20"
"F\000\004\0"
"=\001one\0",
0x01,
"0x1<=one>");
h_snprintb(
"\177\20"
"F\0\2CKS\0"
"*CKS\0"
"=\0" "1/4\0",
0x00,
"0<CKS=1/4>");
h_snprintb_val_error(
"\177\020"
"=\245match\0",
0xa5,
"0xa5#");
h_snprintb_val_error(
"\177\020"
":\245match\0",
0xa5,
"0xa5#");
h_snprintb_val_error(
"\177\020"
"*match\0",
0xa5,
"0xa5#");
h_snprintb(
"\177\020"
"f\000\010f\0"
"*=default\0"
"=\245match\0",
0xa5,
"0xa5<f=0xa5=default=match>");
h_snprintb(
"\177\020"
"F\000\010F\0"
"*default\0"
":\xa5-match\0",
0xa5,
"0xa5<default-match>");
h_snprintb(
"\177\020"
"f\000\010f\0"
"*=default-f\0"
"*ignored\0",
0xa5,
"0xa5<f=0xa5=default-f>");
h_snprintb(
"\177\020"
"F\000\010\0"
"*default-F\0"
"*ignored\0",
0xa5,
"0xa5<default-F>");
h_snprintb(
"\177\020"
"f\000\004field\0"
"=\017m1\0"
"=\017match\0",
0xff,
"0xff<field=0xf=m1=match>");
h_snprintb(
"\010\002BITTWO\001BITONE",
0x03,
"03<BITTWO,BITONE>");
h_snprintb(
"\x10"
"\x10" "NOTBOOT"
"\x0f" "FPP"
"\x0e" "SDVMA"
"\x0c" "VIDEO"
"\x0b" "LORES"
"\x0a" "FPA"
"\x09" "DIAG"
"\x07" "CACHE"
"\x06" "IOCACHE"
"\x05" "LOOPBACK"
"\x04" "DBGCACHE",
0xe860,
"0xe860<NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE>");
h_snprintb(
"\177\020"
"b\000" "LSB\0"
"b\001" "BITONE\0"
"f\004\004" "NIBBLE2\0"
"f\020\004" "BURST\0"
"=\x04" "FOUR\0"
"=\x0f" "FIFTEEN\0"
"b\037" "MSB\0",
0x800f0701,
"0x800f0701<LSB,NIBBLE2=0,BURST=0xf=FIFTEEN,MSB>");
#define MAP_FMT \
"\177\020" \
"b\0" "SHARED\0" \
"b\1" "PRIVATE\0" \
"b\2" "COPY\0" \
"b\4" "FIXED\0" \
"b\5" "RENAME\0" \
"b\6" "NORESERVE\0" \
"b\7" "INHERIT\0" \
"b\11" "HASSEMAPHORE\0" \
"b\12" "TRYFIXED\0" \
"b\13" "WIRED\0" \
"F\14\1\0" \
":\0" "FILE\0" \
":\1" "ANONYMOUS\0" \
"b\15" "STACK\0" \
"F\30\010\0" \
":\000" "ALIGN=NONE\0" \
":\015" "ALIGN=8KB\0" \
"*" "ALIGN=2^%ju\0"
h_snprintb(
MAP_FMT,
0x0d001234,
"0xd001234<COPY,FIXED,RENAME,HASSEMAPHORE,ANONYMOUS,ALIGN=8KB>");
h_snprintb(
MAP_FMT,
0x2e000000,
"0x2e000000<FILE,ALIGN=2^46>");
for (char ch = 'A'; ch <= '~'; ch++) {
char rot13 = ch >= 'a' && ch <= 'm' ? ch + 13
: ch >= 'n' && ch <= 'z' ? ch - 13
: '?';
char expected[8];
ATF_REQUIRE_EQ(7,
snprintf(expected, sizeof(expected), "%#x<%c>", ch, rot13));
h_snprintb(
"\177\020"
"F\000\010\0"
":an\0:bo\0:cp\0:dq\0:er\0:fs\0:gt\0:hu\0"
":iv\0:jw\0:kx\0:ly\0:mz\0"
":na\0:ob\0:pc\0:qd\0:re\0:sf\0:tg\0:uh\0"
":vi\0:wj\0:xk\0:yl\0:zm\0"
"*?\0",
ch,
expected);
}
h_snprintb_len(
0, "\177\020", 0x00,
1, "");
h_snprintb_len(
1, "\177\020", 0x00,
1, "");
h_snprintb_len(
2, "\177\020", 0x00,
1, "0");
h_snprintb_len(
3, "\177\020", 0x00,
1, "0");
h_snprintb_len(
3, "\177\020", 0x07,
3, "0#");
h_snprintb_len(
4, "\177\020", 0x07,
3, "0x7");
h_snprintb_len(
7, "\177\020b\000lsb\0", 0x07,
8, "0x7<l#");
h_snprintb_len(
8, "\177\020b\000lsb\0", 0x07,
8, "0x7<ls#");
h_snprintb_len(
9, "\177\020b\000lsb\0", 0x07,
8, "0x7<lsb>");
h_snprintb_len(
9, "\177\020b\000one\0b\001two\0", 0x07,
12, "0x7<one#");
h_snprintb_len(
10, "\177\020b\000one\0b\001two\0", 0x07,
12, "0x7<one,#");
h_snprintb_len(
12, "\177\020b\000one\0b\001two\0", 0x07,
12, "0x7<one,tw#");
h_snprintb_len(
13, "\177\020b\000one\0b\001two\0", 0x07,
12, "0x7<one,two>");
}
ATF_TC(snprintb_m);
ATF_TC_HEAD(snprintb_m, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks snprintb_m(3)");
}
ATF_TC_BODY(snprintb_m, tc)
{
h_snprintb_m(
"\020",
0xff,
1,
"#\0");
h_snprintb_m(
"\020"
"\001lsb",
0xff,
4,
"0xf#\0");
h_snprintb_m(
"\020"
"\001bit1"
"\002bit2",
0xff,
7,
"0xff<b#\0"
"0xff<b#\0");
h_snprintb_m(
"\020"
"\001bit1"
"\0022",
0xff,
9,
"0xff<bit#\0"
"0xff<2>\0");
h_snprintb_m(
"\020"
"\0011"
"\002bit2",
0xff,
8,
"0xff<1>\0"
"0xff<bi#\0");
h_snprintb_m(
"\020"
"\0011"
"\002bit2",
0xff,
9,
"0xff<1>\0"
"0xff<bit#\0");
h_snprintb_m(
"\020"
"\0011"
"\002bit2",
0xff,
10,
"0xff<1>\0"
"0xff<bit2>\0");
h_snprintb_m(
"\177\020",
0xff,
3,
"0x#\0");
h_snprintb_m(
"\177\020"
"b\000bit\0",
0xff,
4,
"0xf#\0");
h_snprintb_m(
"\177\020"
"b\000bit0\0"
"b\001two\0",
0xff,
8,
"0xff<bi#\0"
"0xff<tw#\0");
h_snprintb_m(
"\177\020"
"b\000bit0\0"
"b\001two\0",
0xff,
9,
"0xff<bit#\0"
"0xff<two>\0");
h_snprintb_m(
"\177\020"
"b\000one\0"
"b\001three\0",
0xff,
9,
"0xff<one>\0"
"0xff<thr#\0");
h_snprintb_m(
"\177\020"
"b\000one\0"
"b\001three\0",
0xff,
10,
"0xff<one>\0"
"0xff<thre#\0");
h_snprintb_m(
"\177\020"
"b\000one\0"
"b\001three\0",
0xff,
11,
"0xff<one>\0"
"0xff<three>\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0",
0xff,
3,
"0x#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0",
0xff,
4,
"0xf#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0",
0xff,
6,
"0xff<#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0",
0xff,
7,
"0xff<l#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0",
0xff,
10,
"0xff<lo=0#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"=\017match\0",
0xff,
12,
"0xff<lo=0xf#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"=\017match\0",
0xff,
16,
"0xff<lo=0xf=mat#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"=\017match\0",
0xff,
17,
"0xff<lo=0xf=matc#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"f\000\004low-bits\0"
"=\017match\0",
0xff,
12,
"0xff<lo=0xf>\0"
"0xff<low-bi#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"f\000\004low-bits\0"
"=\017match\0",
0xff,
13,
"0xff<lo=0xf>\0"
"0xff<low-bit#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"f\000\004low-bits\0"
"=\017match\0",
0xff,
16,
"0xff<lo=0xf>\0"
"0xff<low-bits=0#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"f\000\004low-bits\0"
"=\017match\0",
0xff,
18,
"0xff<lo=0xf>\0"
"0xff<low-bits=0xf#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"f\000\004low-bits\0"
"=\017match\0",
0xff,
22,
"0xff<lo=0xf>\0"
"0xff<low-bits=0xf=mat#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"f\000\004low-bits\0"
"=\017match\0",
0xff,
23,
"0xff<lo=0xf>\0"
"0xff<low-bits=0xf=matc#\0");
h_snprintb_m(
"\177\020"
"f\000\004lo\0"
"f\000\004low-bits\0"
"=\017match\0",
0xff,
24,
"0xff<lo=0xf>\0"
"0xff<low-bits=0xf=match>\0");
h_snprintb_m(
"\177\020"
"F\000\004\0",
0xff,
3,
"0x#\0");
h_snprintb_m(
"\177\020"
"F\000\004\0",
0xff,
4,
"0xf#\0");
h_snprintb_m(
"\177\020"
"F\000\004\0"
":\017match\0",
0xff,
9,
"0xff<mat#\0");
h_snprintb_m(
"\177\020"
"F\000\004\0"
":\017match\0",
0xff,
10,
"0xff<matc#\0");
h_snprintb_m(
"\177\020"
"F\000\004\0"
":\017m1\0"
":\017match\0",
0xff,
10,
"0xff<m1ma#\0");
h_snprintb_m(
"\177\020"
"F\000\004\0"
":\017m1\0"
":\017match\0",
0xff,
12,
"0xff<m1matc#\0");
h_snprintb_m(
"\177\020"
"F\000\004\0"
":\017m1\0"
":\017match\0",
0xff,
13,
"0xff<m1match>\0");
h_snprintb_m(
"\177\020"
"f\000\004f\0"
"*=default\0",
0xff,
17,
"0xff<f=0xf=defau#\0");
h_snprintb_m(
"\177\020"
"f\000\004bits\0"
"=\000zero\0",
0xff,
11,
"0xff<bits=#\0");
h_snprintb_m(
"\177\020"
"b\000" "LSB\0"
"b\001" "BITONE\0"
"f\004\004" "NIBBLE2\0"
"f\020\004" "BURST\0"
"=\x04" "FOUR\0"
"=\x0f" "FIFTEEN\0"
"b\037" "MSB\0",
0x800f0701,
34,
"0x800f0701<LSB,NIBBLE2=0>\0"
"0x800f0701<BURST=0xf=FIFTEEN,MSB>\0");
h_snprintb_m_len(
1024,
"\177",
0xff,
128,
-1,
"#\0");
h_snprintb_m_len(
15,
"\177\020"
"b\000lsb\0"
"b\001two\0",
0xff,
11,
20,
"0xff<lsb>\0"
"0x#\0");
h_snprintb_m_len(
16,
"\177\020"
"b\000lsb\0"
"b\001two\0",
0xff,
11,
20,
"0xff<lsb>\0"
"0xf#\0");
h_snprintb_m_len(
24,
"\177\020"
"f\000\004bits\0"
"*=fallback\0"
"b\0024\0",
0xff,
64,
26,
"0xff<bits=0xf=fallbac#\0");
h_snprintb_m_len(
20,
"\177\020"
"F\000\004\0"
"*fallback(%040jd)\0",
0xff,
64,
57,
"0xff<fallback(000#\0");
h_snprintb_m_len(
15,
"\177\020"
"F\000\004\0"
"*fallback(%010jd)\0"
"F\004\004\0"
"*fallback(%010jd)\0",
0xff,
64,
48,
"0xff<fallbac#\0");
h_snprintb_m(
"\177\020"
"b\0LSB\0"
"b\1_BITONE\0"
"f\4\4NIBBLE2\0"
"f\x10\4BURST\0"
"=\04FOUR\0"
"=\17FIFTEEN\0"
"b\x1fMSB\0",
0x800f0701,
33,
"0x800f0701<LSB,NIBBLE2=0>\0"
"0x800f0701<BURST=0xf=FIFTEEN,MSB>\0");
h_snprintb_m(
"\177\020"
"b\0LSB\0"
"b\1_BITONE\0"
"f\4\4NIBBLE2\0"
"f\020\4BURST\0"
"=\04FOUR\0"
"=\17FIFTEEN\0"
"b\037MSB\0",
0x800f0701,
32,
"0x800f0701<LSB,NIBBLE2=0>\0"
"0x800f0701<BURST=0xf=FIFTEEN>\0"
"0x800f0701<MSB>\0");
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, snprintb);
ATF_TP_ADD_TC(tp, snprintb_m);
return atf_no_error();
}