ubinos
signaltest01.c
/*
* Copyright (c) 2009 Sung Ho Park
*
* SPDX-License-Identifier: Apache-2.0
*/
#if (INCLUDE__UBINOS__UBIK_TEST == 1)
#if !(UBINOS__UBIK_TEST__EXCLUDE_SIGNALTESTSET == 1)
#include <stdio.h>
#include <stdlib.h>
static void signaltest01_task1func(void * arg) {
int r;
int i;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
unsigned int waittick = ubik_timemstotick(UBINOS__UBIK_TEST__TASKWAITTIMEMS * UBINOS__UBIK_TEST__TASKLOOPCOUNT);
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\n");
printf("Task 1 waits signal\n");
printf("Task 1: fail at signal_wait(), err=%d\n", r);
goto end0;
}
printf("Task 1 receives signal\n");
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\n");
printf("Task 1 waits signal\n");
printf("Task 1: fail at signal_wait(), err=%d\n", r);
goto end0;
}
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\n");
printf("Task 1 waits signal with timeout\n");
if (UBIK_ERR__TIMEOUT != r) {
printf("Task 1: fail at signal_wait_timed(), err=%d\n", r);
goto end0;
}
printf("\n");
printf("Task 1's timeout period expires\n");
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\n");
end0:
printf("Task 1 ends\n");
}
static void signaltest01_task2func(void * arg) {
int r;
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("\n");
printf("Task 2 waits signal\n");
printf("Task 2: fail at signal_wait(), err=%d\n", r);
goto end0;
}
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\n");
end0:
printf("Task 2 ends\n");
}
static void signaltest01_task3func(void * arg) {
int r;
int i;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("3");
bsp_busywait(waitvalue);
}
printf("\n");
printf("Task 3 sends signal with no waiters\n");
if (0 != r) {
printf("Task 3: fail at signal_send(), err=%d\n", r);
goto end0;
}
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 2); i++) {
printf("3");
bsp_busywait(waitvalue);
}
printf("\n");
printf("Task 3 sends signal\n");
if (0 != r) {
printf("Task 3: fail at signal_send(), err=%d\n", r);
goto end0;
}
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1); i++) {
printf("3");
bsp_busywait(waitvalue);
}
printf("\n");
printf("Task 3 broadcasts signal\n");
if (0 != r) {
printf("Task 3: fail at signal_broadcast(), err=%d\n", r);
goto end0;
}
for (i=0; i<(UBINOS__UBIK_TEST__TASKLOOPCOUNT * 2); i++) {
printf("3");
bsp_busywait(waitvalue);
}
printf("\n");
end0:
printf("Task 3 ends\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("\n");
printf("<test>\n");
printf("<name>ubik_test_signaltest01</name>\n");
printf("<description>Basic functional test of signal</description>\n");
printf("<message>\n");
if (0 != r) {
printf("fail at signal_create(), err=%d\n", r);
r = -1;
goto end0;
}
printf("Task 3 begins\n");
r = task_create_noautodel(&_g_ubik_test_task_a[3-1], signaltest01_task3func, NULL, task_getpriority(NULL)-3, 0, "signaltest01 task 3");
if (0 != r) {
printf("fail at task_create_noautodel(), err=%d\n", r);
r = -1;
goto end1;
}
task_sleep(sleepvalue);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 01: ");
if (count1 != _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 == _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 02: ");
if (count1 != _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 == _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue);
printf("\n");
printf("Task 1 begins\n");
r = task_create_noautodel(&_g_ubik_test_task_a[1-1], signaltest01_task1func, NULL, task_getpriority(NULL)-1, 0, "signaltest01 task 1");
if (0 != r) {
printf("fail at task_create_noautodel(), err=%d\n", r);
r = -1;
goto end2;
}
printf("Task 2 begins\n");
r = task_create_noautodel(&_g_ubik_test_task_a[2-1], signaltest01_task2func, NULL, task_getpriority(NULL)-2, 0, "signaltest01 task 2");
if (0 != r) {
printf("fail at task_create_noautodel(), err=%d\n", r);
r = -1;
goto end2;
}
task_sleep(sleepvalue);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 03: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 != _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 04: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2 || count3 != _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 05: ");
if (count1 != _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 == _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 06: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 != _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 07: ");
if (count1 != _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 == _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 08: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 != _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 09: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2 || count3 != _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 10: ");
if (count1 != _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 == _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 11: ");
if (count1 == _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 != _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
printf("\n");
printf("Checking\n");
task_sleep(sleepvalue);
printf("\n");
printf("Check point 12: ");
if (count1 != _g_ubik_test_count1 || count2 != _g_ubik_test_count2 || count3 == _g_ubik_test_count3) {
printf("fail\n");
r = -1;
goto end2;
}
printf("pass\n");
r = 0;
end2:
if (0 != r2) {
printf("fail at task_join_and_delete(), err=%d\n", r2);
r = -1;
}
end1:
if (0 != r2) {
printf("fail at signal_delete(), err=%d\n", r2);
r = -1;
}
end0:
if (0 != r || 0 > _g_ubik_test_result) {
r = -1;
}
else {
r = 0;
}
printf("</message>\n");
printf("<result>");
if (0 == r) {
printf("pass");
}
else {
printf("fail");
}
printf("</result>\n");
printf("</test>\n");
printf("\n");
return r;
}
#endif /* !(UBINOS__UBIK_TEST__EXCLUDE_SIGNALTESTSET == 1) */
#endif /* (INCLUDE__UBINOS__UBIK_TEST == 1) */
void bsp_busywait(unsigned int count)
unsigned int bsp_getbusywaitcountperms(void)
int signal_wait_timed(signal_pt signal, unsigned int tick)
int signal_send(signal_pt signal, int sigtype)
int signal_delete(signal_pt *signal_p)
int signal_wait(signal_pt signal)
int signal_broadcast(signal_pt signal, int sigtype)
int signal_create(signal_pt *signal_p)
stdlib (Standard Library) API
int task_create_noautodel(task_pt *task_p, taskfunc_ft func, void *arg, int priority, unsigned int stackdepth, const char *name)
int task_join_and_delete(task_pt *task_p, int *result_p, int count)
int task_sleep(unsigned int tick)
int task_getpriority(task_pt task)
#define NULL
Definition: type.h:42
#define UBIK_ERR__TIMEOUT
Definition: ubik.h:32
unsigned int ubik_timemstotick(unsigned int timems)
ubik test API
volatile unsigned int _g_ubik_test_count1
태스크 별 시험 진행 상황을 저장하는 전역 변수 1
task_pt _g_ubik_test_task_a[4]
시험 용 태스크 배열
volatile unsigned int _g_ubik_test_count2
태스크 별 시험 진행 상황을 저장하는 전역 변수 2
signal_pt _g_ubik_test_signal
시험 용 시그널
int ubik_test_signaltest01(void)
Test on basic functions of signal.
volatile unsigned int _g_ubik_test_count3
태스크 별 시험 진행 상황을 저장하는 전역 변수 3
volatile unsigned int _g_ubik_test_result
시험 결과를 저장하는 전역 변수
#define UBINOS__UBIK_TEST__SIGTYPE
Definition: ubik_test.h:23