|
Asterisk - The Open Source Telephony Project GIT-master-20e40a9
|
taskprocessor unit tests More...
#include "asterisk.h"#include <unistd.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"#include "asterisk/cli.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. | |
| AST_TEST_DEFINE (default_taskprocessor_load) | |
| Load test for taskprocessor with default listener. | |
| AST_TEST_DEFINE (serializer_pool) | |
| Baseline test for a serializer pool. | |
| AST_TEST_DEFINE (subsystem_alert) | |
| Baseline test for subsystem alert. | |
| AST_TEST_DEFINE (taskprocessor_cli_show) | |
| Test for CLI command "core show taskprocessor <name>". | |
| AST_TEST_DEFINE (taskprocessor_listener) | |
| Test for a taskprocessor with custom listener. | |
| AST_TEST_DEFINE (taskprocessor_push_local) | |
| AST_TEST_DEFINE (taskprocessor_shutdown) | |
| 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 | |
| static int | listener_test_task (void *ignore) |
| Queued task for taskprocessor listener test. | |
| static int | load_module (void) |
| static int | load_task (void *data) |
| a queued task to be used in the taskprocessor load test | |
| 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. | |
| static struct task_data * | task_data_create (void) |
| Create a task_data object. | |
| static void | task_data_dtor (void *obj) |
| static int | task_wait (struct task_data *task_data) |
| Wait for a task to execute. | |
| static void | test_emptied (struct ast_taskprocessor_listener *listener) |
| test taskprocessor listener's emptied callback. | |
| static void * | test_listener_pvt_alloc (void) |
| test taskprocessor listener's alloc callback | |
| static void | test_shutdown (struct ast_taskprocessor_listener *listener) |
| test taskprocessor listener's shutdown callback. | |
| static int | test_start (struct ast_taskprocessor_listener *listener) |
| test taskprocessor listener's start callback | |
| static void | test_task_pushed (struct ast_taskprocessor_listener *listener, int was_empty) |
| test taskprocessor listener's task_pushed callback | |
| 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 = ASTERISK_GPL_KEY , .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 |
| #define LOW_WATER_MARK 3 |
| #define NUM_TASKS 20000 |
Definition at line 317 of file test_taskprocessor.c.
| #define TEST_DATA_ARRAY_SIZE 10 |
|
static |
Definition at line 1159 of file test_taskprocessor.c.
|
static |
Definition at line 1159 of file test_taskprocessor.c.
| struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1159 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 135 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, NULL, RAII_VAR, task(), task_data_create(), task_wait(), TEST_EXECUTE, TEST_INIT, and TPS_REF_DEFAULT.
| 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 355 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, 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 | ( | 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 904 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(), NULL, options, RAII_VAR, task(), task_data_create(), task_wait(), TEST_EXECUTE, TEST_INIT, and task_data::wait_time.
| AST_TEST_DEFINE | ( | subsystem_alert | ) |
Baseline test for subsystem alert.
Definition at line 183 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, 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 | ( | taskprocessor_cli_show | ) |
Test for CLI command "core show taskprocessor <name>".
This test creates a taskprocessor, queues tasks with controlled execution, and verifies that the CLI command displays the queued tasks correctly.
Definition at line 975 of file test_taskprocessor.c.
References ao2_cleanup, ast_cli_command, ast_taskprocessor_get(), ast_taskprocessor_push, ast_taskprocessor_unreference(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, cleanup(), NULL, RAII_VAR, task(), task_data_create(), task_wait(), TEST_EXECUTE, TEST_INIT, TPS_REF_DEFAULT, and task_data::wait_time.
| 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 tasks, 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 558 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(), listener(), listener_test_task(), NULL, test_listener_pvt::shutdown, test_callbacks, TEST_EXECUTE, TEST_INIT, and test_listener_pvt_alloc().
| AST_TEST_DEFINE | ( | taskprocessor_push_local | ) |
Definition at line 840 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, local_task_exe(), NULL, RAII_VAR, task_data_create(), task_wait(), TEST_EXECUTE, TEST_INIT, and TPS_REF_DEFAULT.
| AST_TEST_DEFINE | ( | taskprocessor_shutdown | ) |
Definition at line 752 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, 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().
|
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 526 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 510 of file test_taskprocessor.c.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 1146 of file test_taskprocessor.c.
References AST_MODULE_LOAD_SUCCESS.
|
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 339 of file test_taskprocessor.c.
References ast_cond_signal, load_task_data::cond, load_task_results, 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 829 of file test_taskprocessor.c.
References ast_taskprocessor_local::data, ast_taskprocessor_local::local_data, ast_taskprocessor::local_data, and task().
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 665 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 657 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 714 of file test_taskprocessor.c.
References lock, shutdown_data::lock, SCOPED_MUTEX, and shutdown_data::task_complete.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 738 of file test_taskprocessor.c.
References ast_cond_signal, shutdown_data::in, lock, shutdown_data::lock, SCOPED_MUTEX, and shutdown_data::task_stop_waiting.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 682 of file test_taskprocessor.c.
References ast_cond_signal, ast_cond_wait, shutdown_data::in, 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 696 of file test_taskprocessor.c.
References ast_cond_timedwait, ast_tvnow(), end, lock, shutdown_data::lock, shutdown_data::out, SCOPED_MUTEX, and shutdown_data::task_complete.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 720 of file test_taskprocessor.c.
References ast_cond_timedwait, ast_tvnow(), end, 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 91 of file test_taskprocessor.c.
References ast_cond_signal, task_data::cond, lock, task_data::lock, SCOPED_MUTEX, task_data::task_complete, and task_data::wait_time.
Referenced by __ast_taskpool_push(), __ast_taskpool_push_wait(), __ast_threadpool_push(), ast_taskpool_push(), ast_taskpool_push_wait(), ast_taskpool_serializer_push_wait(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), ast_threadpool_push(), cli_tps_show_taskprocessor(), local_task_exe(), sched_free(), taskpool_sync_task_init(), tps_task_free(), tps_taskprocessor_dtor(), and tps_taskprocessor_pop().
|
static |
Create a task_data object.
Definition at line 67 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(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and AST_TEST_DEFINE().
|
static |
Definition at line 58 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 107 of file test_taskprocessor.c.
References ast_cond_timedwait, ast_tvnow(), task_data::cond, end, lock, task_data::lock, SCOPED_MUTEX, and task_data::task_complete.
Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and AST_TEST_DEFINE().
|
static |
test taskprocessor listener's emptied callback.
Definition at line 483 of file test_taskprocessor.c.
References ast_taskprocessor_listener_get_user_data(), listener(), and test_listener_pvt::num_emptied.
|
static |
test taskprocessor listener's alloc callback
Definition at line 450 of file test_taskprocessor.c.
References ast_calloc.
Referenced by AST_TEST_DEFINE().
|
static |
test taskprocessor listener's shutdown callback.
Definition at line 492 of file test_taskprocessor.c.
References ast_taskprocessor_listener_get_user_data(), listener(), and test_listener_pvt::shutdown.
|
static |
test taskprocessor listener's start callback
Definition at line 461 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 471 of file test_taskprocessor.c.
References ast_taskprocessor_listener_get_user_data(), listener(), test_listener_pvt::num_pushed, and test_listener_pvt::num_was_empty.
|
static |
Definition at line 745 of file test_taskprocessor.c.
References ast_taskprocessor_unreference(), and NULL.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 1133 of file test_taskprocessor.c.
|
static |
Definition at line 1159 of file test_taskprocessor.c.
|
static |
Definition at line 1159 of file test_taskprocessor.c.
|
static |
Referenced by AST_TEST_DEFINE(), and load_task().
|
static |
Definition at line 498 of file test_taskprocessor.c.
Referenced by AST_TEST_DEFINE().