esys-nulltcti.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*******************************************************************************
  3. * Copyright 2018, Fraunhofer SIT sponsored by Infineon Technologies AG
  4. * All rights reserved.
  5. ******************************************************************************/
  6. #ifdef HAVE_CONFIG_H
  7. #include <config.h>
  8. #endif
  9. #include <stdarg.h>
  10. #include <inttypes.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <setjmp.h>
  14. #include <cmocka.h>
  15. #include "tss2_esys.h"
  16. #define LOGMODULE tests
  17. #include "util/log.h"
  18. #define TCTI_FAKE_MAGIC 0x46414b4500000000ULL /* 'FAKE\0' */
  19. #define TCTI_FAKE_VERSION 0x1
  20. typedef TSS2_TCTI_CONTEXT_COMMON_V1 TSS2_TCTI_CONTEXT_FAKE;
  21. void
  22. tcti_fake_finalize(TSS2_TCTI_CONTEXT *tctiContext)
  23. {
  24. UNUSED(tctiContext);
  25. }
  26. TSS2_RC
  27. __wrap_Tss2_TctiLdr_Initialize (const char *nameConf,
  28. TSS2_TCTI_CONTEXT **tcti)
  29. {
  30. if (tcti == NULL)
  31. return TSS2_BASE_RC_GENERAL_FAILURE;
  32. /* This is to calm down scan-build */
  33. TSS2_TCTI_CONTEXT_FAKE **faketcti = (TSS2_TCTI_CONTEXT_FAKE **) tcti;
  34. *faketcti = calloc(1, sizeof(TSS2_TCTI_CONTEXT_FAKE));
  35. TSS2_TCTI_MAGIC(*faketcti) = TCTI_FAKE_MAGIC;
  36. TSS2_TCTI_VERSION(*faketcti) = TCTI_FAKE_VERSION;
  37. TSS2_TCTI_TRANSMIT(*faketcti) = (void*)1;
  38. TSS2_TCTI_RECEIVE(*faketcti) = (void*)1;
  39. TSS2_TCTI_FINALIZE(*faketcti) = tcti_fake_finalize;
  40. TSS2_TCTI_CANCEL(*faketcti) = NULL;
  41. TSS2_TCTI_GET_POLL_HANDLES(*faketcti) = NULL;
  42. TSS2_TCTI_SET_LOCALITY(*faketcti) = NULL;
  43. return TSS2_RC_SUCCESS;
  44. }
  45. void
  46. __wrap_Tss2_TctiLdr_Finalize (TSS2_TCTI_CONTEXT **tcti)
  47. {
  48. free(*tcti);
  49. *tcti = NULL;
  50. }
  51. static void
  52. test(void **state)
  53. {
  54. TSS2_RC r;
  55. ESYS_CONTEXT *ectx;
  56. r = Esys_Initialize(&ectx, NULL, NULL);
  57. assert_int_equal(r, TSS2_RC_SUCCESS);
  58. Esys_Finalize(&ectx);
  59. assert_ptr_equal(ectx, NULL);
  60. }
  61. int
  62. main(int argc, char *argv[])
  63. {
  64. const struct CMUnitTest tests[] = {
  65. cmocka_unit_test(test),
  66. };
  67. return cmocka_run_group_tests(tests, NULL, NULL);
  68. }