summaryrefslogtreecommitdiff
path: root/tests/tlcl_tests.c
diff options
context:
space:
mode:
authorAndrey Pronin <apronin@chromium.org>2017-10-06 20:01:53 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-12 16:35:30 -0700
commit3b805725c15022783f0737a72b4f27962abf48cd (patch)
tree901659ef5fe07f9799b298f66871ef49301a782b /tests/tlcl_tests.c
parent5d5b2f16109662dceb55dfbe62772ee41887be82 (diff)
downloadvboot-firmware-scribe-10045.B.tar.gz
1) Extend TlclGetVersion to return vendor specific data, if requested. 2) Extend 'tpmc getver' to include vendor specific data. BRANCH=none BUG=chromium:771561 TEST=unit tests, running 'tpmc getver' Change-Id: Ic04c242d4e6f33b45a80479be9ab9777b317ebe2 Reviewed-on: https://chromium-review.googlesource.com/706240 Commit-Ready: Andrey Pronin <apronin@chromium.org> Tested-by: Andrey Pronin <apronin@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org>
Diffstat (limited to 'tests/tlcl_tests.c')
-rw-r--r--tests/tlcl_tests.c69
1 files changed, 64 insertions, 5 deletions
diff --git a/tests/tlcl_tests.c b/tests/tlcl_tests.c
index b8d64a86..c2f3681c 100644
--- a/tests/tlcl_tests.c
+++ b/tests/tlcl_tests.c
@@ -351,19 +351,54 @@ static void GetVersionTest(void)
uint32_t vendor;
uint64_t firmware_version;
+ uint8_t vendor_specific[32];
+ size_t vendor_specific_size;
ResetMocks();
calls[0].rsp = response;
calls[0].rsp_size = sizeof(response);
- TEST_EQ(TlclGetVersion(&vendor, &firmware_version), 0, "GetVersion");
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version, NULL, NULL), 0,
+ "GetVersion");
TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
TEST_EQ(vendor, 0x49465800, " vendor");
TEST_EQ(firmware_version, 0x420, " firmware_version");
ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ vendor_specific_size = 100;
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version,
+ NULL, &vendor_specific_size), 0,
+ "GetVersion - vendor specific size");
+ TEST_EQ(vendor_specific_size, 0xd, " vendor specific size");
+
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ vendor_specific_size = sizeof(vendor_specific);
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version,
+ vendor_specific, &vendor_specific_size), 0,
+ "GetVersion - vendor specific data");
+ TEST_EQ(vendor_specific_size, 0xd, " vendor specific size");
+ TEST_EQ(memcmp(vendor_specific, response + 29, 0xd), 0,
+ " vendor specific data check");
+
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ vendor_specific_size = 4;
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version,
+ vendor_specific, &vendor_specific_size), 0,
+ "GetVersion - vendor specific data, short buf");
+ TEST_EQ(vendor_specific_size, 4,
+ " min(vendor specific size, buf size)");
+ TEST_EQ(memcmp(vendor_specific, response + 29, 4), 0,
+ " vendor specific data check");
+
+ ResetMocks();
SetResponse(0, TPM_E_IOERROR, 0);
- TEST_EQ(TlclGetVersion(&vendor, &firmware_version), TPM_E_IOERROR,
- "GetVersion - error");
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version, NULL, NULL),
+ TPM_E_IOERROR, "GetVersion - error");
TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
/* Adjust response to indicate a 1 byte too short payload size. */
@@ -371,8 +406,32 @@ static void GetVersionTest(void)
ResetMocks();
calls[0].rsp = response;
calls[0].rsp_size = sizeof(response);
- TEST_EQ(TlclGetVersion(&vendor, &firmware_version), TPM_E_IOERROR,
- "GetVersion -- short");
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version, NULL, NULL),
+ TPM_E_IOERROR, "GetVersion -- short");
+ TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
+
+ /* Adjust response to indicate a payload size too long for the
+ * response buffer. */
+ ToTpmUint32(response + kTpmResponseHeaderLength,
+ TPM_LARGE_ENOUGH_COMMAND_SIZE - sizeof(uint32_t) -
+ kTpmResponseHeaderLength + 1);
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version, NULL, NULL),
+ TPM_E_IOERROR, "GetVersion -- long");
+ TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
+
+ /* Restore the original payload length and adjust response to contain
+ * less vendor specific data than indicated in its size. */
+ ToTpmUint32(response + kTpmResponseHeaderLength, 0x1c);
+ ToTpmUint16(response + 27, 0xd + 1);
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ TEST_EQ(TlclGetVersion(&vendor, &firmware_version,
+ NULL, &vendor_specific_size), TPM_E_IOERROR,
+ "GetVersion -- short with vendor specific");
TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
}