Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: tests/tpm_lite/timing.c

Issue 6719005: Cherry-pick vboot_reference files from TOT to support crossystem (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@0.11.257.B
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « host/lib/crossystem.c ('k') | tests/vboot_nvstorage_test.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 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 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /* Timing test for various TPM operations. This is mostly a sanity check to 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 7 * make sure the part doesn't have ridicolously bad timing on simple
8 * operations. 8 * operations.
9 */ 9 */
10 10
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <stdint.h> 12 #include <stdint.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <sys/time.h> 14 #include <sys/time.h>
15 #include <time.h> 15 #include <time.h>
16 16
17 #include "tlcl.h" 17 #include "tlcl.h"
18 #include "tlcl_tests.h" 18 #include "tlcl_tests.h"
19 #include "utility.h" 19 #include "utility.h"
20 20
21 /* Runs [op] and ensures it returns success and doesn't run longer than 21 /* Runs [op] and ensures it returns success and doesn't run longer than
22 * [time_limit] in milliseconds. 22 * [time_limit] in milliseconds.
23 */ 23 */
24 #define TTPM_CHECK(op, time_limit) do { \ 24 #define TTPM_CHECK(op, time_limit) do { \
25 struct timeval before, after; \ 25 struct timeval before, after; \
26 int time; \ 26 int time; \
27 uint32_t __result; \ 27 uint32_t __result; \
28 gettimeofday(&before, NULL); \ 28 gettimeofday(&before, NULL); \
29 __result = op; \ 29 __result = op; \
30 if (__result != TPM_SUCCESS) { \ 30 if (__result != TPM_SUCCESS) { \
31 printf(#op ": error 0x%x\n", __result); \ 31 printf(#op ": error 0x%x\n", __result); \
32 exit(1); \ 32 errors++; \
33 } \ 33 } \
34 gettimeofday(&after, NULL); \ 34 gettimeofday(&after, NULL); \
35 time = (int) ((after.tv_sec - before.tv_sec) * 1000 + \ 35 time = (int) ((after.tv_sec - before.tv_sec) * 1000 + \
36 (after.tv_usec - before.tv_usec) / 1000); \ 36 (after.tv_usec - before.tv_usec) / 1000); \
37 printf(#op ": %d ms\n", time); \ 37 printf(#op ": %d ms\n", time); \
38 if (time > time_limit) { \ 38 if (time > time_limit) { \
39 printf(#op " exceeded " #time_limit " ms\n"); \ 39 printf(#op " exceeded " #time_limit " ms\n"); \
40 exit(1); \ 40 time_limit_exceeded = 1; \
41 } \ 41 } \
42 } while (0) 42 } while (0)
43 43
44 int main(int argc, char** argv) { 44 int main(int argc, char** argv) {
45 uint32_t x; 45 uint32_t x;
46 uint8_t in[20], out[20]; 46 uint8_t in[20], out[20];
47 int time_limit_exceeded = 0;
48 int errors = 0;
47 49
48 TlclLibInit(); 50 TlclLibInit();
51 TTPM_CHECK(0, 50);
49 TTPM_CHECK(TlclStartupIfNeeded(), 50); 52 TTPM_CHECK(TlclStartupIfNeeded(), 50);
50 TTPM_CHECK(TlclContinueSelfTest(), 100); 53 TTPM_CHECK(TlclContinueSelfTest(), 100);
51 TTPM_CHECK(TlclSelfTestFull(), 1000); 54 TTPM_CHECK(TlclSelfTestFull(), 1000);
52 TTPM_CHECK(TlclAssertPhysicalPresence(), 100); 55 TTPM_CHECK(TlclAssertPhysicalPresence(), 100);
53 TTPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), 100); 56 TTPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
54 TTPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)), 100); 57 TTPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
55 TTPM_CHECK(TlclExtend(0, in, out), 200); 58 TTPM_CHECK(TlclExtend(0, in, out), 200);
56 TTPM_CHECK(TlclSetGlobalLock(), 50); 59 TTPM_CHECK(TlclSetGlobalLock(), 50);
57 TTPM_CHECK(TlclLockPhysicalPresence(), 100); 60 TTPM_CHECK(TlclLockPhysicalPresence(), 100);
58 printf("TEST SUCCEEDED\n"); 61 if (time_limit_exceeded || errors > 0) {
59 return 0; 62 printf("TEST FAILED\n");
63 exit(1);
64 } else {
65 printf("TEST SUCCEEDED\n");
66 return 0;
67 }
60 } 68 }
OLDNEW
« no previous file with comments | « host/lib/crossystem.c ('k') | tests/vboot_nvstorage_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698