diff options
author | Vic Yang <victoryang@chromium.org> | 2013-08-07 06:06:44 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-08-18 04:27:27 -0700 |
commit | 0e9d829e913a28f148a191bb2664a91e2888d985 (patch) | |
tree | 6d5bceb2710d6dd72a8897773950e94ef11845aa /test/console_edit.c | |
parent | 0ece0dc9556f065f89e67af72847579d1b4ce3cd (diff) | |
download | chrome-ec-0e9d829e913a28f148a191bb2664a91e2888d985.tar.gz |
Add test for console command history
This tests that command history is as expected. Also fix a bug that some
checks in console_edit test are skipped.
BUG=chrome-os-partner:19236
TEST=Pass console_edit test.
BRANCH=None
Change-Id: Ifbd3d1690f25b35bf5efe523e656b013aa534d26
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/64837
Diffstat (limited to 'test/console_edit.c')
-rw-r--r-- | test/console_edit.c | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/test/console_edit.c b/test/console_edit.c index 1649102477..5b4cc7944c 100644 --- a/test/console_edit.c +++ b/test/console_edit.c @@ -68,6 +68,26 @@ static void ctrl_key(char c) UART_INJECT(seq); } +/* + * Helper function to compare multiline strings. When comparing, CR's are + * ignored. + */ +static int compare_multiline_string(const char *s1, const char *s2) +{ + do { + while (*s1 == '\r') + ++s1; + while (*s2 == '\r') + ++s2; + if (*s1 != *s2) + return 1; + ++s1; + ++s2; + } while (*s1 || *s2); + + return 0; +} + /*****************************************************************************/ /* Tests */ @@ -156,8 +176,7 @@ static int test_history_up_up(void) arrow_key(ARROW_UP, 2); UART_INJECT("\n"); msleep(30); - TEST_CHECK(cmd_1_call_cnt == 2); - TEST_CHECK(cmd_2_call_cnt == 1); + TEST_CHECK(cmd_1_call_cnt == 2 && cmd_2_call_cnt == 1); } static int test_history_up_up_down(void) @@ -172,8 +191,7 @@ static int test_history_up_up_down(void) arrow_key(ARROW_DOWN, 1); UART_INJECT("\n"); msleep(30); - TEST_CHECK(cmd_1_call_cnt == 1); - TEST_CHECK(cmd_2_call_cnt == 2); + TEST_CHECK(cmd_1_call_cnt == 1 && cmd_2_call_cnt == 2); } static int test_history_edit(void) @@ -185,8 +203,7 @@ static int test_history_edit(void) arrow_key(ARROW_UP, 1); UART_INJECT("\b2\n"); msleep(30); - TEST_CHECK(cmd_1_call_cnt == 1); - TEST_CHECK(cmd_2_call_cnt == 1); + TEST_CHECK(cmd_1_call_cnt == 1 && cmd_2_call_cnt == 1); } static int test_history_stash(void) @@ -200,8 +217,32 @@ static int test_history_stash(void) arrow_key(ARROW_DOWN, 1); UART_INJECT("2\n"); msleep(30); - TEST_CHECK(cmd_1_call_cnt == 1); - TEST_CHECK(cmd_2_call_cnt == 1); + TEST_CHECK(cmd_1_call_cnt == 1 && cmd_2_call_cnt == 1); +} + +static int test_history_list(void) +{ + const char *exp_output = "history\n" /* Input command */ + "test3\n" /* Output 4 last commands */ + "test4\n" + "test5\n" + "history\n" + "> "; + + UART_INJECT("test1\n"); + UART_INJECT("test2\n"); + UART_INJECT("test3\n"); + UART_INJECT("test4\n"); + UART_INJECT("test5\n"); + msleep(30); + test_capture_console(1); + UART_INJECT("history\n"); + msleep(30); + test_capture_console(0); + TEST_ASSERT(compare_multiline_string(test_get_captured_console(), + exp_output) == 0); + + return EC_SUCCESS; } void run_test(void) @@ -219,6 +260,7 @@ void run_test(void) RUN_TEST(test_history_up_up_down); RUN_TEST(test_history_edit); RUN_TEST(test_history_stash); + RUN_TEST(test_history_list); test_print_result(); } |