ubinos
stimertest02.c
/*
* Copyright (c) 2009 Sung Ho Park
*
* SPDX-License-Identifier: Apache-2.0
*/
#if (INCLUDE__UBINOS__UBIK_TEST == 1)
#if (1 != UBINOS__UBIK_TEST__EXCLUDE_STIMERTESTSET)
#include <stdio.h>
#include <stdlib.h>
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 stimertest02_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 sets stimer with oneshot option\n");
if (0 != r) {
printf("task 1: fail at stimer_set(), err=%d\n", r);
goto end0;
}
printf("task 1 starts stimer\n");
if (0 != r) {
printf("task 1: fail at stimer_start(), err=%d\n", r);
goto end0;
}
printf("task 1 waits a signal from stimer\n");
if (0 != r) {
printf("task 1: fail at sem_take(), err=%d\n", r);
goto end0;
}
printf("\n");
printf("task 1 receives a signal from stimer\n");
printf("task 1 wakes up\n");
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 1; i++) {
printf("1");
bsp_busywait(waitvalue);
}
printf("\n");
printf("task 1 waits a signal from stimer with timeout (for %d ms)\n", ubik_ticktotimems(waittick * 2));
r = sem_take_timed(_g_ubik_test_sem, waittick * 2);
if (UBIK_ERR__TIMEOUT != r) {
printf("task 1: fail at sem_take_timed(), err=%d\n", r);
goto end0;
}
printf("\n");
printf("task 1 wakes up\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 stimertest02_task2func(void * arg) {
int i;
unsigned int waitvalue = UBINOS__UBIK_TEST__TASKWAITTIMEMS * bsp_getbusywaitcountperms();
for (i=0; i<UBINOS__UBIK_TEST__TASKLOOPCOUNT * 6; i++) {
printf("2");
bsp_busywait(waitvalue);
}
printf("\n");
printf("task 2 ends\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("\n");
printf("<test>\n");
printf("<name>ubik_test_stimertest02</name>\n");
printf("<description>Oneshot stimer test</description>\n");
printf("<message>\n");
if (0 != r) {
printf("fail at stimer_create(), err=%d\n", r);
r = -1;
goto end0;
}
if (0 != r) {
printf("fail at semb_create(), err=%d\n", r);
r = -1;
goto end1;
}
printf("create task 2\n");
r = task_create_noautodel(&_g_ubik_test_task_a[2-1], stimertest02_task2func, NULL, task_getpriority(NULL)-2, 0, "stimertest02 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 01: ");
if (count1 != _g_ubik_test_count1 || count2 == _g_ubik_test_count2) {
printf("fail\n");
r = -1;
goto end3;
}
printf("pass\n");
task_sleep(sleepvalue);
printf("\n");
printf("create task 1\n");
r = task_create_noautodel(&_g_ubik_test_task_a[1-1], stimertest02_task1func, NULL, task_getpriority(NULL)-1, 0, "stimertest02 task 1");
if (0 != r) {
printf("fail at task_create_noautodel(), err=%d\n", r);
r = -1;
goto end3;
}
task_sleep(sleepvalue);
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) {
printf("fail\n");
r = -1;
goto end3;
}
printf("pass\n");
task_sleep(sleepvalue * 2);
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) {
printf("fail\n");
r = -1;
goto end3;
}
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) {
printf("fail\n");
r = -1;
goto end3;
}
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) {
printf("fail\n");
r = -1;
goto end3;
}
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) {
printf("fail\n");
r = -1;
goto end3;
}
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) {
printf("fail\n");
r = -1;
goto end3;
}
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) {
printf("fail\n");
r = -1;
goto end3;
}
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) {
printf("fail\n");
r = -1;
goto end3;
}
printf("pass\n");
r = 0;
end3:
if (0 != r2) {
printf("fail at task_join_and_delete(), err=%d\n", r2);
r = -1;
}
end2:
if (0 != r2) {
printf("fail at sem_delete(), err=%d\n", r2);
r = -1;
}
end1:
if (0 != r2) {
printf("fail at stimer_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 /* (1 != UBINOS__UBIK_TEST__EXCLUDE_STIMERTESTSET) */
#endif /* (INCLUDE__UBINOS__UBIK_TEST == 1) */
void bsp_busywait(unsigned int count)
unsigned int bsp_getbusywaitcountperms(void)
int semb_create(sem_pt *sem_p)
int sem_delete(sem_pt *sem_p)
int sem_take_timed(sem_pt sem, unsigned int tick)
int sem_take(sem_pt sem)
stdlib (Standard Library) API
int stimer_delete(stimer_pt *stimer_p)
int stimer_set(stimer_pt stimer, unsigned int tick, sem_pt sem, unsigned int option)
int stimer_create(stimer_pt *stimer_p)
#define STIMER_OPT__ONESHOT
Definition: stimer.h:146
int stimer_start(stimer_pt stimer)
Definition: sem.h:129
Definition: stimer.h:154
Definition: task.h:342
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
unsigned int ubik_ticktotimems(unsigned int tick)
#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
int ubik_test_stimertest02(void)
Test on oneshot notification function of semaphore timer.
stimer_pt _g_ubik_test_stimer
시험 용 세마포어 타이머
volatile unsigned int _g_ubik_test_result
시험 결과를 저장하는 전역 변수
sem_pt _g_ubik_test_sem
시험 용 세마포어