From e06e519a908dd7640764778cfb91c29699f3f679 Mon Sep 17 00:00:00 2001 From: "David M. Lee" Date: Wed, 8 May 2013 13:39:08 +0000 Subject: 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 --- tests/test_endpoints.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 tests/test_endpoints.c (limited to 'tests/test_endpoints.c') diff --git a/tests/test_endpoints.c b/tests/test_endpoints.c new file mode 100644 index 000000000..2758e8e78 --- /dev/null +++ b/tests/test_endpoints.c @@ -0,0 +1,158 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2013, Digium, Inc. + * + * David M. Lee, II + * + * 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 \endverbatim + * + * \ingroup tests + */ + +/*** MODULEINFO + TEST_FRAMEWORK + core + ***/ + +#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->num_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, + ); -- cgit v1.2.3