2c5157f851002c2e0fe95bd72019452eba43dd7a
[pintos-anon] / src / tests / threads / stdio.c
1 /* Test program for printf() in lib/kernel/stdio.c.
2
3    Attempts to test printf() functionality that is not
4    sufficiently tested elsewhere in Pintos.
5
6    This is not a test we will run on your submitted projects.
7    It is here for completeness.
8 */
9
10 #undef NDEBUG
11 #include <limits.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14
15 /* Test printf() implementation. */
16 void
17 test (void) 
18 {
19   long long x;
20   int i;
21
22   /* Check that commas show up in the right places, for positive
23      numbers. */
24   x = i = 0;
25   while (x < LLONG_MAX / 10)
26     {
27       x = x * 10 + ++i % 10;
28       printf ("%'26lld %'#29llo %'#19llx\n", x, x, x);
29     }
30
31   /* Check that commas show up in the right places, for negative
32      numbers. */
33   x = i = 0;
34   while (x < LLONG_MAX / 10)
35     {
36       x = x * 10 + ++i % 10;
37       printf ("%'26lld %'29llo %'19llx\n", -x, -x, -x);
38     }
39
40   /* Check `+', ` ' flags. */
41   for (i = -1; i <= +1; i++) 
42     {
43       printf ("[%d|%+d|% d] ", i, i, i);
44       printf ("[%x|%+x|% x]  ", i, i, i);
45       printf ("[%o|%+o|% o]\n", i, i, i);
46     }
47
48   /* Check `#' flag. */
49   for (i = -1; i <= +1; i++) 
50     {
51       printf ("[%#d|%+#d|% #d] ", i, i, i);
52       printf ("[%#x|%+#x|% #x] ", i, i, i);
53       printf ("[%#o|%+#o|% #o]\n", i, i, i);
54     }
55
56   printf ("0031: [%9s]\n", "abcdefgh");
57   printf ("0063: [%- o]\n", 036657730000);
58   printf ("0064: [%- u]\n", 4139757568);
59   printf ("0065: [%- x]\n", 0xf6bfb000);
60   printf ("0178: [%-to]\n", (ptrdiff_t) 036657730000);
61   printf ("0191: [%-tu]\n", (ptrdiff_t) 4139757568);
62   printf ("0242: [%-zi]\n", (size_t) -155209728);
63   printf ("0257: [%-zd]\n", (size_t) -155209728);
64   printf ("0347: [%+#o]\n", 036657730000);
65   printf ("0349: [%+#x]\n", 0xf6bfb000);
66   printf ("0539: [% zi]\n", (size_t) -155209728);
67   printf ("0540: [% zd]\n", (size_t) -155209728);
68   printf ("0602: [% tu]\n", (ptrdiff_t) 4139757568);
69   printf ("0605: [% #o]\n", 036657730000);
70   printf ("0607: [% #x]\n", 0xf6bfb000);
71   printf ("0702: [%# x]\n", 0xf6bfb000);
72   printf ("0875: [%#zd]\n", (size_t) -155209728);
73   printf ("1184: [%0zi]\n", (size_t) -155209728);
74   printf ("1483: [%'tu]\n", (ptrdiff_t) 4139757568);
75   printf ("1557: [%-'d]\n", -155209728);
76   printf ("1676: [%.zi]\n", (size_t) -155209728);
77   printf ("1897: [%zi]\n", (size_t) -155209728);
78   printf ("1899: [%zd]\n", (size_t) -155209728);
79   printf ("2791: [%+zi]\n", (size_t) -155209728);
80 }