45 unsigned int x_success;
46 unsigned int x_failure;
47 unsigned int u_success;
48 unsigned int u_failure;
51 static void output_tests(
struct test *tests,
size_t num_tests,
int fd)
55 for (x = 0; x < num_tests; x++) {
56 ast_cli(fd,
"Test %u: %s\n", x + 1, tests[x].name);
57 ast_cli(fd,
"\tExpected Successes: %u\n", tests[x].x_success);
58 ast_cli(fd,
"\tExpected Failures: %u\n", tests[x].x_failure);
59 ast_cli(fd,
"\tUnexpected Successes: %u\n", tests[x].u_success);
60 ast_cli(fd,
"\tUnexpected Failures: %u\n", tests[x].u_failure);
61 ast_cli(fd,
"Test %u Result: %s\n", x + 1, (tests[x].u_success + tests[x].u_failure) ?
"FAIL" :
"PASS");
70 struct test tests[] = {
71 { .name =
"Simple register/message/unregister",
73 { .name =
"Register multiple levels",
79 e->
command =
"logger test dynamic";
81 "Usage: logger test dynamic\n"
88 for (test = 0; test < ARRAY_LEN(tests); test++) {
89 ast_cli(a->fd,
"Test %u: %s.\n", test + 1, tests[test].name);
93 ast_cli(a->fd,
"Test: got level %u\n", level);
96 tests[test].x_success++;
98 ast_cli(a->fd,
"Test: Failed, could not register level 'test'.\n");
99 tests[test].u_failure++;
104 char level_name[18][8];
106 for (x = 0; x < ARRAY_LEN(level_name); x++) {
107 sprintf(level_name[x],
"level%02u", x);
110 tests[test].u_failure++;
112 tests[test].x_failure++;
114 level_name[x][0] =
'\0';
116 ast_cli(a->fd,
"Test: registered '%s', got level %u\n", level_name[x], level);
118 tests[test].x_success++;
120 tests[test].u_success++;
125 for (x = 0; x < ARRAY_LEN(level_name); x++) {
126 if (!ast_strlen_zero(level_name[x])) {
134 output_tests(tests, ARRAY_LEN(tests), a->fd);
143 struct test tests[] = {
144 { .name =
"Log 10,000 messages",
150 e->
command =
"logger test performance";
152 "Usage: logger test performance\n"
159 for (test = 0; test < ARRAY_LEN(tests); test++) {
160 ast_cli(a->fd,
"Test %u: %s.\n", test + 1, tests[test].name);
165 struct timeval start, end;
168 ast_cli(a->fd,
"Test: got level %u\n", level);
170 for (x = 0; x < 10000; x++) {
175 ast_cli(a->fd,
"Test: 10,000 messages in %f seconds.\n", (
float) elapsed / 1000);
177 tests[test].x_success++;
179 ast_cli(a->fd,
"Test: Failed, could not register level 'perftest'.\n");
180 tests[test].u_failure++;
186 output_tests(tests, ARRAY_LEN(tests), a->fd);
194 int current_queue_limit;
196 struct timeval start, end;
198 char tmppath[] =
"/tmp/asterisk_logger_queue.XXXXXX";
203 e->
command =
"logger test queue";
205 "Usage: logger test queue\n"
212 fd = mkstemp(tmppath);
214 ast_cli(a->fd,
"Test: Failed, could not create temporary log file '%s'.\n", tmppath);
220 ast_cli(a->fd,
"Test: Failed, could not register level 'queuetest'.\n");
223 ast_cli(a->fd,
"Test: got level %d for 'queuetest'.\n", level);
226 ast_cli(a->fd,
"Test: Unable to create logger channel '%s'\n", tmppath);
231 ast_cli(a->fd,
"Test: Current queue limit: %d. Setting to 100 for test.\n", current_queue_limit);
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");
238 for (x = 0; x < 10000; x++) {
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);
258 AST_CLI_DEFINE(handle_cli_dynamic_level_test,
"Test the dynamic logger level implementation"),
259 AST_CLI_DEFINE(handle_cli_performance_test,
"Test the logger performance"),
260 AST_CLI_DEFINE(handle_cli_queue_test,
"Test the logger queue"),
263 static int unload_module(
void)
269 static int load_module(
void)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
descriptor for a cli entry.
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
int ast_logger_get_queue_limit(void)
Get the maximum number of messages allowed in the processing queue.
void ast_logger_set_queue_limit(int queue_limit)
Set the maximum number of messages allowed in the processing queue.
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
General Asterisk PBX channel definitions.
Core PBX routines and definitions.
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
int ast_logger_register_level(const char *name)
Register a new logger level.
Standard Command Line Interface.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...