[asterisk-commits] mmichelson: branch mmichelson/threadpool r376412 - /team/mmichelson/threadpoo...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Nov 17 15:55:45 CST 2012
Author: mmichelson
Date: Sat Nov 17 15:55:42 2012
New Revision: 376412
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376412
Log:
Add a second default taskprocessor test that executes 20000 tasks.
Modified:
team/mmichelson/threadpool/tests/test_taskprocessor.c
Modified: team/mmichelson/threadpool/tests/test_taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/tests/test_taskprocessor.c?view=diff&rev=376412&r1=376411&r2=376412
==============================================================================
--- team/mmichelson/threadpool/tests/test_taskprocessor.c (original)
+++ team/mmichelson/threadpool/tests/test_taskprocessor.c Sat Nov 17 15:55:42 2012
@@ -110,6 +110,71 @@
return res;
}
+AST_TEST_DEFINE(default_taskprocessor_load)
+{
+ static const int NUM_TASKS = 20000;
+ struct ast_taskprocessor *tps;
+ struct task_data task_data;
+ struct timeval start;
+ struct timespec ts;
+ enum ast_test_result_state res = AST_TEST_PASS;
+ int timedwait_res;
+ int i;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "default_taskprocessor_load";
+ info->category = "/main/taskprocessor/";
+ info->summary = "Load test of default taskproccesor";
+ info->description =
+ "Ensure that many queued tasks are executed.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ tps = ast_taskprocessor_get("test", TPS_REF_DEFAULT);
+
+ if (!tps) {
+ ast_test_status_update(test, "Unable to create test taskprocessor\n");
+ return AST_TEST_FAIL;
+ }
+
+ start = ast_tvnow();
+
+ ts.tv_sec = start.tv_sec + 60;
+ ts.tv_nsec = start.tv_usec * 1000;
+
+ ast_cond_init(&task_data.cond, NULL);
+ ast_mutex_init(&task_data.lock);
+ task_data.task_complete = 0;
+
+ for (i = 0; i < NUM_TASKS; ++i) {
+ ast_taskprocessor_push(tps, task, &task_data);
+ }
+
+ ast_mutex_lock(&task_data.lock);
+ while (task_data.task_complete < NUM_TASKS) {
+ timedwait_res = ast_cond_timedwait(&task_data.cond, &task_data.lock, &ts);
+ if (timedwait_res == ETIMEDOUT) {
+ break;
+ }
+ }
+
+ if (task_data.task_complete != NUM_TASKS) {
+ ast_test_status_update(test, "Unexpected number of tasks executed. Expected %d but got %d\n",
+ NUM_TASKS, task_data.task_complete);
+ res = AST_TEST_FAIL;
+ goto test_end;
+ }
+
+test_end:
+ tps = ast_taskprocessor_unreference(tps);
+ ast_mutex_destroy(&task_data.lock);
+ ast_cond_destroy(&task_data.cond);
+ return res;
+}
+
struct test_listener_pvt {
int num_pushed;
int num_emptied;
@@ -267,6 +332,7 @@
static int unload_module(void)
{
ast_test_unregister(default_taskprocessor);
+ ast_test_unregister(default_taskprocessor_load);
ast_test_unregister(taskprocessor_listener);
return 0;
}
@@ -274,6 +340,7 @@
static int load_module(void)
{
ast_test_register(default_taskprocessor);
+ ast_test_register(default_taskprocessor_load);
ast_test_register(taskprocessor_listener);
return AST_MODULE_LOAD_SUCCESS;
}
More information about the asterisk-commits
mailing list