Asterisk - The Open Source Telephony Project
18.5.0
|
taskprocessor unit tests More...
#include "asterisk.h"
#include "asterisk/test.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/module.h"
#include "asterisk/astobj2.h"
#include "asterisk/serializer.h"
#include "asterisk/threadpool.h"
Go to the source code of this file.
Data Structures | |
struct | load_task_data |
Relevant data associated with taskprocessor load test. More... | |
struct | shutdown_data |
struct | task_data |
userdata associated with baseline taskprocessor test More... | |
struct | test_listener_pvt |
Private data for the test taskprocessor listener. More... | |
Macros | |
#define | HIGH_WATER_MARK 6 |
#define | LOW_WATER_MARK 3 |
#define | NUM_TASKS 20000 |
#define | TEST_DATA_ARRAY_SIZE 10 |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
AST_TEST_DEFINE (default_taskprocessor) | |
Baseline test for default taskprocessor. More... | |
AST_TEST_DEFINE (subsystem_alert) | |
Baseline test for subsystem alert. More... | |
AST_TEST_DEFINE (default_taskprocessor_load) | |
Load test for taskprocessor with default listener. More... | |
AST_TEST_DEFINE (taskprocessor_listener) | |
Test for a taskprocessor with custom listener. More... | |
AST_TEST_DEFINE (taskprocessor_shutdown) | |
AST_TEST_DEFINE (taskprocessor_push_local) | |
AST_TEST_DEFINE (serializer_pool) | |
Baseline test for a serializer pool. More... | |
static int | check_stats (struct ast_test *test, const struct test_listener_pvt *pvt, int num_pushed, int num_emptied, int num_was_empty) |
helper to ensure that statistics the listener is keeping are what we expect More... | |
static int | listener_test_task (void *ignore) |
Queued task for taskprocessor listener test. More... | |
static int | load_module (void) |
static int | load_task (void *data) |
a queued task to be used in the taskprocessor load test More... | |
static int | local_task_exe (struct ast_taskprocessor_local *local) |
static struct shutdown_data * | shutdown_data_create (int dont_wait) |
static void | shutdown_data_dtor (void *data) |
static int | shutdown_has_completed (struct shutdown_data *shutdown_data) |
static void | shutdown_poke (struct shutdown_data *shutdown_data) |
static int | shutdown_task_exec (void *data) |
static int | shutdown_waitfor_completion (struct shutdown_data *shutdown_data) |
static int | shutdown_waitfor_start (struct shutdown_data *shutdown_data) |
static int | task (void *data) |
Queued task for baseline test. More... | |
static struct task_data * | task_data_create (void) |
Create a task_data object. More... | |
static void | task_data_dtor (void *obj) |
static int | task_wait (struct task_data *task_data) |
Wait for a task to execute. More... | |
static void | test_emptied (struct ast_taskprocessor_listener *listener) |
test taskprocessor listener's emptied callback. More... | |
static void * | test_listener_pvt_alloc (void) |
test taskprocessor listener's alloc callback More... | |
static void | test_shutdown (struct ast_taskprocessor_listener *listener) |
test taskprocessor listener's shutdown callback. More... | |
static int | test_start (struct ast_taskprocessor_listener *listener) |
test taskprocessor listener's start callback More... | |
static void | test_task_pushed (struct ast_taskprocessor_listener *listener, int was_empty) |
test taskprocessor listener's task_pushed callback More... | |
static void * | tps_shutdown_thread (void *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "taskprocessor test module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct load_task_data | load_task_results |
static const struct ast_taskprocessor_listener_callbacks | test_callbacks |
taskprocessor unit tests
Definition in file test_taskprocessor.c.
#define HIGH_WATER_MARK 6 |
Referenced by AST_TEST_DEFINE().
#define LOW_WATER_MARK 3 |
Referenced by AST_TEST_DEFINE().
#define NUM_TASKS 20000 |
Definition at line 314 of file test_taskprocessor.c.
Referenced by AST_TEST_DEFINE().
#define TEST_DATA_ARRAY_SIZE 10 |
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 990 of file test_taskprocessor.c.
|
static |
Definition at line 990 of file test_taskprocessor.c.
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 990 of file test_taskprocessor.c.
AST_TEST_DEFINE | ( | default_taskprocessor | ) |
Baseline test for default taskprocessor.
This test ensures that when a task is added to a taskprocessor that has been allocated with a default listener that the task gets executed as expected
Definition at line 132 of file test_taskprocessor.c.
References ao2_cleanup, ast_taskprocessor_get(), ast_taskprocessor_push(), ast_taskprocessor_unreference(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), NULL, RAII_VAR, task(), task_data_create(), task_wait(), TEST_EXECUTE, TEST_INIT, and TPS_REF_DEFAULT.
AST_TEST_DEFINE | ( | subsystem_alert | ) |
Baseline test for subsystem alert.
Definition at line 180 of file test_taskprocessor.c.
References ao2_cleanup, ast_taskprocessor_alert_get(), ast_taskprocessor_alert_set_levels(), ast_taskprocessor_get(), ast_taskprocessor_get_subsystem_alert(), ast_taskprocessor_push(), ast_taskprocessor_size(), ast_taskprocessor_suspend(), ast_taskprocessor_unreference(), ast_taskprocessor_unsuspend(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, data_cleanup(), HIGH_WATER_MARK, sip_to_pjsip::info(), LOW_WATER_MARK, NULL, RAII_VAR, task(), task_data_create(), task_wait(), TEST_DATA_ARRAY_SIZE, TEST_EXECUTE, TEST_INIT, TPS_REF_DEFAULT, and task_data::wait_time.
AST_TEST_DEFINE | ( | default_taskprocessor_load | ) |
Load test for taskprocessor with default listener.
This test queues a large number of tasks, each with random data associated. The test ensures that all of the tasks are run and that the tasks are executed in the same order that they were queued
Definition at line 352 of file test_taskprocessor.c.
References ast_cond_destroy, ast_cond_init, ast_cond_timedwait, ast_mutex_destroy, ast_mutex_init, ast_mutex_lock, ast_mutex_unlock, ast_random(), ast_taskprocessor_get(), ast_taskprocessor_push(), ast_taskprocessor_unreference(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_tvnow(), load_task_data::cond, sip_to_pjsip::info(), load_task(), load_task_results, load_task_data::lock, NULL, NUM_TASKS, load_task_data::task_rand, load_task_data::tasks_completed, TEST_EXECUTE, TEST_INIT, and TPS_REF_DEFAULT.
AST_TEST_DEFINE | ( | taskprocessor_listener | ) |
Test for a taskprocessor with custom listener.
This test pushes tasks to a taskprocessor with a custom listener, executes the taskss, and destroys the taskprocessor.
The test ensures that the listener's callbacks are called when expected and that the data being passed in is accurate.
Definition at line 555 of file test_taskprocessor.c.
References ao2_cleanup, ast_free, ast_taskprocessor_create_with_listener(), ast_taskprocessor_execute(), ast_taskprocessor_listener_alloc(), ast_taskprocessor_push(), ast_taskprocessor_unreference(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, check_stats(), sip_to_pjsip::info(), listener(), listener_test_task(), NULL, test_listener_pvt::shutdown, TEST_EXECUTE, TEST_INIT, and test_listener_pvt_alloc().
AST_TEST_DEFINE | ( | taskprocessor_shutdown | ) |
Definition at line 749 of file test_taskprocessor.c.
References ao2_cleanup, ast_pthread_create, ast_taskprocessor_get(), ast_taskprocessor_push(), ast_taskprocessor_unreference(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), NULL, RAII_VAR, shutdown_data_create(), shutdown_has_completed(), shutdown_poke(), shutdown_task_exec(), shutdown_waitfor_completion(), shutdown_waitfor_start(), TEST_EXECUTE, TEST_INIT, TPS_REF_DEFAULT, and tps_shutdown_thread().
AST_TEST_DEFINE | ( | taskprocessor_push_local | ) |
Definition at line 837 of file test_taskprocessor.c.
References ao2_cleanup, ast_taskprocessor_get(), ast_taskprocessor_push_local(), ast_taskprocessor_set_local(), ast_taskprocessor_unreference(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), local_task_exe(), NULL, RAII_VAR, task_data_create(), task_wait(), TEST_EXECUTE, TEST_INIT, and TPS_REF_DEFAULT.
AST_TEST_DEFINE | ( | serializer_pool | ) |
Baseline test for a serializer pool.
This test ensures that when a task is added to a taskprocessor that has been allocated with a default listener that the task gets executed as expected
Definition at line 901 of file test_taskprocessor.c.
References ao2_cleanup, ast_serializer_pool_create(), ast_serializer_pool_destroy(), ast_serializer_pool_get(), ast_serializer_pool_name(), ast_serializer_pool_set_alerts(), ast_taskprocessor_push(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_threadpool_create(), AST_THREADPOOL_OPTIONS_VERSION, ast_threadpool_shutdown(), sip_to_pjsip::info(), NULL, RAII_VAR, task(), task_data_create(), task_wait(), TEST_EXECUTE, TEST_INIT, threadpool, ast_threadpool_options::version, and task_data::wait_time.
|
static |
helper to ensure that statistics the listener is keeping are what we expect
test | The currently-running test |
pvt | The private data for the taskprocessor listener |
num_pushed | The expected current number of tasks pushed to the processor |
num_emptied | The expected current number of times the taskprocessor has become empty |
num_was_empty | The expected current number of times that tasks were pushed to an empty taskprocessor |
-1 | Stats were not as expected |
0 | Stats were as expected |
Definition at line 523 of file test_taskprocessor.c.
References ast_test_status_update, test_listener_pvt::num_emptied, test_listener_pvt::num_pushed, and test_listener_pvt::num_was_empty.
Referenced by AST_TEST_DEFINE().
|
static |
Queued task for taskprocessor listener test.
Does nothing.
Definition at line 507 of file test_taskprocessor.c.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 978 of file test_taskprocessor.c.
References AST_MODULE_LOAD_SUCCESS, and ast_test_register().
|
static |
a queued task to be used in the taskprocessor load test
The task increments the number of tasks executed and puts the passed-in data into the next slot in the array of random data.
Definition at line 336 of file test_taskprocessor.c.
References ast_cond_signal, load_task_data::cond, load_task_results, task_data::lock, load_task_data::lock, SCOPED_MUTEX, load_task_data::task_rand, and load_task_data::tasks_completed.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 826 of file test_taskprocessor.c.
References ast_taskprocessor_local::data, ast_taskprocessor::local_data, ast_taskprocessor_local::local_data, and task().
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 662 of file test_taskprocessor.c.
References ao2_alloc, ao2_cleanup, ao2_ref, ast_cond_init, ast_mutex_init, shutdown_data::in, shutdown_data::lock, NULL, shutdown_data::out, RAII_VAR, shutdown_data_dtor(), and shutdown_data::task_stop_waiting.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 654 of file test_taskprocessor.c.
References ast_cond_destroy, ast_mutex_destroy, shutdown_data::in, shutdown_data::lock, and shutdown_data::out.
Referenced by shutdown_data_create().
|
static |
Definition at line 711 of file test_taskprocessor.c.
References task_data::lock, shutdown_data::lock, SCOPED_MUTEX, and shutdown_data::task_complete.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 735 of file test_taskprocessor.c.
References ast_cond_signal, shutdown_data::in, task_data::lock, shutdown_data::lock, SCOPED_MUTEX, and shutdown_data::task_stop_waiting.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 679 of file test_taskprocessor.c.
References ast_cond_signal, ast_cond_wait, shutdown_data::in, task_data::lock, shutdown_data::lock, shutdown_data::out, SCOPED_MUTEX, shutdown_data::task_complete, shutdown_data::task_started, and shutdown_data::task_stop_waiting.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 693 of file test_taskprocessor.c.
References ast_cond_timedwait, ast_tvnow(), task_data::lock, shutdown_data::lock, shutdown_data::out, SCOPED_MUTEX, and shutdown_data::task_complete.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 717 of file test_taskprocessor.c.
References ast_cond_timedwait, ast_tvnow(), task_data::lock, shutdown_data::lock, shutdown_data::out, SCOPED_MUTEX, and shutdown_data::task_started.
Referenced by AST_TEST_DEFINE().
|
static |
Queued task for baseline test.
The task simply sets a boolean to indicate the task has been run and then signals a condition saying it's complete
Definition at line 88 of file test_taskprocessor.c.
References ast_cond_signal, task_data::cond, task_data::lock, SCOPED_MUTEX, task_data::task_complete, and task_data::wait_time.
Referenced by AST_TEST_DEFINE(), ast_threadpool_push(), local_task_exe(), tps_taskprocessor_dtor(), and tps_taskprocessor_pop().
|
static |
Create a task_data object.
Definition at line 64 of file test_taskprocessor.c.
References ao2_alloc, ast_cond_init, ast_mutex_init, task_data::cond, task_data::lock, NULL, task_data::task_complete, task_data_dtor(), and task_data::wait_time.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 55 of file test_taskprocessor.c.
References ast_cond_destroy, ast_mutex_destroy, task_data::cond, and task_data::lock.
Referenced by task_data_create().
|
static |
Wait for a task to execute.
Definition at line 104 of file test_taskprocessor.c.
References ast_cond_timedwait, ast_tvnow(), task_data::cond, task_data::lock, SCOPED_MUTEX, and task_data::task_complete.
Referenced by AST_TEST_DEFINE().
|
static |
test taskprocessor listener's emptied callback.
Definition at line 480 of file test_taskprocessor.c.
References ast_taskprocessor_listener_get_user_data(), and test_listener_pvt::num_emptied.
|
static |
test taskprocessor listener's alloc callback
Definition at line 447 of file test_taskprocessor.c.
References ast_calloc.
Referenced by AST_TEST_DEFINE().
|
static |
test taskprocessor listener's shutdown callback.
Definition at line 489 of file test_taskprocessor.c.
References ast_taskprocessor_listener_get_user_data(), and test_listener_pvt::shutdown.
|
static |
test taskprocessor listener's start callback
Definition at line 458 of file test_taskprocessor.c.
|
static |
test taskprocessor listener's task_pushed callback
Adjusts private data's stats as indicated by the parameters.
Definition at line 468 of file test_taskprocessor.c.
References ast_taskprocessor_listener_get_user_data(), test_listener_pvt::num_pushed, and test_listener_pvt::num_was_empty.
|
static |
Definition at line 742 of file test_taskprocessor.c.
References ast_taskprocessor_unreference(), and NULL.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 966 of file test_taskprocessor.c.
References ast_test_unregister().
|
static |
Definition at line 990 of file test_taskprocessor.c.
|
static |
Definition at line 990 of file test_taskprocessor.c.
|
static |
Referenced by AST_TEST_DEFINE(), and load_task().
|
static |
Definition at line 495 of file test_taskprocessor.c.