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
5
Living_SDK/kernel/vcall/espos/test/component.mk
Normal file
5
Living_SDK/kernel/vcall/espos/test/component.mk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
#Component Makefile
|
||||
#
|
||||
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
||||
12
Living_SDK/kernel/vcall/espos/test/test_espos_event.c
Normal file
12
Living_SDK/kernel/vcall/espos/test/test_espos_event.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
|
||||
|
||||
// No event group API yet
|
||||
|
||||
|
||||
126
Living_SDK/kernel/vcall/espos/test/test_espos_mem.c
Normal file
126
Living_SDK/kernel/vcall/espos/test/test_espos_mem.c
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if 0
|
||||
#include "unity.h"
|
||||
#include "espos_mem.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_semaphore.h"
|
||||
#include "espos_time.h"
|
||||
|
||||
static espos_sem_t sync_semaphore;
|
||||
|
||||
TEST_CASE("ESPOS mm api test", "[espos]")
|
||||
{
|
||||
uint8_t *buf;
|
||||
uint8_t non_zero = 0;
|
||||
uint32_t i;
|
||||
|
||||
// do malloc
|
||||
buf = espos_malloc(1024);
|
||||
memset(buf, 0xFF, 1024);
|
||||
TEST_ASSERT(buf != NULL);
|
||||
espos_free(buf);
|
||||
|
||||
// do zalloc
|
||||
buf = espos_zalloc(1024);
|
||||
TEST_ASSERT(buf != NULL);
|
||||
for (i = 0; i < 1024; i++) {
|
||||
if (buf[i] != 0) {
|
||||
non_zero = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
TEST_ASSERT(non_zero == 0);
|
||||
espos_free(buf);
|
||||
}
|
||||
|
||||
static int tryAllocMem()
|
||||
{
|
||||
int **mem;
|
||||
int i, noAllocated, j;
|
||||
mem = malloc(sizeof(int) * 1024);
|
||||
if (!mem) {
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < 1024; i++) {
|
||||
mem[i] = malloc(1024);
|
||||
if (mem[i] == NULL) {
|
||||
break;
|
||||
}
|
||||
for (j = 0; j < 1024 / 4; j++) {
|
||||
mem[i][j] = (0xdeadbeef);
|
||||
}
|
||||
}
|
||||
noAllocated = i;
|
||||
for (i = 0; i < noAllocated; i++) {
|
||||
for (j = 0; j < 1024 / 4; j++) {
|
||||
TEST_ASSERT(mem[i][j] == (0xdeadbeef));
|
||||
}
|
||||
free(mem[i]);
|
||||
}
|
||||
free(mem);
|
||||
return noAllocated;
|
||||
}
|
||||
|
||||
static void malloc_free_task(void *p)
|
||||
{
|
||||
uint32_t i;
|
||||
uint8_t *buf;
|
||||
for (i = 0; i < 0xFFFF; i++) {
|
||||
buf = espos_malloc(1024);
|
||||
espos_task_delay(1);
|
||||
espos_free(buf);
|
||||
}
|
||||
espos_sem_give(sync_semaphore);
|
||||
espos_task_del(0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS concurrent use of malloc free test", "[espos]")
|
||||
{
|
||||
uint32_t m1, m2;
|
||||
espos_task_t new_task_handle;
|
||||
|
||||
espos_sem_create(&sync_semaphore, NULL, 2, 0);
|
||||
|
||||
m1 = tryAllocMem();
|
||||
|
||||
espos_task_create(&new_task_handle, "malloc_free_task1", NULL, 1,
|
||||
0, 1024, malloc_free_task, 0);
|
||||
espos_task_create(&new_task_handle, "malloc_free_task2", NULL, 1,
|
||||
0, 1024, malloc_free_task, 0);
|
||||
|
||||
// wait task exit
|
||||
espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY);
|
||||
espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY);
|
||||
espos_sem_del(sync_semaphore);
|
||||
|
||||
m2 = tryAllocMem();
|
||||
|
||||
TEST_ASSERT(m1 == m2);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS mm API invalid parameter test", "[espos]")
|
||||
{
|
||||
uint8_t *buf;
|
||||
buf = espos_malloc(0xFFFFFFFF);
|
||||
TEST_ASSERT(buf == NULL);
|
||||
buf = espos_malloc(0);
|
||||
TEST_ASSERT(buf == NULL);
|
||||
buf = espos_zalloc(0xFFFFFFFF);
|
||||
TEST_ASSERT(buf == NULL);
|
||||
buf = espos_zalloc(0);
|
||||
TEST_ASSERT(buf == NULL);
|
||||
|
||||
// TODO: need to check if free invalid pointer will cause exception
|
||||
espos_free(NULL);
|
||||
espos_free((void *)0xFFFF);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// To add more test cases for specific RTOS, like fragment handling
|
||||
|
||||
223
Living_SDK/kernel/vcall/espos/test/test_espos_mutex.c
Normal file
223
Living_SDK/kernel/vcall/espos/test/test_espos_mutex.c
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_mutex.h"
|
||||
#include "espos_semaphore.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_queue.h"
|
||||
#include "test_espos_run_in_isr.h"
|
||||
|
||||
#define ESPOS_MUTEX_ADD_TEST_COUNT 0xFFFF
|
||||
#define ESPOS_MUTEX_CREATE_INVALID ESPOS_MUTEX_NORMAL + 10
|
||||
#define ESPOS_MUTEX_INVALID_HANDLE 0
|
||||
|
||||
static espos_sem_t sync_semaphore;
|
||||
static espos_mutex_t global_mutex;
|
||||
static espos_queue_t isr_queue;
|
||||
static int count;
|
||||
|
||||
TEST_CASE("ESPOS mutex create delete test", "[espos]")
|
||||
{
|
||||
uint32_t i;
|
||||
espos_queue_t mutex = 0;
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
if (espos_mutex_create(&mutex, ESPOS_MUTEX_NORMAL) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (espos_mutex_del(mutex) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mutex_test_task(void *p)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < ESPOS_MUTEX_ADD_TEST_COUNT; i++) {
|
||||
TEST_ASSERT(espos_mutex_lock(global_mutex, ESPOS_MAX_DELAY) == 0);
|
||||
count++;
|
||||
TEST_ASSERT(espos_mutex_unlock(global_mutex) == 0);
|
||||
}
|
||||
TEST_ASSERT(espos_sem_give(sync_semaphore) == 0);
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS mutex lock unlock test", "[espos]")
|
||||
{
|
||||
espos_task_t new_task_handle;
|
||||
|
||||
TEST_ASSERT(espos_mutex_create(&global_mutex, ESPOS_MUTEX_NORMAL) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_semaphore, 2, 0) == 0);
|
||||
count = 0;
|
||||
|
||||
TEST_ASSERT(espos_task_create(&new_task_handle, "mutex_test_task1", NULL, 1,
|
||||
0, 2048, mutex_test_task, 0) == 0);
|
||||
TEST_ASSERT(espos_task_create(&new_task_handle, "mutex_test_task2", NULL, 1,
|
||||
0, 2048, mutex_test_task, 0) == 0);
|
||||
|
||||
// wait task exit
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_del(sync_semaphore) == 0);
|
||||
|
||||
TEST_ASSERT(count == (ESPOS_MUTEX_ADD_TEST_COUNT << 1));
|
||||
TEST_ASSERT(espos_mutex_del(global_mutex) == 0);
|
||||
}
|
||||
|
||||
static void mutex_lock_test_task(void *p)
|
||||
{
|
||||
TEST_ASSERT(espos_mutex_lock(global_mutex, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_mutex_unlock(global_mutex) == 0);
|
||||
TEST_ASSERT(espos_sem_give(sync_semaphore) == 0);
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS delete mutex in use test", "[espos]")
|
||||
{
|
||||
// TODO: this case is RTOS dependent
|
||||
espos_task_t new_task_handle;
|
||||
|
||||
TEST_ASSERT(espos_mutex_create(&global_mutex, ESPOS_MUTEX_NORMAL) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_semaphore, 1, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_mutex_lock(global_mutex, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
TEST_ASSERT(espos_task_create(&new_task_handle, "mutex_lock_test_task", NULL, ESPOS_TASK_PRIO_MAX,
|
||||
0, 2048, mutex_lock_test_task, 0) == 0);
|
||||
|
||||
|
||||
TEST_ASSERT(espos_mutex_unlock(global_mutex) == 0);
|
||||
|
||||
// wait task exit
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
TEST_ASSERT(espos_mutex_del(global_mutex) == 0);
|
||||
TEST_ASSERT(espos_sem_del(sync_semaphore) == 0);
|
||||
}
|
||||
|
||||
static void mutex_unlock_test_task(void *p)
|
||||
{
|
||||
TEST_ASSERT(espos_mutex_unlock(global_mutex) == -EPERM);
|
||||
TEST_ASSERT(espos_sem_give(sync_semaphore) == 0);
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS mutex unlock by different task test", "[espos]")
|
||||
{
|
||||
espos_task_t new_task_handle;
|
||||
|
||||
TEST_ASSERT(espos_mutex_create(&global_mutex, ESPOS_MUTEX_NORMAL) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_semaphore, 1, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_mutex_lock(global_mutex, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
TEST_ASSERT(espos_task_create(&new_task_handle, "mutex_unlock_test_task", NULL, ESPOS_TASK_PRIO_MAX,
|
||||
0, 1024, mutex_unlock_test_task, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
TEST_ASSERT(espos_mutex_del(global_mutex) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_del(sync_semaphore) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS mutex lock timeout test", "[espos]")
|
||||
{
|
||||
espos_queue_t mutex;
|
||||
|
||||
TEST_ASSERT(espos_mutex_create(&mutex, ESPOS_MUTEX_NORMAL) == 0);
|
||||
|
||||
TEST_ASSERT(espos_mutex_lock(mutex, ESPOS_NO_DELAY) == 0);
|
||||
TEST_ASSERT(espos_mutex_lock(mutex, ESPOS_NO_DELAY) == -ETIMEDOUT);
|
||||
|
||||
TEST_ASSERT(espos_mutex_del(mutex) == 0);
|
||||
}
|
||||
|
||||
static void mutex_lock_hold_test_task(void *p)
|
||||
{
|
||||
espos_sem_t sem = (espos_sem_t) p;
|
||||
|
||||
TEST_ASSERT(espos_mutex_lock(global_mutex, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_give(sync_semaphore) == 0);
|
||||
TEST_ASSERT(espos_sem_take(sem, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_del(sem) == 0);
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS mutex lock get holder test", "[espos]")
|
||||
{
|
||||
espos_task_t new_task_handle;
|
||||
espos_sem_t sem;
|
||||
|
||||
TEST_ASSERT(espos_mutex_create(&global_mutex, ESPOS_MUTEX_NORMAL) == 0);
|
||||
TEST_ASSERT(espos_sem_create(&sync_semaphore, 1, 0) == 0);
|
||||
TEST_ASSERT(espos_sem_create(&sem, 1, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_mutex_lock(global_mutex, ESPOS_NO_DELAY) == 0);
|
||||
TEST_ASSERT(espos_mutex_get_holder(global_mutex) == espos_task_get_current());
|
||||
TEST_ASSERT(espos_mutex_unlock(global_mutex) == 0);
|
||||
|
||||
TEST_ASSERT(espos_task_create(&new_task_handle, "mutex_lock_hold_test_task", (void *)sem, ESPOS_TASK_PRIO_MAX,
|
||||
0, 2048, mutex_lock_hold_test_task, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_mutex_get_holder(global_mutex) == new_task_handle);
|
||||
TEST_ASSERT(espos_sem_give(sem) == 0);
|
||||
|
||||
TEST_ASSERT(espos_mutex_del(global_mutex) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS mutex recursive lock unlock test", "[espos]")
|
||||
{
|
||||
//TODO: to add this case if recursive lock is supported
|
||||
}
|
||||
|
||||
static void IRAM_ATTR mutex_isr_test(void)
|
||||
{
|
||||
uint8_t msg = 0;
|
||||
|
||||
if (espos_mutex_lock(global_mutex, 0) != -EINTR
|
||||
|| espos_mutex_unlock(global_mutex) != -EINTR) {
|
||||
msg = 1;
|
||||
}
|
||||
TEST_ASSERT(espos_queue_send(isr_queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS use mutex in ISR test", "[espos]")
|
||||
{
|
||||
uint8_t msg;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&isr_queue, 1, 1) == 0);
|
||||
TEST_ASSERT(espos_mutex_create(&global_mutex, ESPOS_MUTEX_NORMAL) == 0);
|
||||
|
||||
espos_test_run_in_isr(mutex_isr_test);
|
||||
TEST_ASSERT(espos_queue_recv(isr_queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(msg == 0);
|
||||
TEST_ASSERT(espos_mutex_del(global_mutex) == 0);
|
||||
TEST_ASSERT(espos_queue_del(isr_queue) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS mutex API invalid parameter test", "[espos]")
|
||||
{
|
||||
espos_queue_t mutex;
|
||||
|
||||
TEST_ASSERT(espos_mutex_create(NULL, ESPOS_MUTEX_NORMAL) == -EINVAL);
|
||||
TEST_ASSERT(espos_mutex_create(&mutex, ESPOS_MUTEX_CREATE_INVALID) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_mutex_lock(ESPOS_MUTEX_INVALID_HANDLE, 0) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_mutex_unlock(ESPOS_MUTEX_INVALID_HANDLE) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_mutex_del(ESPOS_MUTEX_INVALID_HANDLE) == -EINVAL);
|
||||
}
|
||||
58
Living_SDK/kernel/vcall/espos/test/test_espos_performance.c
Normal file
58
Living_SDK/kernel/vcall/espos/test/test_espos_performance.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_include.h"
|
||||
|
||||
uint32_t tick;
|
||||
|
||||
|
||||
// memory management
|
||||
TEST_CASE("ESPOS malloc free performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// scheduler
|
||||
TEST_CASE("ESPOS task context switch performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS isr context switch performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS critical section performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// spin lock
|
||||
TEST_CASE("ESPOS spin lock performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// queue
|
||||
TEST_CASE("ESPOS queue send recv performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// semaphore
|
||||
TEST_CASE("ESPOS semaphore performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// timer
|
||||
TEST_CASE("ESPOS timer accuracy performance", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
248
Living_SDK/kernel/vcall/espos/test/test_espos_queue.c
Normal file
248
Living_SDK/kernel/vcall/espos/test/test_espos_queue.c
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_queue.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_semaphore.h"
|
||||
#include "espos_time.h"
|
||||
#include "test_espos_run_in_isr.h"
|
||||
|
||||
#define ESPOS_QUEUE_INVALID_OPT (ESPOS_QUEUE_SEND_OPT_NORMAL+10)
|
||||
#define ESPOS_QUEUE_INVALID_POS (ESPOS_QUEUE_SEND_BACK+10)
|
||||
#define ESPOS_QUEUE_INVALID_HANDLE 0
|
||||
|
||||
static espos_sem_t sync_semaphore;
|
||||
static espos_queue_t global_queue;
|
||||
static espos_queue_t isr_queue;
|
||||
|
||||
TEST_CASE("ESPOS queue create delete", "[espos]")
|
||||
{
|
||||
uint32_t i;
|
||||
espos_queue_t queue = ESPOS_QUEUE_INVALID_HANDLE;
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
if (espos_queue_create(&queue, 16, 50) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (espos_queue_del(queue) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void queue_send_task(void *p)
|
||||
{
|
||||
uint32_t msg = 0xF1F2F3F4;
|
||||
uint8_t *received = (uint8_t *) p;
|
||||
|
||||
TEST_ASSERT(espos_queue_send(global_queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
// should switch to recv task and then switch back
|
||||
TEST_ASSERT(*received == 1);
|
||||
|
||||
TEST_ASSERT(espos_sem_give(sync_semaphore) == 0);
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
static void queue_recv_task(void *p)
|
||||
{
|
||||
uint32_t msg;
|
||||
uint8_t *received = (uint8_t *) p;
|
||||
|
||||
TEST_ASSERT(espos_queue_recv(global_queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
// check msg value
|
||||
TEST_ASSERT(msg = 0xF1F2F3F4);
|
||||
|
||||
// set received flag
|
||||
*received = 1;
|
||||
TEST_ASSERT(espos_sem_give(sync_semaphore) == 0);
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS queue send receive", "[espos]")
|
||||
{
|
||||
espos_task_t new_task_handle;
|
||||
uint8_t received = 0;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&global_queue, 4, 10) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_semaphore, 2, 0) == 0);
|
||||
|
||||
// recv task with higher priority, create recv task first
|
||||
TEST_ASSERT(espos_task_create_on_cpu(&new_task_handle, "queue_recv_task", &received, 2,
|
||||
0, 1024, queue_recv_task, 0, 0) == 0);
|
||||
TEST_ASSERT(espos_task_create_on_cpu(&new_task_handle, "queue_send_task", &received, 1,
|
||||
0, 1024, queue_send_task, 0, 0) == 0);
|
||||
|
||||
// wait task exit
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_del(sync_semaphore) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(global_queue) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS queue flush", "[espos]")
|
||||
{
|
||||
uint32_t msg = 0;
|
||||
espos_queue_t queue = ESPOS_QUEUE_INVALID_HANDLE;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&queue, 4, 10) == 0);
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, ESPOS_MAX_DELAY,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == 0);
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, ESPOS_MAX_DELAY,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_flush(queue) == 0);
|
||||
TEST_ASSERT(espos_queue_msg_waiting(queue) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_flush(queue) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(queue) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS queue send front/end", "[espos]")
|
||||
{
|
||||
uint32_t msg;
|
||||
espos_queue_t queue = ESPOS_QUEUE_INVALID_HANDLE;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&queue, 4, 10) == 0);
|
||||
msg = 0x01;
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, ESPOS_MAX_DELAY,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == 0);
|
||||
msg = 0x02;
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, ESPOS_MAX_DELAY,
|
||||
ESPOS_QUEUE_SEND_FRONT, ESPOS_QUEUE_SEND_OPT_NORMAL) == 0);
|
||||
msg = 0x03;
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, ESPOS_MAX_DELAY,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_recv(queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(msg == 0x02);
|
||||
|
||||
TEST_ASSERT(espos_queue_recv(queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(msg == 0x01);
|
||||
|
||||
TEST_ASSERT(espos_queue_recv(queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(msg == 0x03);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(queue) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS queue timeout test", "[espos]")
|
||||
{
|
||||
uint32_t msg;
|
||||
espos_queue_t queue = ESPOS_QUEUE_INVALID_HANDLE;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&queue, 4, 1) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, 0,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, 0,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == -ETIMEDOUT);
|
||||
|
||||
TEST_ASSERT(espos_queue_recv(queue, &msg, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_recv(queue, &msg, 0) == -ETIMEDOUT);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(queue) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS queue create/delete API invalid param test", "[espos]")
|
||||
{
|
||||
espos_queue_t queue = ESPOS_QUEUE_INVALID_HANDLE;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&queue, 0xFFFF, 0xFFFFFF) == -ENOMEM);
|
||||
TEST_ASSERT(espos_queue_del(queue) == -EINVAL);
|
||||
TEST_ASSERT(espos_queue_create(NULL, 4, 10) == -EINVAL);
|
||||
TEST_ASSERT(espos_queue_create(&queue, 0, 10) == -EINVAL);
|
||||
TEST_ASSERT(espos_queue_create(&queue, 4, 0) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(ESPOS_QUEUE_INVALID_HANDLE) == -EINVAL)
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS queue send API invalid param test", "[espos]")
|
||||
{
|
||||
uint32_t msg;
|
||||
espos_queue_t queue = ESPOS_QUEUE_INVALID_HANDLE;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&queue, 4, 10) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, NULL, 0,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == -EINVAL);
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, 0,
|
||||
ESPOS_QUEUE_INVALID_POS, ESPOS_QUEUE_SEND_OPT_NORMAL) == -EINVAL);
|
||||
TEST_ASSERT(espos_queue_send_generic(queue, &msg, 0,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_INVALID_OPT) == -EINVAL);
|
||||
TEST_ASSERT(espos_queue_send_generic(ESPOS_QUEUE_INVALID_HANDLE, &msg, 0,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_INVALID_OPT) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(queue) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS queue recv/wait/flush API invalid param test", "[espos]")
|
||||
{
|
||||
uint32_t msg;
|
||||
espos_queue_t queue = ESPOS_QUEUE_INVALID_HANDLE;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&queue, 4, 10) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_recv(ESPOS_QUEUE_INVALID_HANDLE, &msg, 0) == -EINVAL);
|
||||
TEST_ASSERT(espos_queue_recv(queue, NULL, 0) == -EINVAL);
|
||||
|
||||
//TODO: don't konw what could happen if passing invalid queue handle
|
||||
TEST_ASSERT(espos_queue_msg_waiting(ESPOS_QUEUE_INVALID_HANDLE) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_flush(ESPOS_QUEUE_INVALID_HANDLE) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(queue) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS deleting a queue in use test", "[espos]")
|
||||
{
|
||||
// TODO: this case is RTOS dependent
|
||||
espos_task_t new_task_handle;
|
||||
uint8_t received = 0;
|
||||
uint32_t msg = 0xF1F2F3F4;
|
||||
|
||||
TEST_ASSERT(espos_queue_create(&global_queue, 4, 1) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_semaphore, 1, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_task_create_on_cpu(&new_task_handle, "queue_recv_task", &received, 1,
|
||||
0, 1024, queue_recv_task, 0, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_send(global_queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
// wait task exit
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(received == 1);
|
||||
TEST_ASSERT(espos_sem_del(sync_semaphore) == 0);
|
||||
|
||||
TEST_ASSERT(espos_queue_del(global_queue) == 0);
|
||||
}
|
||||
|
||||
static void IRAM_ATTR queue_isr_test(void)
|
||||
{
|
||||
uint8_t msg = 0;
|
||||
TEST_ASSERT(espos_queue_send_generic(isr_queue, &msg, ESPOS_MAX_DELAY,
|
||||
ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS send to queue in ISR test", "[espos]")
|
||||
{
|
||||
uint8_t msg;
|
||||
espos_queue_create(&isr_queue, 1, 1);
|
||||
espos_test_run_in_isr(queue_isr_test);
|
||||
espos_queue_recv(isr_queue, &msg, ESPOS_MAX_DELAY);
|
||||
TEST_ASSERT(msg == 0);
|
||||
espos_queue_del(isr_queue);
|
||||
}
|
||||
62
Living_SDK/kernel/vcall/espos/test/test_espos_run_in_isr.c
Normal file
62
Living_SDK/kernel/vcall/espos/test/test_espos_run_in_isr.c
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "esp_types.h"
|
||||
#include "rom/ets_sys.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_scheduler.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
#include "driver/periph_ctrl.h"
|
||||
#include "driver/timer.h"
|
||||
|
||||
#include "test_espos_run_in_isr.h"
|
||||
|
||||
#define TIMER_INTR_SEL TIMER_INTR_LEVEL /*!< Timer level interrupt */
|
||||
#define TIMER_GROUP TIMER_GROUP_0 /*!< Test on timer group 0 */
|
||||
#define TIMER_DIVIDER 16 /*!< Hardware timer clock divider */
|
||||
|
||||
static void IRAM_ATTR timer_isr(void *p)
|
||||
{
|
||||
espos_test_isr_routine routine = (espos_test_isr_routine) p;
|
||||
|
||||
espos_isr_enter();
|
||||
|
||||
TIMERG0.int_clr_timers.t0 = 1;
|
||||
|
||||
routine();
|
||||
|
||||
espos_isr_exit();
|
||||
}
|
||||
|
||||
void espos_test_run_in_isr(espos_test_isr_routine routine)
|
||||
{
|
||||
|
||||
int timer_group = TIMER_GROUP_0;
|
||||
int timer_idx = TIMER_0;
|
||||
timer_config_t config;
|
||||
config.alarm_en = 1;
|
||||
config.auto_reload = 0;
|
||||
config.counter_dir = TIMER_COUNT_UP;
|
||||
config.divider = TIMER_DIVIDER;
|
||||
config.intr_type = TIMER_INTR_SEL;
|
||||
config.counter_en = TIMER_PAUSE;
|
||||
/*Configure timer*/
|
||||
timer_init(timer_group, timer_idx, &config);
|
||||
/*Stop timer counter*/
|
||||
timer_pause(timer_group, timer_idx);
|
||||
/*Load counter value */
|
||||
timer_set_counter_value(timer_group, timer_idx, 0x00000000ULL);
|
||||
/*Set alarm value*/
|
||||
timer_set_alarm_value(timer_group, timer_idx, 1);
|
||||
timer_set_auto_reload(timer_group, timer_idx, TIMER_AUTORELOAD_DIS);
|
||||
/*Enable timer interrupt*/
|
||||
timer_enable_intr(timer_group, timer_idx);
|
||||
/*Set ISR handler*/
|
||||
timer_isr_register(timer_group, timer_idx, timer_isr,
|
||||
(void *) routine, ESP_INTR_FLAG_IRAM, NULL);
|
||||
/*Start timer counter*/
|
||||
timer_start(timer_group, timer_idx);
|
||||
}
|
||||
27
Living_SDK/kernel/vcall/espos/test/test_espos_run_in_isr.h
Normal file
27
Living_SDK/kernel/vcall/espos/test/test_espos_run_in_isr.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _TEST_ESPOS_RUN_IN_ISR_H_
|
||||
#define _TEST_ESPOS_RUN_IN_ISR_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef void (*espos_test_isr_routine)(void);
|
||||
|
||||
/*
|
||||
* @brief run handler in timer isr
|
||||
*/
|
||||
void espos_test_run_in_isr(espos_test_isr_routine routine);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
52
Living_SDK/kernel/vcall/espos/test/test_espos_scheduler.c
Normal file
52
Living_SDK/kernel/vcall/espos/test/test_espos_scheduler.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_scheduler.h"
|
||||
#include "espos_spinlock.h"
|
||||
#include "test_espos_run_in_isr.h"
|
||||
|
||||
#define ESPOS_SCHEDULER_INVALID_HANDLE -1
|
||||
|
||||
uint32_t count;
|
||||
|
||||
TEST_CASE("ESPOS scheduler critical section test", "[espos]")
|
||||
{
|
||||
//TODO: how to test critical section?
|
||||
}
|
||||
|
||||
static void count_task(void *p)
|
||||
{
|
||||
count ++;
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS scheduler preempt suspend resume test", "[espos]")
|
||||
{
|
||||
espos_task_t new_task_handle;
|
||||
|
||||
count = 0;
|
||||
|
||||
TEST_ASSERT(espos_task_create_on_cpu(&new_task_handle, "count_task", NULL, 10,
|
||||
0, 1024, count_task, 0, 0) == 0);
|
||||
TEST_ASSERT(espos_task_create_on_cpu(&new_task_handle, "count_task", NULL, 10,
|
||||
0, 1024, count_task, 0, 0) == 0);
|
||||
|
||||
TEST_ASSERT(count == 2);
|
||||
|
||||
count = 0;
|
||||
|
||||
TEST_ASSERT(espos_preempt_suspend_local() == 0);
|
||||
|
||||
TEST_ASSERT(espos_task_create_on_cpu(&new_task_handle, "count_task", NULL, 10,
|
||||
0, 1024, count_task, 0, 0) == 0);
|
||||
TEST_ASSERT(espos_task_create_on_cpu(&new_task_handle, "count_task", NULL, 10,
|
||||
0, 1024, count_task, 0, 0) == 0);
|
||||
|
||||
TEST_ASSERT(count == 0);
|
||||
TEST_ASSERT(espos_preempt_resume_local() == 0);
|
||||
}
|
||||
174
Living_SDK/kernel/vcall/espos/test/test_espos_semaphore.c
Normal file
174
Living_SDK/kernel/vcall/espos/test/test_espos_semaphore.c
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_semaphore.h"
|
||||
#include "espos_queue.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_time.h"
|
||||
#include "driver/timer.h"
|
||||
#include "test_espos_run_in_isr.h"
|
||||
|
||||
#define ESPOS_SEM_INVALID_HANDLE 0
|
||||
|
||||
static espos_sem_t sync_semaphore;
|
||||
static espos_sem_t global_sema;
|
||||
static espos_queue_t isr_queue;
|
||||
|
||||
TEST_CASE("ESPOS semaphore create delete test", "[espos]")
|
||||
{
|
||||
uint32_t i;
|
||||
espos_sem_t sem;
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
if (espos_sem_create(&sem, 1, 1) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (espos_sem_del(sem) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void sema_give_task(void *p)
|
||||
{
|
||||
uint8_t *taken = (uint8_t *) p;
|
||||
|
||||
TEST_ASSERT(espos_sem_give(global_sema) == 0);
|
||||
|
||||
// should switch to recv task and then switch back
|
||||
TEST_ASSERT(*taken == 1);
|
||||
|
||||
espos_sem_give(sync_semaphore);
|
||||
espos_task_del(0);
|
||||
}
|
||||
|
||||
static void sema_take_task(void *p)
|
||||
{
|
||||
uint8_t *taken = (uint8_t *) p;
|
||||
|
||||
TEST_ASSERT(espos_sem_take(global_sema, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
// set taken flag
|
||||
*taken = 1;
|
||||
|
||||
espos_sem_give(sync_semaphore);
|
||||
espos_task_del(0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS semaphore take give test", "[espos]")
|
||||
{
|
||||
espos_task_t new_task_handle;
|
||||
uint8_t taken = 0;
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&global_sema, 1, 0) == 0);
|
||||
|
||||
espos_sem_create(&sync_semaphore, 2, 0);
|
||||
|
||||
// recv task with higher priority, create recv task first
|
||||
espos_task_create_on_cpu(&new_task_handle, "sema_take_task", &taken, 2,
|
||||
0, 1024, sema_take_task, 0, 0);
|
||||
espos_task_create_on_cpu(&new_task_handle, "sema_give_task", &taken, 1,
|
||||
0, 1024, sema_give_task, 0, 0);
|
||||
|
||||
// wait task exit
|
||||
espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY);
|
||||
espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY);
|
||||
espos_sem_del(sync_semaphore);
|
||||
|
||||
TEST_ASSERT(espos_sem_del(global_sema) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS semaphore count test", "[espos]")
|
||||
{
|
||||
uint8_t i;
|
||||
espos_sem_t sem;
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sem, 5, 1) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(sem, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_trytake(sem) == -ETIMEDOUT);
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
TEST_ASSERT(espos_sem_give(sem) == 0);
|
||||
}
|
||||
|
||||
TEST_ASSERT(espos_sem_give(sem) == -EAGAIN);
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
TEST_ASSERT(espos_sem_trytake(sem) == 0);
|
||||
}
|
||||
|
||||
TEST_ASSERT(espos_sem_del(sem) == 0);
|
||||
}
|
||||
|
||||
static void IRAM_ATTR semaphore_isr_test(void)
|
||||
{
|
||||
uint8_t msg = 0;
|
||||
espos_sem_t sem;
|
||||
|
||||
if (espos_sem_create(&sem, 2, 1) != -EINTR) {
|
||||
msg = 1;
|
||||
}
|
||||
|
||||
if (espos_sem_take(global_sema, 0) != 0
|
||||
|| espos_sem_give(global_sema) != 0
|
||||
|| espos_sem_del(global_sema) != -EINTR) {
|
||||
msg = 1;
|
||||
}
|
||||
espos_queue_send(isr_queue, &msg, ESPOS_MAX_DELAY);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS use semaphore in ISR test", "[espos]")
|
||||
{
|
||||
uint8_t msg;
|
||||
|
||||
espos_queue_create(&isr_queue, 1, 1);
|
||||
TEST_ASSERT(espos_sem_create(&global_sema, 2, 1) == 0);
|
||||
|
||||
espos_test_run_in_isr(semaphore_isr_test);
|
||||
espos_queue_recv(isr_queue, &msg, ESPOS_MAX_DELAY);
|
||||
TEST_ASSERT(msg == 0);
|
||||
espos_sem_del(global_sema);
|
||||
espos_queue_del(isr_queue);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS deleting a semaphore in use test", "[espos]")
|
||||
{
|
||||
// TODO: this case is RTOS dependent
|
||||
espos_task_t new_task_handle;
|
||||
uint8_t taken = 0;
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&global_sema, 1, 0) == 0);
|
||||
|
||||
espos_sem_create(&sync_semaphore, 1, 0);
|
||||
|
||||
espos_task_create_on_cpu(&new_task_handle, "sema_take_task", &taken, ESPOS_TASK_PRIO_MAX,
|
||||
0, 1024, sema_take_task, 0, 0);
|
||||
|
||||
espos_sem_give(global_sema);
|
||||
|
||||
// wait task exit
|
||||
espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY);
|
||||
TEST_ASSERT(taken == 1);
|
||||
espos_sem_del(sync_semaphore);
|
||||
|
||||
TEST_ASSERT(espos_sem_del(global_sema) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS semaphore API invalid parameter test", "[espos]")
|
||||
{
|
||||
TEST_ASSERT(espos_sem_create(NULL, 5, 1) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(ESPOS_SEM_INVALID_HANDLE, ESPOS_MAX_DELAY) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_sem_give(ESPOS_SEM_INVALID_HANDLE) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_sem_del(ESPOS_SEM_INVALID_HANDLE) == -EINVAL);
|
||||
}
|
||||
|
||||
119
Living_SDK/kernel/vcall/espos/test/test_espos_spinlock.c
Normal file
119
Living_SDK/kernel/vcall/espos/test/test_espos_spinlock.c
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_spinlock.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_queue.h"
|
||||
#include "espos_semaphore.h"
|
||||
#include "test_espos_run_in_isr.h"
|
||||
|
||||
#define ESPOS_SPINLOCK_INVALID_HANDLE NULL
|
||||
|
||||
#define ESPOS_SPINLOCK_ADD_TEST_COUNT 0xFFFF
|
||||
|
||||
static espos_sem_t sync_semaphore;
|
||||
static espos_queue_t isr_queue;
|
||||
static espos_spinlock_t global_spinlock;
|
||||
static int count;
|
||||
|
||||
TEST_CASE("ESPOS spinlock create delete test", "[espos]")
|
||||
{
|
||||
espos_spinlock_t spinlock;
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
if (espos_spinlock_create(&spinlock) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
}
|
||||
if (espos_spinlock_del(&spinlock) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void spinlock_test_task(void *p)
|
||||
{
|
||||
for (int i = 0; i < ESPOS_SPINLOCK_ADD_TEST_COUNT; i++) {
|
||||
TEST_ASSERT(espos_spinlock_lock(&global_spinlock) == 0);
|
||||
count++;
|
||||
TEST_ASSERT(espos_spinlock_unlock(&global_spinlock) == 0);
|
||||
}
|
||||
TEST_ASSERT(espos_sem_give(sync_semaphore) == 0);
|
||||
TEST_ASSERT(espos_task_del(0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS spinlock lock unlock test", "[espos]")
|
||||
{
|
||||
espos_task_t new_task_handle;
|
||||
|
||||
TEST_ASSERT(espos_spinlock_create(&global_spinlock) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_semaphore, 2, 0) == 0);
|
||||
count = 0;
|
||||
|
||||
TEST_ASSERT(espos_task_create(&new_task_handle, "spinlock_test_task1", NULL, 1,
|
||||
0, 1024, spinlock_test_task, 0) == 0);
|
||||
TEST_ASSERT(espos_task_create(&new_task_handle, "spinlock_test_task2", NULL, 1,
|
||||
0, 1024, spinlock_test_task, 0) == 0);
|
||||
|
||||
// wait task exit
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_take(sync_semaphore, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(espos_sem_del(sync_semaphore) == 0);
|
||||
|
||||
TEST_ASSERT(count == (ESPOS_SPINLOCK_ADD_TEST_COUNT << 1));
|
||||
TEST_ASSERT(espos_spinlock_del(&global_spinlock) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS spinlock trylock test", "[espos]")
|
||||
{
|
||||
espos_spinlock_t spinlock;
|
||||
|
||||
TEST_ASSERT(espos_spinlock_create(&spinlock) == 0);
|
||||
|
||||
TEST_ASSERT(espos_spinlock_trylock(&spinlock) == 0);
|
||||
TEST_ASSERT(espos_spinlock_trylock(&spinlock) == -EAGAIN);
|
||||
|
||||
TEST_ASSERT(espos_spinlock_unlock(&spinlock) == 0);
|
||||
|
||||
TEST_ASSERT(espos_spinlock_del(&spinlock) == 0);
|
||||
}
|
||||
|
||||
static void IRAM_ATTR spinlock_isr_test(void)
|
||||
{
|
||||
uint8_t msg = 0;
|
||||
|
||||
if (espos_spinlock_lock(&global_spinlock) != 0
|
||||
|| espos_spinlock_unlock(&global_spinlock) != 0) {
|
||||
msg = 1;
|
||||
}
|
||||
TEST_ASSERT(espos_queue_send(isr_queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS spinlock use in ISR test", "[espos]")
|
||||
{
|
||||
uint8_t msg;
|
||||
TEST_ASSERT(espos_queue_create(&isr_queue, 1, 1) == 0);
|
||||
TEST_ASSERT(espos_spinlock_create(&global_spinlock) == 0);
|
||||
espos_test_run_in_isr(spinlock_isr_test);
|
||||
TEST_ASSERT(espos_queue_recv(isr_queue, &msg, ESPOS_MAX_DELAY) == 0);
|
||||
TEST_ASSERT(msg == 0);
|
||||
TEST_ASSERT(espos_queue_del(isr_queue) == 0);
|
||||
TEST_ASSERT(espos_spinlock_del(&global_spinlock) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS spinlock API invalid parameter test", "[espos]")
|
||||
{
|
||||
TEST_ASSERT(espos_spinlock_create(NULL) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_spinlock_lock(NULL) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_spinlock_trylock(NULL) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_spinlock_unlock(NULL) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_spinlock_del(ESPOS_SPINLOCK_INVALID_HANDLE) == -EINVAL);
|
||||
}
|
||||
73
Living_SDK/kernel/vcall/espos/test/test_espos_task.c
Normal file
73
Living_SDK/kernel/vcall/espos/test/test_espos_task.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_task.h"
|
||||
|
||||
uint32_t count;
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task SMP create delete test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task multi-core test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task yield test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task exit test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task suspend resume test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task sleep test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task private data test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task priority test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task time slice test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task option test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task stack size test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ESPOS task API misc param test", "[espos]")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
30
Living_SDK/kernel/vcall/espos/test/test_espos_time.c
Normal file
30
Living_SDK/kernel/vcall/espos/test/test_espos_time.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_time.h"
|
||||
#include "espos_task.h"
|
||||
|
||||
#define _ESPOS_TIME_DELAY_TICK 100
|
||||
#define _ESPOS_TIME_DELAY_TICK_TH 120
|
||||
|
||||
TEST_CASE("ESPOS get tick test", "[espos]")
|
||||
{
|
||||
espos_tick_t tick1, tick2;
|
||||
tick1 = espos_get_tick_count();
|
||||
espos_task_delay(_ESPOS_TIME_DELAY_TICK);
|
||||
tick2 = espos_get_tick_count();
|
||||
|
||||
TEST_ASSERT(tick2 - tick1 >= _ESPOS_TIME_DELAY_TICK);
|
||||
TEST_ASSERT(tick2 - tick1 < _ESPOS_TIME_DELAY_TICK_TH);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS tick ms convert test", "[espos]")
|
||||
{
|
||||
TEST_ASSERT(espos_ticks_to_ms(espos_ms_to_ticks(10)) == 10);
|
||||
|
||||
TEST_ASSERT(espos_ms_to_ticks(0xFFFFFFFF) == 0xFFFFFFFF / 10);
|
||||
}
|
||||
162
Living_SDK/kernel/vcall/espos/test/test_espos_timer.c
Normal file
162
Living_SDK/kernel/vcall/espos/test/test_espos_timer.c
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "espos_timer.h"
|
||||
#include "espos_semaphore.h"
|
||||
|
||||
#define ESPOS_TIMER_INVALID_OPT 0xFF
|
||||
#define ESPOS_TIMER_INVALID_HANDLE 0
|
||||
#define ESPOS_TIMER_CHANGE_OPT_INVALID 5
|
||||
|
||||
static const char *TIMER_NAME = "timer_test";
|
||||
|
||||
static espos_sem_t sync_sema;
|
||||
static espos_timer_t global_timer;
|
||||
static int count;
|
||||
|
||||
static void espos_test_timer_dummy_cb(espos_timer_t timer, void *arg)
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS timer create delete test", "[espos]")
|
||||
{
|
||||
uint32_t i;
|
||||
espos_timer_t timer = ESPOS_TIMER_INVALID_HANDLE;
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
if (espos_timer_create(&timer, TIMER_NAME, espos_test_timer_dummy_cb, NULL,
|
||||
1, ESPOS_TIMER_NO_AUTO_RUN) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (espos_timer_del(timer) != 0) {
|
||||
TEST_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void espos_test_timer_cb(espos_timer_t timer, void *arg)
|
||||
{
|
||||
TEST_ASSERT(global_timer == timer);
|
||||
TEST_ASSERT(arg == NULL);
|
||||
count++;
|
||||
TEST_ASSERT(espos_sem_give(sync_sema) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS timer no auto run test", "[espos]")
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_sema, 1, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_timer_create(&global_timer, TIMER_NAME, espos_test_timer_cb, NULL,
|
||||
espos_ms_to_ticks(20), ESPOS_TIMER_NO_AUTO_RUN) == 0);
|
||||
|
||||
count = 0;
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
TEST_ASSERT(espos_timer_start(global_timer) == 0);
|
||||
TEST_ASSERT(espos_sem_take(sync_sema, ESPOS_MAX_DELAY) == 0);
|
||||
}
|
||||
|
||||
TEST_ASSERT(count == 100);
|
||||
TEST_ASSERT(espos_sem_del(sync_sema) == 0);
|
||||
TEST_ASSERT(espos_timer_del(global_timer) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS timer auto run test", "[espos]")
|
||||
{
|
||||
uint32_t i;
|
||||
espos_sem_create(&sync_sema, 1, 0);
|
||||
|
||||
TEST_ASSERT(espos_timer_create(&global_timer, TIMER_NAME, espos_test_timer_cb, NULL,
|
||||
espos_ms_to_ticks(20), ESPOS_TIMER_AUTO_RUN) == 0);
|
||||
|
||||
count = 0;
|
||||
TEST_ASSERT(espos_timer_start(global_timer) == 0);
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
espos_sem_take(sync_sema, ESPOS_MAX_DELAY);
|
||||
}
|
||||
|
||||
TEST_ASSERT(espos_timer_stop(global_timer) == 0);
|
||||
|
||||
TEST_ASSERT(count == 100);
|
||||
TEST_ASSERT(espos_sem_del(sync_sema) == 0);
|
||||
TEST_ASSERT(espos_timer_del(global_timer) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS timer auto run test", "[espos]")
|
||||
{
|
||||
espos_timer_t timer;
|
||||
|
||||
TEST_ASSERT(espos_sem_create(&sync_sema, 1, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_timer_create(&timer, TIMER_NAME, espos_test_timer_cb, NULL,
|
||||
20, ESPOS_TIMER_NO_AUTO_RUN) == 0);
|
||||
|
||||
TEST_ASSERT(espos_timer_start(timer) == 0);
|
||||
TEST_ASSERT(espos_timer_start(timer) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(sync_sema, 200) == 0);
|
||||
|
||||
TEST_ASSERT(espos_timer_stop(timer) == 0);
|
||||
TEST_ASSERT(espos_timer_stop(timer) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(sync_sema, 200) == -ETIMEDOUT);
|
||||
|
||||
TEST_ASSERT(espos_timer_del(timer) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS timer change test", "[espos]")
|
||||
{
|
||||
TEST_ASSERT(espos_sem_create(&sync_sema, 1, 0) == 0);
|
||||
|
||||
TEST_ASSERT(espos_timer_create(&global_timer, TIMER_NAME, espos_test_timer_cb, NULL,
|
||||
20, ESPOS_TIMER_AUTO_RUN) == 0);
|
||||
|
||||
count = 0;
|
||||
|
||||
TEST_ASSERT(espos_timer_start(global_timer) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(sync_sema, ESPOS_MAX_DELAY) == 0);
|
||||
|
||||
TEST_ASSERT(espos_sem_take(sync_sema, 200) == 0);
|
||||
TEST_ASSERT(espos_sem_take(sync_sema, 200) == 0);
|
||||
|
||||
TEST_ASSERT(espos_timer_stop(global_timer) == 0);
|
||||
|
||||
TEST_ASSERT(count == 3);
|
||||
TEST_ASSERT(espos_sem_del(sync_sema) == 0);
|
||||
TEST_ASSERT(espos_timer_del(global_timer) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPOS timer API param test", "[espos]")
|
||||
{
|
||||
espos_timer_t timer;
|
||||
TEST_ASSERT(espos_timer_create(&timer, NULL, NULL, espos_test_timer_cb,
|
||||
20, ESPOS_TIMER_NO_AUTO_RUN) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_timer_create(NULL, NULL, espos_test_timer_cb, NULL,
|
||||
20, ESPOS_TIMER_AUTO_RUN) == -EINVAL);
|
||||
TEST_ASSERT(espos_timer_create(&timer, NULL, NULL, NULL,
|
||||
20, ESPOS_TIMER_AUTO_RUN) == -EINVAL);
|
||||
TEST_ASSERT(espos_timer_create(&timer, NULL, NULL, espos_test_timer_cb,
|
||||
20, ESPOS_TIMER_INVALID_OPT) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_timer_start(ESPOS_TIMER_INVALID_HANDLE) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_timer_stop(ESPOS_TIMER_INVALID_HANDLE) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_timer_change(ESPOS_TIMER_INVALID_HANDLE,
|
||||
ESPOS_TIMER_CHANGE_ONCE, NULL) == -EINVAL);
|
||||
TEST_ASSERT(espos_timer_change(timer,
|
||||
ESPOS_TIMER_CHANGE_OPT_INVALID, NULL) == -EINVAL);
|
||||
|
||||
TEST_ASSERT(espos_timer_del(ESPOS_TIMER_INVALID_HANDLE) == -EINVAL);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue