log.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /***********************************************************************
  3. * Copyright (c) 2019, Infineon Technologies AG
  4. *
  5. * All rights reserved.
  6. ***********************************************************************/
  7. #ifdef HAVE_CONFIG_H
  8. #include <config.h>
  9. #endif
  10. #include <inttypes.h>
  11. #include <stdio.h>
  12. #include <stdbool.h>
  13. #include <stdlib.h>
  14. #include <setjmp.h>
  15. #include <cmocka.h>
  16. #include "tss2_tpm2_types.h"
  17. #include "util/io.h"
  18. #define LOGMODULE test
  19. #include "util/log.h"
  20. static void
  21. execute_doLog(char *env_log_level){
  22. setenv("TSS2_LOG", env_log_level, 1);
  23. LOG_DEBUG("test");
  24. LOG_TRACE("test");
  25. LOG_INFO("test");
  26. LOG_WARNING("test");
  27. LOG_INFO("test");
  28. /* reset log level for next test */
  29. LOGMODULE_status = LOGLEVEL_UNDEFINED;
  30. }
  31. static void
  32. doLog_test (void **state)
  33. {
  34. execute_doLog("ALL+none");
  35. execute_doLog("ALL+unused");
  36. execute_doLog("ALL+error");
  37. execute_doLog("ALL+warning");
  38. execute_doLog("ALL+info");
  39. execute_doLog("ALL+debug");
  40. execute_doLog("ALL+trace");
  41. execute_doLog("ALL+xxxxx");
  42. execute_doLog("marshal+xxxxx");
  43. execute_doLog("marshal+debug");
  44. execute_doLog("test+debug");
  45. execute_doLog("test+xxxx");
  46. execute_doLog("ukn+xxxx");
  47. execute_doLog("test+xxxx");
  48. execute_doLog("TEST+trace");
  49. execute_doLog("ALL+xxxxx,mashal+xxxx,tcti+DEBug");
  50. execute_doLog("ALL+none,mashal+WARNING,tcti+DEBug");
  51. }
  52. int
  53. main (int argc, char *argv[])
  54. {
  55. const struct CMUnitTest tests[] = {
  56. cmocka_unit_test (doLog_test),
  57. };
  58. return cmocka_run_group_tests (tests, NULL, NULL);
  59. }