1 /* Copyright 2013-2014 IBM Corp.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 * implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <config.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <assert.h>
21 #include <stdarg.h>
22
23 #define __TEST__
24
25 unsigned long tb_hz = 512000000;
26
mftb(void)27 static inline unsigned long mftb(void)
28 {
29 return 42;
30 }
31
32 #define pr_fmt(f) "PREFIX: " f
33 #include "../../libc/include/stdio.h"
34 #include "../console-log.c"
35 #include "../../libc/stdio/snprintf.c"
36 #include "../../libc/stdio/vsnprintf.c"
37
38 struct debug_descriptor debug_descriptor;
39
40 bool flushed_to_drivers;
41 char console_buffer[4096];
42
console_write(bool flush_to_drivers,const void * buf,size_t count)43 ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
44 {
45 flushed_to_drivers = flush_to_drivers;
46 memcpy(console_buffer, buf, count);
47 return count;
48 }
49
main(void)50 int main(void)
51 {
52 debug_descriptor.console_log_levels = 0x75;
53
54 prlog(PR_EMERG, "Hello World");
55 assert(strcmp(console_buffer, "[ 0.000000042,0] PREFIX: Hello World") == 0);
56 assert(flushed_to_drivers==true);
57
58 memset(console_buffer, 0, sizeof(console_buffer));
59
60 // Below log level
61 prlog(PR_TRACE, "Hello World");
62 assert(console_buffer[0] == 0);
63
64 // Should not be flushed to console
65 prlog(PR_DEBUG, "Hello World");
66 assert(strcmp(console_buffer, "[ 0.000000042,7] PREFIX: Hello World") == 0);
67 assert(flushed_to_drivers==false);
68
69 printf("Hello World");
70 assert(strcmp(console_buffer, "[ 0.000000042,5] PREFIX: Hello World") == 0);
71 assert(flushed_to_drivers==true);
72
73 return 0;
74 }
75