[asterisk-commits] mjordan: trunk r384389 - in /trunk: apps/ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Mar 30 00:06:57 CDT 2013
Author: mjordan
Date: Sat Mar 30 00:06:54 2013
New Revision: 384389
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384389
Log:
Convert TestEvent AMI events over to Stasis Core
This patch migrates the TestEvent AMI events to first be dispatched over the
Stasis-Core message bus. This helps to preserve the ordering of the events
with other events in the AMI system, such as the various channel related
events.
Modified:
trunk/apps/app_voicemail.c
trunk/include/asterisk/test.h
trunk/main/manager.c
trunk/main/test.c
Modified: trunk/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=384389&r1=384388&r2=384389
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Sat Mar 30 00:06:54 2013
@@ -10953,7 +10953,6 @@
/* If ADSI is supported, setup login screen */
adsi_begin(chan, &useadsi);
- ast_test_suite_assert(valid);
if (!valid) {
goto out;
}
Modified: trunk/include/asterisk/test.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/test.h?view=diff&rev=384389&r1=384388&r2=384389
==============================================================================
--- trunk/include/asterisk/test.h (original)
+++ trunk/include/asterisk/test.h Sat Mar 30 00:06:54 2013
@@ -134,6 +134,41 @@
/*! Macros used for the Asterisk Test Suite AMI events */
#ifdef TEST_FRAMEWORK
+struct stasis_topic;
+struct stasis_message_type;
+
+/*!
+ * \since 12
+ * \brief Obtain the \ref stasis_topic for \ref ast_test_suite_event_notify
+ * messages
+ *
+ * \retval A stasis topic
+ */
+struct stasis_topic *ast_test_suite_topic(void);
+
+/*!
+ * \since 12
+ * \brief Obtain the \ref stasis_message_type for \ref ast_test_suite_event_notify
+ * messages
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_test_suite_message_type(void);
+
+/*!
+ * \since 12
+ * \brief The message payload in a \ref ast_test_suite_message_type
+ */
+struct ast_test_suite_message_payload;
+
+/*!
+ * \since 12
+ * \brief Get the JSON for a \ref ast_test_suite_message_payload
+ *
+ * \retval An \ref ast_json object
+ */
+struct ast_json *ast_test_suite_get_blob(struct ast_test_suite_message_payload *payload);
+
/*!
* \brief Notifies the test suite of a change in application state
*
@@ -151,39 +186,14 @@
__attribute__((format(printf, 5, 6)));
/*!
- * \brief Notifies the test suite of a failed assert on an expression
- *
- * \details
- * If the expression provided evaluates to true, no action is taken. If the expression
- * evaluates to a false, a TestEvent manager event is raised with a subtype of Assert, notifying
- * the test suite that the expression failed to evaluate to true.
- *
- * \param exp The expression to evaluate
- *
- * \return Nothing
- */
-void __ast_test_suite_assert_notify(const char *file, const char *func, int line, const char *exp);
-
-/*!
* \ref __ast_test_suite_event_notify()
*/
#define ast_test_suite_event_notify(s, f, ...) \
__ast_test_suite_event_notify(__FILE__, __PRETTY_FUNCTION__, __LINE__, (s), (f), ## __VA_ARGS__)
-/*!
- * \ref __ast_test_suite_assert_notify()
- */
-#define ast_test_suite_assert(exp) \
- do { \
- if (__builtin_expect(!(exp), 1)) { \
- __ast_test_suite_assert_notify(__FILE__, __PRETTY_FUNCTION__, __LINE__, #exp); \
- } \
- } while (0)
-
#else
#define ast_test_suite_event_notify(s, f, ...)
-#define ast_test_suite_assert(exp)
#endif
Modified: trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager.c?view=diff&rev=384389&r1=384388&r2=384389
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Sat Mar 30 00:06:54 2013
@@ -92,6 +92,8 @@
#include "asterisk/stringfields.h"
#include "asterisk/presencestate.h"
#include "asterisk/stasis.h"
+#include "asterisk/test.h"
+#include "asterisk/json.h"
/*** DOCUMENTATION
<manager name="Ping" language="en_US">
@@ -7343,6 +7345,50 @@
ast_channel_set_manager_vars(args.argc, args.vars);
}
+#ifdef TEST_FRAMEWORK
+
+static void test_suite_event_cb(void *data, struct stasis_subscription *sub,
+ struct stasis_topic *topic,
+ struct stasis_message *message)
+{
+ struct ast_test_suite_message_payload *payload;
+ struct ast_json *blob;
+ const char *type;
+
+ if (stasis_message_type(message) != ast_test_suite_message_type()) {
+ return;
+ }
+
+ payload = stasis_message_data(message);
+ if (!payload) {
+ return;
+ }
+ blob = ast_test_suite_get_blob(payload);
+ if (!blob) {
+ return;
+ }
+
+ type = ast_json_string_get(ast_json_object_get(blob, "type"));
+ if (ast_strlen_zero(type) || strcmp("testevent", type)) {
+ return;
+ }
+
+ manager_event(EVENT_FLAG_TEST, "TestEvent",
+ "Type: StateChange\r\n"
+ "State: %s\r\n"
+ "AppFile: %s\r\n"
+ "AppFunction: %s\r\n"
+ "AppLine: %ld\r\n"
+ "%s\r\n",
+ ast_json_string_get(ast_json_object_get(blob, "state")),
+ ast_json_string_get(ast_json_object_get(blob, "appfile")),
+ ast_json_string_get(ast_json_object_get(blob, "appfunction")),
+ ast_json_integer_get(ast_json_object_get(blob, "line")),
+ ast_json_string_get(ast_json_object_get(blob, "data")));
+}
+
+#endif
+
/*! \internal \brief Free a user record. Should already be removed from the list */
static void manager_free_user(struct ast_manager_user *user)
{
@@ -7499,6 +7545,10 @@
ast_manager_register_xml_core("AOCMessage", EVENT_FLAG_AOC, action_aocmessage);
ast_manager_register_xml_core("Filter", EVENT_FLAG_SYSTEM, action_filter);
+#ifdef TEST_FRAMEWORK
+ stasis_subscribe(ast_test_suite_topic(), test_suite_event_cb, NULL);
+#endif
+
ast_cli_register_multiple(cli_manager, ARRAY_LEN(cli_manager));
__ast_custom_function_register(&managerclient_function, NULL);
ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
Modified: trunk/main/test.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/test.c?view=diff&rev=384389&r1=384388&r2=384389
==============================================================================
--- trunk/main/test.c (original)
+++ trunk/main/test.c Sat Mar 30 00:06:54 2013
@@ -45,7 +45,19 @@
#include "asterisk/ast_version.h"
#include "asterisk/paths.h"
#include "asterisk/time.h"
-#include "asterisk/manager.h"
+#include "asterisk/stasis.h"
+#include "asterisk/json.h"
+#include "asterisk/astobj2.h"
+
+/*! \since 12
+ * \brief The topic for test suite messages
+ */
+struct stasis_topic *test_suite_topic;
+
+/*! \since 12
+ * \brief The message type for test suite messages
+ */
+static struct stasis_message_type *test_suite_type;
/*! This array corresponds to the values defined in the ast_test_state enum */
static const char * const test_result2str[] = {
@@ -910,49 +922,104 @@
AST_CLI_DEFINE(test_cli_generate_results, "generate test results to file"),
};
+struct stasis_topic *ast_test_suite_topic(void)
+{
+ return test_suite_topic;
+}
+
+struct stasis_message_type *ast_test_suite_message_type(void)
+{
+ return test_suite_type;
+}
+
+/*!
+ * \since 12
+ * \brief A wrapper object that can be ao2 ref counted around an \ref ast_json blob
+ */
+struct ast_test_suite_message_payload {
+ struct ast_json *blob; /*!< The actual blob that we want to deliver */
+};
+
+/*! \internal
+ * \since 12
+ * \brief Destructor for \ref ast_test_suite_message_payload
+ */
+static void test_suite_message_payload_dtor(void *obj)
+{
+ struct ast_test_suite_message_payload *payload = obj;
+
+ if (payload->blob) {
+ ast_json_unref(payload->blob);
+ }
+}
+
+struct ast_json *ast_test_suite_get_blob(struct ast_test_suite_message_payload *payload)
+{
+ return payload->blob;
+}
+
void __ast_test_suite_event_notify(const char *file, const char *func, int line, const char *state, const char *fmt, ...)
{
- struct ast_str *buf = NULL;
+ RAII_VAR(struct ast_test_suite_message_payload *, payload,
+ ao2_alloc(sizeof(*payload), test_suite_message_payload_dtor),
+ ao2_cleanup);
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_str *, buf, ast_str_create(128), ast_free);
va_list ap;
- if (!(buf = ast_str_create(128))) {
+ if (!buf) {
+ return;
+ }
+ if (!payload) {
return;
}
va_start(ap, fmt);
ast_str_set_va(&buf, 0, fmt, ap);
va_end(ap);
-
- manager_event(EVENT_FLAG_TEST, "TestEvent",
- "Type: StateChange\r\n"
- "State: %s\r\n"
- "AppFile: %s\r\n"
- "AppFunction: %s\r\n"
- "AppLine: %d\r\n"
- "%s\r\n",
- state, file, func, line, ast_str_buffer(buf));
-
- ast_free(buf);
-}
-
-void __ast_test_suite_assert_notify(const char *file, const char *func, int line, const char *exp)
-{
- manager_event(EVENT_FLAG_TEST, "TestEvent",
- "Type: Assert\r\n"
- "AppFile: %s\r\n"
- "AppFunction: %s\r\n"
- "AppLine: %d\r\n"
- "Expression: %s\r\n",
- file, func, line, exp);
+ payload->blob = ast_json_pack("{s: s, s: s, s: s, s: s, s: i, s: s}",
+ "type", "testevent",
+ "state", state,
+ "appfile", file,
+ "appfunction", func,
+ "line", line,
+ "data", ast_str_buffer(buf));
+ if (!payload->blob) {
+ return;
+ }
+ msg = stasis_message_create(ast_test_suite_message_type(), payload);
+ if (!msg) {
+ return;
+ }
+ stasis_publish(ast_test_suite_topic(), msg);
}
#endif /* TEST_FRAMEWORK */
+#ifdef TEST_FRAMEWORK
+
+static void test_cleanup(void)
+{
+ ao2_cleanup(test_suite_topic);
+ test_suite_topic = NULL;
+ ao2_cleanup(test_suite_type);
+ test_suite_type = NULL;
+}
+
+#endif
+
int ast_test_init(void)
{
#ifdef TEST_FRAMEWORK
+ /* Create stasis topic */
+ test_suite_topic = stasis_topic_create("test_suite_topic");
+ test_suite_type = stasis_message_type_create("test_suite_type");
+ if (!test_suite_topic || !test_suite_type) {
+ return -1;
+ }
/* Register cli commands */
ast_cli_register_multiple(test_cli, ARRAY_LEN(test_cli));
+ ast_register_atexit(test_cleanup);
#endif
return 0;
More information about the asterisk-commits
mailing list