Skip to content

Commit

Permalink
console: separate record overflow logic and add
Browse files Browse the repository at this point in the history
console_record_isempty as avail doesn't serve to know
output has been read fully with readline's
  • Loading branch information
IonAgorria authored and clamor-s committed Oct 3, 2023
1 parent 5155cd1 commit b322c4b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
15 changes: 12 additions & 3 deletions common/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,8 @@ int console_record_init(void)
ret = membuff_new((struct membuff *)&gd->console_in,
CONFIG_CONSOLE_RECORD_IN_SIZE);

gd->flags |= GD_FLG_RECORD;

return ret;
}

Expand All @@ -836,11 +838,13 @@ int console_record_reset_enable(void)
return 0;
}

int console_record_readline(char *str, int maxlen)
bool console_record_overflow(void)
{
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');
}
Expand All @@ -850,6 +854,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));
Expand Down
14 changes: 14 additions & 0 deletions include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down
9 changes: 4 additions & 5 deletions test/ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

return 0;
}

Expand Down

0 comments on commit b322c4b

Please sign in to comment.