[PATCH v5 3/5] common: console: introduce overflow and isempty calls

Simon Glass sjg at chromium.org
Thu Dec 28 14:37:17 CET 2023


Hi Svyatoslav,

On Thu, Dec 28, 2023 at 9:03 AM Svyatoslav Ryhel <clamor95 at gmail.com> wrote:
>
> From: Ion Agorria <ion at agorria.com>
>
> Separate record overflow logic and add console_record_isempty
> as available calls don't serve to know output has been read
> fully with readline's.
>
> Signed-off-by: Ion Agorria <ion at agorria.com>
> Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
> Reviewed-by: Mattijs Korpershoek <mkorpershoek at baylibre.com>
> ---
>  common/console.c  | 15 ++++++++++++---
>  include/console.h | 26 ++++++++++++++++++++++++++
>  test/ut.c         |  9 ++++-----
>  3 files changed, 42 insertions(+), 8 deletions(-)
>
> diff --git a/common/console.c b/common/console.c
> index 1ffda49c87..833da61733 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -821,6 +821,8 @@ int console_record_init(void)
>         ret = membuff_new((struct membuff *)&gd->console_in,
>                           CONFIG_CONSOLE_RECORD_IN_SIZE);
>
> +       gd->flags |= GD_FLG_RECORD;

Why is this here? It is currently enabled by
console_record_reset_enable(). In any case it looks like this needs it
own patch.

> +
>         return ret;
>  }
>
> @@ -839,11 +841,13 @@ int console_record_reset_enable(void)
>         return 0;
>  }
>
> -int console_record_readline(char *str, int maxlen)
> +bool console_record_overflow(void)

There is too much going on in this patch. Why is
console_record_overflow() changing? Can that go in its own patch?

>  {
> -       if (gd->flags & GD_FLG_RECORD_OVF)
> -               return -ENOSPC;
> +       return gd->flags & GD_FLG_RECORD_OVF ? true : false;
> +}
>
> +int console_record_readline(char *str, int maxlen)
> +{
>         return membuff_readline((struct membuff *)&gd->console_out, str,
>                                 maxlen, '\0');
>  }
> @@ -853,6 +857,11 @@ int console_record_avail(void)
>         return membuff_avail((struct membuff *)&gd->console_out);
>  }
>
> +bool console_record_isempty(void)
> +{
> +       return membuff_isempty((struct membuff *)&gd->console_out);
> +}
> +
>  int console_in_puts(const char *str)
>  {
>         return membuff_put((struct membuff *)&gd->console_in, str, strlen(str));
> diff --git a/include/console.h b/include/console.h
> index e29817e57b..21466d51a9 100644
> --- a/include/console.h
> +++ b/include/console.h
> @@ -64,6 +64,13 @@ void console_record_reset(void);
>   */
>  int console_record_reset_enable(void);
>
> +/**
> + * console_record_overflow() - returns state of buffers overflow
> + *
> + * Return: true if the console buffer was overflowed
> + */
> +bool console_record_overflow(void);
> +
>  /**
>   * console_record_readline() - Read a line from the console output
>   *
> @@ -84,6 +91,13 @@ int console_record_readline(char *str, int maxlen);
>   */
>  int console_record_avail(void);
>
> +/**
> + * console_record_isempty() - Returns if console output is empty
> + *
> + * Return: true if empty
> + */
> +bool console_record_isempty(void);
> +
>  /**
>   * console_in_puts() - Write a string to the console input buffer
>   *
> @@ -113,6 +127,12 @@ static inline int console_record_reset_enable(void)
>         return -ENOSYS;
>  }
>
> +static inline bool console_record_overflow(void)
> +{
> +       /* No overflow */
> +       return false;
> +}
> +
>  static inline int console_record_readline(char *str, int maxlen)
>  {
>         /* Nothing to read */
> @@ -131,6 +151,12 @@ static inline int console_in_puts(const char *str)
>         return 0;
>  }
>
> +static inline bool console_record_isempty(void)
> +{
> +       /* Always empty */
> +       return true;
> +}
> +
>  #endif /* !CONFIG_CONSOLE_RECORD */
>
>  /**
> diff --git a/test/ut.c b/test/ut.c
> index 628e9dc980..2a3bb8133a 100644
> --- a/test/ut.c
> +++ b/test/ut.c
> @@ -53,15 +53,14 @@ long ut_check_delta(ulong last)
>
>  static int readline_check(struct unit_test_state *uts)
>  {
> -       int ret;
> -
> -       ret = console_record_readline(uts->actual_str, sizeof(uts->actual_str));
> -       if (ret == -ENOSPC) {
> +       if (console_record_overflow()) {
>                 ut_fail(uts, __FILE__, __LINE__, __func__,
>                         "Console record buffer too small - increase CONFIG_CONSOLE_RECORD_OUT_SIZE");
> -               return ret;
> +               return -ENOSPC;
>         }
>
> +       console_record_readline(uts->actual_str, sizeof(uts->actual_str));

I don't see why these are changing. We can use -ENOSPC for overflow, right?

> +
>         return 0;
>  }
>
> --
> 2.40.1
>

Regards,
SImon


More information about the U-Boot mailing list