Asterisk - The Open Source Telephony Project GIT-master-f36a736
test_scope_trace.c
Go to the documentation of this file.
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/*!
20 * \file
21 * \brief Test for Scope Trace
22 *
23 * \author\verbatim George Joseph <gjoseph@digium.com> \endverbatim
24 *
25 * tests for Scope Trace
26 * \ingroup tests
27 */
28
29/*** MODULEINFO
30 <depend>TEST_FRAMEWORK</depend>
31 <support_level>core</support_level>
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
42static 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
48static void test_scope_trace(void)
49{
50 SCOPE_ENTER(1, "subfunction\n");
51 SCOPE_EXIT_RTN("got out\n");
52}
53
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
67
68 SCOPE_EXIT_RTN_VALUE(AST_TEST_PASS, "test no variables\n");
69}
70
71
72AST_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 /* need to exit the case scope */
87 SCOPE_EXIT("TEST_INIT\n");
88 /* need to exit the function */
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");
105 }
106
107 ast_trace(1);
108 ast_trace(1, "test no variables\n");
109 ast_trace(1, "%s\n", "test variable");
110
112}
113
114static int unload_module(void)
115{
116 AST_TEST_UNREGISTER(scope_test);
117 return 0;
118}
119
120static int load_module(void)
121{
122 AST_TEST_REGISTER(scope_test);
124}
125
Asterisk main include file. File version handling, generic pbx functions.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define SCOPE_EXIT_RTN(...)
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_TRACE(__level,...)
#define SCOPE_ENTER(level,...)
#define SCOPE_EXIT_EXPR(__expr,...)
#define SCOPE_EXIT(...)
#define ast_trace(level,...)
Support for logging to various files, console and syslog Configuration in file logger....
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
def info(msg)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
Definition: strings.h:1189
Support for dynamic strings.
Definition: strings.h:623
Test Framework API.
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_FAIL
Definition: test.h:196
@ AST_TEST_NOT_RUN
Definition: test.h:194
static struct test_val a
static const char * str_appender(struct ast_str **buf, char *a)
AST_TEST_DEFINE(scope_test)
static int test_scope_enter_function(void)
static void test_scope_trace(void)
static int load_module(void)
static int unload_module(void)
Utility functions.