From patchwork Mon Jan 27 15:49:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240309 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:54 -0700 Subject: [PATCH 19/21] console: Add a function to read a line of the output / eof In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.19.I8114ed3d67267c833b7d9f456e6da6e9c4653c9b@changeid> When recording the console output for testing it is useful to be able to read the output a line at a time to check that the output is correct. Also we need to check that we get to the end of the output. Add a console function to return the next line and another to see how must data is left. Signed-off-by: Simon Glass --- common/console.c | 11 +++++++++++ include/console.h | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/common/console.c b/common/console.c index 168ba60d0d..7681da19a2 100644 --- a/common/console.c +++ b/common/console.c @@ -621,6 +621,17 @@ void console_record_reset_enable(void) console_record_reset(); gd->flags |= GD_FLG_RECORD; } + +int console_record_readline(char *str, int maxlen) +{ + return membuff_readline(&gd->console_out, str, maxlen, ' '); +} + +int console_record_avail(void) +{ + return membuff_avail(&gd->console_out); +} + #endif /* test if ctrl-c was pressed */ diff --git a/include/console.h b/include/console.h index e935c601f1..74afe22b7e 100644 --- a/include/console.h +++ b/include/console.h @@ -41,6 +41,25 @@ void console_record_reset(void); */ void console_record_reset_enable(void); +/** + * console_record_readline() - Read a line from the console output + * + * This reads the next available line from the console output previously + * recorded. + * + * @str: Place to put string + * @maxlen: Maximum length of @str including nul terminator + * @return length of string returned + */ +int console_record_readline(char *str, int maxlen); + +/** + * console_record_avail() - Get the number of available bytes in console output + * + * @return available bytes (0 if empty) + */ +int console_record_avail(void); + /** * console_announce_r() - print a U-Boot console on non-serial consoles *