Philip Tricca | 364c0ce | 2016-07-23 16:48:37 -0700 | [diff] [blame^] | 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | #include <setjmp.h> |
| 5 | #include <cmocka.h> |
| 6 | |
| 7 | #include "sapi/tpm20.h" |
| 8 | #include "sysapi_util.h" |
| 9 | |
| 10 | /** |
| 11 | * Test to be sure we get back the expected # of command handles for |
| 12 | * common command code: TPM_CC_PolicyPCR. |
| 13 | */ |
| 14 | static void |
| 15 | GetNumCommandHandles_PolicyPCR_unit (void **state) |
| 16 | { |
| 17 | int num_handles; |
| 18 | TPM_CC command_code = TPM_CC_PolicyPCR; |
| 19 | |
| 20 | num_handles = GetNumCommandHandles (command_code); |
| 21 | assert_int_equal (num_handles, 1); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Test to be sure we get back the expected * of |
| 26 | */ |
| 27 | static void |
| 28 | GetNumResponseHandles_HMAC_Start_unit (void **state) |
| 29 | { |
| 30 | int num_handles; |
| 31 | TPM_CC command_code = TPM_CC_HMAC_Start; |
| 32 | |
| 33 | num_handles = GetNumResponseHandles (command_code); |
| 34 | assert_int_equal (num_handles, 1); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Tests to ensure that GetNumCommandHandles and GetNumResponseHandles |
| 39 | * returns 0 for unknown command codes. |
| 40 | * Since 0 is a valid number here it may make more sense to return something |
| 41 | * to indicate an error condition. Probaly best to catch unknown command |
| 42 | * codes as early as possible? |
| 43 | */ |
| 44 | static void |
| 45 | GetNumCommandHandles_LAST_plus_one (void **state) |
| 46 | { |
| 47 | int num_handles; |
| 48 | TPM_CC command_code = TPM_CC_LAST + 1; |
| 49 | |
| 50 | num_handles = GetNumCommandHandles (command_code); |
| 51 | assert_int_equal (num_handles, 0); |
| 52 | } |
| 53 | |
| 54 | static void |
| 55 | GetNumResponseHandles_LAST_plus_one (void **state) |
| 56 | { |
| 57 | int num_handles; |
| 58 | TPM_CC command_code = TPM_CC_LAST + 1; |
| 59 | |
| 60 | num_handles = GetNumResponseHandles (command_code); |
| 61 | assert_int_equal (num_handles, 0); |
| 62 | } |
| 63 | |
| 64 | int |
| 65 | main (int argc, |
| 66 | char *argv[]) |
| 67 | { |
| 68 | const UnitTest tests [] = { |
| 69 | unit_test (GetNumCommandHandles_PolicyPCR_unit), |
| 70 | unit_test (GetNumResponseHandles_HMAC_Start_unit), |
| 71 | unit_test (GetNumCommandHandles_LAST_plus_one), |
| 72 | unit_test (GetNumResponseHandles_LAST_plus_one), |
| 73 | }; |
| 74 | return run_tests (tests); |
| 75 | } |