| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include "asterisk.h" |
| 35 |
|
| 36 |
#include "asterisk/utils.h" |
| 37 |
#include "asterisk/module.h" |
| 38 |
#include "asterisk/test.h" |
| 39 |
#include "asterisk/logger.h" |
| 40 |
|
| 41 |
|
| 42 |
static const char *str_appender(struct ast_str**buf, char *a) |
| 43 |
{ |
| 44 |
ast_str_append(buf, 0, "<append %s>", a); |
| 45 |
return ast_str_buffer(*buf); |
| 46 |
} |
| 47 |
|
| 48 |
static void test_scope_trace(void) |
| 49 |
{ |
| 50 |
SCOPE_ENTER(1, "subfunction\n"); |
| 51 |
SCOPE_EXIT_RTN("got out\n"); |
| 52 |
} |
| 53 |
|
| 54 |
static int test_scope_enter_function(void) |
| 55 |
{ |
| 56 |
SCOPE_ENTER(1, "%s %s %s %s %s %s %s\n", |
| 57 |
ast_str_tmp(12, str_appender(&STR_TMP, "str1")), |
| 58 |
ast_str_tmp(12, str_appender(&STR_TMP, "str2")), |
| 59 |
ast_str_tmp(32, str_appender(&STR_TMP, "AAAAAAAAAAAAAAAAAAAAAAAA")), |
| 60 |
ast_str_tmp(12, str_appender(&STR_TMP, "B")), |
| 61 |
"ccccccccccccc", |
| 62 |
ast_str_tmp(12, str_appender(&STR_TMP, "DDDDD")), |
| 63 |
ast_str_tmp(12, str_appender(&STR_TMP, "ww")) |
| 64 |
); |
| 65 |
|
| 66 |
test_scope_trace(); |
| 67 |
|
| 68 |
SCOPE_EXIT_RTN_VALUE(AST_TEST_PASS, "test no variables\n"); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
AST_TEST_DEFINE(scope_test) |
| 73 |
{ |
| 74 |
SCOPE_ENTER(1, "top %s function\n", "scope_test"); |
| 75 |
|
| 76 |
ast_trace(1, "%s\n", "test outer"); |
| 77 |
|
| 78 |
switch (cmd) { |
| 79 |
case TEST_INIT: |
| 80 |
{ |
| 81 |
SCOPE_ENTER(1, "TEST_INIT\n"); |
| 82 |
info->name = "scope_test"; |
| 83 |
info->category = "/main/logging/"; |
| 84 |
info->summary = "Scope Trace Tests"; |
| 85 |
info->description = "Scope Trace Tests"; |
| 86 |
|
| 87 |
SCOPE_EXIT("TEST_INIT\n"); |
| 88 |
|
| 89 |
SCOPE_EXIT_RTN_VALUE(AST_TEST_NOT_RUN, "BYE\n"); |
| 90 |
} |
| 91 |
case TEST_EXECUTE: |
| 92 |
{ |
| 93 |
SCOPE_ENTER(1, "TEST_EXECUTE\n"); |
| 94 |
ast_trace(1, "%s\n", "test execute"); |
| 95 |
SCOPE_EXIT_EXPR(break, "TEST_EXECUTE\n"); |
| 96 |
} |
| 97 |
default: |
| 98 |
ast_test_status_update(test, "Shouldn't have gotten here\n"); |
| 99 |
return AST_TEST_FAIL; |
| 100 |
} |
| 101 |
|
| 102 |
if (1) { |
| 103 |
SCOPE_TRACE(1, "IF block\n"); |
| 104 |
test_scope_enter_function(); |
| 105 |
} |
| 106 |
|
| 107 |
ast_trace(1); |
| 108 |
ast_trace(1, "test no variables\n"); |
| 109 |
ast_trace(1, "%s\n", "test variable"); |
| 110 |
|
| 111 |
SCOPE_EXIT_RTN_VALUE(AST_TEST_PASS, "Something: %d\n", AST_TEST_PASS); |
| 112 |
} |
| 113 |
|
| 114 |
static int unload_module(void) |
| 115 |
{ |
| 116 |
AST_TEST_UNREGISTER(scope_test); |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
static int load_module(void) |
| 121 |
{ |
| 122 |
AST_TEST_REGISTER(scope_test); |
| 123 |
return AST_MODULE_LOAD_SUCCESS; |
| 124 |
} |
| 125 |
|
| 126 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Scope Trace Test"); |