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.
References 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, ast_cli_args::fd, test::name, NULL, output_tests(), test, test::u_failure, test::u_success, ast_cli_entry::usage, test::x_failure, and test::x_success.
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++) {
93 ast_cli(a->
fd,
"Test: got level %u\n", level);
98 ast_cli(a->
fd,
"Test: Failed, could not register level 'test'.\n");
104 char level_name[18][8];
106 for (x = 0; x <
ARRAY_LEN(level_name); x++) {
107 sprintf(level_name[x],
"level%02u", x);
114 level_name[x][0] =
'\0';
116 ast_cli(a->
fd,
"Test: registered '%s', got level %u\n", level_name[x], level);
125 for (x = 0; x <
ARRAY_LEN(level_name); x++) {
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
void ast_cli(int fd, const char *fmt,...)
#define ast_strlen_zero(foo)
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
int ast_logger_register_level(const char *name)
Register a new logger level.
static void output_tests(struct test *tests, size_t num_tests, int fd)
static struct ast_test * test
Definition at line 139 of file test_logger.c.
References 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, ast_cli_args::fd, test::name, NULL, output_tests(), test, test::u_failure, ast_cli_entry::usage, and test::x_success.
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);
179 ast_cli(a->
fd,
"Test: Failed, could not register level 'perftest'.\n");
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
void ast_cli(int fd, const char *fmt,...)
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
int ast_logger_register_level(const char *name)
Register a new logger level.
static void output_tests(struct test *tests, size_t num_tests, int fd)
static struct ast_test * test
Definition at line 191 of file test_logger.c.
References 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, error(), ast_cli_args::fd, NULL, and ast_cli_entry::usage.
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);
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
void ast_cli(int fd, const char *fmt,...)
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
void ast_logger_set_queue_limit(int queue_limit)
Set the maximum number of messages allowed in the processing queue.
int ast_logger_register_level(const char *name)
Register a new logger level.
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
int ast_logger_get_queue_limit(void)
Get the maximum number of messages allowed in the processing queue.
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
int error(const char *format,...)