43 #define UNIT_TEST_DEVICE_IDENTIFIER "unit_test_device_identifier" 45 #define DEVICE_STATE_CHANNEL_TYPE "TestDeviceState" 47 #define DEVSTATE_PROVIDER "TestDevState" 49 #define DEVSTATE_PROVIDER_LC "testdevstate" 51 #define DEVSTATE_PROVIDER_LEN 12 265 state = payload->
state;
296 struct timespec wait_time = { .tv_sec = wait_now.tv_sec + 1, .tv_nsec = wait_now.tv_usec * 1000 };
301 if (error == ETIMEDOUT) {
322 info->name =
"device2extenstate_test";
323 info->category =
"/main/devicestate/";
324 info->summary =
"Tests combined devstate mapping and device to extension state mapping.";
326 "Verifies device state aggregate results match the expected combined " 327 "devstate. Then verifies the combined devstate maps to the expected " 336 "Something has changed, this test must be updated.\n",
354 "does not match %s at combined_result[%d].\n",
364 "does not match %s at exten_result[%d]\n",
436 if (device_state->
eid) {
464 struct timespec end = {
465 .tv_sec = start.tv_sec + 10,
466 .tv_nsec = start.tv_usec * 1000
473 if (!res || res == ETIMEDOUT) {
523 info->name =
"device_state_aggregation_test";
524 info->category =
"/main/devicestate/";
525 info->summary =
"Tests message routing and aggregation through the Stasis device state system.";
527 "Verifies that the device state system passes " 528 "messages appropriately, that the aggregator is " 529 "working properly, that the aggregate results match " 530 "the expected combined devstate, and that the cached " 531 "aggregate devstate is correct.";
537 foreign_eid =
ast_malloc(
sizeof(*foreign_eid));
538 ast_test_validate(
test,
NULL != foreign_eid);
539 memset(foreign_eid, 0xFF,
sizeof(*foreign_eid));
545 ast_test_validate(
test,
NULL != device_msg_router);
549 ast_test_validate(
test, !res);
552 ast_test_validate(
test, !res);
626 info->name = __func__;
627 info->category =
"/main/devicestate/";
628 info->summary =
"Test adding a device state provider";
630 "Test that a custom device state provider can be added, and that\n" 631 "it cannot be added if already added.";
648 info->name = __func__;
649 info->category =
"/main/devicestate/";
650 info->summary =
"Test removing a device state provider";
652 "Test that a custom device state provider can be removed, and that\n" 653 "it cannot be removed if already removed.";
683 info->name = __func__;
684 info->category =
"/main/devicestate/";
685 info->summary =
"Test updates coming from a device state provider";
687 "This unit test checks that a custom device state provider can\n" 688 "have updates published for it. This includes both cacheable and\n" 689 "non-cacheable events. In the case of non-cacheable events, the\n" 690 "device state provider's callback function is queried for the\n" 691 "device state when AST_DEVICE_UNKNOWN is published.";
719 expected_results[i]);
757 expected_results[i]);
792 info->name = __func__;
793 info->category =
"/main/devicestate/";
794 info->summary =
"Test ast_device_state conversions";
796 "Test various transformations of ast_device_state values.";
846 struct timespec wait_time = { .tv_sec = wait_now.tv_sec + 1, .tv_nsec = wait_now.tv_usec * 1000 };
851 if (error == ETIMEDOUT) {
877 info->name = __func__;
878 info->category =
"/main/devicestate/";
879 info->summary =
"Test deriving device state from a channel's state";
881 "Test querying a channel's state to derive a device state.";
892 ast_test_validate(
test, chan !=
NULL);
921 .description =
"Device State Unit Test Channel Driver",
#define DEVICE_STATE_CHANNEL_TYPE
struct stasis_topic * ast_device_state_topic(const char *device)
Get the Stasis topic for device state messages for a specific device.
struct ao2_container * stasis_cache_dump_all(struct stasis_cache *cache, struct stasis_message_type *type)
Dump all entity items from the cache to a subscription.
#define UNIT_TEST_DEVICE_IDENTIFIER
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
enum sip_cc_notify_state state
const char * ast_devstate2str(enum ast_device_state devstate) attribute_pure
Convert device state to text string for output.
static char exten[AST_MAX_EXTENSION]
Main Channel structure associated with a channel.
ast_device_state
Device States.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
ast_extension_states
Extension states.
Asterisk main include file. File version handling, generic pbx functions.
static enum ast_device_state current_device_state
The current device state for our device state provider.
static ast_mutex_t update_lock
Mutex for update_cond.
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
#define DEVSTATE_PROVIDER
static AST_VECTOR(, enum ast_device_state) result_states
The resulting device state updates caused by some function call.
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
#define ao2_callback(c, flags, cb_fn, arg)
enum ast_device_state state
static unsigned int chan_idx
Used to assign an increasing integer to channel name.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
enum ast_device_state ast_parse_device_state(const char *device)
Search the Channels by Name.
static int combined_results[]
#define AST_TEST_REGISTER(cb)
int ast_devstate_prov_del(const char *label)
Remove device state provider.
static void cache_cleanup(int unused)
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
static void consumer_finalize(void *data, struct stasis_subscription *sub, struct stasis_message *message)
#define AST_VECTOR_REMOVE_UNORDERED(vec, idx)
Remove an element from an unordered vector by index.
#define ast_cond_init(cond, attr)
struct stasis_message * stasis_cache_clear_create(struct stasis_message *message)
A message which instructs the caching topic to remove an entry from its cache.
static void consumer_dtor(void *obj)
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
struct stasis_message * stasis_cache_get_by_eid(struct stasis_cache *cache, struct stasis_message_type *type, const char *id, const struct ast_eid *eid)
Retrieve an item from the cache for a specific entity.
#define ast_mutex_lock(a)
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 ...
static int chan_test_devicestate_cb(const char *device_number)
#define ast_cond_signal(cond)
An Entity ID is essentially a MAC address, brief and unique.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
Get the aggregate device state result.
static ast_mutex_t channel_cb_lock
Mutext for channel_cb_cond.
#define DEVSTATE_PROVIDER_LEN
static int chan_callback_called
Whether or not the channel device state callback was called.
pthread_cond_t ast_cond_t
#define ast_strlen_zero(foo)
int sig_on_non_aggregate_state
static struct consumer * consumer_create(void)
static int wait_for_device_state_updates(struct ast_test *test, int expected_updates)
void * ao2_object_get_lockaddr(void *obj)
Return the mutex lock address of an object.
static void device_state_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Stasis subscription callback for device state updates.
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
struct stasis_topic * ast_device_state_topic_cached(void)
Get the Stasis caching topic for device state messages.
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_test_status_update(a, b, c...)
const struct ast_eid * eid
The EID of the server where this message originated.
#define ao2_ref(o, delta)
const char * ast_extension_state2str(int extension_state)
Return string representation of the state of an extension.
struct stasis_message_type * stasis_cache_update_type(void)
Message type for cache update messages.
static enum ast_device_state devstate_prov_cb(const char *data)
#define ast_malloc(len)
A wrapper for malloc()
enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
Convert channel state to devicestate.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
#define stasis_message_router_create(topic)
#define stasis_subscribe(topic, callback, data)
static int cache_update(struct stasis_message *msg, const void *data)
Message matcher looking for cache update messages.
static void consumer_reset(struct consumer *consumer)
void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
Add a device state to the aggregate device state.
static int remove_device_states_cb(void *obj, void *arg, int flags)
const char * ast_devstate_str(enum ast_device_state devstate) attribute_pure
Convert device state to text string that is easier to parse.
struct stasis_message * new_snapshot
New value.
int ast_publish_device_state_full(const char *device, enum ast_device_state state, enum ast_devstate_cache cachable, struct ast_eid *eid)
Publish a device state update with EID.
struct stasis_cache * ast_device_state_cache(void)
Backend cache for ast_device_state_topic_cached()
static void safe_hangup(void *object)
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define AST_TEST_UNREGISTER(cb)
static int load_module(void)
#define ast_cond_destroy(cond)
#define ao2_alloc(data_size, destructor_fn)
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
int stasis_subscription_final_message(struct stasis_subscription *sub, struct stasis_message *msg)
Determine whether a message is the final message to be received on a subscription.
enum ast_extension_states ast_devstate_to_extenstate(enum ast_device_state devstate)
Map devstate to an extension state.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
Initialize aggregate device state.
AST_TEST_DEFINE(device2extenstate_test)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
enum ast_device_state state
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
Module has failed to load, may be in an inconsistent state.
Vector container support.
#define DEVSTATE_PROVIDER_LC
static ast_cond_t channel_cb_cond
Condition wait variable for channel tech device state cb.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
static int wait_for_channel_callback(struct ast_test *test)
Wait until the test channel driver's devicestate callback is called.
static void clear_result_states(void)
Clear out all recorded device states in result_states.
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
void stasis_message_router_unsubscribe(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic.
struct stasis_forward * sub
static int unload_module(void)
You shouldn't care about the contents of this struct.
enum ast_device_state aggregate_state
The structure that contains device state.
int error(const char *format,...)
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
static int exten_results[]
int ast_devstate_changed_literal(enum ast_device_state state, enum ast_devstate_cache cachable, const char *device)
Tells Asterisk the State for Device is changed.
static void consumer_exec(void *data, struct stasis_subscription *sub, struct stasis_message *message)
#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.
static void consumer_wait_for(struct consumer *consumer)
#define ast_cond_timedwait(cond, mutex, time)
struct ast_channel_tech chan_test_devicestate
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_MUTEX_DEFINE_STATIC(mutex)
#define ast_mutex_unlock(a)
static ast_cond_t update_cond
Condition wait variable for device state updates.
#define ast_publish_device_state(device, state, cachable)
Publish a device state update.