Asterisk - The Open Source Telephony Project
21.4.1
|
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. | |
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. | |
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 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.
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 ast_taskprocessor_get(), ast_taskprocessor_push(), ast_taskprocessor_unreference(), RAII_VAR, task(), task_data_create(), task_wait(), 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 352 of file test_taskprocessor.c.
References ast_taskprocessor_get(), ast_taskprocessor_push(), ast_taskprocessor_unreference(), ast_tvnow(), load_task_data::cond, load_task(), load_task_data::lock, load_task_data::task_rand, load_task_data::tasks_completed, 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 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 555 of file test_taskprocessor.c.
References ast_taskprocessor_create_with_listener(), ast_taskprocessor_execute(), ast_taskprocessor_listener_alloc(), ast_taskprocessor_push(), ast_taskprocessor_unreference(), check_stats(), listener_test_task(), and test_listener_pvt_alloc().
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 ast_taskprocessor_push(), RAII_VAR, task(), task_data_create(), task_wait(), 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.
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 |
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 load_task_data::cond, lock, load_task_data::lock, SCOPED_MUTEX, load_task_data::task_rand, and load_task_data::tasks_completed.
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 lock, SCOPED_MUTEX, task_data::task_complete, and task_data::wait_time.
Referenced by AST_TEST_DEFINE().
|
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().