summaryrefslogtreecommitdiff
path: root/main/test.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2013-03-30 05:06:54 +0000
committerMatthew Jordan <mjordan@digium.com>2013-03-30 05:06:54 +0000
commite8015cc4603773288525508fc4635993efc654ce (patch)
treeb0723a48cab61cecd2b8ba081d89e1205ef0e3db /main/test.c
parentd16efd5be89892f00465241ad8a83d7ea542f585 (diff)
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. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@384389 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/test.c')
-rw-r--r--main/test.c111
1 files changed, 89 insertions, 22 deletions
diff --git a/main/test.c b/main/test.c
index 612697a15..12df75dd0 100644
--- a/main/test.c
+++ b/main/test.c
@@ -45,7 +45,19 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
#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 @@ static struct ast_cli_entry test_cli[] = {
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);
+ 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);
+}
- 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));
+#endif /* TEST_FRAMEWORK */
- ast_free(buf);
-}
+#ifdef TEST_FRAMEWORK
-void __ast_test_suite_assert_notify(const char *file, const char *func, int line, const char *exp)
+static void test_cleanup(void)
{
- 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);
+ ao2_cleanup(test_suite_topic);
+ test_suite_topic = NULL;
+ ao2_cleanup(test_suite_type);
+ test_suite_type = NULL;
}
-#endif /* TEST_FRAMEWORK */
+#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;