[asterisk-commits] kpfleming: branch kpfleming/dynamic_logger_levels r191994 - in /team/kpflemin...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon May 4 07:29:01 CDT 2009
Author: kpfleming
Date: Mon May 4 07:28:58 2009
New Revision: 191994
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=191994
Log:
make level unregistration safe in spite of messages that may be queued
add another test to the test module, and make the test module able to track and output successess and failures
Modified:
team/kpfleming/dynamic_logger_levels/main/logger.c
team/kpfleming/dynamic_logger_levels/tests/test_logger.c
Modified: team/kpfleming/dynamic_logger_levels/main/logger.c
URL: http://svn.digium.com/svn-view/asterisk/team/kpfleming/dynamic_logger_levels/main/logger.c?view=diff&rev=191994&r1=191993&r2=191994
==============================================================================
--- team/kpfleming/dynamic_logger_levels/main/logger.c (original)
+++ team/kpfleming/dynamic_logger_levels/main/logger.c Mon May 4 07:28:58 2009
@@ -232,10 +232,6 @@
found = 1;
break;
}
- }
- if (!found) {
- fprintf(stderr, "Logfile Warning: Unknown keyword '%s' at line %d of logger.conf\n",
- w, lineno);
}
}
@@ -372,10 +368,10 @@
AST_RWLIST_WRLOCK(&logchannels);
while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list)))
ast_free(chan);
+ global_logmask = 0;
if (!locked)
AST_RWLIST_UNLOCK(&logchannels);
- global_logmask = 0;
errno = 0;
/* close syslog */
closelog();
@@ -393,9 +389,9 @@
if (!locked)
AST_RWLIST_WRLOCK(&logchannels);
AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
+ global_logmask |= chan->logmask;
if (!locked)
AST_RWLIST_UNLOCK(&logchannels);
- global_logmask |= chan->logmask;
return;
}
@@ -1377,6 +1373,7 @@
void ast_logger_unregister_level(const char *name)
{
+ unsigned int found = 0;
unsigned int x;
ast_mutex_lock(&dynamic_levels_lock);
@@ -1390,13 +1387,35 @@
continue;
}
+ found = 1;
+ break;
+ }
+
+ ast_mutex_unlock(&dynamic_levels_lock);
+
+ if (found) {
+ /* take this level out of the global_logmask, to ensure that no new log messages
+ * will be queued for it
+ */
+
+ AST_RWLIST_WRLOCK(&logchannels);
+ global_logmask &= ~(1 << x);
+ AST_RWLIST_UNLOCK(&logchannels);
+
+ /* we need to flush any pending log messages as they may refer to the level
+ * we are about to remove. this is done by signaling the logger thread,
+ * yielding the processor, then waiting for the logmsgs list lock to become available again
+ */
+
+ AST_LIST_LOCK(&logmsgs);
+ ast_cond_signal(&logcond);
+ AST_LIST_UNLOCK(&logmsgs);
+ sched_yield();
+ AST_LIST_LOCK(&logmsgs);
+ AST_LIST_UNLOCK(&logmsgs);
+
levels[x] = NULL;
- break;
- }
-
- ast_mutex_unlock(&dynamic_levels_lock);
-
- if (x < ARRAY_LEN(levels)) {
+
ast_debug(1, "Unregistered dynamic logger level '%s' with index %d.\n", name, x);
update_logchannels();
Modified: team/kpfleming/dynamic_logger_levels/tests/test_logger.c
URL: http://svn.digium.com/svn-view/asterisk/team/kpfleming/dynamic_logger_levels/tests/test_logger.c?view=diff&rev=191994&r1=191993&r2=191994
==============================================================================
--- team/kpfleming/dynamic_logger_levels/tests/test_logger.c (original)
+++ team/kpfleming/dynamic_logger_levels/tests/test_logger.c Mon May 4 07:28:58 2009
@@ -41,9 +41,39 @@
#include "asterisk/app.h"
#include "asterisk/cli.h"
+struct test {
+ const char *name;
+ unsigned int x_success;
+ unsigned int x_failure;
+ unsigned int u_success;
+ unsigned int u_failure;
+};
+
+static void output_tests(struct test *tests, size_t num_tests, int fd)
+{
+ unsigned int x;
+
+ for (x = 0; x < num_tests; x++) {
+ ast_cli(fd, "Test %d: %s\n", x + 1, tests[x].name);
+ ast_cli(fd, "\tExpected Successes: %d\n", tests[x].x_success);
+ ast_cli(fd, "\tExpected Failures: %d\n", tests[x].x_failure);
+ ast_cli(fd, "\tUnexpected Successes: %d\n", tests[x].u_success);
+ ast_cli(fd, "\tUnexpected Failures: %d\n", tests[x].u_failure);
+ ast_cli(fd, "Test %d Result: %s\n", x + 1, (tests[x].u_success + tests[x].u_failure) ? "FAIL" : "PASS");
+ }
+}
+
static char *handle_cli_dynamic_level_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
unsigned int level;
+ unsigned int x;
+ unsigned int test;
+ struct test tests[] = {
+ { .name = "Simple register/message/unregister",
+ },
+ { .name = "Register multiple levels",
+ },
+ };
switch (cmd) {
case CLI_INIT:
@@ -56,15 +86,53 @@
return NULL;
}
- ast_cli(a->fd, "Test 1: Register level 'test', send a message, unregister.\n");
+ for (test = 0; test < ARRAY_LEN(tests); test++) {
+ ast_cli(a->fd, "Test %d: %s.\n", test + 1, tests[test].name);
+ switch (test) {
+ case 0:
+ if ((level = ast_logger_register_level("test")) != -1) {
+ ast_cli(a->fd, "Test 1: got level %d\n", level);
+ ast_log_dynamic_level(level, "Logger Dynamic Test: Test 1\n");
+ ast_logger_unregister_level("test");
+ tests[test].x_success++;
+ } else {
+ ast_cli(a->fd, "Test 1: Failed, could not register level 'test'.\n");
+ tests[test].u_failure++;
+ }
+ break;
+ case 1:
+ {
+ char level_name[18][8];
- if ((level = ast_logger_register_level("test")) != -1) {
- ast_cli(a->fd, "Test 1: got level %d\n", level);
- ast_log_dynamic_level(level, "Logger Dynamic Test: Test 1\n");
- ast_logger_unregister_level("test");
- } else {
- ast_cli(a->fd, "Test 1: Failed, could not register level 'test'.\n");
+ for (x = 0; x < ARRAY_LEN(level_name); x++) {
+ sprintf(level_name[x], "level%02d", x);
+ if ((level = ast_logger_register_level(level_name[x])) == -1) {
+ if (x < 16) {
+ tests[test].u_failure++;
+ } else {
+ tests[test].x_failure++;
+ }
+ level_name[x][0] = '\0';
+ } else {
+ ast_cli(a->fd, "Test 2: registered '%s', got level %d\n", level_name[x], level);
+ if (x < 16) {
+ tests[test].x_success++;
+ } else {
+ tests[test].u_success++;
+ }
+ }
+ }
+
+ for (x = 0; x < ARRAY_LEN(level_name); x++) {
+ if (!ast_strlen_zero(level_name[x])) {
+ ast_logger_unregister_level(level_name[x]);
+ }
+ }
+ }
+ }
}
+
+ output_tests(tests, ARRAY_LEN(tests), a->fd);
return CLI_SUCCESS;
}
More information about the asterisk-commits
mailing list