diff options
author | Luigi Semenzato <semenzato@google.com> | 2011-02-08 14:50:41 -0800 |
---|---|---|
committer | Luigi Semenzato <semenzato@google.com> | 2011-02-08 14:50:41 -0800 |
commit | 8e14bc05e8a092b5dc2f43780c0537775c8f5026 (patch) | |
tree | 597013b7f0f1e7a9000e9ee40553f3c90c3de2fd | |
parent | 856e072e8119cab07fd884e54853f1c3897452ee (diff) | |
download | vboot-8e14bc05e8a092b5dc2f43780c0537775c8f5026.tar.gz |
Improve error messages from tests.
Change-Id: I111e0fb38188e70659d735f0949a7bdb548a258b
BUG=433
TEST=compiled and ran the tests. No QA testing required.
Review URL: http://codereview.chromium.org/6349091
-rw-r--r-- | tests/tpm_lite/globallock.c | 7 | ||||
-rw-r--r-- | tests/tpm_lite/redefine_unowned.c | 13 | ||||
-rw-r--r-- | tests/tpm_lite/tlcl_tests.h | 23 |
3 files changed, 20 insertions, 23 deletions
diff --git a/tests/tpm_lite/globallock.c b/tests/tpm_lite/globallock.c index 98a49df7..24b6861f 100644 --- a/tests/tpm_lite/globallock.c +++ b/tests/tpm_lite/globallock.c @@ -16,7 +16,6 @@ int main(int argc, char** argv) { uint32_t zero = 0; - uint32_t result; uint32_t x; TlclLibInit(); @@ -31,8 +30,7 @@ int main(int argc, char** argv) { // Verifies that write to index0 fails. x = 1; - result = TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)); - assert(result == TPM_E_AREA_LOCKED); + TPM_EXPECT(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), TPM_E_AREA_LOCKED); TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); assert(x == 0); @@ -47,8 +45,7 @@ int main(int argc, char** argv) { // Verifies that write to index1 fails. x = 3; - result = TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)); - assert(result == TPM_E_BAD_PRESENCE); + TPM_EXPECT(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)), TPM_E_BAD_PRESENCE); TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); assert(x == 2); printf("TEST SUCCEEDED\n"); diff --git a/tests/tpm_lite/redefine_unowned.c b/tests/tpm_lite/redefine_unowned.c index eb5dfe5d..f7d70d16 100644 --- a/tests/tpm_lite/redefine_unowned.c +++ b/tests/tpm_lite/redefine_unowned.c @@ -16,7 +16,6 @@ int main(int argc, char** argv) { uint32_t perm; - uint32_t result; uint32_t x; TlclLibInit(); @@ -43,8 +42,8 @@ int main(int argc, char** argv) { TlclSetGlobalLock(); // Verifies that index0 cannot be redefined. - result = TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); - assert(result == TPM_E_AREA_LOCKED); + TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)), + TPM_E_AREA_LOCKED); // Checks that index1 can. TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t))); @@ -54,10 +53,10 @@ int main(int argc, char** argv) { TlclLockPhysicalPresence(); // Verifies that neither index0 nor index1 can be redefined. - result = TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); - assert(result == TPM_E_BAD_PRESENCE); - result = TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)); - assert(result == TPM_E_BAD_PRESENCE); + TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)), + TPM_E_BAD_PRESENCE); + TPM_EXPECT(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)), + TPM_E_BAD_PRESENCE); printf("TEST SUCCEEDED\n"); exit(0); diff --git a/tests/tpm_lite/tlcl_tests.h b/tests/tpm_lite/tlcl_tests.h index 57e8fd92..5e23ee39 100644 --- a/tests/tpm_lite/tlcl_tests.h +++ b/tests/tpm_lite/tlcl_tests.h @@ -13,18 +13,19 @@ #define INDEX0 0xcafe #define INDEX1 0xcaff -#define DO_ON_FAILURE(tpm_command, action) do { \ - uint32_t result; \ - if ((result = (tpm_command)) != TPM_SUCCESS) { \ - action; \ - } \ - } while (0) - /* Prints error and returns on failure */ -#define TPM_CHECK(tpm_command) \ - DO_ON_FAILURE(tpm_command, \ - printf("TEST FAILED: line %d: " #tpm_command ": 0x%x\n", \ - __LINE__, result); return result) +#define TPM_CHECK(tpm_command) TPM_EXPECT(tpm_command, TPM_SUCCESS) + +#define TPM_EXPECT(tpm_command, expected_result) do { \ + uint32_t _result = (tpm_command); \ + uint32_t _exp = (expected_result); \ + if (_result != _exp) { \ + printf("TEST FAILED: line %d: " #tpm_command ": 0x%x" \ + " (expecting 0x%x)\n", __LINE__, _result, _exp); \ + return _result; \ + } \ +} while (0) + /* Executes TlclStartup(), but ignores POSTINIT error if the * TLCL_RESILIENT_STARTUP environment variable is set. |