• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
12 #include <stdlib.h>
13 
14 #include "tss2_sys.h"
15 
16 #define LOGMODULE test
17 #include "util/log.h"
18 #include "test.h"
19 /**
20  */
21 int
test_invoke(TSS2_SYS_CONTEXT * sapi_context)22 test_invoke (TSS2_SYS_CONTEXT *sapi_context)
23 {
24     TSS2_RC rc;
25 
26     /* NOTE: this should never be done in real applications.
27      * It is only done here for test purposes.
28      */
29     TSS2_TCTI_CONTEXT_COMMON_V2 tctiContext;
30 
31     LOG_INFO("Sys_Initialize tests started.");
32 
33     rc = Tss2_Sys_Initialize( (TSS2_SYS_CONTEXT *)0, 10, (TSS2_TCTI_CONTEXT *)1, (TSS2_ABI_VERSION *)1 );
34     if( rc != TSS2_SYS_RC_BAD_REFERENCE  ) {
35         LOG_ERROR("Sys_Initialize context NULL test FAILED! Response Code : %x", rc);
36         exit(1);
37     }
38 
39     rc = Tss2_Sys_Initialize( (TSS2_SYS_CONTEXT *)1, 10, (TSS2_TCTI_CONTEXT *)0, (TSS2_ABI_VERSION *)1 );
40     if( rc != TSS2_SYS_RC_BAD_REFERENCE  ) {
41         LOG_ERROR("Sys_Initialize tcti  NULL test FAILED! Response Code : %x", rc);
42         exit(1);
43     }
44 
45     rc = Tss2_Sys_Initialize( (TSS2_SYS_CONTEXT *)1, 10, (TSS2_TCTI_CONTEXT *)1, (TSS2_ABI_VERSION *)1 );
46     if( rc != TSS2_SYS_RC_INSUFFICIENT_CONTEXT ) {
47         LOG_ERROR("Sys_Initialize insufficient context FAILED! Response Code : %x", rc);
48         exit(1);
49     }
50 
51     /* NOTE: don't do this in real applications. */
52     TSS2_TCTI_RECEIVE (&tctiContext) = (TSS2_TCTI_RECEIVE_FCN)1;
53     TSS2_TCTI_TRANSMIT (&tctiContext) = (TSS2_TCTI_TRANSMIT_FCN)0;
54 
55     rc = Tss2_Sys_Initialize( (TSS2_SYS_CONTEXT *)1, Tss2_Sys_GetContextSize (0), (TSS2_TCTI_CONTEXT *)&tctiContext, (TSS2_ABI_VERSION *)1 );
56     if( rc != TSS2_SYS_RC_BAD_TCTI_STRUCTURE ) {
57         LOG_ERROR("Sys_Initialize FAILED! Response Code : %x", rc);
58         exit(1);
59     }
60 
61     /* NOTE: don't do this in real applications. */
62     TSS2_TCTI_RECEIVE (&tctiContext) = (TSS2_TCTI_RECEIVE_FCN)0;
63     TSS2_TCTI_TRANSMIT (&tctiContext) = (TSS2_TCTI_TRANSMIT_FCN)1;
64 
65     rc = Tss2_Sys_Initialize( (TSS2_SYS_CONTEXT *)1, Tss2_Sys_GetContextSize (0), (TSS2_TCTI_CONTEXT *)&tctiContext, (TSS2_ABI_VERSION *)1 );
66     if( rc != TSS2_SYS_RC_BAD_TCTI_STRUCTURE ) {
67         LOG_ERROR("Sys_Initialize FAILED! Response Code : %x", rc);
68         exit(1);
69     }
70 
71     LOG_INFO("Sys_Initialize Test Passed!");
72     return 0;
73 }
74