diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-08-14 15:05:12 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-08-20 15:47:34 -0400 |
commit | c7916d6b820bde690145450ba02209e741154866 (patch) | |
tree | 8fa39e9d28e8d1f384471540e58cdc280975c72e /common/elapi/elapi_test | |
parent | b776f0af14866051ab9dcdb696345643424261d5 (diff) | |
download | sssd-c7916d6b820bde690145450ba02209e741154866.tar.gz sssd-c7916d6b820bde690145450ba02209e741154866.tar.bz2 sssd-c7916d6b820bde690145450ba02209e741154866.zip |
ELAPI: Adding concept of targets
The targets are the destinations which
caller wants to send the events to.
The sinks are now on the second level
under targets and constitute a so called
fail over chain for a target.
Such approach eliminates the need for complex
routing function.
The dispatcher keeps the list of targets in a collection.
The element in the collection is the target context.
Also gispatcher keeps the list of the sinks
in a separate collection.
Each target context has a list of the sinks
associated with this target. But those are just
pointers (at least for now) to the sinks
form the list kept by dispatcher.
I had to add some internal debug callbacks
to be able to see that all the internals of
the dispatcher are actually in order.
See the conttent of config file for more comments.
Also see information posted on SSSD wiki.
https://fedorahosted.org/sssd/wiki/WikiPage/ELAPIInterface
Diffstat (limited to 'common/elapi/elapi_test')
-rw-r--r-- | common/elapi/elapi_test/Makefile.am | 38 | ||||
-rw-r--r-- | common/elapi/elapi_test/configure.ac | 26 | ||||
-rw-r--r-- | common/elapi/elapi_test/elapi_ut.c | 341 | ||||
-rw-r--r-- | common/elapi/elapi_test/elapi_ut.conf | 97 | ||||
-rw-r--r-- | common/elapi/elapi_test/m4/.dir | 0 |
5 files changed, 502 insertions, 0 deletions
diff --git a/common/elapi/elapi_test/Makefile.am b/common/elapi/elapi_test/Makefile.am new file mode 100644 index 00000000..b16102c8 --- /dev/null +++ b/common/elapi/elapi_test/Makefile.am @@ -0,0 +1,38 @@ +TRACE_LEVEL=@TRACE_VAR@ + +topdir=$(srcdir)/../.. + +AM_CFLAGS = -DELAPI_DEFAULT_CONFIG_DIR=\"$(srcdir)\" \ + -DELAPI_DEFAULT_CONFIG_APP_DIR=\"$(srcdir)\" \ + -DELAPI_DEFAULT_APP_NAME=\"elapi_ut\" \ + -DELAPI_DEFAULT_APP_NAME_SIZE=127 + +if HAVE_GCC + AM_CFLAGS += \ + -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual \ + -Wcast-align -Wwrite-strings +endif + +AM_CPPFLAGS = -I$(topdir) -I$(topdir)/ini -I$(topdir)/trace -I$(topdir)/collection -I$(topdir)/elapi $(TRACE_LEVEL) + +ACLOCAL_AMFLAGS = -I m4 + +# Build library +noinst_LTLIBRARIES = libelapi_test.la +libelapi_test_la_SOURCES = \ + ../elapi_event.c \ + ../elapi_log.c \ + ../elapi_internal.c \ + ../elapi_event.h \ + ../elapi_priv.h \ + ../elapi_sink.h \ + ../elapi_log.h \ + ../elapi_async.h \ + ../elapi.h + +# Build unit test +check_PROGRAMS = elapi_ut +elapi_ut_SOURCES = elapi_ut.c +elapi_ut_LDADD = libelapi_test.la ../../ini/libini_config.la ../../collection/libcollection.la + +TESTS = elapi_ut diff --git a/common/elapi/elapi_test/configure.ac b/common/elapi/elapi_test/configure.ac new file mode 100644 index 00000000..f2431bd3 --- /dev/null +++ b/common/elapi/elapi_test/configure.ac @@ -0,0 +1,26 @@ +AC_INIT([elapi],[0.0.1],[freeipa-devel@redhat.com]) +AC_CONFIG_SRCDIR([elapi_ut.c]) +AC_CONFIG_AUX_DIR([build]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) +AC_PROG_CC +AC_PROG_LIBTOOL +AC_CONFIG_MACRO_DIR([m4]) +AC_PROG_INSTALL + +AM_CONDITIONAL([HAVE_GCC], [test "$ac_cv_prog_gcc" = yes]) + +m4_pattern_allow([AM_SILENT_RULES]) +AM_SILENT_RULES + +AC_CONFIG_HEADERS([config.h]) + +# Enable trace build +AC_ARG_ENABLE([trace], + [AS_HELP_STRING([--enable-trace[=LEVEL]],[build with low level tracing enabled])], + [trace_level="$enableval"], + [trace_level="0"]) +AS_IF([test ["$trace_level" -gt "0"] -a ["$trace_level" -lt "8"] ],[AC_SUBST([TRACE_VAR],["-DTRACE_LEVEL=$trace_level"])]) + + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/common/elapi/elapi_test/elapi_ut.c b/common/elapi/elapi_test/elapi_ut.c new file mode 100644 index 00000000..ed434221 --- /dev/null +++ b/common/elapi/elapi_test/elapi_ut.c @@ -0,0 +1,341 @@ +/* + ELAPI + + Unit test for the ELAPI event interface. + + Copyright (C) Dmitri Pal <dpal@redhat.com> 2009 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <stdio.h> +#include <stdarg.h> +#define TRACE_HOME +#include "trace.h" +#include "elapi.h" +#include "collection_tools.h" + +/* THIS IS A PRIVATE HEADER - included for debugging purposes only! */ +#include "elapi_priv.h" + +int simple_event_test(void) +{ + int error = 0; + struct collection_item *event; + char bin[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + + printf("Simple test START:\n"); + + error = elapi_set_default_template( + E_BASE_DEFV1 | E_BASE_HOSTEXT, + "%n( bin )", bin, 8, + " %sb( logical1 )", "false", + "%sb( logical2 )", "YES", + " %db(logical3)", 1, + "%d(int_number),", -200, + "%u(unsigned_number)", 300, + "%ld(long_number)", -1234567, + "%lu(long_unsigned_number)", 123456789, + "%s(just_string)", "string", + "%*s(sub_string)", "truncated string", 10, /* Expect word truncated */ + "%e(double_number)", 3.141592 * 3, + "simple", "value", + "-" E_UTCTIME, /* Remove UTCTIME from the list */ + E_MESSAGE, + "%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)", + E_EOARG); + + if (error) { + printf("Failed to set default template! %d\n", error); + return error; + } + + error = elapi_create_simple_event( + &event, + " %db(foo_logical)", 0, + "%d(foo_int_number),", -2000, + "%u(foo_unsigned_number)", 3000, + "%ld(foo_long_number)", -7654321, + E_EOARG); + + if (error) { + printf("Failed to create simple event! %d\n", error); + return error; + } + + error = ELAPI_EVT_DEBUG(event); + if (error) { + printf("Failed to log event to debug ! %d\n", error); + elapi_destroy_event(event); + return error; + } + + error = ELAPI_EVT_LOG(event); + if (error) { + printf("Failed to log event to log ! %d\n", error); + elapi_destroy_event(event); + return error; + } + + error = ELAPI_EVT_AUDIT(event); + + if (error) { + printf("Failed to log event to audit ! %d\n", error); + elapi_destroy_event(event); + return error; + } + + elapi_destroy_event(event); + + error = elapi_msg(E_TARGET_DEBUG, NULL, "a", "b", "c", "d", E_EOARG); + if (error) { + printf("Failed to log \"debug\" event! %d\n", error); + return error; + } + + error = elapi_msg(E_TARGET_LOG, NULL, "a", "b", "c", "d", E_EOARG); + if (error) { + printf("Failed to log \"log\" event! %d\n", error); + return error; + } + + error = elapi_msg(E_TARGET_AUDIT, NULL, "a", "b", "c", "d", E_EOARG); + if (error) { + printf("Failed to log \"audit\" event! %d\n", error); + return error; + } + + /* Internal function to print dispatcher guts */ + elapi_internal_print_dispatcher(elapi_get_dispatcher()); + + printf("Simple test success!\n"); + + return error; +} + +int complex_event_test(void) +{ + int error = 0; + struct collection_item *template = NULL; + struct collection_item *event = NULL, *event_copy = NULL; + char bin[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + struct collection_item *col = NULL; + struct elapi_dispatcher *dispatcher = NULL; + + printf("Complex test START:\n"); + + error = elapi_create_event_template( + &template, + E_BASE_DEFV1 | E_BASE_HOSTEXT, + "%lu(long_unsigned_number)", 123456789, + "%s(just_string)", "string", + "%*s(sub_string)", "truncated string", 10, /* Expect word truncated */ + "%e(double_number)", 3.141592 * 3, + "simple", "value", + "-" E_UTCTIME, /* Remove UTCTIME from the list */ + E_MESSAGE, + "%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)", + E_EOARG); + + if (error) { + printf("Failed to set create template %d\n", error); + return error; + } + + error = elapi_create_event( + &event, + template, + NULL, + 0, + " %db(evt_logical)", 0, + "%d(evt_int_number),", -2000, + "%u(evt_unsigned_number)", 3000, + "%ld(evt_long_number)", -7654321, + E_EOARG); + + if (error) { + printf("Failed to set create template %d\n", error); + elapi_destroy_event_template(template); + return error; + } + + col_debug_collection(template, COL_TRAVERSE_FLAT); + col_debug_collection(event, COL_TRAVERSE_FLAT); + + error = elapi_log(E_TARGET_DEBUG, event); + + elapi_destroy_event(event); + + if (error) { + printf("Failed to log event! %d\n", error); + return error; + } + + + elapi_destroy_event_template(template); + + error = elapi_create_event_template( + &template, + E_BASE_DEFV1 | E_BASE_HOSTEXT, + "%n( bin )", bin, 8, + " %sb( logical1 )", "false", + "%sb( logical2 )", "YES", + " %db(logical3)", 1, + "%d(int_number),", -200, + "%u(unsigned_number)", 300, + "%ld(long_number)", -1234567, + E_MESSAGE, + "%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)", + E_EOARG); + + if (error) { + printf("Failed to set create template %d\n", error); + return error; + } + + if ((error = col_create_collection(&col, "test", 0)) || + /* We are forcing overwrite with different type */ + (error = col_add_int_property(col, NULL, "unsigned_number", 1)) || + (error = col_add_long_property(col, NULL, "bin", 100000000L))) { + elapi_destroy_event_template(template); + printf("Failed to add property. Error %d\n", error); + return error; + } + + error = elapi_create_event( + &event, + template, + col, + COL_ADD_MODE_FLAT, + E_MESSAGE, + "%(stamp) a good message", + "-int_number", + E_EOARG); + + if (error) { + printf("Failed to set create template %d\n", error); + elapi_destroy_event_template(template); + col_destroy_collection(col); + return error; + } + + col_destroy_collection(col); + + col_debug_collection(template, COL_TRAVERSE_FLAT); + col_debug_collection(event, COL_TRAVERSE_FLAT); + + + if ((error = col_create_collection(&col, "test", 0)) || + /* We are forsing overwrite with different type */ + (error = col_add_int_property(col, NULL, "zzz", 1)) || + (error = col_add_long_property(col, NULL, "zzz2", 100000000L))) { + elapi_destroy_event_template(template); + printf("Failed to add property. Error %d\n", error); + elapi_destroy_event(event); + return error; + } + + error = elapi_modify_event( + event, + col, + COL_ADD_MODE_REFERENCE, + "-"E_MESSAGE, + "bin", "bin-string", + E_EOARG); + + if (error) { + printf("Failed to set create template %d\n", error); + elapi_destroy_event(event); + elapi_destroy_event_template(template); + col_destroy_collection(col); + return error; + } + + col_destroy_collection(col); + + error = elapi_copy_event(&event_copy, event); + if (error) { + printf("Failed to set create template %d\n", error); + elapi_destroy_event(event); + elapi_destroy_event_template(template); + return error; + } + + error = elapi_create_dispatcher(&dispatcher, "elapi_ut", "./sdfdsdf"); + if (error) { + elapi_destroy_event(event); + elapi_destroy_event(event_copy); + elapi_destroy_event_template(template); + printf("Failed to create dispatcher %d\n", error); + return error; + } + + error = elapi_dsp_log(E_TARGET_DEBUG, dispatcher, event); + + elapi_destroy_event(event); + + if (error) { + elapi_destroy_event(event_copy); + elapi_destroy_event_template(template); + printf("Failed to log event! %d\n", error); + return error; + } + + error = elapi_dsp_log(E_TARGET_DEBUG, dispatcher, event_copy); + + elapi_destroy_event(event_copy); + + if (error) { + elapi_destroy_event_template(template); + printf("Failed to log event! %d\n", error); + return error; + } + + error = elapi_dsp_msg(E_TARGET_DEBUG, dispatcher, template, "a", "b", "c", "d", E_EOARG); + if (error) { + elapi_destroy_event_template(template); + printf("Failed to log event! %d\n", error); + return error; + } + + error = elapi_dsp_msg(E_TARGET_DEBUG, dispatcher, NULL, "a", "b", "c", "d", E_EOARG); + if (error) { + elapi_destroy_event_template(template); + printf("Failed to log event! %d\n", error); + return error; + } + + elapi_destroy_event_template(template); + + elapi_internal_print_dispatcher(dispatcher); + + elapi_destroy_dispatcher(dispatcher); + + return error; +} + + +/* Main function of the unit test */ + +int main(int argc, char *argv[]) +{ + int error = 0; + + printf("Start\n"); + if ((error = simple_event_test()) || + (error = complex_event_test())) { + printf("Failed!\n"); + } + else printf("Success!\n"); + /* Add other tests here ... */ + return error; +} diff --git a/common/elapi/elapi_test/elapi_ut.conf b/common/elapi/elapi_test/elapi_ut.conf new file mode 100644 index 00000000..d15a4550 --- /dev/null +++ b/common/elapi/elapi_test/elapi_ut.conf @@ -0,0 +1,97 @@ +; This is a sample configuration file for ELAPI + +; The dispatcher section defines general configuration +; for the ELAPI. It has following configuration parameters: +; +; targets - (required) +; Defines possible logical destinations where message can be sent. +; It is one of the arguments of the calling interface. It is numeric. +; It is done this way for performance reasons so it is faster to compare. +; But in the configuration it is easier to deal with targets as strings. +; To overcome this issue each target is assigned a number in the INI file. +; The ELAPI convention is to have three default targets: +; "debug", "audit" and "log" but application developers can add others as needed. +; The default value for debug target is 1, for audit 2 and log is 4. +; Changing the value defined for debug to be 7 ( logical OR of 1, 2 and 4) +; will result in all messages sent into debug log. +; This might be convenient during troubleshooting and would allow seeing all +; events emitted by the application in one place. +; If you want the event to be sent into two targets at the same time +; add a target with different name but same value. +; For example if the log events need to go to local and remote files +; in parallel you would create another target: logremote +; and give it same value as log (which by convention is 4) + + + +[dispatcher] +targets=debug, audit, log + +; Inside section for each target the following parameters can be defined: +; +; value - (optional) +; Stores the value associated with this target. +; If the bit-wise AND of this value and the value provided by caller +; of the interface is greater than 0 the event is logged into the +; target destination. If omitted all events are sent to this target. +; sinks - (required) +; Defines the list of the sink names that need to be loaded +; each will have its own section. +; Only one of the sinks is active - first in the list. +; The list contains sinks in the fail over order. +; + +[debug] +value = 1 +sinks = debugfile, stderr + +[audit] +value = 2 +sinks = auditfile, syslog + +[log] +value = 4 +sinks = logfile, syslog + +; Each sink needs to have it's own section. +; +; COMMON FOR EVERY SINK +; +; provider - (required) +; Defines the name of the sink or the special reserved word to +; indecate that it is a sink provided natively by ELAPI library. +; +; Special sinks provided natively by ELAPI are: +; file +; stderr +; syslog +; +; Example: +; provider=file +; +; this would mean the destination for this sink is a file. +; +; If the sink is provided as an external plugin +; the syntax should be the following: +; +; provider=custom_audit +; +; In this case the ELAPI will try to load shared library with the name +; constructed using specified value. In the given example +; ELAPI will try to load libelapi_sink_custom_audit.so library. +; The general pattern is: libelapi_sink_<source>.so + +[debugfile] +provider=file + +[logfile] +provider=file + +[auditfile] +provider=file + +[stderr] +provider=stderr + +[syslog] +provider=syslog diff --git a/common/elapi/elapi_test/m4/.dir b/common/elapi/elapi_test/m4/.dir new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/common/elapi/elapi_test/m4/.dir |