[19/21] console: Add a function to read a line of the output / eof
diff mbox series

Message ID 20200127084920.19.I8114ed3d67267c833b7d9f456e6da6e9c4653c9b@changeid
State Accepted
Commit b612312816ffe41a3a7616aa00394ffb248cf91e
Delegated to: Simon Glass
Headers show
Series
  • dm: Various enhancements to prepare for ACPI
Related show

Commit Message

Simon Glass Jan. 27, 2020, 3:49 p.m. UTC
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 <sjg@chromium.org>
---

 common/console.c  | 11 +++++++++++
 include/console.h | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+)

Comments

Simon Glass Feb. 5, 2020, 5:55 p.m. UTC | #1
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 <sjg@chromium.org>
---

 common/console.c  | 11 +++++++++++
 include/console.h | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+)

Applied to u-boot-dm, thanks!
Heinrich Schuchardt Feb. 12, 2020, 5:14 p.m. UTC | #2
On 2/5/20 6:55 PM, sjg@google.com wrote:
> 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 <sjg@chromium.org>
> ---
>
>   common/console.c  | 11 +++++++++++
>   include/console.h | 19 +++++++++++++++++++
>   2 files changed, 30 insertions(+)
>
> Applied to u-boot-dm, thanks!
>

With this merged patch U-Boot does not compile:

common/console.c:629:26: error: passing argument 1 of ‘membuff_readline’
discards ‘volatile’ qualifier from pointer target type
[-Werror=discarded-qualifiers]
   629 |  return membuff_readline(&gd->console_out, str, maxlen, ' ');
       |                          ^~~~~~~~~~~~~~~~
In file included from include/asm-generic/global_data.h:24,
                  from ./arch/arm/include/asm/global_data.h:87,
                  from include/common.h:36,
                  from common/console.c:7:

Best regards

Heinrich
Tom Rini Feb. 12, 2020, 5:24 p.m. UTC | #3
On Wed, Feb 12, 2020 at 06:14:49PM +0100, Heinrich Schuchardt wrote:
> On 2/5/20 6:55 PM, sjg@google.com wrote:
> > 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 <sjg@chromium.org>
> > ---
> > 
> >   common/console.c  | 11 +++++++++++
> >   include/console.h | 19 +++++++++++++++++++
> >   2 files changed, 30 insertions(+)
> > 
> > Applied to u-boot-dm, thanks!
> > 
> 
> With this merged patch U-Boot does not compile:
> 
> common/console.c:629:26: error: passing argument 1 of ‘membuff_readline’
> discards ‘volatile’ qualifier from pointer target type
> [-Werror=discarded-qualifiers]
>   629 |  return membuff_readline(&gd->console_out, str, maxlen, ' ');
>       |                          ^~~~~~~~~~~~~~~~
> In file included from include/asm-generic/global_data.h:24,
>                  from ./arch/arm/include/asm/global_data.h:87,
>                  from include/common.h:36,
>                  from common/console.c:7:

... with gcc-9.x I assume.  We really do need to extend the CI loops to
cover this someway or another, at least for Sandbox like with do with
clang.  Or maybe even just a newer clang would also catch it?  It looks
like an "easy" path forward here to test at least is to switch from
LLVM-7 to LLVM-10.  I'll fire off a travis test now and see what
happens.
Tom Rini Feb. 12, 2020, 10:14 p.m. UTC | #4
On Wed, Feb 12, 2020 at 12:24:16PM -0500, Tom Rini wrote:
> On Wed, Feb 12, 2020 at 06:14:49PM +0100, Heinrich Schuchardt wrote:
> > On 2/5/20 6:55 PM, sjg@google.com wrote:
> > > 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 <sjg@chromium.org>
> > > ---
> > > 
> > >   common/console.c  | 11 +++++++++++
> > >   include/console.h | 19 +++++++++++++++++++
> > >   2 files changed, 30 insertions(+)
> > > 
> > > Applied to u-boot-dm, thanks!
> > > 
> > 
> > With this merged patch U-Boot does not compile:
> > 
> > common/console.c:629:26: error: passing argument 1 of ‘membuff_readline’
> > discards ‘volatile’ qualifier from pointer target type
> > [-Werror=discarded-qualifiers]
> >   629 |  return membuff_readline(&gd->console_out, str, maxlen, ' ');
> >       |                          ^~~~~~~~~~~~~~~~
> > In file included from include/asm-generic/global_data.h:24,
> >                  from ./arch/arm/include/asm/global_data.h:87,
> >                  from include/common.h:36,
> >                  from common/console.c:7:
> 
> ... with gcc-9.x I assume.  We really do need to extend the CI loops to
> cover this someway or another, at least for Sandbox like with do with
> clang.  Or maybe even just a newer clang would also catch it?  It looks
> like an "easy" path forward here to test at least is to switch from
> LLVM-7 to LLVM-10.  I'll fire off a travis test now and see what
> happens.

I did manage to convince Travis to use LLVM-10 but it doesn't throw out
a warning on this code.  I'll post the patch all the same as an RFC for
now as we'll need it at some point.

Patch
diff mbox series

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
  *