LCOV - code coverage report
Current view: top level - core/test - run-console-log-pr_fmt.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 21 21 100.0 %
Date: 2024-01-02 21:04:04 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Copyright 2015-2016 IBM Corp.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <config.h>
       7                 :            : #include <stdlib.h>
       8                 :            : #include <string.h>
       9                 :            : #include <assert.h>
      10                 :            : #include <stdarg.h>
      11                 :            : 
      12                 :            : #define __TEST__
      13                 :            : 
      14                 :            : unsigned long tb_hz = 512000000;
      15                 :            : 
      16                 :          4 : static inline unsigned long mftb(void)
      17                 :            : {
      18                 :          4 :         return 42;
      19                 :            : }
      20                 :            : 
      21                 :            : #define pr_fmt(f) "PREFIX: " f
      22                 :            : #include "../../libc/include/stdio.h"
      23                 :            : #include "../console-log.c"
      24                 :            : #include "../../libc/stdio/snprintf.c"
      25                 :            : #include "../../libc/stdio/vsnprintf.c"
      26                 :            : 
      27                 :            : struct debug_descriptor debug_descriptor;
      28                 :            : 
      29                 :            : bool flushed_to_drivers;
      30                 :            : char console_buffer[4096];
      31                 :            : 
      32                 :          3 : ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
      33                 :            : {
      34                 :          3 :         flushed_to_drivers = flush_to_drivers;
      35                 :          3 :         memcpy(console_buffer, buf, count);
      36                 :          3 :         return count;
      37                 :            : }
      38                 :            : 
      39                 :          1 : int main(void)
      40                 :            : {
      41                 :          1 :         debug_descriptor.console_log_levels = 0x75;
      42                 :            : 
      43                 :          1 :         prlog(PR_EMERG, "Hello World");
      44                 :          1 :         assert(strcmp(console_buffer, "[    0.000000042,0] PREFIX: Hello World") == 0);
      45                 :          1 :         assert(flushed_to_drivers==true);
      46                 :            : 
      47                 :          1 :         memset(console_buffer, 0, sizeof(console_buffer));
      48                 :            : 
      49                 :            :         // Below log level
      50                 :          1 :         prlog(PR_TRACE, "Hello World");
      51                 :          1 :         assert(console_buffer[0] == 0);
      52                 :            : 
      53                 :            :         // Should not be flushed to console
      54                 :          1 :         prlog(PR_DEBUG, "Hello World");
      55                 :          1 :         assert(strcmp(console_buffer, "[    0.000000042,7] PREFIX: Hello World") == 0);
      56                 :          1 :         assert(flushed_to_drivers==false);
      57                 :            : 
      58                 :          1 :         printf("Hello World");
      59                 :          1 :         assert(strcmp(console_buffer, "[    0.000000042,5] PREFIX: Hello World") == 0);
      60                 :          1 :         assert(flushed_to_drivers==true);
      61                 :            : 
      62                 :          1 :         return 0;
      63                 :            : }

Generated by: LCOV version 1.14