/* $NetBSD: t_snprintb.c,v 1.36 2024/04/08 21:28:35 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. * All rights reserved. * * This code was contributed to The NetBSD Foundation by Christos Zoulas and * Roland Illig. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_snprintb.c,v 1.36 2024/04/08 21:28:35 rillig Exp $"); #include #include #include #include #include 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, size_t line_max, int want_rv, const char *want_buf, size_t want_bufsize) { char buf[1024], vis_bitfmt[1024], vis_want_buf[1024], vis_buf[1024]; ATF_REQUIRE(bufsize <= sizeof(buf)); ATF_REQUIRE(want_bufsize <= sizeof(buf)); if (bitfmtlen > 2 && bitfmt[0] == '\177') ATF_REQUIRE_MSG( bitfmt[bitfmtlen - 1] == '\0', "%s:%zu: missing trailing '\\0' in new-style bitfmt", file, line); if (bufsize == 0) want_bufsize = 0; memset(buf, 0x5a, sizeof(buf)); int rv = snprintb_m(buf, bufsize, bitfmt, val, line_max); size_t have_bufsize = sizeof(buf); 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( 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, 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) { // style and number base, old style, octal, zero value // // The value 0 does not get a leading '0'. h_snprintb( "\010", 0x00, "0"); // style and number base, old style, octal, nonzero value // // Nonzero octal values get a leading '0'. h_snprintb( "\010", 0xff, "0377"); // style and number base, old style, decimal, zero value h_snprintb( "\012", 0x00, "0"); // style and number base, old style, decimal, nonzero value h_snprintb( "\012", 0xff, "255"); // style and number base, old style, hexadecimal, zero value // // The value 0 does not get a leading '0x'. h_snprintb( "\020", 0x00, "0"); // style and number base, old style, hexadecimal, nonzero value // // Nonzero hexadecimal values get a leading '0x'. h_snprintb( "\177\020", 0xff, "0xff"); // style and number base, old style, invalid base 0 h_snprintb_error( "", "#"); // style and number base, old style, invalid base 2 h_snprintb_error( "\002", "#"); // style and number base, old style, invalid base 255 or -1 h_snprintb_error( "\377", "#"); // style and number base, new style, octal, zero value // // The value 0 does not get a leading '0'. h_snprintb( "\177\010", 0x00, "0"); // style and number base, new style, octal, nonzero value // // Nonzero octal values get a leading '0'. h_snprintb( "\177\010", 0xff, "0377"); // style and number base, new style, decimal, zero value h_snprintb( "\177\012", 0x00, "0"); // style and number base, new style, decimal, nonzero value h_snprintb( "\177\012", 0xff, "255"); // style and number base, new style, hexadecimal, zero value // // The value 0 does not get a leading '0x'. h_snprintb( "\177\020", 0x00, "0"); // style and number base, new style, hexadecimal, nonzero value // // Nonzero hexadecimal values get a leading '0x'. h_snprintb( "\177\020", 0xff, "0xff"); // style and number base, new style, invalid number base 0 h_snprintb_error( "\177", "#"); // style and number base, new style, invalid number base 2 h_snprintb_error( "\177\002", "#"); // style and number base, new style, invalid number base 255 or -1 h_snprintb_error( "\177\377", "#"); // old style, from lsb to msb h_snprintb( "\020" "\001bit1" "\002bit2" "\037bit31" "\040bit32", 0xffffffff80000001, "0xffffffff80000001"); // old style, invalid bit number, at the beginning h_snprintb_error( "\020" "\041invalid", "0#"); // old style, invalid bit number, in the middle // // The old-style format supports only 32 bits, interpreting the // \041 as part of the text belonging to bit 1. h_snprintb( "\020" "\001bit1" "\041bit33", 0x01, "0x1"); // old style, repeated bit numbers // // When a bit number is mentioned more than once, // this is most likely a typo. h_snprintb( "\020" "\001once" "\001again", 0x01, "0x1"); // old style, non-printable description // // The characters ' ' and '\t' are interpreted as bit numbers, // not as part of the description; the visual arrangement in this // example is intentionally misleading. h_snprintb( "\020" "\001least significant" "\002horizontal\ttab" "\003\xC3\xA4", 0xff, "0xff"); // old style, empty description // // The description of a bit in the old format must not be empty, // to prevent multiple commas in a row. h_snprintb_val_error( "\020" "\001lsb" "\004" "\005" "\010msb", 0xff, "0xff' h_snprintb_len( 8, "\020\001lsb", 0x07, 8, "0x7' h_snprintb_len( 9, "\020\001lsb", 0x07, 8, "0x7"); // old style, buffer too small for second description h_snprintb_len( 9, "\020\001one\002two", 0x07, 12, "0x7' after second description h_snprintb_len( 12, "\020\001one\002two", 0x07, 12, "0x7' after second description h_snprintb_len( 13, "\020\001one\002two", 0x07, 12, "0x7"); // new style, buffer size 0, null buffer // // If the buffer size is 0, the buffer may be NULL. 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); // new style single bits 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"); // new style single bits, duplicate bits h_snprintb( "\177\020" "b\000lsb\0" "b\000lsb\0" "b\000lsb\0", 0xff, "0xff"); // new style single bits, 'b' with empty description // // The description of a 'b' conversion must not be empty, as the // output would contain several commas in a row. h_snprintb_val_error( "\177\020" "b\000lsb\0" "b\001\0" "b\002\0" "b\007msb\0", 0xff, "0xff"); // new style named bit-field, octal // // The bit-field value gets a leading '0' iff it is nonzero. h_snprintb( "\177\010" "f\000\010byte0\0" "f\010\010byte1\0", 0x0100, "0400"); // new style named bit-field, decimal h_snprintb( "\177\012" "f\000\010byte0\0" "f\010\010byte1\0", 0x0100, "256"); // new style named bit-field, hexadecimal // // The bit-field value gets a leading '0x' iff it is nonzero. h_snprintb( "\177\020" "f\000\010byte0\0" "f\010\010byte1\0", 0x0100, "0x100"); // new style bit-field, from 0 width 0 h_snprintb( "\177\020" "f\000\000zero-width\0" "=\000zero\0", 0xffff, "0xffff"); // new style bit-field, from 0 width 1 h_snprintb( "\177\020" "f\000\001lsb\0" "=\000zero\0" "=\001one\0", 0x0, "0"); h_snprintb( "\177\020" "f\000\001lsb\0" "=\000zero\0" "=\001one\0", 0x1, "0x1"); // new style bit-field, from 0 width 63 h_snprintb( "\177\020" "f\000\077uint63\0" "=\125match\0", 0xaaaa5555aaaa5555, "0xaaaa5555aaaa5555"); // new style bit-field, from 0 width 64 h_snprintb( "\177\020" "f\000\100uint64\0" "=\125match\0", 0xaaaa5555aaaa5555, "0xaaaa5555aaaa5555"); // new style bit-field, from 0 width 65 h_snprintb_error( "\177\020" "f\000\101uint65\0", "0#"); // new style bit-field, from 1 width 8 h_snprintb( "\177\020" "f\001\010uint8\0" "=\203match\0", 0x0106, "0x106"); // new style bit-field, from 1 width 9 // // The '=' and ':' directives can match a bit-field value between // 0 and 255, independent of the bit-field's width. h_snprintb( "\177\020" "f\001\011uint9\0" "=\203match\0" "*=default-f\0" "F\001\011\0" ":\203match\0" "*default-F\0", 0x0306, "0x306"); // new style bit-field, from 24 width 32 h_snprintb( "\177\020" "f\030\040uint32\0", 0xaaaa555500000000, "0xaaaa555500000000"); // new style bit-field, from 60 width 4 h_snprintb( "\177\020" "f\074\004uint4\0", 0xf555555555555555, "0xf555555555555555"); // new style bit-field, from 60 width 5 // // The end of the bit-field is out of bounds. h_snprintb( "\177\020" "f\074\005uint5\0", 0xf555555555555555, "0xf555555555555555"); // new style bit-field, from 64 width 0 // // The beginning of the bit-field is out of bounds, the end is fine. h_snprintb_error( "\177\020" "f\100\000uint0\0", "0#"); // new style bit-field, from 65 width 0 // // The beginning and end of the bit-field are out of bounds. h_snprintb_error( "\177\020" "f\101\000uint0\0", "0#"); // new style bit-field, 'f' with empty description // // The description of an 'f' conversion must not be empty, as the // output would contain an isolated '='. h_snprintb_val_error( "\177\020" "f\000\004\0" "=\001one\0", 0x1, "0x1#"); // new style bit-field, non-printable description // // Contrary to the old-style format, the new-style format allows // arbitrary characters in the description, even control characters // and non-ASCII characters. 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>"); // new style bit-field, '=' with empty description // // The description of a '=' conversion must not be empty, as the // output would contain several '=' in a row. h_snprintb_val_error( "\177\020" "f\000\004f\0" "=\001one\0" "=\001\0" "=\001\0", 0x1, "0x1"); // new style bit-field, 'F' with non-exhaustive ':' // // A bit-field that does not match any values generates multiple commas // in a row, which looks confusing. The ':' conversions should either be // exhaustive, or there should be a '*' catch-all conversion. h_snprintb( "\177\020" "b\000bit0\0" "F\000\004\0" ":\1one\0" ":\2two\0" "b\001bit1\0", 0x3, "0x3"); // new style bit-field, '=', can never match // // The extracted value from the bit-field has 7 bits and is thus less // than 128, therefore it can neither match 128 nor 255. h_snprintb( "\177\020" "f\000\007f\0" "=\200never\0" "=\377never\0", 0xff, "0xff"); // new style, two separate bit-fields h_snprintb( "\177\020" "f\000\004f1\0" "=\001one\0" "=\002two\0" "f\004\004f2\0" "=\001one\0" "=\002two\0", 0x12, "0x12"); // new style, mixed named and unnamed bit-fields 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"); // new style bit-field, overlapping h_snprintb( "\177\020" "f\000\004lo\0" "f\002\004mid\0" "f\004\004hi\0" "f\000\010all\0", 0x18, "0x18"); // new style bit-field, difference between '=' and ':' // // The ':' conversion can almost emulate the '=' conversion, without the // numeric output and with a different separator. It's best to use // either 'f' with '=', or 'F' with ':', but not mix them. h_snprintb( "\177\020" "f\000\004field\0" "=\010f-value\0" "F\000\000\0" // Use an empty bit-field ":\000separator\0" // to generate a separator. "F\000\004\0" ":\010F-value\0", 0x18, "0x18"); // new style bit-field default, fixed string // // The 'f' conversion pairs up with the '=' conversion, // the 'F' conversion pairs up with the ':' conversion, // but there's only one 'default' conversion for both variants, // so its description should include the '=' when used with 'f' but // not with 'F'. h_snprintb( "\177\020" "f\030\010f1\0" "*default\0" "f\020\010f2\0" "*=default\0" "F\010\010\0" "*default\0" "F\010\010\0" "*=default\0", 0x11223344, "0x11223344"); // new style bit-field default, numeric conversion specifier h_snprintb( "\177\020" "f\010\010f\0" "*=f(%ju)\0" "F\000\010F\0" "*F(%ju)\0", 0x1122, "0x1122"); // new style bit-field default, can never match // // The '=' conversion are exhaustive, making the '*' redundant. h_snprintb( "\177\020" "f\010\002f\0" "=\000zero\0" "=\001one\0" "=\002two\0" "=\003three\0" "*default\0", 0xff00, "0xff00"); // new style bit-field default, invalid conversion specifier // // There is no reliable way to make snprintf return an error, as such // errors are defined as undefined behavior in the C standard. // Instead, here's a conversion specifier that produces a literal '%'. h_snprintb( "\177\020" "f\000\010f\0" "*=%030ju%%\0", 0xff, "0xff"); // new style unknown conversion, at the beginning h_snprintb_val_error( "\177\020" "unknown\0", 0xff, "0xff#"); // new style unknown conversion, after a known conversion h_snprintb_val_error( "\177\020" "b\007msb\0" "unknown\0", 0xff, "0xff"); // example from the manual page, old style hexadecimal // // When using a hexadecimal escape sequence to encode a bit number, // the description must not start with a hexadecimal digit, or that // digit is interpreted as part of the bit number. To prevent this, // the bit number and the description need to be written as separate // string literals. 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"); // example from the manual page, new style bits and fields 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"); // example from the manual page, new style mmap #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"); h_snprintb( MAP_FMT, 0x2e000000, "0x2e000000"); // It is possible but cumbersome to implement a reduced variant of // rot13 using snprintb, shown here for lowercase letters only. 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" // If snprintf accepted "%jc", it would be possible to // echo the non-alphabetic characters instead of a // catchall question mark. "*?\0", ch, expected); } // new style, small buffers 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"); h_snprintb_len( 9, "\177\020b\000one\0b\001two\0", 0x07, 12, "0x7"); } 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) { // old style, line_max exceeded by number in line 1 h_snprintb_m( "\020", 0xff, 1, "#\0"); // old style, line_max exceeded by '<' in line 1 h_snprintb_m( "\020" "\001lsb", 0xff, 4, "0xf#\0"); // old style, line_max exceeded by description h_snprintb_m( "\020" "\001bit1" "\002bit2", 0xff, 7, "0xff' in line 1 h_snprintb_m( "\020" "\001bit1" "\0022", 0xff, 9, "0xff\0"); // old style, line_max exceeded by description in line 2 h_snprintb_m( "\020" "\0011" "\002bit2", 0xff, 8, "0xff<1>\0" "0xff' in line 2 h_snprintb_m( "\020" "\0011" "\002bit2", 0xff, 9, "0xff<1>\0" "0xff\0" "0xff\0"); // new style, line_max exceeded by value in line 1 h_snprintb_m( "\177\020", 0xff, 3, "0x#\0"); // new style, line_max exceeded by single-bit '<' in line 1 h_snprintb_m( "\177\020" "b\000bit\0", 0xff, 4, "0xf#\0"); // new style, line_max exceeded by single-bit description in line 1 h_snprintb_m( "\177\020" "b\000bit0\0" "b\001two\0", 0xff, 8, "0xff' in line 1 h_snprintb_m( "\177\020" "b\000bit0\0" "b\001two\0", 0xff, 9, "0xff\0"); // new style, line_max exceeded by single-bit description in line 2 h_snprintb_m( "\177\020" "b\000one\0" "b\001three\0", 0xff, 9, "0xff\0" "0xff' in line 2 h_snprintb_m( "\177\020" "b\000one\0" "b\001three\0", 0xff, 10, "0xff\0" "0xff\0" "0xff\0"); // new style, line_max exceeded by named bit-field number in line 1 h_snprintb_m( "\177\020" "f\000\004lo\0", 0xff, 3, "0x#\0"); // new style, line_max exceeded by named bit-field '<' in line 1 h_snprintb_m( "\177\020" "f\000\004lo\0", 0xff, 4, "0xf#\0"); // new style, line_max exceeded by bit-field description in line 1 h_snprintb_m( "\177\020" "f\000\004lo\0", 0xff, 6, "0xff<#\0"); // new style, line_max exceeded by named bit-field '=' in line 1 h_snprintb_m( "\177\020" "f\000\004lo\0", 0xff, 7, "0xff' in line 1 h_snprintb_m( "\177\020" "f\000\004lo\0" "=\017match\0", 0xff, 17, "0xff\0" "0xff\0" "0xff\0" "0xff' in line 2 h_snprintb_m( "\177\020" "f\000\004lo\0" "f\000\004low-bits\0" "=\017match\0", 0xff, 23, "0xff\0" "0xff\0" "0xff\0"); // new style, line_max exceeded by unnamed bit-field number in line 1 h_snprintb_m( "\177\020" "F\000\004\0", 0xff, 3, "0x#\0"); // new style, line_max exceeded by unnamed bit-field '<' in line 1 h_snprintb_m( "\177\020" "F\000\004\0", 0xff, 4, "0xf#\0"); // new style, line_max exceeded by unnamed bit-field value description // in line 1 h_snprintb_m( "\177\020" "F\000\004\0" ":\017match\0", 0xff, 9, "0xff' in line 1 h_snprintb_m( "\177\020" "F\000\004\0" ":\017match\0", 0xff, 10, "0xff' in line 2 h_snprintb_m( "\177\020" "F\000\004\0" ":\017m1\0" ":\017match\0", 0xff, 10, "0xff\0"); // new style, line_max exceeded by bit-field default h_snprintb_m( "\177\020" "f\000\004f\0" "*=default\0", 0xff, 17, "0xff\0" "0x800f0701\0"); // new style, missing number base h_snprintb_m_len( 1024, "\177", 0xff, 128, -1, "#\0"); // new style, buffer too small for complete number in line 2 h_snprintb_m_len( 15, "\177\020" "b\000lsb\0" "b\001two\0", 0xff, 11, 20, "0xff\0" "0x#\0"); // new-style format, buffer too small for '<' in line 2 h_snprintb_m_len( 16, "\177\020" "b\000lsb\0" "b\001two\0", 0xff, 11, 20, "0xff\0" "0xf#\0"); // new-style format, buffer too small for textual fallback h_snprintb_m_len( 24, "\177\020" "f\000\004bits\0" "*=fallback\0" "b\0024\0", 0xff, 64, 26, "0xff\0" "0x800f0701\0"); // new style, bits and fields, line break after field description 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\0" "0x800f0701\0" "0x800f0701\0"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, snprintb); ATF_TP_ADD_TC(tp, snprintb_m); return atf_no_error(); }