asterisk/tests/test_stasis_endpoints.c

306 lines
9.3 KiB
C
Raw Normal View History

Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2013, Digium, Inc.
*
* David M. Lee, II <dlee@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.
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
*
* \author\verbatim David M. Lee, II <dlee@digium.com> \endverbatim
*
* \ingroup tests
*/
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
<depend>res_stasis_test</depend>
<support_level>core</support_level>
***/
#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/channel.h"
#include "asterisk/endpoints.h"
#include "asterisk/module.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/stasis_test.h"
#include "asterisk/test.h"
static const char *test_category = "/stasis/endpoints/";
/*! \brief Message matcher looking for cache update messages */
static int cache_update(struct stasis_message *msg, const void *data) {
struct stasis_cache_update *update;
struct ast_endpoint_snapshot *snapshot;
const char *name = data;
if (stasis_cache_update_type() != stasis_message_type(msg)) {
return 0;
}
update = stasis_message_data(msg);
if (ast_endpoint_snapshot_type() != update->type) {
return 0;
}
snapshot = stasis_message_data(update->old_snapshot);
if (!snapshot) {
snapshot = stasis_message_data(update->new_snapshot);
}
return 0 == strcmp(name, snapshot->resource);
}
AST_TEST_DEFINE(state_changes)
{
RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
RAII_VAR(struct ast_channel *, chan, NULL, ast_hangup);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
struct stasis_message *msg;
struct stasis_message_type *type;
struct ast_endpoint_snapshot *actual_snapshot;
int actual_count;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = test_category;
info->summary = "Test endpoint updates as its state changes";
info->description =
"Test endpoint updates as its state changes";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
uut = ast_endpoint_create("TEST", __func__);
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);
ast_test_validate(test, NULL != sub);
ast_endpoint_set_state(uut, AST_ENDPOINT_OFFLINE);
actual_count = stasis_message_sink_wait_for_count(sink, 1,
STASIS_SINK_DEFAULT_WAIT);
ast_test_validate(test, 1 == actual_count);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
msg = sink->messages[0];
type = stasis_message_type(msg);
ast_test_validate(test, ast_endpoint_snapshot_type() == type);
actual_snapshot = stasis_message_data(msg);
ast_test_validate(test, AST_ENDPOINT_OFFLINE == actual_snapshot->state);
ast_endpoint_set_max_channels(uut, 8675309);
actual_count = stasis_message_sink_wait_for_count(sink, 2,
STASIS_SINK_DEFAULT_WAIT);
ast_test_validate(test, 2 == actual_count);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
msg = sink->messages[1];
type = stasis_message_type(msg);
ast_test_validate(test, ast_endpoint_snapshot_type() == type);
actual_snapshot = stasis_message_data(msg);
ast_test_validate(test, 8675309 == actual_snapshot->max_channels);
return AST_TEST_PASS;
}
AST_TEST_DEFINE(cache_clear)
{
RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
RAII_VAR(struct ast_channel *, chan, NULL, ast_hangup);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
struct stasis_message *msg;
struct stasis_message_type *type;
struct ast_endpoint_snapshot *actual_snapshot;
struct stasis_cache_update *update;
int message_index;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = test_category;
info->summary = "Test endpoint state change messages";
info->description = "Test endpoint state change messages";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
/* Subscribe to the cache topic */
sink = stasis_message_sink_create();
ast_test_validate(test, NULL != sink);
sub = stasis_subscribe(
ast_endpoint_topic_all_cached(),
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
stasis_message_sink_cb(), sink);
ast_test_validate(test, NULL != sub);
uut = ast_endpoint_create("TEST", __func__);
ast_test_validate(test, NULL != uut);
/* Since the cache topic is a singleton (ew), it may have messages from
* elsewheres that it's processing, or maybe even some final messages
* from the prior test. We've got to wait_for our specific message,
* instead of wait_for_count.
*/
message_index = stasis_message_sink_wait_for(sink, 0,
cache_update, __func__, STASIS_SINK_DEFAULT_WAIT);
ast_test_validate(test, 0 <= message_index);
/* First message should be a cache creation entry for our endpoint */
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
msg = sink->messages[message_index];
type = stasis_message_type(msg);
ast_test_validate(test, stasis_cache_update_type() == type);
update = stasis_message_data(msg);
ast_test_validate(test, ast_endpoint_snapshot_type() == update->type);
ast_test_validate(test, NULL == update->old_snapshot);
actual_snapshot = stasis_message_data(update->new_snapshot);
ast_test_validate(test, 0 == strcmp("TEST", actual_snapshot->tech));
ast_test_validate(test,
0 == strcmp(__func__, actual_snapshot->resource));
ast_endpoint_shutdown(uut);
uut = NULL;
/* Note: there's a few messages between the creation and the clear.
* Wait for all of them... */
message_index = stasis_message_sink_wait_for(sink, message_index + 2,
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
cache_update, __func__, STASIS_SINK_DEFAULT_WAIT);
ast_test_validate(test, 0 <= message_index);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
/* Now we should have a cache removal entry */
msg = sink->messages[message_index];
type = stasis_message_type(msg);
ast_test_validate(test, stasis_cache_update_type() == type);
update = stasis_message_data(msg);
ast_test_validate(test, ast_endpoint_snapshot_type() == update->type);
actual_snapshot = stasis_message_data(update->old_snapshot);
ast_test_validate(test, 0 == strcmp("TEST", actual_snapshot->tech));
ast_test_validate(test,
0 == strcmp(__func__, actual_snapshot->resource));
ast_test_validate(test, NULL == update->new_snapshot);
return AST_TEST_PASS;
}
AST_TEST_DEFINE(channel_messages)
{
RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
RAII_VAR(struct ast_channel *, chan, NULL, ast_hangup);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
struct stasis_message *msg;
struct stasis_message_type *type;
struct ast_endpoint_snapshot *actual_snapshot;
int expected_count;
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
int actual_count;
int i;
int channel_index = -1;
int endpoint_index = -1;
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = test_category;
info->summary = "Test channel messages on an endpoint topic";
info->description =
"Test channel messages on an endpoint topic";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
uut = ast_endpoint_create("TEST", __func__);
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);
ast_test_validate(test, NULL != sub);
chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", __func__, "100",
"100", "default", NULL, NULL, 0, "TEST/test_res");
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
ast_test_validate(test, NULL != chan);
ast_endpoint_add_channel(uut, chan);
actual_count = stasis_message_sink_wait_for_count(sink, 1,
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
STASIS_SINK_DEFAULT_WAIT);
ast_test_validate(test, 1 == actual_count);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
msg = sink->messages[0];
type = stasis_message_type(msg);
ast_test_validate(test, ast_endpoint_snapshot_type() == type);
actual_snapshot = stasis_message_data(msg);
ast_test_validate(test, 1 == actual_snapshot->num_channels);
ast_hangup(chan);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
chan = NULL;
expected_count = 3;
actual_count = stasis_message_sink_wait_for_count(sink, expected_count,
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
STASIS_SINK_DEFAULT_WAIT);
ast_test_validate(test, expected_count == actual_count);
for (i = 0; i < expected_count; i++) {
msg = sink->messages[i];
type = stasis_message_type(msg);
if (type == ast_channel_snapshot_type()) {
channel_index = i;
}
if (type == ast_endpoint_snapshot_type()) {
endpoint_index = i;
}
}
ast_test_validate(test, channel_index >= 0 && endpoint_index >= 0);
actual_snapshot = stasis_message_data(sink->messages[endpoint_index]);
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
ast_test_validate(test, 0 == actual_snapshot->num_channels);
return AST_TEST_PASS;
}
static int unload_module(void)
{
AST_TEST_UNREGISTER(state_changes);
AST_TEST_UNREGISTER(cache_clear);
AST_TEST_UNREGISTER(channel_messages);
return 0;
}
static int load_module(void)
{
AST_TEST_REGISTER(state_changes);
AST_TEST_REGISTER(cache_clear);
AST_TEST_REGISTER(channel_messages);
return AST_MODULE_LOAD_SUCCESS;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Endpoint stasis-related testing",
.support_level = AST_MODULE_SUPPORT_CORE,
Initial support for endpoints. An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver 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. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08 13:39:08 +00:00
.load = load_module,
.unload = unload_module,
.requires = "res_stasis_test",
);