2009-11-23 01:55:08 +01:00
|
|
|
/*
|
|
|
|
|
test-threadpool.c - test thread pool creation and usage
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Michael Ploujnikov <ploujj@gmail.com>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "tests/test.h"
|
|
|
|
|
|
|
|
|
|
#include "backend/threadpool.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
TESTS_BEGIN
|
|
|
|
|
|
|
|
|
|
|
2009-11-23 22:40:31 +01:00
|
|
|
TEST ("basic-acquire-release")
|
2009-11-23 01:55:08 +01:00
|
|
|
{
|
2009-11-24 01:05:57 +01:00
|
|
|
ECHO("start by initializing the threadpool");
|
2009-11-23 22:40:31 +01:00
|
|
|
lumiera_threadpool_init();
|
2009-11-24 01:05:57 +01:00
|
|
|
ECHO("acquiring thread 1");
|
2009-11-23 22:40:31 +01:00
|
|
|
LumieraThread t1 =
|
|
|
|
|
lumiera_threadpool_acquire_thread(LUMIERA_THREAD_INTERACTIVE,
|
|
|
|
|
"test purpose",
|
|
|
|
|
NULL);
|
2009-11-24 01:05:57 +01:00
|
|
|
ECHO("acquiring thread 2");
|
2009-11-23 22:40:31 +01:00
|
|
|
LumieraThread t2 =
|
|
|
|
|
lumiera_threadpool_acquire_thread(LUMIERA_THREAD_IDLE,
|
|
|
|
|
"test purpose",
|
|
|
|
|
NULL);
|
|
|
|
|
|
2009-11-24 01:05:57 +01:00
|
|
|
//ECHO("thread 1 kind=%d", t1->kind);
|
|
|
|
|
CHECK(LUMIERA_THREAD_INTERACTIVE == t1->kind);
|
|
|
|
|
//ECHO("thread 1 state=%d", t1->state);
|
|
|
|
|
CHECK(LUMIERA_THREADSTATE_IDLE == t1->state);
|
|
|
|
|
//ECHO("thread 2 kind=%d", t2->kind);
|
2009-11-24 01:47:20 +01:00
|
|
|
CHECK(LUMIERA_THREAD_IDLE == t2->kind);
|
2009-11-24 01:05:57 +01:00
|
|
|
//ECHO("thread 2 state=%d", t2->state);
|
|
|
|
|
CHECK(LUMIERA_THREADSTATE_IDLE == t2->state);
|
2009-11-23 22:40:31 +01:00
|
|
|
|
2009-11-24 01:05:57 +01:00
|
|
|
ECHO("releasing thread 1");
|
2009-11-23 22:40:31 +01:00
|
|
|
lumiera_threadpool_release_thread(t1);
|
2009-11-24 01:05:57 +01:00
|
|
|
ECHO("thread 1 has been released");
|
2009-11-23 22:40:31 +01:00
|
|
|
|
2009-11-24 01:05:57 +01:00
|
|
|
ECHO("releasing thread 2");
|
2009-11-23 22:40:31 +01:00
|
|
|
lumiera_threadpool_release_thread(t2);
|
2009-11-24 01:05:57 +01:00
|
|
|
ECHO("thread 2 has been released");
|
2009-11-25 04:25:00 +01:00
|
|
|
|
|
|
|
|
lumiera_threadpool_destroy();
|
2009-11-23 01:55:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TESTS_END
|