test_scope_trace.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2020, Sangoma Technologies Corp
  5. *
  6. * George Joseph <gjoseph@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \file
  20. * \brief Test for Scope Trace
  21. *
  22. * \author\verbatim George Joseph <gjoseph@digium.com> \endverbatim
  23. *
  24. * tests for Scope Trace
  25. * \ingroup tests
  26. */
  27. /*** MODULEINFO
  28. <depend>TEST_FRAMEWORK</depend>
  29. <support_level>core</support_level>
  30. ***/
  31. #include "asterisk.h"
  32. #include "asterisk/utils.h"
  33. #include "asterisk/module.h"
  34. #include "asterisk/test.h"
  35. #include "asterisk/logger.h"
  36. static const char *str_appender(struct ast_str**buf, char *a)
  37. {
  38. ast_str_append(buf, 0, "<append %s>", a);
  39. return ast_str_buffer(*buf);
  40. }
  41. static void test_scope_trace(void)
  42. {
  43. SCOPE_ENTER(1, "subfunction\n");
  44. SCOPE_EXIT_RTN("got out\n");
  45. }
  46. static int test_scope_enter_function(void)
  47. {
  48. SCOPE_ENTER(1, "%s %s %s %s %s %s %s\n",
  49. ast_str_tmp(12, str_appender(&STR_TMP, "str1")),
  50. ast_str_tmp(12, str_appender(&STR_TMP, "str2")),
  51. ast_str_tmp(32, str_appender(&STR_TMP, "AAAAAAAAAAAAAAAAAAAAAAAA")),
  52. ast_str_tmp(12, str_appender(&STR_TMP, "B")),
  53. "ccccccccccccc",
  54. ast_str_tmp(12, str_appender(&STR_TMP, "DDDDD")),
  55. ast_str_tmp(12, str_appender(&STR_TMP, "ww"))
  56. );
  57. test_scope_trace();
  58. SCOPE_EXIT_RTN_VALUE(AST_TEST_PASS, "test no variables\n");
  59. }
  60. AST_TEST_DEFINE(scope_test)
  61. {
  62. SCOPE_ENTER(1, "top %s function\n", "scope_test");
  63. ast_trace(1, "%s\n", "test outer");
  64. switch (cmd) {
  65. case TEST_INIT:
  66. {
  67. SCOPE_ENTER(1, "TEST_INIT\n");
  68. info->name = "scope_test";
  69. info->category = "/main/logging/";
  70. info->summary = "Scope Trace Tests";
  71. info->description = "Scope Trace Tests";
  72. /* need to exit the case scope */
  73. SCOPE_EXIT("TEST_INIT\n");
  74. /* need to exit the function */
  75. SCOPE_EXIT_RTN_VALUE(AST_TEST_NOT_RUN, "BYE\n");
  76. }
  77. case TEST_EXECUTE:
  78. {
  79. SCOPE_ENTER(1, "TEST_EXECUTE\n");
  80. ast_trace(1, "%s\n", "test execute");
  81. SCOPE_EXIT_EXPR(break, "TEST_EXECUTE\n");
  82. }
  83. default:
  84. ast_test_status_update(test, "Shouldn't have gotten here\n");
  85. return AST_TEST_FAIL;
  86. }
  87. if (1) {
  88. SCOPE_TRACE(1, "IF block\n");
  89. test_scope_enter_function();
  90. }
  91. ast_trace(1);
  92. ast_trace(1, "test no variables\n");
  93. ast_trace(1, "%s\n", "test variable");
  94. SCOPE_EXIT_RTN_VALUE(AST_TEST_PASS, "Something: %d\n", AST_TEST_PASS);
  95. }
  96. static int unload_module(void)
  97. {
  98. AST_TEST_UNREGISTER(scope_test);
  99. return 0;
  100. }
  101. static int load_module(void)
  102. {
  103. AST_TEST_REGISTER(scope_test);
  104. return AST_MODULE_LOAD_SUCCESS;
  105. }
  106. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Scope Trace Test");