ubinos
tasktest07.c
/*
Copyright (C) 2009 Sung Ho Park
Contact: ubinos.org@gmail.com
This file is part of the lib_ubik_test component of the Ubinos.
GNU General Public License Usage
This file may be used under the terms of the GNU
General Public License version 3.0 as published by the Free Software
Foundation and appearing in the file license_gpl3.txt included in the
packaging of this file. Please review the following information to
ensure the GNU General Public License version 3.0 requirements will be
met: http://www.gnu.org/copyleft/gpl.html.
GNU Lesser General Public License Usage
Alternatively, this file may be used under the terms of the GNU Lesser
General Public License version 2.1 as published by the Free Software
Foundation and appearing in the file license_lgpl.txt included in the
packaging of this file. Please review the following information to
ensure the GNU Lesser General Public License version 2.1 requirements
will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Commercial Usage
Alternatively, licensees holding valid commercial licenses may
use this file in accordance with the commercial license agreement
provided with the software or, alternatively, in accordance with the
terms contained in a written agreement between you and rightful owner.
*/
#if ( !(UBINOS__UBIK_TEST__EXCLUDE_TASKTESTSET3 == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_MUTEXTESTSET == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_SIGNALTESTSET == 1) && \
!(UBINOS__UBIK_TEST__EXCLUDE_CONDVTESTSET == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_SEMTESTSET == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_MSGQTESTSET == 1) )
#include <stdio.h>
#include <stdlib.h>
#define SIGOBJCOUNT 5
extern volatile unsigned int _g_ubik_test_result;
extern volatile unsigned int _g_ubik_test_count1;
extern volatile unsigned int _g_ubik_test_count2;
static void tasktest07_task1func(void * arg) {
int r;
int i;
int j;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
unsigned int waittick = ubik_timemstotick(UBINOS__UBIK_TEST__TASKWAITTIMEMS * UBINOS__UBIK_TEST__TASKLOOPCOUNT);
unsigned char msg[UBINOS__UBIK_TEST__MSGQSIZE];
void * sigobj_a[SIGOBJCOUNT];
int sigtype_a[SIGOBJCOUNT];
void * param_a[SIGOBJCOUNT];
sigobj_a[0] =_g_ubik_test_mutex;
sigobj_a[1] =_g_ubik_test_signal;
sigobj_a[2] =_g_ubik_test_condv;
sigobj_a[3] =_g_ubik_test_sem;
sigobj_a[4] =_g_ubik_test_msgq;
param_a[0] = NULL;
param_a[1] = NULL;
param_a[2] = (void *) _g_ubik_test_mutex2;
param_a[3] = NULL;
param_a[4] = (void *) msg;
r = task_setmaxwaitsigobj(NULL, SIGOBJCOUNT);
if (0 != r) {
printf("task 1: fail at task_setmaxwaitsigobj(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 1 waits for multiple signals (without all option)\r\n");
if (0 != r) {
printf("task 1: fail at mutex_lock(), err=%d\r\n", r);
goto end0;
}
r = task_waitforsigobjs(sigobj_a, sigtype_a, param_a, SIGOBJCOUNT, 0);
if (0 != r) {
printf("task 1: fail at task_waitforsigobjs(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 1: fail at mutex_unlock(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<SIGOBJCOUNT; i++) {
switch (i) {
case 0:
case 1:
case 2:
case 3:
case 5:
if (-1 != sigtype_a[i]) {
printf("task 1: sigtype_a[%d] value is wrong\r\n", i);
goto end0;
}
break;
case 4:
if (0 != sigtype_a[i]) {
printf("task 1: sigtype_a[%d] value is wrong\r\n", i);
goto end0;
}
for (j=0; j<UBINOS__UBIK_TEST__MSGQSIZE; j++) {
if (j != msg[j]) {
printf("task 1: received message is wrong\r\n");
goto end0;
}
}
break;
}
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 1 waits for multiple signals with all option\r\n");
if (0 != r) {
printf("task 1: fail at mutex_lock(), err=%d\r\n", r);
goto end0;
}
r = task_waitforsigobjs(sigobj_a, sigtype_a, param_a, SIGOBJCOUNT, TASK_WAITOPT__ALL);
if (0 != r) {
printf("task 1: fail at task_waitforsigobjs(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 1: fail at mutex_unlock(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<SIGOBJCOUNT; i++) {
switch (i) {
case 0:
case 1:
case 2:
case 3:
if (0 != sigtype_a[i]) {
printf("task 1: sigtype_a[%d] value is wrong\r\n", i);
goto end0;
}
break;
case 4:
if (0 != sigtype_a[i]) {
printf("task 1: sigtype_a[%d] value is wrong\r\n", i);
goto end0;
}
for (j=0; j<UBINOS__UBIK_TEST__MSGQSIZE; j++) {
if ((UBINOS__UBIK_TEST__MSGQSIZE - j) != msg[j]) {
printf("task 1: received message is wrong\r\n");
goto end0;
}
}
break;
}
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 1 unlocks mutex\r\n");
if (0 != r) {
printf("task 1: fail at mutex_unlock(), err=%d\r\n", r);
goto end0;
}
printf("task 1 tries to sleep (for %d ms)\r\n", ubik_ticktotimems(waittick));
task_sleep(waittick);
printf("\r\n");
printf("task 1 wakes up\r\n");
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 1 waits for multiple signals with all option and timeout (for %d ms)\r\n", ubik_ticktotimems(waittick * 2));
if (0 != r) {
printf("task 1: fail at mutex_lock(), err=%d\r\n", r);
goto end0;
}
r = task_waitforsigobjs_timed(sigobj_a, sigtype_a, param_a, SIGOBJCOUNT, TASK_WAITOPT__ALL, waittick * 2);
if (UBIK_ERR__TIMEOUT != r) {
printf("task 1: fail at task_waitforsigobjs(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 1: fail at mutex_unlock(), err=%d\r\n", r);
goto end0;
}
printf("\r\n");
printf("task 1 wakes up\r\n");
for (i=0; i<SIGOBJCOUNT; i++) {
switch (i) {
case 0:
case 1:
case 2:
case 4:
if (UBIK_ERR__TIMEOUT != sigtype_a[i]) {
printf("task 1: sigtype_a[%d] value is wrong\r\n", i);
goto end0;
}
break;
case 3:
if (0 != sigtype_a[i]) {
printf("task 1: sigtype_a[%d] value is wrong\r\n", i);
goto end0;
}
break;
}
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\r\n");
end0:
printf("task 1 ends\r\n");
}
static void tasktest07_task2func(void * arg) {
int r;
int i;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
unsigned char msg[UBINOS__UBIK_TEST__MSGQSIZE];
printf("task 2 locks mutex\r\n");
if (0 != r) {
printf("task 2: fail at mutex_lock(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 2; i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 2 sends one signal\r\n");
for (i=0; i<UBINOS__UBIK_TEST__MSGQSIZE; i++) {
msg[i] = i;
}
if (0 != r) {
printf("task 2: fail at msgq_send(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 2 sends one signal\r\n");
for (i=0; i<UBINOS__UBIK_TEST__MSGQSIZE; i++) {
msg[i] = UBINOS__UBIK_TEST__MSGQSIZE - i;
}
if (0 != r) {
printf("task 2: fail at msgq_send(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 2 sends all other signals\r\n");
if (0 != r) {
printf("task 2: fail at mutex_unlock(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 2: fail at signal_send(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 2: fail at mutex_lock(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 2: fail at condv_signal(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 2: fail at mutex_unlock(), err=%d\r\n", r);
goto end0;
}
if (0 != r) {
printf("task 2: fail at sem_give(), err=%d\r\n", r);
goto end0;
}
printf("task 2 locks mutex\r\n");
if (0 != r) {
printf("task 2: fail at mutex_lock(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 2; i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 2 sends one signal\r\n");
if (0 != r) {
printf("task 2: fail at sem_give(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 2; i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("task 2 unlocks mutex\r\n");
if (0 != r) {
printf("task 2: fail at mutex_unlock(), err=%d\r\n", r);
goto end0;
}
end0:
printf("task 2 ends\r\n");
}
int r;
int r2;
unsigned int count1;
unsigned int count2;
unsigned int sleepvalue = ubik_timemstotick(UBINOS__UBIK_TEST__TASKWAITTIMEMS) * UBINOS__UBIK_TEST__TASKLOOPCOUNT / 3;
printf("\r\n");
printf("<test>\r\n");
printf("<name>ubik_test_tasktest07</name>\r\n");
printf("<description>Test on wait for multiple signal objects function of task</description>\n\r");
printf("<message>\n\r");
if (0 != r) {
printf("fail at mutex_create(), err=%d\r\n", r);
r = -1;
goto end0;
}
if (0 != r) {
printf("fail at mutex_create(), err=%d\r\n", r);
r = -1;
goto end0;
}
if (0 != r) {
printf("fail at mutex_create(), err=%d\r\n", r);
r = -1;
goto end0;
}
if (0 != r) {
printf("fail at mutex_create(), err=%d\r\n", r);
r = -1;
goto end0;
}
if (0 != r) {
printf("fail at mutex_create(), err=%d\r\n", r);
r = -1;
goto end0;
}
r = msgq_create(&_g_ubik_test_msgq, UBINOS__UBIK_TEST__MSGQSIZE, UBINOS__UBIK_TEST__MSGQMAXCOUNT);
if (0 != r) {
printf("fail at mutex_create(), err=%d\r\n", r);
r = -1;
goto end0;
}
printf("create task 2\r\n");
r = task_create(&_g_ubik_test_task_a[2-1], tasktest07_task2func, NULL, task_getpriority(NULL)-2, 256, "tasktest07 task 2");
if (0 != r) {
printf("fail at task_create(), err=%d\r\n", r);
r = -1;
goto end1;
}
task_sleep(sleepvalue);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 01: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("create task 1\r\n");
r = task_create(&_g_ubik_test_task_a[1-1], tasktest07_task1func, NULL, task_getpriority(NULL)-1, 256, "tasktest07 task 1");
if (0 != r) {
printf("fail at task_create(), err=%d\r\n", r);
r = -1;
goto end2;
}
task_sleep(sleepvalue);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 02: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 03: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 04: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 05: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 06: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 07: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 08: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 09: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 10: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 11: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 12: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue * 2);
printf("\r\n");
printf("checking\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("check point 13: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
r = 0;
end2:
if (0 != r2) {
printf("fail at task_join(), err=%d\r\n", r2);
r = -1;
}
end1:
if (0 != r2) {
printf("fail at mutex_delete(), err=%d\r\n", r2);
r = -1;
}
}
if (0 != r2) {
printf("fail at mutex_delete(), err=%d\r\n", r2);
r = -1;
}
}
if (0 != r2) {
printf("fail at signal_delete(), err=%d\r\n", r2);
r = -1;
}
}
if (0 != r2) {
printf("fail at condv_delete(), err=%d\r\n", r2);
r = -1;
}
}
if (0 != r2) {
printf("fail at sem_delete(), err=%d\r\n", r2);
r = -1;
}
}
if (0 != r2) {
printf("fail at msgq_delete(), err=%d\r\n", r2);
r = -1;
}
}
end0:
if (0 != r || 0 > _g_ubik_test_result) {
r = -1;
}
else {
r = 0;
}
printf("</message>\n\r");
printf("<result>");
if (0 == r) {
printf("pass");
}
else {
printf("fail");
}
printf("</result>\r\n");
printf("</test>\r\n");
printf("\r\n");
return r;
}
#endif /* ( !(UBINOS__UBIK_TEST__EXCLUDE_TASKTESTSET3 == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_MUTEXTESTSET == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_SIGNALTESTSET == 1) &&
!(UBINOS__UBIK_TEST__EXCLUDE_CONDVTESTSET == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_SEMTESTSET == 1) && !(UBINOS__UBIK_TEST__EXCLUDE_MSGQTESTSET == 1) ) */
_g_ubik_test_task_a
task_pt _g_ubik_test_task_a[4]
시험 용 태스크 배열
mutex_unlock
int mutex_unlock(mutex_pt mutex)
sem_create
int sem_create(sem_pt *sem_p)
condv_delete
int condv_delete(condv_pt *condv_p)
task_join
int task_join(task_pt *task_p, int *result_p, int count)
mutex_lock
int mutex_lock(mutex_pt mutex)
UBIK_ERR__TIMEOUT
#define UBIK_ERR__TIMEOUT
Definition: ubik.h:55
_g_ubik_test_msgq
msgq_pt _g_ubik_test_msgq
시험 용 메시지큐
TASK_WAITOPT__ALL
#define TASK_WAITOPT__ALL
Definition: task.h:355
msgq_create
int msgq_create(msgq_pt *msgq_p, unsigned int msgsize, unsigned int maxcount)
signal_create
int signal_create(signal_pt *signal_p)
_g_ubik_test_count2
volatile unsigned int _g_ubik_test_count2
태스크 별 시험 진행 상황을 저장하는 전역 변수 2
task_waitforsigobjs
int task_waitforsigobjs(void **sigobj_p, int *sigtype_p, void **param_p, int count, unsigned int waitopt)
ubik_timemstotick
unsigned int ubik_timemstotick(unsigned int timems)
mutex_delete
int mutex_delete(mutex_pt *mutex_p)
msgq_delete
int msgq_delete(msgq_pt *msgq_p)
ubik_test.h
ubik test API
bsp_getbusywaitcountperms
unsigned int bsp_getbusywaitcountperms(void)
__task_tip_t
Definition: task.h:361
_g_ubik_test_mutex2
mutex_pt _g_ubik_test_mutex2
시험 용 뮤택스 2
signal_send
int signal_send(signal_pt signal, int sigtype)
__msgq_tip_t
Definition: msgq.h:150
bsp_busywait
void bsp_busywait(unsigned int count)
__mutex_tip_t
Definition: mutex.h:257
ubik_ticktotimems
unsigned int ubik_ticktotimems(unsigned int tick)
condv_create
int condv_create(condv_pt *condv_p)
_g_ubik_test_count1
volatile unsigned int _g_ubik_test_count1
태스크 별 시험 진행 상황을 저장하는 전역 변수 1
_g_ubik_test_result
volatile unsigned int _g_ubik_test_result
시험 결과를 저장하는 전역 변수
msgq_send
int msgq_send(msgq_pt msgq, unsigned char *msg)
task_create
int task_create(task_pt *task_p, taskfunc_ft func, void *arg, int priority, unsigned int stackdepth, const char *name)
_g_ubik_test_condv
condv_pt _g_ubik_test_condv
시험 용 상태변수
ubik_test_tasktest07
int ubik_test_tasktest07(void)
Test on wait for multiple signal objects function of task.
sem_delete
int sem_delete(sem_pt *sem_p)
signal_delete
int signal_delete(signal_pt *signal_p)
__condv_tip_t
Definition: condv.h:60
__sem_tip_t
Definition: sem.h:151
sem_give
int sem_give(sem_pt sem)
task_getpriority
int task_getpriority(task_pt task)
condv_signal
int condv_signal(condv_pt condv)
__signal_tip_t
Definition: signal.h:59
task_setmaxwaitsigobj
int task_setmaxwaitsigobj(task_pt task, int max)
NULL
#define NULL
Definition: type.h:65
mutex_create
int mutex_create(mutex_pt *mutex_p)
_g_ubik_test_signal
signal_pt _g_ubik_test_signal
시험 용 시그널
stdlib.h
stdlib (Standard Library) API
task_sleep
int task_sleep(unsigned int tick)
task_waitforsigobjs_timed
int task_waitforsigobjs_timed(void **sigobj_p, int *sigtype_p, void **param_p, int count, unsigned int waitopt, unsigned int tick)
_g_ubik_test_sem
sem_pt _g_ubik_test_sem
시험 용 세마포어
_g_ubik_test_mutex
mutex_pt _g_ubik_test_mutex
시험 용 뮤택스