Test module for the logging subsystem.
- Author
Kevin P. Fleming <kpfleming@digium.com>
Definition in file test_logger.c.
Definition at line 65 of file test_logger.c.
66{
67 unsigned int level;
68 unsigned int x;
70 struct test tests[] = {
71 { .
name =
"Simple register/message/unregister",
72 },
73 { .name = "Register multiple levels",
74 },
75 };
76
77 switch (cmd) {
79 e->
command =
"logger test dynamic";
81 "Usage: logger test dynamic\n"
82 "";
86 }
87
91 case 0:
93 ast_cli(
a->fd,
"Test: got level %u\n", level);
97 } else {
98 ast_cli(
a->fd,
"Test: Failed, could not register level 'test'.\n");
100 }
101 break;
102 case 1:
103 {
104 char level_name[18][8];
105
106 for (x = 0; x <
ARRAY_LEN(level_name); x++) {
107 sprintf(level_name[x], "level%02u", x);
109 if (x < 16) {
111 } else {
113 }
114 level_name[x][0] = '\0';
115 } else {
116 ast_cli(
a->fd,
"Test: registered '%s', got level %u\n", level_name[x], level);
117 if (x < 16) {
119 } else {
121 }
122 }
123 }
124
125 for (x = 0; x <
ARRAY_LEN(level_name); x++) {
128 }
129 }
130 }
131 }
132 }
133
135
137}
void ast_cli(int fd, const char *fmt,...)
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
int ast_logger_register_level(const char *name)
Register a new logger level.
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static void output_tests(struct test *tests, size_t num_tests, int fd)
References a, ARRAY_LEN, ast_cli(), ast_log_dynamic_level, ast_logger_register_level(), ast_logger_unregister_level(), ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, test::name, NULL, output_tests(), test::u_failure, test::u_success, ast_cli_entry::usage, test::x_failure, and test::x_success.
Definition at line 139 of file test_logger.c.
140{
141 unsigned int level;
143 struct test tests[] = {
144 { .
name =
"Log 10,000 messages",
145 },
146 };
147
148 switch (cmd) {
150 e->
command =
"logger test performance";
152 "Usage: logger test performance\n"
153 "";
157 }
158
162 case 0:
164 unsigned int x;
165 struct timeval start,
end;
166 int elapsed;
167
168 ast_cli(
a->fd,
"Test: got level %u\n", level);
170 for (x = 0; x < 10000; x++) {
172 }
175 ast_cli(
a->fd,
"Test: 10,000 messages in %f seconds.\n", (
float) elapsed / 1000);
178 } else {
179 ast_cli(
a->fd,
"Test: Failed, could not register level 'perftest'.\n");
181 }
182 break;
183 }
184 }
185
187
189}
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
References a, ARRAY_LEN, ast_cli(), ast_log_dynamic_level, ast_logger_register_level(), ast_logger_unregister_level(), ast_tvdiff_ms(), ast_tvnow(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, end, test::name, NULL, output_tests(), test::u_failure, ast_cli_entry::usage, and test::x_success.
Definition at line 191 of file test_logger.c.
192{
193 int level;
194 int current_queue_limit;
195 unsigned int x;
196 struct timeval start,
end;
197 int elapsed;
198 char tmppath[] = "/tmp/asterisk_logger_queue.XXXXXX";
199 int fd;
200
201 switch (cmd) {
203 e->
command =
"logger test queue";
205 "Usage: logger test queue\n"
206 "";
210 }
211
212 fd = mkstemp(tmppath);
213 if (fd < 0) {
214 ast_cli(
a->fd,
"Test: Failed, could not create temporary log file '%s'.\n", tmppath);
216 }
217
219 if (level < 0) {
220 ast_cli(
a->fd,
"Test: Failed, could not register level 'queuetest'.\n");
222 }
223 ast_cli(
a->fd,
"Test: got level %d for 'queuetest'.\n", level);
224
226 ast_cli(
a->fd,
"Test: Unable to create logger channel '%s'\n", tmppath);
228 }
229
231 ast_cli(
a->fd,
"Test: Current queue limit: %d. Setting to 100 for test.\n", current_queue_limit);
233
234 ast_cli(
a->fd,
"Test: You should see SOME 'exceeded' and 'resumed' messages after the test "
235 "is completed. How many is dependent on system resources.\n");
236
238 for (x = 0; x < 10000; x++) {
240 }
243 ast_cli(
a->fd,
"Test: 10,000 messages in %f seconds.\n", (
float) elapsed / 1000);
244 ast_cli(
a->fd,
"Test: Completed. Resetting queue limit to %d.\n", current_queue_limit);
246
248
251 close(fd);
252 unlink(tmppath);
253
255}
int ast_logger_get_queue_limit(void)
Get the maximum number of messages allowed in the processing queue.
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
void ast_logger_set_queue_limit(int queue_limit)
Set the maximum number of messages allowed in the processing queue.
int error(const char *format,...)
References a, ast_cli(), ast_log_dynamic_level, ast_logger_create_channel(), ast_logger_get_queue_limit(), ast_logger_register_level(), ast_logger_remove_channel(), ast_logger_set_queue_limit(), AST_LOGGER_SUCCESS, ast_logger_unregister_level(), ast_tvdiff_ms(), ast_tvnow(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, end, error(), NULL, and ast_cli_entry::usage.