~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/core/test/run-console-log.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#define _printf printf
 
26
 
 
27
static inline unsigned long mftb(void)
 
28
{
 
29
        return 42;
 
30
}
 
31
 
 
32
int _printf(const char* fmt, ...);
 
33
 
 
34
#include "../console-log.c"
 
35
 
 
36
struct debug_descriptor debug_descriptor;
 
37
 
 
38
bool flushed_to_drivers;
 
39
char console_buffer[4096];
 
40
 
 
41
ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
 
42
{
 
43
        flushed_to_drivers = flush_to_drivers;
 
44
        memcpy(console_buffer, buf, count);
 
45
        return count;
 
46
}
 
47
 
 
48
int main(void)
 
49
{
 
50
        debug_descriptor.console_log_levels = 0x75;
 
51
 
 
52
        prlog(PR_EMERG, "Hello World");
 
53
        assert(memcmp(console_buffer, "[42,0] Hello World", strlen("[42,0] Hello World")) == 0);
 
54
        assert(flushed_to_drivers==true);
 
55
 
 
56
        memset(console_buffer, 0, sizeof(console_buffer));
 
57
 
 
58
        // Below log level
 
59
        prlog(PR_TRACE, "Hello World");
 
60
        assert(console_buffer[0] == 0);
 
61
 
 
62
        // Should not be flushed to console
 
63
        prlog(PR_DEBUG, "Hello World");
 
64
        assert(memcmp(console_buffer, "[42,7] Hello World", strlen("[42,7] Hello World")) == 0);
 
65
        assert(flushed_to_drivers==false);
 
66
 
 
67
        printf("Hello World");
 
68
        assert(memcmp(console_buffer, "[42,5] Hello World", strlen("[42,5] Hello World")) == 0);
 
69
        assert(flushed_to_drivers==true);
 
70
 
 
71
        return 0;
 
72
}