17#include "threads/test.h"
23checkf (
const char *expect,
const char *format, ...)
28 printf (
"\"%s\" -> \"%s\": ", format, expect);
31 vsnprintf (output,
sizeof output, format, args);
34 if (
strcmp (expect, output))
36 printf (
"\nFAIL: actual output \"%s\"\n", output);
47 printf (
"Testing formats:");
53 checkf (
"123",
"%'d", 123);
54 checkf (
"1,234",
"%'d", 1234);
55 checkf (
"12,345",
"%'d", 12345);
56 checkf (
"123,456",
"%'ld", 123456L);
57 checkf (
"1,234,567",
"%'ld", 1234567L);
58 checkf (
"12,345,678",
"%'ld", 12345678L);
59 checkf (
"123,456,789",
"%'ld", 123456789L);
60 checkf (
"1,234,567,890",
"%'ld", 1234567890L);
61 checkf (
"12,345,678,901",
"%'lld", 12345678901LL);
62 checkf (
"123,456,789,012",
"%'lld", 123456789012LL);
63 checkf (
"1,234,567,890,123",
"%'lld", 1234567890123LL);
64 checkf (
"12,345,678,901,234",
"%'lld", 12345678901234LL);
65 checkf (
"123,456,789,012,345",
"%'lld", 123456789012345LL);
66 checkf (
"1,234,567,890,123,456",
"%'lld", 1234567890123456LL);
67 checkf (
"12,345,678,901,234,567",
"%'lld", 12345678901234567LL);
68 checkf (
"123,456,789,012,345,678",
"%'lld", 123456789012345678LL);
69 checkf (
"1,234,567,890,123,456,789",
"%'lld", 1234567890123456789LL);
74 checkf (
"-12",
"%'d", -12);
75 checkf (
"-123",
"%'d", -123);
76 checkf (
"-1,234",
"%'d", -1234);
77 checkf (
"-12,345",
"%'d", -12345);
78 checkf (
"-123,456",
"%'ld", -123456L);
79 checkf (
"-1,234,567",
"%'ld", -1234567L);
80 checkf (
"-12,345,678",
"%'ld", -12345678L);
81 checkf (
"-123,456,789",
"%'ld", -123456789L);
82 checkf (
"-1,234,567,890",
"%'ld", -1234567890L);
83 checkf (
"-12,345,678,901",
"%'lld", -12345678901LL);
84 checkf (
"-123,456,789,012",
"%'lld", -123456789012LL);
85 checkf (
"-1,234,567,890,123",
"%'lld", -1234567890123LL);
86 checkf (
"-12,345,678,901,234",
"%'lld", -12345678901234LL);
87 checkf (
"-123,456,789,012,345",
"%'lld", -123456789012345LL);
88 checkf (
"-1,234,567,890,123,456",
"%'lld", -1234567890123456LL);
89 checkf (
"-12,345,678,901,234,567",
"%'lld", -12345678901234567LL);
90 checkf (
"-123,456,789,012,345,678",
"%'lld", -123456789012345678LL);
91 checkf (
"-1,234,567,890,123,456,789",
"%'lld", -1234567890123456789LL);
97 checkf (
"+0 ",
"%+-5d", 0);
99 checkf (
"00000",
"%05d", 0);
101 checkf (
" 00",
"%5.2d", 0);
106 checkf (
" +1",
"%+5d", 1);
107 checkf (
"+1 ",
"%+-5d", 1);
109 checkf (
"00001",
"%05d", 1);
110 checkf (
" 1",
"%5.0d", 1);
111 checkf (
" 01",
"%5.2d", 1);
114 checkf (
" -1",
"%5d", -1);
115 checkf (
"-1 ",
"%-5d", -1);
116 checkf (
" -1",
"%+5d", -1);
117 checkf (
"-1 ",
"%+-5d", -1);
118 checkf (
" -1",
"% 5d", -1);
119 checkf (
"-0001",
"%05d", -1);
120 checkf (
" -1",
"%5.0d", -1);
121 checkf (
" -01",
"%5.2d", -1);
124 checkf (
"12345",
"%5d", 12345);
125 checkf (
"12345",
"%-5d", 12345);
126 checkf (
"+12345",
"%+5d", 12345);
127 checkf (
"+12345",
"%+-5d", 12345);
128 checkf (
" 12345",
"% 5d", 12345);
129 checkf (
"12345",
"%05d", 12345);
130 checkf (
"12345",
"%5.0d", 12345);
131 checkf (
"12345",
"%5.2d", 12345);
132 checkf (
"12345",
"%d", 12345);
134 checkf (
"123456",
"%5d", 123456);
135 checkf (
"123456",
"%-5d", 123456);
136 checkf (
"+123456",
"%+5d", 123456);
137 checkf (
"+123456",
"%+-5d", 123456);
138 checkf (
" 123456",
"% 5d", 123456);
139 checkf (
"123456",
"%05d", 123456);
140 checkf (
"123456",
"%5.0d", 123456);
141 checkf (
"123456",
"%5.2d", 123456);
142 checkf (
"123456",
"%d", 123456);
152 checkf (
" 00000000",
"%#10.8x", 0);
158 checkf (
" 01",
"%#5o", 1);
159 checkf (
" 0x1",
"%#5x", 1);
160 checkf (
" 0X1",
"%#5X", 1);
161 checkf (
"0x00000001",
"%#10.8x", 1);
163 checkf (
"123456",
"%5u", 123456);
164 checkf (
"361100",
"%5o", 123456);
165 checkf (
"1e240",
"%5x", 123456);
166 checkf (
"1E240",
"%5X", 123456);
167 checkf (
"0361100",
"%#5o", 123456);
168 checkf (
"0x1e240",
"%#5x", 123456);
169 checkf (
"0X1E240",
"%#5X", 123456);
170 checkf (
"0x0001e240",
"%#10.8x", 123456);
173 checkf (
"foobar",
"%c%c%c%c%c%c",
'f',
'o',
'o',
'b',
'a',
'r');
174 checkf (
" left-right ",
"%6s%s%-7s",
"left",
"-",
"right");
175 checkf (
"trim",
"%.4s",
"trimoff");
179 checkf (
" abcdefgh",
"%9s",
"abcdefgh");
180 checkf (
"36657730000",
"%- o", (
unsigned) 036657730000);
181 checkf (
"4139757568",
"%- u", (
unsigned) 4139757568UL);
182 checkf (
"f6bfb000",
"%- x", (
unsigned) 0xf6bfb000);
185 checkf (
"-155209728",
"%-zi", (
size_t) -155209728);
186 checkf (
"-155209728",
"%-zd", (
size_t) -155209728);
187 checkf (
"036657730000",
"%+#o", (
unsigned) 036657730000);
188 checkf (
"0xf6bfb000",
"%+#x", (
unsigned) 0xf6bfb000);
189 checkf (
"-155209728",
"% zi", (
size_t) -155209728);
190 checkf (
"-155209728",
"% zd", (
size_t) -155209728);
192 checkf (
"036657730000",
"% #o", (
unsigned) 036657730000);
193 checkf (
"0xf6bfb000",
"% #x", (
unsigned) 0xf6bfb000);
194 checkf (
"0xf6bfb000",
"%# x", (
unsigned) 0xf6bfb000);
195 checkf (
"-155209728",
"%#zd", (
size_t) -155209728);
196 checkf (
"-155209728",
"%0zi", (
size_t) -155209728);
198 checkf (
"-155,209,728",
"%-'d", -155209728);
199 checkf (
"-155209728",
"%.zi", (
size_t) -155209728);
200 checkf (
"-155209728",
"%zi", (
size_t) -155209728);
201 checkf (
"-155209728",
"%zd", (
size_t) -155209728);
202 checkf (
"-155209728",
"%+zi", (
size_t) -155209728);
205 printf (
"\nstdio: PASS\n");
int vsnprintf(char *buffer, size_t buf_size, const char *format, va_list args)
Like vprintf(), except that output is stored into BUFFER, which must have space for BUF_SIZE characte...
int printf(const char *format,...)
Writes formatted output to the console.
#define va_start(LIST, ARG)
__builtin_va_list va_list
GCC has <stdarg.h> functionality as built-ins, so all we need is to use it.
__PTRDIFF_TYPE__ ptrdiff_t
GCC predefines the types we need for ptrdiff_t and size_t, so that we don't have to guess.
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
void test(void)
Test printf() implementation.
static int failure_cnt
Test program for printf() in lib/stdio.c.
static void checkf(const char *expect, const char *format,...)