43 #define TEST_CATEGORY "/main/bridging/"
45 #define CHANNEL_TECH_NAME "BridgingTestChannel"
47 #define TEST_CHANNEL_FORMAT ast_format_slin
75 ast_channel_tech_pvt_set(chan, NULL);
82 .type = CHANNEL_TECH_NAME,
83 .description =
"Mock channel technology for bridge tests",
89 static void test_nanosleep(
int secs,
long nanosecs)
91 struct timespec sleep_time = {secs, nanosecs};
93 while ((nanosleep(&sleep_time, &sleep_time) == -1) && (errno == EINTR)) {
100 ast_channel_lock(channel);
102 ast_channel_unlock(channel);
103 test_nanosleep(0, 1000000);
104 ast_channel_lock(channel);
106 ast_channel_unlock(channel);
112 ast_channel_lock(channel);
114 ast_channel_unlock(channel);
115 test_nanosleep(0, 1000000);
116 ast_channel_lock(channel);
118 ast_channel_unlock(channel);
124 ast_channel_lock(channel);
126 ast_channel_unlock(channel);
127 test_nanosleep(0, 1000000);
128 ast_channel_lock(channel);
130 ast_channel_unlock(channel);
134 #define START_ALICE(channel, pvt) START_CHANNEL(channel, pvt, "Alice", "100")
137 #define START_BOB(channel, pvt) START_CHANNEL(channel, pvt, "Bob", "200")
139 #define START_CHANNEL(channel, pvt, name, number) do { \
140 channel = ast_channel_alloc(0, AST_STATE_UP, number, name, number, number, \
141 "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/" name); \
142 pvt = ast_calloc(1, sizeof(*pvt)); \
143 ast_channel_tech_pvt_set(channel, pvt); \
144 ast_channel_nativeformats_set(channel, test_bridging_chan_tech.capabilities); \
145 ast_channel_set_rawwriteformat(channel, TEST_CHANNEL_FORMAT); \
146 ast_channel_set_rawreadformat(channel, TEST_CHANNEL_FORMAT); \
147 ast_channel_set_writeformat(channel, TEST_CHANNEL_FORMAT); \
148 ast_channel_set_readformat(channel, TEST_CHANNEL_FORMAT); \
149 ast_channel_unlock(channel); \
153 #define HANGUP_CHANNEL(channel) do { \
154 ao2_ref(channel, +1); \
155 ast_hangup((channel)); \
156 ao2_cleanup(channel); \
160 static void safe_channel_release(
struct ast_channel *chan)
168 static void safe_bridge_destroy(
struct ast_bridge *bridge)
176 static void stream_periodic_frames(
struct ast_channel *chan,
int ms,
int interval_ms)
180 ast_assert(chan != NULL);
182 ast_assert(0 < interval_ms);
184 nanosecs = interval_ms * 1000000L;
188 if (interval_ms < ms) {
191 nanosecs = ms * 1000000L;
194 test_nanosleep(0, nanosecs);
208 .data.ptr = &t38_parameters,
209 .datalen =
sizeof(t38_parameters),
217 info->name = __func__;
218 info->category = TEST_CATEGORY;
219 info->summary =
"Test that deferred frames from a channel in a bridge get written";
221 "This test creates two channels, queues a deferrable frame on one, places it into\n"
222 "a bridge, confirms the frame was read by the bridge, adds the second channel to the\n"
223 "bridge, and makes sure the deferred frame is written to it.";
224 return AST_TEST_NOT_RUN;
231 ast_test_validate(
test, bridge1 != NULL);
247 stream_periodic_frames(chan_alice, 1000, 20);
262 return AST_TEST_PASS;
265 static int unload_module(
void)
267 AST_TEST_UNREGISTER(test_bridging_deferred_queue);
276 static int load_module(
void)
285 AST_TEST_REGISTER(test_bridging_deferred_queue);
Main Channel structure associated with a channel.
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Asterisk main include file. File version handling, generic pbx functions.
Time-related functions and macros.
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
#define START_ALICE(channel, pvt)
Create a test_bridging_chan_tech for Alice.
A private structure for the test channel.
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
static void wait_for_unbridged(struct ast_channel *channel)
Wait until a channel is not bridged.
int condition
The expected indication.
enum ast_control_t38 request_response
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
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 ...
unsigned int indicated
The number of indicated things.
static void wait_for_bridged(struct ast_channel *channel)
Wait until a channel is bridged.
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.
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.
#define HANGUP_CHANNEL(channel)
Hang up a test channel safely.
Structure that contains information about a bridge.
static void wait_for_empty_queue(struct ast_channel *channel)
Wait until a channel has no frames on its read queue.
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.
Module has failed to load, may be in an inconsistent state.
Basic bridge subclass API.
static int test_bridging_chan_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Callback function for when a frame is written to a channel.
struct ast_frame ast_null_frame
struct ast_bridge * ast_bridge_basic_new(void)
Create a new basic class bridge.
static struct ast_channel_tech test_bridging_chan_tech
A channel technology used for the unit tests.
Data structure associated with a single frame of data.
#define AST_TEST_DEFINE(hdr)
enum ast_frame_type frametype
Call Parking and Pickup API Includes code and algorithms from the Zapata library. ...
#define START_BOB(channel, pvt)
Create a test_bridging_chan_tech for Bob.
#define ASTERISK_GPL_KEY
The text the key() function should return.
static int test_bridging_chan_hangup(struct ast_channel *chan)
Callback function for when a channel is hung up.
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.