43#define TEST_CATEGORY "/main/bridging/"
45#define CHANNEL_TECH_NAME "BridgingTestChannel"
47#define TEST_CHANNEL_FORMAT ast_format_slin
83 .description =
"Mock channel technology for bridge tests",
91 struct timespec sleep_time = {secs, nanosecs};
93 while ((nanosleep(&sleep_time, &sleep_time) == -1) && (
errno == EINTR)) {
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); \
184 nanosecs = interval_ms * 1000000L;
188 if (interval_ms < ms) {
191 nanosecs = ms * 1000000L;
208 .data.ptr = &t38_parameters,
209 .datalen =
sizeof(t38_parameters),
217 info->name = __func__;
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.";
231 ast_test_validate(
test, bridge1 !=
NULL);
Asterisk main include file. File version handling, generic pbx functions.
int ast_bridge_depart(struct ast_channel *chan)
Depart a channel from a bridge.
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
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)
@ AST_BRIDGE_IMPART_CHAN_DEPARTABLE
Basic bridge subclass API.
struct ast_bridge * ast_bridge_basic_new(void)
Create a new basic class bridge.
General Asterisk PBX channel definitions.
@ AST_CHAN_TP_INTERNAL
Channels with this particular technology are an implementation detail of Asterisk and should generall...
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_channel_lock(chan)
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
struct ast_readq_list * ast_channel_readq(struct ast_channel *chan)
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 ...
#define ast_channel_unlock(chan)
Call Parking and Pickup API Includes code and algorithms from the Zapata library.
@ AST_T38_REQUEST_NEGOTIATE
@ AST_CONTROL_T38_PARAMETERS
struct ast_frame ast_null_frame
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Structure that contains information about a bridge.
Structure to describe a channel "technology", ie a channel driver See for examples:
struct ast_format_cap * capabilities
Main Channel structure associated with a channel.
enum ast_control_t38 request_response
Data structure associated with a single frame of data.
enum ast_frame_type frametype
A private structure for the test channel.
int condition
The expected indication.
unsigned int indicated
The number of indicated things.
#define AST_TEST_REGISTER(cb)
#define AST_TEST_UNREGISTER(cb)
#define TEST_CHANNEL_FORMAT
static void wait_for_empty_queue(struct ast_channel *channel)
Wait until a channel has no frames on its read queue.
static int test_bridging_chan_hangup(struct ast_channel *chan)
Callback function for when a channel is hung up.
static void safe_bridge_destroy(struct ast_bridge *bridge)
#define CHANNEL_TECH_NAME
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.
#define START_ALICE(channel, pvt)
Create a test_bridging_chan_tech for Alice.
static void safe_channel_release(struct ast_channel *chan)
static void wait_for_unbridged(struct ast_channel *channel)
Wait until a channel is not bridged.
static void test_nanosleep(int secs, long nanosecs)
static int load_module(void)
#define START_BOB(channel, pvt)
Create a test_bridging_chan_tech for Bob.
static int unload_module(void)
static void wait_for_bridged(struct ast_channel *channel)
Wait until a channel is bridged.
static struct ast_channel_tech test_bridging_chan_tech
A channel technology used for the unit tests.
AST_TEST_DEFINE(test_bridging_deferred_queue)
#define HANGUP_CHANNEL(channel)
Hang up a test channel safely.
static void stream_periodic_frames(struct ast_channel *chan, int ms, int interval_ms)
Time-related functions and macros.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.