2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2012, Digium, Inc.
6 * Mark Michelson <mmichelson@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief taskprocessor unit tests
23 * \author Mark Michelson <mmichelson@digium.com>
28 <depend>TEST_FRAMEWORK</depend>
29 <support_level>core</support_level>
34 #include "asterisk/test.h"
35 #include "asterisk/taskprocessor.h"
36 #include "asterisk/module.h"
44 static int task(void *data)
46 struct task_data *task_data = data;
47 SCOPED_MUTEX(lock, &task_data->lock);
48 task_data->task_complete = 1;
49 ast_cond_signal(&task_data->cond);
53 AST_TEST_DEFINE(default_taskprocessor)
55 struct ast_taskprocessor *tps;
56 struct task_data task_data;
57 enum ast_test_result_state res = AST_TEST_PASS;
61 info->name = "default_taskprocessor";
62 info->category = "/main/taskprocessor/";
63 info->summary = "Test of default taskproccesor";
65 "Ensures that queued tasks are executed.";
66 return AST_TEST_NOT_RUN;
71 tps = ast_taskprocessor_get("test", TPS_REF_DEFAULT);
74 ast_test_status_update(test, "Unable to create test taskprocessor\n");
78 ast_cond_init(&task_data.cond, NULL);
79 ast_mutex_init(&task_data.lock);
80 task_data.task_complete = 0;
82 ast_taskprocessor_push(tps, task, &task_data);
83 ast_mutex_lock(&task_data.lock);
84 while (!task_data.task_complete) {
85 ast_cond_wait(&task_data.cond, &task_data.lock);
88 if (!task_data.task_complete) {
89 ast_test_status_update(test, "Queued task did not execute!\n");
95 tps = ast_taskprocessor_unreference(tps);
96 ast_mutex_destroy(&task_data.lock);
97 ast_cond_destroy(&task_data.cond);
101 static int unload_module(void)
103 ast_test_unregister(default_taskprocessor);
107 static int load_module(void)
109 ast_test_register(default_taskprocessor);
110 return AST_MODULE_LOAD_SUCCESS;
113 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "taskprocessor test module");