summaryrefslogtreecommitdiff
path: root/tests/test_channel.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2017-03-08 13:24:46 +0000
committerJoshua Colp <jcolp@digium.com>2017-03-27 19:54:44 +0000
commit5d938045d465d66e28bb49816c482a8b68f99342 (patch)
tree50b25c29fc199a66c246c95871b492e242a68c7a /tests/test_channel.c
parentf5603cb1ece5001d1288004c9bc6ed51448deb81 (diff)
channel: Remove old epoll support and fixed max number of file descriptors.
This change removes the old epoll support which has not been used or maintained in quite some time. The fixed number of file descriptors on a channel has also been removed. File descriptors are now contained in a growable vector. This can be used like before by specifying a specific position to store a file descriptor at or using a new API call, ast_channel_fd_add, which adds a file descriptor to the channel and returns its position. Tests have been added which cover the growing behavior of the vector and the new API call. ASTERISK-26885 Change-Id: I1a754b506c009b83dfdeeb08c2d2815db30ef928
Diffstat (limited to 'tests/test_channel.c')
-rw-r--r--tests/test_channel.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/test_channel.c b/tests/test_channel.c
new file mode 100644
index 000000000..854aff782
--- /dev/null
+++ b/tests/test_channel.c
@@ -0,0 +1,119 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, Digium, Inc.
+ *
+ * Joshua Colp <jcolp@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 Channel unit tests
+ *
+ * \author Joshua Colp <jcolp@digium.com>
+ *
+ */
+
+/*** MODULEINFO
+ <depend>TEST_FRAMEWORK</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include "asterisk/module.h"
+#include "asterisk/test.h"
+#include "asterisk/channel.h"
+
+AST_TEST_DEFINE(set_fd_grow)
+{
+ struct ast_channel *mock_channel;
+ enum ast_test_result_state res = AST_TEST_PASS;
+ int pos;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "set_fd_grow";
+ info->category = "/main/channel/";
+ info->summary = "channel setting file descriptor with growth test";
+ info->description =
+ "Test that setting a file descriptor on a high position of a channel results in -1 set on any new positions";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ mock_channel = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, "TestChannel");
+ ast_test_validate_cleanup(test, mock_channel, res, done);
+
+ ast_channel_set_fd(mock_channel, AST_EXTENDED_FDS + 10, 1);
+ ast_test_validate_cleanup(test, ast_channel_fd_count(mock_channel) == AST_EXTENDED_FDS + 11, res, done);
+
+ for (pos = AST_EXTENDED_FDS; (pos < AST_EXTENDED_FDS + 10); pos++) {
+ ast_test_validate_cleanup(test, ast_channel_fd(mock_channel, pos) == -1, res, done);
+ }
+
+done:
+ ast_hangup(mock_channel);
+
+ return res;
+}
+
+AST_TEST_DEFINE(add_fd)
+{
+ struct ast_channel *mock_channel;
+ enum ast_test_result_state res = AST_TEST_PASS;
+ int pos;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "add_fd";
+ info->category = "/main/channel/";
+ info->summary = "channel adding file descriptor test";
+ info->description =
+ "Test that adding a file descriptor to a channel places it in the expected position";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ mock_channel = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, "TestChannel");
+ ast_test_validate_cleanup(test, mock_channel, res, done);
+
+ pos = ast_channel_fd_add(mock_channel, 1);
+ ast_test_validate_cleanup(test, pos == AST_EXTENDED_FDS, res, done);
+
+ ast_channel_set_fd(mock_channel, pos, -1);
+ ast_test_validate_cleanup(test, ast_channel_fd(mock_channel, pos) == -1, res, done);
+
+done:
+ ast_hangup(mock_channel);
+
+ return res;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(set_fd_grow);
+ AST_TEST_UNREGISTER(add_fd);
+ return 0;
+}
+
+static int load_module(void)
+{
+ AST_TEST_REGISTER(set_fd_grow);
+ AST_TEST_REGISTER(add_fd);
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel Unit Tests");