[svn-commits] dlee: branch dlee/endpoints r387289 - in /team/dlee/endpoints: include/asteri...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed May 1 23:48:58 CDT 2013
Author: dlee
Date: Wed May 1 23:48:56 2013
New Revision: 387289
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387289
Log:
Endpoint tests
Added:
team/dlee/endpoints/include/asterisk/stasis_test.h (with props)
team/dlee/endpoints/res/res_stasis_test.c (with props)
team/dlee/endpoints/res/res_stasis_test.exports.in (with props)
team/dlee/endpoints/tests/test_endpoints.c (with props)
team/dlee/endpoints/tests/test_stasis_endpoints.c (with props)
Modified:
team/dlee/endpoints/include/asterisk/endpoints.h
team/dlee/endpoints/main/endpoints.c
Modified: team/dlee/endpoints/include/asterisk/endpoints.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/endpoints.h?view=diff&rev=387289&r1=387288&r2=387289
==============================================================================
--- team/dlee/endpoints/include/asterisk/endpoints.h (original)
+++ team/dlee/endpoints/include/asterisk/endpoints.h Wed May 1 23:48:56 2013
@@ -35,6 +35,11 @@
* creates channels, it can use ast_endpoint_add_channel() to associate channels
* to the endpoint. This updated the endpoint appropriately, and forwards all of
* the channel's events to the endpoint's topic.
+ *
+ * In order to avoid excessive locking on the endpoint object itself, the
+ * mutable state is not accessible via getters. Instead, you can create a
+ * snapshot using ast_endpoint_snapshot_create() to get a consistent snapshot of
+ * the internal state.
*/
#include "asterisk/json.h"
Added: team/dlee/endpoints/include/asterisk/stasis_test.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/stasis_test.h?view=auto&rev=387289
==============================================================================
--- team/dlee/endpoints/include/asterisk/stasis_test.h (added)
+++ team/dlee/endpoints/include/asterisk/stasis_test.h Wed May 1 23:48:56 2013
@@ -1,0 +1,104 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef _ASTERISK_STASIS_TEST_H
+#define _ASTERISK_STASIS_TEST_H
+
+/*!
+ * \file \brief Test infrastructure for dealing with Stasis.
+ *
+ * \author David M. Lee, II <dlee at digium.com>
+ */
+
+#include "asterisk/lock.h"
+#include "asterisk/stasis.h"
+
+#define DEFAULT_WAIT_MILLIS 5000
+
+/*! \brief Structure that collects messages from a topic */
+struct stasis_message_sink {
+ /*! Condition mutex. */
+ ast_mutex_t lock;
+ /*! Condition to signal state changes */
+ ast_cond_t cond;
+ /*! Maximum number of messages messages field can hold without
+ * realloc */
+ size_t max_messages;
+ /*! Current number of messages in messages field. */
+ size_t num_messages;
+ /*! Boolean flag to be set when unsubscribe is received */
+ int is_done:1;
+ /*! Ordered array of messages received */
+ struct stasis_message **messages;
+};
+
+/*!
+ * \brief Create a message sink.
+ *
+ * This is an AO2 managed object, which you ao2_cleanup() when done. The
+ * destructor waits for an unsubscribe message to be received, to ensure the
+ * object isn't disposed of before the topic is finished.
+ */
+struct stasis_message_sink *stasis_message_sink_create(void);
+
+/*!
+ * \brief Topic callback to receive messages.
+ * See \ref stasis_subscription_cb
+ */
+void stasis_message_sink_cb(void *data, struct stasis_subscription *sub,
+ struct stasis_topic *topic, struct stasis_message *message);
+
+/*!
+ * \brief Wait for a sink's num_messages field to reach a certain level.
+ *
+ * The optional timeout prevents complete deadlock in a test.
+ *
+ * \param sink Sink to wait on.
+ * \param num_messages sink->num_messages value to wait for.
+ * \param timeout_millis Number of milliseconds to wait. -1 to wait forever.
+ * \return Actual sink->num_messages value at return.
+ * If this is < \a num_messages, then the timeout expired.
+ */
+int stasis_message_sink_wait_for(struct stasis_message_sink *sink,
+ int num_messages, int timeout_millis);
+
+/*!
+ * \brief Ensures that no new messages are received.
+ *
+ * The optional timeout prevents complete deadlock in a test.
+ *
+ * \param sink Sink to wait on.
+ * \param num_messages expecte \a sink->num_messages.
+ * \param timeout_millis Number of milliseconds to wait for.
+ * \return Actual sink->num_messages value at return.
+ * If this is < \a num_messages, then the timeout expired.
+ */
+int stasis_message_sink_should_stay(struct stasis_message_sink *sink,
+ int num_messages, int timeout_millis);
+
+/*!
+ * \brief Creates a test message.
+ */
+struct stasis_message *stasis_test_message_create(void);
+
+/*!
+ * \brief Gets the type of messages created by stasis_test_message_create().
+ */
+struct stasis_message_type *stasis_test_message_type(void);
+
+#endif /* _ASTERISK_STASIS_TEST_H */
Propchange: team/dlee/endpoints/include/asterisk/stasis_test.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dlee/endpoints/include/asterisk/stasis_test.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dlee/endpoints/include/asterisk/stasis_test.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/dlee/endpoints/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/endpoints.c?view=diff&rev=387289&r1=387288&r2=387289
==============================================================================
--- team/dlee/endpoints/main/endpoints.c (original)
+++ team/dlee/endpoints/main/endpoints.c Wed May 1 23:48:56 2013
@@ -166,8 +166,15 @@
RAII_VAR(struct ast_endpoint *, endpoint, NULL, ao2_cleanup);
int r = 0;
- ast_assert(tech != NULL);
- ast_assert(resource != NULL);
+ if (ast_strlen_zero(tech)) {
+ ast_log(LOG_ERROR, "Endpoint tech cannot be empty\n");
+ return NULL;
+ }
+
+ if (ast_strlen_zero(resource)) {
+ ast_log(LOG_ERROR, "Endpoint resource cannot be empty\n");
+ return NULL;
+ }
ast_debug(3, "%s(%s, %s)\n", __func__, tech, resource);
@@ -232,7 +239,9 @@
{
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
- ast_assert(endpoint != NULL);
+ if (endpoint == NULL) {
+ return;
+ }
message = stasis_cache_clear_create(ast_endpoint_snapshot_type(), endpoint->id);
if (message) {
Added: team/dlee/endpoints/res/res_stasis_test.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/res/res_stasis_test.c?view=auto&rev=387289
==============================================================================
--- team/dlee/endpoints/res/res_stasis_test.c (added)
+++ team/dlee/endpoints/res/res_stasis_test.c Wed May 1 23:48:56 2013
@@ -1,0 +1,210 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file \brief Test infrastructure for dealing with Stasis.
+ *
+ * \author David M. Lee, II <dlee at digium.com>
+ */
+
+/*** MODULEINFO
+ <depend>TEST_FRAMEWORK</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
+
+#include "asterisk/astobj2.h"
+#include "asterisk/module.h"
+#include "asterisk/stasis_test.h"
+
+static struct stasis_message_type *test_message_type;
+
+static void stasis_message_sink_dtor(void *obj)
+{
+ struct stasis_message_sink *sink = obj;
+
+ {
+ SCOPED_MUTEX(lock, &sink->lock);
+ while (!sink->is_done) {
+ /* Normally waiting forever is bad, but if we're not
+ * done, we're not done. */
+ ast_cond_wait(&sink->cond, &sink->lock);
+ }
+ }
+
+ ast_mutex_destroy(&sink->lock);
+ ast_cond_destroy(&sink->cond);
+
+ while (sink->num_messages > 0) {
+ ao2_cleanup(sink->messages[--sink->num_messages]);
+ }
+ ast_free(sink->messages);
+ sink->messages = NULL;
+ sink->max_messages = 0;
+}
+
+struct stasis_message_sink *stasis_message_sink_create(void)
+{
+ RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
+
+ sink = ao2_alloc(sizeof(*sink), stasis_message_sink_dtor);
+ if (!sink) {
+ return NULL;
+ }
+ ast_mutex_init(&sink->lock);
+ ast_cond_init(&sink->cond, NULL);
+ sink->max_messages = 4;
+ sink->messages =
+ ast_malloc(sizeof(*sink->messages) * sink->max_messages);
+ if (!sink->messages) {
+ return NULL;
+ }
+ ao2_ref(sink, +1);
+ return sink;
+}
+
+void stasis_message_sink_cb(void *data, struct stasis_subscription *sub,
+ struct stasis_topic *topic, struct stasis_message *message)
+{
+ struct stasis_message_sink *sink = data;
+
+ SCOPED_MUTEX(lock, &sink->lock);
+
+ if (sink->num_messages == sink->max_messages) {
+ size_t new_max_messages = sink->max_messages * 2;
+ struct stasis_message **new_messages = ast_realloc(
+ sink->messages,
+ sizeof(*new_messages) * new_max_messages);
+ if (!new_messages) {
+ return;
+ }
+ sink->max_messages = new_max_messages;
+ sink->messages = new_messages;
+ }
+
+ ao2_ref(message, +1);
+ sink->messages[sink->num_messages++] = message;
+
+ if (stasis_subscription_final_message(sub, message)) {
+ sink->is_done = 1;
+ }
+
+ ast_cond_signal(&sink->cond);
+}
+
+int stasis_message_sink_wait_for(struct stasis_message_sink *sink,
+ int num_messages, int timeout_millis)
+{
+ struct timeval start = ast_tvnow();
+ struct timeval delta = {
+ .tv_sec = timeout_millis / 1000,
+ .tv_usec = (timeout_millis % 1000) * 1000,
+ };
+ struct timeval deadline_tv = ast_tvadd(start, delta);
+ struct timespec deadline = {
+ .tv_sec = deadline_tv.tv_sec,
+ .tv_nsec = 1000 * deadline_tv.tv_usec,
+ };
+
+ SCOPED_MUTEX(lock, &sink->lock);
+ while (sink->num_messages < num_messages) {
+ int r = ast_cond_timedwait(&sink->cond, &sink->lock, &deadline);
+
+ if (r == ETIMEDOUT) {
+ break;
+ } else if (r != 0) {
+ ast_log(LOG_ERROR, "Unexpected condition error: %s\n",
+ strerror(r));
+ break;
+ }
+ }
+ return sink->num_messages;
+}
+
+int stasis_message_sink_should_stay(struct stasis_message_sink *sink,
+ int num_messages, int timeout_millis)
+{
+ struct timeval start = ast_tvnow();
+ struct timeval delta = ast_tv(0, 1000 * timeout_millis);
+ struct timeval deadline_tv = ast_tvadd(start, delta);
+ struct timespec deadline = {
+ .tv_sec = deadline_tv.tv_sec,
+ .tv_nsec = 1000 * deadline_tv.tv_usec,
+ };
+
+ SCOPED_MUTEX(lock, &sink->lock);
+ while (sink->num_messages == num_messages) {
+ int r = ast_cond_timedwait(&sink->cond, &sink->lock, &deadline);
+
+ if (r == ETIMEDOUT) {
+ break;
+ } else {
+ ast_log(LOG_ERROR, "Unexpected condition error: %s\n",
+ strerror(r));
+ break;
+ }
+ }
+ return sink->num_messages;
+}
+
+struct stasis_message *stasis_test_message_create(void)
+{
+ RAII_VAR(void *, data, NULL, ao2_cleanup);
+
+ /* We just need the unique pointer; don't care what's in it */
+ data = ao2_alloc(1, NULL);
+ if (!data) {
+ return NULL;
+ }
+
+ return stasis_message_create(stasis_test_message_type(), data);
+}
+
+struct stasis_message_type *stasis_test_message_type(void)
+{
+ return test_message_type;
+}
+
+static int unload_module(void)
+{
+ ao2_cleanup(stasis_test_message_type);
+ test_message_type = NULL;
+ return 0;
+}
+
+static int load_module(void)
+{
+ test_message_type = stasis_message_type_create(
+ "stasis_test_message");
+ if (!test_message_type) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY,
+ AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER,
+ "Stasis test utilities",
+ .load = load_module,
+ .unload = unload_module,
+ .load_pri = AST_MODPRI_APP_DEPEND,
+ );
Propchange: team/dlee/endpoints/res/res_stasis_test.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dlee/endpoints/res/res_stasis_test.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dlee/endpoints/res/res_stasis_test.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/dlee/endpoints/res/res_stasis_test.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/res/res_stasis_test.exports.in?view=auto&rev=387289
==============================================================================
--- team/dlee/endpoints/res/res_stasis_test.exports.in (added)
+++ team/dlee/endpoints/res/res_stasis_test.exports.in Wed May 1 23:48:56 2013
@@ -1,0 +1,6 @@
+{
+ global:
+ LINKER_SYMBOL_PREFIXstasis_*;
+ local:
+ *;
+};
Propchange: team/dlee/endpoints/res/res_stasis_test.exports.in
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dlee/endpoints/res/res_stasis_test.exports.in
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dlee/endpoints/res/res_stasis_test.exports.in
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/dlee/endpoints/tests/test_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/tests/test_endpoints.c?view=auto&rev=387289
==============================================================================
--- team/dlee/endpoints/tests/test_endpoints.c (added)
+++ team/dlee/endpoints/tests/test_endpoints.c Wed May 1 23:48:56 2013
@@ -1,0 +1,158 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file \brief Test endpoints.
+ *
+ * \author\verbatim David M. Lee, II <dlee at digium.com> \endverbatim
+ *
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+ <depend>TEST_FRAMEWORK</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/astobj2.h"
+#include "asterisk/endpoints.h"
+#include "asterisk/module.h"
+#include "asterisk/stasis_endpoints.h"
+#include "asterisk/test.h"
+
+static const char *test_category = "/core/endpoints/";
+
+AST_TEST_DEFINE(create)
+{
+ RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = __func__;
+ info->category = test_category;
+ info->summary = "Test endpoint creation";
+ info->description = "Test endpoint creation";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ ast_test_validate(test, NULL == ast_endpoint_create(NULL, NULL));
+ ast_test_validate(test, NULL == ast_endpoint_create("", ""));
+ ast_test_validate(test, NULL == ast_endpoint_create("TEST", ""));
+ ast_test_validate(test, NULL == ast_endpoint_create("", "test_res"));
+
+ uut = ast_endpoint_create("TEST", "test_res");
+ ast_test_validate(test, NULL != uut);
+
+ ast_test_validate(test,
+ 0 == strcmp("TEST", ast_endpoint_get_tech(uut)));
+ ast_test_validate(test,
+ 0 == strcmp("test_res", ast_endpoint_get_resource(uut)));
+
+ return AST_TEST_PASS;
+}
+
+
+AST_TEST_DEFINE(defaults)
+{
+ RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
+ RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = __func__;
+ info->category = test_category;
+ info->summary = "Test defaults for new endpoints";
+ info->description = "Test defaults for new endpoints";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ uut = ast_endpoint_create("TEST", "test_res");
+ ast_test_validate(test, NULL != uut);
+ snapshot = ast_endpoint_snapshot_create(uut);
+ ast_test_validate(test, NULL != snapshot);
+
+ ast_test_validate(test, 0 == strcmp("TEST/test_res", snapshot->id));
+ ast_test_validate(test, 0 == strcmp("TEST", snapshot->tech));
+ ast_test_validate(test, 0 == strcmp("test_res", snapshot->resource));
+ ast_test_validate(test, AST_ENDPOINT_UNKNOWN == snapshot->state);
+ ast_test_validate(test, -1 == snapshot->max_channels);
+ ast_test_validate(test, 0 == snapshot->current_channels);
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(setters)
+{
+ RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
+ RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = __func__;
+ info->category = test_category;
+ info->summary = "Test endpoint setters";
+ info->description = "Test endpoint setters";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ uut = ast_endpoint_create("TEST", "test_res");
+ ast_test_validate(test, NULL != uut);
+
+ ast_endpoint_set_state(uut, AST_ENDPOINT_ONLINE);
+ ast_endpoint_set_max_channels(uut, 314159);
+
+ snapshot = ast_endpoint_snapshot_create(uut);
+ ast_test_validate(test, NULL != snapshot);
+
+ ast_test_validate(test, AST_ENDPOINT_ONLINE == snapshot->state);
+ ast_test_validate(test, 314159 == snapshot->max_channels);
+
+ return AST_TEST_PASS;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(create);
+ AST_TEST_UNREGISTER(defaults);
+ AST_TEST_UNREGISTER(setters);
+ return 0;
+}
+
+static int load_module(void)
+{
+ AST_TEST_REGISTER(create);
+ AST_TEST_REGISTER(defaults);
+ AST_TEST_REGISTER(setters);
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
+ "Endpoint testing",
+ .load = load_module,
+ .unload = unload_module,
+ );
Propchange: team/dlee/endpoints/tests/test_endpoints.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dlee/endpoints/tests/test_endpoints.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dlee/endpoints/tests/test_endpoints.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/dlee/endpoints/tests/test_stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/tests/test_stasis_endpoints.c?view=auto&rev=387289
==============================================================================
--- team/dlee/endpoints/tests/test_stasis_endpoints.c (added)
+++ team/dlee/endpoints/tests/test_stasis_endpoints.c Wed May 1 23:48:56 2013
@@ -1,0 +1,116 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file \brief Test endpoints.
+ *
+ * \author\verbatim David M. Lee, II <dlee at digium.com> \endverbatim
+ *
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+ <depend>TEST_FRAMEWORK</depend>
+ <depend>res_stasis_test</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/astobj2.h"
+#include "asterisk/channel.h"
+#include "asterisk/endpoints.h"
+#include "asterisk/module.h"
+#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stasis_test.h"
+#include "asterisk/test.h"
+
+static const char *test_category = "/stasis/endpoints/";
+
+static void safe_channel_release(struct ast_channel *chan)
+{
+ if (!chan) {
+ return;
+ }
+ ast_channel_release(chan);
+}
+
+AST_TEST_DEFINE(channel_messages)
+{
+ RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
+ RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
+ RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
+ int actual;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = __func__;
+ info->category = test_category;
+ info->summary = "Test endpoint setters";
+ info->description = "Test endpoint setters";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ uut = ast_endpoint_create("TEST", "test_res");
+ ast_test_validate(test, NULL != uut);
+
+ sink = stasis_message_sink_create();
+ ast_test_validate(test, NULL != sink);
+
+ sub = stasis_subscribe(ast_endpoint_topic(uut), stasis_message_sink_cb,
+ sink);
+
+ chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "test_res", "100",
+ "100", "default", NULL, 0, "TEST/test_res");
+ ast_test_validate(test, NULL != chan);
+
+ ast_endpoint_add_channel(uut, chan);
+
+ actual = stasis_message_sink_wait_for(sink, 2, DEFAULT_WAIT_MILLIS);
+ ast_test_validate(test, 2 == actual);
+
+ safe_channel_release(chan);
+ chan = NULL;
+
+ return AST_TEST_PASS;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(channel_messages);
+ return 0;
+}
+
+static int load_module(void)
+{
+ AST_TEST_REGISTER(channel_messages);
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
+ "Endpoint testing",
+ .load = load_module,
+ .unload = unload_module,
+ .nonoptreq = "res_stasis_test",
+ );
Propchange: team/dlee/endpoints/tests/test_stasis_endpoints.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dlee/endpoints/tests/test_stasis_endpoints.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dlee/endpoints/tests/test_stasis_endpoints.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the svn-commits
mailing list