1 | /* |
---|
2 | * Exercise putk, printk, and getchark |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2010. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/score/basedefs.h> |
---|
17 | |
---|
18 | /* |
---|
19 | * Undefined the RTEMS_PRINTFLIKE and make it nothing. The test code |
---|
20 | * contained in the file is suppose to be wrong. |
---|
21 | */ |
---|
22 | #undef RTEMS_PRINTFLIKE |
---|
23 | #define RTEMS_PRINTFLIKE(_a, _b) |
---|
24 | |
---|
25 | #define TEST_INIT |
---|
26 | |
---|
27 | #define TESTS_USE_PRINTK |
---|
28 | #include <rtems/bspIo.h> |
---|
29 | #include <tmacros.h> |
---|
30 | |
---|
31 | const char rtems_test_name[] = "SPPRINTK"; |
---|
32 | |
---|
33 | /* forward declarations to avoid warnings */ |
---|
34 | rtems_task Init(rtems_task_argument argument); |
---|
35 | int test_getchar(void); |
---|
36 | void do_getchark(void); |
---|
37 | void do_putk(void); |
---|
38 | void do_printk(void); |
---|
39 | |
---|
40 | int test_getchar(void) |
---|
41 | { |
---|
42 | return 0x35; |
---|
43 | } |
---|
44 | |
---|
45 | void do_getchark(void) |
---|
46 | { |
---|
47 | int sc; |
---|
48 | BSP_polling_getchar_function_type poll_char; |
---|
49 | |
---|
50 | poll_char = BSP_poll_char; |
---|
51 | |
---|
52 | BSP_poll_char = NULL; |
---|
53 | |
---|
54 | putk( "getchark - NULL getchar method - return -1" ); |
---|
55 | sc = getchark(); |
---|
56 | rtems_test_assert( sc == -1 ); |
---|
57 | |
---|
58 | putk( "getchark - test getchar method - returns 0x35" ); |
---|
59 | BSP_poll_char = test_getchar; |
---|
60 | sc = getchark(); |
---|
61 | rtems_test_assert( sc == 0x35 ); |
---|
62 | |
---|
63 | BSP_poll_char = poll_char; |
---|
64 | } |
---|
65 | |
---|
66 | void do_putk(void) |
---|
67 | { |
---|
68 | putk( "This is a test of putk" ); |
---|
69 | } |
---|
70 | |
---|
71 | void do_printk(void) |
---|
72 | { |
---|
73 | long lm = 2147483647L; |
---|
74 | unsigned long ulm = 4294967295UL; |
---|
75 | long long llm = 9223372036854775807LL; |
---|
76 | long long ullm = 18446744073709551615ULL; |
---|
77 | |
---|
78 | printk( "bad format -- %%q in parentheses (%q)\n" ); |
---|
79 | |
---|
80 | printk( "bad format -- %%lq in parentheses (%lq)\n", 0x1234 ); |
---|
81 | |
---|
82 | printk( "%%O octal upper case 16 -- %O\n", 16 ); |
---|
83 | printk( "%%o octal lower case of 16 -- %O\n", 16 ); |
---|
84 | printk( "%%I of 16 -- %I\n", 16 ); |
---|
85 | printk( "%%i of 16 -- %i\n", 16 ); |
---|
86 | printk( "%%D of 16 -- %D\n", 16 ); |
---|
87 | printk( "%%d of 16 -- %d\n", 16 ); |
---|
88 | printk( "%%-3d of 16 -- %-3d\n", 16 ); |
---|
89 | printk( "%%U of 16 -- %U\n", 16 ); |
---|
90 | printk( "%%u of 16 -- %u\n", 16 ); |
---|
91 | printk( "%%X of 16 -- %X\n", 16 ); |
---|
92 | printk( "%%x of 16 -- %x\n", 16 ); |
---|
93 | printk( "%%p of 0x1234 -- %p\n", (void *)0x1234 ); |
---|
94 | |
---|
95 | /* long */ |
---|
96 | printk( "%%lo of 2147483647 -- %lo\n", lm ); |
---|
97 | printk( "%%li of 2147483647 -- %li\n", lm ); |
---|
98 | printk( "%%lu of 2147483647 -- %lu\n", lm ); |
---|
99 | printk( "%%lx of 2147483647 -- %lx\n", lm ); |
---|
100 | printk( "%%lo of -2147483648 -- %lo\n", -lm - 1L ); |
---|
101 | printk( "%%li of -2147483648 -- %li\n", -lm - 1L ); |
---|
102 | printk( "%%lx of -2147483648 -- %lx\n", -lm - 1L ); |
---|
103 | printk( "%%lo of 4294967295 -- %lo\n", ulm ); |
---|
104 | printk( "%%lu of 4294967295 -- %lu\n", ulm ); |
---|
105 | printk( "%%lx of 4294967295 -- %lx\n", ulm ); |
---|
106 | |
---|
107 | /* long long */ |
---|
108 | printk( "%%llo of 9223372036854775807 -- %llo\n", llm ); |
---|
109 | printk( "%%lli of 9223372036854775807 -- %lli\n", llm ); |
---|
110 | printk( "%%llu of 9223372036854775807 -- %llu\n", llm ); |
---|
111 | printk( "%%llx of 9223372036854775807 -- %llx\n", llm ); |
---|
112 | printk( "%%llo of -9223372036854775808 -- %llo\n", -llm - 1LL ); |
---|
113 | printk( "%%lli of -9223372036854775808 -- %lli\n", -llm - 1LL ); |
---|
114 | printk( "%%llx of -9223372036854775808 -- %llx\n", -llm - 1LL ); |
---|
115 | printk( "%%llo of 18446744073709551615 -- %llo\n", ullm ); |
---|
116 | printk( "%%llu of 18446744073709551615 -- %llu\n", ullm ); |
---|
117 | printk( "%%llx of 18446744073709551615 -- %llx\n", ullm ); |
---|
118 | |
---|
119 | /* negative numbers */ |
---|
120 | printk( "%%d of -16 -- %d\n", -16 ); |
---|
121 | printk( "%%d of -16 -- %-3d\n", -16 ); |
---|
122 | printk( "%%u of -16 -- %u\n", -16 ); |
---|
123 | |
---|
124 | /* string formats */ |
---|
125 | printk( "%%s of Mary Had a Little Lamb -- (%s)\n", |
---|
126 | "Mary Had a Little Lamb" ); |
---|
127 | printk( "%%s of NULL -- (%s)\n", NULL ); |
---|
128 | printk( "%%12s of joel -- (%20s)\n", "joel" ); |
---|
129 | printk( "%%4s of joel -- (%4s)\n", "joel" ); |
---|
130 | printk( "%%-12s of joel -- (%-20s)\n", "joel" ); |
---|
131 | printk( "%%-4s of joel -- (%-4s)\n", "joel" ); |
---|
132 | printk( "%%c of X -- (%c)\n", 'X' ); |
---|
133 | } |
---|
134 | |
---|
135 | rtems_task Init( |
---|
136 | rtems_task_argument argument |
---|
137 | ) |
---|
138 | { |
---|
139 | TEST_BEGIN(); |
---|
140 | |
---|
141 | do_putk(); |
---|
142 | putk(""); |
---|
143 | |
---|
144 | do_printk(); |
---|
145 | putk(""); |
---|
146 | |
---|
147 | do_getchark(); |
---|
148 | |
---|
149 | TEST_END(); |
---|
150 | rtems_test_exit( 0 ); |
---|
151 | } |
---|
152 | |
---|
153 | /* configuration information */ |
---|
154 | |
---|
155 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
156 | |
---|
157 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
158 | |
---|
159 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
160 | |
---|
161 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
162 | |
---|
163 | #define CONFIGURE_INIT |
---|
164 | |
---|
165 | #include <rtems/confdefs.h> |
---|