main-sys.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <stdbool.h>
  11. #include <stdlib.h>
  12. #define LOGMODULE test
  13. #include "tss2_sys.h"
  14. #include "util/log.h"
  15. #include "test.h"
  16. #include "test-options.h"
  17. #include "context-util.h"
  18. /**
  19. * This program is a template for integration tests (ones that use the TCTI
  20. * and the SYS contexts / API directly). It does nothing more than parsing
  21. * command line options that allow the caller (likely a script) to specify
  22. * which TCTI to use for the test.
  23. */
  24. int
  25. main (int argc,
  26. char *argv[])
  27. {
  28. TSS2_SYS_CONTEXT *sys_context;
  29. int ret;
  30. test_opts_t opts = {
  31. .tcti_type = TCTI_DEFAULT,
  32. .device_file = DEVICE_PATH_DEFAULT,
  33. .socket_address = HOSTNAME_DEFAULT,
  34. .socket_port = PORT_DEFAULT,
  35. };
  36. UNUSED(argc);
  37. UNUSED(argv);
  38. get_test_opts_from_env (&opts);
  39. if (sanity_check_test_opts (&opts) != 0) {
  40. LOG_ERROR("Checking test options");
  41. return 99; /* fatal error */
  42. }
  43. sys_context = sys_init_from_opts (&opts);
  44. if (sys_context == NULL) {
  45. LOG_ERROR("SYS context not initialized");
  46. return 99; /* fatal error */
  47. }
  48. ret = Tss2_Sys_Startup(sys_context, TPM2_SU_CLEAR);
  49. if (ret != TSS2_RC_SUCCESS && ret != TPM2_RC_INITIALIZE) {
  50. LOG_ERROR("TPM Startup FAILED! Response Code : 0x%x", ret);
  51. exit(1);
  52. }
  53. ret = test_invoke (sys_context);
  54. sys_teardown_full (sys_context);
  55. return ret;
  56. }