43 #define TEST_CATEGORY "/channels/features/"
45 #define CHANNEL_TECH_NAME "FeaturesTestChannel"
47 #define TEST_BACKEND_NAME "Features Test Logging"
49 #define TEST_CHANNEL_FORMAT ast_format_slin
53 .type = CHANNEL_TECH_NAME,
54 .description =
"Mock channel technology for Features tests",
57 static void test_nanosleep(
int secs,
long nanosecs)
59 struct timespec sleep_time = {secs, nanosecs};
61 while ((nanosleep(&sleep_time, &sleep_time) == -1) && (errno == EINTR)) {
68 ast_channel_lock(channel);
70 ast_channel_unlock(channel);
71 test_nanosleep(0, 1000000);
72 ast_channel_lock(channel);
74 ast_channel_unlock(channel);
80 ast_channel_lock(channel);
82 ast_channel_unlock(channel);
83 test_nanosleep(0, 1000000);
84 ast_channel_lock(channel);
86 ast_channel_unlock(channel);
90 #define START_ALICE(channel) START_CHANNEL(channel, "Alice", "100")
93 #define START_BOB(channel) START_CHANNEL(channel, "Bob", "200")
95 #define START_CHANNEL(channel, name, number) do { \
96 channel = ast_channel_alloc(0, AST_STATE_UP, number, name, number, number, \
97 "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/" name); \
98 ast_channel_nativeformats_set(channel, test_features_chan_tech.capabilities); \
99 ast_channel_set_rawwriteformat(channel, TEST_CHANNEL_FORMAT); \
100 ast_channel_set_rawreadformat(channel, TEST_CHANNEL_FORMAT); \
101 ast_channel_set_writeformat(channel, TEST_CHANNEL_FORMAT); \
102 ast_channel_set_readformat(channel, TEST_CHANNEL_FORMAT); \
103 ast_channel_unlock(channel); \
107 #define HANGUP_CHANNEL(channel) do { \
108 ao2_ref(channel, +1); \
109 ast_hangup((channel)); \
110 ao2_cleanup(channel); \
114 static void safe_channel_release(
struct ast_channel *chan)
122 static void safe_bridge_destroy(
struct ast_bridge *bridge)
132 int *callback_executed = obj;
133 (*callback_executed)++;
138 static void stream_periodic_frames(
struct ast_channel *chan,
int ms,
int interval_ms)
142 ast_assert(chan != NULL);
144 ast_assert(0 < interval_ms);
146 nanosecs = interval_ms * 1000000L;
150 if (interval_ms < ms) {
153 nanosecs = ms * 1000000L;
156 test_nanosleep(0, nanosecs);
167 int callback_executed = 0;
168 struct ast_frame f = { AST_FRAME_DTMF, };
172 info->name = __func__;
173 info->category = TEST_CATEGORY;
174 info->summary =
"Test running DTMF hooks on a channel via the feature hooks mechanism";
176 "This test creates two channels, adds a DTMF hook to one, places them into\n"
177 "a bridge, and verifies that the DTMF hook added to the channel feature\n"
178 "hooks can be triggered once the channel is bridged.";
179 return AST_TEST_NOT_RUN;
186 ast_test_validate(
test, bridge1 != NULL);
188 ast_test_validate(
test, bridge2 != NULL);
215 stream_periodic_frames(chan_alice, 1000, 20);
238 stream_periodic_frames(chan_alice, 1000, 20);
248 ast_test_validate(
test, callback_executed == 2);
250 return AST_TEST_PASS;
260 int callback_executed = 0;
264 info->name = __func__;
265 info->category = TEST_CATEGORY;
266 info->summary =
"Test running interval hooks on a channel via the feature hooks mechanism";
268 "This test creates two channels, adds an interval hook to one, places them\n"
269 "into a bridge, and verifies that the interval hook added to the channel\n"
270 "feature hooks is triggered once the channel is bridged.";
271 return AST_TEST_NOT_RUN;
278 ast_test_validate(
test, bridge1 != NULL);
280 ast_test_validate(
test, bridge2 != NULL);
299 test_nanosleep(1, 500000000);
307 ast_test_validate(
test, callback_executed >= 1);
308 callback_executed = 0;
317 test_nanosleep(1, 500000000);
327 ast_test_validate(
test, callback_executed >= 1);
329 return AST_TEST_PASS;
332 static int unload_module(
void)
334 AST_TEST_UNREGISTER(test_features_channel_dtmf);
335 AST_TEST_UNREGISTER(test_features_channel_interval);
344 static int load_module(
void)
353 AST_TEST_REGISTER(test_features_channel_dtmf);
354 AST_TEST_REGISTER(test_features_channel_interval);
Main Channel structure associated with a channel.
void ast_bridge_features_cleanup(struct ast_bridge_features *features)
Clean up the contents of a bridge features structure.
Asterisk main include file. File version handling, generic pbx functions.
Structure that contains features information.
Time-related functions and macros.
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
int ast_bridge_features_init(struct ast_bridge_features *features)
Initialize bridge features structure.
static void wait_for_bridged(struct ast_channel *channel)
Wait until a channel is bridged.
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
int ast_channel_register(const struct ast_channel_tech *tech)
Register a channel technology (a new channel driver) Called by a channel module to register the kind ...
struct ast_frame_subclass subclass
int ast_bridge_impart(struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, enum ast_bridge_impart_flags flags) attribute_warn_unused_result
Impart a channel to a bridge (non-blocking)
General Asterisk PBX channel definitions.
int ast_bridge_interval_hook(struct ast_bridge_features *features, enum ast_bridge_hook_timer_option flags, unsigned int interval, ast_bridge_hook_callback callback, void *hook_pvt, ast_bridge_hook_pvt_destructor destructor, enum ast_bridge_hook_remove_flags remove_flags)
Attach an interval hook to a bridge features structure.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Structure that contains information about a bridge.
int ast_bridge_depart(struct ast_channel *chan)
Depart a channel from a bridge.
struct ast_format_cap * capabilities
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
static void wait_for_unbridged(struct ast_channel *channel)
Wait until a channel is not bridged.
Module has failed to load, may be in an inconsistent state.
Basic bridge subclass API.
int ast_bridge_dtmf_hook(struct ast_bridge_features *features, const char *dtmf, ast_bridge_hook_callback callback, void *hook_pvt, ast_bridge_hook_pvt_destructor destructor, enum ast_bridge_hook_remove_flags remove_flags)
Attach a DTMF hook to a bridge features structure.
struct ast_frame ast_null_frame
struct ast_bridge * ast_bridge_basic_new(void)
Create a new basic class bridge.
Structure that contains information regarding a channel in a bridge.
#define START_BOB(channel)
Create a test_features_chan_tech for Bob.
static struct ast_channel_tech test_features_chan_tech
A channel technology used for the unit tests.
Data structure associated with a single frame of data.
#define AST_TEST_DEFINE(hdr)
Call Parking and Pickup API Includes code and algorithms from the Zapata library. ...
int ast_channel_feature_hooks_append(struct ast_channel *chan, struct ast_bridge_features *features)
Appends to the channel-attached features a channel has access to upon being bridged.
#define START_ALICE(channel)
Create a test_features_chan_tech for Alice.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define HANGUP_CHANNEL(channel)
Hang up a test channel safely.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.