uboot/test/log/nolog_test.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
   4 *
   5 * Logging function tests for CONFIG_LOG=n.
   6 */
   7
   8/* Needed for testing log_debug() */
   9#define DEBUG 1
  10
  11#include <common.h>
  12#include <console.h>
  13#include <log.h>
  14#include <asm/global_data.h>
  15#include <test/log.h>
  16#include <test/test.h>
  17#include <test/suites.h>
  18#include <test/ut.h>
  19
  20DECLARE_GLOBAL_DATA_PTR;
  21
  22#define BUFFSIZE 32
  23
  24static int log_test_nolog_err(struct unit_test_state *uts)
  25{
  26        char buf[BUFFSIZE];
  27
  28        memset(buf, 0, BUFFSIZE);
  29        console_record_reset_enable();
  30        log_err("testing %s\n", "log_err");
  31        gd->flags &= ~GD_FLG_RECORD;
  32        ut_assertok(ut_check_console_line(uts, "testing log_err"));
  33        ut_assertok(ut_check_console_end(uts));
  34        return 0;
  35}
  36LOG_TEST(log_test_nolog_err);
  37
  38static int log_test_nolog_warning(struct unit_test_state *uts)
  39{
  40        char buf[BUFFSIZE];
  41
  42        memset(buf, 0, BUFFSIZE);
  43        console_record_reset_enable();
  44        log_warning("testing %s\n", "log_warning");
  45        gd->flags &= ~GD_FLG_RECORD;
  46        ut_assertok(ut_check_console_line(uts, "testing log_warning"));
  47        ut_assertok(ut_check_console_end(uts));
  48        return 0;
  49}
  50LOG_TEST(log_test_nolog_warning);
  51
  52static int log_test_nolog_notice(struct unit_test_state *uts)
  53{
  54        char buf[BUFFSIZE];
  55
  56        memset(buf, 0, BUFFSIZE);
  57        console_record_reset_enable();
  58        log_notice("testing %s\n", "log_notice");
  59        gd->flags &= ~GD_FLG_RECORD;
  60        ut_assertok(ut_check_console_line(uts, "testing log_notice"));
  61        ut_assertok(ut_check_console_end(uts));
  62        return 0;
  63}
  64LOG_TEST(log_test_nolog_notice);
  65
  66static int log_test_nolog_info(struct unit_test_state *uts)
  67{
  68        char buf[BUFFSIZE];
  69
  70        memset(buf, 0, BUFFSIZE);
  71        console_record_reset_enable();
  72        log_err("testing %s\n", "log_info");
  73        gd->flags &= ~GD_FLG_RECORD;
  74        ut_assertok(ut_check_console_line(uts, "testing log_info"));
  75        ut_assertok(ut_check_console_end(uts));
  76        return 0;
  77}
  78LOG_TEST(log_test_nolog_info);
  79
  80#undef _DEBUG
  81#define _DEBUG 0
  82static int nolog_test_nodebug(struct unit_test_state *uts)
  83{
  84        char buf[BUFFSIZE];
  85
  86        memset(buf, 0, BUFFSIZE);
  87        console_record_reset_enable();
  88        debug("testing %s\n", "debug");
  89        gd->flags &= ~GD_FLG_RECORD;
  90        ut_assertok(ut_check_console_end(uts));
  91        return 0;
  92}
  93LOG_TEST(nolog_test_nodebug);
  94
  95static int log_test_nolog_nodebug(struct unit_test_state *uts)
  96{
  97        char buf[BUFFSIZE];
  98
  99        memset(buf, 0, BUFFSIZE);
 100        console_record_reset_enable();
 101        log_debug("testing %s\n", "log_debug");
 102        gd->flags &= ~GD_FLG_RECORD;
 103        ut_assert(!strcmp(buf, ""));
 104        ut_assertok(ut_check_console_end(uts));
 105        return 0;
 106}
 107LOG_TEST(log_test_nolog_nodebug);
 108
 109#undef _DEBUG
 110#define _DEBUG 1
 111static int nolog_test_debug(struct unit_test_state *uts)
 112{
 113        char buf[BUFFSIZE];
 114
 115        memset(buf, 0, BUFFSIZE);
 116        console_record_reset_enable();
 117        debug("testing %s\n", "debug");
 118        gd->flags &= ~GD_FLG_RECORD;
 119        ut_assertok(ut_check_console_line(uts, "testing debug"));
 120        ut_assertok(ut_check_console_end(uts));
 121        return 0;
 122}
 123LOG_TEST(nolog_test_debug);
 124
 125static int log_test_nolog_debug(struct unit_test_state *uts)
 126{
 127        char buf[BUFFSIZE];
 128
 129        memset(buf, 0, BUFFSIZE);
 130        console_record_reset_enable();
 131        log_debug("testing %s\n", "log_debug");
 132        log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
 133        gd->flags &= ~GD_FLG_RECORD;
 134        ut_assertok(ut_check_console_line(uts, "testing log_debug"));
 135        ut_assertok(ut_check_console_line(uts, "more log_debug"));
 136        ut_assertok(ut_check_console_end(uts));
 137        return 0;
 138}
 139LOG_TEST(log_test_nolog_debug);
 140