1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /*********************************************************************** 3 * Copyright (c) 2017-2018, Intel Corporation 4 * 5 * All rights reserved. 6 ***********************************************************************/ 7 #ifdef HAVE_CONFIG_H 8 #include <config.h> 9 #endif 10 11 #include <stdbool.h> 12 #include <stdlib.h> 13 14 #define LOGMODULE test 15 #include "tss2_sys.h" 16 #include "util/log.h" 17 #include "test.h" 18 #include "test-options.h" 19 #include "context-util.h" 20 21 /** 22 * This program is a template for integration tests (ones that use the TCTI 23 * and the SAPI contexts / API directly). It does nothing more than parsing 24 * command line options that allow the caller (likely a script) to specify 25 * which TCTI to use for the test. 26 */ 27 int main(int argc,char * argv[])28main (int argc, 29 char *argv[]) 30 { 31 TSS2_SYS_CONTEXT *sapi_context; 32 int ret; 33 test_opts_t opts = { 34 .tcti_type = TCTI_DEFAULT, 35 .device_file = DEVICE_PATH_DEFAULT, 36 .socket_address = HOSTNAME_DEFAULT, 37 .socket_port = PORT_DEFAULT, 38 }; 39 40 (void) argc; 41 (void) argv; 42 43 get_test_opts_from_env (&opts); 44 if (sanity_check_test_opts (&opts) != 0) { 45 LOG_ERROR("Checking test options"); 46 return 99; /* fatal error */ 47 } 48 sapi_context = sapi_init_from_opts (&opts); 49 if (sapi_context == NULL) { 50 LOG_ERROR("SAPI context not initialized"); 51 return 99; /* fatal error */ 52 } 53 54 ret = Tss2_Sys_Startup(sapi_context, TPM2_SU_CLEAR); 55 if (ret != TSS2_RC_SUCCESS && ret != TPM2_RC_INITIALIZE) { 56 LOG_ERROR("TPM Startup FAILED! Response Code : 0x%x", ret); 57 exit(1); 58 } 59 60 ret = test_invoke (sapi_context); 61 62 sapi_teardown_full (sapi_context); 63 64 return ret; 65 } 66