mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-13 21:45:38 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
96
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_del.c
Normal file
96
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_del.c
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "buf_queue_test.h"
|
||||
|
||||
#define TEST_BUFQUEUE_MSG0_SIZE 8
|
||||
#define TEST_BUFQUEUE_BUF0_SIZE 16
|
||||
#define TEST_BUFQUEUE_MSG_MAX 8
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static char g_test_recv_msg0[TEST_BUFQUEUE_MSG0_SIZE];
|
||||
static char g_test_bufqueue_buf0[TEST_BUFQUEUE_MSG0_SIZE];
|
||||
static kbuf_queue_t g_test_bufqueue0;
|
||||
|
||||
static void buf_queue_create_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_buf_queue_create(NULL, "test_bufqueue0", g_test_bufqueue_buf0,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, NULL, g_test_bufqueue_buf0,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0", NULL,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
g_test_bufqueue_buf0,
|
||||
0, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_SIZE_ZERO);
|
||||
}
|
||||
|
||||
static void buf_queue_del_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_buf_queue_del(NULL);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(& sem, "test_sem ", 0);
|
||||
ret = krhino_buf_queue_del((kbuf_queue_t *)&sem);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
|
||||
ret = krhino_buf_queue_dyn_del(&g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_DEL_ERR);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
size_t size;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
(void **)&g_test_bufqueue_buf0,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check krhino_buf_queue_create param */
|
||||
buf_queue_create_param_test();
|
||||
|
||||
/* check krhino_buf_queue_del param */
|
||||
buf_queue_del_param_test();
|
||||
|
||||
ret = krhino_buf_queue_del(&g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
next_test_case_notify();
|
||||
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_buf_queue_del_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
test_case_check_err = 0;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_bufqueue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
BUFQUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "buf_queue_test.h"
|
||||
|
||||
#define TEST_BUFQUEUE_MSG_MAX 4
|
||||
#define TEST_BUFQUEUE_MAX_NUM 10
|
||||
#define TEST_BUFQUEUE_SIZE 100
|
||||
#define TEST_BUFQUEUE_MSG0_SIZE 10
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktask_t *task_1_test;
|
||||
static kbuf_queue_t *g_test_bufqueue0;
|
||||
static char g_test_recv_msg0[TEST_BUFQUEUE_MSG0_SIZE];
|
||||
|
||||
static void queue_dyn_create_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_buf_queue_dyn_create(NULL, "test_bufqueue0", 0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_dyn_create(&g_test_bufqueue0, NULL, 4,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_dyn_create(&g_test_bufqueue0, NULL, 0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_SIZE_ZERO);
|
||||
}
|
||||
|
||||
static void queue_dyn_del_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
ret = krhino_buf_queue_dyn_del(NULL);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_dyn_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
100, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_del(g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
ret = krhino_buf_queue_dyn_del(g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
|
||||
krhino_sem_create(& sem, "test_sem ", 0);
|
||||
ret = krhino_buf_queue_dyn_del((kbuf_queue_t *)&sem);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
int i;
|
||||
size_t size;
|
||||
kstat_t ret = 0;
|
||||
|
||||
while (1) {
|
||||
/* check krhino_buf_queue_dyn_create param */
|
||||
queue_dyn_create_param_test();
|
||||
|
||||
/* check krhino_buf_queue_del param */
|
||||
queue_dyn_del_param_test();
|
||||
|
||||
for (i = 1; i < TEST_BUFQUEUE_MAX_NUM; i++) {
|
||||
ret = krhino_buf_queue_dyn_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
i * 8, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_dyn_del(g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
ret = krhino_buf_queue_dyn_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
TEST_BUFQUEUE_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_recv(g_test_bufqueue0, RHINO_WAIT_FOREVER,
|
||||
g_test_recv_msg0, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BLK_DEL);
|
||||
|
||||
ret = krhino_buf_queue_dyn_del(g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_queue1_entry(void *arg)
|
||||
{
|
||||
if (test_case_check_err == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("buf queue dyn create&del", PASS);
|
||||
} else {
|
||||
test_case_check_err = 0;
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("buf queue dyn create&del", FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_1_test);
|
||||
}
|
||||
|
||||
kstat_t task_buf_queue_dyn_create_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_bufqueue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_1_test, "task_bufqueue0_test", 0, 11,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue1_entry, 1);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "buf_queue_test.h"
|
||||
|
||||
#define TEST_BUFQUEUE_MSG0_SIZE 8
|
||||
#define TEST_BUFQUEUE_BUF0_SIZE 16
|
||||
#define TEST_BUFQUEUE_MSG_MAX 8
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static char g_test_send_msg0[TEST_BUFQUEUE_MSG0_SIZE] = {0};
|
||||
static char g_test_bufqueue_buf0[TEST_BUFQUEUE_MSG0_SIZE] = {0};
|
||||
static kbuf_queue_t g_test_bufqueue0;
|
||||
|
||||
static void buf_queue_flush_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_buf_queue_flush(NULL);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(& sem, "test_sem ", 0);
|
||||
ret = krhino_buf_queue_flush((kbuf_queue_t *)&sem);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
g_test_bufqueue_buf0,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check krhino_buf_queue_flush param */
|
||||
buf_queue_flush_param_test();
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_FULL);
|
||||
|
||||
ret = krhino_buf_queue_flush(&g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_del(&g_test_bufqueue0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
if (test_case_check_err == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("buf queue flush", PASS);
|
||||
} else {
|
||||
test_case_check_err = 0;
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("buf queue flush", FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_buf_queue_flush_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_bufqueue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
BUFQUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "buf_queue_test.h"
|
||||
|
||||
#define TEST_BUFQUEUE_MSG0_SIZE 8
|
||||
#define TEST_BUFQUEUE_BUF0_SIZE 16
|
||||
#define TEST_BUFQUEUE_MSG_MAX 8
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static char g_test_send_msg0[TEST_BUFQUEUE_MSG0_SIZE];
|
||||
static char g_test_bufqueue_buf0[TEST_BUFQUEUE_MSG0_SIZE];
|
||||
static kbuf_queue_t g_test_bufqueue0;
|
||||
|
||||
static void buf_queue_info_get_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
kbuf_queue_info_t info;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_buf_queue_info_get(NULL, &info);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_info_get(&g_test_bufqueue0, NULL);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(& sem, "test_sem ", 0);
|
||||
ret = krhino_buf_queue_info_get((kbuf_queue_t *)&sem, &info);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
kbuf_queue_info_t info;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
g_test_bufqueue_buf0,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check krhino_buf_queue_info_get param */
|
||||
buf_queue_info_get_param_test();
|
||||
|
||||
ret = krhino_buf_queue_info_get(&g_test_bufqueue0, &info);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
BUFQUEUE_VAL_CHK((info.free_buf_size == TEST_BUFQUEUE_BUF0_SIZE) &&
|
||||
(info.buf_size == TEST_BUFQUEUE_BUF0_SIZE));
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
|
||||
ret = krhino_buf_queue_info_get(&g_test_bufqueue0, &info);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
BUFQUEUE_VAL_CHK(info.free_buf_size == (TEST_BUFQUEUE_BUF0_SIZE -
|
||||
TEST_BUFQUEUE_MSG0_SIZE - 1) &&
|
||||
(info.buf_size == TEST_BUFQUEUE_BUF0_SIZE));
|
||||
|
||||
if (test_case_check_err == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("buf queue info get", PASS);
|
||||
} else {
|
||||
test_case_check_err = 0;
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("buf queue info get", FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_buf_queue_info_get_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_bufqueue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
BUFQUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
281
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_recv.c
Normal file
281
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_recv.c
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "buf_queue_test.h"
|
||||
|
||||
#define TEST_BUFQUEUE_MSG0_SIZE TEST_BUFQUEUE_MSG_MAX+1u
|
||||
#define TEST_BUFQUEUE_BUF0_ERR_SIZE 43
|
||||
#define TEST_BUFQUEUE_BUF0_SIZE 48
|
||||
#define TEST_BUFQUEUE_MSG_NUM 3
|
||||
#define TEST_BUFQUEUE_MSG_MAX (TEST_BUFQUEUE_BUF0_SIZE/TEST_BUFQUEUE_MSG_NUM)-sizeof(size_t)
|
||||
/* four char here */
|
||||
static char send_char[TEST_BUFQUEUE_MSG_NUM + 1] = "aos";
|
||||
|
||||
#define TEST_BUFQUEUE_RCV_TASK_RPI 10
|
||||
#define TEST_BUFQUEUE_SND_TASK_HIGH_RPI 9
|
||||
#define TEST_BUFQUEUE_SND_TASK_LOW_RPI 11
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktask_t *task_1_test;
|
||||
static ktask_t *task_2_test;
|
||||
static char g_test_send_msg0[TEST_BUFQUEUE_MSG0_SIZE] = {0};
|
||||
static char g_test_send_msg1[TEST_BUFQUEUE_MSG0_SIZE] = {0};
|
||||
static char g_test_recv_msg0[TEST_BUFQUEUE_MSG0_SIZE] = {0};
|
||||
static char g_test_bufqueue_buf0[TEST_BUFQUEUE_BUF0_SIZE] = {0};
|
||||
static size_t g_test_bufqueue_buf1[2] = {0};
|
||||
|
||||
static kbuf_queue_t g_test_bufqueue0;
|
||||
static kbuf_queue_t g_test_bufqueue1;
|
||||
|
||||
static void buf_queue_recv_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
size_t size;
|
||||
ksem_t sem;
|
||||
|
||||
memset(&sem, 0, sizeof(ksem_t));
|
||||
|
||||
ret = krhino_buf_queue_recv(NULL, RHINO_WAIT_FOREVER, &g_test_recv_msg0, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER, NULL, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER,
|
||||
&g_test_recv_msg0, NULL);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(& sem, "test_sem ", 0);
|
||||
ret = krhino_buf_queue_recv((kbuf_queue_t *)&sem, RHINO_WAIT_FOREVER,
|
||||
&g_test_recv_msg0, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void buf_queue_send_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
memset(&sem, 0, sizeof(ksem_t));
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, NULL, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
|
||||
ret = krhino_buf_queue_send(NULL, g_test_send_msg0, TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX + 1);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_MSG_SIZE_OVERFLOW);
|
||||
|
||||
|
||||
ret = krhino_sem_create(&sem, "test_sem ", 0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
g_test_bufqueue0.blk_obj.obj_type = RHINO_OBJ_TYPE_NONE;
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
g_test_bufqueue0.blk_obj.obj_type = RHINO_BUF_QUEUE_OBJ_TYPE;
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
ret = krhino_buf_queue_send((kbuf_queue_t *)&sem, g_test_send_msg0, 0);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
|
||||
static void task_queue1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
kbuf_queue_info_t info;
|
||||
|
||||
while (1) {
|
||||
memset(g_test_send_msg0, 'y', TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(g_test_send_msg0, 'o', TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(g_test_send_msg0, 's', TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
krhino_task_dyn_del(task_1_test);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_queue2_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
kbuf_queue_info_t info;
|
||||
size_t count = 0;
|
||||
|
||||
while (1) {
|
||||
|
||||
memset(g_test_send_msg1, 's', TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg1,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
count++;
|
||||
|
||||
memset(g_test_send_msg1, 'o', TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg1,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
count++;
|
||||
|
||||
|
||||
memset(g_test_send_msg1, 'y', TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg1,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
count++;
|
||||
|
||||
|
||||
memset(g_test_send_msg1, 'w', TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg1,
|
||||
TEST_BUFQUEUE_MSG_MAX);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_FULL);
|
||||
|
||||
krhino_buf_queue_info_get(&g_test_bufqueue0, &info);
|
||||
|
||||
BUFQUEUE_VAL_CHK(count == info.cur_num);
|
||||
krhino_task_dyn_del(task_2_test);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
size_t size;
|
||||
int count = 0;
|
||||
size_t msg;
|
||||
|
||||
/* err param test */
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
(void *)g_test_bufqueue_buf0,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, 0);
|
||||
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
|
||||
(void *)g_test_bufqueue_buf0,
|
||||
TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
|
||||
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_fix_buf_queue_create(&g_test_bufqueue1, "test_bufqueue1",
|
||||
(void *)g_test_bufqueue_buf1, sizeof(size_t), 2);
|
||||
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
msg = 0x11;
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t));
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t));
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t));
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_FULL);
|
||||
|
||||
krhino_buf_queue_recv(&g_test_bufqueue1, RHINO_NO_WAIT, &msg, &size);
|
||||
krhino_buf_queue_recv(&g_test_bufqueue1, RHINO_NO_WAIT, &msg, &size);
|
||||
|
||||
ret = krhino_buf_queue_recv(&g_test_bufqueue1, 1, &msg, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_BLK_TIMEOUT);
|
||||
|
||||
/* check krhino_buf_queue_recv */
|
||||
buf_queue_recv_param_test();
|
||||
|
||||
buf_queue_send_param_test();
|
||||
|
||||
/* check RHINO_NO_WAIT */
|
||||
ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_NO_WAIT, &g_test_recv_msg0,
|
||||
&size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_NO_PEND_WAIT);
|
||||
|
||||
/* check sched disalbe */
|
||||
ret = krhino_sched_disable();
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER,
|
||||
&g_test_recv_msg0, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SCHED_DISABLE);
|
||||
ret = krhino_sched_enable();
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_1_test, "task_bufqueue1_test", 0,
|
||||
TEST_BUFQUEUE_SND_TASK_LOW_RPI,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue1_entry, 1);
|
||||
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
do {
|
||||
ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER,
|
||||
g_test_recv_msg0, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(g_test_send_msg0, send_char[count], TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = memcmp(g_test_send_msg0, g_test_recv_msg0, size);
|
||||
count ++;
|
||||
} while (count < TEST_BUFQUEUE_MSG_NUM);
|
||||
|
||||
|
||||
ret = krhino_task_dyn_create(&task_2_test, "task_bufqueue2_test", 0,
|
||||
TEST_BUFQUEUE_SND_TASK_HIGH_RPI,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue2_entry, 1);
|
||||
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND / 10);
|
||||
|
||||
count = 0;
|
||||
|
||||
do {
|
||||
ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER,
|
||||
g_test_recv_msg0, &size);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(g_test_send_msg1, send_char[count], TEST_BUFQUEUE_MSG_MAX);
|
||||
ret = memcmp(g_test_send_msg1, g_test_recv_msg0, size);
|
||||
count ++;
|
||||
} while (count < TEST_BUFQUEUE_MSG_NUM);
|
||||
|
||||
|
||||
if (test_case_check_err == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("buf queue recv", PASS);
|
||||
} else {
|
||||
test_case_check_err = 0;
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("buf queue recv", FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
|
||||
kstat_t task_buf_queue_recv_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
test_case_check_err = 0;
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_bufqueue0_test", 0,
|
||||
TEST_BUFQUEUE_RCV_TASK_RPI,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
28
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_test.c
Normal file
28
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_test.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "buf_queue_test.h"
|
||||
|
||||
void buf_queue_test(void)
|
||||
{
|
||||
task_buf_queue_recv_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_buf_queue_del_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_buf_queue_flush_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_buf_queue_info_get_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_buf_queue_dyn_create_test();
|
||||
next_test_case_wait();
|
||||
|
||||
}
|
||||
|
||||
27
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_test.h
Normal file
27
Living_SDK/kernel/rhino/test/core/buf_queue/buf_queue_test.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef BUF_QUEUE_TEST_H
|
||||
#define BUF_QUEUE_TEST_H
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 256
|
||||
|
||||
#define BUFQUEUE_VAL_CHK(value) do {if ((int)(value) == 0) \
|
||||
{ \
|
||||
test_case_critical_enter(); \
|
||||
test_case_check_err++; \
|
||||
test_case_critical_exit(); \
|
||||
printf("buf queue test is [FAIL %d],file %s, func %s, line %d\n", \
|
||||
(int)++test_case_check_err, __FILE__, __FUNCTION__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
kstat_t task_buf_queue_send_test(void);
|
||||
kstat_t task_buf_queue_recv_test(void);
|
||||
kstat_t task_buf_queue_del_test(void);
|
||||
kstat_t task_buf_queue_flush_test(void);
|
||||
kstat_t task_buf_queue_info_get_test(void);
|
||||
kstat_t task_buf_queue_dyn_create_test(void);
|
||||
|
||||
#endif /* BUF_QUEUE_TEST_H */
|
||||
23
Living_SDK/kernel/rhino/test/core/combination/comb_test.c
Executable file
23
Living_SDK/kernel/rhino/test/core/combination/comb_test.c
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "comb_test.h"
|
||||
|
||||
static const test_case_t comb_case_runner[] = {
|
||||
sem_event_coopr_test,
|
||||
sem_buf_queue_coopr_test,
|
||||
sem_mutex_coopr_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void comb_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)comb_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
18
Living_SDK/kernel/rhino/test/core/combination/comb_test.h
Executable file
18
Living_SDK/kernel/rhino/test/core/combination/comb_test.h
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef COMB_TEST_H
|
||||
#define COMB_TEST_H
|
||||
|
||||
#define TASK_COMB_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 256
|
||||
|
||||
void comb_test(void);
|
||||
void sem_queue_coopr_test(void);
|
||||
void sem_event_coopr_test(void);
|
||||
void sem_buf_queue_coopr_test(void);
|
||||
void sem_mutex_coopr_test(void);
|
||||
|
||||
#endif /* SEM_TEST_H */
|
||||
|
||||
90
Living_SDK/kernel/rhino/test/core/combination/sem_event.c
Normal file
90
Living_SDK/kernel/rhino/test/core/combination/sem_event.c
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "comb_test.h"
|
||||
|
||||
static ktask_t *task_sem;
|
||||
static ktask_t *task_ksem_trigger;
|
||||
static ktask_t *task_event_trigger;
|
||||
static ksem_t *sem_comb;
|
||||
static kevent_t event_sem;
|
||||
|
||||
#define MODULE_NAME "sem_event_opr"
|
||||
|
||||
|
||||
static void task_sem_opr_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_take(sem_comb, RHINO_WAIT_FOREVER);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_sem_dyn_del(sem_comb);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_ksem_trigger_opr_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t flag;
|
||||
|
||||
ret = krhino_event_get(&event_sem, 0x1, RHINO_AND_CLEAR, &flag,
|
||||
RHINO_WAIT_FOREVER);
|
||||
if ((ret == RHINO_SUCCESS) && (flag == 0x3)) {
|
||||
krhino_sem_give(sem_comb);
|
||||
krhino_event_del(&event_sem);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
static void task_event_trigger_opr_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_event_set(&event_sem, 0x1, RHINO_OR);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
void sem_event_coopr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
krhino_sem_dyn_create(&sem_comb, "semtest", 0);
|
||||
krhino_event_create(&event_sem, "eventtest", 0x2);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_COMB_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_opr_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_ksem_trigger, MODULE_NAME, 0,
|
||||
TASK_COMB_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_ksem_trigger_opr_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_event_trigger, MODULE_NAME, 0,
|
||||
TASK_COMB_PRI + 2,
|
||||
0, TASK_TEST_STACK_SIZE, task_event_trigger_opr_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
76
Living_SDK/kernel/rhino/test/core/combination/sem_mutex.c
Normal file
76
Living_SDK/kernel/rhino/test/core/combination/sem_mutex.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "comb_test.h"
|
||||
|
||||
static ktask_t *task_sem;
|
||||
static ktask_t *task_mutex;
|
||||
static ksem_t *sem_comb;
|
||||
static kmutex_t mutex_comb;
|
||||
|
||||
#define MODULE_NAME "sem_mutex_opr"
|
||||
|
||||
static void task_sem_opr_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_take(sem_comb, RHINO_WAIT_FOREVER);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_sem_dyn_del(sem_comb);
|
||||
krhino_mutex_del(&mutex_comb);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_mutex_opr_entry(void *arg)
|
||||
{
|
||||
krhino_mutex_lock(&mutex_comb, RHINO_WAIT_FOREVER);
|
||||
krhino_mutex_lock(&mutex_comb, RHINO_WAIT_FOREVER);
|
||||
krhino_mutex_lock(&mutex_comb, RHINO_WAIT_FOREVER);
|
||||
krhino_mutex_lock(&mutex_comb, RHINO_WAIT_FOREVER);
|
||||
krhino_mutex_lock(&mutex_comb, RHINO_WAIT_FOREVER);
|
||||
krhino_mutex_lock(&mutex_comb, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_mutex_unlock(&mutex_comb);
|
||||
krhino_mutex_unlock(&mutex_comb);
|
||||
krhino_mutex_unlock(&mutex_comb);
|
||||
krhino_mutex_unlock(&mutex_comb);
|
||||
krhino_mutex_unlock(&mutex_comb);
|
||||
krhino_mutex_unlock(&mutex_comb);
|
||||
|
||||
krhino_sem_give(sem_comb);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void sem_mutex_coopr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
krhino_sem_dyn_create(&sem_comb, "semtest", 0);
|
||||
krhino_mutex_create(&mutex_comb, "mutex");
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_COMB_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_opr_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex, MODULE_NAME, 0, TASK_COMB_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_opr_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "comb_test.h"
|
||||
|
||||
static ktask_t *task_sem;
|
||||
static ktask_t *task_buf_queue;
|
||||
static ktask_t *task_buf_queue_trigger;
|
||||
|
||||
static ksem_t *test_sem;
|
||||
static kbuf_queue_t test_buf_queue;
|
||||
static uint8_t buf_queue_test_buf[1];
|
||||
static uint8_t buf_queue_recv[1];
|
||||
static uint8_t buf_queue_send[1];
|
||||
|
||||
#define MODULE_NAME "sem_queue_buf_opr"
|
||||
|
||||
static void task_sem_opr_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_WAIT_FOREVER);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_sem_dyn_del(test_sem);
|
||||
krhino_buf_queue_del(&test_buf_queue);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_buf_queue_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
size_t size;
|
||||
|
||||
ret = krhino_buf_queue_recv(&test_buf_queue, RHINO_WAIT_FOREVER,
|
||||
(void *)buf_queue_recv, &size);
|
||||
if ((ret == RHINO_SUCCESS) && (*(uint8_t *)buf_queue_recv == 0x5a)) {
|
||||
krhino_sem_give(test_sem);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
static void task_buf_queue_trigger_entry(void *arg)
|
||||
{
|
||||
*(uint8_t *)buf_queue_send = 0x5a;
|
||||
|
||||
krhino_buf_queue_send(&test_buf_queue, (void *)buf_queue_send, 1);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void sem_buf_queue_coopr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
krhino_sem_dyn_create(&test_sem, "semtest", 0);
|
||||
krhino_buf_queue_create(&test_buf_queue, "bugqueue", (void *)buf_queue_test_buf,
|
||||
8, 1);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_COMB_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_opr_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_buf_queue, MODULE_NAME, 0, TASK_COMB_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_buf_queue_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_buf_queue_trigger, MODULE_NAME, 0,
|
||||
TASK_COMB_PRI + 2,
|
||||
0, TASK_TEST_STACK_SIZE, task_buf_queue_trigger_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
54
Living_SDK/kernel/rhino/test/core/event/event_break.c
Normal file
54
Living_SDK/kernel/rhino/test/core/event/event_break.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "event_test.h"
|
||||
|
||||
#define MODULE_NAME "event_break"
|
||||
|
||||
#define TEST_FLAG 0x5a5a5a5a
|
||||
|
||||
static uint8_t event_break_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_event_create(NULL, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.blk_obj.obj_type == RHINO_EVENT_OBJ_TYPE);
|
||||
|
||||
test_event.blk_obj.obj_type = RHINO_OBJ_TYPE_NONE;
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
test_event.blk_obj.obj_type = RHINO_EVENT_OBJ_TYPE;
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t event_func_runner[] = {
|
||||
event_break_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void event_break_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_event_entry_register(MODULE_NAME, (test_func_t *)event_func_runner,
|
||||
sizeof(event_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_event, MODULE_NAME, 0, TASK_EVENT_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_event_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
322
Living_SDK/kernel/rhino/test/core/event/event_opr.c
Normal file
322
Living_SDK/kernel/rhino/test/core/event/event_opr.c
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "event_test.h"
|
||||
|
||||
#define MODULE_NAME "event_opr"
|
||||
#define MODULE_NAME_CO "event_coopr"
|
||||
|
||||
#define TEST_FLAG 0x5a5a5a5a
|
||||
#define CHK_AND_ALL_FLAG 0x5a5a5a5a
|
||||
#define CHK_AND_ONE_FLAG 0x00000002
|
||||
#define CHK_AND_ZERO_FLAG 0x00000000
|
||||
#define CHK_AND_PEND_FLAG 0x5a5a5a55
|
||||
|
||||
static uint8_t event_opr_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
CPSR_ALLOC();
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
/* check event AND FLAG */
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event.blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event.blk_obj.obj_type = RHINO_EVENT_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_AND);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event.blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ALL_FLAG, RHINO_AND, &actl_flags,
|
||||
RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event.blk_obj.obj_type = RHINO_EVENT_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ALL_FLAG, RHINO_AND, &actl_flags,
|
||||
RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ONE_FLAG, RHINO_AND, &actl_flags,
|
||||
RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ZERO_FLAG, RHINO_AND, &actl_flags,
|
||||
RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t event_opr_case2(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
/* check event AND_CLEAR FLAG */
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ALL_FLAG, RHINO_AND_CLEAR,
|
||||
&actl_flags, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == (TEST_FLAG & (~CHK_AND_ALL_FLAG)));
|
||||
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ONE_FLAG, RHINO_AND_CLEAR,
|
||||
&actl_flags, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == (TEST_FLAG & (~CHK_AND_ONE_FLAG)));
|
||||
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ZERO_FLAG, RHINO_AND_CLEAR,
|
||||
&actl_flags, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == (TEST_FLAG & (~CHK_AND_ZERO_FLAG)));
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t event_opr_case3(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
/* check event OR FLAG */
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ALL_FLAG, RHINO_OR, &actl_flags,
|
||||
RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ONE_FLAG, RHINO_OR, &actl_flags,
|
||||
RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ZERO_FLAG, RHINO_OR, &actl_flags,
|
||||
RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_NO_PEND_WAIT);
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t event_opr_case4(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
/* check event OR_CLEAR FLAG */
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ALL_FLAG, RHINO_OR_CLEAR,
|
||||
&actl_flags, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == (TEST_FLAG & (~CHK_AND_ALL_FLAG)));
|
||||
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_ONE_FLAG, RHINO_OR_CLEAR,
|
||||
&actl_flags, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(actl_flags == TEST_FLAG);
|
||||
MYASSERT(test_event.flags == (TEST_FLAG & (~CHK_AND_ONE_FLAG)));
|
||||
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t event_opr_case5(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
/* try to get event flag in case of sched disable */
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
krhino_sched_disable();
|
||||
|
||||
ret = krhino_event_get(&test_event, CHK_AND_PEND_FLAG, RHINO_AND, &actl_flags,
|
||||
RHINO_WAIT_FOREVER);
|
||||
MYASSERT(ret == RHINO_SCHED_DISABLE);
|
||||
|
||||
krhino_sched_enable();
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t event_func_runner[] = {
|
||||
event_opr_case1,
|
||||
event_opr_case2,
|
||||
event_opr_case3,
|
||||
event_opr_case4,
|
||||
event_opr_case5,
|
||||
NULL
|
||||
};
|
||||
|
||||
void event_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_event_entry_register(MODULE_NAME, (test_func_t *)event_func_runner,
|
||||
sizeof(event_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_event, MODULE_NAME, 0, TASK_EVENT_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_event_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_event_co1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_event_get(&test_event, ~CHK_AND_ALL_FLAG, RHINO_AND, &actl_flags,
|
||||
RHINO_WAIT_FOREVER);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
break;
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
|
||||
krhino_event_del(&test_event);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, PASS);
|
||||
|
||||
krhino_event_del(&test_event);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_event_co2_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_event_set(&test_event, ~CHK_AND_ALL_FLAG, RHINO_OR);
|
||||
break;
|
||||
}
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void event_coopr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
if (ret != RHINO_SUCCESS && test_event.flags != TEST_FLAG) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_event_co1, MODULE_NAME, 0, TASK_EVENT_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_event_co1_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_event_co2, MODULE_NAME, 0, TASK_EVENT_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_event_co2_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
128
Living_SDK/kernel/rhino/test/core/event/event_param.c
Normal file
128
Living_SDK/kernel/rhino/test/core/event/event_param.c
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "event_test.h"
|
||||
|
||||
#define MODULE_NAME "event_param"
|
||||
|
||||
#define TEST_FLAG 0x5a5a5a5a
|
||||
|
||||
static uint8_t event_param_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
CPSR_ALLOC();
|
||||
|
||||
ret = krhino_event_create(NULL, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_create(&test_event, NULL, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_event_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event.mm_alloc_flag = K_OBJ_DYN_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event.mm_alloc_flag = K_OBJ_STATIC_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_event_dyn_create(NULL, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_dyn_create(&test_event_ext, NULL, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_dyn_create(&test_event_ext, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_event_dyn_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event_ext->blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_dyn_del(test_event_ext);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event_ext->blk_obj.obj_type = RHINO_EVENT_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event_ext->mm_alloc_flag = K_OBJ_STATIC_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_dyn_del(test_event_ext);
|
||||
MYASSERT(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_event_ext->mm_alloc_flag = K_OBJ_DYN_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_event_dyn_del(test_event_ext);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t event_param_case2(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_event_get(NULL, 0, RHINO_AND, &actl_flags, RHINO_WAIT_FOREVER);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_get(&test_event, 0, RHINO_AND, NULL, RHINO_WAIT_FOREVER);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_get(&test_event, 0, 0xff, &actl_flags, RHINO_WAIT_FOREVER);
|
||||
MYASSERT(ret == RHINO_NO_THIS_EVENT_OPT);
|
||||
|
||||
ret = krhino_event_set(NULL, TEST_FLAG, RHINO_OR);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_event_set(&test_event, TEST_FLAG, 0xff);
|
||||
MYASSERT(ret == RHINO_NO_THIS_EVENT_OPT);
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t event_func_runner[] = {
|
||||
event_param_case1,
|
||||
event_param_case2,
|
||||
NULL
|
||||
};
|
||||
|
||||
void event_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_event_entry_register(MODULE_NAME, (test_func_t *)event_func_runner,
|
||||
sizeof(event_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_event, MODULE_NAME, 0, TASK_EVENT_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_event_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
57
Living_SDK/kernel/rhino/test/core/event/event_reinit.c
Normal file
57
Living_SDK/kernel/rhino/test/core/event/event_reinit.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "event_test.h"
|
||||
|
||||
#define MODULE_NAME "event_reinit"
|
||||
|
||||
#define TEST_FLAG 0x5a5a5a5a
|
||||
|
||||
static uint8_t event_reinit_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.blk_obj.obj_type == RHINO_EVENT_OBJ_TYPE);
|
||||
MYASSERT(test_event.blk_obj.blk_policy == BLK_POLICY_PRI);
|
||||
MYASSERT(test_event.blk_obj.name != NULL);
|
||||
MYASSERT(test_event.flags == TEST_FLAG);
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_event_create(&test_event, MODULE_NAME, TEST_FLAG & 0x0000ffff);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_event.blk_obj.obj_type == RHINO_EVENT_OBJ_TYPE);
|
||||
MYASSERT(test_event.flags == (TEST_FLAG & 0x0000ffff));
|
||||
|
||||
ret = krhino_event_del(&test_event);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t event_func_runner[] = {
|
||||
event_reinit_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void event_reinit_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_event_entry_register(MODULE_NAME, (test_func_t *)event_func_runner,
|
||||
sizeof(event_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_event, MODULE_NAME, 0, TASK_EVENT_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_event_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
80
Living_SDK/kernel/rhino/test/core/event/event_test.c
Normal file
80
Living_SDK/kernel/rhino/test/core/event/event_test.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "event_test.h"
|
||||
|
||||
ktask_t *task_event;
|
||||
ktask_t *task_event_co1;
|
||||
ktask_t *task_event_co2;
|
||||
kevent_t test_event;
|
||||
kevent_t *test_event_ext;
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t event_case_runner[] = {
|
||||
event_param_test,
|
||||
event_break_test,
|
||||
event_reinit_test,
|
||||
event_opr_test,
|
||||
event_coopr_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void event_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)event_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_event_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_event_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
32
Living_SDK/kernel/rhino/test/core/event/event_test.h
Normal file
32
Living_SDK/kernel/rhino/test/core/event/event_test.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef EVENT_TEST_H
|
||||
#define EVENT_TEST_H
|
||||
|
||||
#define TASK_EVENT_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do {if ((int)(value) == 0) { printf("xxxx: %d \n", __LINE__); return 1; }} while (0)
|
||||
|
||||
extern ktask_t *task_event;
|
||||
extern ktask_t *task_event_co1;
|
||||
extern ktask_t *task_event_co2;
|
||||
extern kevent_t test_event;
|
||||
extern kevent_t *test_event_ext;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_event_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum);
|
||||
void task_event_entry(void *arg);
|
||||
void event_test(void);
|
||||
void event_param_test(void);
|
||||
void event_opr_test(void);
|
||||
void event_break_test(void);
|
||||
void event_reinit_test(void);
|
||||
void event_coopr_test(void);
|
||||
|
||||
#endif /* EVENT_TEST_H */
|
||||
|
||||
133
Living_SDK/kernel/rhino/test/core/mm/mm_break.c
Normal file
133
Living_SDK/kernel/rhino/test/core/mm/mm_break.c
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_break"
|
||||
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
|
||||
static uint8_t mm_break_case1(void)
|
||||
{
|
||||
void *ptr, *newptr;
|
||||
kstat_t ret;
|
||||
char *ptrarray[10];
|
||||
int i;
|
||||
size_t oldsize;
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
#if (K_MM_STATISTIC > 0)
|
||||
|
||||
oldsize = pmmhead->used_size;
|
||||
ptr = k_mm_alloc(pmmhead, 8);
|
||||
MYASSERT(ptr != NULL);
|
||||
|
||||
MYASSERT((pmmhead->used_size - oldsize ) == RHINO_CONFIG_MM_BLK_SIZE);
|
||||
|
||||
k_mm_free(pmmhead, ptr);
|
||||
|
||||
oldsize = pmmhead->used_size;
|
||||
ptr = k_mm_alloc(pmmhead, RHINO_CONFIG_MM_BLK_SIZE);
|
||||
MYASSERT(ptr != NULL);
|
||||
MYASSERT((pmmhead->used_size - oldsize ) == RHINO_CONFIG_MM_BLK_SIZE);
|
||||
k_mm_free(pmmhead, ptr);
|
||||
|
||||
oldsize = pmmhead->used_size;
|
||||
ptr = k_mm_alloc(pmmhead, RHINO_CONFIG_MM_BLK_SIZE + 1);
|
||||
|
||||
MYASSERT(ptr != NULL);
|
||||
MYASSERT((pmmhead->used_size - oldsize ) ==
|
||||
(RHINO_CONFIG_MM_BLK_SIZE >= MM_MIN_SIZE ?
|
||||
RHINO_CONFIG_MM_BLK_SIZE + MM_ALIGN_SIZE + MMLIST_HEAD_SIZE :
|
||||
MM_MIN_SIZE + MMLIST_HEAD_SIZE));
|
||||
k_mm_free(pmmhead, ptr);
|
||||
#endif
|
||||
|
||||
|
||||
ptr = k_mm_alloc(pmmhead, RHINO_CONFIG_MM_BLK_SIZE / 2);
|
||||
MYASSERT(ptr != NULL);
|
||||
|
||||
newptr = k_mm_realloc(pmmhead, ptr, RHINO_CONFIG_MM_BLK_SIZE / 2 + 1 );
|
||||
MYASSERT(newptr == ptr);
|
||||
|
||||
newptr = k_mm_realloc(pmmhead, ptr, RHINO_CONFIG_MM_BLK_SIZE - 1);
|
||||
MYASSERT(newptr == ptr);
|
||||
|
||||
ptr = newptr;
|
||||
newptr = k_mm_realloc(pmmhead, ptr, RHINO_CONFIG_MM_BLK_SIZE + 1);
|
||||
MYASSERT(newptr != ptr);
|
||||
|
||||
ptr = newptr;
|
||||
newptr = k_mm_realloc(pmmhead, ptr, RHINO_CONFIG_MM_BLK_SIZE + 2);
|
||||
MYASSERT(newptr == ptr);
|
||||
|
||||
ptr = newptr;
|
||||
newptr = k_mm_realloc(pmmhead, ptr, RHINO_CONFIG_MM_BLK_SIZE * 4);
|
||||
MYASSERT(newptr == ptr);
|
||||
|
||||
ptr = newptr;
|
||||
newptr = k_mm_realloc(pmmhead, ptr, RHINO_CONFIG_MM_BLK_SIZE * 3);
|
||||
MYASSERT(newptr == ptr);
|
||||
|
||||
newptr = k_mm_realloc(pmmhead, ptr, 0);
|
||||
MYASSERT(newptr == NULL);
|
||||
|
||||
ptr = k_mm_realloc(pmmhead, NULL, RHINO_CONFIG_MM_BLK_SIZE * 3);
|
||||
MYASSERT(ptr != NULL);
|
||||
|
||||
k_mm_free(pmmhead, ptr);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
ptrarray[i] = k_mm_alloc(pmmhead, (i + 1) * 2);
|
||||
MYASSERT(ptrarray[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (i % 2 == 0) {
|
||||
k_mm_free(pmmhead, ptrarray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (i % 2 != 0) {
|
||||
ptrarray[i] = k_mm_realloc(pmmhead, ptrarray[i], (i + 1) * 3);
|
||||
}
|
||||
MYASSERT(ptrarray[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (i % 2 != 0) {
|
||||
k_mm_free(pmmhead, ptrarray[i]);
|
||||
}
|
||||
}
|
||||
krhino_deinit_mm_head(pmmhead);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_func_runner[] = {
|
||||
mm_break_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_break_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_entry_register(MODULE_NAME, (test_func_t *)mm_func_runner,
|
||||
sizeof(mm_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm, MODULE_NAME, 0, TASK_MM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
146
Living_SDK/kernel/rhino/test/core/mm/mm_opr.c
Normal file
146
Living_SDK/kernel/rhino/test/core/mm/mm_opr.c
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_opr"
|
||||
#define MODULE_NAME_CO "mm_coopr"
|
||||
static void *co_ptr;
|
||||
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
|
||||
static uint8_t mm_opr_case1(void)
|
||||
{
|
||||
char *ptr;
|
||||
kstat_t ret;
|
||||
char tmp;
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ptr = k_mm_alloc(pmmhead, 64);
|
||||
MYASSERT(ptr != NULL);
|
||||
//for vagrind test
|
||||
//ptr[64] = ptr[-1];
|
||||
|
||||
k_mm_free(pmmhead, ptr);
|
||||
|
||||
krhino_deinit_mm_head(pmmhead);
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
krhino_deinit_mm_head(pmmhead);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t mm_opr_case2(void)
|
||||
{
|
||||
void *r_ptr[16];
|
||||
int8_t cnt;
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
/* alloc out of mm pools then free all */
|
||||
cnt = 0;
|
||||
for (cnt = 0; cnt < 16; ++cnt) {
|
||||
r_ptr[cnt] = k_mm_alloc(pmmhead, cnt + 26);
|
||||
if (r_ptr[cnt] == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
k_mm_free(pmmhead, r_ptr[--cnt]);
|
||||
|
||||
} while (cnt > 0);
|
||||
|
||||
krhino_deinit_mm_head(pmmhead);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_func_runner[] = {
|
||||
mm_opr_case1,
|
||||
mm_opr_case2,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_entry_register(MODULE_NAME, (test_func_t *)mm_func_runner,
|
||||
sizeof(mm_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm, MODULE_NAME, 0, TASK_MM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_mm_co1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
co_ptr = k_mm_alloc(pmmhead, 16);
|
||||
k_mm_free(pmmhead, co_ptr);
|
||||
|
||||
co_ptr = k_mm_alloc(pmmhead, 18);
|
||||
k_mm_free(pmmhead, co_ptr);
|
||||
|
||||
co_ptr = k_mm_alloc(pmmhead, 32);
|
||||
k_mm_free(pmmhead, co_ptr);
|
||||
|
||||
co_ptr = k_mm_alloc(pmmhead, 65);
|
||||
k_mm_free(pmmhead, co_ptr);
|
||||
|
||||
co_ptr = k_mm_alloc(pmmhead, 178);
|
||||
k_mm_free(pmmhead, co_ptr);
|
||||
|
||||
co_ptr = k_mm_alloc(pmmhead, 333);
|
||||
k_mm_free(pmmhead, co_ptr);
|
||||
|
||||
krhino_deinit_mm_head(pmmhead);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void mm_coopr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm, MODULE_NAME, 0, TASK_MM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_co1_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
85
Living_SDK/kernel/rhino/test/core/mm/mm_param.c
Normal file
85
Living_SDK/kernel/rhino/test/core/mm/mm_param.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_param"
|
||||
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
|
||||
static uint8_t mm_param_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_init_mm_head(NULL, (void *)mm_pool, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, NULL, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MIN_FREE_MEMORY_SIZE + RHINO_CONFIG_MM_TLF_BLK_SIZE - 1);
|
||||
MYASSERT(ret == RHINO_MM_POOL_SIZE_ERR);
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
ret = krhino_deinit_mm_head(pmmhead);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t mm_param_case2(void)
|
||||
{
|
||||
void *ptr;
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_init_mm_head(&pmmhead, (void *)mm_pool, MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ptr = k_mm_alloc( NULL, 64);
|
||||
MYASSERT(ptr == NULL);
|
||||
|
||||
ptr = k_mm_alloc(pmmhead, 0);
|
||||
MYASSERT(ptr == NULL);
|
||||
|
||||
ptr = k_mm_alloc(pmmhead, 64);
|
||||
MYASSERT((ptr > (void *)mm_pool) && (ptr < ((void *)mm_pool + MM_POOL_SIZE)));
|
||||
k_mm_free(pmmhead, ptr);
|
||||
|
||||
ptr = k_mm_alloc(pmmhead, 16);
|
||||
|
||||
MYASSERT(krhino_mblk_check(pmmhead->fix_pool, ptr));
|
||||
|
||||
k_mm_free(pmmhead, ptr);
|
||||
|
||||
krhino_deinit_mm_head(pmmhead);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_func_runner[] = {
|
||||
mm_param_case1,
|
||||
mm_param_case2,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_entry_register(MODULE_NAME, (test_func_t *)mm_func_runner,
|
||||
sizeof(mm_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm, MODULE_NAME, 0, TASK_MM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
51
Living_SDK/kernel/rhino/test/core/mm/mm_reinit.c
Normal file
51
Living_SDK/kernel/rhino/test/core/mm/mm_reinit.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_reinit"
|
||||
|
||||
static uint8_t mm_reinit_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mm_pool_init(&mm_pool_test, MODULE_NAME, (void *)mm_pool,
|
||||
MM_POOL_MIN_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(mm_pool_test.fragments == 2);
|
||||
MYASSERT(mm_pool_test.pool_name != NULL);
|
||||
MYASSERT(mm_pool_test.avail == (MM_POOL_MIN_SIZE - (MM_HEAD_SIZE << 1)));
|
||||
|
||||
ret = krhino_mm_pool_init(&mm_pool_test, MODULE_NAME, (void *)mm_pool,
|
||||
MM_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(mm_pool_test.fragments == 2);
|
||||
MYASSERT(mm_pool_test.pool_name != NULL);
|
||||
MYASSERT(mm_pool_test.avail == (MM_POOL_SIZE - (MM_HEAD_SIZE << 1)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_func_runner[] = {
|
||||
mm_reinit_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_reinit_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_entry_register(MODULE_NAME, (test_func_t *)mm_func_runner,
|
||||
sizeof(mm_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm, MODULE_NAME, 0, TASK_MM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
82
Living_SDK/kernel/rhino/test/core/mm/mm_test.c
Normal file
82
Living_SDK/kernel/rhino/test/core/mm/mm_test.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_test.h"
|
||||
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
|
||||
ktask_t *task_mm;
|
||||
ktask_t *task_mm_co;
|
||||
k_mm_head *pmmhead;
|
||||
char mm_pool[MM_POOL_SIZE] = {0};
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t mm_case_runner[] = {
|
||||
mm_param_test,
|
||||
mm_break_test,
|
||||
mm_opr_test,
|
||||
mm_coopr_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)mm_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_mm_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_mm_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
#endif
|
||||
|
||||
33
Living_SDK/kernel/rhino/test/core/mm/mm_test.h
Normal file
33
Living_SDK/kernel/rhino/test/core/mm/mm_test.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef MM_TEST_H
|
||||
#define MM_TEST_H
|
||||
|
||||
#define TASK_MM_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
#define MM_POOL_SIZE (1024 * 11)
|
||||
|
||||
#define MYASSERT(value) do {if ((int)(value) == 0) { printf("%s:%d\n", __FUNCTION__, __LINE__);return 1; }} while (0)
|
||||
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
extern ktask_t *task_mm;
|
||||
extern ktask_t *task_mm_co;
|
||||
extern k_mm_head *pmmhead;
|
||||
extern char mm_pool[MM_POOL_SIZE];
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_mm_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum);
|
||||
void task_mm_entry(void *arg);
|
||||
void mm_test(void);
|
||||
void mm_param_test(void);
|
||||
//void mm_reinit_test(void);
|
||||
void mm_break_test(void);
|
||||
void mm_opr_test(void);
|
||||
void mm_coopr_test(void);
|
||||
#endif
|
||||
#endif /* MM_TEST_H */
|
||||
|
||||
42
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_break.c
Normal file
42
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_break.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_blk_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_blk_break"
|
||||
|
||||
static uint8_t mm_blk_break_case1(void)
|
||||
{
|
||||
void *ptr;
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_blk_func_runner[] = {
|
||||
mm_blk_break_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_blk_break_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_blk_entry_register(MODULE_NAME, (test_func_t *)mm_blk_func_runner,
|
||||
sizeof(mm_blk_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm_blk, MODULE_NAME, 0, TASK_MM_BLK_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_blk_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
70
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_fragment.c
Normal file
70
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_fragment.c
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_blk_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_blk_fragment"
|
||||
|
||||
static uint8_t mm_blk_fragment_case1(void)
|
||||
{
|
||||
void *ptr[16];
|
||||
kstat_t ret;
|
||||
uint8_t blkavail;
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check malloc save pointer number is enough or not */
|
||||
MYASSERT(mblk_pool_test.blk_whole <= 16);
|
||||
|
||||
/* alloc all blocks */
|
||||
blkavail = 0;
|
||||
do {
|
||||
ret = krhino_mblk_alloc(&mblk_pool_test, &ptr[blkavail]);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
blkavail++;
|
||||
}
|
||||
} while (ret == RHINO_SUCCESS);
|
||||
|
||||
MYASSERT(mblk_pool_test.blk_avail == 0);
|
||||
MYASSERT(blkavail == mblk_pool_test.blk_whole);
|
||||
|
||||
/* free all blocks */
|
||||
blkavail = 0;
|
||||
do {
|
||||
ret = krhino_mblk_free(&mblk_pool_test, ptr[blkavail]);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
blkavail++;
|
||||
}
|
||||
} while (ret == RHINO_SUCCESS);
|
||||
|
||||
MYASSERT(mblk_pool_test.blk_avail == mblk_pool_test.blk_whole);
|
||||
MYASSERT(blkavail == mblk_pool_test.blk_whole);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_blk_func_runner[] = {
|
||||
mm_blk_fragment_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_blk_fragment_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_blk_entry_register(MODULE_NAME, (test_func_t *)mm_blk_func_runner,
|
||||
sizeof(mm_blk_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm_blk, MODULE_NAME, 0, TASK_MM_BLK_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_blk_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
104
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_opr.c
Normal file
104
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_opr.c
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_blk_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_blk_opr"
|
||||
#define MODULE_NAME_CO "mm_blk_coopr"
|
||||
|
||||
static void *co_ptr;
|
||||
static ktask_t *blk_task;
|
||||
|
||||
static uint8_t mm_blk_opr_case1(void)
|
||||
{
|
||||
void *ptr;
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mblk_alloc(&mblk_pool_test, &ptr);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mblk_free(&mblk_pool_test, ptr);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_blk_func_runner[] = {
|
||||
mm_blk_opr_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_blk_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_blk_entry_register(MODULE_NAME, (test_func_t *)mm_blk_func_runner,
|
||||
sizeof(mm_blk_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm_blk, MODULE_NAME, 0, TASK_MM_BLK_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_blk_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_mm_blk_co1_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_mblk_alloc(&mblk_pool_test, &co_ptr);
|
||||
krhino_mblk_free(&mblk_pool_test, co_ptr);
|
||||
krhino_task_sleep(5);
|
||||
krhino_mblk_alloc(&mblk_pool_test, &co_ptr);
|
||||
krhino_mblk_free(&mblk_pool_test, co_ptr);
|
||||
krhino_task_sleep(5);
|
||||
krhino_mblk_alloc(&mblk_pool_test, &co_ptr);
|
||||
krhino_mblk_free(&mblk_pool_test, co_ptr);
|
||||
krhino_task_sleep(5);
|
||||
krhino_mblk_alloc(&mblk_pool_test, &co_ptr);
|
||||
krhino_mblk_free(&mblk_pool_test, co_ptr);
|
||||
krhino_task_sleep(5);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (mblk_pool_test.blk_avail == (MBLK_POOL_SIZE / mblk_pool_test.blk_size)) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
|
||||
void mm_blk_coopr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&blk_task, MODULE_NAME, 0, TASK_MM_BLK_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_blk_co1_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
104
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_param.c
Normal file
104
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_param.c
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_blk_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_blk_param"
|
||||
|
||||
static uint8_t mm_blk_param_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mblk_pool_init(NULL, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 1, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, NULL, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 1, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, NULL,
|
||||
MBLK_POOL_SIZE >> 1, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
/* check block size is less than half of pool size */
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
(MBLK_POOL_SIZE >> 1) + 1, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_BLK_POOL_SIZE_ERR);
|
||||
|
||||
/* check block size is less than half of pool size */
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_BLK_POOL_SIZE_ERR);
|
||||
|
||||
/* check pool address is not align */
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME,
|
||||
(void *)(mblk_pool + 1),
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_INV_ALIGN);
|
||||
|
||||
/* check block size is not align */
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
(MBLK_POOL_SIZE >> 2) + 1, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_INV_ALIGN);
|
||||
|
||||
/* check pool size is not align */
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE + 1);
|
||||
MYASSERT(ret == RHINO_INV_ALIGN);
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t mm_blk_param_case2(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
void *ptr;
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mblk_alloc(NULL, &ptr);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mblk_alloc(&mblk_pool_test, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mblk_free(NULL, ptr);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mblk_free(&mblk_pool_test, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_blk_func_runner[] = {
|
||||
mm_blk_param_case1,
|
||||
mm_blk_param_case2,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_blk_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_blk_entry_register(MODULE_NAME, (test_func_t *)mm_blk_func_runner,
|
||||
sizeof(mm_blk_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm_blk, MODULE_NAME, 0, TASK_MM_BLK_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_blk_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
53
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_reinit.c
Normal file
53
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_reinit.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_blk_test.h"
|
||||
|
||||
#define MODULE_NAME "mm_blk_reinit"
|
||||
|
||||
static uint8_t mm_blk_reinit_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 2, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(mblk_pool_test.pool_name != NULL);
|
||||
MYASSERT(mblk_pool_test.blk_avail == (MBLK_POOL_SIZE /
|
||||
mblk_pool_test.blk_size));
|
||||
MYASSERT(mblk_pool_test.blk_size == MBLK_POOL_SIZE >> 2);
|
||||
|
||||
ret = krhino_mblk_pool_init(&mblk_pool_test, MODULE_NAME, (void *)mblk_pool,
|
||||
MBLK_POOL_SIZE >> 3, MBLK_POOL_SIZE);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(mblk_pool_test.pool_name != NULL);
|
||||
MYASSERT(mblk_pool_test.blk_avail == (MBLK_POOL_SIZE /
|
||||
mblk_pool_test.blk_size));
|
||||
MYASSERT(mblk_pool_test.blk_size == MBLK_POOL_SIZE >> 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mm_blk_func_runner[] = {
|
||||
mm_blk_reinit_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_blk_reinit_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mm_blk_entry_register(MODULE_NAME, (test_func_t *)mm_blk_func_runner,
|
||||
sizeof(mm_blk_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mm_blk, MODULE_NAME, 0, TASK_MM_BLK_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mm_blk_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
80
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_test.c
Normal file
80
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_test.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mm_blk_test.h"
|
||||
|
||||
ktask_t *task_mm_blk;
|
||||
ktask_t *task_mm_blk_co;
|
||||
mblk_pool_t mblk_pool_test;
|
||||
char mblk_pool[MBLK_POOL_SIZE];
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t mm_blk_case_runner[] = {
|
||||
mm_blk_param_test,
|
||||
mm_blk_opr_test,
|
||||
mm_blk_break_test,
|
||||
mm_blk_reinit_test,
|
||||
mm_blk_fragment_test,
|
||||
mm_blk_coopr_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mm_blk_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)mm_blk_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_mm_blk_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_mm_blk_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
34
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_test.h
Normal file
34
Living_SDK/kernel/rhino/test/core/mm_blk/mm_blk_test.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef MM_BLK_TEST_H
|
||||
#define MM_BLK_TEST_H
|
||||
|
||||
#define TASK_MM_BLK_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MBLK_POOL_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do {if ((int)(value) == 0) { printf("%s:%d\n", __FUNCTION__, __LINE__);return 1; }} while (0)
|
||||
|
||||
extern ktask_t *task_mm_blk;
|
||||
extern ktask_t *task_mm_blk_co;
|
||||
extern mblk_pool_t mblk_pool_test;
|
||||
extern char mblk_pool[MBLK_POOL_SIZE];
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_mm_blk_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum);
|
||||
void task_mm_blk_entry(void *arg);
|
||||
void mm_blk_test(void);
|
||||
void mm_blk_param_test(void);
|
||||
void mm_blk_opr_test(void);
|
||||
void mm_blk_break_test(void);
|
||||
void mm_blk_reinit_test(void);
|
||||
void mm_blk_fragment_test(void);
|
||||
void mm_blk_coopr_test(void);
|
||||
|
||||
#endif /* MM_BLK_TEST_H */
|
||||
|
||||
303
Living_SDK/kernel/rhino/test/core/mutex/mutex_opr.c
Normal file
303
Living_SDK/kernel/rhino/test/core/mutex/mutex_opr.c
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mutex_test.h"
|
||||
|
||||
#define MODULE_NAME "mutex_opr"
|
||||
#define MODULE_NAME_CO1 "mutex_coopr1"
|
||||
#define MODULE_NAME_CO2 "mutex_coopr2"
|
||||
|
||||
static uint8_t mutex_opr_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint8_t old_pri;
|
||||
|
||||
ret = krhino_mutex_create(&test_mutex, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_unlock(&test_mutex);
|
||||
MYASSERT(ret == RHINO_MUTEX_NOT_RELEASED_BY_OWNER);
|
||||
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
krhino_task_pri_change(krhino_cur_task_get(), TASK_MUTEX_PRI, &old_pri);
|
||||
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_MUTEX_OWNER_NESTED);
|
||||
|
||||
ret = krhino_mutex_unlock(&test_mutex);
|
||||
MYASSERT(ret == RHINO_MUTEX_OWNER_NESTED);
|
||||
|
||||
ret = krhino_mutex_unlock(&test_mutex);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_del(&test_mutex);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mutex_func_runner[] = {
|
||||
mutex_opr_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mutex_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mutex_entry_register(MODULE_NAME, (test_func_t *)mutex_func_runner,
|
||||
sizeof(mutex_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex, MODULE_NAME, 0, TASK_MUTEX_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t task_pri_get(ktask_t *task)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
uint8_t pri;
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
pri = task->prio;
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
return pri;
|
||||
}
|
||||
|
||||
void task_mutex_coopr1_co1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
krhino_task_sleep(5);
|
||||
|
||||
krhino_sched_disable();
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_WAIT_FOREVER);
|
||||
if (ret != RHINO_SCHED_DISABLE) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
}
|
||||
krhino_sched_enable();
|
||||
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_NO_WAIT);
|
||||
if (ret != RHINO_NO_PEND_WAIT) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_WAIT_FOREVER);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
}
|
||||
|
||||
krhino_mutex_unlock(&test_mutex);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void task_mutex_coopr1_co2_entry(void *arg)
|
||||
{
|
||||
uint8_t pri;
|
||||
|
||||
krhino_mutex_create(&test_mutex, MODULE_NAME_CO1);
|
||||
|
||||
while (1) {
|
||||
krhino_mutex_lock(&test_mutex, RHINO_WAIT_FOREVER);
|
||||
krhino_task_sleep(10);
|
||||
|
||||
/* now, the task's priority is revert */
|
||||
pri = task_pri_get(krhino_cur_task_get());
|
||||
if (pri != TASK_MUTEX_PRI) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
krhino_mutex_del(&test_mutex);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
|
||||
return;
|
||||
} else {
|
||||
krhino_task_dyn_del(task_mutex_co1);
|
||||
krhino_mutex_unlock(&test_mutex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, PASS);
|
||||
|
||||
krhino_mutex_del(&test_mutex);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
/* the case is to test a mutex task owner 's priority revert in case of another higher
|
||||
* priority task try to get mutex */
|
||||
void mutex_coopr1_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex_co1, MODULE_NAME_CO1, 0, TASK_MUTEX_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_coopr1_co1_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex_co2, MODULE_NAME_CO1, 0,
|
||||
TASK_MUTEX_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_coopr1_co2_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_mutex_coopr2_co1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
krhino_task_sleep(10);
|
||||
|
||||
ret = krhino_mutex_lock(&test_mutex_co1, RHINO_WAIT_FOREVER);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
krhino_mutex_unlock(&test_mutex_co1);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_mutex_coopr2_co2_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_task_sleep(10);
|
||||
|
||||
krhino_mutex_lock(&test_mutex_co2, RHINO_WAIT_FOREVER);
|
||||
krhino_mutex_lock(&test_mutex_co2, RHINO_WAIT_FOREVER);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_mutex_coopr2_co3_entry(void *arg)
|
||||
{
|
||||
uint8_t pri;
|
||||
|
||||
krhino_mutex_create(&test_mutex_co1, MODULE_NAME_CO2);
|
||||
krhino_mutex_create(&test_mutex_co2, MODULE_NAME_CO2);
|
||||
|
||||
while (1) {
|
||||
krhino_mutex_lock(&test_mutex_co1, RHINO_WAIT_FOREVER);
|
||||
krhino_mutex_lock(&test_mutex_co2, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_task_sleep(20);
|
||||
pri = task_pri_get(krhino_cur_task_get());
|
||||
if (pri == TASK_MUTEX_PRI) {
|
||||
krhino_mutex_unlock(&test_mutex_co1);
|
||||
|
||||
pri = task_pri_get(krhino_cur_task_get());
|
||||
if (pri == TASK_MUTEX_PRI + 1) {
|
||||
krhino_mutex_unlock(&test_mutex_co2);
|
||||
|
||||
pri = task_pri_get(krhino_cur_task_get());
|
||||
if (pri == TASK_MUTEX_PRI + 2) {
|
||||
break;
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO2, FAIL);
|
||||
|
||||
krhino_mutex_del(&test_mutex);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO2, FAIL);
|
||||
|
||||
krhino_mutex_del(&test_mutex);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO2, FAIL);
|
||||
|
||||
krhino_mutex_del(&test_mutex);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME_CO2, PASS);
|
||||
|
||||
krhino_mutex_del(&test_mutex);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
|
||||
void mutex_coopr2_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex_co1, MODULE_NAME_CO2, 0, TASK_MUTEX_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_coopr2_co1_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex_co2, MODULE_NAME_CO2, 0,
|
||||
TASK_MUTEX_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_coopr2_co2_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex_co3, MODULE_NAME_CO2, 0,
|
||||
TASK_MUTEX_PRI + 2,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_coopr2_co3_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
145
Living_SDK/kernel/rhino/test/core/mutex/mutex_param.c
Normal file
145
Living_SDK/kernel/rhino/test/core/mutex/mutex_param.c
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mutex_test.h"
|
||||
|
||||
#define MODULE_NAME "mutex_param"
|
||||
|
||||
static uint8_t mutex_param_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
CPSR_ALLOC();
|
||||
|
||||
ret = krhino_mutex_create(NULL, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_create(&test_mutex, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_create(&test_mutex, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_mutex.mm_alloc_flag = K_OBJ_DYN_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_mutex_del(&test_mutex);
|
||||
MYASSERT(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_mutex.mm_alloc_flag = K_OBJ_STATIC_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_mutex_del(&test_mutex);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_dyn_create(NULL, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_dyn_create(&test_mutex_dyn, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_dyn_create(&test_mutex_dyn, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_dyn_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_mutex_dyn->blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_mutex_dyn_del(test_mutex_dyn);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_mutex_dyn->blk_obj.obj_type = RHINO_MUTEX_OBJ_TYPE;
|
||||
test_mutex_dyn->mm_alloc_flag = K_OBJ_STATIC_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_mutex_dyn_del(test_mutex_dyn);
|
||||
MYASSERT(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_mutex_dyn->mm_alloc_flag = K_OBJ_DYN_ALLOC;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_mutex_dyn_del(test_mutex_dyn);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_dyn_create(NULL, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_dyn_create(&test_mutex_dyn, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_dyn_create(&test_mutex_dyn, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_dyn_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
test_mutex_dyn->blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
ret = krhino_mutex_dyn_del(test_mutex_dyn);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
test_mutex_dyn->blk_obj.obj_type = RHINO_MUTEX_OBJ_TYPE;
|
||||
test_mutex_dyn->mm_alloc_flag = K_OBJ_STATIC_ALLOC;
|
||||
ret = krhino_mutex_dyn_del(test_mutex_dyn);
|
||||
MYASSERT(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
test_mutex_dyn->mm_alloc_flag = K_OBJ_DYN_ALLOC;
|
||||
ret = krhino_mutex_dyn_del(test_mutex_dyn);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t mutex_param_case2(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
CPSR_ALLOC();
|
||||
|
||||
ret = krhino_mutex_create(&test_mutex, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_lock(NULL, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_unlock(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_mutex_unlock(&test_mutex);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_del(&test_mutex);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mutex_func_runner[] = {
|
||||
mutex_param_case1,
|
||||
mutex_param_case2,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mutex_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mutex_entry_register(MODULE_NAME, (test_func_t *)mutex_func_runner,
|
||||
sizeof(mutex_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex, MODULE_NAME, 0, TASK_MUTEX_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
59
Living_SDK/kernel/rhino/test/core/mutex/mutex_reinit.c
Normal file
59
Living_SDK/kernel/rhino/test/core/mutex/mutex_reinit.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mutex_test.h"
|
||||
|
||||
#define MODULE_NAME "mutex_reinit"
|
||||
|
||||
static uint8_t mutex_reinit_case(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mutex_create(&test_mutex, MODULE_NAME);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
test_mutex.blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
test_mutex.blk_obj.obj_type = RHINO_MUTEX_OBJ_TYPE;
|
||||
ret = krhino_mutex_lock(&test_mutex, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
test_mutex.blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
ret = krhino_mutex_unlock(&test_mutex);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
test_mutex.blk_obj.obj_type = RHINO_MUTEX_OBJ_TYPE;
|
||||
ret = krhino_mutex_unlock(&test_mutex);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_del(&test_mutex);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t mutex_func_runner[] = {
|
||||
mutex_reinit_case,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mutex_reinit_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_mutex_entry_register(MODULE_NAME, (test_func_t *)mutex_func_runner,
|
||||
sizeof(mutex_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_mutex, MODULE_NAME, 0, TASK_MUTEX_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_mutex_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
83
Living_SDK/kernel/rhino/test/core/mutex/mutex_test.c
Normal file
83
Living_SDK/kernel/rhino/test/core/mutex/mutex_test.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "mutex_test.h"
|
||||
|
||||
ktask_t *task_mutex;
|
||||
ktask_t *task_mutex_co1;
|
||||
ktask_t *task_mutex_co2;
|
||||
ktask_t *task_mutex_co3;
|
||||
kmutex_t *test_mutex_dyn;
|
||||
kmutex_t test_mutex;
|
||||
kmutex_t test_mutex_co1;
|
||||
kmutex_t test_mutex_co2;
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t mutex_case_runner[] = {
|
||||
mutex_param_test,
|
||||
mutex_reinit_test,
|
||||
mutex_opr_test,
|
||||
mutex_coopr1_test,
|
||||
mutex_coopr2_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void mutex_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)mutex_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_mutex_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_mutex_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
35
Living_SDK/kernel/rhino/test/core/mutex/mutex_test.h
Normal file
35
Living_SDK/kernel/rhino/test/core/mutex/mutex_test.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef MUTEX_TEST_H
|
||||
#define MUTEX_TEST_H
|
||||
|
||||
#define TASK_MUTEX_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do {if ((int)(value) == 0) { printf("line:%d\n", __LINE__);return 1; }} while (0)
|
||||
|
||||
extern ktask_t *task_mutex;
|
||||
extern ktask_t *task_mutex_co1;
|
||||
extern ktask_t *task_mutex_co2;
|
||||
extern ktask_t *task_mutex_co3;
|
||||
extern kmutex_t *test_mutex_dyn;
|
||||
extern kmutex_t test_mutex;
|
||||
extern kmutex_t test_mutex_co1;
|
||||
extern kmutex_t test_mutex_co2;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_mutex_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casnum);
|
||||
void task_mutex_entry(void *arg);
|
||||
void mutex_test(void);
|
||||
void mutex_param_test(void);
|
||||
void mutex_opr_test(void);
|
||||
void mutex_reinit_test(void);
|
||||
void mutex_coopr1_test(void);
|
||||
void mutex_coopr2_test(void);
|
||||
|
||||
#endif /* MUTEX_TEST_H */
|
||||
|
||||
119
Living_SDK/kernel/rhino/test/core/queue/queue_back_send.c
Normal file
119
Living_SDK/kernel/rhino/test/core/queue/queue_back_send.c
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "queue_test.h"
|
||||
|
||||
#define TEST_QUEUE_MSG0_SIZE 30
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktask_t *task_1_test;
|
||||
static void *queue_send_msg = (void *)1;
|
||||
static void *queue_recv_msg = (void *)1;
|
||||
static kqueue_t *g_test_queue0;
|
||||
|
||||
static void queue_back_send_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_queue_back_send(NULL, queue_send_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(&sem, "test_sem ", 0);
|
||||
ret = krhino_queue_back_send((kqueue_t *)&sem, queue_send_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void krhino_queue_dyn_create_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_queue_dyn_create(NULL, "test_queue0", TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
}
|
||||
|
||||
static void krhino_queue_dyn_del_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_queue_dyn_del(NULL);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_queue_del(g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
krhino_sem_create(&sem, "test_sem ", 0);
|
||||
ret = krhino_queue_dyn_del((kqueue_t *)&sem);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
/* check krhino_queue_back_send param */
|
||||
queue_back_send_param_test();
|
||||
|
||||
/* check krhino_queue_back_send */
|
||||
ret = krhino_queue_recv(g_test_queue0, RHINO_WAIT_FOREVER, &queue_recv_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
if (queue_recv_msg == queue_send_msg) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("queue back send", PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("queue back send", FAIL);
|
||||
}
|
||||
|
||||
krhino_queue_dyn_del_param_test();
|
||||
ret = krhino_queue_dyn_del(g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_queue1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
/* check krhino_queue_back_send */
|
||||
ret = krhino_queue_back_send(g_test_queue0, queue_send_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
krhino_task_dyn_del(task_1_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_queue_back_send_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
krhino_queue_dyn_create_param_test();
|
||||
|
||||
ret = krhino_queue_dyn_create(&g_test_queue0, "test_queue0",
|
||||
TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_queue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_1_test, "task_queue1_test", 0, 11,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue1_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
65
Living_SDK/kernel/rhino/test/core/queue/queue_del.c
Normal file
65
Living_SDK/kernel/rhino/test/core/queue/queue_del.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "queue_test.h"
|
||||
|
||||
#define TEST_QUEUE_MSG0_SIZE 1
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static void *queue_recv_msg = (void *)1;
|
||||
static void *g_test_queue_msg0[TEST_QUEUE_MSG0_SIZE];
|
||||
static kqueue_t g_test_queue0;
|
||||
|
||||
static void queue_del_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_queue_del(NULL);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_queue_dyn_del(&g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
krhino_sem_create(&sem, "test_sem ", 0);
|
||||
ret = krhino_queue_del((kqueue_t *)&sem);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_queue_create(&g_test_queue0, "test_queue0",
|
||||
(void **)&g_test_queue_msg0, TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check krhino_queue_del param */
|
||||
queue_del_param_test();
|
||||
|
||||
ret = krhino_queue_del(&g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_queue_del_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_queue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
81
Living_SDK/kernel/rhino/test/core/queue/queue_flush.c
Normal file
81
Living_SDK/kernel/rhino/test/core/queue/queue_flush.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "queue_test.h"
|
||||
|
||||
#define TEST_QUEUE_MSG0_SIZE 1
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static void *queue_send_msg = (void *)1;
|
||||
static void *g_test_queue_msg0[TEST_QUEUE_MSG0_SIZE];
|
||||
static kqueue_t g_test_queue0;
|
||||
|
||||
static void queue_flush_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_queue_flush(NULL);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(&sem, "test_sem ", 0);
|
||||
ret = krhino_queue_flush((kqueue_t *)&sem);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_queue_create(&g_test_queue0, "test_queue0",
|
||||
(void **)&g_test_queue_msg0, TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check krhino_queue_flush param */
|
||||
queue_flush_param_test();
|
||||
|
||||
ret = krhino_queue_is_full(&g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_QUEUE_NOT_FULL);
|
||||
|
||||
ret = krhino_queue_back_send(&g_test_queue0, queue_send_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_is_full(&g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_QUEUE_FULL);
|
||||
|
||||
ret = krhino_queue_flush(&g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_is_full(&g_test_queue0);
|
||||
if (ret == RHINO_QUEUE_NOT_FULL) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("queue flush", PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("queue flush", PASS);
|
||||
}
|
||||
|
||||
krhino_queue_del(&g_test_queue0);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_queue_flush_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_queue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
123
Living_SDK/kernel/rhino/test/core/queue/queue_info_get.c
Normal file
123
Living_SDK/kernel/rhino/test/core/queue/queue_info_get.c
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "queue_test.h"
|
||||
|
||||
#define TEST_QUEUE_MSG0_SIZE 2
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktask_t *task_1_test;
|
||||
static void *queue_send_msg = (void *)1;
|
||||
static void *queue_recv_msg = (void *)1;
|
||||
static void *g_test_queue_msg0[TEST_QUEUE_MSG0_SIZE];
|
||||
static kqueue_t g_test_queue0;
|
||||
|
||||
static void print_queue_info(msg_info_t *info)
|
||||
{
|
||||
#if 0
|
||||
printf("\nqueue info:\n");
|
||||
printf("msg_q.peak_num: 0x%x\n", (uint32_t)info->msg_q.peak_num);
|
||||
printf("msg_q.cur_num: 0x%x\n", (uint32_t)info->msg_q.cur_num);
|
||||
printf("msg_q.queue_start: 0x%x\n", (uint32_t)info->msg_q.queue_start);
|
||||
printf("msg_q.queue_end: 0x%x\n", (uint32_t)info->msg_q.queue_end);
|
||||
printf("msg_q.read: 0x%x\n", (uint32_t)info->msg_q.read);
|
||||
printf("msg_q.write: 0x%x\n", (uint32_t)info->msg_q.write);
|
||||
printf("msg_q.size: 0x%x\n", (uint32_t)info->msg_q.size);
|
||||
printf("pend_entry: 0x%x\n", (uint32_t)info->pend_entry);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void queue_info_get_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
msg_info_t info0;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_queue_info_get(NULL, &info0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_queue_info_get(&g_test_queue0, NULL);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(&sem, "test_sem ", 0);
|
||||
ret = krhino_queue_info_get((kqueue_t *)&sem, &info0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
msg_info_t info0;
|
||||
msg_info_t info1;
|
||||
|
||||
while (1) {
|
||||
/* check krhino_info_get param */
|
||||
queue_info_get_param_test();
|
||||
|
||||
ret = krhino_queue_info_get(&g_test_queue0, &info0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
print_queue_info(&info0);
|
||||
|
||||
ret = krhino_queue_recv(&g_test_queue0, RHINO_WAIT_FOREVER, &queue_recv_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_info_get(&g_test_queue0, &info1);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
print_queue_info(&info1);
|
||||
|
||||
krhino_task_sleep(10);
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT("queue info get", PASS);
|
||||
|
||||
krhino_queue_del(&g_test_queue0);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_queue1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
msg_info_t info0;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_queue_back_send(&g_test_queue0, queue_send_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_back_send(&g_test_queue0, queue_send_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_info_get(&g_test_queue0, &info0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
print_queue_info(&info0);
|
||||
|
||||
krhino_task_dyn_del(task_1_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_queue_info_get_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_queue_create(&g_test_queue0, "test_queue0",
|
||||
(void **)&g_test_queue_msg0, TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_queue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_1_test, "task_queue1_test", 0, 11,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue1_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
75
Living_SDK/kernel/rhino/test/core/queue/queue_is_full.c
Normal file
75
Living_SDK/kernel/rhino/test/core/queue/queue_is_full.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "queue_test.h"
|
||||
|
||||
#define TEST_QUEUE_MSG0_SIZE 1
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static void *queue_send_msg = (void *)1;
|
||||
static void *g_test_queue_msg0[TEST_QUEUE_MSG0_SIZE];
|
||||
static kqueue_t g_test_queue0;
|
||||
|
||||
static void queue_is_full_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_queue_is_full(NULL);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(&sem, "test_sem ", 0);
|
||||
ret = krhino_queue_is_full((kqueue_t *)&sem);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_queue_create(&g_test_queue0, "test_queue0",
|
||||
(void **)&g_test_queue_msg0, TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check krhino_queue_is_full param */
|
||||
queue_is_full_param_test();
|
||||
|
||||
ret = krhino_queue_is_full(&g_test_queue0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_QUEUE_NOT_FULL);
|
||||
|
||||
ret = krhino_queue_back_send(&g_test_queue0, queue_send_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_is_full(&g_test_queue0);
|
||||
if (ret == RHINO_QUEUE_FULL) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("queue is full", PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("queue is full", FAIL);
|
||||
}
|
||||
|
||||
krhino_queue_del(&g_test_queue0);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_queue_is_full_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_queue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
97
Living_SDK/kernel/rhino/test/core/queue/queue_nowait_recv.c
Normal file
97
Living_SDK/kernel/rhino/test/core/queue/queue_nowait_recv.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "queue_test.h"
|
||||
|
||||
#define TEST_QUEUE_MSG0_SIZE 1
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static void *queue_recv_msg = (void *)1;
|
||||
static void *g_test_queue_msg0[TEST_QUEUE_MSG0_SIZE];
|
||||
static kqueue_t g_test_queue0;
|
||||
|
||||
static void queue_create_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_queue_create(NULL, "test_queue0", (void **)&g_test_queue_msg0,
|
||||
TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_queue_create(&g_test_queue0, NULL, (void **)&g_test_queue_msg0,
|
||||
TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_queue_create(&g_test_queue0, "test_queue0", NULL,
|
||||
TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_queue_create(&g_test_queue0, "test_queue0",
|
||||
(void **)&g_test_queue_msg0, 0);
|
||||
QUEUE_VAL_CHK(ret == RHINO_INV_PARAM);
|
||||
}
|
||||
|
||||
static void queue_recv_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ksem_t sem;
|
||||
|
||||
ret = krhino_queue_recv(NULL, RHINO_NO_WAIT, &queue_recv_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_queue_recv(&g_test_queue0, RHINO_NO_WAIT, NULL);
|
||||
QUEUE_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sem_create(&sem, "test_sem ", 0);
|
||||
ret = krhino_queue_recv((kqueue_t *)&sem, RHINO_WAIT_FOREVER, &queue_recv_msg);
|
||||
QUEUE_VAL_CHK(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
krhino_sem_del(&sem);
|
||||
}
|
||||
|
||||
static void task_queue0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_queue_create(&g_test_queue0, "test_queue0",
|
||||
(void **)&g_test_queue_msg0, TEST_QUEUE_MSG0_SIZE);
|
||||
QUEUE_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
/* check krhino_queue_create param */
|
||||
queue_create_param_test();
|
||||
|
||||
/* check krhino_queue_recv param */
|
||||
queue_recv_param_test();
|
||||
|
||||
ret = krhino_queue_recv(&g_test_queue0, RHINO_NO_WAIT, &queue_recv_msg);
|
||||
|
||||
if (ret == RHINO_NO_PEND_WAIT) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("queue nowait recv", PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("queue nowait recv", FAIL);
|
||||
}
|
||||
|
||||
krhino_queue_del(&g_test_queue0);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_queue_nowait_recv_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_queue0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_queue0_entry, 1);
|
||||
QUEUE_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
30
Living_SDK/kernel/rhino/test/core/queue/queue_test.c
Normal file
30
Living_SDK/kernel/rhino/test/core/queue/queue_test.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "queue_test.h"
|
||||
|
||||
void queue_test(void)
|
||||
{
|
||||
task_queue_back_send_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_queue_nowait_recv_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_queue_is_full_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_queue_flush_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_queue_del_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_queue_info_get_test();
|
||||
next_test_case_wait();
|
||||
}
|
||||
|
||||
22
Living_SDK/kernel/rhino/test/core/queue/queue_test.h
Normal file
22
Living_SDK/kernel/rhino/test/core/queue/queue_test.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef QUEUE_TEST_H
|
||||
#define QUEUE_TEST_H
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 256
|
||||
|
||||
#define QUEUE_VAL_CHK(value) do {if ((int)(value) == 0) \
|
||||
{printf("queue test is [FAIL %d], func %s, line %d\n", \
|
||||
(int)++test_case_fail,__FUNCTION__, __LINE__);}}while(0)
|
||||
|
||||
kstat_t task_queue_back_send_test(void);
|
||||
kstat_t task_queue_nowait_recv_test(void);
|
||||
kstat_t task_queue_notify_set_test(void);
|
||||
kstat_t task_queue_is_full_test(void);
|
||||
kstat_t task_queue_flush_test(void);
|
||||
kstat_t task_queue_del_test(void);
|
||||
kstat_t task_queue_info_get_test(void);
|
||||
|
||||
#endif /* QUEUE_TEST_H */
|
||||
402
Living_SDK/kernel/rhino/test/core/ringbuf/ringbuf_break.c
Normal file
402
Living_SDK/kernel/rhino/test/core/ringbuf/ringbuf_break.c
Normal file
|
|
@ -0,0 +1,402 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <k_ringbuf.h>
|
||||
#include <test_fw.h>
|
||||
#include "ringbuf_test.h"
|
||||
|
||||
#define MODULE_NAME "ringbuf_break"
|
||||
|
||||
#define RINGBUF_SIZE_SMALL 16
|
||||
#define RINGBUF_SIZE_MIDDLE (256+16)
|
||||
#define RINGBUF_SIZE_BIG (16384 * 2 + 32)
|
||||
|
||||
#define RINGBUF_FIX_LEN 4
|
||||
|
||||
#if (RHINO_CONFIG_RINGBUF_VENDOR > 0)
|
||||
|
||||
static k_ringbuf_t g_fix_ringbuf;
|
||||
static k_ringbuf_t g_dyn_ringbuf;
|
||||
|
||||
static char *push_data[] = {
|
||||
"1111",
|
||||
"2222",
|
||||
"3333",
|
||||
"4444",
|
||||
"5555",
|
||||
"6666"
|
||||
};
|
||||
uint8_t ringbuf_small_buf[RINGBUF_SIZE_SMALL];
|
||||
uint8_t ringbuf_middle_buf[RINGBUF_SIZE_MIDDLE];
|
||||
uint8_t dyn_data_big_buf[RINGBUF_SIZE_BIG];
|
||||
|
||||
uint8_t dyn_data_small[RINGBUF_SIZE_SMALL / 2 - 2];
|
||||
uint8_t dyn_data_middle[RINGBUF_SIZE_MIDDLE];
|
||||
uint8_t dyn_data_big_rev[RINGBUF_SIZE_BIG];
|
||||
uint8_t dyn_data_big[RINGBUF_SIZE_BIG];
|
||||
|
||||
#endif
|
||||
|
||||
static uint8_t ringbuf_break_case_fix(void)
|
||||
{
|
||||
#if (RHINO_CONFIG_RINGBUF_VENDOR > 0)
|
||||
kstat_t ret;
|
||||
uint8_t rev[RINGBUF_FIX_LEN];
|
||||
size_t len;
|
||||
size_t i = 0;
|
||||
|
||||
ret = krhino_ringbuf_init(NULL, NULL, 0, 0, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_fix_ringbuf, NULL, 0, RINGBUF_TYPE_FIX, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_fix_ringbuf, (void *)ringbuf_small_buf, 0,
|
||||
RINGBUF_TYPE_FIX, 0);
|
||||
MYASSERT(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_fix_ringbuf, (void *)ringbuf_small_buf,
|
||||
sizeof(ringbuf_small_buf), 3, 0);
|
||||
MYASSERT(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_fix_ringbuf, (void *)ringbuf_small_buf,
|
||||
sizeof(ringbuf_small_buf), RINGBUF_TYPE_FIX, 0);
|
||||
MYASSERT(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_fix_ringbuf, (void *)ringbuf_small_buf,
|
||||
sizeof(ringbuf_small_buf), RINGBUF_TYPE_FIX, RINGBUF_FIX_LEN);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(NULL, NULL, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, NULL, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[0], 1);
|
||||
MYASSERT(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[0], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(NULL, NULL, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_fix_ringbuf, NULL, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_fix_ringbuf, (void *)&rev[0], 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = memcmp(rev, push_data[0], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
/*empty now,push full */
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[1], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[1], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[2], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[3], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
/* test ringbuf full */
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[4], 4);
|
||||
MYASSERT(ret == RHINO_RINGBUF_FULL);
|
||||
|
||||
ret = krhino_ringbuf_is_full(&g_fix_ringbuf);
|
||||
MYASSERT(ret == true);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_fix_ringbuf, (void *)&rev[0], NULL);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = memcmp(rev, (uint8_t *)push_data[1], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[4], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_fix_ringbuf, (void *)&rev[0], &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = memcmp(rev, (uint8_t *)push_data[1], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
/* test tail==end */
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[5], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_fix_ringbuf, (void *)&rev[0], &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = memcmp(rev, (uint8_t *)push_data[2], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
ret = krhino_ringbuf_push(&g_fix_ringbuf, (void *)push_data[0], 4);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_fix_ringbuf, (void *)&rev[0], &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
ret = krhino_ringbuf_reset(&g_fix_ringbuf);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_is_empty(&g_fix_ringbuf);
|
||||
MYASSERT(ret == true);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
static uint8_t ringbuf_break_case_dyn(void)
|
||||
{
|
||||
#if (RHINO_CONFIG_RINGBUF_VENDOR > 0)
|
||||
kstat_t ret;
|
||||
size_t data_len;
|
||||
size_t len;
|
||||
size_t i = 0;
|
||||
|
||||
memset(dyn_data_small, '1', sizeof(dyn_data_small));
|
||||
memset(dyn_data_middle, '2', sizeof(dyn_data_middle));
|
||||
|
||||
ret = krhino_ringbuf_init(NULL, NULL, 0, 0, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
/* small buffer test */
|
||||
ret = krhino_ringbuf_init(&g_dyn_ringbuf, NULL, 0, RINGBUF_TYPE_DYN, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_dyn_ringbuf, ringbuf_small_buf, 0, RINGBUF_TYPE_DYN,
|
||||
0);
|
||||
MYASSERT(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_dyn_ringbuf, ringbuf_small_buf, RINGBUF_SIZE_SMALL,
|
||||
3, 0);
|
||||
MYASSERT(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_ringbuf_init(&g_dyn_ringbuf, ringbuf_small_buf, RINGBUF_SIZE_SMALL,
|
||||
RINGBUF_TYPE_DYN, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_small,
|
||||
sizeof(dyn_data_small));
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, NULL, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, NULL);
|
||||
MYASSERT(ret == RHINO_INV_PARAM);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == sizeof(dyn_data_small));
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_RINGBUF_EMPTY);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_small,
|
||||
sizeof(dyn_data_small));
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_small,
|
||||
sizeof(dyn_data_small));
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_small,
|
||||
sizeof(dyn_data_small));
|
||||
MYASSERT(ret == RHINO_RINGBUF_FULL);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == sizeof(dyn_data_small));
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_small,
|
||||
sizeof(dyn_data_small));
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == sizeof(dyn_data_small));
|
||||
|
||||
/* middle buffer */
|
||||
ret = krhino_ringbuf_init(&g_dyn_ringbuf, ringbuf_middle_buf,
|
||||
RINGBUF_SIZE_MIDDLE, RINGBUF_TYPE_DYN, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
data_len = sizeof(dyn_data_middle) - 2;
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_is_full(&g_dyn_ringbuf);
|
||||
MYASSERT(ret == true);
|
||||
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
data_len = sizeof(dyn_data_middle) / 2 - 4;
|
||||
|
||||
memset(dyn_data_middle, '3', sizeof(dyn_data_middle));
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_RINGBUF_EMPTY);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(dyn_data_middle, '5', sizeof(dyn_data_middle));
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(dyn_data_middle, '4', sizeof(dyn_data_middle));
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_RINGBUF_FULL);
|
||||
|
||||
memset(dyn_data_middle, '5', sizeof(dyn_data_middle));
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(dyn_data_middle, '6', sizeof(dyn_data_middle));
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, (void *)dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(dyn_data_middle, '4', sizeof(dyn_data_middle));
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
memset(dyn_data_middle, '6', sizeof(dyn_data_middle));
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_reset(&g_dyn_ringbuf);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
/* random test */
|
||||
for (i = 0; i < 5; ++i) {
|
||||
data_len = sizeof(dyn_data_middle) / 2 - i;
|
||||
memset(dyn_data_middle, i, sizeof(dyn_data_middle));
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_middle, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
/* big data test */
|
||||
|
||||
memset(dyn_data_big, '3', RINGBUF_SIZE_BIG);
|
||||
|
||||
|
||||
ret = krhino_ringbuf_init(&g_dyn_ringbuf, dyn_data_big_buf, RINGBUF_SIZE_BIG,
|
||||
RINGBUF_TYPE_DYN, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
data_len = sizeof(dyn_data_big_buf) - 4;
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, (void *)dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
data_len = sizeof(dyn_data_big_buf) / 2 - 4;
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, (void *)dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
ret = memcmp(dyn_data_big_rev, dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_RINGBUF_EMPTY);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, (void *)dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, (void *)dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, (void *)dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_RINGBUF_FULL);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
|
||||
ret = krhino_ringbuf_push(&g_dyn_ringbuf, (void *)dyn_data_big, data_len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_ringbuf_pop(&g_dyn_ringbuf, dyn_data_big_rev, &len);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(len == data_len);
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t ringbuf_func_runner[] = {
|
||||
ringbuf_break_case_fix,
|
||||
ringbuf_break_case_dyn,
|
||||
NULL
|
||||
};
|
||||
|
||||
void ringbuf_break_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_ringbuf_entry_register(MODULE_NAME, (test_func_t *)ringbuf_func_runner,
|
||||
sizeof(ringbuf_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_ringbuf, MODULE_NAME, 0, TASK_RINGBUF_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_ringbuf_entry, 1);
|
||||
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
76
Living_SDK/kernel/rhino/test/core/ringbuf/ringbuf_test.c
Normal file
76
Living_SDK/kernel/rhino/test/core/ringbuf/ringbuf_test.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <k_ringbuf.h>
|
||||
#include <test_fw.h>
|
||||
#include "ringbuf_test.h"
|
||||
|
||||
ktask_t *task_ringbuf;
|
||||
ktask_t *task_ringbuf_co;
|
||||
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t ringbuf_case_runner[] = {
|
||||
ringbuf_break_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void ringbuf_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)ringbuf_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_ringbuf_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_ringbuf_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
25
Living_SDK/kernel/rhino/test/core/ringbuf/ringbuf_test.h
Normal file
25
Living_SDK/kernel/rhino/test/core/ringbuf/ringbuf_test.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef RINGBUF_TEST_H
|
||||
#define RINGBUF_TEST_H
|
||||
|
||||
#define TASK_RINGBUF_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do {if ((value) == 0) { printf("%s:%d\n", __FUNCTION__, __LINE__); }} while (0)
|
||||
|
||||
extern ktask_t *task_ringbuf;
|
||||
extern ktask_t *task_ringbuf_co;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_ringbuf_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum);
|
||||
void task_ringbuf_entry(void *arg);
|
||||
void ringbuf_test(void);
|
||||
void ringbuf_break_test(void);
|
||||
|
||||
#endif /* RINGBUF_TEST_H */
|
||||
|
||||
50
Living_SDK/kernel/rhino/test/core/sem/sem_break.c
Normal file
50
Living_SDK/kernel/rhino/test/core/sem/sem_break.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sem_test.h"
|
||||
|
||||
#define MODULE_NAME "sem_break"
|
||||
|
||||
static uint8_t sem_break_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
/* try to delete after change it */
|
||||
test_sem->blk_obj.obj_type = RHINO_EVENT_OBJ_TYPE;
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
/* try to delete after recover it */
|
||||
test_sem->blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t sem_func_runner[] = {
|
||||
sem_break_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sem_break_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_sem_entry_register(MODULE_NAME, (test_func_t *)sem_func_runner,
|
||||
sizeof(sem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
69
Living_SDK/kernel/rhino/test/core/sem/sem_count.c
Normal file
69
Living_SDK/kernel/rhino/test/core/sem/sem_count.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sem_test.h"
|
||||
|
||||
#define MODULE_NAME "sem_count"
|
||||
|
||||
static uint8_t sem_count_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
sem_count_t cnt;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 3);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_sem->count == 3);
|
||||
MYASSERT(test_sem->peak_count == 3);
|
||||
|
||||
ret = krhino_sem_count_get(test_sem, &cnt);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(cnt == 3);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_count_get(test_sem, &cnt);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(cnt == 2);
|
||||
|
||||
test_sem->blk_obj.obj_type = RHINO_MUTEX_OBJ_TYPE;
|
||||
ret = krhino_sem_count_set(test_sem, 8);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
test_sem->blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
ret = krhino_sem_count_set(test_sem, 8);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_count_get(test_sem, &cnt);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(cnt == 8);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t sem_func_runner[] = {
|
||||
sem_count_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sem_count_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_sem_entry_register(MODULE_NAME, (test_func_t *)sem_func_runner,
|
||||
sizeof(sem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
233
Living_SDK/kernel/rhino/test/core/sem/sem_opr.c
Normal file
233
Living_SDK/kernel/rhino/test/core/sem/sem_opr.c
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sem_test.h"
|
||||
|
||||
#define MODULE_NAME "sem_opr"
|
||||
#define MODULE_NAME_CO1 "sem_coopr1"
|
||||
#define MODULE_NAME_CO2 "sem_coopr2"
|
||||
|
||||
#define LOOP_CNT 8
|
||||
|
||||
static uint8_t sem_opr_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
sem_count_t cnt;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 3);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give_all(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_count_get(test_sem, &cnt);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(cnt == 3);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t sem_func_runner[] = {
|
||||
sem_opr_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sem_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_sem_entry_register(MODULE_NAME, (test_func_t *)sem_func_runner,
|
||||
sizeof(sem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_entry, 1);
|
||||
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_sem_coopr1_co1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint8_t cnt = 0;
|
||||
|
||||
krhino_sem_take(test_sem, 100);
|
||||
krhino_sem_take(test_sem, 100);
|
||||
krhino_sem_take(test_sem, 100);
|
||||
|
||||
while (1) {
|
||||
ret = krhino_sem_take(test_sem, RHINO_WAIT_FOREVER);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
cnt++;
|
||||
|
||||
if (cnt >= LOOP_CNT) {
|
||||
krhino_sem_count_set(test_sem, 16);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, PASS);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_sem_coopr1_co2_entry(void *arg)
|
||||
{
|
||||
uint8_t cnt = 0;
|
||||
sem_count_t sem_cnt;
|
||||
|
||||
while (1) {
|
||||
if (cnt < LOOP_CNT) {
|
||||
cnt++;
|
||||
krhino_sem_give(test_sem);
|
||||
} else {
|
||||
krhino_sem_count_get(test_sem, &sem_cnt);
|
||||
|
||||
if (sem_cnt == 16) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
krhino_sem_dyn_del(test_sem);
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void sem_coopr1_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 3);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem_co1, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_coopr1_co1_entry, 1);
|
||||
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
}
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem_co2, MODULE_NAME, 0, TASK_SEM_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_coopr1_co2_entry, 1);
|
||||
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_sem_coopr2_co1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_take(test_sem_co1, RHINO_WAIT_FOREVER);
|
||||
|
||||
TEST_FW_VAL_CHK(MODULE_NAME_CO2, ret == RHINO_SUCCESS);
|
||||
|
||||
if (test_case_check_err > 0) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO2, FAIL);
|
||||
} else {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME_CO2, PASS);
|
||||
}
|
||||
|
||||
krhino_sem_dyn_del(test_sem_co1);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_sem_coopr2_co2_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
/* no task block on the semaphore and wait notification from other task */
|
||||
krhino_task_sleep(5);
|
||||
ret = krhino_sem_take(test_sem_co2, RHINO_NO_WAIT);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
krhino_sem_give(test_sem_co1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
krhino_sem_dyn_del(test_sem_co2);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_sem_coopr2_co3_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
while (1) {
|
||||
ret = krhino_sem_give(test_sem_co2);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void sem_coopr2_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
test_case_check_err = 0;
|
||||
|
||||
krhino_sem_dyn_create(&test_sem_co1, MODULE_NAME, 0);
|
||||
krhino_sem_dyn_create(&test_sem_co2, MODULE_NAME, 0);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_coopr2_co1_entry, 1);
|
||||
|
||||
TEST_FW_VAL_CHK(MODULE_NAME_CO2, ret == RHINO_SUCCESS);
|
||||
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem_co1, MODULE_NAME, 0, TASK_SEM_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_coopr2_co2_entry, 1);
|
||||
|
||||
TEST_FW_VAL_CHK(MODULE_NAME_CO2, ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem_co2, MODULE_NAME, 0, TASK_SEM_PRI + 2,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_coopr2_co3_entry, 1);
|
||||
TEST_FW_VAL_CHK(MODULE_NAME_CO2, ret == RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
170
Living_SDK/kernel/rhino/test/core/sem/sem_param.c
Normal file
170
Living_SDK/kernel/rhino/test/core/sem/sem_param.c
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sem_test.h"
|
||||
|
||||
#define MODULE_NAME "sem_param"
|
||||
|
||||
static uint8_t sem_param_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_dyn_create(NULL, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, NULL, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, (sem_count_t) - 1);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_dyn_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
test_sem->mm_alloc_flag = K_OBJ_STATIC_ALLOC;
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
test_sem->mm_alloc_flag = K_OBJ_DYN_ALLOC;
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_create(&test_sem_ext, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
test_sem_ext.blk_obj.obj_type = RHINO_MUTEX_OBJ_TYPE;
|
||||
ret = krhino_sem_del(&test_sem_ext);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
test_sem_ext.blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
test_sem_ext.mm_alloc_flag = K_OBJ_DYN_ALLOC;
|
||||
ret = krhino_sem_del(&test_sem_ext);
|
||||
MYASSERT(ret == RHINO_KOBJ_DEL_ERR);
|
||||
|
||||
test_sem_ext.mm_alloc_flag = K_OBJ_STATIC_ALLOC;
|
||||
ret = krhino_sem_del(&test_sem_ext);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t sem_param_case2(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
CPSR_ALLOC();
|
||||
sem_count_t count_old;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(NULL, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_sem_give(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
krhino_sched_disable();
|
||||
ret = krhino_sem_take(test_sem, RHINO_WAIT_FOREVER);
|
||||
krhino_sched_enable();
|
||||
MYASSERT(ret == RHINO_SCHED_DISABLE);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
count_old = test_sem->count;
|
||||
test_sem->count = -1;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SEM_OVF);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_sem->count = count_old;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_sem->blk_obj.obj_type = RHINO_MUTEX_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_sem_take(test_sem, RHINO_WAIT_FOREVER);
|
||||
MYASSERT(ret == RHINO_KOBJ_TYPE_ERR);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
test_sem->blk_obj.obj_type = RHINO_SEM_OBJ_TYPE;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
ret = krhino_sem_give_all(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t sem_param_case3(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t sem_param_case4(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
sem_count_t count;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_count_get(NULL, &count);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_sem_count_get(test_sem, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_sem_count_set(NULL, 2);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_sem_count_set(test_sem, (sem_count_t) - 1);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t sem_func_runner[] = {
|
||||
sem_param_case1,
|
||||
sem_param_case2,
|
||||
sem_param_case3,
|
||||
sem_param_case4,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sem_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_sem_entry_register(MODULE_NAME, (test_func_t *)sem_func_runner,
|
||||
sizeof(sem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
120
Living_SDK/kernel/rhino/test/core/sem/sem_reinit.c
Normal file
120
Living_SDK/kernel/rhino/test/core/sem/sem_reinit.c
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sem_test.h"
|
||||
|
||||
#define MODULE_NAME "sem_reinit"
|
||||
|
||||
static uint8_t sem_reinit_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 3);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
MYASSERT(test_sem->count == 3);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_sem->count == 4);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t sem_reinit_case2(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_sem_dyn_create(&test_sem, MODULE_NAME, 3);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_sem->count == 3);
|
||||
MYASSERT(test_sem->peak_count == 3);
|
||||
MYASSERT(test_sem->blk_obj.obj_type == RHINO_SEM_OBJ_TYPE);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(test_sem, RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
MYASSERT(test_sem->count == 3);
|
||||
|
||||
ret = krhino_sem_give(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(test_sem->count == 4);
|
||||
|
||||
ret = krhino_sem_dyn_del(test_sem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t sem_func_runner[] = {
|
||||
sem_reinit_case1,
|
||||
sem_reinit_case2,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sem_reinit_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_sem_entry_register(MODULE_NAME, (test_func_t *)sem_func_runner,
|
||||
sizeof(sem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sem_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, PASS);
|
||||
}
|
||||
}
|
||||
|
||||
84
Living_SDK/kernel/rhino/test/core/sem/sem_test.c
Normal file
84
Living_SDK/kernel/rhino/test/core/sem/sem_test.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sem_test.h"
|
||||
|
||||
ktask_t *task_sem;
|
||||
ktask_t *task_sem_co1;
|
||||
ktask_t *task_sem_co2;
|
||||
ksem_t *test_sem;
|
||||
ksem_t test_sem_ext;
|
||||
ksem_t *test_sem_co1;
|
||||
ksem_t *test_sem_co2;
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t sem_case_runner[] = {
|
||||
sem_param_test,
|
||||
sem_break_test,
|
||||
sem_reinit_test,
|
||||
sem_count_test,
|
||||
sem_opr_test,
|
||||
sem_coopr1_test,
|
||||
sem_coopr2_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sem_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)sem_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_sem_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_sem_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
36
Living_SDK/kernel/rhino/test/core/sem/sem_test.h
Normal file
36
Living_SDK/kernel/rhino/test/core/sem/sem_test.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef SEM_TEST_H
|
||||
#define SEM_TEST_H
|
||||
|
||||
#define TASK_SEM_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do {if ((int)(value) == 0) { return 1; }} while (0)
|
||||
|
||||
extern ktask_t *task_sem;
|
||||
extern ktask_t *task_sem_co1;
|
||||
extern ktask_t *task_sem_co2;
|
||||
extern ksem_t *test_sem;
|
||||
extern ksem_t test_sem_ext;
|
||||
extern ksem_t *test_sem_co1;
|
||||
extern ksem_t *test_sem_co2;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_sem_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casnum);
|
||||
void task_sem_entry(void *arg);
|
||||
void sem_test(void);
|
||||
void sem_param_test(void);
|
||||
void sem_break_test(void);
|
||||
void sem_reinit_test(void);
|
||||
void sem_count_test(void);
|
||||
void sem_opr_test(void);
|
||||
void sem_coopr1_test(void);
|
||||
void sem_coopr2_test(void);
|
||||
|
||||
#endif /* SEM_TEST_H */
|
||||
|
||||
80
Living_SDK/kernel/rhino/test/core/sys/sys_opr.c
Normal file
80
Living_SDK/kernel/rhino/test/core/sys/sys_opr.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sys_test.h"
|
||||
|
||||
#define MODULE_NAME "sys_opr"
|
||||
|
||||
static uint8_t sys_opr_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t version;
|
||||
|
||||
version = krhino_version_get();
|
||||
if (version != RHINO_VERSION) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_start();
|
||||
if (ret != RHINO_RUNNING) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_sched_disable();
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* sched disable (out intrpt) */
|
||||
ret = krhino_sched_disable();
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_sched_enable();
|
||||
if (ret != RHINO_SCHED_DISABLE) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_sched_enable();
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_sched_enable();
|
||||
if (ret != RHINO_SCHED_ALREADY_ENABLED) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t sys_func_runner[] = {
|
||||
sys_opr_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sys_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_sys_entry_register(MODULE_NAME, (test_func_t *)sys_func_runner,
|
||||
sizeof(sys_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_sys, MODULE_NAME, 0, TASK_SYS_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_sys_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
72
Living_SDK/kernel/rhino/test/core/sys/sys_test.c
Normal file
72
Living_SDK/kernel/rhino/test/core/sys/sys_test.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "sys_test.h"
|
||||
|
||||
ktask_t *task_sys;
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t sys_case_runner[] = {
|
||||
sys_opr_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void sys_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)sys_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_sys_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_sys_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
24
Living_SDK/kernel/rhino/test/core/sys/sys_test.h
Normal file
24
Living_SDK/kernel/rhino/test/core/sys/sys_test.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef SYS_TEST_H
|
||||
#define SYS_TEST_H
|
||||
|
||||
#define TASK_SYS_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do { printf("ERROR: %s:%d, ERROR-NO: %d\n", __FUNCTION__, __LINE__, value); } while (0)
|
||||
|
||||
extern ktask_t *task_sys;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_sys_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum);
|
||||
void task_sys_entry(void *arg);
|
||||
void sys_test(void);
|
||||
void sys_opr_test(void);
|
||||
|
||||
#endif /* SYS_TEST_H */
|
||||
|
||||
74
Living_SDK/kernel/rhino/test/core/task/task_del.c
Normal file
74
Living_SDK/kernel/rhino/test/core/task/task_del.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 512
|
||||
#define LOOP_CNT 1
|
||||
|
||||
static ktask_t *task_del_test_0;
|
||||
static ktask_t *task_del_test_1;
|
||||
static ktask_t *task_del_test_2;
|
||||
|
||||
static void task_del_entry_0(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_task_dyn_del(NULL);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_del_entry_1(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_task_dyn_del(NULL);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_del_entry_2(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_task_dyn_del(NULL);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
void task_del_test()
|
||||
{
|
||||
test_case_check_err = 0;
|
||||
|
||||
if (krhino_task_dyn_create(&task_del_test_0, "task_del_test0", NULL, 7,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_del_entry_0, 1) != RHINO_SUCCESS) {
|
||||
test_case_check_err++;
|
||||
printf("task_del_test 0 creat fail \n");
|
||||
}
|
||||
|
||||
if (krhino_task_dyn_create(&task_del_test_1, "task_del_test1", NULL, 5,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_del_entry_1, 1) != RHINO_SUCCESS) {
|
||||
test_case_check_err++;
|
||||
printf("task_del_test1 creat fail \n");
|
||||
}
|
||||
|
||||
if (krhino_task_dyn_create(&task_del_test_2, "task_del_test2", NULL, 59,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_del_entry_2, 1) != RHINO_SUCCESS) {
|
||||
test_case_check_err++;
|
||||
printf("task_del_test2 creat fail \n");
|
||||
}
|
||||
|
||||
if (test_case_check_err != 0) {
|
||||
test_case_fail ++;
|
||||
PRINT_RESULT("task_del", FAIL);
|
||||
} else {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("task_del", PASS);
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
}
|
||||
|
||||
494
Living_SDK/kernel/rhino/test/core/task/task_misc_test.c
Normal file
494
Living_SDK/kernel/rhino/test/core/task/task_misc_test.c
Normal file
|
|
@ -0,0 +1,494 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 512
|
||||
static ktask_t *task_misc;
|
||||
static ktask_t task_misc2;
|
||||
static ktask_t *task_misc3;
|
||||
static ktask_t *task_misc4;
|
||||
|
||||
static ksem_t *sem;
|
||||
static ksem_t *sem2;
|
||||
static ksem_t *sem3;
|
||||
|
||||
static ksem_t *sem4;
|
||||
static kmutex_t *mutex4;
|
||||
static kevent_t *event4;
|
||||
static ktimer_t *timer4;
|
||||
static kbuf_queue_t *buf_queue4;
|
||||
static kqueue_t *queue4;
|
||||
|
||||
static kmutex_t mutex;
|
||||
|
||||
void task_misc_entry2(void *arg)
|
||||
{
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND / 10);
|
||||
|
||||
krhino_task_del(NULL);
|
||||
krhino_task_dyn_del(&task_misc2);
|
||||
krhino_task_del(&task_misc2);
|
||||
}
|
||||
|
||||
void task_misc_entry3(void *arg)
|
||||
{
|
||||
krhino_sem_dyn_create(&sem3, "sem_misc33", 0);
|
||||
krhino_sem_take(sem3, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_sched_disable();
|
||||
krhino_task_dyn_del(task_misc3);
|
||||
krhino_sched_enable();
|
||||
|
||||
krhino_task_dyn_del(task_misc3);
|
||||
}
|
||||
|
||||
void task_misc_entry4(void *arg)
|
||||
{
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
krhino_task_dyn_del(task_misc4);
|
||||
}
|
||||
|
||||
|
||||
static void timer_cb4(void *timer, void *arg)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void task_misc_entry(void *arg)
|
||||
{
|
||||
size_t task_free;
|
||||
uint8_t old_pri;
|
||||
kstat_t ret;
|
||||
uint8_t policy;
|
||||
void *info;
|
||||
cpu_stack_t *task_misc2_stack;
|
||||
ktask_t tmp;
|
||||
|
||||
CPSR_ALLOC();
|
||||
|
||||
krhino_task_resume(task_misc3);
|
||||
krhino_task_del(task_misc3);
|
||||
|
||||
krhino_sched_disable();
|
||||
krhino_task_suspend(krhino_cur_task_get());
|
||||
krhino_sched_enable();
|
||||
|
||||
krhino_task_suspend(NULL);
|
||||
|
||||
krhino_task_sleep(0);
|
||||
|
||||
krhino_sched_disable();
|
||||
krhino_task_sleep(1);
|
||||
krhino_sched_enable();
|
||||
|
||||
krhino_task_yield();
|
||||
|
||||
krhino_task_stack_min_free(NULL, &task_free);
|
||||
krhino_task_stack_min_free(task_misc, NULL);
|
||||
krhino_task_stack_min_free(task_misc, &task_free);
|
||||
|
||||
krhino_mutex_create(&mutex, "test");
|
||||
krhino_mutex_lock(&mutex, RHINO_WAIT_FOREVER);
|
||||
|
||||
ret = krhino_task_pri_change(task_misc, 15, &old_pri);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_pri_change", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_pri_change", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
krhino_mutex_unlock(&mutex);
|
||||
|
||||
ret = krhino_task_pri_change(NULL, 15, &old_pri);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_pri_change para 1", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_pri_change para 1", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_pri_change(task_misc, 15, NULL);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_pri_change para 2", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_pri_change para 2", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_pri_change(task_misc, RHINO_IDLE_PRI, &old_pri);
|
||||
|
||||
if (ret == RHINO_PRI_CHG_NOT_ALLOWED) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_pri_change para 3", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_pri_change para 3", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
task_misc2_stack = krhino_mm_alloc(TASK_TEST_STACK_SIZE);
|
||||
|
||||
if (task_misc2_stack == NULL) {
|
||||
|
||||
PRINT_RESULT("krhino_mm_alloc failed", FAIL);
|
||||
}
|
||||
|
||||
krhino_mutex_lock(&mutex, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_task_create(NULL, "task_misc2", NULL, 1,
|
||||
0, task_misc2_stack, TASK_TEST_STACK_SIZE / sizeof(cpu_stack_t),
|
||||
task_misc_entry2, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, NULL, NULL, 1,
|
||||
0, task_misc2_stack, TASK_TEST_STACK_SIZE / sizeof(cpu_stack_t),
|
||||
task_misc_entry2, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, "task_misc2", NULL, 1,
|
||||
0, task_misc2_stack, TASK_TEST_STACK_SIZE / sizeof(cpu_stack_t),
|
||||
NULL, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, "task_misc2", NULL, 1,
|
||||
0, NULL, TASK_TEST_STACK_SIZE / sizeof(cpu_stack_t),
|
||||
task_misc_entry2, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, "task_misc2", NULL, RHINO_CONFIG_PRI_MAX,
|
||||
0, task_misc2_stack, 0, task_misc_entry2, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, "task_misc2", NULL, RHINO_CONFIG_PRI_MAX,
|
||||
0, task_misc2_stack, 0, task_misc_entry2, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, "task_misc2", NULL, RHINO_CONFIG_PRI_MAX,
|
||||
0, task_misc2_stack, TASK_TEST_STACK_SIZE / sizeof(cpu_stack_t),
|
||||
task_misc_entry2, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, "task_misc2", NULL, RHINO_IDLE_PRI,
|
||||
50, task_misc2_stack, TASK_TEST_STACK_SIZE / sizeof(cpu_stack_t),
|
||||
task_misc_entry2, 1);
|
||||
|
||||
krhino_task_create(&task_misc2, "task_misc2", NULL, 1,
|
||||
50, task_misc2_stack, TASK_TEST_STACK_SIZE / sizeof(cpu_stack_t),
|
||||
task_misc_entry2, 1);
|
||||
|
||||
krhino_mutex_unlock(&mutex);
|
||||
|
||||
ret = krhino_task_time_slice_set(NULL, 30);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_time_slice_set para 1", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_time_slice_set para 1", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_time_slice_set(task_misc, 0);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_time_slice_set para 2", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_time_slice_set para 2", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_time_slice_set(task_misc, 20);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_time_slice_set para 3", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_time_slice_set para 3", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
krhino_sched_policy_set(task_misc, 0x11);
|
||||
|
||||
ret = krhino_sched_policy_set(task_misc, KSCHED_FIFO);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sched_policy_set para 1", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_sched_policy_set para 1", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_sched_policy_set(task_misc, KSCHED_RR);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sched_policy_set para 2", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_sched_policy_set para 2", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_sched_policy_set(NULL, KSCHED_RR);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sched_policy_set para 3", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_sched_policy_set para 3", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_sched_policy_get(NULL, &policy);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sched_policy_get para 1", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("ykrhino_sched_policy_get para 1", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_sched_policy_get(task_misc, NULL);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sched_policy_get para 2", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_sched_policy_get para 2", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_sched_policy_get(task_misc, &policy);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sched_policy_get para 3", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_sched_policy_get para 3", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
#define INFO_IDX (RHINO_CONFIG_TASK_INFO_NUM - 1)
|
||||
ret = krhino_task_info_set(NULL, INFO_IDX, (void *)0x111);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_info_set para 2", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_info_set para 2", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_info_set(task_misc, INFO_IDX, (void *)0x111);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_info_set para 3", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_info_set para 3", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_info_get(task_misc, INFO_IDX, &info);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_info_get para 1", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_info_get para 1", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_info_get(NULL, INFO_IDX, &info);
|
||||
|
||||
if (ret == RHINO_NULL_PTR) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_info_get para 2", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_info_get para 2", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
#undef INFO_IDX
|
||||
|
||||
task_free = krhino_global_space_get();
|
||||
|
||||
if (task_free > 0u) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_global_space_get", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_global_space_get", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
tmp.blk_state = BLK_ABORT;
|
||||
pend_state_end_proc(&tmp);
|
||||
|
||||
tmp.blk_state = BLK_TIMEOUT;
|
||||
|
||||
pend_state_end_proc(&tmp);
|
||||
|
||||
#if (RHINO_CONFIG_HW_COUNT > 0)
|
||||
krhino_overhead_measure();
|
||||
#endif
|
||||
krhino_sem_give(sem3);
|
||||
|
||||
ret = krhino_sem_dyn_create(&sem4, "del", 0);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sem_dyn_create", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_sem_dyn_create", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_sem_dyn_del(sem4);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_sem_dyn_del", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_sem_dyn_del", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_mutex_dyn_create(&mutex4, "mutex4");
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_mutex_dyn_create", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_mutex_dyn_create", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_mutex_dyn_del(mutex4);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_mutex_dyn_del", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_mutex_dyn_del", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_event_dyn_create(&event4, "event4", 0);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_event_dyn_create", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_event_dyn_create", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_event_dyn_del(event4);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_event_dyn_del", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_event_dyn_del", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_timer_dyn_create(&timer4, "timer4", timer_cb4, 10, 0, 0, 0);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_timer_dyn_create", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_timer_dyn_create", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_timer_dyn_del(timer4);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_timer_dyn_del", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_timer_dyn_del", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_buf_queue_dyn_create(&buf_queue4, "queue4", 100, 20);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_buf_queue_dyn_create", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_buf_queue_dyn_create", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_buf_queue_dyn_del(buf_queue4);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_buf_queue_dyn_del", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_buf_queue_dyn_del", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_queue_dyn_create(&queue4, "queue4", 10);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_queue_dyn_create", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_queue_dyn_create", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_queue_dyn_del(queue4);
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_queue_dyn_del", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_queue_dyn_del", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
ret = krhino_task_wait_abort(krhino_cur_task_get());
|
||||
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("krhino_task_wait_abort ready", PASS);
|
||||
} else {
|
||||
PRINT_RESULT("krhino_task_wait_abort ready", FAIL);
|
||||
test_case_fail++;
|
||||
}
|
||||
|
||||
krhino_task_dyn_create(&task_misc4, "task_misc_test4", 0, 1,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_misc_entry4, 1);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void task_misc_test(void)
|
||||
{
|
||||
krhino_task_dyn_create(NULL, "task_misc_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_misc_entry, 1);
|
||||
|
||||
krhino_task_dyn_create(&task_misc, "task_misc_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_misc_entry, 1);
|
||||
|
||||
krhino_task_dyn_create(&task_misc3, "task_misc_test3", 0, 5,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_misc_entry3, 1);
|
||||
}
|
||||
|
||||
38
Living_SDK/kernel/rhino/test/core/task/task_sleep.c
Normal file
38
Living_SDK/kernel/rhino/test/core/task/task_sleep.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
#define LOOP_CNT 1
|
||||
|
||||
ktask_t *task_0_test;
|
||||
static uint32_t cnt;
|
||||
|
||||
void task_sleep_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
cnt++;
|
||||
|
||||
if (cnt == LOOP_CNT) {
|
||||
test_case_success++;
|
||||
cnt = 0u;
|
||||
PRINT_RESULT("task_sleep", PASS);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void task_sleep_test(void)
|
||||
{
|
||||
if (krhino_task_dyn_create(&task_0_test, "task_sleep_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_sleep_entry, 1) != RHINO_SUCCESS) {
|
||||
printf("task_sleep_test fail \n");
|
||||
}
|
||||
}
|
||||
|
||||
47
Living_SDK/kernel/rhino/test/core/task/task_suspend_test.c
Normal file
47
Living_SDK/kernel/rhino/test/core/task/task_suspend_test.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 512
|
||||
|
||||
ktask_t *task_1_test;
|
||||
ktask_t *task_2_test;
|
||||
|
||||
void task_suspend_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_task_suspend(krhino_cur_task_get());
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT("task_suspend", PASS);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
void task_resume_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
krhino_task_resume(task_1_test);
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
void task_suspend_test(void)
|
||||
{
|
||||
krhino_task_dyn_create(&task_1_test, "task_suspend_test_1", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_suspend_entry, 1);
|
||||
|
||||
/* for smp sync */
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND / 10);
|
||||
|
||||
krhino_task_dyn_create(&task_2_test, "task_suspend_test_2", 0, 11,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_resume_entry, 1);
|
||||
}
|
||||
|
||||
31
Living_SDK/kernel/rhino/test/core/task/task_test.c
Normal file
31
Living_SDK/kernel/rhino/test/core/task/task_test.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
extern void task_sleep_test(void);
|
||||
extern void task_suspend_test(void);
|
||||
extern void task_yield_test(void);
|
||||
extern void task_yield_test(void);
|
||||
extern void task_misc_test(void);
|
||||
|
||||
extern void task_del_test(void);
|
||||
|
||||
void task_test(void)
|
||||
{
|
||||
|
||||
task_del_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_sleep_test();
|
||||
next_test_case_wait();
|
||||
task_suspend_test();
|
||||
next_test_case_wait();
|
||||
task_yield_test();
|
||||
next_test_case_wait();
|
||||
task_misc_test();
|
||||
next_test_case_wait();
|
||||
}
|
||||
|
||||
46
Living_SDK/kernel/rhino/test/core/task/task_yield_test.c
Normal file
46
Living_SDK/kernel/rhino/test/core/task/task_yield_test.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 512
|
||||
|
||||
static ktask_t *task_1_test;
|
||||
static ktask_t *task_2_test;
|
||||
|
||||
void task_yield_1_entry(void *arg)
|
||||
{
|
||||
#if (RHINO_CONFIG_SCHED_RR > 0)
|
||||
krhino_sched_policy_set(krhino_cur_task_get(), KSCHED_FIFO);
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
krhino_task_yield();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void task_yield_2_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("task_yield", PASS);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
void task_yield_test(void)
|
||||
{
|
||||
krhino_task_dyn_create(&task_1_test, "task_yield_test_1", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_yield_1_entry, 1);
|
||||
|
||||
krhino_task_dyn_create(&task_2_test, "task_yield_test_2", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE,
|
||||
task_yield_2_entry, 1);
|
||||
}
|
||||
|
||||
57
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_count.c
Normal file
57
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_count.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "tasksem_test.h"
|
||||
|
||||
#define MODULE_NAME "tasksem_count"
|
||||
|
||||
static uint8_t tasksem_count_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
sem_count_t count;
|
||||
|
||||
ret = krhino_task_sem_create(task_tasksem, &test_tasksem, MODULE_NAME, 8);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_count_get(NULL, &count);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_count_get(task_tasksem, &count);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
MYASSERT(count == 8);
|
||||
|
||||
ret = krhino_task_sem_count_set(NULL, 3);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_count_set(task_tasksem, (sem_count_t) - 1);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_del(task_tasksem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t tasksem_func_runner[] = {
|
||||
tasksem_count_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void tasksem_count_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_tasksem_entry_register(MODULE_NAME, (test_func_t *)tasksem_func_runner,
|
||||
sizeof(tasksem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_tasksem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_tasksem_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
135
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_opr.c
Normal file
135
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_opr.c
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "tasksem_test.h"
|
||||
|
||||
#define MODULE_NAME "tasksem_opr"
|
||||
#define MODULE_NAME_CO1 "tasksem_coopr1"
|
||||
#define MODULE_NAME_CO2 "tasksem_coopr2"
|
||||
|
||||
#define LOOP_CNT 8
|
||||
|
||||
static void task_tasksem_co2_entry(void *arg);
|
||||
|
||||
static uint8_t tasksem_opr_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_sem_create(task_tasksem, &test_tasksem, MODULE_NAME, 8);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_take(RHINO_NO_WAIT);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_give(task_tasksem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_del(task_tasksem);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t tasksem_func_runner[] = {
|
||||
tasksem_opr_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void tasksem_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_tasksem_entry_register(MODULE_NAME, (test_func_t *)tasksem_func_runner,
|
||||
sizeof(tasksem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_tasksem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_tasksem_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
static void task_tasksem_co1_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint8_t cnt = 0;
|
||||
|
||||
ret = krhino_task_sem_create(krhino_cur_task_get(), &test_tasksem_co1, MODULE_NAME, 0);
|
||||
MYASSERT_INFO(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_dyn_create(&task_tasksem_co2, MODULE_NAME, 0, TASK_SEM_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, task_tasksem_co2_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ret = krhino_task_sem_take(RHINO_WAIT_FOREVER);
|
||||
MYASSERT_INFO(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_give(task_tasksem_co2);
|
||||
MYASSERT_INFO(ret == RHINO_SUCCESS);
|
||||
|
||||
cnt++;
|
||||
if (cnt >= LOOP_CNT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
krhino_task_sem_del(krhino_cur_task_get());
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
static void task_tasksem_co2_entry(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint8_t cnt = 0;
|
||||
|
||||
ret = krhino_task_sem_create(krhino_cur_task_get(), &test_tasksem_co2, MODULE_NAME, 0);
|
||||
MYASSERT_INFO(ret == RHINO_SUCCESS);
|
||||
|
||||
while (1) {
|
||||
ret = krhino_task_sem_give(task_tasksem_co1);
|
||||
MYASSERT_INFO(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_take(RHINO_WAIT_FOREVER);
|
||||
if (ret == RHINO_BLK_TIMEOUT) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
break;
|
||||
}
|
||||
|
||||
cnt++;
|
||||
if (cnt >= LOOP_CNT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, PASS);
|
||||
|
||||
krhino_task_sem_del(krhino_cur_task_get());
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void tasksem_coopr1_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_tasksem_co1, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_tasksem_co1_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME_CO1, FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
81
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_param.c
Normal file
81
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_param.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "tasksem_test.h"
|
||||
|
||||
#define MODULE_NAME "tasksem_param"
|
||||
|
||||
static uint8_t tasksem_param_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_sem_create(NULL, &test_tasksem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_create(task_tasksem, NULL, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_create(task_tasksem, &test_tasksem, NULL, 0);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_create(task_tasksem, &test_tasksem, MODULE_NAME,
|
||||
(sem_count_t) - 1);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_create(task_tasksem, &test_tasksem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_del(NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t tasksem_param_case2(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
sem_count_t count;
|
||||
|
||||
ret = krhino_task_sem_create(task_tasksem, &test_tasksem, MODULE_NAME, 0);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_sem_count_get(NULL, &count);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_count_get(task_tasksem, NULL);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_count_set(NULL, 3);
|
||||
MYASSERT(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_task_sem_count_set(task_tasksem, (sem_count_t) - 1);
|
||||
MYASSERT(ret == RHINO_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const test_func_t tasksem_func_runner[] = {
|
||||
tasksem_param_case1,
|
||||
tasksem_param_case2,
|
||||
NULL
|
||||
};
|
||||
|
||||
void tasksem_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_tasksem_entry_register(MODULE_NAME, (test_func_t *)tasksem_func_runner,
|
||||
sizeof(tasksem_func_runner) / sizeof(test_case_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_tasksem, MODULE_NAME, 0, TASK_SEM_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_tasksem_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
80
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_test.c
Normal file
80
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_test.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "tasksem_test.h"
|
||||
|
||||
ktask_t *task_tasksem;
|
||||
ktask_t *task_tasksem_co1;
|
||||
ktask_t *task_tasksem_co2;
|
||||
ksem_t test_tasksem;
|
||||
ksem_t test_tasksem_co1;
|
||||
ksem_t test_tasksem_co2;
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t tasksem_case_runner[] = {
|
||||
tasksem_param_test,
|
||||
tasksem_count_test,
|
||||
tasksem_opr_test,
|
||||
tasksem_coopr1_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void tasksem_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)tasksem_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_tasksem_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_tasksem_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
34
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_test.h
Normal file
34
Living_SDK/kernel/rhino/test/core/task_sem/tasksem_test.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef TASKSEM_TEST_H
|
||||
#define TASKSEM_TEST_H
|
||||
|
||||
#define TASK_SEM_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do {if ((int)(value) == 0) { return 1; }} while (0)
|
||||
#define MYASSERT_INFO(value) do {if ((int)(value) == 0) { printf("%s:%d\n", __FUNCTION__, __LINE__); }} while (0)
|
||||
|
||||
extern ktask_t *task_tasksem;
|
||||
extern ktask_t *task_tasksem_co1;
|
||||
extern ktask_t *task_tasksem_co2;
|
||||
extern ksem_t test_tasksem;
|
||||
extern ksem_t test_tasksem_co1;
|
||||
extern ksem_t test_tasksem_co2;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_tasksem_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casnum);
|
||||
void task_tasksem_entry(void *arg);
|
||||
void tasksem_test(void);
|
||||
void tasksem_param_test(void);
|
||||
void tasksem_count_test(void);
|
||||
void tasksem_opr_test(void);
|
||||
void tasksem_coopr1_test(void);
|
||||
void tasksem_coopr2_test(void);
|
||||
|
||||
#endif /* TASKSEM_TEST_H */
|
||||
|
||||
78
Living_SDK/kernel/rhino/test/core/time/time_opr.c
Normal file
78
Living_SDK/kernel/rhino/test/core/time/time_opr.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "time_test.h"
|
||||
|
||||
#define MODULE_NAME "time_opr"
|
||||
#define MODULE_NAME_CO "time_coopr"
|
||||
|
||||
void gettaskinfo(void)
|
||||
{
|
||||
klist_t *taskhead = &g_kobj_list.task_head;
|
||||
klist_t *taskend = taskhead;
|
||||
klist_t *tmp;
|
||||
ktask_t *task;
|
||||
|
||||
printf("\n");
|
||||
printf("---------------------------------------------\n");
|
||||
printf("Name State StackSize\n");
|
||||
printf("---------------------------------------------\n");
|
||||
for (tmp = taskhead->next; tmp != taskend; tmp = tmp->next) {
|
||||
task = krhino_list_entry(tmp, ktask_t, task_stats_item);
|
||||
printf("%s\t\t %d\t\t\%d\n", task->task_name, (int)task->task_state,
|
||||
(int)task->stack_size);
|
||||
}
|
||||
printf("---------------------------------------------\n");
|
||||
}
|
||||
|
||||
static uint8_t time_opr_case(void)
|
||||
{
|
||||
tick_t ticks;
|
||||
sys_time_t ms;
|
||||
sys_time_t start;
|
||||
sys_time_t end;
|
||||
|
||||
ticks = krhino_ms_to_ticks(1000);
|
||||
MYASSERT(ticks == RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
|
||||
ms = krhino_ticks_to_ms(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
MYASSERT(ms == 1000);
|
||||
|
||||
start = krhino_sys_tick_get();
|
||||
krhino_task_sleep(10);
|
||||
end = krhino_sys_tick_get();
|
||||
|
||||
MYASSERT((end - start) < 15);
|
||||
|
||||
start = krhino_sys_time_get();
|
||||
krhino_task_sleep(16);
|
||||
end = krhino_sys_time_get();
|
||||
|
||||
MYASSERT((end - start) < (20 * 1000 / RHINO_CONFIG_TICKS_PER_SECOND));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t time_func_runner[] = {
|
||||
time_opr_case,
|
||||
NULL
|
||||
};
|
||||
|
||||
void time_opr_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_time_entry_register(MODULE_NAME, (test_func_t *)time_func_runner,
|
||||
sizeof(time_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_time, MODULE_NAME, 0, TASK_TIME_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, task_time_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
72
Living_SDK/kernel/rhino/test/core/time/time_test.c
Normal file
72
Living_SDK/kernel/rhino/test/core/time/time_test.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "time_test.h"
|
||||
|
||||
ktask_t *task_time;
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t time_case_runner[] = {
|
||||
time_opr_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void time_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)time_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void task_time_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_time_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
24
Living_SDK/kernel/rhino/test/core/time/time_test.h
Normal file
24
Living_SDK/kernel/rhino/test/core/time/time_test.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef TIME_TEST_H
|
||||
#define TIME_TEST_H
|
||||
|
||||
#define TASK_TIME_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do {if ((int)(value) == 0) { return 1; }} while (0)
|
||||
|
||||
extern ktask_t *task_time;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_time_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum);
|
||||
void task_time_entry(void *arg);
|
||||
void time_test(void);
|
||||
void time_opr_test(void);
|
||||
|
||||
#endif /* TIME_TEST_H */
|
||||
|
||||
106
Living_SDK/kernel/rhino/test/core/timer/timer_change.c
Normal file
106
Living_SDK/kernel/rhino/test/core/timer/timer_change.c
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "timer_test.h"
|
||||
|
||||
#define TIMER0_ROUND 1
|
||||
#define TIMER0_MAGIC 0x12345678
|
||||
#define TIMER0_TEST_TIMES 100
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktimer_t timer_0_test;
|
||||
static ktimer_t timer_1_test;
|
||||
static ksem_t sem_0_test;
|
||||
|
||||
static void timer_0_func(void *timer, void *arg)
|
||||
{
|
||||
krhino_sem_give(&sem_0_test);
|
||||
}
|
||||
|
||||
static void timer_1_func(void *timer, void *arg)
|
||||
{
|
||||
krhino_sem_give(&sem_0_test);
|
||||
}
|
||||
|
||||
static void timer_change_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_timer_change(NULL, TIMER0_ROUND, TIMER0_ROUND);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_change(&timer_0_test, 0, TIMER0_ROUND);
|
||||
TIMER_VAL_CHK(ret == RHINO_INV_PARAM);
|
||||
}
|
||||
|
||||
static void task_timer0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret = 0;
|
||||
|
||||
while (1) {
|
||||
/* check krhino_timer_change param */
|
||||
timer_change_param_test();
|
||||
|
||||
ret = krhino_sem_create(&sem_0_test, "sem_0_test", 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_create(&timer_0_test, "timer_0_test", timer_0_func,
|
||||
TIMER0_ROUND * 10, TIMER0_ROUND * 10, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_create(&timer_1_test, "timer_1_test", timer_1_func,
|
||||
TIMER0_ROUND * 20, TIMER0_ROUND * 20, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_change(&timer_1_test, TIMER0_ROUND, TIMER0_ROUND);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_start(&timer_1_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_start(&timer_0_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_stop(&timer_0_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_del(&timer_0_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_stop(&timer_1_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_del(&timer_1_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
test_case_success++;
|
||||
|
||||
PRINT_RESULT("timer change", PASS);
|
||||
krhino_sem_del(&sem_0_test);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_timer_change_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_timer0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_timer0_entry, 1);
|
||||
TIMER_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
141
Living_SDK/kernel/rhino/test/core/timer/timer_create_del.c
Normal file
141
Living_SDK/kernel/rhino/test/core/timer/timer_create_del.c
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "timer_test.h"
|
||||
|
||||
#define TIMER0_ROUND 1
|
||||
#define TIMER0_MAGIC 0x12345678
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktimer_t timer_0_test;
|
||||
static ktimer_t timer_1_test;
|
||||
static ksem_t sem_0_test;
|
||||
static ktimer_t timer;
|
||||
|
||||
static void timer_0_func(ktimer_t *timer, void *arg)
|
||||
{
|
||||
TIMER_VAL_CHK(timer == &timer_0_test);
|
||||
TIMER_VAL_CHK((size_t)arg == TIMER0_MAGIC);
|
||||
|
||||
krhino_sem_give(&sem_0_test);
|
||||
}
|
||||
|
||||
static void timer_1_func(ktimer_t *timer, void *arg)
|
||||
{
|
||||
TIMER_VAL_CHK(timer == &timer_1_test);
|
||||
TIMER_VAL_CHK((size_t)arg == TIMER0_MAGIC);
|
||||
|
||||
krhino_sem_give(&sem_0_test);
|
||||
}
|
||||
|
||||
static void timer_create_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_timer_create(NULL, "timer_0_test", (timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_create(&timer_0_test, NULL, (timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_create(&timer_0_test, "timer_0_test", NULL, TIMER0_ROUND,
|
||||
TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_create(&timer_0_test, "timer_0_test",
|
||||
(timer_cb_t)timer_0_func,
|
||||
0, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_INV_PARAM);
|
||||
}
|
||||
|
||||
static void timer_del_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
memset(&timer, 0, sizeof(ktimer_t));
|
||||
|
||||
ret = krhino_timer_del(NULL);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_start(&timer);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_stop(&timer);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_change(&timer, 10, 10);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_del(&timer);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
static void task_timer0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret = 0;
|
||||
|
||||
while (1) {
|
||||
/* check krhino_timer_create */
|
||||
timer_create_param_test();
|
||||
|
||||
/* check krhino_timer_del */
|
||||
timer_del_param_test();
|
||||
|
||||
ret = krhino_sem_create(&sem_0_test, "sem_0_test", 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_create(&timer_0_test, "timer_0_test",
|
||||
(timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_del(&timer_0_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_create(&timer_1_test, "timer_0_test",
|
||||
(timer_cb_t)timer_1_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 1);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_stop(&timer_1_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
ret = krhino_timer_dyn_del(&timer_1_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_del(&timer_1_test);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("timer create&del", PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("timer create&del", FAIL);
|
||||
}
|
||||
|
||||
krhino_sem_del(&sem_0_test);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_timer_create_del_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_timer0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_timer0_entry, 1);
|
||||
TIMER_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
127
Living_SDK/kernel/rhino/test/core/timer/timer_dyn_create_del.c
Normal file
127
Living_SDK/kernel/rhino/test/core/timer/timer_dyn_create_del.c
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "timer_test.h"
|
||||
|
||||
#define TIMER0_ROUND 1
|
||||
#define TIMER0_MAGIC 0x12345678
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktimer_t *timer_0_test;
|
||||
static ksem_t sem_0_test;
|
||||
|
||||
static void timer_0_func(ktimer_t *timer, void *arg)
|
||||
{
|
||||
TIMER_VAL_CHK(timer == timer_0_test);
|
||||
TIMER_VAL_CHK((size_t)arg == TIMER0_MAGIC);
|
||||
|
||||
krhino_sem_give(&sem_0_test);
|
||||
}
|
||||
|
||||
|
||||
static void timer_dyn_create_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_timer_dyn_create(NULL, "timer_0_test", (timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_dyn_create(&timer_0_test, NULL, (timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_dyn_create(&timer_0_test, "timer_0_test", NULL, TIMER0_ROUND,
|
||||
TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_dyn_create(&timer_0_test, "timer_0_test",
|
||||
(timer_cb_t)timer_0_func,
|
||||
0, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_INV_PARAM);
|
||||
}
|
||||
|
||||
static void timer_dyn_del_param_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
ktimer_t timer;
|
||||
|
||||
memset(&timer, 0 , sizeof(ktimer_t));
|
||||
|
||||
ret = krhino_timer_dyn_del(NULL);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
|
||||
ret = krhino_timer_dyn_create(&timer_0_test, "timer_0_test",
|
||||
(timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_dyn_del(timer_0_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
static void task_timer0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret = 0;
|
||||
|
||||
while (1) {
|
||||
/* check krhino_timer_dyn_create param */
|
||||
timer_dyn_create_param_test();
|
||||
|
||||
/* check krhino_timer_dyn_del param */
|
||||
timer_dyn_del_param_test();
|
||||
|
||||
ret = krhino_sem_create(&sem_0_test, "sem_0_test", 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_dyn_create(&timer_0_test, "timer_0_test",
|
||||
(timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_dyn_del(timer_0_test);
|
||||
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_dyn_create(&timer_0_test, "timer_0_test",
|
||||
(timer_cb_t)timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 1);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
ret = krhino_timer_stop(timer_0_test);
|
||||
ret = krhino_timer_dyn_del(timer_0_test);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("timer dyn create&del", PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("timer dyn create&del", FAIL);
|
||||
}
|
||||
|
||||
krhino_sem_del(&sem_0_test);
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_timer_dyn_create_del_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_timer0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_timer0_entry, 1);
|
||||
TIMER_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
89
Living_SDK/kernel/rhino/test/core/timer/timer_start_stop.c
Normal file
89
Living_SDK/kernel/rhino/test/core/timer/timer_start_stop.c
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "timer_test.h"
|
||||
|
||||
#define TIMER0_ROUND 1
|
||||
#define TIMER0_MAGIC 0x12345678
|
||||
#define TIMER0_TEST_TIMES 100
|
||||
|
||||
static ktask_t *task_0_test;
|
||||
static ktimer_t timer_0_test;
|
||||
static ksem_t sem_0_test;
|
||||
static uint32_t timer_0_count;
|
||||
|
||||
static void timer_0_func(void *timer, void *arg)
|
||||
{
|
||||
krhino_sem_give(&sem_0_test);
|
||||
}
|
||||
|
||||
static void timer_start_param_test()
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_timer_start(NULL);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
}
|
||||
|
||||
static void timer_stop_param_test()
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_timer_stop(NULL);
|
||||
TIMER_VAL_CHK(ret == RHINO_NULL_PTR);
|
||||
}
|
||||
|
||||
static void task_timer0_entry(void *arg)
|
||||
{
|
||||
kstat_t ret = 0;
|
||||
|
||||
while (1) {
|
||||
timer_0_count = 0;
|
||||
|
||||
/* check krhino_timer_start param */
|
||||
timer_start_param_test();
|
||||
|
||||
/* check krhino_timer_stop param */
|
||||
timer_stop_param_test();
|
||||
|
||||
ret = krhino_sem_create(&sem_0_test, "sem_0_test", 0);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_create(&timer_0_test, "timer_0_test", timer_0_func,
|
||||
TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 1);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_stop(&timer_0_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_del(&timer_0_test);
|
||||
TIMER_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
|
||||
test_case_success++;
|
||||
PRINT_RESULT("timer start&stop", PASS);
|
||||
|
||||
krhino_sem_del(&sem_0_test);
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
}
|
||||
|
||||
kstat_t task_timer_start_stop_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_task_dyn_create(&task_0_test, "task_timer0_test", 0, 10,
|
||||
0, TASK_TEST_STACK_SIZE, task_timer0_entry, 1);
|
||||
TIMER_VAL_CHK((ret == RHINO_SUCCESS) || (ret == RHINO_STOPPED));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
24
Living_SDK/kernel/rhino/test/core/timer/timer_test.c
Normal file
24
Living_SDK/kernel/rhino/test/core/timer/timer_test.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#include "timer_test.h"
|
||||
|
||||
void timer_test(void)
|
||||
{
|
||||
task_timer_create_del_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_timer_dyn_create_del_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_timer_start_stop_test();
|
||||
next_test_case_wait();
|
||||
|
||||
task_timer_change_test();
|
||||
next_test_case_wait();
|
||||
}
|
||||
|
||||
19
Living_SDK/kernel/rhino/test/core/timer/timer_test.h
Normal file
19
Living_SDK/kernel/rhino/test/core/timer/timer_test.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef TIMER_TEST_H
|
||||
#define TIMER_TEST_H
|
||||
|
||||
#define TASK_TEST_STACK_SIZE 256
|
||||
|
||||
#define TIMER_VAL_CHK(value) do {if ((int)(value) == 0) \
|
||||
{printf("timer test is [FAIL %d], func %s, line %d\n", \
|
||||
(int)++test_case_fail,__FUNCTION__, __LINE__);}}while(0)
|
||||
|
||||
kstat_t task_timer_create_del_test(void);
|
||||
kstat_t task_timer_dyn_create_del_test(void);
|
||||
kstat_t task_timer_start_stop_test(void);
|
||||
kstat_t task_timer_change_test(void);
|
||||
|
||||
#endif /* TIMER_TEST_H */
|
||||
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "workqueue_test.h"
|
||||
|
||||
#define MODULE_NAME "workqueue_interface"
|
||||
|
||||
#if (RHINO_CONFIG_WORKQUEUE > 0)
|
||||
static ksem_t g_wq_test_sem;
|
||||
|
||||
static void work0_func(void *arg)
|
||||
{
|
||||
krhino_task_sleep(45);
|
||||
printf("--%s--\n", (char *)arg);
|
||||
}
|
||||
|
||||
static void work1_func(void *arg)
|
||||
{
|
||||
krhino_task_sleep(15);
|
||||
printf("--%s--\n", (char *)arg);
|
||||
}
|
||||
|
||||
static void work2_func(void *arg)
|
||||
{
|
||||
krhino_task_sleep(10);
|
||||
printf("--%s--\n", (char *)arg);
|
||||
}
|
||||
|
||||
static void work3_func(void *arg)
|
||||
{
|
||||
printf("--%s--\n", (char *)arg);
|
||||
}
|
||||
|
||||
static void work4_func(void *arg)
|
||||
{
|
||||
krhino_task_sleep(15);
|
||||
printf("--%s--\n", (char *)arg);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
}
|
||||
|
||||
static void work5_func(void *arg)
|
||||
{
|
||||
printf("--%s--\n", (char *)arg);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
}
|
||||
|
||||
static void work6_func(void *arg)
|
||||
{
|
||||
printf("--%s--\n", (char *)arg);
|
||||
}
|
||||
|
||||
#define WORK_STACK_BUF 512
|
||||
|
||||
cpu_stack_t stack0_buf[WORK_STACK_BUF];
|
||||
cpu_stack_t stack1_buf[WORK_STACK_BUF];
|
||||
cpu_stack_t stack2_buf[WORK_STACK_BUF];
|
||||
|
||||
static kworkqueue_t wq0;
|
||||
static kworkqueue_t wq1;
|
||||
static kworkqueue_t wq2;
|
||||
static kwork_t work0;
|
||||
static kwork_t work1;
|
||||
static kwork_t work2;
|
||||
static kwork_t work3;
|
||||
static kwork_t work4;
|
||||
static kwork_t work5;
|
||||
static kwork_t work6;
|
||||
|
||||
static uint8_t workqueue_interface_case1(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
size_t stack0_size = WORK_STACK_BUF;
|
||||
size_t stack1_size = WORK_STACK_BUF;
|
||||
size_t stack2_size = WORK_STACK_BUF;
|
||||
|
||||
printf("==========WORKQUEUE TEST START!==========\n");
|
||||
|
||||
krhino_sem_create(&g_wq_test_sem, "WORKQUEUE-SEM", 0);
|
||||
|
||||
/* creat workqueues */
|
||||
ret = krhino_workqueue_create(&wq0, "WORKQUEUE1-TEST", TASK_WORKQUEUE_PRI,
|
||||
stack0_buf, stack0_size);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_workqueue_create(&wq1, "WORKQUEUE1-TEST", TASK_WORKQUEUE_PRI,
|
||||
stack1_buf, stack1_size);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_workqueue_create(&wq2, "WORKQUEUE2-TEST", TASK_WORKQUEUE_PRI,
|
||||
stack2_buf, stack2_size);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_workqueue_create(&wq1, "WORKQUEUE", TASK_WORKQUEUE_PRI,
|
||||
stack1_buf, stack1_size);
|
||||
if (ret != RHINO_WORKQUEUE_EXIST) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* init works */
|
||||
ret = krhino_work_init(&work0, work0_func, "WORK 0", 0);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(&work1, work1_func, "WORK 1", 0);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(&work2, work2_func, "WORK 2", 1);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(&work3, work3_func, "WORK 3", 20);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(&work4, work4_func, "WORK 4", 18);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(&work5, work5_func, "WORK 5", 40);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(&work6, work6_func, "WORK 6", 50);
|
||||
if (ret != RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
krhino_sem_give(&g_wq_test_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* work run */
|
||||
krhino_work_run(&wq1, &work0);
|
||||
krhino_work_run(&wq1, &work1);
|
||||
krhino_work_run(&wq1, &work1);
|
||||
|
||||
krhino_work_run(&wq1, &work2);
|
||||
krhino_work_run(&wq1, &work2);
|
||||
krhino_work_run(&wq1, &work3);
|
||||
|
||||
krhino_work_sched(&work4);
|
||||
krhino_work_sched(&work5);
|
||||
krhino_work_sched(&work6);
|
||||
|
||||
/* wait for task4 */
|
||||
krhino_sem_take(&g_wq_test_sem, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_work_sched(&work5);
|
||||
|
||||
/* wait for task6 */
|
||||
krhino_sem_take(&g_wq_test_sem, RHINO_WAIT_FOREVER);
|
||||
|
||||
printf("=====FUNCTION TEST DONE!=====\n");
|
||||
|
||||
ret = krhino_workqueue_create(NULL, "WORKQUEUE1-TEST", TASK_WORKQUEUE_PRI,
|
||||
stack1_buf, stack1_size);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_workqueue_create(&wq1, NULL, TASK_WORKQUEUE_PRI,
|
||||
stack1_buf, stack1_size);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_workqueue_create(&wq1, "WORKQUEUE1-TEST", RHINO_CONFIG_PRI_MAX,
|
||||
stack1_buf, stack1_size);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_workqueue_create(&wq1, "WORKQUEUE1-TEST", TASK_WORKQUEUE_PRI,
|
||||
NULL, stack1_size);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_workqueue_create(&wq1, "WORKQUEUE1-TEST", TASK_WORKQUEUE_PRI,
|
||||
stack1_buf, 0);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(NULL, work1_func, "WORK 1", 200);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = krhino_work_init(&work1, NULL, "WORK 1", 200);
|
||||
if (ret == RHINO_SUCCESS) {
|
||||
MYASSERT(ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
krhino_work_run(NULL, &work3);
|
||||
krhino_work_run(&wq1, NULL);
|
||||
|
||||
printf("=====PARAMTER TEST DONE!=====\n");
|
||||
|
||||
krhino_sem_del(&g_wq_test_sem);
|
||||
|
||||
printf("==========WORKQUEUE TEST DONE!==========\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const test_func_t workqueue_func_runner[] = {
|
||||
workqueue_interface_case1,
|
||||
NULL
|
||||
};
|
||||
|
||||
void workqueue_interface_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
task_workqueue_entry_register(MODULE_NAME,
|
||||
(test_func_t *)workqueue_func_runner,
|
||||
sizeof(workqueue_func_runner) / sizeof(test_func_t));
|
||||
|
||||
ret = krhino_task_dyn_create(&task_workqueue, MODULE_NAME, 0,
|
||||
TASK_WORKQUEUE_PRI, 0, TASK_TEST_STACK_SIZE,
|
||||
task_workqueue_entry, 1);
|
||||
if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(MODULE_NAME, FAIL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
72
Living_SDK/kernel/rhino/test/core/workqueue/workqueue_test.c
Normal file
72
Living_SDK/kernel/rhino/test/core/workqueue/workqueue_test.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "workqueue_test.h"
|
||||
|
||||
ktask_t *task_workqueue;
|
||||
|
||||
static test_func_t *module_runner;
|
||||
static const char *module_name;
|
||||
static uint8_t module_casenum;
|
||||
|
||||
static const test_case_t workqueue_case_runner[] = {
|
||||
workqueue_interface_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
void task_workqueue_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum)
|
||||
{
|
||||
module_runner = runner;
|
||||
module_name = name;
|
||||
module_casenum = casenum;
|
||||
}
|
||||
|
||||
void task_workqueue_entry(void *arg)
|
||||
{
|
||||
test_func_t *runner;
|
||||
uint8_t caseidx;
|
||||
char name[64];
|
||||
uint8_t casenum;
|
||||
|
||||
runner = (test_func_t *)module_runner;
|
||||
casenum = module_casenum;
|
||||
caseidx = 0;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (casenum > 2) {
|
||||
caseidx++;
|
||||
sprintf(name, "%s_%d", module_name, caseidx);
|
||||
} else {
|
||||
sprintf(name, "%s", module_name);
|
||||
}
|
||||
|
||||
if ((*runner)() == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT(name, PASS);
|
||||
} else {
|
||||
test_case_fail++;
|
||||
PRINT_RESULT(name, FAIL);
|
||||
}
|
||||
runner++;
|
||||
}
|
||||
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
}
|
||||
|
||||
void workqueue_test(void)
|
||||
{
|
||||
if (test_case_register((test_case_t *)workqueue_case_runner) == 0) {
|
||||
test_case_run();
|
||||
test_case_unregister();
|
||||
}
|
||||
}
|
||||
|
||||
24
Living_SDK/kernel/rhino/test/core/workqueue/workqueue_test.h
Normal file
24
Living_SDK/kernel/rhino/test/core/workqueue/workqueue_test.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef WORKQUEUE_TEST_H
|
||||
#define WORKQUEUE_TEST_H
|
||||
|
||||
#define TASK_WORKQUEUE_PRI 16
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define MYASSERT(value) do { printf("ERROR: %s:%d, ERROR-NO: %d\n", __FUNCTION__, __LINE__, value); } while (0)
|
||||
|
||||
extern ktask_t *task_workqueue;
|
||||
|
||||
typedef uint8_t (*test_func_t)(void);
|
||||
|
||||
void task_workqueue_entry_register(const char *name, test_func_t *runner,
|
||||
uint8_t casenum);
|
||||
void task_workqueue_entry(void *arg);
|
||||
void workqueue_test(void);
|
||||
void workqueue_interface_test(void);
|
||||
|
||||
#endif /* WORKQUEUE_TEST_H */
|
||||
|
||||
3
Living_SDK/kernel/rhino/test/perf/README.txt
Normal file
3
Living_SDK/kernel/rhino/test/perf/README.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
1 Open the compile switch CONFIG_TEST_PERFORMANCE in the defconfig
|
||||
2 Performance test only support csky 802 mow.
|
||||
|
||||
115
Living_SDK/kernel/rhino/test/perf/intrealtime.c
Normal file
115
Living_SDK/kernel/rhino/test/perf/intrealtime.c
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#define RELOAD (unsigned long )40000
|
||||
#define NUM 100
|
||||
|
||||
extern ksem_t *SYNhandle;
|
||||
extern void WaitForNew_tick(void);
|
||||
extern double Turn_to_Realtime(double counter);
|
||||
extern void show_times_detail(volatile double *ft, int nsamples,
|
||||
char *title, uint32_t ignore_first);
|
||||
|
||||
extern void hobbit_timer0_stop(void);
|
||||
extern void hobbit_timer0_init(uint32_t hz);
|
||||
extern void hobbit_timer0_start(void);
|
||||
extern uint32_t hobbit_timer0_get_curval(void);
|
||||
extern void hobbit_timer0_clr(void);
|
||||
|
||||
static double InTimeBUFF[sizeof(double)*NUM] ;
|
||||
static volatile uint32_t INT_NUM ;
|
||||
static unsigned long Endtime;
|
||||
static unsigned long starttime;
|
||||
|
||||
|
||||
void IntRealtimetest(void *arg)
|
||||
{
|
||||
WaitForNew_tick();
|
||||
unsigned short i;
|
||||
INT_NUM = 0;
|
||||
|
||||
memset(InTimeBUFF, 0, sizeof(double)*NUM);
|
||||
|
||||
hobbit_timer0_stop();
|
||||
hobbit_timer0_init(RELOAD);
|
||||
hobbit_timer0_start();
|
||||
|
||||
while (INT_NUM < NUM);
|
||||
|
||||
for (i = 0; i < NUM; i++) {
|
||||
InTimeBUFF[i] = (double) Turn_to_Realtime(InTimeBUFF[i]);
|
||||
}
|
||||
|
||||
show_times_detail(InTimeBUFF, NUM, "IntTime\t", 1);
|
||||
|
||||
krhino_sem_give(SYNhandle);
|
||||
|
||||
krhino_task_yield();
|
||||
|
||||
}
|
||||
|
||||
void SoftIntRealtimetest(void *arg)
|
||||
{
|
||||
WaitForNew_tick();
|
||||
unsigned short i;
|
||||
INT_NUM = 0;
|
||||
|
||||
hobbit_timer0_stop();
|
||||
hobbit_timer0_init(RELOAD);
|
||||
|
||||
memset(InTimeBUFF, 0, sizeof(double)*NUM);
|
||||
|
||||
hobbit_timer0_start();
|
||||
|
||||
do {
|
||||
starttime = hobbit_timer0_get_curval();
|
||||
__asm__("trap 1");
|
||||
|
||||
} while (INT_NUM < NUM);
|
||||
|
||||
hobbit_timer0_stop();
|
||||
|
||||
for (i = 0; i < NUM; i++) {
|
||||
InTimeBUFF[i] = (double) Turn_to_Realtime(InTimeBUFF[i]);
|
||||
}
|
||||
|
||||
show_times_detail(InTimeBUFF, NUM, "SoftIntTime\t", 1);
|
||||
|
||||
krhino_sem_give(SYNhandle);
|
||||
|
||||
krhino_task_yield();
|
||||
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TEST_PERFORMANCE
|
||||
void __attribute__((isr)) timer0_handler(void)
|
||||
{
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
hobbit_timer0_stop();
|
||||
hobbit_timer0_clr();
|
||||
InTimeBUFF[INT_NUM] = (double)(RELOAD - Endtime);
|
||||
INT_NUM ++;
|
||||
|
||||
if (INT_NUM < NUM) {
|
||||
hobbit_timer0_start();
|
||||
}
|
||||
}
|
||||
#else
|
||||
void timer0_handler(void)
|
||||
{
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
hobbit_timer0_stop();
|
||||
hobbit_timer0_clr();
|
||||
InTimeBUFF[INT_NUM] = (double)(RELOAD - Endtime);
|
||||
INT_NUM ++;
|
||||
|
||||
if (INT_NUM < NUM) {
|
||||
hobbit_timer0_start();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
133
Living_SDK/kernel/rhino/test/perf/mutex.c
Normal file
133
Living_SDK/kernel/rhino/test/perf/mutex.c
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#define TASK_TEST_PRI 20
|
||||
#define TASK_MAIN_PRI 15
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
#define SWITCH_NUM 100
|
||||
|
||||
extern ksem_t *SYNhandle;
|
||||
extern void WaitForNew_tick(void);
|
||||
extern double Turn_to_Realtime(double counter);
|
||||
extern void show_times_detail(volatile double *ft, int nsamples,
|
||||
char *title, uint32_t ignore_first);
|
||||
|
||||
extern void hobbit_timer0_stop(void);
|
||||
extern void hobbit_timer0_init(uint32_t hz);
|
||||
extern void hobbit_timer0_start(void);
|
||||
extern uint32_t hobbit_timer0_get_curval(void);
|
||||
extern void hobbit_timer0_clr(void);
|
||||
|
||||
static volatile unsigned long Starttime, Endtime, Runtime;
|
||||
static double ShufBUFF[sizeof(double)*SWITCH_NUM] ;
|
||||
static volatile unsigned long ShufSwitch = 0;
|
||||
static ksem_t *Shufhandle_1;
|
||||
static kmutex_t Shufhandle_0;
|
||||
static ktask_t *ShufTaskHandle[2];
|
||||
static ksem_t *ShufSynhandle;
|
||||
|
||||
|
||||
static uint8_t task_pri_get(ktask_t *task)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
uint8_t pri;
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
pri = task->prio;
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
return pri;
|
||||
}
|
||||
|
||||
static void MutexShuf1(void *arg)
|
||||
{
|
||||
unsigned long OurPriority;
|
||||
uint8_t oldpri;
|
||||
|
||||
while (1) {
|
||||
krhino_mutex_lock(&Shufhandle_0, RHINO_WAIT_FOREVER);
|
||||
OurPriority = task_pri_get(krhino_cur_task_get());
|
||||
krhino_task_pri_change(ShufTaskHandle[1], OurPriority - 1, &oldpri);
|
||||
|
||||
Starttime = hobbit_timer0_get_curval();
|
||||
krhino_mutex_unlock(&Shufhandle_0);
|
||||
|
||||
krhino_sem_take(Shufhandle_1, RHINO_WAIT_FOREVER);
|
||||
|
||||
if (ShufSwitch >= SWITCH_NUM) {
|
||||
krhino_sem_give(ShufSynhandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void MutexShuf2(void *arg)
|
||||
{
|
||||
unsigned long Priority;
|
||||
uint8_t oldpri;
|
||||
|
||||
while (1) {
|
||||
krhino_mutex_lock(&Shufhandle_0, RHINO_WAIT_FOREVER);
|
||||
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
Runtime = Starttime - Endtime;
|
||||
|
||||
ShufBUFF[ShufSwitch] = (double)Runtime;
|
||||
|
||||
krhino_mutex_unlock(&Shufhandle_0);
|
||||
krhino_sem_give(Shufhandle_1);
|
||||
ShufSwitch++;
|
||||
|
||||
if (ShufSwitch >= SWITCH_NUM) {
|
||||
krhino_sem_give(ShufSynhandle);
|
||||
|
||||
}
|
||||
|
||||
Priority = task_pri_get(ShufTaskHandle[0]);
|
||||
krhino_task_pri_change(krhino_cur_task_get(), Priority + 1, &oldpri);
|
||||
}
|
||||
}
|
||||
|
||||
void MutexShufTimetest(void *arg)
|
||||
{
|
||||
unsigned long i ;
|
||||
|
||||
WaitForNew_tick();
|
||||
ShufSwitch = 0;
|
||||
|
||||
hobbit_timer0_stop();
|
||||
hobbit_timer0_init(0xffffffff);
|
||||
|
||||
memset(ShufBUFF, 0, sizeof(double)*SWITCH_NUM);
|
||||
|
||||
krhino_mutex_create(&Shufhandle_0, "mutex");
|
||||
krhino_sem_dyn_create(&Shufhandle_1, "sem", 0);
|
||||
|
||||
krhino_sem_dyn_create(&ShufSynhandle, "sem", 0);
|
||||
|
||||
krhino_task_dyn_create(&ShufTaskHandle[0], "test_task", 0, TASK_TEST_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, MutexShuf1, 1);
|
||||
krhino_task_dyn_create(&ShufTaskHandle[1], "test_task", 0, TASK_TEST_PRI + 2,
|
||||
0, TASK_TEST_STACK_SIZE, MutexShuf2, 1);
|
||||
|
||||
hobbit_timer0_start();
|
||||
krhino_sem_take(ShufSynhandle, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_task_dyn_del(ShufTaskHandle[0]);
|
||||
krhino_task_dyn_del(ShufTaskHandle[1]);
|
||||
|
||||
for (i = 0; i < SWITCH_NUM; i++) {
|
||||
ShufBUFF[i] = (double) Turn_to_Realtime(ShufBUFF[i]);
|
||||
}
|
||||
|
||||
show_times_detail(ShufBUFF , SWITCH_NUM, "MutexShuf\t", 1);
|
||||
krhino_task_sleep(20);
|
||||
krhino_sem_give(SYNhandle);
|
||||
}
|
||||
122
Living_SDK/kernel/rhino/test/perf/perf.c
Normal file
122
Living_SDK/kernel/rhino/test/perf/perf.c
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#define TASK_TEST_PRI 20
|
||||
#define TASK_MAIN_PRI 15
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define PRECISION 1000000000
|
||||
|
||||
#define APB_DEFAULT_FREQ 20000000
|
||||
|
||||
ktask_t *test_task;
|
||||
ktask_t *main_task;
|
||||
|
||||
ksem_t *SYNhandle;
|
||||
ksem_t *SYNmainhandle;
|
||||
|
||||
double Turn_to_Realtime(double counter);
|
||||
void WaitForNew_tick(void);
|
||||
void OS_RealTime_test(void);
|
||||
|
||||
extern int krhino_bsp_intc_attach_irq(int irq, int isr);
|
||||
extern int krhino_bsp_intc_enable_irq(int irq);;
|
||||
extern void timer0_handler(void);
|
||||
|
||||
extern void show_times_hdr(void);
|
||||
extern void IntRealtimetest(void *arg);
|
||||
extern void TaskYIELDtimeTest(void *arg);
|
||||
extern void PreemptionTimetest(void *arg);
|
||||
extern void MutexShufTimetest(void *arg);
|
||||
extern void BinaryShufTimetest(void *arg);
|
||||
|
||||
|
||||
double Turn_to_Realtime(double counter)
|
||||
{
|
||||
double realtime_us;
|
||||
double US_CLK = (double)(PRECISION / APB_DEFAULT_FREQ) ;
|
||||
return realtime_us = (US_CLK * counter);
|
||||
}
|
||||
|
||||
void WaitForNew_tick(void)
|
||||
{
|
||||
sys_time_t nowtick;
|
||||
nowtick = krhino_sys_tick_get();
|
||||
|
||||
while (krhino_sys_tick_get() == nowtick);
|
||||
}
|
||||
|
||||
|
||||
void OS_test(void *arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
WaitForNew_tick();
|
||||
krhino_sem_dyn_create(&SYNhandle, "syn_sem", 0);
|
||||
krhino_sem_dyn_create(&SYNmainhandle, "synmain_sem", 0);
|
||||
show_times_hdr();
|
||||
|
||||
#if 1
|
||||
ret = krhino_task_dyn_create(&test_task, "test_task", 0, TASK_TEST_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, IntRealtimetest, 1);
|
||||
krhino_sem_take(SYNhandle, RHINO_WAIT_FOREVER);
|
||||
krhino_task_dyn_del(test_task);
|
||||
|
||||
krhino_task_sleep(50);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
krhino_task_dyn_create(&test_task, "test_task", 0, TASK_TEST_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, TaskYIELDtimeTest, 1);
|
||||
krhino_sem_take(SYNhandle, RHINO_WAIT_FOREVER);
|
||||
krhino_task_dyn_del(test_task);
|
||||
krhino_task_sleep(50);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
krhino_task_dyn_create(&test_task, "test_task", 0, TASK_TEST_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, PreemptionTimetest, 1);
|
||||
krhino_sem_take(SYNhandle, RHINO_WAIT_FOREVER);
|
||||
krhino_task_dyn_del(test_task);
|
||||
|
||||
krhino_task_sleep(50);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
krhino_task_dyn_create(&test_task, "test_task", 0, TASK_TEST_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, MutexShufTimetest, 1);
|
||||
|
||||
krhino_sem_take(SYNhandle, RHINO_WAIT_FOREVER);
|
||||
krhino_task_dyn_del(test_task);
|
||||
|
||||
krhino_task_sleep(50);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
krhino_task_dyn_create(&test_task, "test_task", 0, TASK_TEST_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, BinaryShufTimetest, 1);
|
||||
|
||||
krhino_sem_take(SYNhandle, RHINO_WAIT_FOREVER);
|
||||
krhino_task_dyn_del(test_task);
|
||||
|
||||
krhino_task_sleep(50);
|
||||
#endif
|
||||
|
||||
krhino_task_dyn_del(krhino_cur_task_get());
|
||||
|
||||
}
|
||||
|
||||
void OS_RealTime_test(void)
|
||||
{
|
||||
krhino_bsp_intc_enable_irq(2);
|
||||
#ifndef CONFIG_TEST_PERFORMANCE
|
||||
krhino_bsp_intc_attach_irq(2, (int)timer0_handler);
|
||||
#endif
|
||||
krhino_task_dyn_create(&main_task, "main_task", 0, TASK_MAIN_PRI,
|
||||
0, TASK_TEST_STACK_SIZE, OS_test, 1);
|
||||
}
|
||||
|
||||
221
Living_SDK/kernel/rhino/test/perf/realtimelib.c
Normal file
221
Living_SDK/kernel/rhino/test/perf/realtimelib.c
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <k_config.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#define APB_DEFAULT_FREQ 20000000
|
||||
|
||||
void show_times_hdr(void)
|
||||
{
|
||||
printf("\r\nFreeRTOS Function RealTime Test\r\n");
|
||||
printf("\r\nTesting Parameters:\r\n");
|
||||
printf(" TICK_RATE_HZ : %dHZ\r\n",
|
||||
(unsigned long) RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
printf(" CLOCK_SAMPLE : %dHZ\r\n", (unsigned long) APB_DEFAULT_FREQ);
|
||||
|
||||
printf(" Confidence\r\n");
|
||||
printf(" Ave Min Max Var Ave Min Function SampleNum \r\n");
|
||||
printf("===== ===== ===== ===== ======= ======== ========= \r\n");
|
||||
}
|
||||
|
||||
|
||||
void show_time_in_us(unsigned long result) //ns to us
|
||||
{
|
||||
printf("%03d.%03dus\t", (int)(result / 1000), (int)(result % 1000));
|
||||
}
|
||||
|
||||
void show_times_detail(volatile double *ft, int nsamples, char *title,
|
||||
uint32_t ignore_first)
|
||||
{
|
||||
int i;
|
||||
double delta = 0.0, min = 0.0, max = 0.0, ave_dev = 0.0 , ave = 0.0 ;
|
||||
unsigned int start_sample = 0, total_samples = 0, con_ave = 0, con_min = 0,
|
||||
error = 0;
|
||||
double total = 0.0;
|
||||
|
||||
if (ignore_first) {
|
||||
start_sample = 1;
|
||||
total_samples = nsamples - 1;
|
||||
} else {
|
||||
start_sample = 0;
|
||||
total_samples = nsamples;
|
||||
}
|
||||
|
||||
for (i = start_sample; i < nsamples; i++) {
|
||||
if (ft[i] <= 0) {
|
||||
ft[i] = 0;
|
||||
error ++;
|
||||
}
|
||||
|
||||
total += ft[i];
|
||||
}
|
||||
|
||||
ave = total / (float)(total_samples - error);
|
||||
total = 0.0;
|
||||
min = 0xffffffff;
|
||||
max = 0.0;
|
||||
|
||||
for (i = start_sample; i < nsamples; i++) {
|
||||
if (ft[i] > (10 * ave)) {
|
||||
ft[i] = 0;
|
||||
error ++;
|
||||
}
|
||||
|
||||
delta = ft[i];
|
||||
|
||||
if (delta != 0) {
|
||||
if (delta < min) {
|
||||
min = delta;
|
||||
}
|
||||
|
||||
if (delta > max) {
|
||||
max = delta;
|
||||
}
|
||||
}
|
||||
|
||||
total += delta;
|
||||
}
|
||||
|
||||
ave = total / (float)(total_samples - error);
|
||||
|
||||
total = 0.0;
|
||||
ave_dev = 0.0;
|
||||
|
||||
for (i = start_sample; i < nsamples; i++) {
|
||||
delta = ft[i];
|
||||
|
||||
if (delta != 0) {
|
||||
delta = delta - ave;
|
||||
|
||||
if (delta < 0) {
|
||||
delta = -delta;
|
||||
}
|
||||
|
||||
ave_dev += delta;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
ave_dev /= (float)(total_samples - error);
|
||||
|
||||
con_ave = 0;
|
||||
con_min = 0;
|
||||
|
||||
for (i = start_sample; i < nsamples; i++) {
|
||||
|
||||
delta = ft[i];
|
||||
|
||||
if (delta != 0) {
|
||||
if ((delta <= (ave + ave_dev)) && (delta >= (ave - ave_dev))) {
|
||||
con_ave++;
|
||||
}
|
||||
|
||||
if ((delta <= (min + ave_dev)) && (delta >= (min - ave_dev))) {
|
||||
con_min++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
con_ave = (con_ave * 100) / total_samples;
|
||||
con_min = (con_min * 100) / total_samples;
|
||||
show_time_in_us((unsigned long) ave);
|
||||
show_time_in_us((unsigned long) min);
|
||||
show_time_in_us((unsigned long) max);
|
||||
show_time_in_us((unsigned long) ave_dev);
|
||||
printf(" %d%%, %d%%\t", con_ave, con_min);
|
||||
printf(title);
|
||||
printf(" %d\r\n", total_samples);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void show_times_detail_2(volatile unsigned long ft[], int nsamples,
|
||||
char *title, uint32_t ignore_first)
|
||||
{
|
||||
int i;
|
||||
|
||||
long long delta, min, max, con_ave, con_min, ave_dev;
|
||||
int start_sample, total_samples;
|
||||
long long total, ave;
|
||||
|
||||
if (ignore_first) {
|
||||
start_sample = 1;
|
||||
total_samples = nsamples - 1;
|
||||
} else {
|
||||
start_sample = 0;
|
||||
total_samples = nsamples;
|
||||
}
|
||||
|
||||
total = 0;
|
||||
min = 0x7fffffff;
|
||||
max = 0;
|
||||
|
||||
for (i = start_sample; i < nsamples; i++) {
|
||||
delta = ft[i];
|
||||
delta *= 1000;
|
||||
total += delta;
|
||||
|
||||
if (delta < min) {
|
||||
min = delta;
|
||||
}
|
||||
|
||||
if (delta > max) {
|
||||
max = delta;
|
||||
}
|
||||
}
|
||||
|
||||
ave = total / total_samples;
|
||||
total = 0;
|
||||
ave_dev = 0;
|
||||
|
||||
for (i = start_sample; i < nsamples; i++) {
|
||||
delta = ft[i];
|
||||
delta *= 1000;
|
||||
delta = delta - ave;
|
||||
|
||||
if (delta < 0) {
|
||||
delta = -delta;
|
||||
}
|
||||
|
||||
ave_dev += delta;
|
||||
}
|
||||
|
||||
ave_dev /= total_samples;
|
||||
con_ave = 0;
|
||||
con_min = 0;
|
||||
|
||||
for (i = start_sample; i < nsamples; i++) {
|
||||
delta = ft[i];
|
||||
delta *= 1000;
|
||||
|
||||
if ((delta <= (ave + ave_dev)) && (delta >= (ave - ave_dev))) {
|
||||
con_ave++;
|
||||
}
|
||||
|
||||
if ((delta <= (min + ave_dev)) && (delta >= (min - ave_dev))) {
|
||||
con_min++;
|
||||
}
|
||||
}
|
||||
|
||||
con_ave = (con_ave * 100) / total_samples;
|
||||
con_min = (con_min * 100) / total_samples;
|
||||
show_time_in_us(ave);
|
||||
show_time_in_us(min);
|
||||
show_time_in_us(max);
|
||||
show_time_in_us(ave_dev);
|
||||
printf(" %lld%% %lld%%", con_ave, con_min);
|
||||
printf(" %s\n", title);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
end_of_test_group(void)
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
104
Living_SDK/kernel/rhino/test/perf/sem.c
Normal file
104
Living_SDK/kernel/rhino/test/perf/sem.c
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#define TASK_TEST_PRI 20
|
||||
#define TASK_MAIN_PRI 15
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
#define SWITCH_NUM 100
|
||||
|
||||
extern ksem_t *SYNhandle;
|
||||
extern void WaitForNew_tick(void);
|
||||
extern double Turn_to_Realtime(double counter);
|
||||
extern void show_times_detail(volatile double *ft, int nsamples,
|
||||
char *title, uint32_t ignore_first);
|
||||
|
||||
extern void hobbit_timer0_stop(void);
|
||||
extern void hobbit_timer0_init(uint32_t hz);
|
||||
extern void hobbit_timer0_start(void);
|
||||
extern uint32_t hobbit_timer0_get_curval(void);
|
||||
extern void hobbit_timer0_clr(void);
|
||||
|
||||
static volatile unsigned long Starttime, Endtime, Runtime;
|
||||
static double ShufBUFF[sizeof(double)*SWITCH_NUM] ;
|
||||
static volatile unsigned long ShufSwitch = 0;
|
||||
static ksem_t *Shufhandle[2];
|
||||
static ktask_t *ShufTaskHandle[2];
|
||||
static ksem_t *ShufSynhandle;
|
||||
|
||||
|
||||
static void BinaryShuf1(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
|
||||
Starttime = hobbit_timer0_get_curval();
|
||||
krhino_sem_give(Shufhandle[0]);
|
||||
krhino_sem_take(Shufhandle[1], RHINO_WAIT_FOREVER);
|
||||
|
||||
if (ShufSwitch >= SWITCH_NUM) {
|
||||
krhino_sem_give(ShufSynhandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void BinaryShuf2(void *arg)
|
||||
{
|
||||
WaitForNew_tick();
|
||||
|
||||
while (1) {
|
||||
krhino_sem_take(Shufhandle[0], RHINO_WAIT_FOREVER);
|
||||
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
Runtime = Starttime - Endtime;
|
||||
|
||||
ShufBUFF[ShufSwitch] = Runtime;
|
||||
krhino_sem_give(Shufhandle[1]);
|
||||
ShufSwitch++;
|
||||
|
||||
if (ShufSwitch >= SWITCH_NUM) {
|
||||
krhino_sem_give(ShufSynhandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryShufTimetest(void *arg)
|
||||
{
|
||||
unsigned long i ;
|
||||
WaitForNew_tick();
|
||||
|
||||
krhino_sem_dyn_create(&ShufSynhandle, "synsem", 0);
|
||||
ShufSwitch = 0;
|
||||
|
||||
hobbit_timer0_stop();
|
||||
hobbit_timer0_init(0xffffffff);
|
||||
|
||||
memset(ShufBUFF, 0, sizeof(double)*SWITCH_NUM);
|
||||
|
||||
krhino_sem_dyn_create(&Shufhandle[0], "sem", 0);
|
||||
krhino_sem_dyn_create(&Shufhandle[1], "sem", 0);
|
||||
|
||||
|
||||
krhino_task_dyn_create(&ShufTaskHandle[0], "test_task", 0, TASK_TEST_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, BinaryShuf1, 1);
|
||||
krhino_task_dyn_create(&ShufTaskHandle[1], "test_task", 0, TASK_TEST_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, BinaryShuf2, 1);
|
||||
|
||||
hobbit_timer0_start();
|
||||
|
||||
krhino_sem_take(ShufSynhandle, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_task_dyn_del(ShufTaskHandle[0]);
|
||||
krhino_task_dyn_del(ShufTaskHandle[1]);
|
||||
|
||||
for (i = 0; i < SWITCH_NUM; i++) {
|
||||
ShufBUFF[i] = (double) Turn_to_Realtime(ShufBUFF[i]);
|
||||
}
|
||||
|
||||
show_times_detail(ShufBUFF , SWITCH_NUM, "BinaryShuf\t", 1);
|
||||
krhino_task_sleep(30);
|
||||
krhino_sem_give(SYNhandle);
|
||||
}
|
||||
141
Living_SDK/kernel/rhino/test/perf/taskpree.c
Normal file
141
Living_SDK/kernel/rhino/test/perf/taskpree.c
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#define TASK_TEST_PRI 20
|
||||
#define TASK_MAIN_PRI 15
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
#define PreeTime 100
|
||||
|
||||
extern ksem_t *SYNhandle;
|
||||
extern void WaitForNew_tick(void);
|
||||
extern double Turn_to_Realtime(double counter);
|
||||
extern void show_times_detail(volatile double *ft, int nsamples,
|
||||
char *title, uint32_t ignore_first);
|
||||
|
||||
extern void hobbit_timer0_stop(void);
|
||||
extern void hobbit_timer0_init(uint32_t hz);
|
||||
extern void hobbit_timer0_start(void);
|
||||
extern uint32_t hobbit_timer0_get_curval(void);
|
||||
extern void hobbit_timer0_clr(void);
|
||||
|
||||
static ksem_t *PreeSynhandle;
|
||||
static double PreeBUFF[sizeof(double)*PreeTime] ;
|
||||
static ktask_t *PreeTaskHandle[5];
|
||||
static volatile unsigned long PreeCount = 0;
|
||||
static volatile unsigned long Starttime = 0, Endtime = 0, Runtime = 0;
|
||||
|
||||
static void Preemption0(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
|
||||
Starttime = hobbit_timer0_get_curval();
|
||||
krhino_task_resume(PreeTaskHandle[1]);
|
||||
|
||||
if (PreeCount >= PreeTime) {
|
||||
krhino_sem_give(PreeSynhandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void Preemption1(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
Runtime = Starttime - Endtime;
|
||||
|
||||
PreeBUFF[PreeCount++] = (double)Runtime;
|
||||
|
||||
if (PreeCount >= PreeTime) {
|
||||
krhino_sem_give(PreeSynhandle);
|
||||
}
|
||||
|
||||
Starttime = hobbit_timer0_get_curval();
|
||||
krhino_task_resume(PreeTaskHandle[2]);
|
||||
|
||||
krhino_task_suspend(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
static void Preemption2(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
Runtime = Starttime - Endtime;
|
||||
PreeBUFF[PreeCount++] = (double)Runtime;
|
||||
|
||||
if (PreeCount >= PreeTime) {
|
||||
krhino_sem_give(PreeSynhandle);
|
||||
}
|
||||
|
||||
Starttime = hobbit_timer0_get_curval();
|
||||
krhino_task_resume(PreeTaskHandle[3]);
|
||||
|
||||
krhino_task_suspend(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
static void Preemption3(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
Runtime = Starttime - Endtime;
|
||||
|
||||
PreeBUFF[PreeCount++] = (double)Runtime;
|
||||
|
||||
if (PreeCount >= PreeTime) {
|
||||
krhino_sem_give(PreeSynhandle);
|
||||
}
|
||||
|
||||
krhino_task_suspend(krhino_cur_task_get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PreemptionTimetest(void *arg)
|
||||
{
|
||||
unsigned long i ;
|
||||
WaitForNew_tick();
|
||||
krhino_sem_dyn_create(&PreeSynhandle, "pree", 0);
|
||||
|
||||
hobbit_timer0_stop();
|
||||
hobbit_timer0_init(0xffffffff);
|
||||
|
||||
memset(PreeBUFF, 0, sizeof(double)*PreeTime);
|
||||
krhino_task_dyn_create(&PreeTaskHandle[0], "test_task", 0, TASK_TEST_PRI + 4,
|
||||
0, TASK_TEST_STACK_SIZE, Preemption0, 1);
|
||||
krhino_task_dyn_create(&PreeTaskHandle[1], "test_task", 0, TASK_TEST_PRI + 3,
|
||||
0, TASK_TEST_STACK_SIZE, Preemption1, 1);
|
||||
krhino_task_dyn_create(&PreeTaskHandle[2], "test_task", 0, TASK_TEST_PRI + 2,
|
||||
0, TASK_TEST_STACK_SIZE, Preemption2, 1);
|
||||
krhino_task_dyn_create(&PreeTaskHandle[3], "test_task", 0, TASK_TEST_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, Preemption3, 1);
|
||||
krhino_task_suspend(PreeTaskHandle[1]);
|
||||
krhino_task_suspend(PreeTaskHandle[2]);
|
||||
krhino_task_suspend(PreeTaskHandle[3]);
|
||||
|
||||
hobbit_timer0_start();
|
||||
krhino_sem_take(PreeSynhandle, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_task_dyn_del(PreeTaskHandle[0]);
|
||||
krhino_task_dyn_del(PreeTaskHandle[1]);
|
||||
krhino_task_dyn_del(PreeTaskHandle[2]);
|
||||
krhino_task_dyn_del(PreeTaskHandle[3]);
|
||||
|
||||
for (i = 0; i < PreeTime; i++) {
|
||||
PreeBUFF[i] = (double) Turn_to_Realtime(PreeBUFF[i]);
|
||||
}
|
||||
|
||||
show_times_detail(PreeBUFF , PreeTime, "TaskPree\t", 1);
|
||||
krhino_task_sleep(5);
|
||||
krhino_sem_give(SYNhandle);
|
||||
}
|
||||
106
Living_SDK/kernel/rhino/test/perf/taskswitch.c
Normal file
106
Living_SDK/kernel/rhino/test/perf/taskswitch.c
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#define TASK_TEST_PRI 20
|
||||
#define TASK_MAIN_PRI 15
|
||||
#define TASK_TEST_STACK_SIZE 1024
|
||||
|
||||
extern ksem_t *SYNhandle;
|
||||
extern void WaitForNew_tick(void);
|
||||
extern double Turn_to_Realtime(double counter);
|
||||
extern void show_times_detail(volatile double *ft, int nsamples,
|
||||
char *title, uint32_t ignore_first);
|
||||
|
||||
extern void hobbit_timer0_stop(void);
|
||||
extern void hobbit_timer0_init(uint32_t hz);
|
||||
extern void hobbit_timer0_start(void);
|
||||
extern uint32_t hobbit_timer0_get_curval(void);
|
||||
extern void hobbit_timer0_clr(void);
|
||||
|
||||
#define TASKSWITCH_NUM 100
|
||||
|
||||
static volatile unsigned long TaskSwitch = 0;
|
||||
static ktask_t *xSwitchTaskHandle[2];
|
||||
static volatile unsigned long Starttime, Endtime;
|
||||
static volatile double SwitchTimeBUFF[sizeof(double)*TASKSWITCH_NUM] ;
|
||||
static ksem_t *Switchhandle[2];
|
||||
static ksem_t *SwitchSynhandle;
|
||||
|
||||
|
||||
static void SwitchTask3(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
for (TaskSwitch = 0; TaskSwitch < TASKSWITCH_NUM;) {
|
||||
Starttime = hobbit_timer0_get_curval();
|
||||
krhino_task_yield();
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
SwitchTimeBUFF[TaskSwitch++] = (double)(Starttime - Endtime);
|
||||
}
|
||||
|
||||
krhino_sem_give(SwitchSynhandle);
|
||||
}
|
||||
}
|
||||
|
||||
static void SwitchTask4(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
for (; TaskSwitch < TASKSWITCH_NUM;) {
|
||||
Endtime = hobbit_timer0_get_curval();
|
||||
SwitchTimeBUFF[TaskSwitch++] = (double)(Starttime - Endtime);
|
||||
Starttime = hobbit_timer0_get_curval();
|
||||
krhino_task_yield();
|
||||
}
|
||||
|
||||
krhino_sem_give(SwitchSynhandle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TaskYIELDtimeTest(void *arg)
|
||||
{
|
||||
unsigned long i ;
|
||||
|
||||
krhino_sem_dyn_create(&SwitchSynhandle, "switch", 0);
|
||||
TaskSwitch = 0;
|
||||
WaitForNew_tick();
|
||||
|
||||
hobbit_timer0_stop();
|
||||
|
||||
hobbit_timer0_init(0xffffffff);
|
||||
|
||||
memset((void *)SwitchTimeBUFF, 0, sizeof(double)*TASKSWITCH_NUM);
|
||||
|
||||
krhino_sem_dyn_create(&Switchhandle[0], "s1", 0);
|
||||
|
||||
krhino_sem_dyn_create(&Switchhandle[1], "s1", 0);
|
||||
|
||||
|
||||
krhino_task_dyn_create(&xSwitchTaskHandle[0], "test_task", 0, TASK_TEST_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, SwitchTask3, 1);
|
||||
|
||||
krhino_task_dyn_create(&xSwitchTaskHandle[1], "test_task", 0, TASK_TEST_PRI + 1,
|
||||
0, TASK_TEST_STACK_SIZE, SwitchTask4, 1);
|
||||
|
||||
hobbit_timer0_start();
|
||||
|
||||
krhino_sem_take(SwitchSynhandle, RHINO_WAIT_FOREVER);
|
||||
|
||||
krhino_task_dyn_del(xSwitchTaskHandle[0]);
|
||||
krhino_task_dyn_del(xSwitchTaskHandle[1]);
|
||||
|
||||
|
||||
for (i = 0; i < TASKSWITCH_NUM; i++) {
|
||||
SwitchTimeBUFF[i] = Turn_to_Realtime(SwitchTimeBUFF[i]);
|
||||
|
||||
}
|
||||
|
||||
show_times_detail(SwitchTimeBUFF , TASKSWITCH_NUM, "TaskYIELD\t", 1);
|
||||
krhino_task_sleep(10);
|
||||
|
||||
krhino_sem_give(SYNhandle);
|
||||
|
||||
}
|
||||
78
Living_SDK/kernel/rhino/test/perf/timer.c
Normal file
78
Living_SDK/kernel/rhino/test/perf/timer.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
|
||||
#define putreg32(v, x) (*(volatile uint32_t*)(x) = (v))
|
||||
#define getreg32(x) (*(volatile uint32_t *)(x))
|
||||
#define HOBBIT_TIMER0_BASE (0x50000000)
|
||||
#define TIMER0_LOAD_COUNT (volatile uint32_t *)(HOBBIT_TIMER0_BASE + 0x00)
|
||||
#define TIMER0_CUR_VAL (volatile uint32_t *)(HOBBIT_TIMER0_BASE + 0x04)
|
||||
#define TIMER0_CONTROL (volatile uint32_t *)(HOBBIT_TIMER0_BASE + 0x08)
|
||||
#define TIMER0_EOI (volatile uint32_t *)(HOBBIT_TIMER0_BASE + 0x0C)
|
||||
#define TIMER0_INT_STAT (volatile uint32_t *)(HOBBIT_TIMER0_BASE + 0x10)
|
||||
|
||||
|
||||
|
||||
|
||||
#define TIMER_ENABLE (1UL << 0)
|
||||
#define TIMER_MOD_FREE (0UL << 1)
|
||||
#define TIMER_MOD_USER (1UL << 1)
|
||||
#define TIMER_INT_MASK (1UL << 2)
|
||||
|
||||
static inline uint32_t readreg32(volatile uint32_t *addr)
|
||||
{
|
||||
return *(volatile uint32_t *)addr;
|
||||
}
|
||||
|
||||
static inline void writereg32(uint32_t val, volatile uint32_t *addr)
|
||||
{
|
||||
*(volatile uint32_t *)addr = val;
|
||||
}
|
||||
|
||||
void hobbit_timer0_clr(void)
|
||||
{
|
||||
readreg32(TIMER0_EOI);
|
||||
}
|
||||
|
||||
uint32_t hobbit_timer0_get_curval(void)
|
||||
{
|
||||
return getreg32(TIMER0_CUR_VAL);
|
||||
}
|
||||
|
||||
void hobbit_timer0_stop(void)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = getreg32(TIMER0_CONTROL);
|
||||
reg &= ~(TIMER_ENABLE);
|
||||
putreg32(reg, TIMER0_CONTROL);
|
||||
}
|
||||
|
||||
void hobbit_timer0_init(uint32_t hz)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
writereg32(hz, TIMER0_LOAD_COUNT);
|
||||
|
||||
reg = readreg32(TIMER0_CONTROL);
|
||||
reg |= TIMER_MOD_USER;
|
||||
reg |= TIMER_ENABLE;
|
||||
reg &= ~(TIMER_INT_MASK);
|
||||
writereg32(reg, TIMER0_CONTROL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void hobbit_timer0_start(void)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = getreg32(TIMER0_CONTROL);
|
||||
reg |= TIMER_ENABLE;
|
||||
putreg32(reg, TIMER0_CONTROL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
62
Living_SDK/kernel/rhino/test/posix/posix_cond_test.c
Normal file
62
Living_SDK/kernel/rhino/test/posix/posix_cond_test.c
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static pthread_t thread;
|
||||
static pthread_cond_t cond;
|
||||
static pthread_mutex_t mutex;
|
||||
static int flag = 1;
|
||||
|
||||
extern int gettimeofday(struct timeval *tv, void *tzp);
|
||||
|
||||
static void *demo_task1(void *arg)
|
||||
{
|
||||
struct timeval now;
|
||||
struct timespec outtime;
|
||||
pthread_mutex_lock(&mutex);
|
||||
while (flag)
|
||||
{
|
||||
printf("demo_task1\n");
|
||||
gettimeofday(&now, NULL);
|
||||
outtime.tv_sec = now.tv_sec + 5;
|
||||
outtime.tv_nsec = now.tv_usec * 1000;
|
||||
pthread_cond_timedwait(&cond, &mutex, &outtime);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
printf("demo_task1 exit\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task2(void *arg)
|
||||
{
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND*10);
|
||||
printf("Now terminate the thread!\n");
|
||||
flag = 0;
|
||||
pthread_mutex_lock(&mutex);
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *init_task(void *arg)
|
||||
{
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
pthread_cond_init(&cond, NULL);
|
||||
|
||||
pthread_create(&thread, NULL, demo_task1, NULL);
|
||||
pthread_create(&thread, NULL, demo_task2, NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void posix_test_case4(void)
|
||||
{
|
||||
pthread_create(&thread, NULL, init_task, NULL);
|
||||
}
|
||||
|
||||
|
||||
58
Living_SDK/kernel/rhino/test/posix/posix_mutex_test.c
Normal file
58
Living_SDK/kernel/rhino/test/posix/posix_mutex_test.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static pthread_mutex_t mutex;
|
||||
|
||||
static void *init_task(void *arg)
|
||||
{
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task1(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("demo_task1 get sem %d\n", count++);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task2(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
printf("demo_task2 release sem %d\n", count++);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void posix_test_case3(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
pthread_create(&thread, NULL, init_task, NULL);
|
||||
pthread_create(&thread, NULL, demo_task1, NULL);
|
||||
pthread_create(&thread, NULL, demo_task2, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
57
Living_SDK/kernel/rhino/test/posix/posix_sem_test.c
Normal file
57
Living_SDK/kernel/rhino/test/posix/posix_sem_test.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
static sem_t sem;
|
||||
|
||||
static void *init_task(void *arg)
|
||||
{
|
||||
sem_init(&sem, 0, 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task1(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
sem_wait(&sem);
|
||||
printf("demo_task1 get sem %d\n", count++);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task2(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
sem_post(&sem);
|
||||
|
||||
printf("demo_task2 release sem %d\n", count++);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void posix_test_case2(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
pthread_create(&thread, NULL, init_task, NULL);
|
||||
pthread_create(&thread, NULL, demo_task1, NULL);
|
||||
pthread_create(&thread, NULL, demo_task2, NULL);
|
||||
}
|
||||
|
||||
|
||||
33
Living_SDK/kernel/rhino/test/posix/posix_task_test.c
Normal file
33
Living_SDK/kernel/rhino/test/posix/posix_task_test.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static void *demo_task(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("hello world! count %d\n", count++);
|
||||
|
||||
//sleep 1 second
|
||||
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* test target : pthread_create() */
|
||||
void posix_test_case1(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
pthread_create(&thread, NULL, demo_task, NULL);
|
||||
}
|
||||
|
||||
19
Living_SDK/kernel/rhino/test/posix/posix_test.c
Normal file
19
Living_SDK/kernel/rhino/test/posix/posix_test.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
extern void posix_test_case1(void);
|
||||
extern void posix_test_case2(void);
|
||||
extern void posix_test_case3(void);
|
||||
extern void posix_test_case4(void);
|
||||
|
||||
|
||||
void posix_test_entry(void)
|
||||
{
|
||||
//posix_test_case1();
|
||||
//posix_test_case2();
|
||||
//posix_test_case3();
|
||||
//posix_test_case4();
|
||||
}
|
||||
|
||||
|
||||
85
Living_SDK/kernel/rhino/test/test.mk
Normal file
85
Living_SDK/kernel/rhino/test/test.mk
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
NAME := test
|
||||
|
||||
GLOBAL_INCLUDES += ./
|
||||
|
||||
ifeq ($(COMPILER),)
|
||||
$(NAME)_CFLAGS += -Wall -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-implicit-function-declaration
|
||||
$(NAME)_CFLAGS += -Wno-type-limits -Wno-sign-compare -Wno-pointer-sign -Wno-uninitialized
|
||||
$(NAME)_CFLAGS += -Wno-return-type -Wno-unused-function -Wno-unused-but-set-variable
|
||||
$(NAME)_CFLAGS += -Wno-unused-value -Wno-strict-aliasing
|
||||
else ifeq ($(COMPILER),gcc)
|
||||
$(NAME)_CFLAGS += -Wall -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-implicit-function-declaration
|
||||
$(NAME)_CFLAGS += -Wno-type-limits -Wno-sign-compare -Wno-pointer-sign -Wno-uninitialized
|
||||
$(NAME)_CFLAGS += -Wno-return-type -Wno-unused-function -Wno-unused-but-set-variable
|
||||
$(NAME)_CFLAGS += -Wno-unused-value -Wno-strict-aliasing
|
||||
endif
|
||||
|
||||
$(NAME)_SOURCES := \
|
||||
test_fw.c \
|
||||
test_self_entry.c \
|
||||
core/buf_queue/buf_queue_del.c \
|
||||
core/buf_queue/buf_queue_dyn_create.c \
|
||||
core/buf_queue/buf_queue_flush.c \
|
||||
core/buf_queue/buf_queue_info_get.c \
|
||||
core/buf_queue/buf_queue_recv.c \
|
||||
core/buf_queue/buf_queue_test.c \
|
||||
core/event/event_break.c \
|
||||
core/event/event_opr.c \
|
||||
core/event/event_param.c \
|
||||
core/event/event_reinit.c \
|
||||
core/event/event_test.c \
|
||||
core/mm/mm_break.c \
|
||||
core/mm/mm_opr.c \
|
||||
core/mm/mm_param.c \
|
||||
core/mm/mm_test.c \
|
||||
core/mm_blk/mm_blk_break.c \
|
||||
core/mm_blk/mm_blk_fragment.c \
|
||||
core/mm_blk/mm_blk_opr.c \
|
||||
core/mm_blk/mm_blk_param.c \
|
||||
core/mm_blk/mm_blk_reinit.c \
|
||||
core/mm_blk/mm_blk_test.c \
|
||||
core/mutex/mutex_opr.c \
|
||||
core/mutex/mutex_param.c \
|
||||
core/mutex/mutex_reinit.c \
|
||||
core/mutex/mutex_test.c \
|
||||
core/queue/queue_back_send.c \
|
||||
core/queue/queue_del.c \
|
||||
core/queue/queue_flush.c \
|
||||
core/queue/queue_info_get.c \
|
||||
core/queue/queue_is_full.c \
|
||||
core/queue/queue_nowait_recv.c \
|
||||
core/queue/queue_test.c \
|
||||
core/sem/sem_break.c \
|
||||
core/sem/sem_count.c \
|
||||
core/sem/sem_param.c \
|
||||
core/sem/sem_reinit.c \
|
||||
core/sem/sem_test.c \
|
||||
core/sem/sem_opr.c \
|
||||
core/sys/sys_opr.c \
|
||||
core/sys/sys_test.c \
|
||||
core/task/task_sleep.c \
|
||||
core/task/task_del.c \
|
||||
core/task/task_suspend_test.c \
|
||||
core/task/task_test.c \
|
||||
core/task/task_yield_test.c \
|
||||
core/task/task_misc_test.c \
|
||||
core/task_sem/tasksem_count.c \
|
||||
core/task_sem/tasksem_opr.c \
|
||||
core/task_sem/tasksem_param.c \
|
||||
core/task_sem/tasksem_test.c \
|
||||
core/time/time_opr.c \
|
||||
core/time/time_test.c \
|
||||
core/timer/timer_change.c \
|
||||
core/timer/timer_create_del.c \
|
||||
core/timer/timer_dyn_create_del.c \
|
||||
core/timer/timer_start_stop.c \
|
||||
core/timer/timer_test.c \
|
||||
core/workqueue/workqueue_test.c \
|
||||
core/workqueue/workqueue_interface.c \
|
||||
core/ringbuf/ringbuf_break.c \
|
||||
core/ringbuf/ringbuf_test.c \
|
||||
core/combination/comb_test.c \
|
||||
core/combination/sem_event.c \
|
||||
core/combination/sem_queue_buf.c \
|
||||
core/combination/sem_mutex.c \
|
||||
|
||||
129
Living_SDK/kernel/rhino/test/test_fw.c
Normal file
129
Living_SDK/kernel/rhino/test/test_fw.c
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
uint32_t test_case_success;
|
||||
uint32_t test_case_fail;
|
||||
uint32_t test_case_check_err;
|
||||
static ksem_t test_case_sem;
|
||||
static kmutex_t test_case_mutex;
|
||||
static test_case_t *case_func_runner = NULL;
|
||||
|
||||
extern void task_test(void);
|
||||
extern void mm_test(void);
|
||||
extern void mm_blk_test(void);
|
||||
extern void time_test(void);
|
||||
extern void sys_test(void);
|
||||
extern void event_test(void);
|
||||
extern void sem_test(void);
|
||||
extern void tasksem_test(void);
|
||||
extern void mutex_test(void);
|
||||
extern void timer_test(void);
|
||||
extern void queue_test(void);
|
||||
extern void buf_queue_test(void);
|
||||
extern void comb_test(void);
|
||||
extern void workqueue_test(void);
|
||||
extern void ysh_cmd_test(void);
|
||||
extern void mm_region_test(void);
|
||||
extern void ringbuf_test(void);
|
||||
|
||||
test_case_map_t test_fw_map[] = {
|
||||
{"task_test", task_test},
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
{"mm_test", mm_test},
|
||||
#endif
|
||||
{"mm_blk_test", mm_blk_test},
|
||||
{"time_test", time_test},
|
||||
{"sys_test", sys_test},
|
||||
{"event_test", event_test},
|
||||
{"sem_test", sem_test},
|
||||
{"tasksem_test", tasksem_test},
|
||||
{"mutex_test", mutex_test},
|
||||
{"timer_test", timer_test},
|
||||
{"ringbuf_test", ringbuf_test},
|
||||
{"queue_test", queue_test},
|
||||
#if (RHINO_CONFIG_WORKQUEUE > 0)
|
||||
{"workqueue_test", workqueue_test},
|
||||
#endif
|
||||
{"buf_queue_test", buf_queue_test},
|
||||
{"comb_test", comb_test},
|
||||
/* last must be NULL! */
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
uint8_t test_case_register(test_case_t *case_runner)
|
||||
{
|
||||
if (case_func_runner == NULL) {
|
||||
case_func_runner = case_runner;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void test_case_unregister(void)
|
||||
{
|
||||
if (case_func_runner != NULL) {
|
||||
case_func_runner = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void test_case_run(void)
|
||||
{
|
||||
test_case_t *runner;
|
||||
|
||||
runner = (test_case_t *)case_func_runner;
|
||||
|
||||
while (1) {
|
||||
if (*runner == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
(*runner)();
|
||||
runner++;
|
||||
next_test_case_wait();
|
||||
}
|
||||
}
|
||||
|
||||
void test_case_init(void)
|
||||
{
|
||||
test_case_success = 0;
|
||||
test_case_fail = 0;
|
||||
krhino_sem_create(&test_case_sem, "test_case_sem", 0);
|
||||
krhino_mutex_create(&test_case_mutex, "test_case_mutex");
|
||||
}
|
||||
|
||||
void test_case_cleanup(void)
|
||||
{
|
||||
krhino_sem_del(&test_case_sem);
|
||||
krhino_mutex_del(&test_case_mutex);
|
||||
}
|
||||
|
||||
void test_case_critical_enter(void)
|
||||
{
|
||||
krhino_mutex_lock(&test_case_mutex, RHINO_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
void test_case_critical_exit(void)
|
||||
{
|
||||
krhino_mutex_unlock(&test_case_mutex);
|
||||
}
|
||||
|
||||
void next_test_case_notify(void)
|
||||
{
|
||||
if (krhino_sem_give(&test_case_sem) != RHINO_SUCCESS) {
|
||||
printf("next_test_case_notify failed!!!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void next_test_case_wait(void)
|
||||
{
|
||||
if (krhino_sem_take(&test_case_sem, RHINO_WAIT_FOREVER) != RHINO_SUCCESS) {
|
||||
printf("next_test_case_wait failed!!!\n");
|
||||
}
|
||||
|
||||
krhino_task_sleep(10);
|
||||
}
|
||||
62
Living_SDK/kernel/rhino/test/test_fw.h
Normal file
62
Living_SDK/kernel/rhino/test/test_fw.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef TEST_FRAMEWORK_H
|
||||
#define TEST_FRAMEWORK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*test_case_t)(void);
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
test_case_t fn;
|
||||
} test_case_map_t;
|
||||
|
||||
extern test_case_map_t test_fw_map[];
|
||||
extern void vc_port_printf(char *f, ...);
|
||||
extern uint32_t test_case_success;
|
||||
extern uint32_t test_case_fail;
|
||||
extern uint32_t test_case_check_err;
|
||||
|
||||
void next_test_case_notify(void);
|
||||
void next_test_case_wait(void);
|
||||
uint8_t test_case_register(test_case_t *case_runner);
|
||||
void test_case_run(void);
|
||||
void test_case_unregister(void);
|
||||
void test_case_init(void);
|
||||
void test_case_cleanup(void);
|
||||
void test_case_critical_enter(void);
|
||||
void test_case_critical_exit(void);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define printf vc_port_printf
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#define PASS 0
|
||||
#define FAIL 1
|
||||
|
||||
#define PRINT_PASS(s) printf("%-30s test [PASS %d]\n", s, (int)test_case_success)
|
||||
#define PRINT_FAIL(s) printf("%-30s test [FAIL %d]\n", s, (int)test_case_fail)
|
||||
#define PRINT_RESULT(s, f) do { if (f == PASS) { PRINT_PASS(s); } else { PRINT_FAIL(s); }} while (0)
|
||||
|
||||
#define TEST_FW_VAL_CHK(module_name,value) do {if ((int)(value) == 0) \
|
||||
{ \
|
||||
test_case_critical_enter(); \
|
||||
test_case_check_err++; \
|
||||
test_case_critical_exit(); \
|
||||
printf("%s test is [FAIL %d], func %s, line %d\n", \
|
||||
module_name, (int)++test_case_check_err, __FUNCTION__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* TEST_FRAMEWORK_H */
|
||||
40
Living_SDK/kernel/rhino/test/test_self_entry.c
Normal file
40
Living_SDK/kernel/rhino/test/test_self_entry.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
|
||||
#define TEST_CASE_TASK_STACK_SIZE 1024
|
||||
ktask_t test_case_task;
|
||||
cpu_stack_t test_case_task_stack[TEST_CASE_TASK_STACK_SIZE];
|
||||
|
||||
void test_case_task_entry(void *arg)
|
||||
{
|
||||
int item;
|
||||
|
||||
test_case_init();
|
||||
|
||||
for (item = 0 ;; item++) {
|
||||
if (test_fw_map[item].fn == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
(*test_fw_map[item].fn)();
|
||||
}
|
||||
|
||||
printf("all test finished, successed test case %d, failed test case %d\n",
|
||||
(int)test_case_success, (int)test_case_fail);
|
||||
|
||||
while (1) {
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
void test_case_task_start(void)
|
||||
{
|
||||
krhino_task_create(&test_case_task, "test_case_task", NULL, 5,
|
||||
0, test_case_task_stack, TEST_CASE_TASK_STACK_SIZE,
|
||||
test_case_task_entry, 1);
|
||||
}
|
||||
|
||||
109
Living_SDK/kernel/rhino/test/tools/ysh_unit_test.c
Normal file
109
Living_SDK/kernel/rhino/test/tools/ysh_unit_test.c
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <test_fw.h>
|
||||
#include "ysh_unit_test.h"
|
||||
|
||||
#define TEST_YSH_CMD_DAEMON_RPI 8
|
||||
#define TASK_TEST_STACK_SIZE 512
|
||||
|
||||
#ifdef CSP_LINUXHOST
|
||||
static ktask_t *task_0_test;
|
||||
extern ktask_t g_ysh_task;
|
||||
extern int32_t ysh_init(void);
|
||||
extern void ysh_task_start(void);
|
||||
|
||||
#ifdef CONFIG_YSH_SIMULATE
|
||||
extern uint8_t g_ysh_queue_init;
|
||||
extern kbuf_queue_t g_ysh_simulate_queue;
|
||||
#endif
|
||||
|
||||
static void task_ysh0_entry(void *arg)
|
||||
{
|
||||
#ifdef CONFIG_YSH_SIMULATE
|
||||
kstat_t tmp;
|
||||
char *cmd = NULL;
|
||||
int ret = ysh_init();
|
||||
YSH_VAL_CHK(ret == 0);
|
||||
|
||||
if (g_ysh_task.task_name == NULL) {
|
||||
ysh_task_start();
|
||||
}
|
||||
|
||||
krhino_task_sleep(1);
|
||||
if (g_ysh_queue_init == 0) {
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
return ;
|
||||
}
|
||||
|
||||
krhino_task_sleep(1);
|
||||
|
||||
cmd = "help";
|
||||
tmp = krhino_buf_queue_send(&g_ysh_simulate_queue, cmd, strlen(cmd));
|
||||
YSH_VAL_CHK(tmp == RHINO_SUCCESS);
|
||||
krhino_task_sleep(1);
|
||||
|
||||
cmd = "dumpsys task";
|
||||
tmp = krhino_buf_queue_send(&g_ysh_simulate_queue, cmd, strlen(cmd));
|
||||
|
||||
krhino_task_sleep(1);
|
||||
|
||||
cmd = "dumpsys info";
|
||||
tmp = krhino_buf_queue_send(&g_ysh_simulate_queue, cmd, strlen(cmd));
|
||||
|
||||
krhino_task_sleep(1);
|
||||
|
||||
|
||||
cmd = "bt";
|
||||
tmp = krhino_buf_queue_send(&g_ysh_simulate_queue, cmd, strlen(cmd));
|
||||
|
||||
krhino_task_sleep(1);
|
||||
|
||||
cmd = "test";
|
||||
tmp = krhino_buf_queue_send(&g_ysh_simulate_queue, cmd, strlen(cmd));
|
||||
|
||||
krhino_task_sleep(1);
|
||||
|
||||
if (test_case_check_err == 0) {
|
||||
test_case_success++;
|
||||
PRINT_RESULT("ysh test", PASS);
|
||||
} else {
|
||||
test_case_check_err = 0;
|
||||
test_case_fail++;
|
||||
PRINT_RESULT("ysh test", FAIL);
|
||||
}
|
||||
|
||||
krhino_task_del(&g_ysh_task);
|
||||
#endif
|
||||
next_test_case_notify();
|
||||
krhino_task_dyn_del(task_0_test);
|
||||
}
|
||||
|
||||
void ysh_cmd_test(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
test_case_check_err = 0;
|
||||
ret = krhino_task_dyn_create(&task_0_test, "ysh_cmd_daemon", 0,
|
||||
TEST_YSH_CMD_DAEMON_RPI,
|
||||
0, TASK_TEST_STACK_SIZE, task_ysh0_entry, 1);
|
||||
|
||||
YSH_VAL_CHK(ret == RHINO_SUCCESS);
|
||||
krhino_task_sleep(10);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
19
Living_SDK/kernel/rhino/test/tools/ysh_unit_test.h
Normal file
19
Living_SDK/kernel/rhino/test/tools/ysh_unit_test.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef YSH_TEST_H
|
||||
#define YSH_TEST_H
|
||||
|
||||
#define YSH_VAL_CHK(value) do {if ((int)(value) == 0) \
|
||||
{ \
|
||||
test_case_critical_enter(); \
|
||||
test_case_check_err++; \
|
||||
test_case_critical_exit(); \
|
||||
printf("ysh test is [FAIL %d], func %s, line %d\n", \
|
||||
++test_case_check_err, __FUNCTION__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void ysh_cmd_test(void);
|
||||
#endif /* YSH_TEST_H */
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue