OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 |
| 6 /* Timing test for various TPM operations. This is mostly a sanity check to |
| 7 * make sure the part doesn't have ridicolously bad timing on simple |
| 8 * operations. |
| 9 */ |
| 10 |
| 11 #include <stdio.h> |
| 12 #include <stdint.h> |
| 13 #include <stdlib.h> |
| 14 #include <sys/time.h> |
| 15 #include <time.h> |
| 16 |
| 17 #include "tlcl.h" |
| 18 #include "tlcl_tests.h" |
| 19 #include "utility.h" |
| 20 |
| 21 /* Runs [op] and ensures it returns success and doesn't run longer than |
| 22 * [time_limit] in milliseconds. |
| 23 */ |
| 24 #define TTPM_CHECK(op, time_limit) do { \ |
| 25 struct timeval before, after; \ |
| 26 int time; \ |
| 27 uint32_t __result; \ |
| 28 gettimeofday(&before, NULL); \ |
| 29 __result = op; \ |
| 30 if (__result != TPM_SUCCESS) { \ |
| 31 printf(#op ": error 0x%x\n", __result); \ |
| 32 exit(1); \ |
| 33 } \ |
| 34 gettimeofday(&after, NULL); \ |
| 35 time = (int) ((after.tv_sec - before.tv_sec) * 1000 + \ |
| 36 (after.tv_usec - before.tv_usec) / 1000); \ |
| 37 printf(#op ": %d ms\n", time); \ |
| 38 if (time > time_limit) { \ |
| 39 printf(#op " exceeded " #time_limit " ms\n"); \ |
| 40 exit(1); \ |
| 41 } \ |
| 42 } while (0) |
| 43 |
| 44 int main(int argc, char** argv) { |
| 45 uint32_t x; |
| 46 uint8_t in[20], out[20]; |
| 47 |
| 48 TlclLibInit(); |
| 49 TTPM_CHECK(TlclStartupIfNeeded(), 50); |
| 50 TTPM_CHECK(TlclContinueSelfTest(), 100); |
| 51 TTPM_CHECK(TlclSelfTestFull(), 1000); |
| 52 TTPM_CHECK(TlclAssertPhysicalPresence(), 100); |
| 53 TTPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), 100); |
| 54 TTPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)), 100); |
| 55 TTPM_CHECK(TlclExtend(0, in, out), 200); |
| 56 TTPM_CHECK(TlclSetGlobalLock(), 50); |
| 57 TTPM_CHECK(TlclLockPhysicalPresence(), 100); |
| 58 printf("TEST SUCCEEDED\n"); |
| 59 return 0; |
| 60 } |
OLD | NEW |