From bd74ad1e2008e31754718ecc1882a6ac98dbb11e Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Sun, 29 Sep 2013 10:07:51 +0800 Subject: [PATCH] Test more error cases of host command handling This adds tests of invalid command version and invalid command. BUG=chrome-os-partner:19236 TEST=Pass host_command test BRANCH=None Change-Id: I49ce1b4c8b31ef98d9ee8203e88adfa521471d6d Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/170935 Reviewed-by: Bill Richardson Reviewed-by: Randall Spangler --- test/host_command.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/host_command.c b/test/host_command.c index 639b32ed8a..cd8d57413c 100644 --- a/test/host_command.c +++ b/test/host_command.c @@ -119,7 +119,29 @@ static int test_hostcmd_driver_error(void) return EC_SUCCESS; } -static int test_hostcmd_wrong_version(void) +static int test_hostcmd_invalid_command(void) +{ + hostcmd_fill_in_default(); + + req->command = 0xff; + hostcmd_send(); + TEST_ASSERT(resp->result == EC_RES_INVALID_COMMAND); + + return EC_SUCCESS; +} + +static int test_hostcmd_wrong_command_version(void) +{ + hostcmd_fill_in_default(); + + req->command_version = 1; + hostcmd_send(); + TEST_ASSERT(resp->result == EC_RES_INVALID_VERSION); + + return EC_SUCCESS; +} + +static int test_hostcmd_wrong_struct_version(void) { hostcmd_fill_in_default(); @@ -153,7 +175,9 @@ void run_test(void) RUN_TEST(test_hostcmd_too_short); RUN_TEST(test_hostcmd_too_long); RUN_TEST(test_hostcmd_driver_error); - RUN_TEST(test_hostcmd_wrong_version); + RUN_TEST(test_hostcmd_invalid_command); + RUN_TEST(test_hostcmd_wrong_command_version); + RUN_TEST(test_hostcmd_wrong_struct_version); RUN_TEST(test_hostcmd_invalid_checksum); test_print_result();