Asterisk - The Open Source Telephony Project
18.5.0
|
Test infrastructure for dealing with Stasis. More...
#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/module.h"
#include "asterisk/stasis_test.h"
Go to the source code of this file.
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static int | load_module (void) |
static struct timespec | make_deadline (int timeout_millis) |
static void | message_sink_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message) |
Implementation of the stasis_message_sink_cb() callback. More... | |
stasis_subscription_cb | stasis_message_sink_cb (void) |
Topic callback to receive messages. More... | |
struct stasis_message_sink * | stasis_message_sink_create (void) |
Create a message sink. More... | |
static void | stasis_message_sink_dtor (void *obj) |
int | stasis_message_sink_should_stay (struct stasis_message_sink *sink, int num_messages, int timeout_millis) |
Ensures that no new messages are received. More... | |
int | stasis_message_sink_wait_for (struct stasis_message_sink *sink, int start, stasis_wait_cb cmp_cb, const void *data, int timeout_millis) |
Wait for a message that matches the given criteria. More... | |
int | stasis_message_sink_wait_for_count (struct stasis_message_sink *sink, int num_messages, int timeout_millis) |
Wait for a sink's num_messages field to reach a certain level. More... | |
STASIS_MESSAGE_TYPE_DEFN (stasis_test_message_type) | |
struct stasis_message * | stasis_test_message_create (void) |
Creates a test message. More... | |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Stasis test utilities" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
Test infrastructure for dealing with Stasis.
Definition in file res_stasis_test.c.
|
static |
Definition at line 273 of file res_stasis_test.c.
|
static |
Definition at line 273 of file res_stasis_test.c.
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 273 of file res_stasis_test.c.
|
static |
Definition at line 259 of file res_stasis_test.c.
References AST_MODFLAG_GLOBAL_SYMBOLS, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, STASIS_MESSAGE_TYPE_INIT, stasis_test_message_type(), and unload_module().
|
static |
Definition at line 63 of file res_stasis_test.c.
References ast_tvadd(), and ast_tvnow().
Referenced by stasis_message_sink_should_stay(), stasis_message_sink_wait_for(), and stasis_message_sink_wait_for_count().
|
static |
Implementation of the stasis_message_sink_cb() callback.
Why the roundabout way of exposing this via stasis_message_sink_cb()? Well, it has to do with how we previously loaded modules, using RTLD_LAZY
.
The stasis_message_sink_cb() function gave us a layer of indirection so that the initial lazy binding would still work as expected.
Definition at line 108 of file res_stasis_test.c.
References ao2_ref, ast_cond_signal, ast_realloc, stasis_message_sink::cond, stasis_message_sink::is_done, stasis_message_sink::lock, lock, stasis_message_sink::max_messages, stasis_message_sink::messages, stasis_message_sink::num_messages, SCOPED_MUTEX, stasis_message_type(), stasis_subscription_change_type(), and stasis_subscription_final_message().
Referenced by stasis_message_sink_cb().
stasis_subscription_cb stasis_message_sink_cb | ( | void | ) |
Topic callback to receive messages.
We return a function pointer instead of simply exposing the function because of the vagaries of dlopen(), RTLD_LAZY
, and function pointers. See the comment on the implementation for details why.
Definition at line 143 of file res_stasis_test.c.
References message_sink_cb().
Referenced by AST_TEST_DEFINE().
struct stasis_message_sink* stasis_message_sink_create | ( | void | ) |
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.
Definition at line 79 of file res_stasis_test.c.
References ao2_alloc, ao2_cleanup, ao2_ref, ast_cond_init, ast_malloc, ast_mutex_init, NULL, RAII_VAR, and stasis_message_sink_dtor().
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 39 of file res_stasis_test.c.
References ao2_cleanup, ast_cond_destroy, ast_cond_wait, ast_free, ast_mutex_destroy, stasis_message_sink::cond, stasis_message_sink::is_done, stasis_message_sink::lock, lock, stasis_message_sink::max_messages, stasis_message_sink::messages, NULL, stasis_message_sink::num_messages, and SCOPED_MUTEX.
Referenced by stasis_message_sink_create().
int stasis_message_sink_should_stay | ( | struct stasis_message_sink * | sink, |
int | num_messages, | ||
int | timeout_millis | ||
) |
Ensures that no new messages are received.
The optional timeout prevents complete deadlock in a test.
sink | Sink to wait on. |
num_messages | expecte sink->num_messages. |
timeout_millis | Number of milliseconds to wait for. |
Definition at line 170 of file res_stasis_test.c.
References ast_cond_timedwait, ast_log, stasis_message_sink::cond, stasis_message_sink::lock, lock, LOG_ERROR, make_deadline(), stasis_message_sink::num_messages, and SCOPED_MUTEX.
int stasis_message_sink_wait_for | ( | struct stasis_message_sink * | sink, |
int | start, | ||
stasis_wait_cb | cmp_cb, | ||
const void * | data, | ||
int | timeout_millis | ||
) |
Wait for a message that matches the given criteria.
sink | Sink to wait on. |
start | Index of message to start with. |
cmp_cb | comparison function. This returns true (non-zero) on match and false (zero) on match. |
timeout_millis | Number of milliseconds to wait. |
Definition at line 191 of file res_stasis_test.c.
References ast_cond_timedwait, ast_log, stasis_message_sink::cond, stasis_message_sink::lock, lock, LOG_ERROR, make_deadline(), stasis_message_sink::messages, stasis_message_sink::num_messages, and SCOPED_MUTEX.
Referenced by AST_TEST_DEFINE().
int stasis_message_sink_wait_for_count | ( | struct stasis_message_sink * | sink, |
int | num_messages, | ||
int | timeout_millis | ||
) |
Wait for a sink's num_messages field to reach a certain level.
The optional timeout prevents complete deadlock in a test.
sink | Sink to wait on. |
num_messages | sink->num_messages value to wait for. |
timeout_millis | Number of milliseconds to wait. -1 to wait forever. |
Definition at line 149 of file res_stasis_test.c.
References ast_cond_timedwait, ast_log, stasis_message_sink::cond, stasis_message_sink::lock, lock, LOG_ERROR, make_deadline(), stasis_message_sink::num_messages, and SCOPED_MUTEX.
Referenced by AST_TEST_DEFINE().
STASIS_MESSAGE_TYPE_DEFN | ( | stasis_test_message_type | ) |
|
static |
Definition at line 253 of file res_stasis_test.c.
References STASIS_MESSAGE_TYPE_CLEANUP, and stasis_test_message_type().
Referenced by load_module().
|
static |
Definition at line 273 of file res_stasis_test.c.
|
static |
Definition at line 273 of file res_stasis_test.c.