From 89d7fa59ea9674d8f7d561739f81cdb3d9c80774 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Thu, 13 Aug 2020 10:07:09 -0700 Subject: CBI: Make test fail if a tag is missing from unit test This patch adds a check in the unit test which fails if there is a tag missing from test_all_tags. This will force developers to pay attension to the unit test when adding a new tag. BUG=none BRANCH=none TEST=buildall Signed-off-by: Daisuke Nojiri Change-Id: I34d054493e16454c3662b289eaa6d4de362a26f4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2354200 --- test/cbi.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/cbi.c') diff --git a/test/cbi.c b/test/cbi.c index 936dc204b8..f0fe68f162 100644 --- a/test/cbi.c +++ b/test/cbi.c @@ -8,6 +8,7 @@ #include "common.h" #include "console.h" #include "cros_board_info.h" +#include "ec_commands.h" #include "gpio.h" #include "i2c.h" #include "test_util.h" @@ -125,29 +126,60 @@ static int test_all_tags(void) { uint8_t d8; uint32_t d32; + const char string[] = "abc"; + uint8_t buf[32]; + uint8_t size; + int count = 0; /* Populate all data and read out */ d8 = 0x12; TEST_ASSERT(cbi_set_board_info(CBI_TAG_BOARD_VERSION, &d8, sizeof(d8)) == EC_SUCCESS); + count++; TEST_ASSERT(cbi_set_board_info(CBI_TAG_OEM_ID, &d8, sizeof(d8)) == EC_SUCCESS); + count++; TEST_ASSERT(cbi_set_board_info(CBI_TAG_SKU_ID, &d8, sizeof(d8)) == EC_SUCCESS); + count++; + TEST_ASSERT(cbi_set_board_info(CBI_TAG_DRAM_PART_NUM, + string, sizeof(string)) + == EC_SUCCESS); + count++; + TEST_ASSERT(cbi_set_board_info(CBI_TAG_OEM_NAME, + string, sizeof(string)) + == EC_SUCCESS); + count++; TEST_ASSERT(cbi_set_board_info(CBI_TAG_MODEL_ID, &d8, sizeof(d8)) == EC_SUCCESS); + count++; TEST_ASSERT(cbi_set_board_info(CBI_TAG_FW_CONFIG, &d8, sizeof(d8)) == EC_SUCCESS); + count++; TEST_ASSERT(cbi_set_board_info(CBI_TAG_PCB_SUPPLIER, &d8, sizeof(d8)) == EC_SUCCESS); + count++; TEST_ASSERT(cbi_set_board_info(CBI_TAG_SSFC, &d8, sizeof(d8)) == EC_SUCCESS); + count++; + + /* Read out all */ TEST_ASSERT(cbi_get_board_version(&d32) == EC_SUCCESS); TEST_EQ(d32, d8, "0x%x"); TEST_ASSERT(cbi_get_oem_id(&d32) == EC_SUCCESS); TEST_EQ(d32, d8, "0x%x"); TEST_ASSERT(cbi_get_sku_id(&d32) == EC_SUCCESS); TEST_EQ(d32, d8, "0x%x"); + size = sizeof(buf); + TEST_ASSERT(cbi_get_board_info(CBI_TAG_DRAM_PART_NUM, buf, &size) + == EC_SUCCESS); + TEST_ASSERT(strncmp(buf, string, sizeof(string)) == 0); + TEST_EQ((size_t)size - 1, strlen(buf), "%zu"); + size = sizeof(buf); + TEST_ASSERT(cbi_get_board_info(CBI_TAG_OEM_NAME, buf, &size) + == EC_SUCCESS); + TEST_ASSERT(strncmp(buf, string, sizeof(string)) == 0); + TEST_EQ((size_t)size - 1, strlen(buf), "%zu"); TEST_ASSERT(cbi_get_model_id(&d32) == EC_SUCCESS); TEST_EQ(d32, d8, "0x%x"); TEST_ASSERT(cbi_get_fw_config(&d32) == EC_SUCCESS); @@ -157,6 +189,9 @@ static int test_all_tags(void) TEST_ASSERT(cbi_get_ssfc(&d32) == EC_SUCCESS); TEST_EQ(d32, d8, "0x%x"); + /* Fail if a (new) tag is missing from the unit test. */ + TEST_EQ(count, CBI_TAG_COUNT, "%d"); + /* Write protect */ gpio_set_level(GPIO_WP, 1); TEST_ASSERT(cbi_write() == EC_ERROR_ACCESS_DENIED); -- cgit v1.2.1