40 #include "asterisk/stasis_channels.h"
45 static const char *test_category =
"/stasis/endpoints/";
51 const char *name = data;
67 return 0 == strcmp(name, snapshot->
resource);
83 info->name = __func__;
84 info->category = test_category;
85 info->summary =
"Test endpoint updates as its state changes";
87 "Test endpoint updates as its state changes";
88 return AST_TEST_NOT_RUN;
94 ast_test_validate(
test, NULL != uut);
97 ast_test_validate(
test, NULL != sink);
101 ast_test_validate(
test, NULL != sub);
105 STASIS_SINK_DEFAULT_WAIT);
106 ast_test_validate(
test, 1 == actual_count);
107 msg = sink->messages[0];
115 STASIS_SINK_DEFAULT_WAIT);
116 ast_test_validate(
test, 2 == actual_count);
117 msg = sink->messages[1];
123 return AST_TEST_PASS;
140 info->name = __func__;
141 info->category = test_category;
142 info->summary =
"Test endpoint state change messages";
143 info->description =
"Test endpoint state change messages";
144 return AST_TEST_NOT_RUN;
151 ast_test_validate(
test, NULL != sink);
153 sub = stasis_subscribe(
156 ast_test_validate(
test, NULL != sub);
159 ast_test_validate(
test, NULL != uut);
168 ast_test_validate(
test, 0 <= message_index);
171 msg = sink->messages[message_index];
178 ast_test_validate(
test, 0 == strcmp(
"TEST", actual_snapshot->
tech));
179 ast_test_validate(
test,
180 0 == strcmp(__func__, actual_snapshot->
resource));
189 ast_test_validate(
test, 0 <= message_index);
192 msg = sink->messages[message_index];
198 ast_test_validate(
test, 0 == strcmp(
"TEST", actual_snapshot->
tech));
199 ast_test_validate(
test,
200 0 == strcmp(__func__, actual_snapshot->
resource));
203 return AST_TEST_PASS;
218 int channel_index = -1;
219 int endpoint_index = -1;
223 info->name = __func__;
224 info->category = test_category;
225 info->summary =
"Test channel messages on an endpoint topic";
227 "Test channel messages on an endpoint topic";
228 return AST_TEST_NOT_RUN;
234 ast_test_validate(
test, NULL != uut);
237 ast_test_validate(
test, NULL != sink);
241 ast_test_validate(
test, NULL != sub);
244 "100",
"default", NULL, NULL, 0,
"TEST/test_res");
245 ast_test_validate(
test, NULL != chan);
250 STASIS_SINK_DEFAULT_WAIT);
251 ast_test_validate(
test, 1 == actual_count);
253 msg = sink->messages[0];
264 STASIS_SINK_DEFAULT_WAIT);
265 ast_test_validate(
test, expected_count == actual_count);
267 for (i = 0; i < expected_count; i++) {
268 msg = sink->messages[i];
277 ast_test_validate(
test, channel_index >= 0 && endpoint_index >= 0);
281 return AST_TEST_PASS;
284 static int unload_module(
void)
287 AST_TEST_UNREGISTER(cache_clear);
288 AST_TEST_UNREGISTER(channel_messages);
292 static int load_module(
void)
295 AST_TEST_REGISTER(cache_clear);
296 AST_TEST_REGISTER(channel_messages);
300 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Endpoint stasis-related testing",
301 .support_level = AST_MODULE_SUPPORT_CORE,
303 .unload = unload_module,
304 .requires =
"res_stasis_test",
Structure that collects messages from a topic.
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
struct stasis_message * old_snapshot
Old value from the cache.
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.
struct ast_endpoint * ast_endpoint_create(const char *tech, const char *resource)
Create an endpoint struct.
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
struct stasis_topic * ast_endpoint_topic(struct ast_endpoint *endpoint)
Returns the topic for a specific endpoint.
void ast_endpoint_set_state(struct ast_endpoint *endpoint, enum ast_endpoint_state state)
Updates the state of the given endpoint.
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.
struct stasis_message_sink * stasis_message_sink_create(void)
Create a message sink.
struct stasis_topic * ast_endpoint_topic_all_cached(void)
Cached topic for all endpoint related messages.
General Asterisk PBX channel definitions.
const ast_string_field resource
struct stasis_message_type * stasis_cache_update_type(void)
Message type for cache update messages.
stasis_subscription_cb stasis_message_sink_cb(void)
Topic callback to receive messages.
int ast_endpoint_add_channel(struct ast_endpoint *endpoint, struct ast_channel *chan)
Adds a channel to the given endpoint.
A snapshot of an endpoint's state.
static int cache_update(struct stasis_message *msg, const void *data)
Message matcher looking for cache update messages.
struct stasis_message * new_snapshot
New value.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
const ast_string_field tech
struct stasis_message_type * type
Convenience reference to snapshot type.
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
struct stasis_message_type * ast_channel_snapshot_type(void)
Message type for ast_channel_snapshot_update.
void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint, int max_channels)
Updates the maximum number of channels an endpoint supports.
#define AST_TEST_DEFINE(hdr)
The state change queue. State changes are queued for processing by a separate thread.
void ast_endpoint_shutdown(struct ast_endpoint *endpoint)
Shutsdown an ast_endpoint.
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
enum ast_endpoint_state state
Test infrastructure for dealing with Stasis.