diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cel.c | 69 | ||||
-rw-r--r-- | tests/test_event.c | 548 |
2 files changed, 7 insertions, 610 deletions
diff --git a/tests/test_cel.c b/tests/test_cel.c index 2bf4f29e5..0ad92f475 100644 --- a/tests/test_cel.c +++ b/tests/test_cel.c @@ -56,6 +56,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define CHANNEL_TECH_NAME "CELTestChannel" +#define TEST_BACKEND_NAME "CEL Test Logging" + /*! \brief A placeholder for Asterisk's 'real' CEL configuration */ static struct ast_cel_general_config *saved_config; @@ -1544,9 +1546,6 @@ AST_TEST_DEFINE(test_cel_local_optimize) return AST_TEST_PASS; } -/*! Subscription for CEL events */ -static struct ast_event_sub *event_sub = NULL; - /*! Container for astobj2 duplicated ast_events */ static struct ao2_container *cel_received_events = NULL; @@ -1648,26 +1647,15 @@ static int append_expected_event( return append_expected_event_snapshot(snapshot, type, userdefevname, extra, peer); } -static void test_sub(const struct ast_event *event, void *data) +static void test_sub(struct ast_event *event) { struct ast_event *event_dup = ao2_dup_event(event); - const char *sync_tag; SCOPED_MUTEX(mid_test_lock, &mid_test_sync_lock); if (!event_dup) { return; } - sync_tag = ast_event_get_ie_str(event, AST_EVENT_IE_SERVICE); - if (sync_tag) { - if (!strcmp(sync_tag, "SYNC")) { - /* trigger things */ - SCOPED_MUTEX(lock, &sync_lock); - ast_cond_signal(&sync_out); - return; - } - } - /* save the event for later processing */ ao2_link(cel_received_events, event_dup); @@ -1690,7 +1678,6 @@ static void test_sub(const struct ast_event *event, void *data) */ static int test_cel_init_cb(struct ast_test_info *info, struct ast_test *test) { - ast_assert(event_sub == NULL); ast_assert(cel_received_events == NULL); ast_assert(cel_expected_events == NULL); @@ -1707,8 +1694,9 @@ static int test_cel_init_cb(struct ast_test_info *info, struct ast_test *test) cel_expected_events = ao2_container_alloc(1, NULL, NULL); /* start the CEL event callback */ - event_sub = ast_event_subscribe(AST_EVENT_CEL, test_sub, "CEL Test Logging", - NULL, AST_EVENT_IE_END); + if (ast_cel_backend_register(TEST_BACKEND_NAME, test_sub)) { + return -1; + } return 0; } @@ -1866,29 +1854,6 @@ static int check_events(struct ast_test *test, struct ao2_container *local_expec return 0; } -static struct ast_event *create_sync_event(void) -{ - struct ast_event *event_dup; - RAII_VAR(struct ast_event *, event, ao2_callback(cel_expected_events, 0, NULL, NULL), ao2_cleanup); - uint16_t event_len; - - if (!event) { - return NULL; - } - - event_len = ast_event_get_size(event); - - event_dup = ast_calloc(1, event_len); - if (!event_dup) { - return NULL; - } - - memcpy(event_dup, event, event_len); - ast_event_append_ie_str(&event_dup, AST_EVENT_IE_SERVICE, "SYNC"); - - return event_dup; -} - /*! * \internal * \brief Callback function called after each test executes. @@ -1900,35 +1865,15 @@ static struct ast_event *create_sync_event(void) */ static int cel_verify_and_cleanup_cb(struct ast_test_info *info, struct ast_test *test) { - struct ast_event *sync; RAII_VAR(struct ao2_container *, local_expected, cel_expected_events, ao2_cleanup); RAII_VAR(struct ao2_container *, local_received, cel_received_events, ao2_cleanup); - ast_assert(event_sub != NULL); ast_assert(cel_received_events != NULL); ast_assert(cel_expected_events != NULL); do_sleep(); - /* sync with the event system */ - sync = create_sync_event(); - ast_test_validate(test, sync != NULL); - if (ast_event_queue(sync)) { - ast_event_destroy(sync); - ast_test_validate(test, NULL); - } else { - struct timeval start = ast_tvnow(); - struct timespec end = { - .tv_sec = start.tv_sec + 15, - .tv_nsec = start.tv_usec * 1000 - }; - - SCOPED_MUTEX(lock, &sync_lock); - ast_cond_timedwait(&sync_out, &sync_lock, &end); - } - /* stop the CEL event callback and clean up storage structures*/ - ast_event_unsubscribe(event_sub); - event_sub = NULL; + ast_cel_backend_unregister(TEST_BACKEND_NAME); /* cleaned up by RAII_VAR's */ cel_expected_events = NULL; diff --git a/tests/test_event.c b/tests/test_event.c index 10282b5cc..a7279e585 100644 --- a/tests/test_event.c +++ b/tests/test_event.c @@ -25,7 +25,6 @@ * \ingroup tests * * \todo API Calls not yet touched by a test: XXX TODO - * - ast_event_report_subs() * - ast_event_get_ie_type_name() * - ast_event_get_ie_pltype() * - ast_event_iterator_init() @@ -194,555 +193,9 @@ struct event_sub_data { unsigned int count; }; -static void event_sub_cb(const struct ast_event *event, void *d) -{ - struct event_sub_data *data = d; - - data->count++; -} - -enum test_subs_class_type { - TEST_SUBS_ALL_STR, - TEST_SUBS_CUSTOM_STR, - TEST_SUBS_CUSTOM_RAW, - TEST_SUBS_CUSTOM_UINT, - TEST_SUBS_CUSTOM_EXISTS, - TEST_SUBS_CUSTOM_DYNAMIC, - TEST_SUBS_CUSTOM_ANY, - - /* Must be last. */ - TEST_SUBS_TOTAL, -}; - -/*! - * \internal - * \brief Convert enum test_subs_class_type to string. - * - * \param val Enum value to convert to string. - * - * \return String equivalent of enum value. - */ -static const char *test_subs_class_type_str(enum test_subs_class_type val) -{ - switch (val) { - case TEST_SUBS_ALL_STR: - return "TEST_SUBS_ALL_STR"; - case TEST_SUBS_CUSTOM_STR: - return "TEST_SUBS_CUSTOM_STR"; - case TEST_SUBS_CUSTOM_RAW: - return "TEST_SUBS_CUSTOM_RAW"; - case TEST_SUBS_CUSTOM_UINT: - return "TEST_SUBS_CUSTOM_UINT"; - case TEST_SUBS_CUSTOM_EXISTS: - return "TEST_SUBS_CUSTOM_EXISTS"; - case TEST_SUBS_CUSTOM_DYNAMIC: - return "TEST_SUBS_CUSTOM_DYNAMIC"; - case TEST_SUBS_CUSTOM_ANY: - return "TEST_SUBS_CUSTOM_ANY"; - case TEST_SUBS_TOTAL: - break; - } - return "Unknown"; -} - -/*! - * \internal - * \brief Test event subscriptions - * - * - Query for existing Subscriptions: - * - ast_event_check_subscriber() - */ -AST_TEST_DEFINE(event_sub_test) -{ - enum ast_test_result_state res = AST_TEST_PASS; - struct ast_event *event; - int i; - enum ast_event_subscriber_res sub_res; - struct { - struct ast_event_sub *sub; - struct event_sub_data data; - const unsigned int expected_count; - } test_subs[TEST_SUBS_TOTAL] = { - [TEST_SUBS_ALL_STR] = { - .expected_count = 2, - }, - [TEST_SUBS_CUSTOM_STR] = { - .expected_count = 2, - }, - [TEST_SUBS_CUSTOM_RAW] = { - .expected_count = 2, - }, - [TEST_SUBS_CUSTOM_UINT] = { - .expected_count = 1, - }, - [TEST_SUBS_CUSTOM_EXISTS] = { - .expected_count = 2, - }, - [TEST_SUBS_CUSTOM_DYNAMIC] = { - .expected_count = 1, - }, - [TEST_SUBS_CUSTOM_ANY] = { - .expected_count = 5, - }, - }; - - switch (cmd) { - case TEST_INIT: - info->name = "ast_event_subscribe_test"; - info->category = "/main/event/"; - info->summary = "Test event subscriptions"; - info->description = - "This test exercises the API calls that allow subscriptions " - "to events."; - return AST_TEST_NOT_RUN; - case TEST_EXECUTE: - break; - } - - ast_test_status_update(test, "Check that NO CUSTOM subscribers exist\n"); - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_NONE) { - ast_test_status_update(test, "CUSTOM subscriptions should not exist! (%d)\n", - sub_res); - res = AST_TEST_FAIL; - } - - /* - * Subscription TEST_SUBS_CUSTOM_STR: - * - allocate normally - * - subscribe to CUSTOM events with a CEL_CIDNAME STR IE check - */ - ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_STR subscription\n"); - test_subs[TEST_SUBS_CUSTOM_STR].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb, - test_subs_class_type_str(TEST_SUBS_CUSTOM_STR), &test_subs[TEST_SUBS_CUSTOM_STR].data, - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "FOO/bar", - AST_EVENT_IE_END); - if (!test_subs[TEST_SUBS_CUSTOM_STR].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_STR subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - ast_test_status_update(test, "Check that a CUSTOM subscriber exists\n"); - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_EXISTS) { - ast_test_status_update(test, "A CUSTOM subscription should exist! (%d)\n", - sub_res); - res = AST_TEST_FAIL; - } - - /* - * Subscription TEST_SUBS_ALL_STR: - * - allocate normally - * - subscribe to ALL events with a CEL_CIDNAME STR IE check - */ - ast_test_status_update(test, "Adding TEST_SUBS_ALL_STR subscription\n"); - test_subs[TEST_SUBS_ALL_STR].sub = ast_event_subscribe(AST_EVENT_ALL, event_sub_cb, - test_subs_class_type_str(TEST_SUBS_ALL_STR), &test_subs[TEST_SUBS_ALL_STR].data, - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "FOO/bar", - AST_EVENT_IE_END); - if (!test_subs[TEST_SUBS_ALL_STR].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_ALL_STR subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Subscription TEST_SUBS_CUSTOM_RAW: - * - allocate normally - * - subscribe to CUSTOM events with a CEL_USEREVENT_NAME RAW IE check - */ - ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_RAW subscription\n"); - test_subs[TEST_SUBS_CUSTOM_RAW].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb, - test_subs_class_type_str(TEST_SUBS_CUSTOM_RAW), &test_subs[TEST_SUBS_CUSTOM_RAW].data, - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar"), - AST_EVENT_IE_END); - if (!test_subs[TEST_SUBS_CUSTOM_RAW].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_RAW subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Subscription TEST_SUBS_CUSTOM_UINT: - * - allocate normally - * - subscribe to CUSTOM events with a CEL_AMAFLAGS UINT IE check - */ - ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_UINT subscription\n"); - test_subs[TEST_SUBS_CUSTOM_UINT].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb, - test_subs_class_type_str(TEST_SUBS_CUSTOM_UINT), &test_subs[TEST_SUBS_CUSTOM_UINT].data, - AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, 5, - AST_EVENT_IE_END); - if (!test_subs[TEST_SUBS_CUSTOM_UINT].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_UINT subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Subscription TEST_SUBS_CUSTOM_EXISTS: - * - allocate normally - * - subscribe to CUSTOM events with a CEL_AMAFLAGS UINT and UNIQUEID EXISTS IE check - */ - ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_EXISTS subscription\n"); - test_subs[TEST_SUBS_CUSTOM_EXISTS].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb, - test_subs_class_type_str(TEST_SUBS_CUSTOM_EXISTS), &test_subs[TEST_SUBS_CUSTOM_EXISTS].data, - AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, 4, - AST_EVENT_IE_END); - if (!test_subs[TEST_SUBS_CUSTOM_EXISTS].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_EXISTS subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* For the sake of exercising destruction before activation */ - test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = ast_event_subscribe_new(AST_EVENT_CUSTOM, - event_sub_cb, &test_subs[TEST_SUBS_CUSTOM_DYNAMIC].data); - if (!test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_DYNAMIC subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub); - - /* - * Subscription TEST_SUBS_CUSTOM_DYNAMIC: - * - allocate dynamically - * - subscribe to all CUSTOM events - * - add IE checks for all types - */ - ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_DYNAMIC subscription\n"); - test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = ast_event_subscribe_new(AST_EVENT_CUSTOM, - event_sub_cb, &test_subs[TEST_SUBS_CUSTOM_DYNAMIC].data); - if (!test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_DYNAMIC subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - if (ast_event_sub_append_ie_uint(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_CEL_AMAFLAGS, 4)) { - ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub); - test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL; - ast_test_status_update(test, "Failed to append UINT IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - if (ast_event_sub_append_ie_str(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_CEL_CIDNAME, "FOO/bar")) { - ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub); - test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL; - ast_test_status_update(test, "Failed to append STR IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - if (ast_event_sub_append_ie_raw(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_CEL_USEREVENT_NAME, "800 km", - strlen("800 km"))) { - ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub); - test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL; - ast_test_status_update(test, "Failed to append RAW IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - if (ast_event_sub_activate(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub)) { - ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub); - test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL; - ast_test_status_update(test, "Failed to activate TEST_SUBS_CUSTOM_DYNAMIC subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Exercise the API call to check for existing subscriptions. - */ - ast_test_status_update(test, "Checking for subscribers to specific events\n"); - - /* Check STR matching. */ - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "FOO/bar", - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_EXISTS) { - ast_test_status_update(test, "Str FOO/bar subscription did not exist\n"); - res = AST_TEST_FAIL; - } - - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "Money", - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_NONE) { - ast_test_status_update(test, "Str Money subscription should not exist! (%d)\n", - sub_res); - res = AST_TEST_FAIL; - } - - /* Check RAW matching. */ - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar"), - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_EXISTS) { - ast_test_status_update(test, "Raw FOO/bar subscription did not exist\n"); - res = AST_TEST_FAIL; - } - - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar") - 1, - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_NONE) { - ast_test_status_update(test, "Raw FOO/bar-1 subscription should not exist! (%d)\n", - sub_res); - res = AST_TEST_FAIL; - } - - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "Monkeys", sizeof("Monkeys"), - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_NONE) { - ast_test_status_update(test, "Raw Monkeys subscription should not exist! (%d)\n", - sub_res); - res = AST_TEST_FAIL; - } - - /* Check UINT matching. */ - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, 5, - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_EXISTS) { - ast_test_status_update(test, "UINT=5 subscription did not exist\n"); - res = AST_TEST_FAIL; - } - - sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, 1, - AST_EVENT_IE_END); - if (sub_res != AST_EVENT_SUB_NONE) { - ast_test_status_update(test, "UINT=1 subscription should not exist! (%d)\n", - sub_res); - res = AST_TEST_FAIL; - } - - ast_test_status_update(test, "Special event posting test\n"); - - /* - * Event to check if event is even posted. - * - * Matching subscriptions: - * TEST_SUBS_CUSTOM_RAW - */ - event = ast_event_new(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "Mula", - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar"), - AST_EVENT_IE_END); - if (!event) { - ast_test_status_update(test, "Failed to create event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - if (ast_event_queue(event)) { - ast_event_destroy(event); - event = NULL; - ast_test_status_update(test, "Failed to queue event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - ast_test_status_update(test, "Sleeping a few seconds to allow event propagation...\n"); - sleep(3); - - /* - * Subscription TEST_SUBS_CUSTOM_ANY: - * - allocate normally - * - subscribe to all CUSTOM events - */ - ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_ANY subscription\n"); - test_subs[TEST_SUBS_CUSTOM_ANY].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb, - test_subs_class_type_str(TEST_SUBS_CUSTOM_ANY), &test_subs[TEST_SUBS_CUSTOM_ANY].data, - AST_EVENT_IE_END); - if (!test_subs[TEST_SUBS_CUSTOM_ANY].sub) { - ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_ANY subscription\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Fire off some events and track what was received in the callback - */ - ast_test_status_update(test, "Posting test events\n"); - - /* - * Event to check STR matching. - * - * Matching subscriptions: - * TEST_SUBS_ALL_STR - * TEST_SUBS_CUSTOM_STR - * TEST_SUBS_CUSTOM_ANY - */ - event = ast_event_new(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar") - 1, - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "FOO/bar", - AST_EVENT_IE_END); - if (!event) { - ast_test_status_update(test, "Failed to create event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - if (ast_event_queue(event)) { - ast_event_destroy(event); - event = NULL; - ast_test_status_update(test, "Failed to queue event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Event to check RAW matching. - * - * Matching subscriptions: - * TEST_SUBS_CUSTOM_RAW - * TEST_SUBS_CUSTOM_ANY - */ - event = ast_event_new(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "Misery", - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar"), - AST_EVENT_IE_END); - if (!event) { - ast_test_status_update(test, "Failed to create event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - if (ast_event_queue(event)) { - ast_event_destroy(event); - event = NULL; - ast_test_status_update(test, "Failed to queue event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Event to check UINT matching. - * - * Matching subscriptions: - * TEST_SUBS_CUSTOM_UINT - * TEST_SUBS_CUSTOM_ANY - */ - event = ast_event_new(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, 5, - AST_EVENT_IE_END); - if (!event) { - ast_test_status_update(test, "Failed to create event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - if (ast_event_queue(event)) { - ast_event_destroy(event); - event = NULL; - ast_test_status_update(test, "Failed to queue event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Event to check EXISTS matching. - * - * Matching subscriptions: - * TEST_SUBS_CUSTOM_EXISTS - * TEST_SUBS_CUSTOM_ANY - */ - event = ast_event_new(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, 4, - AST_EVENT_IE_UNIQUEID, AST_EVENT_IE_PLTYPE_UINT, 4, - AST_EVENT_IE_END); - if (!event) { - ast_test_status_update(test, "Failed to create event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - if (ast_event_queue(event)) { - ast_event_destroy(event); - event = NULL; - ast_test_status_update(test, "Failed to queue event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - /* - * Event to get dynamic subscription to have an event. - * - * Matching subscriptions: - * TEST_SUBS_CUSTOM_DYNAMIC - * TEST_SUBS_CUSTOM_EXISTS - * TEST_SUBS_ALL_STR - * TEST_SUBS_CUSTOM_STR - * TEST_SUBS_CUSTOM_ANY - */ - event = ast_event_new(AST_EVENT_CUSTOM, - AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, 4, - AST_EVENT_IE_UNIQUEID, AST_EVENT_IE_PLTYPE_UINT, 5, - AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_RAW, "800 km", strlen("800 km"), - AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, "FOO/bar", - AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, 5, - AST_EVENT_IE_END); - if (!event) { - ast_test_status_update(test, "Failed to create event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - if (ast_event_queue(event)) { - ast_event_destroy(event); - event = NULL; - ast_test_status_update(test, "Failed to queue event\n"); - res = AST_TEST_FAIL; - goto return_cleanup; - } - - event = NULL; - - /* - * Check the results of the test. - * - * First of all, event distribution is asynchronous from the event producer, - * so knowing when to continue from here and check results is an instance of - * the halting problem. A few seconds really should be more than enough time. - * If something was actually blocking event distribution that long, I would call - * it a bug. - * - * See test_subs[] initialization for expected results. - */ - - ast_test_status_update(test, "Sleeping a few seconds to allow event propagation...\n"); - sleep(3); - - for (i = 0; i < ARRAY_LEN(test_subs); i++) { - if (!test_subs[i].sub) { - ast_test_status_update(test, "Missing a test subscription for %s\n", - test_subs_class_type_str(i)); - res = AST_TEST_FAIL; - } - if (test_subs[i].data.count != test_subs[i].expected_count) { - ast_test_status_update(test, - "Unexpected callback count, got %u expected %u for %s\n", - test_subs[i].data.count, test_subs[i].expected_count, - test_subs_class_type_str(i)); - res = AST_TEST_FAIL; - } - } - -return_cleanup: - for (i = 0; i < ARRAY_LEN(test_subs); i++) { - if (test_subs[i].sub) { - test_subs[i].sub = ast_event_unsubscribe(test_subs[i].sub); - } - } - - return res; -} - static int unload_module(void) { AST_TEST_UNREGISTER(event_new_test); - AST_TEST_UNREGISTER(event_sub_test); return 0; } @@ -750,7 +203,6 @@ static int unload_module(void) static int load_module(void) { AST_TEST_REGISTER(event_new_test); - AST_TEST_REGISTER(event_sub_test); return AST_MODULE_LOAD_SUCCESS; } |