ubinos
msgqtest02.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_MSGQTESTSET == 1)
#include <stdio.h>
#include <stdlib.h>
static void msgqtest02_task1func(void * arg) {
int r;
int i;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
unsigned char msg[UBINOS__UBIK_TEST__MSGQSIZE];
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("Task 1 waits signal\r\n");
if (0 != r) {
printf("Task 1: fail at msgq_receive(), err=%d\r\n", r);
goto end0;
}
printf("Task 1 receives signal\r\n");
for (i=0; i<UBINOS__UBIK_TEST__MSGQSIZE; i++) {
if (i+0x00 != msg[i]) {
printf("Task 1: wrong message\r\n");
goto end0;
}
}
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 msgqtest02_task2func(void * arg) {
int i;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\r\n");
printf("Task 2 ends\r\n");
}
static void msgqtest02_task3func(void * arg) {
int r;
int i;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
unsigned char msg[UBINOS__UBIK_TEST__MSGQSIZE];
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 3); i++) {
printf("3");
bsp_busywait(waitvalue);
}
printf("\r\n");
for (i=0; i<UBINOS__UBIK_TEST__MSGQSIZE; i++) {
msg[i] = i+0x00;
}
printf("Task 3 sends signal\r\n");
if (0 != r) {
printf("Task 3: fail at msgq_send(), err=%d\r\n", r);
goto end0;
}
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("3");
bsp_busywait(waitvalue);
}
printf("\r\n");
end0:
printf("Task 3 ends\r\n");
}
int r;
int r2;
unsigned int count1;
unsigned int count2;
unsigned int count3;
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_msgqtest02</name>\r\n");
printf("<description>Priority inversion test of message queue</description>\n\r");
printf("<message>\n\r");
r = msgq_create(&_g_ubik_test_msgq, UBINOS__UBIK_TEST__MSGQSIZE, UBINOS__UBIK_TEST__MSGQMAXCOUNT);
if (0 != r) {
printf("fail at msgq_create(), err=%d\r\n", r);
r = -1;
goto end0;
}
printf("Task 3 begins\r\n");
r = task_create(&_g_ubik_test_task_a[3-1], msgqtest02_task3func, NULL, task_getpriority(NULL)-3, 0, "msgqtest02 task 3");
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 || count3 == _g_ubik_test_count3) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("Task 1 begins\r\n");
r = task_create(&_g_ubik_test_task_a[1-1], msgqtest02_task1func, NULL, task_getpriority(NULL)-1, 0, "msgqtest02 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 || count3 != _g_ubik_test_count3) {
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 || count3 == _g_ubik_test_count3) {
printf("fail\r\n");
r = -1;
goto end2;
}
printf("pass\r\n");
task_sleep(sleepvalue);
printf("\r\n");
printf("Task 2 begins\r\n");
r = task_create(&_g_ubik_test_task_a[2-1], msgqtest02_task2func, NULL, task_getpriority(NULL)-2, 0, "msgqtest02 task 2");
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 04: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2 || count3 != _g_ubik_test_count3) {
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 || count3 == _g_ubik_test_count3) {
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 || count3 != _g_ubik_test_count3) {
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 || count3 == _g_ubik_test_count3) {
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 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_MSGQTESTSET == 1) */
_g_ubik_test_task_a
task_pt _g_ubik_test_task_a[4]
시험 용 태스크 배열
task_join
int task_join(task_pt *task_p, int *result_p, int count)
_g_ubik_test_msgq
msgq_pt _g_ubik_test_msgq
시험 용 메시지큐
msgq_create
int msgq_create(msgq_pt *msgq_p, unsigned int msgsize, unsigned int maxcount)
_g_ubik_test_count2
volatile unsigned int _g_ubik_test_count2
태스크 별 시험 진행 상황을 저장하는 전역 변수 2
ubik_timemstotick
unsigned int ubik_timemstotick(unsigned int timems)
ubik_test_msgqtest02
int ubik_test_msgqtest02(void)
Test for priority inversion situation by message queue.
msgq_delete
int msgq_delete(msgq_pt *msgq_p)
ubik_test.h
ubik test API
bsp_getbusywaitcountperms
unsigned int bsp_getbusywaitcountperms(void)
bsp_busywait
void bsp_busywait(unsigned int count)
_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)
msgq_receive
int msgq_receive(msgq_pt msgq, unsigned char *msg)
_g_ubik_test_count3
volatile unsigned int _g_ubik_test_count3
태스크 별 시험 진행 상황을 저장하는 전역 변수 3
task_getpriority
int task_getpriority(task_pt task)
NULL
#define NULL
Definition: type.h:65
stdlib.h
stdlib (Standard Library) API
task_sleep
int task_sleep(unsigned int tick)