summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/default/src/console.c
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-08-22 11:21:05 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-22 18:44:04 +0000
commit28bd2f73640d7d055e58cc505e6544ecc8fb0bfc (patch)
tree71bb553b032fa711c12240aa9a5ccc297d386ebc /zephyr/test/drivers/default/src/console.c
parentbff54067ec96203e5d71438cd0f7d15ef38185f7 (diff)
downloadchrome-ec-28bd2f73640d7d055e58cc505e6544ecc8fb0bfc.tar.gz
zephyr: Add test for fprintf flushing
Coverage is intermittent for third_party/zephyr/main/subsys/shell/shell_fprintf.c:27. Add test that forces a fprintf buffer flush, and read back from the console to make sure all the text was written. Turn off VT100 commands in the console, it just makes it harder to look at the shell output. BRANCH=None BUG=b:242764426 TEST=./twister --coverage Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I4bae1880ccfeaf8f6586d335d386def614281e8d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3846280 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com> Tested-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Diffstat (limited to 'zephyr/test/drivers/default/src/console.c')
-rw-r--r--zephyr/test/drivers/default/src/console.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/console.c b/zephyr/test/drivers/default/src/console.c
index 9fc5fee470..ccc61f9ae3 100644
--- a/zephyr/test/drivers/default/src/console.c
+++ b/zephyr/test/drivers/default/src/console.c
@@ -5,6 +5,7 @@
#include <zephyr/zephyr.h>
#include <zephyr/ztest.h>
+#include <zephyr/shell/shell_dummy.h> /* nocheck */
#include "builtin/stdio.h"
#include "test/drivers/test_state.h"
@@ -48,4 +49,26 @@ ZTEST_USER(console, buf_notify_null)
zassert_equal(write_count, 4, "got %d", write_count);
}
+ZTEST_USER(console, shell_fprintf_full)
+{
+ const struct shell *shell_zephyr = get_ec_shell();
+ const char *buffer =
+ "This is a very long string, it will cause a buffer flush at "
+ "some point while printing to the shell. Long long text. Blah "
+ "blah. Long long text. Blah blah. Long long text. Blah blah.";
+ const char *outbuffer;
+ size_t buffer_size;
+
+ zassert_true(strlen(buffer) >= shell_zephyr->fprintf_ctx->buffer_size,
+ "buffer is too short, fix test.");
+
+ shell_backend_dummy_clear_output(shell_zephyr); /* nocheck */
+ shell_fprintf(shell_zephyr, SHELL_NORMAL, "%s", buffer);
+
+ outbuffer = shell_backend_dummy_get_output(shell_zephyr, /* nocheck */
+ &buffer_size);
+ zassert_true(strncmp(outbuffer, buffer, strlen(buffer)) == 0,
+ "Invalid console output %s", outbuffer);
+}
+
ZTEST_SUITE(console, drivers_predicate_post_main, NULL, NULL, NULL, NULL);