mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2025-07-31 19:31:05 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
367
Living_SDK/test/testcase/3rdparty/experimental/ramfs_test/ramfs_test.c
vendored
Normal file
367
Living_SDK/test/testcase/3rdparty/experimental/ramfs_test/ramfs_test.c
vendored
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <aos/aos.h>
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <ramfs.h>
|
||||
|
||||
ramfs_file_t test_file[10];
|
||||
char writeBuf[10] = {1,2,3,4,5,6,7,8,9,10};
|
||||
char readBuf[10];
|
||||
char *file_name[10] = {"c/test_file0.txt", "c/test_file1.txt", "c/test_file2.txt", "c/test_file3.txt", "c/test_file4.txt",
|
||||
"c/test_file5.txt", "c/test_file6.txt", "c/test_file7.txt", "c/test_file8.txt", "c/test_file9.txt"};
|
||||
|
||||
ramfs_dir_t test_ramfs_dir;
|
||||
char file_name_dir[32];
|
||||
|
||||
static int test_ramfs_case1(void)
|
||||
{
|
||||
int ret = -1;
|
||||
uint32_t bytes_write = 0;
|
||||
uint32_t bytes_read = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
ramfs_init();
|
||||
|
||||
/******************** test access open write read close file multi imes ********************/
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_access(file_name[i], F_OK);
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = ramfs_open(&test_file[i], file_name[i], RAMFS_MODE_WR|RAMFS_MODE_RD);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[i], F_OK);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[i], R_OK);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[i], W_OK);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
writeBuf[j] += i;
|
||||
}
|
||||
|
||||
ret = ramfs_write(&test_file[i], writeBuf, 10, &bytes_write);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
ret = ramfs_close(&test_file[i]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
ret = ramfs_open(&test_file[i], file_name[i], RAMFS_MODE_WR|RAMFS_MODE_RD);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
ret = ramfs_read(&test_file[i], readBuf, 10, &bytes_read);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
if(readBuf[j] != writeBuf[j])
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
ret = ramfs_close(&test_file[i]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 11;
|
||||
}
|
||||
|
||||
ret = ramfs_remove(file_name[i]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[i], F_OK);
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
return 13;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** test access open write read close multi files ********************/
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
writeBuf[j] = j;
|
||||
}
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_open(&test_file[i], file_name[i], RAMFS_MODE_WR|RAMFS_MODE_RD);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 14;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_write(&test_file[i], writeBuf, 10, &bytes_write);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
writeBuf[j] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_close(&test_file[i]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
}
|
||||
|
||||
ret = ramfs_dir_open(&test_ramfs_dir, "c/");
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 17;
|
||||
}
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_dir_read(&test_ramfs_dir, file_name_dir);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 18;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = strcmp(file_name_dir, file_name[9-i]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 19;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_open(&test_file[i], file_name[i], RAMFS_MODE_WR|RAMFS_MODE_RD);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
writeBuf[j] = j;
|
||||
}
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_read(&test_file[i], readBuf, 10, &bytes_read);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 21;
|
||||
}
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
if(readBuf[j] != (writeBuf[j] + i))
|
||||
{
|
||||
return 22;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
ret = ramfs_close(&test_file[i]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 23;
|
||||
}
|
||||
}
|
||||
/******************** test read access ********************/
|
||||
|
||||
ret = ramfs_open(&test_file[0], file_name[0], RAMFS_MODE_RD);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 24;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[0], R_OK);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[0], W_OK);
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
return 26;
|
||||
}
|
||||
|
||||
ret = ramfs_write(&test_file[0], writeBuf, 10, &bytes_write);
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
return 27;
|
||||
}
|
||||
|
||||
ret = ramfs_close(&test_file[0]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 28;
|
||||
}
|
||||
|
||||
/******************** test write access ********************/
|
||||
ret = ramfs_open(&test_file[0], file_name[0], RAMFS_MODE_WR);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 29;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[0], R_OK);
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
ret = ramfs_access(file_name[0], W_OK);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 31;
|
||||
}
|
||||
|
||||
ret = ramfs_read(&test_file[0], readBuf, 10, &bytes_read);
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
ret = ramfs_close(&test_file[0]);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return 33;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_ramfs_case(void)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
ret = test_ramfs_case1();
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("test ramfs failed, error munber is %d\n",ret);
|
||||
}
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_ramfs_testcases[] = {
|
||||
{ "ramfs", test_ramfs_case},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "ramfs", init, cleanup, setup, teardown, aos_ramfs_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_ramfs(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_ramfs);
|
||||
|
||||
8
Living_SDK/test/testcase/3rdparty/experimental/ramfs_test/ramfs_test.mk
vendored
Normal file
8
Living_SDK/test/testcase/3rdparty/experimental/ramfs_test/ramfs_test.mk
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := ramfs_test
|
||||
|
||||
$(NAME)_COMPONENTS += 3rdparty.experimental.ramfs
|
||||
|
||||
$(NAME)_SOURCES += ramfs_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
150
Living_SDK/test/testcase/3rdparty/experimental/spiffs_test/spiffs_test.c
vendored
Normal file
150
Living_SDK/test/testcase/3rdparty/experimental/spiffs_test/spiffs_test.c
vendored
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <aos/aos.h>
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <aos_spiffs.h>
|
||||
|
||||
static const char *g_string = "spiffs test string.";
|
||||
static const char *g_filepath = "/spiffs/test.txt";
|
||||
static const char *g_dirpath = "/spiffs/testDir";
|
||||
static const char *g_dirtest_1 = "/spiffs/testDir/test_1.txt";
|
||||
static const char *g_dirtest_2 = "/spiffs/testDir/test_2.txt";
|
||||
static const char *g_dirtest_3 = "/spiffs/testDir/test_3.txt";
|
||||
static const char *g_new_filepath = "/spiffs/testDir/newname.txt";
|
||||
|
||||
static void test_spiffs_case(void)
|
||||
{
|
||||
int ret, fd;
|
||||
char readBuffer[32];
|
||||
aos_dir_t *dp;
|
||||
|
||||
/* spiffs write test */
|
||||
fd = aos_open(g_filepath, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
|
||||
if (fd > 0) {
|
||||
ret = aos_write(fd, g_string, strlen(g_string));
|
||||
YUNIT_ASSERT(ret > 0);
|
||||
ret = aos_sync(fd);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
aos_close(fd);
|
||||
}
|
||||
|
||||
/* spiffs read test */
|
||||
fd = aos_open(g_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0) {
|
||||
ret = aos_read(fd, readBuffer, sizeof(readBuffer));
|
||||
YUNIT_ASSERT(ret > 0);
|
||||
|
||||
ret = memcmp(readBuffer, g_string, strlen(g_string));
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
aos_close(fd);
|
||||
}
|
||||
|
||||
/* spiffs readdir test */
|
||||
fd = aos_open(g_dirtest_1, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
fd = aos_open(g_dirtest_2, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
fd = aos_open(g_dirtest_3, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
dp = (aos_dir_t *)aos_opendir(g_dirpath);
|
||||
YUNIT_ASSERT(dp != NULL);
|
||||
|
||||
if (dp) {
|
||||
aos_dirent_t *out_dirent;
|
||||
while(1) {
|
||||
out_dirent = (aos_dirent_t *)aos_readdir(dp);
|
||||
if (out_dirent == NULL)
|
||||
break;
|
||||
|
||||
printf("file name is %s\n", out_dirent->d_name);
|
||||
}
|
||||
}
|
||||
aos_closedir(dp);
|
||||
|
||||
/* spiffs rename test */
|
||||
ret = aos_rename(g_filepath, g_new_filepath);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
fd = aos_open(g_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd < 0);
|
||||
if (fd >= 0)
|
||||
aos_close(fd);
|
||||
|
||||
fd = aos_open(g_new_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
/* spiffs unlink test */
|
||||
ret = aos_unlink(g_new_filepath);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
fd = aos_open(g_new_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd < 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = vfs_spiffs_register();
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
int ret = vfs_spiffs_unregister();
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_spiffs_testcases[] = {
|
||||
{ "spiffs_test", test_spiffs_case},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "spiffs", init, cleanup, setup, teardown, aos_spiffs_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_spiffs(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_spiffs);
|
||||
|
||||
8
Living_SDK/test/testcase/3rdparty/experimental/spiffs_test/spiffs_test.mk
vendored
Normal file
8
Living_SDK/test/testcase/3rdparty/experimental/spiffs_test/spiffs_test.mk
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := spiffs_test
|
||||
|
||||
$(NAME)_COMPONENTS += 3rdparty.experimental.spiffs
|
||||
|
||||
$(NAME)_SOURCES += spiffs_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
271
Living_SDK/test/testcase/aosapi/api_test/aos_event_test.c
Normal file
271
Living_SDK/test/testcase/aosapi/api_test/aos_event_test.c
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define EVENT_INIT_FLAG 0x0F0F0F0F
|
||||
#define EVENT_FLAG_1 0x00000001
|
||||
#define EVENT_FLAG_2 0x01000F01
|
||||
#define EVENT_FLAG_3 0x000000F0
|
||||
|
||||
static aos_event_t event;
|
||||
#ifdef MULTITASK_UNDER_SMP
|
||||
static aos_task_t task1;
|
||||
static aos_task_t task2;
|
||||
static aos_sem_t sem;
|
||||
#endif /* MULTITASK_UNDER_SMP */
|
||||
|
||||
static void CASE_aosapi_kernel_event_new_free()
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
/* create event */
|
||||
|
||||
ret = aos_event_new(&event, EVENT_INIT_FLAG);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* destory event */
|
||||
|
||||
aos_event_free(&event);
|
||||
YUNIT_ASSERT_MSG(event.hdl==NULL, "ret=%d", 0);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_event_op_and()
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
/* create event */
|
||||
|
||||
ret = aos_event_new(&event, EVENT_INIT_FLAG);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*the event now should has event flag value as EVENT_INIT_FLAG(0x0F0F0F0F) */
|
||||
|
||||
/* try to get flag EVENT_FLAG_1(0x00000001) with AND operation should success */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_1, RHINO_AND, &actl_flags,AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* try to get flag EVENT_FLAG_2(0x01000F01) with AND operation should success */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_2, RHINO_AND, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* try to get flag EVENT_FLAG_3(0x000000F0) with AND operation should fail */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_3, RHINO_AND, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret!=(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* destory event */
|
||||
|
||||
aos_event_free(&event);
|
||||
YUNIT_ASSERT_MSG(event.hdl==NULL, "ret=%d", 0);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_event_op_andclear()
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
/* create event */
|
||||
|
||||
ret = aos_event_new(&event, EVENT_INIT_FLAG);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*the event now should has event flag value as EVENT_INIT_FLAG(0x0F0F0F0F) */
|
||||
|
||||
/* try to get flag EVENT_FLAG_1(0x00000001) with AND_CLEAR operation should success */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_1, RHINO_AND_CLEAR, &actl_flags,AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* now the event should has flag 0x0F0F0F0E */
|
||||
|
||||
/*
|
||||
* try to get flag EVENT_FLAG_2(0x01000F01) with AND_CLEAR operation should fail,
|
||||
* because (0x0F0F0F0E & 0x01000F01) != 0x01000F01
|
||||
*/
|
||||
ret = aos_event_get(&event, EVENT_FLAG_2, RHINO_AND, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret!=(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* now the event should still has flag 0x0F0F0F0E */
|
||||
|
||||
/* try to get flag EVENT_FLAG_3(0x000000F0) with AND operation should fail */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_3, RHINO_AND, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret!=(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* destory event */
|
||||
|
||||
aos_event_free(&event);
|
||||
YUNIT_ASSERT_MSG(event.hdl==NULL, "ret=%d", 0);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_event_op_or()
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
/* create event */
|
||||
|
||||
ret = aos_event_new(&event, EVENT_INIT_FLAG);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*set event flag with OR operation */
|
||||
ret = aos_event_set(&event, EVENT_FLAG_1, RHINO_OR);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*the event now should has event flag value as EVENT_INIT_FLAG|EVENT_FLAG_1 = 0x0F0F0F0F */
|
||||
|
||||
/* try to get flag EVENT_FLAG_1(0x00000001) with OR operation should success */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_1, RHINO_OR, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* try to get flag EVENT_FLAG_2(0x01000F01) with OR operation should success */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_2, RHINO_OR, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* try to get flag EVENT_FLAG_3(0x000000F0) with OR operation should fail */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_3, RHINO_OR, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret!=(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* destory event */
|
||||
|
||||
aos_event_free(&event);
|
||||
YUNIT_ASSERT_MSG(event.hdl==NULL, "ret=%d", 0);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_event_op_orclear()
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
/* create event */
|
||||
|
||||
ret = aos_event_new(&event, EVENT_INIT_FLAG);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*the event now should has event flag value as EVENT_INIT_FLAG|EVENT_FLAG_1 = 0x0F0F0F0F */
|
||||
|
||||
/* try to get flag EVENT_FLAG_1(0x00000001) with OR_CLEAR operation should success */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_1, RHINO_OR_CLEAR, &actl_flags,AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* now the event should has flag 0x0F0F0F0E*/
|
||||
|
||||
/*
|
||||
* try to get flag EVENT_FLAG_2(0x01000F01) with OR_CLEAR operation should success,
|
||||
* because (0x0F0F0F0E & 0x01000F01) > 0
|
||||
*/
|
||||
ret = aos_event_get(&event, EVENT_FLAG_2, RHINO_OR_CLEAR, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* now the event should has flag 0x0E0F000E*/
|
||||
|
||||
/* try to get flag EVENT_FLAG_3(0x000000F0) with OR operation should fail */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_3, RHINO_OR, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret!=(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* destory event */
|
||||
|
||||
aos_event_free(&event);
|
||||
YUNIT_ASSERT_MSG(event.hdl==NULL, "ret=%d", 0);
|
||||
}
|
||||
|
||||
#ifdef MULTITASK_UNDER_SMP
|
||||
|
||||
static void event_test_task1_entry(void* arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
uint32_t actl_flags;
|
||||
|
||||
/* try to get flag EVENT_FLAG_3(0x000000F0) with OR operation should fail */
|
||||
ret = aos_event_get(&event, EVENT_FLAG_3, RHINO_OR, &actl_flags, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret!=(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*
|
||||
* try to get flag EVENT_FLAG_3(0x000000F0) with OR operation should wait here,
|
||||
* task2 will set the flags with 0x000000F0, and then task1 will continue
|
||||
*/
|
||||
ret = aos_event_get(&event, EVENT_FLAG_3, RHINO_OR, &actl_flags, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* give the samphore to let main task continue*/
|
||||
aos_sem_signal(&sem);
|
||||
|
||||
/* exit self */
|
||||
aos_task_exit(0);
|
||||
}
|
||||
|
||||
static void event_test_task2_entry(void* arg)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
/*set event flag(0x000000F0) with OR operation, this will un-block task1 */
|
||||
|
||||
ret = aos_event_set(&event, EVENT_FLAG_3, RHINO_OR);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* exit self */
|
||||
aos_task_exit(0);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_event_op_multask(void)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
/* create event */
|
||||
|
||||
ret = aos_event_new(&event, EVENT_INIT_FLAG);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*create a semphore which will be used for sync multi-task*/
|
||||
ret = aos_sem_new(&sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/*the event now should has event flag value as EVENT_INIT_FLAG = 0x0F0F0F0F */
|
||||
|
||||
/* create task1 */
|
||||
|
||||
ret = aos_task_new_ext(&task1, "event_test_task1", event_test_task1_entry,
|
||||
0, 4096, AOS_DEFAULT_APP_PRI);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* create task2, which has a lower pri then task1, this make sure task1 will run first */
|
||||
|
||||
ret = aos_task_new_ext(&task2, "event_test_task2", event_test_task2_entry,
|
||||
0, 4096, AOS_DEFAULT_APP_PRI+1);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* wait for task1 to give samphore */
|
||||
ret = aos_sem_wait(&sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==(RHINO_SUCCESS), "ret=%d", ret);
|
||||
|
||||
/* destory samphore */
|
||||
aos_sem_free(&sem);
|
||||
|
||||
/* destory event */
|
||||
|
||||
aos_event_free(&event);
|
||||
YUNIT_ASSERT_MSG(event.hdl==NULL, "ret=%d", 0);
|
||||
}
|
||||
|
||||
#endif /* MULTITASK_UNDER_SMP */
|
||||
|
||||
void aosapi_kernel_event_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.event.new_free", CASE_aosapi_kernel_event_new_free);
|
||||
yunit_add_test_case(suite, "kernel.event.op_and", CASE_aosapi_kernel_event_op_and);
|
||||
yunit_add_test_case(suite, "kernel.event.op_andclear", CASE_aosapi_kernel_event_op_andclear);
|
||||
yunit_add_test_case(suite, "kernel.event.op_or", CASE_aosapi_kernel_event_op_or);
|
||||
yunit_add_test_case(suite, "kernel.event.op_orclear", CASE_aosapi_kernel_event_op_orclear);
|
||||
#ifdef MULTITASK_UNDER_SMP
|
||||
yunit_add_test_case(suite, "kernel.event.op_multask", CASE_aosapi_kernel_event_op_multask);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
47
Living_SDK/test/testcase/aosapi/api_test/aos_mm_test.c
Normal file
47
Living_SDK/test/testcase/aosapi/api_test/aos_mm_test.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
|
||||
|
||||
static void CASE_aosapi_kernel_mm_param()
|
||||
{
|
||||
/* dumpsys_mm_info_func here */
|
||||
aos_malloc(0);
|
||||
|
||||
/* coredump here */
|
||||
#if 0
|
||||
aos_free(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_mm_allocfree()
|
||||
{
|
||||
const int COUNT = 1024;
|
||||
int *ptr = aos_malloc(sizeof(int)*COUNT);
|
||||
|
||||
memset(ptr, 0, COUNT);
|
||||
int i = 0;
|
||||
for(; i<COUNT; i++) {
|
||||
*(ptr+i) = i;
|
||||
}
|
||||
i = 0;
|
||||
for(; i<COUNT; i++) {
|
||||
YUNIT_ASSERT_MSG((int)*(ptr+i)==i, "*(ptr+i)=%d", i);
|
||||
}
|
||||
aos_free(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
|
||||
void aosapi_kernel_mm_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.mm.param", CASE_aosapi_kernel_mm_param);
|
||||
yunit_add_test_case(suite, "kernel.mm.allocfree", CASE_aosapi_kernel_mm_allocfree);
|
||||
}
|
||||
|
||||
237
Living_SDK/test/testcase/aosapi/api_test/aos_mutex_test.c
Normal file
237
Living_SDK/test/testcase/aosapi/api_test/aos_mutex_test.c
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
|
||||
|
||||
static aos_mutex_t g_mutex1;
|
||||
static aos_mutex_t g_mutex2;
|
||||
static aos_sem_t sync_sem;
|
||||
static const uint32_t LOOP_COUNT = 1000000;
|
||||
|
||||
#define TEST_TASK_STACK_SIZE (8192)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void CASE_aosapi_kernel_mutex_param()
|
||||
{
|
||||
#if 0
|
||||
int ret;
|
||||
aos_mutex_t mutex;
|
||||
// FIXME: null pointer:coredump
|
||||
ret = aos_mutex_new(NULL);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_NULL_PTR, "ret=%d", ret);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// FIXME: null pointer:coredump
|
||||
ret = aos_mutex_lock(NULL, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_NULL_PTR, "ret=%d", ret);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// FIXME: null pointer:coredump
|
||||
ret = aos_mutex_unlock(NULL);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_NULL_PTR, "ret=%d", ret);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
ret = aos_mutex_free(NULL);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_NULL_PTR, "ret=%d", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TASK_aosapi_kernel_mutex_lock1(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int *pflag = (int*)arg;
|
||||
for(int i=0; i<LOOP_COUNT; i++) {
|
||||
ret = aos_mutex_lock(&g_mutex1, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
(*pflag)++;
|
||||
|
||||
ret = aos_mutex_unlock(&g_mutex1);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
}
|
||||
aos_sem_signal(&sync_sem);
|
||||
aos_task_exit(0);
|
||||
}
|
||||
void TASK_aosapi_kernel_mutex_lock2(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int *pflag = (int*)arg;
|
||||
for(int i=0; i<LOOP_COUNT; i++) {
|
||||
ret = aos_mutex_lock(&g_mutex1, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
(*pflag)--;
|
||||
|
||||
ret= aos_mutex_unlock(&g_mutex1);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
}
|
||||
aos_sem_signal(&sync_sem);
|
||||
aos_task_exit(0);
|
||||
}
|
||||
static void CASE_aosapi_kernel_mutex_lock()
|
||||
{
|
||||
int ret = RHINO_SUCCESS;
|
||||
ret = aos_mutex_new(&g_mutex1);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
int flag = 0;
|
||||
ret = aos_task_new("TASK_aosapi_kernel_mutex_lock_wait1",
|
||||
TASK_aosapi_kernel_mutex_lock1, &flag, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_mutex_lock_wait2",
|
||||
TASK_aosapi_kernel_mutex_lock2, &flag, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_mutex_free(&g_mutex1);
|
||||
aos_sem_free(&sync_sem);
|
||||
|
||||
YUNIT_ASSERT_MSG(flag==0, "flag=%d", flag);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TASK_aosapi_kernel_mutex_deadlock1(void *arg)
|
||||
{
|
||||
int ret;
|
||||
ret = aos_mutex_lock(&g_mutex1, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_mutex_lock(&g_mutex2, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_mutex_unlock(&g_mutex1);
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
void TASK_aosapi_kernel_mutex_deadlock2(void *arg)
|
||||
{
|
||||
int ret;
|
||||
ret = aos_mutex_lock(&g_mutex2, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_mutex_lock(&g_mutex1, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_mutex_unlock(&g_mutex2);
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
static void CASE_aosapi_kernel_mutex_deadlock()
|
||||
{
|
||||
int ret = RHINO_SUCCESS;
|
||||
ret = aos_mutex_new(&g_mutex1);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_mutex_new(&g_mutex2);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_mutex_deadlock1",
|
||||
TASK_aosapi_kernel_mutex_deadlock1, NULL, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_mutex_deadlock2",
|
||||
TASK_aosapi_kernel_mutex_deadlock2, NULL, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_mutex_free(&g_mutex1);
|
||||
aos_sem_free(&sync_sem);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void CASE_aosapi_kernel_mutex_repeatlock()
|
||||
{
|
||||
int ret;
|
||||
ret = aos_mutex_new(&g_mutex1);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_mutex_lock(&g_mutex1,AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
// TODO: test fail
|
||||
ret = aos_mutex_lock(&g_mutex1,AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_mutex_free(&g_mutex1);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TASK_aosapi_kernel_mutex_lock_timeout(void *arg)
|
||||
{
|
||||
int ret;
|
||||
ret = aos_mutex_lock(&g_mutex1, 2000);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_mutex_lock(&g_mutex1, RHINO_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_sem_signal(&sync_sem);
|
||||
aos_task_exit(0);
|
||||
}
|
||||
static void CASE_aosapi_kernel_mutex_lock_timeout()
|
||||
{
|
||||
int ret;
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_mutex_new(&g_mutex1);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_mutex_lock(&g_mutex1, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_mutex_lock_timeout",
|
||||
TASK_aosapi_kernel_mutex_lock_timeout, NULL, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem,AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_sem_free(&sync_sem);
|
||||
aos_mutex_free(&g_mutex1);
|
||||
}
|
||||
|
||||
|
||||
void aosapi_kernel_mutex_test_entry(yunit_test_suite_t* suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.mutex.param", CASE_aosapi_kernel_mutex_param);
|
||||
// yunit_add_test_case(suite, "kernel.mutex.lockwait", CASE_aosapi_kernel_mutex_lock);
|
||||
// yunit_add_test_case(suite, "kernel.mutex.locktimeout", CASE_aosapi_kernel_mutex_lock_timeout);
|
||||
yunit_add_test_case(suite, "kernel.mutex.repeat", CASE_aosapi_kernel_mutex_repeatlock);
|
||||
// yunit_add_test_case(suite, "kernel.mutex.deadlock", CASE_aosapi_kernel_mutex_deadlock);
|
||||
|
||||
(void)CASE_aosapi_kernel_mutex_deadlock;
|
||||
(void)CASE_aosapi_kernel_mutex_lock;
|
||||
(void)CASE_aosapi_kernel_mutex_lock_timeout;
|
||||
(void)CASE_aosapi_kernel_mutex_deadlock;
|
||||
|
||||
}
|
||||
|
||||
|
||||
203
Living_SDK/test/testcase/aosapi/api_test/aos_queue_test.c
Normal file
203
Living_SDK/test/testcase/aosapi/api_test/aos_queue_test.c
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <aos/kernel.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define TEST_TASK_STACK_SIZE (8192)
|
||||
|
||||
typedef struct{
|
||||
int id;
|
||||
int len;
|
||||
char msg[32];
|
||||
}Message;
|
||||
#define TEST_QUEUE_MAX_MSG_SIZE (sizeof(Message))
|
||||
#define TEST_QUEUE_MAX_MSG_COUNT (8)
|
||||
#define TEST_QUEUE_SIZE (TEST_QUEUE_MAX_MSG_SIZE * TEST_QUEUE_MAX_MSG_COUNT)
|
||||
|
||||
static char queue_buf[TEST_QUEUE_SIZE] = {0};
|
||||
static aos_queue_t g_queue;
|
||||
static aos_sem_t sync_sem;
|
||||
static Message send_msg;
|
||||
static Message recv_msg;
|
||||
static unsigned int recv_size = 0;
|
||||
static aos_sem_t tmp_sem;
|
||||
static aos_queue_t queue;
|
||||
|
||||
static void CASE_aosapi_kernel_queue_param()
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* aos_queue_new invalid param test */
|
||||
#if 0
|
||||
// TODO: coredump
|
||||
ret = aos_queue_new(NULL, queue_buf, TEST_QUEUE_SIZE, TEST_QUEUE_MAX_MSG_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_NULL_PTR, "ret=%d", ret);
|
||||
#endif
|
||||
ret = aos_queue_new(&queue, NULL, TEST_QUEUE_SIZE, TEST_QUEUE_MAX_MSG_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
ret = aos_queue_new(&queue, queue_buf, 0, TEST_QUEUE_MAX_MSG_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
ret = aos_queue_new(&queue, queue_buf, TEST_QUEUE_SIZE, 0);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
/* aos_queue_send invalid param test */
|
||||
#if 0
|
||||
// TODO: coredump
|
||||
ret = aos_queue_send(NULL, &send_msg, sizeof(send_msg));
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_NULL_PTR, "ret=%d", ret);
|
||||
#endif
|
||||
|
||||
// create fail
|
||||
ret = aos_queue_new(&queue, queue_buf, TEST_QUEUE_SIZE, TEST_QUEUE_MAX_MSG_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_queue_send(&queue, NULL, sizeof(send_msg));
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
ret = aos_queue_send(&queue, &send_msg, 0);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
ret = aos_queue_send(&queue, &send_msg, TEST_QUEUE_MAX_MSG_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_new(&tmp_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
ret = aos_queue_send((aos_queue_t*)&tmp_sem, &send_msg, sizeof(send_msg));
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
aos_sem_free(&tmp_sem);
|
||||
|
||||
/* aos_queue_recv invalid param test */
|
||||
#if 0
|
||||
// TODO: coredump
|
||||
ret = aos_queue_recv(NULL, 10, &recv_msg, &recv_size);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
ret = aos_queue_recv(&queue, 0, &recv_msg, &recv_size);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret= aos_queue_recv(&queue, AOS_WAIT_FOREVER, NULL, &recv_size);
|
||||
YUNIT_ASSERT_MSG(ret==(-EFAULT), "ret=%d", ret);
|
||||
|
||||
ret= aos_queue_recv(&queue, AOS_WAIT_FOREVER, &recv_msg, NULL);
|
||||
YUNIT_ASSERT_MSG(ret==(-EFAULT), "ret=%d", ret);
|
||||
|
||||
aos_sem_new(&tmp_sem, 0);
|
||||
ret = aos_queue_recv((aos_queue_t*)&tmp_sem, AOS_WAIT_FOREVER, &recv_msg, &recv_size);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
aos_sem_free(&tmp_sem);
|
||||
aos_queue_free(&queue);
|
||||
|
||||
/* aos_queue_free invalid param test */
|
||||
#if 0
|
||||
aos_queue_free(NULL);
|
||||
#endif
|
||||
#if 0
|
||||
aos_sem_new(&tmp_sem, 0);
|
||||
aos_queue_free((aos_queue_t*)&tmp_sem);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_KOBJ_TYPE_ERR, "ret=%d", ret);
|
||||
// aos_sem_free(&tmp_sem); // already free
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void TASK_aosapi_kernel_queue_recv(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int i = 1;
|
||||
for(; i<10; i++) {
|
||||
memset(&recv_msg, 0, sizeof(recv_msg));
|
||||
ret = aos_queue_recv(&g_queue, 500, &recv_msg, &recv_size);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
YUNIT_ASSERT_MSG(recv_size==TEST_QUEUE_MAX_MSG_SIZE, "recv_size=%d", recv_size);
|
||||
YUNIT_ASSERT_MSG(recv_msg.id==i, "recv_msg.id=%d", i);
|
||||
YUNIT_ASSERT_MSG(recv_msg.len==5, "recv_msg.leb=5");
|
||||
YUNIT_ASSERT_MSG(strcmp(recv_msg.msg, "hello")==0, "recv_msg.msg=%s", "hello");
|
||||
|
||||
}
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
static void TASK_aosapi_kernel_queue_send(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int i = 1;
|
||||
for(; i<10; i++) {
|
||||
memset(&send_msg, 0, sizeof(send_msg));
|
||||
send_msg.id = i;
|
||||
send_msg.len= 5;
|
||||
strcpy(send_msg.msg,"hello");
|
||||
ret = aos_queue_send(&g_queue, &send_msg, sizeof(send_msg));
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
aos_msleep(50);
|
||||
}
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
static void CASE_aosapi_kernel_queue_send_recv()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
// TODO: nullptr coredump
|
||||
ret = aos_queue_new(&g_queue, queue_buf, TEST_QUEUE_SIZE, TEST_QUEUE_MAX_MSG_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
assert(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_queue_send_testcase",
|
||||
TASK_aosapi_kernel_queue_send, NULL, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
ret = aos_task_new("TASK_aosapi_kernel_queue_recv_testcase",
|
||||
TASK_aosapi_kernel_queue_recv, NULL, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
assert(ret == RHINO_SUCCESS);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_sem_free(&sync_sem);
|
||||
aos_queue_free(&g_queue);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_queue_full()
|
||||
{
|
||||
int ret;
|
||||
// create fail
|
||||
ret = aos_queue_new(&g_queue, queue_buf, TEST_QUEUE_SIZE, TEST_QUEUE_MAX_MSG_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
for(int i=0; i<TEST_QUEUE_MAX_MSG_COUNT-1; i++) {
|
||||
ret = aos_queue_send(&g_queue, &send_msg, sizeof(send_msg));
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
}
|
||||
ret = aos_queue_send(&g_queue, &send_msg, sizeof(send_msg));
|
||||
YUNIT_ASSERT_MSG(ret==(-EPERM), "ret=%d", ret);
|
||||
|
||||
aos_queue_free(&g_queue);
|
||||
}
|
||||
|
||||
|
||||
void aosapi_kernel_queue_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.queue.param", CASE_aosapi_kernel_queue_param);
|
||||
// yunit_add_test_case(suite, "kernel.queue.sendrecv", CASE_aosapi_kernel_queue_send_recv);
|
||||
yunit_add_test_case(suite, "kernel.queue.full", CASE_aosapi_kernel_queue_full);
|
||||
|
||||
(void)CASE_aosapi_kernel_queue_send_recv;
|
||||
}
|
||||
|
||||
|
||||
107
Living_SDK/test/testcase/aosapi/api_test/aos_sem_test.c
Normal file
107
Living_SDK/test/testcase/aosapi/api_test/aos_sem_test.c
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static aos_sem_t sem;
|
||||
|
||||
static void CASE_aosapi_kernel_sem_param()
|
||||
{
|
||||
int ret;
|
||||
aos_mutex_t mutex;
|
||||
|
||||
#if 0
|
||||
// TODO: nullptr coredump
|
||||
ret = aos_sem_new(NULL, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_NULL_PTR, "ret=%d", ret);
|
||||
#endif
|
||||
|
||||
// TODO: test fail
|
||||
ret = aos_sem_new(&sem, -1);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret==RHINO_SUCCESS) {
|
||||
aos_sem_free(&sem);
|
||||
}
|
||||
|
||||
ret = aos_sem_new(&sem, -2);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret==RHINO_SUCCESS) {
|
||||
aos_sem_free(&sem);
|
||||
}
|
||||
|
||||
ret = aos_sem_new(&sem, 0x7FFFFFFF);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret==RHINO_SUCCESS) {
|
||||
aos_sem_free(&sem);
|
||||
}
|
||||
|
||||
// TODO: test fail
|
||||
ret = aos_sem_new(&sem, 0xFFFFFFFF);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret==RHINO_SUCCESS) {
|
||||
aos_sem_free(&sem);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// TODO: nullptr param
|
||||
aos_sem_signal(NULL);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
aos_mutex_new(&mutex);
|
||||
aos_sem_signal((aos_sem_t*)&mutex);
|
||||
aos_mutex_free(&mutex);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// TODO: nullptr param
|
||||
ret = aos_sem_wait(NULL, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
#endif
|
||||
|
||||
aos_mutex_new(&mutex);
|
||||
ret = aos_sem_wait((aos_sem_t*)&mutex, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
aos_mutex_free(&mutex);
|
||||
|
||||
ret = aos_sem_new(&sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
ret = aos_sem_wait(&sem, AOS_NO_WAIT);
|
||||
YUNIT_ASSERT_MSG(ret==(-EPERM), "ret=%d", ret);
|
||||
aos_sem_free(&sem);
|
||||
|
||||
ret = aos_sem_new(&sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
ret = aos_sem_wait(&sem, 1000);
|
||||
YUNIT_ASSERT_MSG(ret==(-EPERM), "ret=%d", ret);
|
||||
aos_sem_free(&sem);
|
||||
|
||||
ret = aos_sem_new(&sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
ret = aos_sem_wait(&sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==(-EPERM), "ret=%d", ret);
|
||||
aos_sem_free(&sem);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_sem_normal()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void aosapi_kernel_sem_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.sem.param", CASE_aosapi_kernel_sem_param);
|
||||
yunit_add_test_case(suite, "kernel.sem.normal", CASE_aosapi_kernel_sem_normal);
|
||||
}
|
||||
|
||||
|
||||
29
Living_SDK/test/testcase/aosapi/api_test/aos_sys_test.c
Normal file
29
Living_SDK/test/testcase/aosapi/api_test/aos_sys_test.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
|
||||
static void CASE_aosapi_kernel_sys_version()
|
||||
{
|
||||
const char *version = aos_version_get();
|
||||
YUNIT_ASSERT(strcmp(version, SYSINFO_KERNEL_VERSION)==0);
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_sys_reboot()
|
||||
{
|
||||
YUNIT_ASSERT(1);
|
||||
}
|
||||
|
||||
|
||||
void aosapi_kernel_sys_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.sys.reboot", CASE_aosapi_kernel_sys_reboot);
|
||||
yunit_add_test_case(suite, "kernel.sys.version", CASE_aosapi_kernel_sys_version);
|
||||
}
|
||||
|
||||
209
Living_SDK/test/testcase/aosapi/api_test/aos_task_test.c
Executable file
209
Living_SDK/test/testcase/aosapi/api_test/aos_task_test.c
Executable file
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <errno.h>
|
||||
|
||||
static aos_sem_t sync_sem;
|
||||
#define TEST_TASK_STACK_SIZE (8192)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TASK_aosapi_kernel_task_new_param(void *arg)
|
||||
{
|
||||
aos_task_exit(0);
|
||||
}
|
||||
static void CASE_aosapi_kernel_task_new_param()
|
||||
{
|
||||
int ret = RHINO_SUCCESS;
|
||||
ret = aos_task_new(NULL, TASK_aosapi_kernel_task_new_param, NULL, 1024);
|
||||
YUNIT_ASSERT_MSG(ret==(-EFAULT), "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_task_new_param", NULL, NULL, 1024);
|
||||
YUNIT_ASSERT_MSG(ret==(-EFAULT), "ret=%d", ret);
|
||||
|
||||
#if 1
|
||||
ret = aos_task_new("TASK_aosapi_kernel_task_new_param",
|
||||
TASK_aosapi_kernel_task_new_param, NULL, 0);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TASK_aosapi_kernel_task_new_batch(void *arg)
|
||||
{
|
||||
aos_sem_signal(&sync_sem);
|
||||
aos_task_exit(0);
|
||||
}
|
||||
static void CASE_aosapi_kernel_task_new_batch()
|
||||
{
|
||||
int i = 0;
|
||||
int success_count = 0;
|
||||
int ret = RHINO_SUCCESS;
|
||||
const int TASK_COUNT = 10;
|
||||
for(i=0; i<TASK_COUNT; i++) {
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_task_new_batch",
|
||||
TASK_aosapi_kernel_task_new_batch, NULL, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret != RHINO_SUCCESS) {
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_sem_free(&sync_sem);
|
||||
success_count += (ret==RHINO_SUCCESS ? 1 : 0);
|
||||
printf("task %d\t", success_count);
|
||||
}
|
||||
YUNIT_ASSERT(success_count == TASK_COUNT);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TASK_aosapi_kernel_task_new_stack(void *arg)
|
||||
{
|
||||
int array[2048];
|
||||
memset(array, 0, sizeof(int)*2048);
|
||||
PRINT_TASK_INFO(krhino_cur_task_get());
|
||||
aos_task_exit(0);
|
||||
}
|
||||
static void CASE_aosapi_kernel_task_new_stack()
|
||||
{
|
||||
#if 0
|
||||
int ret = RHINO_SUCCESS;
|
||||
ret = aos_task_new("TASK_aosapi_kernel_task_new_stack",
|
||||
TASK_aosapi_kernel_task_new_stack, NULL, 256);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
aos_msleep(1000);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
ret = aos_task_new("TASK_aosapi_kernel_task_new_stack",
|
||||
TASK_aosapi_kernel_task_new_stack, NULL, 10);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
aos_msleep(1000);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
ret = aos_task_new("TASK_aosapi_kernel_task_new_stack",
|
||||
TASK_aosapi_kernel_task_new_stack, NULL, 20480000);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
aos_msleep(1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TASK_aosapi_kernel_task_getname(void *arg)
|
||||
{
|
||||
YUNIT_ASSERT(0==strcmp(aos_task_name(), "TASK_aosapi_kernel_task_getname"));
|
||||
aos_sem_signal(&sync_sem);
|
||||
aos_task_exit(0);
|
||||
}
|
||||
static void CASE_aosapi_kernel_task_getname()
|
||||
{
|
||||
int ret = RHINO_SUCCESS;
|
||||
ret= aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new("TASK_aosapi_kernel_task_getname",
|
||||
TASK_aosapi_kernel_task_getname, NULL, TEST_TASK_STACK_SIZE);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret != RHINO_SUCCESS) {
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_sem_free(&sync_sem);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#if 0
|
||||
void TASK_aosapi_kernel_task_new_priority(void *arg)
|
||||
{
|
||||
aos_sem_signal(&sync_sem);
|
||||
aos_task_exit(0);
|
||||
}
|
||||
static void CASE_aosapi_kernel_task_new_priority()
|
||||
{
|
||||
int ret = RHINO_SUCCESS;
|
||||
int success_count = 0;
|
||||
int i = 0;
|
||||
|
||||
#if 1
|
||||
/* */
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new_ext("TASK_aosapi_kernel_task_new_priority",
|
||||
TASK_aosapi_kernel_task_new_priority, NULL,
|
||||
TEST_TASK_STACK_SIZE, RHINO_CONFIG_PRI_MAX);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_BEYOND_MAX_PRI, "ret=%d", ret);
|
||||
if(ret == RHINO_BEYOND_MAX_PRI) {
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
ret = aos_sem_wait(&sync_sem, RHINO_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
aos_sem_free(&sync_sem);
|
||||
|
||||
/* */
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new_ext("TASK_aosapi_kernel_task_new_priority",
|
||||
TASK_aosapi_kernel_task_new_priority, NULL,
|
||||
TEST_TASK_STACK_SIZE, RHINO_CONFIG_USER_PRI_MAX);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret != RHINO_SUCCESS) {
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
ret = aos_sem_wait(&sync_sem, RHINO_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
aos_sem_free(&sync_sem);
|
||||
#endif
|
||||
|
||||
/* */
|
||||
#if 1
|
||||
int pris[] = {11,12,13};
|
||||
for(i=0; i<sizeof(pris)/sizeof(pris[0]); i++) {
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_task_new_ext("TASK_aosapi_kernel_task_new_priority",
|
||||
TASK_aosapi_kernel_task_new_priority, NULL,
|
||||
TEST_TASK_STACK_SIZE, pris[i]);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
if(ret != RHINO_SUCCESS) {
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
ret = aos_sem_wait(&sync_sem, RHINO_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
aos_sem_free(&sync_sem);
|
||||
success_count += (ret==RHINO_SUCCESS ? 1 : 0);
|
||||
printf("\ttask prio=%d\n", pris[i]);
|
||||
}
|
||||
YUNIT_ASSERT_MSG(success_count==sizeof(pris)/sizeof(pris[0]), "success_count=%d", success_count);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void aosapi_kernel_task_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.task.param", CASE_aosapi_kernel_task_new_param);
|
||||
yunit_add_test_case(suite, "kernel.task.stack", CASE_aosapi_kernel_task_new_stack);
|
||||
yunit_add_test_case(suite, "kernel.task.batchcreate", CASE_aosapi_kernel_task_new_batch);
|
||||
// yunit_add_test_case(suite, "kernel.task.priority", CASE_aosapi_kernel_task_new_priority);
|
||||
yunit_add_test_case(suite, "kernel.task.getname", CASE_aosapi_kernel_task_getname);
|
||||
}
|
||||
|
||||
107
Living_SDK/test/testcase/aosapi/api_test/aos_timer_test.c
Normal file
107
Living_SDK/test/testcase/aosapi/api_test/aos_timer_test.c
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <errno.h>
|
||||
|
||||
static aos_timer_t g_timer;
|
||||
static aos_sem_t sync_sem;
|
||||
static int timer_trigger_count = 0;
|
||||
|
||||
static void TIMER_aosapi_kernel_timer_param()
|
||||
{
|
||||
|
||||
}
|
||||
static void CASE_aosapi_kernel_timer_param()
|
||||
{
|
||||
int ret;
|
||||
#if 0
|
||||
ret = aos_timer_new(NULL, TIMER_aosapi_kernel_timer_param, NULL, 1000, 0);
|
||||
YUNIT_ASSERT(ret==RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
ret = aos_timer_new(&g_timer, NULL, NULL, 1000, 0);
|
||||
YUNIT_ASSERT(ret==(-EFAULT));
|
||||
|
||||
ret = aos_timer_new(&g_timer, TIMER_aosapi_kernel_timer_param, NULL, 0, 0);
|
||||
YUNIT_ASSERT(ret==(-EINVAL));
|
||||
|
||||
#if 0
|
||||
ret = aos_timer_start(NULL);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
ret = aos_timer_stop(NULL);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
aos_timer_free(NULL);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
ret = aos_timer_change(NULL, 0);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void TIMER_aosapi_kernel_timer_norepeat()
|
||||
{
|
||||
timer_trigger_count++;
|
||||
aos_timer_stop(&g_timer);
|
||||
}
|
||||
static void CASE_aosapi_kernel_timer_norepeat()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT(ret==RHINO_SUCCESS);
|
||||
|
||||
timer_trigger_count = 0;
|
||||
ret = aos_timer_new(&g_timer, TIMER_aosapi_kernel_timer_norepeat, NULL, 100, 0);
|
||||
YUNIT_ASSERT(ret==RHINO_SUCCESS);
|
||||
|
||||
aos_msleep(1000);
|
||||
YUNIT_ASSERT(timer_trigger_count==1);
|
||||
aos_timer_free(&g_timer);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void TIMER_aosapi_kernel_timer_repeat()
|
||||
{
|
||||
timer_trigger_count++;
|
||||
if(timer_trigger_count==10) {
|
||||
aos_timer_stop(&g_timer);
|
||||
}
|
||||
}
|
||||
static void CASE_aosapi_kernel_timer_repeat()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT(ret==RHINO_SUCCESS);
|
||||
|
||||
timer_trigger_count = 0;
|
||||
ret = aos_timer_new(&g_timer, TIMER_aosapi_kernel_timer_repeat, NULL, 100, 1);
|
||||
YUNIT_ASSERT(ret==RHINO_SUCCESS);
|
||||
aos_msleep(1500);
|
||||
YUNIT_ASSERT(timer_trigger_count==10);
|
||||
aos_timer_free(&g_timer);
|
||||
}
|
||||
|
||||
void aosapi_kernel_timer_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.timer.param", CASE_aosapi_kernel_timer_param);
|
||||
yunit_add_test_case(suite, "kernel.timer.norepeat", CASE_aosapi_kernel_timer_norepeat);
|
||||
yunit_add_test_case(suite, "kernel.timer.repeat", CASE_aosapi_kernel_timer_repeat);
|
||||
}
|
||||
|
||||
133
Living_SDK/test/testcase/aosapi/api_test/aos_workqueue_test.c
Executable file
133
Living_SDK/test/testcase/aosapi/api_test/aos_workqueue_test.c
Executable file
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <errno.h>
|
||||
|
||||
static aos_workqueue_t workqueue;
|
||||
static aos_work_t work;
|
||||
static aos_sem_t sync_sem;
|
||||
static void CASE_aosapi_kernel_workqueue_param()
|
||||
{
|
||||
int ret;
|
||||
#if 0
|
||||
// TODO: test fail(nullptr coredump)
|
||||
ret = aos_workqueue_create(NULL, 10, 1024);
|
||||
YUNIT_ASSERT(ret == RHINO_SUCCESS);
|
||||
#endif
|
||||
|
||||
ret = aos_workqueue_create(&workqueue, RHINO_CONFIG_PRI_MAX, 1024);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
ret = aos_workqueue_create(&workqueue, RHINO_CONFIG_PRI_MAX+1, 1024);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
// TODO: test fail(RHINO_TASK_INV_STACK_SIZE)
|
||||
ret = aos_workqueue_create(&workqueue, 10, 0);
|
||||
YUNIT_ASSERT_MSG(ret==(-EINVAL), "ret=%d", ret);
|
||||
|
||||
#if 0
|
||||
// TODO: test fail(nullptr coredump)
|
||||
aos_workqueue_del(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CASE_aosapi_kernel_workqueue_default()
|
||||
{
|
||||
// TODO: not implement
|
||||
// aos_work_cancle() and aos_work_sched()
|
||||
}
|
||||
|
||||
static void WORK_aosapi_kernel_workqueue_custom(void *arg)
|
||||
{
|
||||
int i = 4;
|
||||
while(i--) {
|
||||
aos_msleep(1000);
|
||||
printf("workqueue:%d\n", i);
|
||||
}
|
||||
aos_sem_signal(&sync_sem);
|
||||
}
|
||||
static void CASE_aosapi_kernel_workqueue_custom()
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = aos_sem_new(&sync_sem, 0);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_workqueue_create(&workqueue, 10, 1024);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_work_init(&work, WORK_aosapi_kernel_workqueue_custom, NULL, 100);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_work_run(&workqueue, &work);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
|
||||
ret = aos_sem_wait(&sync_sem, AOS_WAIT_FOREVER);
|
||||
YUNIT_ASSERT_MSG(ret==RHINO_SUCCESS, "ret=%d", ret);
|
||||
aos_sem_free(&sync_sem);
|
||||
aos_work_destroy(&work);
|
||||
}
|
||||
|
||||
static void WORK_aosapi_kernel_work_param(void* arg)
|
||||
{
|
||||
}
|
||||
static void CASE_aosapi_kernel_work_param()
|
||||
{
|
||||
int ret = 0;
|
||||
#if 0
|
||||
// TODO: nullptr coredump
|
||||
ret = aos_work_init(NULL,WORK_aosapi_kernel_work_param, NULL, 1000);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
ret = aos_work_init(&work, NULL, NULL, 1024);
|
||||
YUNIT_ASSERT(ret == (-EFAULT));
|
||||
|
||||
#if 0
|
||||
// TODO: nullptr coredump
|
||||
ret = aos_work_run(NULL, &work);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// TODO: nullptr coredump
|
||||
ret = aos_workqueue_create(&workqueue, 10, 1024);
|
||||
YUNIT_ASSERT(ret == RHINO_SUCCESS);
|
||||
aos_work_run(&workqueue, NULL);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
aos_workqueue_del(&workqueue);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// TODO: not implement
|
||||
ret = aos_work_cancel(NULL);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// TODO: not implement
|
||||
ret = aos_work_sched(NULL);
|
||||
YUNIT_ASSERT(ret == RHINO_NULL_PTR);
|
||||
#endif
|
||||
|
||||
(void)WORK_aosapi_kernel_work_param;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void aosapi_kernel_workqueue_test_entry(yunit_test_suite_t *suite)
|
||||
{
|
||||
yunit_add_test_case(suite, "kernel.workqueue.param", CASE_aosapi_kernel_workqueue_param);
|
||||
yunit_add_test_case(suite, "kernel.workqueue.default", CASE_aosapi_kernel_workqueue_default);
|
||||
yunit_add_test_case(suite, "kernel.workqueue.custom", CASE_aosapi_kernel_workqueue_custom);
|
||||
yunit_add_test_case(suite, "kernel.work.param", CASE_aosapi_kernel_work_param);
|
||||
}
|
||||
|
||||
17
Living_SDK/test/testcase/aosapi/api_test/api_test.mk
Normal file
17
Living_SDK/test/testcase/aosapi/api_test/api_test.mk
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
NAME := api_test
|
||||
|
||||
$(NAME)_COMPONENTS += rhino
|
||||
|
||||
$(NAME)_SOURCES += test_kernel.c
|
||||
$(NAME)_SOURCES += aos_sys_test.c
|
||||
$(NAME)_SOURCES += aos_task_test.c
|
||||
$(NAME)_SOURCES += aos_mm_test.c
|
||||
$(NAME)_SOURCES += aos_mutex_test.c
|
||||
$(NAME)_SOURCES += aos_queue_test.c
|
||||
$(NAME)_SOURCES += aos_sem_test.c
|
||||
$(NAME)_SOURCES += aos_timer_test.c
|
||||
$(NAME)_SOURCES += aos_workqueue_test.c
|
||||
$(NAME)_SOURCES += aos_event_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
50
Living_SDK/test/testcase/aosapi/api_test/test_kernel.c
Normal file
50
Living_SDK/test/testcase/aosapi/api_test/test_kernel.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <yunit.h>
|
||||
#include <aos/types.h>
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static void setup(void)
|
||||
{
|
||||
}
|
||||
static void teardown(void)
|
||||
{
|
||||
}
|
||||
|
||||
extern void aosapi_kernel_sys_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_task_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_mutex_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_timer_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_queue_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_workqueue_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_mm_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_sem_test_entry(yunit_test_suite_t *suite);
|
||||
extern void aosapi_kernel_event_test_entry(yunit_test_suite_t *suite);
|
||||
|
||||
void test_api(void)
|
||||
{
|
||||
yunit_test_suite_t *suite;
|
||||
suite = yunit_add_test_suite("aosapi", init, cleanup, setup, teardown);
|
||||
|
||||
/* kernel */
|
||||
aosapi_kernel_sys_test_entry(suite);
|
||||
aosapi_kernel_task_test_entry(suite);
|
||||
aosapi_kernel_mutex_test_entry(suite);
|
||||
aosapi_kernel_sem_test_entry(suite);
|
||||
aosapi_kernel_timer_test_entry(suite);
|
||||
|
||||
aosapi_kernel_queue_test_entry(suite);
|
||||
aosapi_kernel_mm_test_entry(suite);
|
||||
aosapi_kernel_workqueue_test_entry(suite);
|
||||
aosapi_kernel_event_test_entry(suite);
|
||||
}
|
||||
AOS_TESTCASE(test_api);
|
||||
20
Living_SDK/test/testcase/aosapi/api_test/ucube.py
Normal file
20
Living_SDK/test/testcase/aosapi/api_test/ucube.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
src = Split('''
|
||||
test_kernel.c
|
||||
aos_sys_test.c
|
||||
aos_task_test.c
|
||||
aos_mm_test.c
|
||||
aos_mutex_test.c
|
||||
aos_queue_test.c
|
||||
aos_sem_test.c
|
||||
aos_timer_test.c
|
||||
aos_workqueue_test.c
|
||||
aos_event_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('api_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/rhino')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
|
||||
1131
Living_SDK/test/testcase/basic_test/aos_test.c
Normal file
1131
Living_SDK/test/testcase/basic_test/aos_test.c
Normal file
File diff suppressed because it is too large
Load diff
8
Living_SDK/test/testcase/basic_test/basic_test.mk
Normal file
8
Living_SDK/test/testcase/basic_test/basic_test.mk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := basic_test
|
||||
|
||||
$(NAME)_SOURCES := aos_test.c cutest/cut.c
|
||||
$(NAME)_COMPONENTS := rhino
|
||||
$(NAME)_COMPONENTS += modules.fs.kv
|
||||
$(NAME)_COMPONENTS += yloop
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror -Wno-unused-varible
|
||||
140
Living_SDK/test/testcase/basic_test/cutest/cut.c
Normal file
140
Living_SDK/test/testcase/basic_test/cutest/cut.c
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "cut.h"
|
||||
|
||||
struct cut_runtime cut;
|
||||
|
||||
static void filter(int argc, char** argv)
|
||||
{
|
||||
int i = 0;
|
||||
struct cut_case *c = NULL;
|
||||
if(argc==2 && 0==strcmp(argv[1], "all"))
|
||||
return;
|
||||
|
||||
for (i = 0; i < cut.ccnt_total; i++) {
|
||||
c = cut.clist[i];
|
||||
if ((argc==2 && (NULL==strstr(c->sname, argv[1]))) ||
|
||||
(argc==3 && (NULL==strstr(c->sname, argv[1]) || NULL==strstr(c->cname, argv[2])))) {
|
||||
cut.clist[i]->skip = 1;
|
||||
cut.ccnt_skip++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void usage(const char* me)
|
||||
{
|
||||
cut_printf("Usage: %s [OPTION] [SUITE] [CASE]\r\n\r\n" \
|
||||
"OPTION:\r\n" \
|
||||
" --help : print this help\r\n" \
|
||||
" --list : list cases\r\n" \
|
||||
" --count : print case count\r\n" \
|
||||
" SUITE : suite name filter, e.g. '%s all' means run all suites\r\n" \
|
||||
" CASE : case name filter\r\n", me, me);
|
||||
}
|
||||
|
||||
static int parse_arg(int argc, char** argv)
|
||||
{
|
||||
if (argc >= 2) {
|
||||
if (0 == strcmp(argv[1], "--list")) {
|
||||
int i = 0;
|
||||
int cnt = 0;
|
||||
cut_printf("\33[1;34mCASE_LIST_BEGIN\33[0m\r\n");
|
||||
for(i=0; i<cut.ccnt_total; i++) {
|
||||
struct cut_case *c = cut.clist[i];
|
||||
if(argc==2 ||
|
||||
(argc==3 && 0==strcmp(argv[2], "all")) ||
|
||||
(argc==3 && NULL!=strstr(c->sname, argv[2])) ||
|
||||
(argc==4 && NULL!=strstr(c->sname, argv[2]) && NULL!=strstr(c->cname, argv[3])))
|
||||
cut_printf("\33[1;34m[%02d] %s.%s\33[0m\r\n", ++cnt, c->sname, c->cname);
|
||||
}
|
||||
cut_printf("\33[1;34mCASE_LIST_END\33[0m\r\n");
|
||||
return 0;
|
||||
}
|
||||
if (0 == strcmp(argv[1], "--count")) {
|
||||
cut_printf("total %d case(s).\r\n", cut.ccnt_total);
|
||||
return 0;
|
||||
}
|
||||
if (0 == strcmp(argv[1], "--help")) {
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void cut_result_report(struct cut_runtime *cut)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
/* print test result locally */
|
||||
cut_printf("===========================================================================\r\n");
|
||||
if (cut->ccnt_fail > 0) {
|
||||
cut_printf("FAIL LIST:\r\n");
|
||||
for (i = 0; i < cut->ccnt_fail; i++) {
|
||||
cut_printf(" [%02d] %s\r\n", i + 1, cut->cerrmsg[i]);
|
||||
cut_free(cut->cerrmsg[i]);
|
||||
}
|
||||
cut_printf("---------------------------------------------------------------------------\r\n");
|
||||
}
|
||||
cut_printf("SUMMARY:\r\n" \
|
||||
" TOTAL: %d\r\n" \
|
||||
" SKIPPED: %d\r\n" \
|
||||
" MATCHED: %d\r\n" \
|
||||
" PASS: %d\r\n", cut->ccnt_total, cut->ccnt_skip,
|
||||
cut->ccnt_total-cut->ccnt_skip, cut->ccnt_pass);
|
||||
|
||||
if (cut->ccnt_fail > 0)
|
||||
{
|
||||
cut_printf(" FAILED: %d\r\n", cut->ccnt_fail);
|
||||
}
|
||||
cut_printf("===========================================================================\r\n");
|
||||
}
|
||||
|
||||
|
||||
int cut_main(int argc, char** argv)
|
||||
{
|
||||
int i = 0, cnt = 0;
|
||||
char *_argv[2] = {"None", "--list"};
|
||||
|
||||
cut.ccnt_pass = 0;
|
||||
cut.ccnt_fail = 0;
|
||||
cut.ccnt_skip = 0;
|
||||
for(i=0; i<cut.ccnt_total; i++) {
|
||||
cut.clist[i]->skip = 0;
|
||||
cut.clist[i]->flag = 1;
|
||||
}
|
||||
|
||||
if (0 == parse_arg(argc, argv))
|
||||
return 0;
|
||||
|
||||
parse_arg(2, _argv);
|
||||
|
||||
filter(argc, argv);
|
||||
|
||||
for(i=0; i < cut.ccnt_total; i++) {
|
||||
cut.ccur = cut.clist[i];
|
||||
if (cut.ccur->skip)
|
||||
continue;
|
||||
|
||||
cut_printf("\33[1;33mTEST [%d/%d] %s.%s...\33[0m\r\n",
|
||||
++cnt, cut.ccnt_total-cut.ccnt_skip, cut.ccur->sname, cut.ccur->cname);
|
||||
if (cut.ccur->setup)
|
||||
cut.ccur->setup(cut.ccur->data);
|
||||
cut.ccur->run((struct cut_case *)(cut.ccur->data));
|
||||
if (cut.ccur->teardown)
|
||||
cut.ccur->teardown(cut.ccur->data);
|
||||
if (cut.ccur->flag) {
|
||||
cut_printf("\33[1;32m[OK]\33[0m\r\n\r\n");
|
||||
cut.ccnt_pass++;
|
||||
}
|
||||
else {
|
||||
cut_printf("\33[1;31m[FAIL]: %s\33[0m\r\n\r\n", cut.cerrmsg[cut.ccnt_fail]);
|
||||
cut.ccnt_fail++;
|
||||
}
|
||||
}
|
||||
cut_result_report(&cut);
|
||||
return cut.ccnt_fail;
|
||||
}
|
||||
|
||||
226
Living_SDK/test/testcase/basic_test/cutest/cut.h
Normal file
226
Living_SDK/test/testcase/basic_test/cutest/cut.h
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef __CUT_H__
|
||||
#define __CUT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#define cut_printf printf
|
||||
#define cut_snprintf snprintf
|
||||
#define cut_malloc malloc
|
||||
#define cut_free free
|
||||
|
||||
#define CUT_CASE_MAX_CNT (32)
|
||||
#define CUT_MSG_MAX_LEN (64)
|
||||
|
||||
extern int cut_main(int argc, char** argv);
|
||||
extern struct cut_runtime cut;
|
||||
|
||||
struct cut_case {
|
||||
const char* sname;
|
||||
const char* cname;
|
||||
void *data;
|
||||
void (*run)(void*);
|
||||
void (*setup)(void*);
|
||||
void (*teardown)(void*);
|
||||
int skip;
|
||||
int flag;
|
||||
};
|
||||
|
||||
struct cut_runtime {
|
||||
int scnt_total;
|
||||
int ccnt_total;
|
||||
int ccnt_pass;
|
||||
int ccnt_fail;
|
||||
int ccnt_skip;
|
||||
struct cut_case *clist[CUT_CASE_MAX_CNT];
|
||||
struct cut_case *ccur;
|
||||
char *cerrmsg[CUT_CASE_MAX_CNT];
|
||||
};
|
||||
|
||||
#define CUT_CASE_RUNNER(sname, cname) cut_##sname##_##cname##_run
|
||||
#define CUT_CASE_NAME(sname, cname) cut_##sname##_##cname
|
||||
#define CUT_CASE_DATA(sname) cut_##sname##_data
|
||||
#define CUT_CASE_SETUP(sname) cut_##sname##_setup
|
||||
#define CUT_CASE_TEARDOWN(sname) cut_##sname##_teardown
|
||||
|
||||
#define DATA(sname) \
|
||||
struct CUT_CASE_DATA(sname)
|
||||
|
||||
#define SETUP(sname) \
|
||||
static void CUT_CASE_SETUP(sname)(struct CUT_CASE_DATA(sname) *data)
|
||||
|
||||
#define TEARDOWN(sname) \
|
||||
static void CUT_CASE_TEARDOWN(sname)(struct CUT_CASE_DATA(sname) *data)
|
||||
|
||||
|
||||
/*
|
||||
* @brief: construct a test case structor and a test case runner
|
||||
* @sname: suite name
|
||||
* @cname: case name
|
||||
* e.g.
|
||||
CASE(mysuite, mycase1) {
|
||||
// do something here
|
||||
ASSERT_TRUE(1);
|
||||
}
|
||||
*/
|
||||
#define CASE(sname, cname) \
|
||||
static void CUT_CASE_RUNNER(sname, cname)(void *null); \
|
||||
static struct cut_case CUT_CASE_NAME(sname, cname) = { \
|
||||
#sname, #cname, NULL, CUT_CASE_RUNNER(sname, cname), NULL, NULL, 0}; \
|
||||
static void CUT_CASE_RUNNER(sname, cname)(void *null)
|
||||
|
||||
/*
|
||||
* @brief: construct a test case structor and a test case runner
|
||||
* with case_data/setup/teardown for each case.
|
||||
* @sname: suite name
|
||||
* @cname: case name
|
||||
* e.g.
|
||||
DATA(mysuite) {
|
||||
int errmsg;
|
||||
char *errcode;
|
||||
};
|
||||
|
||||
SETUP(mysuite) {
|
||||
data->errcode = 0;
|
||||
data->errmsg = (char*)malloc(100);
|
||||
}
|
||||
|
||||
TEARDOWN(mysuite) {
|
||||
if(data->errmsg) {
|
||||
free(data->errmsg);
|
||||
data->errmsg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CASE2(mysuite, mycase1) {
|
||||
data->errcode = 1;
|
||||
strcpy(data->errmsg, "timeout error");
|
||||
ASSERT_TRUE(1);
|
||||
}
|
||||
*/
|
||||
#define CASE2(sname, cname) \
|
||||
static struct CUT_CASE_DATA(sname) CUT_CASE_DATA(sname); \
|
||||
static void CUT_CASE_RUNNER(sname, cname)(struct CUT_CASE_DATA(sname) * data); \
|
||||
static struct cut_case CUT_CASE_NAME(sname, cname) = { \
|
||||
#sname, #cname, &CUT_CASE_DATA(sname), (void(*)(void*))CUT_CASE_RUNNER(sname, cname), \
|
||||
(void(*)(void*))CUT_CASE_SETUP(sname), (void(*)(void*))CUT_CASE_TEARDOWN(sname), 0}; \
|
||||
static void CUT_CASE_RUNNER(sname, cname)(struct CUT_CASE_DATA(sname) * data)
|
||||
|
||||
/*
|
||||
* @brief: construct a test suite by adding test case(s)
|
||||
* @sname: suite name
|
||||
* e.g.
|
||||
SUITE(mysuite) = {
|
||||
ADD_CASE(mysuite, mycase1),
|
||||
ADD_CASE(mysuite, mycase2),
|
||||
ADD_CASE_NULL
|
||||
};
|
||||
*/
|
||||
#define SUITE(sname) struct cut_case *cut_suite_##sname[]
|
||||
|
||||
/*
|
||||
* @brief: add a test case into a test suite
|
||||
* @sname: suite name
|
||||
* @cname: case name
|
||||
*/
|
||||
#define ADD_CASE(sname, cname) &CUT_CASE_NAME(sname, cname)
|
||||
#define ADD_CASE_NULL (struct cut_case*)(NULL)
|
||||
|
||||
/*
|
||||
* @brief: add a test suite into case list
|
||||
* @sname: suite name
|
||||
*/
|
||||
#define ADD_SUITE(sname) \
|
||||
do { \
|
||||
int i = 0; \
|
||||
extern struct cut_case *cut_suite_##sname[]; \
|
||||
struct cut_case *c = cut_suite_##sname[i]; \
|
||||
if (cut.ccnt_total >= CUT_CASE_MAX_CNT) { \
|
||||
cut_printf("reaches maximum case count:%d\n", \
|
||||
CUT_CASE_MAX_CNT); \
|
||||
break; \
|
||||
} \
|
||||
while (c) { \
|
||||
*(cut.clist + cut.ccnt_total++) = c; \
|
||||
c = *(cut_suite_##sname + (++i)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define TRY //if(0==setjmp(cut.jmpbuf))
|
||||
#define EXCEPT //else
|
||||
#define RAISE_EXCEPTION_WITH_MSG(msg) \
|
||||
do \
|
||||
{ \
|
||||
int ret = 0, i = cut.ccnt_fail; \
|
||||
cut.cerrmsg[i] = (char *)cut_malloc(CUT_MSG_MAX_LEN); \
|
||||
assert(cut.cerrmsg[i] != NULL); \
|
||||
memset(cut.cerrmsg[i], 0, CUT_MSG_MAX_LEN); \
|
||||
ret = cut_snprintf(cut.cerrmsg[i], \
|
||||
CUT_MSG_MAX_LEN - 1, \
|
||||
"%s.%s in %s(%d) expected %s", \
|
||||
cut.ccur->sname, cut.ccur->cname, \
|
||||
__FILE__, __LINE__, msg); \
|
||||
if (ret >= CUT_MSG_MAX_LEN) \
|
||||
cut_snprintf(cut.cerrmsg[i] + CUT_MSG_MAX_LEN - 4, \
|
||||
4, "..."); \
|
||||
cut.ccur->flag = 0; \
|
||||
return; \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_TRUE(cond) \
|
||||
do { \
|
||||
if (!(cond)) \
|
||||
RAISE_EXCEPTION_WITH_MSG("[True]"); \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_INT(expected, compare, actual) \
|
||||
do { \
|
||||
if (!((expected)compare(actual))) \
|
||||
RAISE_EXCEPTION_WITH_MSG("[" #expected " " #compare " " #actual "]"); \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_STR(expected, compare, actual) \
|
||||
do { \
|
||||
if (!(strcmp((expected), (actual)) compare 0)) \
|
||||
RAISE_EXCEPTION_WITH_MSG("[" #expected " " #compare " " #actual "]"); \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_IN(expected1, actual, expected2) \
|
||||
do { \
|
||||
if ((actual) < (expected1) || (actual) > (expected2)) \
|
||||
RAISE_EXCEPTION_WITH_MSG("[" #expected1 " <= " #actual " <=" #expected2); \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_FAIL() RAISE_EXCEPTION_WITH_MSG("[should not be here]")
|
||||
#define ASSERT_FALSE(cond) ASSERT_TRUE(!(cond))
|
||||
#define ASSERT_NULL(ptr) ASSERT_INT(ptr, ==, NULL)
|
||||
#define ASSERT_NOT_NULL(ptr) ASSERT_INT(ptr, !=, NULL)
|
||||
#define ASSERT_EQ(actual, expected) ASSERT_INT(actual, ==, expected)
|
||||
#define ASSERT_NE(actual, expected) ASSERT_INT(actual, !=, expected)
|
||||
#define ASSERT_GT(actual, expected) ASSERT_INT(actual, >, expected)
|
||||
#define ASSERT_GE(actual, expected) ASSERT_INT(actual, >=, expected)
|
||||
#define ASSERT_LT(actual, expected) ASSERT_INT(actual, <, expected)
|
||||
#define ASSERT_LE(actual, expected) ASSERT_INT(actual, <=, expected)
|
||||
#define ASSERT_STR_EQ(actual, expected) ASSERT_STR(actual, ==, expected)
|
||||
#define ASSERT_STR_NE(actual, expected) ASSERT_STR(actual, !=, expected)
|
||||
#define ASSERT_STR_GT(actual, expected) ASSERT_STR(actual, >, expected)
|
||||
#define ASSERT_STR_LT(actual, expected) ASSERT_STR(actual, <, expected)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUT_H__ */
|
||||
|
||||
718
Living_SDK/test/testcase/basic_test/rhino_test.c
Normal file
718
Living_SDK/test/testcase/basic_test/rhino_test.c
Normal file
|
|
@ -0,0 +1,718 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "cutest/cut.h"
|
||||
|
||||
#ifndef SYSINFO_ARCH
|
||||
#define SYSINFO_ARCH ""
|
||||
#endif
|
||||
#ifndef SYSINFO_MCU
|
||||
#define SYSINFO_MCU ""
|
||||
#endif
|
||||
#ifndef SYSINFO_DEVICE_NAME
|
||||
#define SYSINFO_DEVICE_NAME ""
|
||||
#endif
|
||||
#ifndef SYSINFO_APP_VERSION
|
||||
#define SYSINFO_APP_VERSION ""
|
||||
#endif
|
||||
#define SYSINFO_KERNEL "RHINO"
|
||||
|
||||
/* dynamic memory alloc test */
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
#define TEST_CONFIG_MM_ENABLED (1)
|
||||
#if (TEST_CONFIG_MM_ENABLED > 0)
|
||||
#define TEST_CONFIG_MALLOC_MAX_SIZE (1024)
|
||||
#define TEST_CONFIG_MALLOC_FREE_TIMES (100000)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* task test */
|
||||
#define TEST_CONFIG_TASK_ENABLED (1)
|
||||
#if (TEST_CONFIG_TASK_ENABLED > 0)
|
||||
#ifndef TEST_CONFIG_STACK_SIZE
|
||||
#define TEST_CONFIG_STACK_SIZE (256)
|
||||
#endif
|
||||
#define TEST_CONFIG_MAX_TASK_COUNT (10)
|
||||
#define TEST_CONFIG_CREATE_TASK_TIMES (10000)
|
||||
#endif
|
||||
|
||||
/* task communication test */
|
||||
#define TEST_CONFIG_TASK_COMM_ENABLED (1)
|
||||
#if (TEST_CONFIG_TASK_COMM_ENABLED > 0)
|
||||
#ifndef TEST_CONFIG_STACK_SIZE
|
||||
#define TEST_CONFIG_STACK_SIZE (256)
|
||||
#endif
|
||||
#define TEST_CONFIG_SYNC_TIMES (100000)
|
||||
#define TEST_CONFIG_QUEUE_BUF_SIZE (32)
|
||||
#endif
|
||||
|
||||
/* timer test */
|
||||
#define TEST_CONFIG_TIMER_ENABLED (1)
|
||||
|
||||
/* kv test */
|
||||
#define TEST_CONFIG_KV_ENABLED (0)
|
||||
#if (TEST_CONFIG_KV_ENABLED > 0)
|
||||
#define TEST_CONFIG_KV_TIMES (10000)
|
||||
#endif
|
||||
|
||||
/* yloop test */
|
||||
#define TEST_CONFIG_YLOOP_ENABLED (0)
|
||||
#if (TEST_CONFIG_YLOOP_ENABLED)
|
||||
#define TEST_CONFIG_YLOOP_EVENT_COUNT (1000)
|
||||
#define TEST_CONFIG_YLOOP_LOOP_COUNT (5)
|
||||
#endif
|
||||
|
||||
static int g_var0 = 0;
|
||||
static int g_var1 = 0;
|
||||
static cpu_stack_t stack_buf[TEST_CONFIG_MAX_TASK_COUNT][TEST_CONFIG_STACK_SIZE];
|
||||
static ktask_t g_task[TEST_CONFIG_MAX_TASK_COUNT];
|
||||
|
||||
static int dump_test_config(void)
|
||||
{
|
||||
#define _PARSE(x) #x
|
||||
#define PARSE(x) _PARSE(x)
|
||||
#define PRINT_CONFIG(x) printf("\33[0;35m%s=%s\33[0m\r\n", #x, PARSE(x))
|
||||
if (strlen(SYSINFO_ARCH)==0 || strlen(SYSINFO_MCU) == 0 || strlen(SYSINFO_DEVICE_NAME)==0) {
|
||||
printf("Please set your device info first!\r\n");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PRINT_CONFIG(SYSINFO_ARCH);
|
||||
PRINT_CONFIG(SYSINFO_MCU);
|
||||
PRINT_CONFIG(SYSINFO_DEVICE_NAME);
|
||||
PRINT_CONFIG(SYSINFO_KERNEL);
|
||||
PRINT_CONFIG(SYSINFO_KERNEL_VERSION);
|
||||
PRINT_CONFIG(SYSINFO_APP_VERSION);
|
||||
}
|
||||
|
||||
PRINT_CONFIG(TEST_CONFIG_MM_ENABLED);
|
||||
#if (TEST_CONFIG_MM_ENABLED > 0)
|
||||
PRINT_CONFIG(TEST_CONFIG_MALLOC_MAX_SIZE);
|
||||
PRINT_CONFIG(TEST_CONFIG_MALLOC_FREE_TIMES);
|
||||
#endif
|
||||
|
||||
PRINT_CONFIG(TEST_CONFIG_TASK_ENABLED);
|
||||
#if (TEST_CONFIG_TASK_ENABLED > 0)
|
||||
PRINT_CONFIG(TEST_CONFIG_MAX_TASK_COUNT);
|
||||
PRINT_CONFIG(TEST_CONFIG_CREATE_TASK_TIMES);
|
||||
#endif
|
||||
|
||||
PRINT_CONFIG(TEST_CONFIG_TASK_COMM_ENABLED);
|
||||
#if (TEST_CONFIG_TASK_COMM_ENABLED > 0)
|
||||
PRINT_CONFIG(TEST_CONFIG_SYNC_TIMES);
|
||||
#endif
|
||||
|
||||
PRINT_CONFIG(TEST_CONFIG_TIMER_ENABLED);
|
||||
|
||||
PRINT_CONFIG(TEST_CONFIG_KV_ENABLED);
|
||||
#if (TEST_CONFIG_KV_ENABLED > 0)
|
||||
PRINT_CONFIG(TEST_CONFIG_KV_TIMES);
|
||||
#endif
|
||||
|
||||
PRINT_CONFIG(TEST_CONFIG_YLOOP_ENABLED);
|
||||
#if (TEST_CONFIG_YLOOP_ENABLED)
|
||||
PRINT_CONFIG(TEST_CONFIG_YLOOP_EVENT_COUNT);
|
||||
PRINT_CONFIG(TEST_CONFIG_YLOOP_LOOP_COUNT);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (TEST_CONFIG_MM_ENABLED > 0)
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
CASE(test_mm, aos_1_001)
|
||||
{
|
||||
unsigned int size = 512;
|
||||
unsigned char *ptr = NULL;
|
||||
|
||||
ptr = krhino_mm_alloc(size);
|
||||
ASSERT_NOT_NULL(ptr);
|
||||
|
||||
krhino_mm_free(ptr);
|
||||
}
|
||||
|
||||
CASE(test_mm, aos_1_002)
|
||||
{
|
||||
/* case is not support by rhino */
|
||||
}
|
||||
|
||||
CASE(test_mm, aos_1_003)
|
||||
{
|
||||
unsigned int size1 = 512;
|
||||
unsigned int size2 = 1024;
|
||||
unsigned char *ptr = NULL;
|
||||
int i = 0;
|
||||
|
||||
ptr = krhino_mm_alloc(size1);
|
||||
ASSERT_NOT_NULL(ptr);
|
||||
memset(ptr, 0x5A, size1);
|
||||
|
||||
krhino_mm_realloc(ptr, size2);
|
||||
ASSERT_NOT_NULL(ptr);
|
||||
memset(ptr+size1, 0xA5, size2-size1);
|
||||
|
||||
for(i=0; i<size1; i++) {
|
||||
if(*(ptr+i) != 0x5A) {
|
||||
krhino_mm_free(ptr);
|
||||
ASSERT_FAIL();
|
||||
}
|
||||
}
|
||||
for(; i<size2; i++) {
|
||||
if(*(ptr+i) != 0xA5) {
|
||||
krhino_mm_free(ptr);
|
||||
ASSERT_FAIL();
|
||||
}
|
||||
}
|
||||
krhino_mm_free(ptr);
|
||||
}
|
||||
|
||||
CASE(test_mm, aos_1_004)
|
||||
{
|
||||
unsigned int size1 = 512;
|
||||
unsigned int size2 = 256;
|
||||
unsigned char *ptr = NULL;
|
||||
int i = 0;
|
||||
|
||||
ptr = krhino_mm_alloc(size1);
|
||||
ASSERT_NOT_NULL(ptr);
|
||||
memset(ptr, 0x5A, size1);
|
||||
|
||||
krhino_mm_realloc(ptr, size2);
|
||||
ASSERT_NOT_NULL(ptr);
|
||||
|
||||
for(i=0; i<size2; i++) {
|
||||
if(*(ptr+i) != 0x5A) {
|
||||
krhino_mm_free(ptr);
|
||||
ASSERT_FAIL();
|
||||
}
|
||||
}
|
||||
krhino_mm_free(ptr);
|
||||
}
|
||||
|
||||
CASE(test_mm, aos_1_005)
|
||||
{
|
||||
char *ptr = NULL;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
for (i = 1; i <= TEST_CONFIG_MALLOC_FREE_TIMES; i++) {
|
||||
ptr = krhino_mm_alloc(TEST_CONFIG_MALLOC_MAX_SIZE);
|
||||
ASSERT_NOT_NULL(ptr);
|
||||
|
||||
for (j = 0; j < TEST_CONFIG_MALLOC_MAX_SIZE; j++) {
|
||||
*(ptr + j) = j;
|
||||
}
|
||||
krhino_mm_free(ptr);
|
||||
if(i % (TEST_CONFIG_MALLOC_FREE_TIMES/10) == 0) {
|
||||
printf("alloc-free: %d/%d\r\n", i, TEST_CONFIG_MALLOC_FREE_TIMES);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* RHINO_CONFIG_MM_TLF > 0 */
|
||||
#endif /* TEST_CONFIG_MM_ENABLED > 0 */
|
||||
|
||||
SUITE(test_mm) = {
|
||||
#if (TEST_CONFIG_MM_ENABLED > 0)
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
ADD_CASE(test_mm, aos_1_001),
|
||||
ADD_CASE(test_mm, aos_1_002),
|
||||
ADD_CASE(test_mm, aos_1_003),
|
||||
ADD_CASE(test_mm, aos_1_004),
|
||||
ADD_CASE(test_mm, aos_1_005),
|
||||
#endif
|
||||
#endif
|
||||
ADD_CASE_NULL
|
||||
};
|
||||
|
||||
#if (TEST_CONFIG_TASK_ENABLED > 0)
|
||||
static void task0(void *arg)
|
||||
{
|
||||
krhino_task_sleep(10);
|
||||
g_var0++;
|
||||
}
|
||||
|
||||
CASE(test_task, aos_1_006)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
g_var0 = 0;
|
||||
printf("create task start\r\n");
|
||||
ret = krhino_task_create(&g_task[0], "task0", NULL, 10, 50,
|
||||
stack_buf[0], TEST_CONFIG_STACK_SIZE, task0, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
printf("create task success\r\n");
|
||||
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND*2);
|
||||
krhino_task_del(&g_task[0]);
|
||||
|
||||
ASSERT_EQ(g_var0, 1);
|
||||
g_var0 = 0;
|
||||
}
|
||||
|
||||
CASE(test_task, aos_1_007)
|
||||
{
|
||||
/* case is not support by rhino */
|
||||
}
|
||||
|
||||
CASE(test_task, aos_1_008)
|
||||
{
|
||||
/* case is not support by rhino */
|
||||
}
|
||||
|
||||
CASE(test_task, aos_1_009)
|
||||
{
|
||||
/* case is not support by rhino */
|
||||
}
|
||||
|
||||
CASE(test_task, aos_1_010)
|
||||
{
|
||||
/* case is not support by rhino */
|
||||
}
|
||||
|
||||
CASE(test_task, aos_1_011)
|
||||
{
|
||||
kstat_t ret;
|
||||
char task_name[10];
|
||||
int i = 0;
|
||||
|
||||
g_var0 = 0;
|
||||
for (i=0; i<TEST_CONFIG_MAX_TASK_COUNT; i++) {
|
||||
sprintf(task_name, "task%d", i);
|
||||
ret = krhino_task_create(&g_task[i], task_name, NULL, 10, 50,
|
||||
stack_buf[i], TEST_CONFIG_STACK_SIZE, task0, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
printf("create %s OK\r\n", task_name);
|
||||
krhino_task_sleep(20);
|
||||
}
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND*5);
|
||||
for (i=0; i<TEST_CONFIG_MAX_TASK_COUNT; i++) {
|
||||
krhino_task_del(&g_task[i]);
|
||||
}
|
||||
|
||||
ASSERT_EQ(g_var0, TEST_CONFIG_MAX_TASK_COUNT);
|
||||
g_var0 = 0;
|
||||
}
|
||||
|
||||
CASE(test_task, aos_1_012)
|
||||
{
|
||||
kstat_t ret;
|
||||
char task_name[10];
|
||||
int i = 0;
|
||||
|
||||
for(i=1; i<=TEST_CONFIG_CREATE_TASK_TIMES; i++) {
|
||||
g_var0 = 0;
|
||||
sprintf(task_name, "task%d", i);
|
||||
ret = krhino_task_create(&g_task[0], task_name, NULL, 10, 50,
|
||||
stack_buf[0], TEST_CONFIG_STACK_SIZE, task0, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
krhino_task_sleep(10);
|
||||
ASSERT_EQ(g_var0, 1);
|
||||
if (i % 50 == 0) {
|
||||
printf("create task: %d/%d\r\n", i, TEST_CONFIG_CREATE_TASK_TIMES);
|
||||
}
|
||||
krhino_task_del(&g_task[0]);
|
||||
krhino_task_sleep(10);
|
||||
}
|
||||
}
|
||||
#endif /* TEST_CONFIG_TASK_ENABLED > 0 */
|
||||
|
||||
SUITE(test_task) =
|
||||
{
|
||||
#if (TEST_CONFIG_TASK_ENABLED > 0)
|
||||
ADD_CASE(test_task, aos_1_006),
|
||||
ADD_CASE(test_task, aos_1_007),
|
||||
ADD_CASE(test_task, aos_1_008),
|
||||
ADD_CASE(test_task, aos_1_009),
|
||||
ADD_CASE(test_task, aos_1_010),
|
||||
ADD_CASE(test_task, aos_1_011),
|
||||
ADD_CASE(test_task, aos_1_012),
|
||||
#endif
|
||||
ADD_CASE_NULL
|
||||
};
|
||||
|
||||
#if (TEST_CONFIG_TASK_COMM_ENABLED > 0)
|
||||
static kmutex_t g_mutex;
|
||||
/* task: decrease g_var0 with mutex*/
|
||||
static void task1(void *arg)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(i=0; i<TEST_CONFIG_SYNC_TIMES; i++) {
|
||||
krhino_mutex_lock(&g_mutex, RHINO_WAIT_FOREVER);
|
||||
g_var0--;
|
||||
krhino_mutex_unlock(&g_mutex);
|
||||
}
|
||||
g_var1++;
|
||||
}
|
||||
|
||||
/* task: increase g_var0 with mutex*/
|
||||
static void task2(void *arg)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(i=0; i<TEST_CONFIG_SYNC_TIMES; i++) {
|
||||
krhino_mutex_lock(&g_mutex, RHINO_WAIT_FOREVER);
|
||||
g_var0++;
|
||||
krhino_mutex_unlock(&g_mutex);
|
||||
}
|
||||
g_var1++;
|
||||
}
|
||||
|
||||
CASE(test_task_comm, aos_1_013)
|
||||
{
|
||||
kstat_t ret;
|
||||
|
||||
ret = krhino_mutex_create(&g_mutex, "g_mutext");
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_lock(&g_mutex, RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_mutex_lock(&g_mutex, RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
ASSERT_EQ(ret, RHINO_MUTEX_OWNER_NESTED);
|
||||
|
||||
ret = krhino_mutex_unlock(&g_mutex);
|
||||
ASSERT_EQ(ret, RHINO_MUTEX_OWNER_NESTED);
|
||||
|
||||
ret = krhino_mutex_del(&g_mutex);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
CASE(test_task_comm, aos_1_014)
|
||||
{
|
||||
kstat_t ret = RHINO_SUCCESS;
|
||||
char task_name[10];
|
||||
int task_count = 4;
|
||||
int i = 0;
|
||||
|
||||
ASSERT_EQ(task_count % 2, 0);
|
||||
|
||||
g_var0 = 0;
|
||||
g_var1 = 0;
|
||||
ret = krhino_mutex_create(&g_mutex, "g_mutext");
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
for (i=0; i<task_count; i++) {
|
||||
if(i < (task_count>>1)) {
|
||||
ret = krhino_task_create(&g_task[i], task_name, NULL, 10, 50,
|
||||
stack_buf[i], TEST_CONFIG_STACK_SIZE, task1, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
else {
|
||||
ret = krhino_task_create(&g_task[i], task_name, NULL, 10, 50,
|
||||
stack_buf[i], TEST_CONFIG_STACK_SIZE, task2, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
krhino_task_sleep(1);
|
||||
}
|
||||
|
||||
while(g_var1 < task_count) {
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
for(i=0; i<task_count; i++) {
|
||||
krhino_task_del(&g_task[i]);
|
||||
}
|
||||
krhino_mutex_del(&g_mutex);
|
||||
ASSERT_EQ(g_var0, 0);
|
||||
}
|
||||
|
||||
#if (RHINO_CONFIG_SEM > 0)
|
||||
static ksem_t g_sem;
|
||||
/* task: decrease g_var with sem */
|
||||
static void task3(void *arg)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(i=0; i<TEST_CONFIG_SYNC_TIMES; i++) {
|
||||
krhino_sem_take(&g_sem, RHINO_WAIT_FOREVER);
|
||||
g_var0--;
|
||||
krhino_sem_give(&g_sem);
|
||||
}
|
||||
g_var1++;
|
||||
}
|
||||
|
||||
/* task: decrease g_var with sem */
|
||||
static void task4(void *arg)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(i=0; i<TEST_CONFIG_SYNC_TIMES; i++) {
|
||||
krhino_sem_take(&g_sem, RHINO_WAIT_FOREVER);
|
||||
g_var0++;
|
||||
krhino_sem_give(&g_sem);
|
||||
}
|
||||
g_var1++;
|
||||
}
|
||||
CASE(test_task_comm, aos_1_015)
|
||||
{
|
||||
kstat_t ret = RHINO_SUCCESS;
|
||||
|
||||
ret = krhino_sem_create(&g_sem, "g_sem", 0);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(&g_sem, RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
ASSERT_EQ(ret, RHINO_BLK_TIMEOUT);
|
||||
|
||||
ret = krhino_sem_give(&g_sem);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_take(&g_sem, RHINO_CONFIG_NEXT_INTRPT_TICKS);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_sem_del(&g_sem);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
CASE(test_task_comm, aos_1_016)
|
||||
{
|
||||
kstat_t ret = RHINO_SUCCESS;
|
||||
char task_name[10] = {0};
|
||||
unsigned int task_count = 4;
|
||||
int i = 0;
|
||||
|
||||
ASSERT_TRUE(task_count%2 == 0);
|
||||
|
||||
ret = krhino_sem_create(&g_sem, "g_sem", 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
g_var0 = 0;
|
||||
g_var1 = 0;
|
||||
for(i=0; i<task_count; i++) {
|
||||
sprintf(task_name, "task%d", i+1);
|
||||
if(i < (task_count>>1)) {
|
||||
ret = krhino_task_create(&g_task[i], task_name, NULL, 10, 50,
|
||||
stack_buf[i], TEST_CONFIG_STACK_SIZE, task3, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
else {
|
||||
ret = krhino_task_create(&g_task[i], task_name, NULL, 10, 50,
|
||||
stack_buf[i], TEST_CONFIG_STACK_SIZE, task4, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
krhino_task_sleep(1);
|
||||
}
|
||||
while(g_var1 < task_count) {
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
for(i=0; i<task_count; i++) {
|
||||
krhino_task_del(&g_task[i]);
|
||||
}
|
||||
krhino_sem_del(&g_sem);
|
||||
ASSERT_EQ(g_var0, 0);
|
||||
}
|
||||
#endif /* RHINO_CONFIG_SEM > 0 */
|
||||
|
||||
#if (RHINO_CONFIG_QUEUE > 0)
|
||||
static char *queue_buf[3][TEST_CONFIG_QUEUE_BUF_SIZE];
|
||||
static kqueue_t g_queue[3];
|
||||
|
||||
/* task: g_queue[0] -> g_queue[1] */
|
||||
static void task5(void *arg)
|
||||
{
|
||||
int *recv = NULL;
|
||||
|
||||
while(1) {
|
||||
krhino_queue_recv(&g_queue[0], RHINO_WAIT_FOREVER, (void**)&recv);
|
||||
krhino_queue_back_send(&g_queue[1], recv);
|
||||
if(*recv == TEST_CONFIG_SYNC_TIMES) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("task5 exit!\r\n");
|
||||
}
|
||||
|
||||
/* task: g_queue[1] -> g_queue[2] */
|
||||
static void task6(void *arg)
|
||||
{
|
||||
int *recv = NULL;
|
||||
|
||||
while(1) {
|
||||
krhino_queue_recv(&g_queue[1], RHINO_WAIT_FOREVER, (void**)&recv);
|
||||
krhino_queue_back_send(&g_queue[2], recv);
|
||||
if(*recv == TEST_CONFIG_SYNC_TIMES) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("task6 exit!\r\n");
|
||||
}
|
||||
|
||||
CASE(test_task_comm, aos_1_017)
|
||||
{
|
||||
kstat_t ret = RHINO_SUCCESS;
|
||||
char *send = "hello world!";
|
||||
char *recv = NULL;
|
||||
|
||||
ret = krhino_queue_create(&g_queue[0], "g_queue", (void**)&queue_buf[0], TEST_CONFIG_QUEUE_BUF_SIZE);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_recv(&g_queue[0], 100, (void**)&recv);
|
||||
ASSERT_EQ(ret, RHINO_BLK_TIMEOUT);
|
||||
|
||||
krhino_queue_del(&g_queue[0]);
|
||||
}
|
||||
|
||||
CASE(test_task_comm, aos_1_018)
|
||||
{
|
||||
kstat_t ret = RHINO_SUCCESS;
|
||||
int i = 0;
|
||||
int send = 0;
|
||||
int *recv = NULL;
|
||||
|
||||
ret = krhino_queue_create(&g_queue[0], "g_queue[0]", (void**)&queue_buf[0], TEST_CONFIG_QUEUE_BUF_SIZE);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_create(&g_queue[1], "g_queue[1]", (void**)&queue_buf[1], TEST_CONFIG_QUEUE_BUF_SIZE);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_create(&g_queue[2], "g_queue[2]", (void**)&queue_buf[2], TEST_CONFIG_QUEUE_BUF_SIZE);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_create(&g_task[0], "task5", NULL, 10, 50,
|
||||
stack_buf[0], TEST_CONFIG_STACK_SIZE, task5, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_task_create(&g_task[1], "task6", NULL, 10, 50,
|
||||
stack_buf[1], TEST_CONFIG_STACK_SIZE, task6, 1);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
for(i=1; i<=TEST_CONFIG_SYNC_TIMES; i++) {
|
||||
send = i;
|
||||
ret = krhino_queue_back_send(&g_queue[0], &send);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_queue_recv(&g_queue[2], RHINO_WAIT_FOREVER, (void **)&recv);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
ASSERT_EQ(send, *recv);
|
||||
if (i % (TEST_CONFIG_SYNC_TIMES/10) == 0) {
|
||||
printf("queue sync: %d/%d\r\n", i, TEST_CONFIG_SYNC_TIMES);
|
||||
}
|
||||
}
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
|
||||
krhino_queue_del(&g_queue[0]);
|
||||
krhino_queue_del(&g_queue[1]);
|
||||
krhino_queue_del(&g_queue[2]);
|
||||
krhino_task_del(&g_task[0]);
|
||||
krhino_task_del(&g_task[1]);
|
||||
}
|
||||
#endif /* RHINO_CONFIG_QUEUE > 0 */
|
||||
#endif /* TEST_CONFIG_TASK_COMM_ENABLED > 0 */
|
||||
|
||||
SUITE(test_task_comm) =
|
||||
{
|
||||
#if (TEST_CONFIG_TASK_COMM_ENABLED > 0)
|
||||
ADD_CASE(test_task_comm, aos_1_013),
|
||||
ADD_CASE(test_task_comm, aos_1_014),
|
||||
#if (RHINO_CONFIG_SEM > 0)
|
||||
ADD_CASE(test_task_comm, aos_1_015),
|
||||
ADD_CASE(test_task_comm, aos_1_016),
|
||||
#endif
|
||||
#if (RHINO_CONFIG_QUEUE > 0)
|
||||
ADD_CASE(test_task_comm, aos_1_017),
|
||||
ADD_CASE(test_task_comm, aos_1_018),
|
||||
#endif
|
||||
#endif
|
||||
ADD_CASE_NULL
|
||||
};
|
||||
|
||||
#if (TEST_CONFIG_TIMER_ENABLED > 0)
|
||||
#if (RHINO_CONFIG_TIMER > 0)
|
||||
static ktimer_t g_timer;
|
||||
static void timer_handler(void* timer, void* args)
|
||||
{
|
||||
printf("timer handler: %d\r\n", ++g_var0);
|
||||
}
|
||||
|
||||
CASE(test_timer, aos_1_019)
|
||||
{
|
||||
kstat_t ret = RHINO_SUCCESS;
|
||||
|
||||
g_var0 = 0;
|
||||
ret = krhino_timer_create(&g_timer, "g_timer", timer_handler, 1, 10, NULL, 0);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_start(&g_timer);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
while(g_var0 != 10) {
|
||||
krhino_task_sleep(1);
|
||||
}
|
||||
krhino_timer_stop(&g_timer);
|
||||
ret = krhino_timer_del(&g_timer);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
|
||||
CASE(test_timer, aos_1_020)
|
||||
{
|
||||
kstat_t ret = RHINO_SUCCESS;
|
||||
|
||||
g_var0 = 0;
|
||||
ret = krhino_timer_create(&g_timer, "g_timer", timer_handler, 1, RHINO_CONFIG_TICKS_PER_SECOND, NULL, 0);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
ret = krhino_timer_start(&g_timer);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
|
||||
while(g_var0 != 3) {
|
||||
krhino_task_sleep(1);
|
||||
}
|
||||
krhino_timer_stop(&g_timer);
|
||||
krhino_timer_change(&g_timer, 1, RHINO_CONFIG_TICKS_PER_SECOND*2);
|
||||
krhino_timer_start(&g_timer);
|
||||
while(g_var0 != 6) {
|
||||
krhino_task_sleep(1);
|
||||
}
|
||||
krhino_timer_stop(&g_timer);
|
||||
ret = krhino_timer_del(&g_timer);
|
||||
ASSERT_EQ(ret, RHINO_SUCCESS);
|
||||
}
|
||||
#endif /* RHINO_CONFIG_TIMER > 0 */
|
||||
#endif /* TEST_CONFIG_TIMER_ENABLED > 0 */
|
||||
|
||||
SUITE(test_timer) =
|
||||
{
|
||||
#if (TEST_CONFIG_TIMER_ENABLED > 0)
|
||||
#if (RHINO_CONFIG_TIMER > 0)
|
||||
ADD_CASE(test_timer, aos_1_019),
|
||||
ADD_CASE(test_timer, aos_1_020),
|
||||
#endif
|
||||
#endif
|
||||
ADD_CASE_NULL
|
||||
};
|
||||
|
||||
#define TEST_TASK_STACKSIZE (512)
|
||||
static ktask_t test_task_obj;
|
||||
static cpu_stack_t test_task_buf[TEST_TASK_STACKSIZE];
|
||||
void test_task(void *arg)
|
||||
{
|
||||
if (0 == dump_test_config()) {
|
||||
printf("test start!\r\n");
|
||||
ADD_SUITE(test_mm);
|
||||
ADD_SUITE(test_task);
|
||||
ADD_SUITE(test_task_comm);
|
||||
ADD_SUITE(test_timer);
|
||||
cut_main(0, NULL);
|
||||
printf("test finished!\r\n");
|
||||
}
|
||||
else {
|
||||
printf("test error!\r\n");
|
||||
}
|
||||
|
||||
krhino_task_del(&test_task_obj);
|
||||
}
|
||||
|
||||
/*extern void sdk_init(void);*/
|
||||
void test_certificate(void)
|
||||
{
|
||||
krhino_init();
|
||||
krhino_task_create(&test_task_obj, "test_task", 0, 20, 50,
|
||||
test_task_buf, TEST_TASK_STACKSIZE, test_task, 1);
|
||||
|
||||
/* mcu-specific initialization start */
|
||||
/*sdk_init();*/
|
||||
/* mcu-specific initialization finish */
|
||||
|
||||
krhino_start();
|
||||
}
|
||||
229
Living_SDK/test/testcase/cloudcoap_test/cloud_coap.c
Normal file
229
Living_SDK/test/testcase/cloudcoap_test/cloud_coap.c
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2020 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <aos/aos.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "iot_import.h"
|
||||
#include "iot_export.h"
|
||||
|
||||
#include "cloud_coap.h"
|
||||
#include "yunit.h"
|
||||
|
||||
static iotx_coap_context_t *p_coap_ctx = NULL;
|
||||
|
||||
static void iotx_response_handler(void *arg, void *p_response)
|
||||
{
|
||||
int len = 0;
|
||||
int ret = -1;
|
||||
unsigned char *p_payload = NULL;
|
||||
iotx_coap_resp_code_t resp_code;
|
||||
|
||||
ret = IOT_CoAP_GetMessageCode(p_response, &resp_code);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
ret = IOT_CoAP_GetMessagePayload(p_response, &p_payload, &len);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
static int iotx_post_data_to_server(iotx_device_info_t *device_info, void *param)
|
||||
{
|
||||
int ret = SUCCESS_RETURN;
|
||||
char *path = NULL;
|
||||
iotx_message_t message;
|
||||
iotx_coap_context_t *p_ctx = (iotx_coap_context_t *)param;
|
||||
|
||||
path = (char *)HAL_Malloc(IOTX_URI_MAX_LEN + 1);
|
||||
if (path == NULL)
|
||||
{
|
||||
YUNIT_ASSERT_MSG((path != NULL), "no mem")
|
||||
return FAIL_RETURN;
|
||||
}
|
||||
|
||||
memset(path, 0, IOTX_URI_MAX_LEN + 1);
|
||||
|
||||
message.p_payload = (unsigned char *)"{\"name\":\"hello world\"}";
|
||||
message.payload_len = strlen("{\"name\":\"hello world\"}");
|
||||
message.resp_callback = iotx_response_handler;
|
||||
message.msg_type = IOTX_MESSAGE_CON;
|
||||
message.content_type = IOTX_CONTENT_TYPE_JSON;
|
||||
|
||||
HAL_Snprintf(path, IOTX_URI_MAX_LEN, "/topic/sys/%s/%s/thing/deviceinfo/update/",
|
||||
(char *)device_info->product_key, (char *)device_info->device_name);
|
||||
|
||||
ret = IOT_CoAP_SendMessage(p_ctx, path, &message);
|
||||
|
||||
if (path)
|
||||
{
|
||||
HAL_Free(path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cloudcoap_init(const char *env, const char *secure)
|
||||
{
|
||||
int ret = SUCCESS_RETURN;
|
||||
int send_interval = 0;
|
||||
int post_count = 0;
|
||||
int success_count = 0;
|
||||
char *url = NULL;
|
||||
iotx_coap_config_t config;
|
||||
iotx_device_info_t deviceinfo;
|
||||
|
||||
memset(&config, 0x00, sizeof(iotx_coap_config_t));
|
||||
|
||||
url = (char *)HAL_Malloc(CLOUD_COAP_URL_MAX_LEN);
|
||||
if (url == NULL)
|
||||
{
|
||||
YUNIT_ASSERT_MSG((url != NULL), "no mem")
|
||||
|
||||
return FAIL_RETURN;
|
||||
}
|
||||
memset(url, 0, CLOUD_COAP_URL_MAX_LEN);
|
||||
|
||||
iotx_device_info_get(&deviceinfo);
|
||||
|
||||
if (0 == strncmp(env, "pre", strlen("pre")))
|
||||
{
|
||||
if (0 == strncmp(secure, "dtls", strlen("dtls")))
|
||||
{
|
||||
config.p_url = IOTX_PRE_DTLS_SERVER_URI;
|
||||
}
|
||||
else if (0 == strncmp(secure, "psk", strlen("psk")))
|
||||
{
|
||||
config.p_url = IOTX_PRE_PSK_SERVER_URI;
|
||||
}
|
||||
else
|
||||
{
|
||||
config.p_url = IOTX_PRE_NOSEC_SERVER_URI;
|
||||
}
|
||||
}
|
||||
else if (0 == strncmp(env, "online", strlen("online")))
|
||||
{
|
||||
if (0 == strncmp(secure, "dtls", strlen("dtls")))
|
||||
{
|
||||
HAL_Snprintf(url, CLOUD_COAP_URL_MAX_LEN, IOTX_ONLINE_DTLS_SERVER_URL, deviceinfo.product_key);
|
||||
config.p_url = url;
|
||||
}
|
||||
else if (0 == strncmp(secure, "psk", strlen("psk")))
|
||||
{
|
||||
HAL_Snprintf(url, CLOUD_COAP_URL_MAX_LEN, IOTX_ONLINE_PSK_SERVER_URL, deviceinfo.product_key);
|
||||
config.p_url = url;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = FAIL_RETURN;
|
||||
YUNIT_ASSERT_MSG((ret == SUCCESS_RETURN), "Online env must access with DTLS/PSK")
|
||||
goto ERROR;
|
||||
}
|
||||
}
|
||||
else if (0 == strncmp(env, "daily", strlen("daily")))
|
||||
{
|
||||
if (0 == strncmp(secure, "dtls", strlen("dtls")))
|
||||
{
|
||||
config.p_url = IOTX_DAILY_DTLS_SERVER_URI;
|
||||
}
|
||||
else if (0 == strncmp(secure, "psk", strlen("psk")))
|
||||
{
|
||||
config.p_url = IOTX_DAILY_PSK_SERVER_URI;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = FAIL_RETURN;
|
||||
YUNIT_ASSERT_MSG((ret == SUCCESS_RETURN), "Daily env must access with DTLS/PSK")
|
||||
goto ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = FAIL_RETURN;
|
||||
YUNIT_ASSERT_MSG((ret == SUCCESS_RETURN), "Params error")
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
config.p_devinfo = (iotx_device_info_t *)&deviceinfo;
|
||||
config.wait_time_ms = CLOUD_COAP_CONNECT_TIMEOUT;
|
||||
|
||||
p_coap_ctx = IOT_CoAP_Init(&config);
|
||||
YUNIT_ASSERT(p_coap_ctx != NULL);
|
||||
|
||||
ERROR:
|
||||
if (url)
|
||||
{
|
||||
HAL_Free(url);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
ret = cloudcoap_init(CLOUD_COAP_DEFAULT_ENV, CLOUD_COAP_DEFAULT_SECURE_TYPE);
|
||||
YUNIT_ASSERT(ret == SUCCESS_RETURN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
YUNIT_ASSERT(p_coap_ctx != NULL);
|
||||
IOT_CoAP_Deinit(&p_coap_ctx);
|
||||
|
||||
//Here sleep 1000ms or else init coap immediately will fail
|
||||
HAL_SleepMs(1000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void cloudcoap_auth_case(void)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
YUNIT_ASSERT(p_coap_ctx != NULL);
|
||||
ret = IOT_CoAP_DeviceNameAuth(p_coap_ctx);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
static void cloudcoap_request_case(void)
|
||||
{
|
||||
int ret = -1;
|
||||
iotx_device_info_t device_info;
|
||||
|
||||
memset(&device_info, 0, sizeof(iotx_device_info_t));
|
||||
|
||||
ret = iotx_device_info_get(&device_info);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
ret = iotx_post_data_to_server(&device_info, p_coap_ctx);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
ret = IOT_CoAP_Yield(p_coap_ctx);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
HAL_SleepMs(CLOUD_COAP_YIELD_TIMEOUT);
|
||||
}
|
||||
|
||||
static yunit_test_case_t cloudcoap_testcases[] = {
|
||||
{"auth", cloudcoap_auth_case},
|
||||
{"request", cloudcoap_request_case},
|
||||
YUNIT_TEST_CASE_NULL};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{"cloudcoap", init, cleanup, setup, teardown, cloudcoap_testcases},
|
||||
YUNIT_TEST_SUITE_NULL};
|
||||
|
||||
void test_cloudcoap(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_cloudcoap);
|
||||
26
Living_SDK/test/testcase/cloudcoap_test/cloud_coap.h
Normal file
26
Living_SDK/test/testcase/cloudcoap_test/cloud_coap.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef __CLOUD_COAP_H__
|
||||
#define __CLOUD_COAP_H__
|
||||
|
||||
#define CLOUD_COAP_LOG_TAG "[CloudCoap]:"
|
||||
|
||||
#define CLOUD_COAP_DEFAULT_ENV "online"
|
||||
#define CLOUD_COAP_DEFAULT_SECURE_TYPE "psk"
|
||||
|
||||
#define CLOUD_COAP_URL_MAX_LEN (128)
|
||||
#define CLOUD_COAP_YIELD_TIMEOUT (200)
|
||||
#define CLOUD_COAP_CONNECT_TIMEOUT (300)
|
||||
/* daily url */
|
||||
#define IOTX_DAILY_DTLS_SERVER_URI "coaps://11.239.164.238:5684"
|
||||
#define IOTX_DAILY_PSK_SERVER_URI "coap-psk://10.101.83.159:5682"
|
||||
|
||||
/* pre url */
|
||||
#define IOTX_PRE_DTLS_SERVER_URI "coaps://pre.coap.cn-shanghai.link.aliyuncs.com:5684"
|
||||
#define IOTX_PRE_NOSEC_SERVER_URI "coap://pre.coap.cn-shanghai.link.aliyuncs.com:5683"
|
||||
#define IOTX_PRE_PSK_SERVER_URI "coap-psk://pre.coap.cn-shanghai.link.aliyuncs.com:5683"
|
||||
|
||||
/* online url */
|
||||
#define IOTX_ONLINE_DTLS_SERVER_URL "coaps://%s.coap.cn-shanghai.link.aliyuncs.com:5684"
|
||||
#define IOTX_ONLINE_NOSEC_SERVER_URI "coap://%s.coap.cn-shanghai.link.aliyuncs.com:5683"
|
||||
#define IOTX_ONLINE_PSK_SERVER_URL "coap-psk://%s.coap.cn-shanghai.link.aliyuncs.com:5682"
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := cloudcoap_test
|
||||
|
||||
$(NAME)_SOURCES := cloud_coap.c
|
||||
|
||||
#Add this MACRO for coap testing
|
||||
GLOBAL_DEFINES += COAP_DTLS_SUPPORT
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror -Wno-unused-varible
|
||||
88
Living_SDK/test/testcase/framework/alink_test/alink_test.c
Normal file
88
Living_SDK/test/testcase/framework/alink_test/alink_test.c
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <aos/types.h>
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include "alink_export.h"
|
||||
|
||||
static void callback_cloud_disconnected(void)
|
||||
{
|
||||
printf("alink wsf server disconnected.\n");
|
||||
}
|
||||
|
||||
static void callback_cloud_connected(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
printf("alink wsf server connected.\n");
|
||||
|
||||
ret = alink_end();
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_alink_sandbox(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = alink_enable_sandbox_mode();
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
alink_register_callback(ALINK_CLOUD_CONNECTED,callback_cloud_connected);
|
||||
alink_register_callback(ALINK_CLOUD_DISCONNECTED,callback_cloud_disconnected);
|
||||
|
||||
ret = alink_start();
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_alink_daily(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = alink_enable_daily_mode(NULL,0);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = alink_start();
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_alink_testcases[] = {
|
||||
{ "daily", test_alink_daily},
|
||||
{ "sandbox",test_alink_sandbox},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "alink", init, cleanup, setup, teardown, aos_alink_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_alink(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_alink);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := alink_test
|
||||
|
||||
$(NAME)_COMPONENTS += protocol.alink ywss
|
||||
|
||||
$(NAME)_SOURCES += alink_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
11
Living_SDK/test/testcase/framework/alink_test/ucube.py
Normal file
11
Living_SDK/test/testcase/framework/alink_test/ucube.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
src = Split('''
|
||||
alink_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('alink_test', src)
|
||||
|
||||
component.add_comp_deps('framework/protocol/alink')
|
||||
component.add_comp_deps('framework/ywss')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
82
Living_SDK/test/testcase/framework/fota_test/fota_test.c
Normal file
82
Living_SDK/test/testcase/framework/fota_test/fota_test.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/aos.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include "ota_transport.h"
|
||||
extern void ota_service_event(input_event_t *event, void *priv_data);
|
||||
extern void ota_check_update(const char *buf, int len);
|
||||
extern void ota_service_init(void);
|
||||
extern void do_update(int len, const char *buf);
|
||||
extern void http_gethost_info(char* src, char* web, char* file, int* port);
|
||||
extern int ota_socket_connect(int port, char *host_addr);
|
||||
extern void ota_download_start(void * buf);
|
||||
extern int8_t platform_ota_parse_requset(const char* request, int *buf_len, ota_request_params * request_parmas);
|
||||
extern int8_t platform_ota_parse_response(const char* response, int buf_len, ota_response_params * response_parmas);
|
||||
|
||||
const char *ota_info = "{\"md5\":\"6B21342306D0F619AF97006B7025D18A\",\"resourceUrl\":\"http://otalink.alicdn.com/ALINKTEST_LIVING_LIGHT_ALINK_TEST/v2.0.0.1/uthash-master.zip\",\"size\":\"265694 \",\"uuid\":\"5B7CFD5C6B1D6A231F5FB6B7DB2B71FD\",\"version\":\"v2.0.0.1\",\"zip\":\"0\"}";
|
||||
|
||||
static void test_fota_case(void)
|
||||
{
|
||||
int ret = 0;
|
||||
input_event_t event;
|
||||
event.type = EV_SYS;
|
||||
event.code = CODE_SYS_ON_START_FOTA;
|
||||
event.value= NULL;
|
||||
ota_service_event(&event, NULL);
|
||||
ota_check_update("",1);
|
||||
ota_download_start(NULL);
|
||||
do_update(0, NULL);
|
||||
do_update(0, ota_info);
|
||||
|
||||
http_gethost_info(NULL, NULL, NULL, NULL);
|
||||
ret = ota_socket_connect(0, NULL);
|
||||
YUNIT_ASSERT(ret == -1);
|
||||
ret = platform_ota_parse_requset(NULL, NULL, NULL);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
ret = platform_ota_parse_response(NULL, 0, NULL);
|
||||
YUNIT_ASSERT(ret == -1)
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_fota_testcases[] = {
|
||||
{ "fota", test_fota_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "fota", init, cleanup, setup, teardown, aos_fota_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_fota(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_fota);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
NAME := fota_test
|
||||
|
||||
$(NAME)_COMPONENTS += fota
|
||||
|
||||
$(NAME)_SOURCES += fota_test.c
|
||||
|
||||
7
Living_SDK/test/testcase/framework/fota_test/ucube.py
Normal file
7
Living_SDK/test/testcase/framework/fota_test/ucube.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
src = Split('''
|
||||
fota_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('fota_test', src)
|
||||
|
||||
component.add_comp_deps('framework/fota')
|
||||
154
Living_SDK/test/testcase/framework/netmgr_test/netmgr_test.c
Normal file
154
Living_SDK/test/testcase/framework/netmgr_test/netmgr_test.c
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/aos.h>
|
||||
#include <hal/base.h>
|
||||
#include <hal/wifi.h>
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
|
||||
#include "netmgr.h"
|
||||
|
||||
enum
|
||||
{
|
||||
SMART_CONFIG_FLAG = 1 << 0,
|
||||
SAVED_CONFIG_FLAG = 1 << 1,
|
||||
DONE_FLAGS = SMART_CONFIG_FLAG | SAVED_CONFIG_FLAG,
|
||||
};
|
||||
|
||||
static uint8_t done_flag = 0;
|
||||
static void smart_config_test(void *arg);
|
||||
static void saved_config_test(void *arg);
|
||||
|
||||
static int events_executor(input_event_t *eventinfo, void *cb_para, int flag)
|
||||
{
|
||||
char ips[16];
|
||||
|
||||
printf("Type:%d Code:%d Flag:%d\n", eventinfo->type, eventinfo->code, flag);
|
||||
if (eventinfo->type != EV_WIFI)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((done_flag == SMART_CONFIG_FLAG) && (flag == SAVED_CONFIG_FLAG))
|
||||
{
|
||||
done_flag = DONE_FLAGS;
|
||||
}
|
||||
|
||||
switch (eventinfo->code)
|
||||
{
|
||||
case CODE_WIFI_ON_GOT_IP:
|
||||
done_flag |= flag;
|
||||
printf("done_flag:%d\n", done_flag);
|
||||
netmgr_deinit();
|
||||
wifi_get_ip(ips);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void saved_config_event_executor(input_event_t *eventinfo, void *cb_para)
|
||||
{
|
||||
events_executor(eventinfo, cb_para, SAVED_CONFIG_FLAG);
|
||||
}
|
||||
|
||||
static void smart_config_event_executor(input_event_t *eventinfo, void *cb_para)
|
||||
{
|
||||
if (events_executor(eventinfo, cb_para, SMART_CONFIG_FLAG) == 0)
|
||||
{
|
||||
aos_schedule_call(saved_config_test, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void smart_config_test(void *arg)
|
||||
{
|
||||
int ret;
|
||||
aos_unregister_event_filter(EV_WIFI, saved_config_event_executor, NULL);
|
||||
aos_register_event_filter(EV_WIFI, smart_config_event_executor, NULL);
|
||||
netmgr_init();
|
||||
ret = netmgr_start(true);
|
||||
#ifdef CONFIG_AOS_NETMGRYTS_NOSMARTCONFIG
|
||||
/* do not wait for WIFI event if no valid AP. */
|
||||
if (ret != 0)
|
||||
done_flag = DONE_FLAGS;
|
||||
#else
|
||||
(void)ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void saved_config_test(void *arg)
|
||||
{
|
||||
int ret;
|
||||
aos_unregister_event_filter(EV_WIFI, smart_config_event_executor, NULL);
|
||||
aos_register_event_filter(EV_WIFI, saved_config_event_executor, NULL);
|
||||
netmgr_init();
|
||||
ret = netmgr_start(true);
|
||||
#ifdef CONFIG_AOS_NETMGRYTS_NOSMARTCONFIG
|
||||
/* do not wait for WIFI event if no valid AP. */
|
||||
if (ret != 0)
|
||||
done_flag = DONE_FLAGS;
|
||||
#else
|
||||
(void)ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_netmgr_cases(void *arg)
|
||||
{
|
||||
aos_schedule_call(smart_config_test, NULL);
|
||||
}
|
||||
|
||||
static void netmgr_test_entry(void *arg)
|
||||
{
|
||||
aos_post_delayed_action(1000, test_netmgr_cases, NULL);
|
||||
aos_loop_run();
|
||||
}
|
||||
|
||||
static void netmgr_test_exit(void *arg)
|
||||
{
|
||||
aos_loop_exit();
|
||||
}
|
||||
|
||||
static void test_netmgr_connect_case(void)
|
||||
{
|
||||
aos_task_new("netmgr_test_main", netmgr_test_entry, NULL, 8192);
|
||||
|
||||
/* Set max 60s wait here, since wifi connect needs time to finish. */
|
||||
check_cond_wait(done_flag == DONE_FLAGS, 60);
|
||||
aos_schedule_call(netmgr_test_exit, NULL);
|
||||
aos_unregister_event_filter(EV_WIFI, smart_config_event_executor, NULL);
|
||||
aos_unregister_event_filter(EV_WIFI, saved_config_event_executor, NULL);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
done_flag = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_netmgr_testcases[] = {
|
||||
{"netmgr_connect", test_netmgr_connect_case},
|
||||
YUNIT_TEST_CASE_NULL};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{"netmgr", init, cleanup, setup, teardown, aos_netmgr_testcases},
|
||||
YUNIT_TEST_SUITE_NULL};
|
||||
|
||||
void test_netmgr(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
NAME := netmgr_test
|
||||
|
||||
$(NAME)_COMPONENTS +=
|
||||
|
||||
$(NAME)_SOURCES += netmgr_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
ifeq (,$(findstring linux, $(BUILD_STRING)))
|
||||
GLOBAL_DEFINES += CONFIG_AOS_NETMGRYTS_NOSMARTCONFIG
|
||||
endif
|
||||
8
Living_SDK/test/testcase/framework/netmgr_test/ucube.py
Normal file
8
Living_SDK/test/testcase/framework/netmgr_test/ucube.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
src = Split('''
|
||||
netmgr_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('netmgr_test', src)
|
||||
|
||||
if aos_global_config.board == 'linuxhost':
|
||||
component.add_global_macros('CONFIG_AOS_NETMGRYTS_NOSMARTCONFIG')
|
||||
362
Living_SDK/test/testcase/framework/uData_test/uData_test.c
Normal file
362
Living_SDK/test/testcase/framework/uData_test/uData_test.c
Normal file
|
|
@ -0,0 +1,362 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <vfs_conf.h>
|
||||
#include <vfs_err.h>
|
||||
#include <vfs_register.h>
|
||||
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/aos.h>
|
||||
#include <aos/uData.h>
|
||||
|
||||
#include "yunit.h"
|
||||
|
||||
#include "hal/soc/soc.h"
|
||||
|
||||
#define UDATA_SUCCES 0
|
||||
|
||||
static int uData_sensor_open(inode_t *node, file_t *file);
|
||||
static int uData_sensor_close(file_t *file);
|
||||
static ssize_t uData_sensor_read(file_t *f, void *buf, size_t len);
|
||||
static ssize_t uData_sensor_write(file_t *f, const void *buf, size_t len);
|
||||
static int uData_sensor_ioctl(file_t *f, int cmd, unsigned long arg);
|
||||
|
||||
file_ops_t uData_sensor_fops = {
|
||||
.open = uData_sensor_open,
|
||||
.close = uData_sensor_close,
|
||||
.read = uData_sensor_read,
|
||||
.write = uData_sensor_write,
|
||||
.ioctl = uData_sensor_ioctl,
|
||||
};
|
||||
|
||||
static sensor_obj_t *g_sensor_obj[TAG_DEV_SENSOR_NUM_MAX];
|
||||
static uint32_t g_sensor_cnt = 0;
|
||||
|
||||
static int drv_virtual_sensor_open(void)
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int drv_virtual_sensor_close(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int drv_virtual_sensor_read(void *buf, size_t len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int drv_virtual_sensor_ioctl(int cmd, unsigned long arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drv_virtual_sensor_init(void){
|
||||
int ret = 0;
|
||||
sensor_obj_t sensor;
|
||||
|
||||
/* fill the sensor obj parameters here */
|
||||
sensor.tag = TAG_DEV_BARO;
|
||||
sensor.path = dev_baro_path;
|
||||
sensor.io_port = I2C_PORT;
|
||||
sensor.open = drv_virtual_sensor_open;
|
||||
sensor.close = drv_virtual_sensor_close;
|
||||
sensor.read = drv_virtual_sensor_read;
|
||||
sensor.write = NULL;
|
||||
sensor.ioctl = drv_virtual_sensor_ioctl;
|
||||
sensor.irq_handle = NULL;
|
||||
|
||||
ret = uData_sensor_create_obj(&sensor);
|
||||
if(unlikely(ret)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG("%s %s successfully \n", SENSOR_STR, __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int uData_find_selected_sensor(char* path )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if(path == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < g_sensor_cnt; i++){
|
||||
if(strncmp(g_sensor_obj[i]->path, path, strlen(path)) == 0){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
static int uData_load_sensor_config(int index )
|
||||
{
|
||||
int ret = 0;
|
||||
g_sensor_obj[index] = (sensor_obj_t*)aos_malloc(sizeof(sensor_obj_t));
|
||||
if(g_sensor_obj[index] == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uData_sensor_obj_register(int index )
|
||||
{
|
||||
int ret = 0;
|
||||
ret = aos_register_driver(g_sensor_obj[index]->path, &uData_sensor_fops, NULL);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uData_sensor_create_obj(sensor_obj_t* sensor)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
g_sensor_obj[g_sensor_cnt] = (sensor_obj_t*)aos_malloc(sizeof(sensor_obj_t));
|
||||
if(g_sensor_obj[g_sensor_cnt] == NULL){
|
||||
return -1;
|
||||
}
|
||||
memset(g_sensor_obj[g_sensor_cnt], 0, sizeof(sensor_obj_t));
|
||||
|
||||
/* install the phy sensor info into the sensor object datebase here */
|
||||
g_sensor_obj[g_sensor_cnt]->io_port = sensor->io_port;
|
||||
g_sensor_obj[g_sensor_cnt]->path = sensor->path;
|
||||
g_sensor_obj[g_sensor_cnt]->tag = sensor->tag;
|
||||
g_sensor_obj[g_sensor_cnt]->open = sensor->open;
|
||||
g_sensor_obj[g_sensor_cnt]->close = sensor->close;
|
||||
g_sensor_obj[g_sensor_cnt]->ioctl = sensor->ioctl;
|
||||
g_sensor_obj[g_sensor_cnt]->read = sensor->read;
|
||||
g_sensor_obj[g_sensor_cnt]->write = sensor->write;
|
||||
g_sensor_obj[g_sensor_cnt]->irq_handle = sensor->irq_handle;
|
||||
g_sensor_obj[g_sensor_cnt]->mode = sensor->mode;
|
||||
g_sensor_obj[g_sensor_cnt]->bus = sensor->bus;
|
||||
g_sensor_obj[g_sensor_cnt]->power = DEV_POWER_OFF; // will update the status later
|
||||
|
||||
/* register the sensor object into the irq list and vfs */
|
||||
ret = uData_sensor_obj_register(g_sensor_cnt);
|
||||
if (ret != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
g_sensor_cnt++;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
free(g_sensor_obj[g_sensor_cnt]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int uData_sensor_hal_get_dev_list(void* buf)
|
||||
{
|
||||
sensor_list_t* list = buf;
|
||||
if(buf == NULL)
|
||||
return -1;
|
||||
|
||||
/* load the sensor count and tag list here */
|
||||
list->cnt = g_sensor_cnt;
|
||||
for(int index = 0; index < g_sensor_cnt; index++){
|
||||
list->list[index] = g_sensor_obj[index]->tag;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uData_sensor_open(inode_t *node, file_t *file)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
if((node == NULL)||(file == NULL)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* just open the /dev/sensor node here */
|
||||
if(strncmp(sensor_node_path, node->i_name, strlen(node->i_name)) == 0){
|
||||
return 0;
|
||||
}
|
||||
|
||||
index = uData_find_selected_sensor(node->i_name);
|
||||
if(( g_sensor_obj[index]->open == NULL)||(index < 0)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_sensor_obj[index]->open();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uData_sensor_close(file_t *file)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
/* just close the /dev/sensor node here */
|
||||
if(strncmp(sensor_node_path, (file->node->i_name), strlen(file->node->i_name)) == 0){
|
||||
return 0;
|
||||
}
|
||||
|
||||
index = uData_find_selected_sensor(file->node->i_name);
|
||||
if(( g_sensor_obj[index]->close == NULL)||(index < 0)){
|
||||
return -1;
|
||||
}
|
||||
g_sensor_obj[index]->close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t uData_sensor_read(file_t *f, void *buf, size_t len)
|
||||
{
|
||||
int index = 0;
|
||||
int ret = 0;
|
||||
|
||||
if(f == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
index = uData_find_selected_sensor(f->node->i_name);
|
||||
if(( g_sensor_obj[index]->read == NULL)||(index < 0)){
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(buf == NULL){
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = g_sensor_obj[index]->read(buf, len);
|
||||
if(ret != 0){
|
||||
goto error;
|
||||
}
|
||||
|
||||
return len;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t uData_sensor_write(file_t *f, const void *buf, size_t len)
|
||||
{
|
||||
/* no need this functionality recently */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uData_sensor_ioctl(file_t *f, int cmd, unsigned long arg)
|
||||
{
|
||||
int ret = 0;
|
||||
int index = 0;
|
||||
|
||||
if(f == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(cmd == SENSOR_IOCTL_GET_SENSOR_LIST){
|
||||
ret = uData_sensor_hal_get_dev_list(arg);
|
||||
if(ret != 0){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
index = uData_find_selected_sensor(f->node->i_name);
|
||||
if(( g_sensor_obj[index]->ioctl == NULL)||(index < 0)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = g_sensor_obj[index]->ioctl(cmd, arg);
|
||||
if(ret != 0){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uData_sensor_hal_register(void)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = aos_register_driver(sensor_node_path, &uData_sensor_fops, NULL);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uData_sensor_init(void){
|
||||
int ret = 0;
|
||||
int index = 0;
|
||||
g_sensor_cnt = 0 ;
|
||||
|
||||
drv_virtual_sensor_init();
|
||||
|
||||
ret = uData_sensor_hal_register();
|
||||
if(ret != 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_udata_subscribe_case(void)
|
||||
{
|
||||
int ret = 0;
|
||||
uData_sensor_init();
|
||||
uData_main();
|
||||
ret = uData_subscribe(UDATA_SERVICE_BARO);
|
||||
YUNIT_ASSERT(ret == UDATA_SUCCES);
|
||||
}
|
||||
|
||||
static void test_udata_unsubscribe_case(void)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = uData_unsubscribe(UDATA_SERVICE_BARO);
|
||||
YUNIT_ASSERT(ret == UDATA_SUCCES);
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_udata_testcases[] = {
|
||||
{ "subscribe", test_udata_subscribe_case },
|
||||
{ "unsubscribe", test_udata_unsubscribe_case },
|
||||
//{ "get list", test_udata_getlist_case },
|
||||
//{ "open", test_udata_open_case},
|
||||
//{ "close", test_udata_close_case},
|
||||
//{ "ioctl", test_udata_ioctl_case},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "uData", init, cleanup, setup, teardown, aos_udata_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_uData(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
|
||||
AOS_TESTCASE(test_uData);
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := uData_test
|
||||
|
||||
$(NAME)_COMPONENTS += framework.common uData
|
||||
|
||||
$(NAME)_SOURCES += uData_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
src = Split('''
|
||||
wifi_hal_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('wifi_hal_test', src)
|
||||
259
Living_SDK/test/testcase/framework/wifi_hal_test/wifi_hal_test.c
Normal file
259
Living_SDK/test/testcase/framework/wifi_hal_test/wifi_hal_test.c
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <aos/aos.h>
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include <hal/soc/soc.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <hal/base.h>
|
||||
#include <hal/wifi.h>
|
||||
|
||||
|
||||
static void test_timer_cb(void *arg)
|
||||
{
|
||||
int *pc = arg;
|
||||
(*pc) ++;
|
||||
}
|
||||
|
||||
static void test_timer_case(void)
|
||||
{
|
||||
int counter = 0, old_counter;
|
||||
timer_dev_t t;
|
||||
|
||||
t.port = 0;
|
||||
t.config.period = 50000; //unit is microsecond
|
||||
|
||||
t.config.reload_mode = TIMER_RELOAD_AUTO;
|
||||
t.config.cb = &test_timer_cb;
|
||||
t.config.arg = &counter;
|
||||
|
||||
hal_timer_init(&t);
|
||||
aos_msleep(1000);
|
||||
YUNIT_ASSERT(counter == 0);
|
||||
|
||||
hal_timer_start(&t);
|
||||
check_cond_wait(counter > 3, 2);
|
||||
|
||||
hal_timer_stop(&t);
|
||||
aos_msleep(1000);
|
||||
|
||||
old_counter = counter;
|
||||
aos_msleep(1000);
|
||||
YUNIT_ASSERT(counter == old_counter);
|
||||
if (counter != old_counter)
|
||||
printf("%s %d %d\n", __func__, counter, old_counter);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t fixmac[6] = {0xd8,0x96,0xe0,0x03,0x04,0x01};
|
||||
|
||||
static int wifi_init(hal_wifi_module_t *m)
|
||||
{
|
||||
printf("wifi init success!!\n");
|
||||
return 0;
|
||||
};
|
||||
|
||||
static void wifi_get_mac_addr(hal_wifi_module_t *m, uint8_t *mac)
|
||||
{
|
||||
(void)m;
|
||||
printf("wifi_get_mac_addr!!\n");
|
||||
memcpy(mac, fixmac, 6);
|
||||
};
|
||||
|
||||
static int wifi_start(hal_wifi_module_t *m, hal_wifi_init_type_t *init_para)
|
||||
{
|
||||
(void)init_para;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wifi_start_adv(hal_wifi_module_t *m, hal_wifi_init_type_adv_t *init_para_adv)
|
||||
{
|
||||
(void)init_para_adv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_ip_stat(hal_wifi_module_t *m, hal_wifi_ip_stat_t *out_net_para, hal_wifi_type_t wifi_type)
|
||||
{
|
||||
(void)wifi_type;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_link_stat(hal_wifi_module_t *m, hal_wifi_link_stat_t *out_stat)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void start_scan(hal_wifi_module_t *m)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void start_scan_adv(hal_wifi_module_t *m)
|
||||
{
|
||||
}
|
||||
|
||||
static int power_off(hal_wifi_module_t *m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int power_on(hal_wifi_module_t *m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int suspend(hal_wifi_module_t *m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int suspend_station(hal_wifi_module_t *m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int suspend_soft_ap(hal_wifi_module_t *m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_channel(hal_wifi_module_t *m, int ch)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void start_monitor(hal_wifi_module_t *m)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void stop_monitor(hal_wifi_module_t *m)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void register_monitor_cb(hal_wifi_module_t *m, monitor_data_cb_t fn)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if (WIFI_CONFIG_SUPPORT_LOWPOWER > 0)
|
||||
static int set_listeninterval(hal_wifi_module_t *m, uint8_t listen_interval)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int enter_powersave(hal_wifi_module_t *m, uint8_t recvDTIMs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int exit_powersave(hal_wifi_module_t *m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static hal_wifi_module_t sim_aos_wifi_module = {
|
||||
.base.name = "sim_aos_wifi_module",
|
||||
.init = wifi_init,
|
||||
.get_mac_addr = wifi_get_mac_addr,
|
||||
.start = wifi_start,
|
||||
.start_adv = wifi_start_adv,
|
||||
.get_ip_stat = get_ip_stat,
|
||||
.get_link_stat = get_link_stat,
|
||||
.start_scan = start_scan,
|
||||
.start_scan_adv = start_scan_adv,
|
||||
.power_off = power_off,
|
||||
.power_on = power_on,
|
||||
.suspend = suspend,
|
||||
.suspend_station = suspend_station,
|
||||
.suspend_soft_ap = suspend_soft_ap,
|
||||
.set_channel = set_channel,
|
||||
.start_monitor = start_monitor,
|
||||
.stop_monitor = stop_monitor,
|
||||
.register_monitor_cb = register_monitor_cb,
|
||||
#if (WIFI_CONFIG_SUPPORT_LOWPOWER > 0)
|
||||
.set_listeninterval = set_listeninterval,
|
||||
.enter_powersave = enter_powersave,
|
||||
.exit_powersave = exit_powersave,
|
||||
#endif
|
||||
};
|
||||
|
||||
static void test_wifi_case(void)
|
||||
{
|
||||
uint8_t mac[6];
|
||||
hal_wifi_module_t *tmp;
|
||||
|
||||
printf("start wifi test case\n");
|
||||
|
||||
tmp = hal_wifi_get_default_module();
|
||||
(void)tmp;
|
||||
|
||||
hal_wifi_register_module(&sim_aos_wifi_module);
|
||||
hal_wifi_init();
|
||||
hal_wifi_get_mac_addr(&sim_aos_wifi_module, mac);
|
||||
hal_wifi_start(&sim_aos_wifi_module, NULL);
|
||||
hal_wifi_start_adv(&sim_aos_wifi_module, NULL);
|
||||
hal_wifi_get_ip_stat(&sim_aos_wifi_module, NULL, SOFT_AP);
|
||||
hal_wifi_get_link_stat(&sim_aos_wifi_module, NULL);
|
||||
hal_wifi_start_scan(&sim_aos_wifi_module);
|
||||
hal_wifi_start_scan_adv(&sim_aos_wifi_module);
|
||||
hal_wifi_power_off(&sim_aos_wifi_module);
|
||||
hal_wifi_power_on(&sim_aos_wifi_module);
|
||||
hal_wifi_suspend(&sim_aos_wifi_module);
|
||||
hal_wifi_suspend_station(&sim_aos_wifi_module);
|
||||
hal_wifi_suspend_soft_ap(&sim_aos_wifi_module);
|
||||
hal_wifi_set_channel(&sim_aos_wifi_module, 0);
|
||||
hal_wifi_start_wifi_monitor(&sim_aos_wifi_module);
|
||||
hal_wifi_stop_wifi_monitor(&sim_aos_wifi_module);
|
||||
hal_wifi_register_monitor_cb(&sim_aos_wifi_module, NULL);
|
||||
printf("first mac addr is 0x%x\n", mac[0]);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_wifi_hal_testcases[] = {
|
||||
{ "timer", test_timer_case },
|
||||
{ "wifi", test_wifi_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "hal", init, cleanup, setup, teardown, aos_wifi_hal_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_wifi_hal(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_wifi_hal);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := wifi_hal_test
|
||||
|
||||
$(NAME)_COMPONENTS +=
|
||||
|
||||
$(NAME)_SOURCES += wifi_hal_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
130
Living_SDK/test/testcase/http_test/http.c
Normal file
130
Living_SDK/test/testcase/http_test/http.c
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2020 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "iot_export.h"
|
||||
#include "utils_httpc.h"
|
||||
|
||||
#include "http.h"
|
||||
#include "yunit.h"
|
||||
|
||||
static char request_buf[MAX_BUF_LEN];
|
||||
static char response_buf[MAX_BUF_LEN];
|
||||
|
||||
static void *http_handle = NULL;
|
||||
|
||||
static int http_do_request(iotx_device_info_t *pdev, void *handle)
|
||||
{
|
||||
int ret = -1;
|
||||
char *path = NULL;
|
||||
iotx_http_message_param_t msg;
|
||||
|
||||
if (NULL == pdev || NULL == handle)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
path = (char *)HAL_Malloc(IOTX_URI_MAX_LEN + 1);
|
||||
if (path == NULL)
|
||||
{
|
||||
YUNIT_ASSERT_MSG((path != NULL), "no mem")
|
||||
return FAIL_RETURN;
|
||||
}
|
||||
|
||||
HAL_Snprintf(request_buf, MAX_BUF_LEN, "{\"name\":\"hello world\"}");
|
||||
memset(response_buf, 0x00, MAX_BUF_LEN);
|
||||
HAL_Snprintf(path, IOTX_URI_MAX_LEN, "/topic/%s/%s/data",
|
||||
pdev->product_key, pdev->device_name);
|
||||
|
||||
msg.request_payload = request_buf;
|
||||
msg.response_payload = response_buf;
|
||||
msg.timeout_ms = DEFAULT_TIMEOUT_MS;
|
||||
msg.request_payload_len = strlen(msg.request_payload) + 1;
|
||||
msg.response_payload_len = MAX_BUF_LEN;
|
||||
msg.topic_path = path;
|
||||
|
||||
ret = IOT_HTTP_SendMessage(handle, &msg);
|
||||
if (path)
|
||||
{
|
||||
HAL_Free(path);
|
||||
}
|
||||
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
iotx_device_info_t device_info;
|
||||
iotx_http_param_t http_param;
|
||||
|
||||
memset(&http_param, 0, sizeof(http_param));
|
||||
|
||||
iotx_device_info_get(&device_info);
|
||||
|
||||
http_param.device_info = &device_info;
|
||||
http_param.timeout_ms = DEFAULT_TIMEOUT_MS;
|
||||
|
||||
http_handle = IOT_HTTP_Init(&http_param);
|
||||
YUNIT_ASSERT(http_handle != NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
IOT_HTTP_Disconnect(http_handle);
|
||||
IOT_HTTP_DeInit(&http_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void http_auth_case(void)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
ret = IOT_HTTP_DeviceNameAuth(http_handle);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
static void http_request_case(void)
|
||||
{
|
||||
int ret = -1;
|
||||
iotx_device_info_t device_info;
|
||||
|
||||
memset(&device_info, 0, sizeof(iotx_device_info_t));
|
||||
|
||||
iotx_device_info_get(&device_info);
|
||||
|
||||
ret = http_do_request(&device_info, http_handle);
|
||||
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
static yunit_test_case_t http_testcases[] = {
|
||||
{"auth", http_auth_case},
|
||||
{"request", http_request_case},
|
||||
YUNIT_TEST_CASE_NULL};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{"http", init, cleanup, setup, teardown, http_testcases},
|
||||
YUNIT_TEST_SUITE_NULL};
|
||||
|
||||
void test_http(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_http);
|
||||
11
Living_SDK/test/testcase/http_test/http.h
Normal file
11
Living_SDK/test/testcase/http_test/http.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef __HTTP_H__
|
||||
#define __HTTP_H__
|
||||
|
||||
#define MAX_BUF_LEN 256
|
||||
#define DEFAULT_TIMEOUT_MS 5000
|
||||
|
||||
#define HTTP_LOG_TAG "[HTTP]:"
|
||||
|
||||
extern int ct_http(const char *host, uint16_t port, int count);
|
||||
|
||||
#endif
|
||||
9
Living_SDK/test/testcase/http_test/http_test.mk
Normal file
9
Living_SDK/test/testcase/http_test/http_test.mk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
NAME := http_test
|
||||
|
||||
$(NAME)_SOURCES := http.c
|
||||
|
||||
#Add this MACRO for http testing
|
||||
GLOBAL_DEFINES += MBEDTLS_SSL_MAX_CONTENT_LEN=8192
|
||||
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror -Wno-unused-varible
|
||||
29
Living_SDK/test/testcase/include/yts.h
Normal file
29
Living_SDK/test/testcase/include/yts.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef YTS_H
|
||||
#define YTS_H
|
||||
|
||||
void osupdate_online_test_run(char *bin, int id2);
|
||||
|
||||
#define check_cond_wait(cond, seconds) do { \
|
||||
unsigned int i; \
|
||||
for (i=0;i<(unsigned int)seconds && !(cond);i++) { \
|
||||
aos_msleep(1000); \
|
||||
} \
|
||||
YUNIT_ASSERT(cond); \
|
||||
} while(0);
|
||||
|
||||
#define run_times(func, times) do { \
|
||||
int i; \
|
||||
for (i=0;i<times;i++, func); \
|
||||
} while(0);
|
||||
|
||||
extern int yts_get_args(const char ***argv);
|
||||
extern void yts_run(int argc, char **argv);
|
||||
extern int yts_run_suite_by_name(const char *suite_name, int test_case_times);
|
||||
extern void ct_yts_run_all(void);
|
||||
|
||||
#endif /* YTS_H */
|
||||
|
||||
381
Living_SDK/test/testcase/kernel/deviceIO_test/deviceIO_test.c
Normal file
381
Living_SDK/test/testcase/kernel/deviceIO_test/deviceIO_test.c
Normal file
|
|
@ -0,0 +1,381 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/aos.h>
|
||||
#include <aos/network.h>
|
||||
|
||||
#include "vfs.h"
|
||||
#include "vfs_inode.h"
|
||||
#include "vfs_register.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
#include "yunit.h"
|
||||
|
||||
#include "device/vfs_adc.h"
|
||||
#include "hal/soc/adc.h"
|
||||
#include "device/vfs_device.h"
|
||||
#include "hal/soc/soc.h"
|
||||
|
||||
uint32_t adc_init_count = 0;
|
||||
uint32_t adc_finalize_count = 0;
|
||||
|
||||
adc_dev_t adc_dev_test =
|
||||
{
|
||||
.port = 0xCD,
|
||||
.config.sampling_cycle = 0x12345678
|
||||
};
|
||||
|
||||
gpio_dev_t gpio_dev_test =
|
||||
{
|
||||
.port = 0x11,
|
||||
.config = INPUT_PULL_UP
|
||||
};
|
||||
|
||||
i2c_dev_t i2c_dev_test =
|
||||
{
|
||||
.port = 0x22,
|
||||
.config.address_width = 0x11111111,
|
||||
.config.freq = 0x22222222,
|
||||
.config.mode = 0x33,
|
||||
.config.dev_addr = 0x1234
|
||||
};
|
||||
|
||||
rtc_dev_t rtc_dev_test =
|
||||
{
|
||||
.port = 0x33
|
||||
};
|
||||
|
||||
char* adc_path = "/dev/adc/";
|
||||
char* gpio_path = "/dev/gpio/";
|
||||
char* i2c_path = "/dev/i2c/";
|
||||
char* rtc_path = "/dev/rtc/";
|
||||
|
||||
int32_t hal_adc_init(adc_dev_t *adc)
|
||||
{
|
||||
adc_dev_t *adc_dev = adc;
|
||||
int32_t ret = -1;
|
||||
|
||||
adc_init_count++;
|
||||
|
||||
if (adc == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((adc_dev->port == 0xCD)
|
||||
&&(adc_dev->config.sampling_cycle == 0x12345678)) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_adc_value_get(adc_dev_t *adc, void *output, uint32_t timeout)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
int32_t *pData = (int32_t *)output;
|
||||
|
||||
if ((adc == NULL)||(output == NULL)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pData[0] = 0x87654321;
|
||||
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_adc_finalize(adc_dev_t *adc)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
|
||||
adc_finalize_count++;
|
||||
|
||||
if (adc == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_gpio_init(gpio_dev_t *gpio)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if(gpio->port == 0x11)
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_gpio_output_high(gpio_dev_t *gpio)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t hal_gpio_output_low(gpio_dev_t *gpio)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int32_t hal_gpio_output_toggle(gpio_dev_t *gpio)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
int32_t hal_gpio_input_get(gpio_dev_t *gpio, uint32_t *value)
|
||||
{
|
||||
*value = 0x12345678;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t hal_gpio_finalize(gpio_dev_t *gpio)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t hal_i2c_init(i2c_dev_t *i2c)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if((i2c->port == 0x22) && (i2c->config.dev_addr == 0x1234)
|
||||
&& (i2c->config.address_width == 0x11111111)
|
||||
&& (i2c->config.mode == 0x33))
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_i2c_master_send(i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data,
|
||||
uint16_t size, uint32_t timeout)
|
||||
{
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
if(data[i] != i) {
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_i2c_master_recv(i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data,
|
||||
uint16_t size, uint32_t timeout)
|
||||
{
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_i2c_finalize(i2c_dev_t *i2c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t hal_rtc_init(rtc_dev_t *rtc)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if(rtc->port == 0x33)
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time)
|
||||
{
|
||||
time->year = 11;
|
||||
time->month = 22;
|
||||
time->date = 33;
|
||||
time->weekday = 44;
|
||||
time->hr = 55;
|
||||
time->min = 66;
|
||||
time->sec = 77;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if((time->year == 11) && (time->month == 22) && (time->date == 33)
|
||||
&& (time->weekday == 44) && (time->hr == 55) && (time->min == 66)
|
||||
&& (time->sec == 77)){
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t hal_rtc_finalize(rtc_dev_t *rtc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_vfs_device_io_case(void)
|
||||
{
|
||||
int fd1 = 0;
|
||||
int fd2 = 0;
|
||||
int fd_gpio = 0;
|
||||
int fd_i2c = 0;
|
||||
int fd_rtc = 0;
|
||||
int i = 0;
|
||||
int ret = -1;
|
||||
int res = 0;
|
||||
uint32_t gpio_value = 0;
|
||||
int32_t adc_val = 0;
|
||||
uint8_t write_buf[10] = {0,1,2,3,4,5,6,7,8,9};
|
||||
uint8_t read_buf[10] = {0};
|
||||
rtc_time_t rtc_time;
|
||||
|
||||
memset(&rtc_time, 0, sizeof(rtc_time));
|
||||
|
||||
ret = aos_register_driver(adc_path, &adc_ops, &adc_dev_test);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
/* The device can be opened several times, but is only initialized when it is first opened */
|
||||
fd1 = aos_open(adc_path,0);
|
||||
YUNIT_ASSERT((fd1 > 64)&&(adc_init_count == 1));
|
||||
|
||||
fd2 = aos_open(adc_path,0);
|
||||
YUNIT_ASSERT((fd2 > 64)&&(adc_init_count == 1));
|
||||
|
||||
ret = aos_read(fd1, &adc_val, sizeof(adc_val));
|
||||
YUNIT_ASSERT((ret == 4)&&(adc_val == 0x87654321));
|
||||
|
||||
ret = aos_read(fd2, &adc_val, sizeof(adc_val));
|
||||
YUNIT_ASSERT((ret == 4)&&(adc_val == 0x87654321));
|
||||
|
||||
/* When the device is opened many times, the hardware is only shut down at the last close */
|
||||
ret = aos_close(fd1);
|
||||
YUNIT_ASSERT((ret == 0)&&(adc_finalize_count == 0));
|
||||
|
||||
ret = aos_close(fd2);
|
||||
YUNIT_ASSERT((ret == 0)&&(adc_finalize_count == 1));
|
||||
|
||||
/* example of gpio */
|
||||
ret = aos_register_driver(gpio_path, &gpio_ops, &gpio_dev_test);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
fd_gpio = aos_open(gpio_path,0);
|
||||
YUNIT_ASSERT(fd1 > 64);
|
||||
|
||||
/* read data from gpio */
|
||||
ret = aos_read(fd_gpio, &gpio_value, sizeof(gpio_value));
|
||||
YUNIT_ASSERT((ret == sizeof(gpio_value))&&(gpio_value == 0x12345678));
|
||||
|
||||
/* output high */
|
||||
ret = aos_ioctl(fd_gpio, IOCTL_GPIO_OUTPUT_HIGHT, 0);
|
||||
YUNIT_ASSERT(ret == 1);
|
||||
|
||||
/* output low */
|
||||
ret = aos_ioctl(fd_gpio, IOCTL_GPIO_OUTPUT_LOW, 0);
|
||||
YUNIT_ASSERT(ret == 2);
|
||||
|
||||
/* toggle output */
|
||||
ret = aos_ioctl(fd_gpio, IOCTL_GPIO_OUTPUT_TOGGLE, 0);
|
||||
YUNIT_ASSERT(ret == 3);
|
||||
|
||||
ret = aos_close(fd_gpio);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
/* example of i2c */
|
||||
ret = aos_register_driver(i2c_path, &i2c_ops, &i2c_dev_test);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
fd_i2c = aos_open(i2c_path,0);
|
||||
YUNIT_ASSERT(fd_i2c > 64);
|
||||
|
||||
ret = aos_read(fd_i2c, read_buf, sizeof(read_buf));
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
if(read_buf[i] != i) {
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
YUNIT_ASSERT((ret == sizeof(read_buf))&&(res == 0));
|
||||
|
||||
ret = aos_write(fd_i2c, write_buf, sizeof(read_buf));
|
||||
YUNIT_ASSERT(ret == sizeof(read_buf));
|
||||
|
||||
ret = aos_close(fd_i2c);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
/* example of rtc */
|
||||
ret = aos_register_driver(rtc_path, &rtc_ops, &rtc_dev_test);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
fd_rtc = aos_open(rtc_path,0);
|
||||
YUNIT_ASSERT(fd_rtc > 64);
|
||||
|
||||
ret = aos_read(fd_rtc, &rtc_time, sizeof(rtc_time));
|
||||
|
||||
if((rtc_time.year == 11) && (rtc_time.month == 22) && (rtc_time.date == 33)
|
||||
&& (rtc_time.weekday == 44) && (rtc_time.hr == 55) && (rtc_time.min == 66)
|
||||
&& (rtc_time.sec == 77)){
|
||||
res = 2;
|
||||
}
|
||||
YUNIT_ASSERT((ret == sizeof(rtc_time))&&(res == 2));
|
||||
|
||||
ret = aos_write(fd_rtc, &rtc_time, sizeof(rtc_time));
|
||||
YUNIT_ASSERT(ret == sizeof(rtc_time));
|
||||
|
||||
ret = aos_close(fd_rtc);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_deviceIO_testcases[] = {
|
||||
{ "device_io", test_vfs_device_io_case},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "device_io", init, cleanup, setup, teardown, aos_deviceIO_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_deviceIO(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_deviceIO);
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
NAME := deviceIO_test
|
||||
|
||||
$(NAME)_COMPONENTS += vfs
|
||||
|
||||
$(NAME)_SOURCES += deviceIO_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
10
Living_SDK/test/testcase/kernel/deviceIO_test/ucube.py
Normal file
10
Living_SDK/test/testcase/kernel/deviceIO_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
deviceIO_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('deviceIO_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/vfs')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
162
Living_SDK/test/testcase/kernel/modules/fatfs_test/fatfs_test.c
Normal file
162
Living_SDK/test/testcase/kernel/modules/fatfs_test/fatfs_test.c
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <fatfs_diskio.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <vfs_register.h>
|
||||
#include <aos/kernel.h>
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
|
||||
#include "fatfs.h"
|
||||
|
||||
static const char *g_string = "Fatfs test string.";
|
||||
static const char *g_filepath = "/sdcard/test.txt";
|
||||
static const char *g_dirpath = "/sdcard/testDir";
|
||||
static const char *g_dirtest_1 = "/sdcard/testDir/test_1.txt";
|
||||
static const char *g_dirtest_2 = "/sdcard/testDir/test_2.txt";
|
||||
static const char *g_dirtest_3 = "/sdcard/testDir/test_3.txt";
|
||||
static const char *g_new_filepath = "/sdcard/testDir/newname.txt";
|
||||
|
||||
static void test_fatfs_case(void)
|
||||
{
|
||||
int ret, fd;
|
||||
char readBuffer[32];
|
||||
|
||||
/* Fatfs write test */
|
||||
fd = aos_open(g_filepath, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
|
||||
if (fd > 0) {
|
||||
ret = aos_write(fd, g_string, strlen(g_string));
|
||||
YUNIT_ASSERT(ret > 0);
|
||||
ret = aos_sync(fd);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
aos_close(fd);
|
||||
}
|
||||
|
||||
/* Fatfs read test */
|
||||
fd = aos_open(g_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0) {
|
||||
ret = aos_read(fd, readBuffer, sizeof(readBuffer));
|
||||
YUNIT_ASSERT(ret > 0);
|
||||
|
||||
ret = memcmp(readBuffer, g_string, strlen(g_string));
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
aos_close(fd);
|
||||
}
|
||||
|
||||
/* Fatfs mkdir test */
|
||||
aos_dir_t *dp = (aos_dir_t *)aos_opendir(g_dirpath);
|
||||
if (!dp) {
|
||||
ret = aos_mkdir(g_dirpath);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
} else {
|
||||
ret = aos_closedir(dp);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
/* Fatfs readdir test */
|
||||
fd = aos_open(g_dirtest_1, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
fd = aos_open(g_dirtest_2, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
fd = aos_open(g_dirtest_3, O_RDWR | O_CREAT | O_TRUNC);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
dp = (aos_dir_t *)aos_opendir(g_dirpath);
|
||||
YUNIT_ASSERT(dp != NULL);
|
||||
|
||||
if (dp) {
|
||||
aos_dirent_t *out_dirent;
|
||||
while(1) {
|
||||
out_dirent = (aos_dirent_t *)aos_readdir(dp);
|
||||
if (out_dirent == NULL)
|
||||
break;
|
||||
|
||||
printf("file name is %s\n", out_dirent->d_name);
|
||||
}
|
||||
}
|
||||
aos_closedir(dp);
|
||||
|
||||
/* Fatfs rename test */
|
||||
ret = aos_rename(g_filepath, g_new_filepath);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
fd = aos_open(g_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd < 0);
|
||||
if (fd >= 0)
|
||||
aos_close(fd);
|
||||
|
||||
fd = aos_open(g_new_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd > 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
|
||||
/* Fatfs unlink test */
|
||||
ret = aos_unlink(g_new_filepath);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
fd = aos_open(g_new_filepath, O_RDONLY);
|
||||
YUNIT_ASSERT(fd < 0);
|
||||
if (fd > 0)
|
||||
aos_close(fd);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = fatfs_register();
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
int ret = fatfs_unregister();
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_fatfs_testcases[] = {
|
||||
{ "fatfs_test", test_fatfs_case},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "fatfs", init, cleanup, setup, teardown, aos_fatfs_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_fatfs(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_fatfs);
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := fatfs_test
|
||||
|
||||
$(NAME)_COMPONENTS += modules.fs.fatfs
|
||||
|
||||
$(NAME)_SOURCES += fatfs_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
10
Living_SDK/test/testcase/kernel/modules/fatfs_test/ucube.py
Normal file
10
Living_SDK/test/testcase/kernel/modules/fatfs_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
fatfs_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('fatfs_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/modules/fs/fatfs')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
285
Living_SDK/test/testcase/kernel/modules/kv_test/kv_test.c
Normal file
285
Living_SDK/test/testcase/kernel/modules/kv_test/kv_test.c
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <aos/aos.h>
|
||||
#include <hal/soc/soc.h>
|
||||
#include "kvmgr.h"
|
||||
|
||||
static char *g_key_1 = "key_1";
|
||||
static char *g_key_2 = "key_2";
|
||||
static char *g_key_3 = "key_3";
|
||||
static char *g_key_4 = "key_4";
|
||||
|
||||
static char *g_val_1 = "val_1";
|
||||
static char *g_val_2 = "val_2";
|
||||
static char *g_val_3 = "val_3";
|
||||
static char *g_val_4 = "val_4";
|
||||
|
||||
static char *g_key_update = "test_1000";
|
||||
static char *g_val_update = "val_19";
|
||||
static char *g_val_update_2 = "val_30";
|
||||
|
||||
static void test_kv_add(void)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = aos_kv_set(g_key_1, g_val_1, strlen(g_val_1),1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = aos_kv_set(g_key_2, g_val_2, strlen(g_val_2),1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = aos_kv_set(g_key_3, g_val_3, strlen(g_val_3),1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = aos_kv_set(g_key_4, g_val_4, strlen(g_val_4),1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_kv_find(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[10] = {0};
|
||||
int len = sizeof(buf);
|
||||
|
||||
ret = aos_kv_get(g_key_1,buf,&len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
YUNIT_ASSERT(len == strlen(g_val_1));
|
||||
|
||||
ret = aos_kv_get(g_key_2,buf,&len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
YUNIT_ASSERT(len == strlen(g_val_2));
|
||||
|
||||
ret = aos_kv_get(g_key_3,buf,&len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
YUNIT_ASSERT(len == strlen(g_val_3));
|
||||
|
||||
ret = aos_kv_get(g_key_4,buf,&len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
YUNIT_ASSERT(len == strlen(g_val_4));
|
||||
}
|
||||
|
||||
static void test_kv_del(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[10] = {0};
|
||||
int len = sizeof(buf);
|
||||
|
||||
ret = aos_kv_del(g_key_1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = aos_kv_del(g_key_2);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = aos_kv_del(g_key_3);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = aos_kv_get(g_key_3,buf,&len);
|
||||
YUNIT_ASSERT(0 != ret);
|
||||
YUNIT_ASSERT(len != strlen(g_val_3)+1);
|
||||
}
|
||||
|
||||
#ifdef YTS_LINUX
|
||||
static void test_kv_loop(void)
|
||||
{
|
||||
int i, j, count, ret = 0;
|
||||
char key[10] = {0};
|
||||
char val[10] = {0};
|
||||
int len = sizeof(val);
|
||||
|
||||
count = 0;
|
||||
for (j = 0; j < 10; j++) {
|
||||
for (i = 0; i < 100; i++) {
|
||||
snprintf(key, sizeof(key), "test_%d", i);
|
||||
snprintf(val, sizeof(val), "val_%d", i);
|
||||
ret = aos_kv_set(key, val, strlen(val),1);
|
||||
if (ret != 0)
|
||||
count++;
|
||||
memset(key, 0, sizeof(key));
|
||||
memset(val, 0, sizeof(val));
|
||||
}
|
||||
|
||||
ret = aos_kv_set(g_key_update, g_val_update, strlen(g_val_update), 1);
|
||||
if (ret != 0)
|
||||
count++;
|
||||
|
||||
ret = aos_kv_set(g_key_update, g_val_update_2, strlen(g_val_update_2), 1);
|
||||
if (ret != 0)
|
||||
count++;
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
len = sizeof(val);
|
||||
snprintf(key, sizeof(key), "test_%d", i);
|
||||
ret = aos_kv_get(key, val, &len);
|
||||
if ((ret != 0) || (strlen(val) != len))
|
||||
count++;
|
||||
memset(key, 0, sizeof(key));
|
||||
memset(val, 0, sizeof(val));
|
||||
}
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
snprintf(key, sizeof(key), "test_%d", i);
|
||||
ret = aos_kv_del(key);
|
||||
if (ret != 0)
|
||||
count++;
|
||||
memset(key, 0, sizeof(key));
|
||||
}
|
||||
|
||||
ret = aos_kv_get(g_key_update, val, &len);
|
||||
if ((ret != 0) || (strlen(g_val_update_2) != len))
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_kv_error_cycle(void)
|
||||
{
|
||||
aos_kv_init();
|
||||
test_kv_loop();
|
||||
aos_kv_deinit();
|
||||
}
|
||||
|
||||
|
||||
/* The physical parition for key-value store */
|
||||
#ifndef CONFIG_AOS_KV_PTN
|
||||
#define KV_TEST_PTN 6
|
||||
#else
|
||||
#define KV_TEST_PTN CONFIG_AOS_KV_PTN
|
||||
#endif
|
||||
|
||||
static void test_kv_error(void)
|
||||
{
|
||||
int i, blk_size = 4096;
|
||||
int blk_nums = KV_TOTAL_SIZE / blk_size;
|
||||
uint32_t offset = 0;
|
||||
char *buf;
|
||||
|
||||
aos_kv_deinit();
|
||||
buf = (char *)aos_malloc(blk_size);
|
||||
if (!buf) {
|
||||
YUNIT_FAIL("malloc failure");
|
||||
return;
|
||||
}
|
||||
|
||||
/* case situation : all partition filled by zero */
|
||||
memset(buf, 0, blk_size);
|
||||
for (i = 0; i < blk_nums; i++) {
|
||||
offset = i * blk_size;
|
||||
hal_flash_erase(KV_TEST_PTN, offset, blk_size);
|
||||
hal_flash_write(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
}
|
||||
test_kv_error_cycle();
|
||||
|
||||
/* case situation : block header state is error */
|
||||
buf[0] = 'K';
|
||||
offset = 0;
|
||||
hal_flash_erase(KV_TEST_PTN, offset, blk_size);
|
||||
hal_flash_write(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
test_kv_error_cycle();
|
||||
|
||||
/* case situation : block header is normal, but others is filled by 0 */
|
||||
buf[0] = 'K';
|
||||
buf[1] = 0xCC;
|
||||
for (i = 0; i < blk_nums; i++) {
|
||||
offset = i * blk_size;
|
||||
hal_flash_erase(KV_TEST_PTN, offset, blk_size);
|
||||
hal_flash_write(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
}
|
||||
test_kv_error_cycle();
|
||||
|
||||
/* case situation : one middle block is abnormal, and other block is clean */
|
||||
memset(buf, -1, blk_size);
|
||||
buf[0] = 'K';
|
||||
buf[1] = 0xEE;
|
||||
for (i = 0; i < blk_nums; i++) {
|
||||
offset = i * blk_size;
|
||||
hal_flash_erase(KV_TEST_PTN, offset, blk_size);
|
||||
hal_flash_write(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
}
|
||||
buf[1] = 0;
|
||||
offset = blk_size;
|
||||
hal_flash_erase(KV_TEST_PTN, offset, blk_size);
|
||||
hal_flash_write(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
test_kv_error_cycle();
|
||||
|
||||
/* case situation : one block is clean, one block is dirty, but header means clean */
|
||||
memset(buf, -1, blk_size);
|
||||
buf[0] = 'K';
|
||||
buf[1] = 0xEE;
|
||||
offset = 0;
|
||||
hal_flash_erase(KV_TEST_PTN, offset, blk_size);
|
||||
hal_flash_write(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
|
||||
memset(buf+2, 0, 100);
|
||||
offset = blk_size;
|
||||
hal_flash_erase(KV_TEST_PTN, offset, blk_size);
|
||||
hal_flash_write(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
|
||||
aos_kv_init();
|
||||
memset(buf, 0, blk_size);
|
||||
offset = blk_size;
|
||||
hal_flash_read(KV_TEST_PTN, &offset, buf, blk_size);
|
||||
YUNIT_ASSERT(buf[1] == 0x44);
|
||||
aos_kv_deinit();
|
||||
|
||||
|
||||
if(buf)
|
||||
aos_free(buf);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = aos_kv_init();
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
int ret = aos_kv_init();
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_kv_testcases[] = {
|
||||
{ "kv_add", test_kv_add },
|
||||
{ "kv_find", test_kv_find },
|
||||
{ "kv_del", test_kv_del },
|
||||
#ifdef YTS_LINUX
|
||||
{ "kv_loop", test_kv_loop},
|
||||
{ "kv_error", test_kv_error},
|
||||
#endif
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "kv", init, cleanup, setup, teardown, aos_kv_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_kv(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_kv);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := kv_test
|
||||
|
||||
$(NAME)_COMPONENTS += modules.fs.kv
|
||||
|
||||
$(NAME)_SOURCES += kv_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
10
Living_SDK/test/testcase/kernel/modules/kv_test/ucube.py
Normal file
10
Living_SDK/test/testcase/kernel/modules/kv_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
kv_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('kv_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/modules/fs/kv')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
155
Living_SDK/test/testcase/kernel/rhino_test/arch/linux/port_test.c
Executable file
155
Living_SDK/test/testcase/kernel/rhino_test/arch/linux/port_test.c
Executable file
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <k_api.h>
|
||||
#include <cpu_event.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "yunit.h"
|
||||
|
||||
#define TID ((long int)syscall(SYS_gettid))
|
||||
|
||||
static cpu_event_t test_cpu_event;
|
||||
static const char *test_msg = "test linuxhost port";
|
||||
|
||||
static ksem_t sem;
|
||||
static pthread_t test_thread;
|
||||
static sem_t pthread_sem;
|
||||
static long int main_tid;
|
||||
static int test_done;
|
||||
|
||||
static void test_event_handler(const void *arg)
|
||||
{
|
||||
YUNIT_ASSERT(arg == test_msg);
|
||||
|
||||
krhino_sem_give(&sem);
|
||||
|
||||
sigset_t sigblocked;
|
||||
sigprocmask(SIG_BLOCK, NULL, &sigblocked);
|
||||
YUNIT_ASSERT(0 == sigismember(&sigblocked, SIGUSR2));
|
||||
YUNIT_ASSERT(0 == sigismember(&sigblocked, SIGALRM));
|
||||
}
|
||||
|
||||
static void test_cpu_event_case(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
test_cpu_event.handler = test_event_handler;
|
||||
test_cpu_event.arg = test_msg;
|
||||
|
||||
ret = cpu_notify_event(&test_cpu_event);
|
||||
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
krhino_sem_take(&sem, RHINO_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
static void test_event_pthread_handler(const void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
YUNIT_ASSERT(arg == &main_tid);
|
||||
|
||||
ret = sem_post(&pthread_sem);
|
||||
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
sigset_t sigblocked;
|
||||
sigprocmask(SIG_BLOCK, NULL, &sigblocked);
|
||||
YUNIT_ASSERT(0 == sigismember(&sigblocked, SIGUSR2));
|
||||
YUNIT_ASSERT(0 == sigismember(&sigblocked, SIGALRM));
|
||||
}
|
||||
|
||||
static void *test_cpu_event_pthread_proc(void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
test_cpu_event.handler = test_event_pthread_handler;
|
||||
test_cpu_event.arg = arg;
|
||||
|
||||
ret = cpu_notify_event(&test_cpu_event);
|
||||
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
ret = sem_wait(&pthread_sem);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
test_done = 1;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void test_cpu_event_pthread_case(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
main_tid = TID;
|
||||
|
||||
ret = pthread_create(&test_thread, NULL, test_cpu_event_pthread_proc, &main_tid);
|
||||
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
while (!test_done) {
|
||||
krhino_task_sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = krhino_sem_create(&sem, "rhino test port", 0);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = sem_init(&pthread_sem, 0, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = krhino_sem_del(&sem);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = sem_destroy(&pthread_sem);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static yunit_test_case_t rhino_port_testcases[] = {
|
||||
{ "Testing cpu_event_case:", test_cpu_event_case },
|
||||
{ "Testing cpu_event_pthread_case:", test_cpu_event_pthread_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "rhino_port", init, cleanup, setup, teardown, rhino_port_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_rhino_port(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
|
||||
70
Living_SDK/test/testcase/kernel/rhino_test/rhino_test.c
Normal file
70
Living_SDK/test/testcase/kernel/rhino_test/rhino_test.c
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/types.h>
|
||||
|
||||
#include "yunit.h"
|
||||
#include <k_api.h>
|
||||
#include "test_fw.h"
|
||||
|
||||
|
||||
#define RHINO_TEST_TASK_PRI 32
|
||||
|
||||
extern void test_rhino_port(void);
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
test_case_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
test_case_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int item = 0;
|
||||
|
||||
void rhino_ytest_fn(void)
|
||||
{
|
||||
YUNIT_ASSERT(test_case_fail == 0);
|
||||
}
|
||||
|
||||
void test_rhino(void)
|
||||
{
|
||||
uint8_t old_pri;
|
||||
void *suite;
|
||||
|
||||
krhino_task_pri_change(krhino_cur_task_get(), RHINO_TEST_TASK_PRI, &old_pri);
|
||||
|
||||
suite = yunit_add_test_suite("rhino", init, cleanup, setup, teardown);
|
||||
|
||||
for (item = 0;; item++) {
|
||||
if ((test_fw_map[item].name == NULL) || (test_fw_map[item].fn == NULL)) {
|
||||
break;
|
||||
}
|
||||
|
||||
yunit_add_test_case(suite, test_fw_map[item].name, test_fw_map[item].fn);
|
||||
}
|
||||
|
||||
yunit_add_test_case(suite, "rhino test stats", rhino_ytest_fn);
|
||||
|
||||
#ifdef YTS_LINUX
|
||||
test_rhino_port();
|
||||
#endif
|
||||
}
|
||||
AOS_TESTCASE(test_rhino);
|
||||
12
Living_SDK/test/testcase/kernel/rhino_test/rhino_test.mk
Normal file
12
Living_SDK/test/testcase/kernel/rhino_test/rhino_test.mk
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
NAME := rhino_test
|
||||
|
||||
$(NAME)_COMPONENTS += rhino
|
||||
|
||||
$(NAME)_SOURCES += rhino_test.c
|
||||
|
||||
ifneq (,$(findstring linux, $(BUILD_STRING)))
|
||||
$(NAME)_SOURCES += arch/linux/port_test.c
|
||||
endif
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
13
Living_SDK/test/testcase/kernel/rhino_test/ucube.py
Normal file
13
Living_SDK/test/testcase/kernel/rhino_test/ucube.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
src = Split('''
|
||||
rhino_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('rhino_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/rhino')
|
||||
|
||||
if aos_global_config.board == 'linuxhost':
|
||||
component.add_sources('arch/linux/port_test.c')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
10
Living_SDK/test/testcase/kernel/vcall_test/ucube.py
Normal file
10
Living_SDK/test/testcase/kernel/vcall_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
vcall_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('vcall_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/vcall')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
145
Living_SDK/test/testcase/kernel/vcall_test/vcall_test.c
Normal file
145
Living_SDK/test/testcase/kernel/vcall_test/vcall_test.c
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <aos/types.h>
|
||||
#include "mico_rtos.h"
|
||||
#include "mico_rtos_common.h"
|
||||
#include "common.h"
|
||||
#include <k_api.h>
|
||||
|
||||
static mico_thread_t task1;
|
||||
static mico_semaphore_t sem1;
|
||||
static mico_mutex_t mutex1;
|
||||
static mico_queue_t queue1;
|
||||
static mico_timer_t timer1;
|
||||
|
||||
#define MSG_SIZE 50
|
||||
|
||||
static void task1_entry(mico_thread_arg_t arg )
|
||||
{
|
||||
char msg[MSG_SIZE];
|
||||
|
||||
mico_rtos_is_current_thread(&task1);
|
||||
mico_rtos_set_semaphore(&sem1);
|
||||
msg[0] = 0x11;
|
||||
msg[MSG_SIZE - 1] = 0x33;
|
||||
|
||||
mico_rtos_push_to_queue(&queue1, NULL, 0);
|
||||
mico_rtos_push_to_queue(&queue1, msg, 0);
|
||||
|
||||
mico_rtos_delete_thread(&task1);
|
||||
}
|
||||
|
||||
|
||||
static void task2_entry(mico_thread_arg_t arg )
|
||||
{
|
||||
mico_rtos_delete_thread(NULL);
|
||||
}
|
||||
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void timer_callback(void* arg)
|
||||
{
|
||||
YUNIT_ASSERT((int)arg == 0x11);
|
||||
}
|
||||
|
||||
static void test_vcall_case(void)
|
||||
{
|
||||
char pcWriteBuffer[20];
|
||||
char msg[50];
|
||||
|
||||
printf("vcall test\n");
|
||||
mico_rtos_delay_milliseconds(0);
|
||||
mico_rtos_init_semaphore(&sem1, 0);
|
||||
mico_rtos_init_semaphore(NULL, 0);
|
||||
mico_rtos_thread_join(NULL);
|
||||
mico_rtos_get_semaphore(&sem1, 0);
|
||||
|
||||
mico_rtos_delete_thread((mico_thread_t*)&g_idle_task);
|
||||
|
||||
mico_rtos_init_queue(&queue1, NULL, MSG_SIZE, 2);
|
||||
|
||||
mico_rtos_create_thread(&task1, 10, NULL, task1_entry, 4096, 0);
|
||||
mico_rtos_create_thread(&task1, 30, "test", task1_entry, 4096, 0);
|
||||
mico_rtos_create_thread(NULL, 40, "test2", task2_entry, 4096, 0);
|
||||
|
||||
mico_rtos_suspend_all_thread();
|
||||
mico_rtos_resume_all_thread();
|
||||
mico_rtos_is_current_thread(&task1);
|
||||
mico_rtos_thread_force_awake(&task1);
|
||||
|
||||
mico_rtos_get_semaphore(&sem1, MICO_NEVER_TIMEOUT);
|
||||
mico_rtos_deinit_semaphore(&sem1);
|
||||
|
||||
mico_rtos_init_mutex(&mutex1);
|
||||
mico_rtos_lock_mutex(&mutex1);
|
||||
mico_rtos_unlock_mutex(&mutex1);
|
||||
mico_rtos_deinit_mutex(&mutex1);
|
||||
|
||||
mico_rtos_pop_from_queue(&queue1, msg, 10000);
|
||||
|
||||
YUNIT_ASSERT((msg[0] == 0x11) && (msg[MSG_SIZE -1] == 0x33));
|
||||
|
||||
mico_rtos_is_queue_empty(&queue1);
|
||||
mico_rtos_is_queue_full(&queue1);
|
||||
mico_rtos_deinit_queue(&queue1);
|
||||
mico_rtos_get_time();
|
||||
|
||||
mico_rtos_init_timer(&timer1, 50, timer_callback, (void *)0x11);
|
||||
mico_rtos_start_timer(&timer1);
|
||||
mico_rtos_is_timer_running(&timer1);
|
||||
|
||||
mico_rtos_delay_milliseconds(200);
|
||||
mico_rtos_stop_timer(&timer1);
|
||||
mico_rtos_is_timer_running(&timer1);
|
||||
|
||||
mico_rtos_reload_timer(&timer1);
|
||||
mico_rtos_delay_milliseconds(200);
|
||||
mico_rtos_stop_timer(&timer1);
|
||||
|
||||
mico_rtos_deinit_timer(&timer1);
|
||||
|
||||
mico_rtos_print_thread_status(pcWriteBuffer, 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static yunit_test_case_t aos_vcall_testcases[] = {
|
||||
{ "vcall", test_vcall_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "vcall", init, cleanup, setup, teardown, aos_vcall_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_vcall(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_vcall);
|
||||
8
Living_SDK/test/testcase/kernel/vcall_test/vcall_test.mk
Normal file
8
Living_SDK/test/testcase/kernel/vcall_test/vcall_test.mk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := vcall_test
|
||||
|
||||
$(NAME)_COMPONENTS += vcall
|
||||
|
||||
$(NAME)_SOURCES += vcall_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
10
Living_SDK/test/testcase/kernel/vfs_test/ucube.py
Normal file
10
Living_SDK/test/testcase/kernel/vfs_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
vfs_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('vfs_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/vfs')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
291
Living_SDK/test/testcase/kernel/vfs_test/vfs_test.c
Normal file
291
Living_SDK/test/testcase/kernel/vfs_test/vfs_test.c
Normal file
|
|
@ -0,0 +1,291 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/aos.h>
|
||||
#include <aos/network.h>
|
||||
|
||||
#include "vfs.h"
|
||||
#include "vfs_inode.h"
|
||||
#include "vfs_register.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
#include "yunit.h"
|
||||
|
||||
#include "device/vfs_adc.h"
|
||||
#include "hal/soc/adc.h"
|
||||
#include "device/vfs_device.h"
|
||||
#include "hal/soc/soc.h"
|
||||
|
||||
static int test_ioctl(file_t *node, int cmd, unsigned long arg)
|
||||
{
|
||||
return -123;
|
||||
}
|
||||
|
||||
static off_t test_lseek(file_t *fp, off_t off, int whence)
|
||||
{
|
||||
return -123;
|
||||
}
|
||||
|
||||
static int test_sync(file_t *fp)
|
||||
{
|
||||
return -123;
|
||||
}
|
||||
|
||||
static int test_stat(file_t *fp, const char *path, struct stat *st)
|
||||
{
|
||||
return -123;
|
||||
}
|
||||
|
||||
static int test_unlink(file_t *fp, const char *path)
|
||||
{
|
||||
return -123;
|
||||
}
|
||||
|
||||
static int test_rename(file_t *fp, const char *oldpath, const char *newpath)
|
||||
{
|
||||
return -123;
|
||||
}
|
||||
|
||||
static int test_mkdir(file_t *fp, const char *path)
|
||||
{
|
||||
return -123;
|
||||
}
|
||||
|
||||
static void test_aos_vfs_case(void)
|
||||
{
|
||||
int i = 0;
|
||||
int fd = 0;
|
||||
int ret = 0;
|
||||
|
||||
char *names[] = {
|
||||
"/tmp/abcd0",
|
||||
"/tmp/abcd1",
|
||||
"/tmp/abcd2",
|
||||
"/tmp/abcd3",
|
||||
"/tmp/abcd4",
|
||||
"/tmp/abcd5",
|
||||
"/tmp/abcd6",
|
||||
"/tmp/abcd7",
|
||||
"/tmp/abcd8",
|
||||
"/tmp/abcd9",
|
||||
};
|
||||
|
||||
file_ops_t myops = {
|
||||
.open = NULL,
|
||||
.ioctl = test_ioctl,
|
||||
};
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
ret = aos_register_driver(names[i], &myops, NULL);
|
||||
YUNIT_ASSERT(ret == VFS_SUCCESS);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
fd = aos_open(names[i], 0);
|
||||
YUNIT_ASSERT(fd >= 0);
|
||||
YUNIT_ASSERT(-123 == aos_ioctl(fd, 0, 0));
|
||||
|
||||
aos_close(fd);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
fd = aos_open(names[i], 0);
|
||||
YUNIT_ASSERT(fd >= 0);
|
||||
|
||||
aos_close(fd);
|
||||
|
||||
ret = aos_unregister_driver(names[i]);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
#ifdef CONFIG_AOS_YTS_ALL
|
||||
fd = aos_open(names[i], 0);
|
||||
ret = aos_ioctl(fd, 0, 0);
|
||||
YUNIT_ASSERT(-ENOENT == ret);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void test_vfs_fs_case(void)
|
||||
{
|
||||
int fd = 0;
|
||||
int ret = 0;
|
||||
struct stat st;
|
||||
char *names = "/tmp/abcd0";
|
||||
|
||||
fs_ops_t myops = {
|
||||
.open = NULL,
|
||||
.lseek = test_lseek,
|
||||
.sync = test_sync,
|
||||
.stat = test_stat,
|
||||
.unlink = test_unlink,
|
||||
.rename = test_rename,
|
||||
.mkdir = test_mkdir,
|
||||
};
|
||||
|
||||
ret = aos_register_fs(names, &myops, NULL);
|
||||
YUNIT_ASSERT(ret == VFS_SUCCESS);
|
||||
|
||||
fd = aos_open(names, 0);
|
||||
YUNIT_ASSERT(fd >= 0);
|
||||
|
||||
YUNIT_ASSERT(-123 == aos_lseek(fd, 0, 0));
|
||||
YUNIT_ASSERT(-123 == aos_sync(fd));
|
||||
aos_close(fd);
|
||||
|
||||
YUNIT_ASSERT(-123 == aos_stat(names, &st));
|
||||
YUNIT_ASSERT(-123 == aos_unlink(names));
|
||||
YUNIT_ASSERT(-123 == aos_rename(names, names));
|
||||
YUNIT_ASSERT(-123 == aos_mkdir(names));
|
||||
|
||||
ret = aos_unregister_fs(names);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
YUNIT_ASSERT(-ENODEV == aos_stat(names, &st));
|
||||
YUNIT_ASSERT(-ENODEV == aos_unlink(names));
|
||||
YUNIT_ASSERT(-ENODEV == aos_rename(names, names));
|
||||
}
|
||||
|
||||
static int create_socket(int port)
|
||||
{
|
||||
struct sockaddr_in my_addr;
|
||||
int ret = -1;
|
||||
int sockfd;
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sockfd < 0)
|
||||
goto out;
|
||||
|
||||
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int));
|
||||
setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &(int){1}, sizeof(int));
|
||||
|
||||
bzero(&my_addr, sizeof(my_addr));
|
||||
my_addr.sin_family = AF_INET;
|
||||
my_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
my_addr.sin_port = htons(port);
|
||||
ret = bind(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr));
|
||||
if (ret < 0)
|
||||
goto out1;
|
||||
|
||||
return sockfd;
|
||||
out1:
|
||||
close(sockfd);
|
||||
out:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int do_poll(int fd_recv, int timeout)
|
||||
{
|
||||
int ret;
|
||||
struct pollfd pfd;
|
||||
char buf2[256];
|
||||
|
||||
pfd.fd = fd_recv;
|
||||
pfd.events = POLLIN;
|
||||
ret = aos_poll(&pfd, 1, timeout);
|
||||
|
||||
if (ret > 0)
|
||||
ret = recv(fd_recv, buf2, sizeof buf2, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define MAXCNT 100
|
||||
static void send_seq_data(void *arg)
|
||||
{
|
||||
int fd = *(int *)arg;
|
||||
struct sockaddr_in addr;
|
||||
char buf[MAXCNT]={0};
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
addr.sin_port = htons(12346);
|
||||
|
||||
int i;
|
||||
for (i=1;i<MAXCNT;i++) {
|
||||
sendto(fd, buf, i, 0, (struct sockaddr *)&addr, sizeof addr);
|
||||
aos_msleep((rand() % 100) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_aos_poll_case(void)
|
||||
{
|
||||
int fd_send = create_socket(12345);
|
||||
int fd_recv = create_socket(12346);
|
||||
struct sockaddr_in addr;
|
||||
char buf[128], buf2[256];
|
||||
int ret;
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
addr.sin_port = htons(12346);
|
||||
|
||||
memset(buf, 0x5a, sizeof buf);
|
||||
|
||||
ret = sendto(fd_send, buf, sizeof buf, 0, (struct sockaddr *)&addr, sizeof addr);
|
||||
YUNIT_ASSERT(ret == sizeof(buf));
|
||||
|
||||
ret = recv(fd_recv, buf2, sizeof buf2, 0);
|
||||
YUNIT_ASSERT(ret == sizeof(buf));
|
||||
|
||||
ret = sendto(fd_send, buf, sizeof buf, 0, (struct sockaddr *)&addr, sizeof addr);
|
||||
YUNIT_ASSERT(ret == sizeof(buf));
|
||||
|
||||
ret = do_poll(fd_recv, 100);
|
||||
YUNIT_ASSERT(ret == sizeof(buf));
|
||||
|
||||
ret = do_poll(fd_recv, 0);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
aos_task_new("sender", send_seq_data, &fd_send, 4096);
|
||||
|
||||
int i;
|
||||
for (i=1;i<MAXCNT;i++) {
|
||||
ret = do_poll(fd_recv, 5000);
|
||||
YUNIT_ASSERT(ret == i);
|
||||
}
|
||||
|
||||
close(fd_send);
|
||||
close(fd_recv);
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_vfs_testcases[] = {
|
||||
{ "register", test_aos_vfs_case },
|
||||
{ "poll", test_aos_poll_case },
|
||||
{ "fs_register", test_vfs_fs_case},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "vfs", init, cleanup, setup, teardown, aos_vfs_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_vfs(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_vfs);
|
||||
8
Living_SDK/test/testcase/kernel/vfs_test/vfs_test.mk
Normal file
8
Living_SDK/test/testcase/kernel/vfs_test/vfs_test.mk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := vfs_test
|
||||
|
||||
$(NAME)_COMPONENTS += vfs
|
||||
|
||||
$(NAME)_SOURCES += vfs_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
10
Living_SDK/test/testcase/kernel/yloop_test/ucube.py
Normal file
10
Living_SDK/test/testcase/kernel/yloop_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
yloop_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('yloop_test', src)
|
||||
|
||||
component.add_comp_deps('kernel/yloop')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
229
Living_SDK/test/testcase/kernel/yloop_test/yloop_test.c
Normal file
229
Living_SDK/test/testcase/kernel/yloop_test/yloop_test.c
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/aos.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
|
||||
#define TASK1 "task1"
|
||||
#define TASK2 "task2"
|
||||
|
||||
struct task_cookie {
|
||||
aos_loop_t loop;
|
||||
int flag;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
#define T_ACTION2_FLAG 0x01
|
||||
#define T_WORK_DONE_FLAG 0x02
|
||||
#define T_WORK_FLAG 0x04
|
||||
#define T_ACTION_TERM_FLAG 0x08
|
||||
#define T_FILTER_ALL_FLAG 0x10
|
||||
#define T_FILTER_ONE_FLAG 0x20
|
||||
#define T_ALL 0x3f
|
||||
|
||||
#define T_FILTER_FLAG 0x01
|
||||
static uint32_t done_flag;
|
||||
static uint32_t unexpected_flag;
|
||||
|
||||
#define TYPE_TEST_1 (EV_USER + 1)
|
||||
#define TYPE_TEST_2 (EV_USER + 2)
|
||||
|
||||
static void filter_all(input_event_t *event, void *private_data)
|
||||
{
|
||||
done_flag |= T_FILTER_ALL_FLAG;
|
||||
}
|
||||
|
||||
static void filter_one(input_event_t *event, void *private_data)
|
||||
{
|
||||
if (event->type != TYPE_TEST_1)
|
||||
unexpected_flag |= T_FILTER_FLAG;
|
||||
else
|
||||
done_flag |= T_FILTER_ONE_FLAG;
|
||||
}
|
||||
|
||||
static void app_delayed_action(void *arg)
|
||||
{
|
||||
struct task_cookie *cookie = arg;
|
||||
|
||||
YUNIT_ASSERT(strcmp(aos_task_name(), cookie->name) == 0);
|
||||
if (cookie->flag == 0) {
|
||||
aos_post_delayed_action(1000, app_delayed_action, arg);
|
||||
}
|
||||
else if (cookie->flag == 1) {
|
||||
aos_schedule_call(app_delayed_action, arg);
|
||||
}
|
||||
else {
|
||||
aos_loop_exit();
|
||||
}
|
||||
cookie->flag ++;
|
||||
}
|
||||
|
||||
static void app_delayed_action2(void *arg)
|
||||
{
|
||||
struct task_cookie *cookie = arg;
|
||||
|
||||
YUNIT_ASSERT(strcmp(aos_task_name(), cookie->name) == 0);
|
||||
|
||||
done_flag |= T_ACTION2_FLAG;
|
||||
}
|
||||
|
||||
static struct task_cookie cookie1 = {
|
||||
.name = TASK1,
|
||||
};
|
||||
|
||||
static struct task_cookie cookie2 = {
|
||||
.name = TASK2,
|
||||
};
|
||||
|
||||
static void work_done(void *arg)
|
||||
{
|
||||
struct task_cookie *cookie = arg;
|
||||
YUNIT_ASSERT(strcmp(aos_task_name(), cookie->name) == 0);
|
||||
aos_loop_exit();
|
||||
|
||||
done_flag |= T_WORK_DONE_FLAG;
|
||||
}
|
||||
|
||||
static void work_not_exec(void *arg)
|
||||
{
|
||||
YUNIT_ASSERT(0);
|
||||
}
|
||||
|
||||
static void mywork(void *arg)
|
||||
{
|
||||
struct task_cookie *cookie = arg;
|
||||
YUNIT_ASSERT(strcmp(aos_task_name(), cookie->name) != 0);
|
||||
|
||||
done_flag |= T_WORK_FLAG;
|
||||
}
|
||||
|
||||
static void app_main_entry(void *arg)
|
||||
{
|
||||
struct task_cookie *cookie = arg;
|
||||
YUNIT_ASSERT(strcmp(aos_task_name(), cookie->name) == 0);
|
||||
|
||||
cookie->loop = aos_current_loop();
|
||||
|
||||
aos_post_delayed_action(1000, app_delayed_action, cookie);
|
||||
|
||||
aos_loop_run();
|
||||
aos_loop_run();
|
||||
|
||||
YUNIT_ASSERT(aos_loop_schedule_work(0, NULL, NULL, NULL, NULL) == 0);
|
||||
YUNIT_ASSERT(aos_loop_schedule_work(0, mywork, arg, NULL, arg) != 0);
|
||||
YUNIT_ASSERT(aos_loop_schedule_work(1000, mywork, arg, work_done, arg) != 0);
|
||||
|
||||
void *w = aos_loop_schedule_work(500, work_not_exec, NULL, NULL, NULL);
|
||||
YUNIT_ASSERT(w != 0);
|
||||
aos_cancel_work(w, work_not_exec, NULL);
|
||||
aos_cancel_work(NULL, work_not_exec, NULL);
|
||||
|
||||
aos_loop_run();
|
||||
aos_task_exit(0);
|
||||
}
|
||||
|
||||
static void action_after_terminated(void *arg)
|
||||
{
|
||||
printf("%s:%d - %s\n", __func__, __LINE__, aos_task_name());
|
||||
aos_loop_exit();
|
||||
|
||||
done_flag |= T_ACTION_TERM_FLAG;
|
||||
}
|
||||
|
||||
static void app_second_entry(void *arg)
|
||||
{
|
||||
struct task_cookie *cookie = arg;
|
||||
YUNIT_ASSERT(strcmp(aos_task_name(), cookie->name) == 0);
|
||||
int i;
|
||||
|
||||
for (i=0;i<1000;i++) {
|
||||
aos_loop_init();
|
||||
aos_loop_destroy();
|
||||
aos_loop_destroy();
|
||||
}
|
||||
|
||||
aos_loop_init();
|
||||
|
||||
cookie->loop = aos_current_loop();
|
||||
aos_post_delayed_action(1000, app_delayed_action, cookie);
|
||||
|
||||
aos_loop_run();
|
||||
|
||||
YUNIT_ASSERT(cookie1.loop != NULL);
|
||||
aos_loop_schedule_call(cookie1.loop, app_delayed_action2, &cookie1);
|
||||
aos_loop_destroy();
|
||||
|
||||
aos_schedule_call(action_after_terminated, NULL);
|
||||
|
||||
aos_task_exit(0);
|
||||
}
|
||||
|
||||
static void test_simple_case(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = aos_register_event_filter(EV_ALL, NULL, NULL);
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
ret = aos_schedule_call(NULL, NULL);
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
ret = aos_post_delayed_action(1000, NULL, NULL);
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
|
||||
aos_register_event_filter(EV_ALL, filter_all, NULL);
|
||||
aos_register_event_filter(TYPE_TEST_1, filter_one, NULL);
|
||||
|
||||
aos_task_new(TASK1, app_main_entry, &cookie1, 8192);
|
||||
aos_task_new(TASK2, app_second_entry, &cookie2, 8192);
|
||||
|
||||
aos_post_event(TYPE_TEST_1, 0, 0);
|
||||
aos_post_event(TYPE_TEST_2, 0, 0);
|
||||
|
||||
check_cond_wait(done_flag == T_ALL, 10);
|
||||
YUNIT_ASSERT(unexpected_flag == 0);
|
||||
|
||||
YUNIT_ASSERT(0 == aos_unregister_event_filter(EV_ALL, filter_all, NULL));
|
||||
YUNIT_ASSERT(0 == aos_unregister_event_filter(TYPE_TEST_1, filter_one, NULL));
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_yloop_testcases[] = {
|
||||
{ "simple", test_simple_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "yloop", init, cleanup, setup, teardown, aos_yloop_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_yloop(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_yloop);
|
||||
8
Living_SDK/test/testcase/kernel/yloop_test/yloop_test.mk
Normal file
8
Living_SDK/test/testcase/kernel/yloop_test/yloop_test.mk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := yloop_test
|
||||
|
||||
$(NAME)_COMPONENTS += yloop
|
||||
|
||||
$(NAME)_SOURCES += yloop_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
193
Living_SDK/test/testcase/list_test/list_test.c
Normal file
193
Living_SDK/test/testcase/list_test/list_test.c
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <aos/aos.h>
|
||||
|
||||
#include "yunit.h"
|
||||
|
||||
struct test_node {
|
||||
int v;
|
||||
slist_t snext;
|
||||
dlist_t dnext;
|
||||
};
|
||||
|
||||
static int list_num(slist_t *head)
|
||||
{
|
||||
int i = 0, j = 0;
|
||||
slist_t *tmp;
|
||||
struct test_node *node;
|
||||
slist_for_each_entry(head, node, struct test_node, snext) {
|
||||
i ++;
|
||||
}
|
||||
|
||||
slist_for_each_entry_safe(head, tmp, node, struct test_node, snext) {
|
||||
j ++;
|
||||
}
|
||||
|
||||
YUNIT_ASSERT(i == j);
|
||||
return i;
|
||||
}
|
||||
|
||||
static void test_slist_case(void)
|
||||
{
|
||||
AOS_SLIST_HEAD(head);
|
||||
struct test_node *node;
|
||||
int i;
|
||||
|
||||
YUNIT_ASSERT(slist_entry(NULL, struct test_node, snext) == NULL);
|
||||
YUNIT_ASSERT(list_num(&head) == 0);
|
||||
YUNIT_ASSERT(slist_entry_number(&head) == 0);
|
||||
YUNIT_ASSERT(slist_empty(&head));
|
||||
|
||||
for (i=0;i<10;i++) {
|
||||
node = malloc(sizeof(*node));
|
||||
node->v = i;
|
||||
slist_add_tail(&node->snext, &head);
|
||||
}
|
||||
YUNIT_ASSERT(slist_entry_number(&head) == 10);
|
||||
|
||||
i = 0;
|
||||
slist_for_each_entry(&head, node, struct test_node, snext) {
|
||||
YUNIT_ASSERT (node->v == i);
|
||||
|
||||
i ++;
|
||||
}
|
||||
YUNIT_ASSERT(i == 10);
|
||||
|
||||
i = 0;
|
||||
slist_t *tmp;
|
||||
slist_for_each_entry_safe(&head, tmp, node, struct test_node, snext) {
|
||||
YUNIT_ASSERT (node->v == i);
|
||||
|
||||
i ++;
|
||||
}
|
||||
YUNIT_ASSERT(i == 10);
|
||||
|
||||
slist_for_each_entry_safe(&head, tmp, node, struct test_node, snext) {
|
||||
slist_del(&node->snext, &head);
|
||||
free(node);
|
||||
}
|
||||
YUNIT_ASSERT(list_num(&head) == 0);
|
||||
|
||||
for (i=0;i<10;i++) {
|
||||
node = malloc(sizeof(*node));
|
||||
node->v = i;
|
||||
slist_add(&node->snext, &head);
|
||||
}
|
||||
|
||||
i = 9;
|
||||
slist_for_each_entry(&head, node, struct test_node, snext) {
|
||||
YUNIT_ASSERT (node->v == i);
|
||||
|
||||
i --;
|
||||
}
|
||||
YUNIT_ASSERT(i == -1);
|
||||
|
||||
slist_for_each_entry_safe(&head, tmp, node, struct test_node, snext) {
|
||||
slist_del(&node->snext, &head);
|
||||
free(node);
|
||||
}
|
||||
YUNIT_ASSERT(list_num(&head) == 0);
|
||||
}
|
||||
|
||||
static int dlist_num(dlist_t *head)
|
||||
{
|
||||
int n = dlist_entry_number(head);
|
||||
struct test_node *node;
|
||||
dlist_t *tmp;
|
||||
|
||||
int i = 0;
|
||||
dlist_for_each_entry(head, node, struct test_node, dnext) {
|
||||
i ++;
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
dlist_for_each_entry_safe(head, tmp, node, struct test_node, dnext) {
|
||||
j ++;
|
||||
}
|
||||
|
||||
YUNIT_ASSERT(n == i);
|
||||
YUNIT_ASSERT(n == j);
|
||||
return n;
|
||||
}
|
||||
|
||||
static void test_dlist_case(void)
|
||||
{
|
||||
AOS_DLIST_HEAD(dhead);
|
||||
YUNIT_ASSERT(dlist_num(&dhead) == 0);
|
||||
|
||||
struct test_node *node;
|
||||
int i;
|
||||
|
||||
YUNIT_ASSERT(dlist_empty(&dhead));
|
||||
|
||||
for (i=0;i<10;i++) {
|
||||
node = malloc(sizeof(*node));
|
||||
node->v = i;
|
||||
dlist_add_tail(&node->dnext, &dhead);
|
||||
}
|
||||
YUNIT_ASSERT(dlist_num(&dhead) == 10);
|
||||
|
||||
i = 0;
|
||||
dlist_for_each_entry(&dhead, node, struct test_node, dnext) {
|
||||
YUNIT_ASSERT (node->v == i);
|
||||
|
||||
i ++;
|
||||
}
|
||||
YUNIT_ASSERT(i == 10);
|
||||
|
||||
i = 0;
|
||||
dlist_t *tmp;
|
||||
dlist_for_each_entry_safe(&dhead, tmp, node, struct test_node, dnext) {
|
||||
YUNIT_ASSERT (node->v == i);
|
||||
|
||||
i ++;
|
||||
}
|
||||
YUNIT_ASSERT(i == 10);
|
||||
|
||||
dlist_for_each_entry_safe(&dhead, tmp, node, struct test_node, dnext) {
|
||||
dlist_del(&node->dnext);
|
||||
free(node);
|
||||
}
|
||||
YUNIT_ASSERT(dlist_num(&dhead) == 0);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_basic_testcases[] = {
|
||||
{ "slist", test_slist_case },
|
||||
{ "dlist", test_dlist_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "list", init, cleanup, setup, teardown, aos_basic_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_list(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_list);
|
||||
5
Living_SDK/test/testcase/list_test/list_test.mk
Normal file
5
Living_SDK/test/testcase/list_test/list_test.mk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
NAME := list_test
|
||||
|
||||
$(NAME)_SOURCES += list_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
8
Living_SDK/test/testcase/list_test/ucube.py
Normal file
8
Living_SDK/test/testcase/list_test/ucube.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
src = Split('''
|
||||
list_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('list_test', src)
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <stdio.h>
|
||||
#include "ali_crypto.h"
|
||||
#include "aos/aos.h"
|
||||
|
||||
extern void ali_crypto_test_entry(void);
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void) {}
|
||||
|
||||
static void teardown(void) {}
|
||||
|
||||
#if 0
|
||||
static void ali_crypto_test(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
static yunit_test_case_t aos_alicrypto_testcases[] = {
|
||||
//{ "alicrypto_test", ali_crypto_test},
|
||||
//{ "alicrypto_test", ali_crypto_test_entry},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = { { "alicrypto", init, cleanup, setup,
|
||||
teardown, aos_alicrypto_testcases },
|
||||
YUNIT_TEST_SUITE_NULL };
|
||||
|
||||
void test_alicrypto(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_alicrypto);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := alicrypto_test
|
||||
|
||||
$(NAME)_COMPONENTS += alicrypto
|
||||
|
||||
$(NAME)_SOURCES += alicrypto_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
src = Split('''
|
||||
alicrypto_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('alicrypto_test', src)
|
||||
component.add_comp_deps('security/alicrypto')
|
||||
210
Living_SDK/test/testcase/security/id2_test/id2_test.c
Normal file
210
Living_SDK/test/testcase/security/id2_test/id2_test.c
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <id2_client.h>
|
||||
#include <stdio.h>
|
||||
#include "aos/aos.h"
|
||||
|
||||
#define MAX_AUTH_LEN 256
|
||||
#define MAX_CRYPTO_LEN 4096
|
||||
|
||||
static void test_id2_client_get_id(void)
|
||||
{
|
||||
int ret = 0;
|
||||
uint32_t len_1 = ID2_ID_LEN + 1;
|
||||
uint8_t id2_1[ID2_ID_LEN + 1] = { 0 };
|
||||
uint32_t len_2 = ID2_ID_LEN - 1;
|
||||
uint8_t id2_2[ID2_ID_LEN - 1] = { 0 };
|
||||
|
||||
// ret = id2_client_get_id(id2_1, &len_1);
|
||||
// YUNIT_ASSERT(ret == IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_id(id2_2, &len_2);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_id(NULL, &len_1);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_id(id2_1, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_id(NULL, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_id2_client_decrypt(void)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t enc_out_data[] = { 0x03, 0x4b, 0x1e, 0x52, 0x33, 0x5f, 0x32, 0x31,
|
||||
0x26, 0x70, 0x91, 0xab, 0x4a, 0x8b, 0x80, 0xdb };
|
||||
uint8_t dec_out_data[sizeof(enc_out_data)] = { 0 };
|
||||
uint32_t enc_len = sizeof(enc_out_data);
|
||||
uint32_t dec_len = sizeof(dec_out_data);
|
||||
|
||||
ret = id2_client_decrypt(NULL, enc_len, dec_out_data, &dec_len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_decrypt(enc_out_data, enc_len, NULL, &dec_len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_decrypt(enc_out_data, enc_len, dec_out_data, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_decrypt(NULL, 0, NULL, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_id2_client_get_challenge_auth_code(void)
|
||||
{
|
||||
int ret = -1;
|
||||
uint32_t len = AUTH_CODE_BUF_LEN;
|
||||
uint8_t auth_code[AUTH_CODE_BUF_LEN] = { 0 };
|
||||
const char *extra = "abcd1234";
|
||||
const char *challenge = "55B83408399FA660F05C82E4F25333DC";
|
||||
const char *challenge_s = "";
|
||||
const char *challenge_l = "55B83408399FA660F05C82E4F25333DC1";
|
||||
|
||||
ret = id2_client_get_challenge_auth_code(NULL, NULL, 0, auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge, NULL,
|
||||
0, NULL, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge, NULL,
|
||||
0, auth_code, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
// ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge,
|
||||
// NULL, 0, auth_code, &len); YUNIT_ASSERT(ret == IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code(NULL, extra, strlen(extra),
|
||||
auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge, extra,
|
||||
strlen(extra), NULL, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge, extra,
|
||||
strlen(extra), auth_code, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
// len = AUTH_CODE_BUF_LEN;
|
||||
// ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge,
|
||||
// extra, strlen(extra), auth_code, &len); YUNIT_ASSERT(ret ==
|
||||
// IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge_s, NULL,
|
||||
0, auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code((const uint8_t *)challenge_l, NULL,
|
||||
0, auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code(
|
||||
(const uint8_t *)challenge_s, extra, strlen(extra), auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_challenge_auth_code(
|
||||
(const uint8_t *)challenge_l, extra, strlen(extra), auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_id2_client_get_timestamp_auth_code(void)
|
||||
{
|
||||
int ret = -1;
|
||||
uint32_t len = AUTH_CODE_BUF_LEN;
|
||||
uint8_t auth_code[AUTH_CODE_BUF_LEN] = { 0 };
|
||||
const char *extra = "abcd1234";
|
||||
const char *timestamp = "1509070455668";
|
||||
const char *timestamp_s = "";
|
||||
const char *timestamp_l = "55B83408399FA660F05C82E4F25333DC1";
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code(NULL, NULL, 0, auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp, NULL,
|
||||
0, NULL, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp, NULL,
|
||||
0, auth_code, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
// ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp,
|
||||
// NULL, 0, auth_code, &len); YUNIT_ASSERT(ret == IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code(NULL, extra, strlen(extra),
|
||||
auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp, extra,
|
||||
strlen(extra), NULL, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp, extra,
|
||||
strlen(extra), auth_code, NULL);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
// len = AUTH_CODE_BUF_LEN;
|
||||
// ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp,
|
||||
// extra, strlen(extra), auth_code, &len); YUNIT_ASSERT(ret ==
|
||||
// IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp_s, NULL,
|
||||
0, auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code((const uint8_t *)timestamp_l, NULL,
|
||||
0, auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code(
|
||||
(const uint8_t *)timestamp_s, extra, strlen(extra), auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
|
||||
ret = id2_client_get_timestamp_auth_code(
|
||||
(const uint8_t *)timestamp_l, extra, strlen(extra), auth_code, &len);
|
||||
YUNIT_ASSERT(ret != IROT_SUCCESS);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
id2_client_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
id2_client_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void) {}
|
||||
|
||||
static void teardown(void) {}
|
||||
|
||||
static yunit_test_case_t aos_id2_client_testcases[] = {
|
||||
{ "id2_client_get_id", test_id2_client_get_id },
|
||||
{ "id2_client_decrypt", test_id2_client_decrypt },
|
||||
{ "id2_client_get_challenge_auth_code",
|
||||
test_id2_client_get_challenge_auth_code },
|
||||
{ "id2_client_get_timestamp_auth_code",
|
||||
test_id2_client_get_timestamp_auth_code },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = { { "id2", init, cleanup, setup, teardown,
|
||||
aos_id2_client_testcases },
|
||||
YUNIT_TEST_SUITE_NULL };
|
||||
|
||||
void test_id2(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_id2);
|
||||
8
Living_SDK/test/testcase/security/id2_test/id2_test.mk
Normal file
8
Living_SDK/test/testcase/security/id2_test/id2_test.mk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := id2_test
|
||||
|
||||
$(NAME)_COMPONENTS += id2 irot
|
||||
|
||||
$(NAME)_SOURCES += id2_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror -Wno-pointer-sign
|
||||
|
||||
14
Living_SDK/test/testcase/security/id2_test/ucube.py
Normal file
14
Living_SDK/test/testcase/security/id2_test/ucube.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
src = Split('''
|
||||
id2_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('id2_test', src)
|
||||
|
||||
dependencis = Split('''
|
||||
security/id2
|
||||
security/irot
|
||||
security/alicrypto
|
||||
''')
|
||||
|
||||
for d in dependencis:
|
||||
component.add_comp_deps(d)
|
||||
342
Living_SDK/test/testcase/security/tls_test/tls_test.c
Normal file
342
Living_SDK/test/testcase/security/tls_test/tls_test.c
Normal file
|
|
@ -0,0 +1,342 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <aos/errno.h>
|
||||
#include <aos/network.h>
|
||||
|
||||
#include <aos/mbedtls_ssl.h>
|
||||
|
||||
const char *mbedtls_real_ca_pem = "-----BEGIN CERTIFICATE-----\n" \
|
||||
"MIIDtzCCAp+gAwIBAgIJAOxbLdldR1+SMA0GCSqGSIb3DQEBBQUAMHIxCzAJBgNV\n"\
|
||||
"BAYTAkNOMREwDwYDVQQIDAh6aGVqaWFuZzERMA8GA1UEBwwIaGFuZ3pob3UxEDAO\n"\
|
||||
"BgNVBAoMB2FsaWJhYmExDjAMBgNVBAsMBXl1bm9zMRswGQYDVQQDDBIqLnNtYXJ0\n"\
|
||||
"LmFsaXl1bi5jb20wHhcNMTQwOTE3MDI0OTM0WhcNMjQwOTE0MDI0OTM0WjByMQsw\n"\
|
||||
"CQYDVQQGEwJDTjERMA8GA1UECAwIemhlamlhbmcxETAPBgNVBAcMCGhhbmd6aG91\n"\
|
||||
"MRAwDgYDVQQKDAdhbGliYWJhMQ4wDAYDVQQLDAV5dW5vczEbMBkGA1UEAwwSKi5z\n"\
|
||||
"bWFydC5hbGl5dW4uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n"\
|
||||
"pwFEj4onz7YZ0ESpG7BNZmuK4KJgGMlFHnEL3AT1YtvB7DGePTNsW9hX3WYsaqy7\n"\
|
||||
"+4PyzJgfNJY3WQr6uPv/EMwqlYMO0F8kg9AmFepuicHh5JvCeTJciG7OH/8qHhEB\n"\
|
||||
"3b3w35un5YxUXuffw3SiFTj+vnFdc3Yj9pBv++0nsDvl6l8TSkJMnRLY8lRzzi1T\n"\
|
||||
"rbdsDeNXLnfeThElMPFeI1h+s7amt2ktBGnv6HAg7a9OehUI8uTpFZ7559Yf8Dpm\n"\
|
||||
"MDijYc6LLLSE6OO5C7im0pg8IRu6oZo1F5raK5gbRU/QI7K58IuIo+k4+clcvtko\n"\
|
||||
"Ck4RkwdvC8cc0u5mJ8mXJwIDAQABo1AwTjAdBgNVHQ4EFgQUw6RWDo81JEoy+Vnf\n"\
|
||||
"vMTvRsLkZ30wHwYDVR0jBBgwFoAUw6RWDo81JEoy+VnfvMTvRsLkZ30wDAYDVR0T\n"\
|
||||
"BAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAS2UQtfguKHnlxH9jpfJUyGKFoaTT\n"\
|
||||
"8/XhPW3CW9c++zDrgNq920iQ42Yl9zB58iJ/v0w6n9quTtIta6QD72ssEJtWc2v2\n"\
|
||||
"rwu14WJB5tGhBRagMvtF7p/56KYxib0p3fqjaE3Neer5r8Mgb6oI13tHbf0WT4JM\n"\
|
||||
"GJCLsDoz4ZwvemLISeonZVSVIezs0BDU/TeEK2kIeUDB14FR6fY/U4ovS/v+han8\n"\
|
||||
"NLhWorEpB1p2sgnSPgSVc6ZPHHyjIQOcWdn56vnOf41rLF/zqjD0Sn7YgceAd5OT\n"\
|
||||
"rJ/t7PbiC/sn8SR7+0ATOMh0vRSA9HuuvoDz0adMhoFnba2FwiENfsLlhw==\n" \
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
const char *mbedtls_fake_ca_pem = "-----BEGIN CERTIFICATE-----\n" \
|
||||
"MIIDhzCCAm+gAwIBAgIBADANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\n" \
|
||||
"MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\n" \
|
||||
"MTEwMjEyMTQ0NDAwWhcNMjEwMjEyMTQ0NDAwWjA7MQswCQYDVQQGEwJOTDERMA8G\n" \
|
||||
"A1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwggEiMA0G\n" \
|
||||
"CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA3zf8F7vglp0/ht6WMn1EpRagzSHx\n" \
|
||||
"mdTs6st8GFgIlKXsm8WL3xoemTiZhx57wI053zhdcHgH057Zk+i5clHFzqMwUqny\n" \
|
||||
"50BwFMtEonILwuVA+T7lpg6z+exKY8C4KQB0nFc7qKUEkHHxvYPZP9al4jwqj+8n\n" \
|
||||
"YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\n" \
|
||||
"R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu\n" \
|
||||
"KNF+AksjoBXyOGVkCeoMbo4bF6BxyLObyavpw/LPh5aPgAIynplYb6LVAgMBAAGj\n" \
|
||||
"gZUwgZIwDAYDVR0TBAUwAwEB/zAdBgNVHQ4EFgQUtFrkpbPe0lL2udWmlQ/rPrzH\n" \
|
||||
"/f8wYwYDVR0jBFwwWoAUtFrkpbPe0lL2udWmlQ/rPrzH/f+hP6Q9MDsxCzAJBgNV\n" \
|
||||
"BAYTAk5MMREwDwYDVQQKEwhQb2xhclNTTDEZMBcGA1UEAxMQUG9sYXJTU0wgVGVz\n" \
|
||||
"dCBDQYIBADANBgkqhkiG9w0BAQUFAAOCAQEAuP1U2ABUkIslsCfdlc2i94QHHYeJ\n" \
|
||||
"SsR4EdgHtdciUI5I62J6Mom+Y0dT/7a+8S6MVMCZP6C5NyNyXw1GWY/YR82XTJ8H\n" \
|
||||
"DBJiCTok5DbZ6SzaONBzdWHXwWwmi5vg1dxn7YxrM9d0IjxM27WNKs4sDQhZBQkF\n" \
|
||||
"pjmfs2cb4oPl4Y9T9meTx/lvdkRYEug61Jfn6cA+qHpyPYdTH+UshITnmp5/Ztkf\n" \
|
||||
"m/UTSLBNFNHesiTZeH31NcxYGdHSme9Nc/gfidRa0FLOCfWxRlFqAI47zG9jAQCZ\n" \
|
||||
"7Z2mCGDNMhjQc+BYcdnl0lPXjdDK6V0qCg1dVewhUBcW5gZKzV7e9+DpVA==\n" \
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
const char *server_name = "alink.tcp.aliyun.com";
|
||||
const int server_port = 443;
|
||||
|
||||
static char alink_req_data[] = {
|
||||
0x57, 0x53, 0x46, 0x31, 0x00, 0x00, 0x00, 0x11,
|
||||
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03
|
||||
};
|
||||
|
||||
static void *sock_fd = NULL;
|
||||
static void *ssl = NULL;
|
||||
|
||||
static void *network_socket_create(const char *net_addr, int port)
|
||||
{
|
||||
int ret;
|
||||
int tcp_fd;
|
||||
struct hostent *host;
|
||||
struct sockaddr_in saddr;
|
||||
int opt_val = 1;
|
||||
|
||||
tcp_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (tcp_fd < 0) {
|
||||
printf("creat socket fail - errno: %d\n", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
host = gethostbyname(net_addr);
|
||||
if (host == NULL) {
|
||||
printf("get host by name fail - errno: %d\n", errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
memset(&saddr, 0, sizeof(saddr));
|
||||
saddr.sin_family = AF_INET;
|
||||
saddr.sin_port = htons(port);
|
||||
saddr.sin_addr.s_addr = *(unsigned long *)(host->h_addr);
|
||||
|
||||
setsockopt(tcp_fd, SOL_SOCKET, SO_RCVTIMEO, &opt_val, sizeof(opt_val));
|
||||
|
||||
do {
|
||||
set_errno(0);
|
||||
ret = connect(tcp_fd, (struct sockaddr*)&saddr, sizeof(struct sockaddr));
|
||||
if (ret < 0 && errno != EINTR) {
|
||||
printf("socket connect fail - errno: %d\n", errno);
|
||||
goto _err;
|
||||
}
|
||||
} while (ret < 0);
|
||||
|
||||
return (void *)tcp_fd;
|
||||
|
||||
_err:
|
||||
close(tcp_fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void network_socket_destroy(void *tcp_fd)
|
||||
{
|
||||
if (tcp_fd == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
close((int)tcp_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_tls_ssl_connect(void)
|
||||
{
|
||||
int ret;
|
||||
void *sock_fd = NULL;
|
||||
void *ssl = NULL;
|
||||
|
||||
sock_fd = network_socket_create(server_name, server_port);
|
||||
YUNIT_ASSERT((int)sock_fd >= 0);
|
||||
|
||||
/*
|
||||
* testcase #1
|
||||
*/
|
||||
ssl = mbedtls_ssl_connect((void *)-1,
|
||||
mbedtls_real_ca_pem, strlen(mbedtls_real_ca_pem));
|
||||
YUNIT_ASSERT(ssl == NULL);
|
||||
|
||||
/*
|
||||
* testcase #2
|
||||
*/
|
||||
ssl = mbedtls_ssl_connect(
|
||||
sock_fd, NULL, strlen(mbedtls_real_ca_pem));
|
||||
YUNIT_ASSERT(ssl == NULL);
|
||||
|
||||
/*
|
||||
* testcase #3
|
||||
*/
|
||||
ssl = mbedtls_ssl_connect(sock_fd, mbedtls_real_ca_pem, 0);
|
||||
YUNIT_ASSERT(ssl == NULL);
|
||||
|
||||
/*
|
||||
* testcase #4
|
||||
*/
|
||||
ssl = mbedtls_ssl_connect(sock_fd,
|
||||
mbedtls_fake_ca_pem, strlen(mbedtls_fake_ca_pem));
|
||||
YUNIT_ASSERT(ssl == NULL);
|
||||
|
||||
network_socket_destroy(sock_fd);
|
||||
|
||||
/*
|
||||
* testcase #5
|
||||
*/
|
||||
sock_fd = network_socket_create(server_name, server_port);
|
||||
YUNIT_ASSERT((int)sock_fd >= 0);
|
||||
|
||||
ssl = mbedtls_ssl_connect(sock_fd,
|
||||
mbedtls_real_ca_pem, strlen(mbedtls_real_ca_pem));
|
||||
YUNIT_ASSERT(ssl != NULL);
|
||||
|
||||
ret = mbedtls_ssl_close(ssl);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
network_socket_destroy(sock_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_tls_ssl_send(void)
|
||||
{
|
||||
int ret = 0;
|
||||
void *sock_fd = NULL;
|
||||
void *ssl = NULL;
|
||||
|
||||
sock_fd = network_socket_create(server_name, server_port);
|
||||
YUNIT_ASSERT((int)sock_fd >= 0);
|
||||
|
||||
ssl = mbedtls_ssl_connect(sock_fd,
|
||||
mbedtls_real_ca_pem, strlen(mbedtls_real_ca_pem));
|
||||
YUNIT_ASSERT(ssl != NULL);
|
||||
|
||||
/*
|
||||
* testcase #1
|
||||
*/
|
||||
ret = mbedtls_ssl_send(NULL, alink_req_data,
|
||||
(int)sizeof(alink_req_data));
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
|
||||
/*
|
||||
* testcase #2
|
||||
*/
|
||||
ret = mbedtls_ssl_send(ssl, NULL,
|
||||
(int)sizeof(alink_req_data));
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
|
||||
/*
|
||||
* testcase #3
|
||||
*/
|
||||
ret = mbedtls_ssl_send(ssl, alink_req_data, 0);
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
|
||||
/*
|
||||
* testcase #4
|
||||
*/
|
||||
ret = mbedtls_ssl_send(ssl, alink_req_data,
|
||||
(int)sizeof(alink_req_data));
|
||||
YUNIT_ASSERT(ret > 0);
|
||||
|
||||
ret = mbedtls_ssl_close(ssl);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
network_socket_destroy(sock_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_tls_ssl_recv(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[128];
|
||||
|
||||
sock_fd = network_socket_create(server_name, server_port);
|
||||
YUNIT_ASSERT((int)sock_fd >= 0);
|
||||
ssl = mbedtls_ssl_connect(sock_fd,
|
||||
mbedtls_real_ca_pem, strlen(mbedtls_real_ca_pem));
|
||||
YUNIT_ASSERT(ssl != NULL);
|
||||
|
||||
ret = mbedtls_ssl_send(ssl, alink_req_data,
|
||||
(int)sizeof(alink_req_data));
|
||||
YUNIT_ASSERT(ret > 0);
|
||||
|
||||
/*
|
||||
* testcase #1
|
||||
*/
|
||||
ret = mbedtls_ssl_recv(NULL, buf, 128);
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
|
||||
/*
|
||||
* testcase #2
|
||||
*/
|
||||
ret = mbedtls_ssl_recv(ssl, NULL, 128);
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
|
||||
/*
|
||||
* testcase #3
|
||||
*/
|
||||
ret = mbedtls_ssl_recv(ssl, buf, 0);
|
||||
YUNIT_ASSERT(ret < 0);
|
||||
|
||||
/*
|
||||
* testcase #4
|
||||
*/
|
||||
ret = mbedtls_ssl_recv(ssl, buf, 128);
|
||||
YUNIT_ASSERT(ret >= 0 || ret == -EAGAIN);
|
||||
|
||||
ret = mbedtls_ssl_close(ssl);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
network_socket_destroy(sock_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_tls_ssl_close(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
sock_fd = network_socket_create(server_name, server_port);
|
||||
YUNIT_ASSERT((int)sock_fd >= 0);
|
||||
ssl = mbedtls_ssl_connect(sock_fd,
|
||||
mbedtls_real_ca_pem, strlen(mbedtls_real_ca_pem));
|
||||
YUNIT_ASSERT(ssl != NULL);
|
||||
|
||||
/*
|
||||
* testcase #1
|
||||
*/
|
||||
ret = mbedtls_ssl_close(NULL);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
/*
|
||||
* testcase #2
|
||||
*/
|
||||
ret = mbedtls_ssl_close(ssl);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
network_socket_destroy(sock_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_tls_testcases[] = {
|
||||
{ "tls_ssl_connect", test_tls_ssl_connect},
|
||||
{ "tls_ssl_send", test_tls_ssl_send},
|
||||
{ "tls_ssl_recv", test_tls_ssl_recv},
|
||||
{ "tls_ssl_close", test_tls_ssl_close},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "tls", init, cleanup, setup, teardown, aos_tls_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_tls(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_tls);
|
||||
8
Living_SDK/test/testcase/security/tls_test/tls_test.mk
Normal file
8
Living_SDK/test/testcase/security/tls_test/tls_test.mk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
NAME := tls_test
|
||||
|
||||
$(NAME)_COMPONENTS += imbedtls
|
||||
|
||||
$(NAME)_SOURCES += tls_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
6
Living_SDK/test/testcase/security/tls_test/ucube.py
Normal file
6
Living_SDK/test/testcase/security/tls_test/ucube.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
src = Split('''
|
||||
tls_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('tls_test', src)
|
||||
component.add_comp_deps('security/mbedtls')
|
||||
10
Living_SDK/test/testcase/testcase.mk
Normal file
10
Living_SDK/test/testcase/testcase.mk
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
NAME := testcase
|
||||
|
||||
GLOBAL_INCLUDES += include
|
||||
|
||||
$(NAME)_COMPONENTS := yunit
|
||||
|
||||
$(NAME)_SOURCES := yts_main.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
11
Living_SDK/test/testcase/ucube.py
Normal file
11
Living_SDK/test/testcase/ucube.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
src = Split('''
|
||||
yts_main.c
|
||||
''')
|
||||
|
||||
component = aos_component('testcase', src)
|
||||
component.add_global_includes('include')
|
||||
component.add_comp_deps('test/yunit')
|
||||
component.add_cflags( "-Wall" )
|
||||
component.add_cflags( "-Werror")
|
||||
|
||||
|
||||
60
Living_SDK/test/testcase/utility/cjson_test/cjson_test.c
Normal file
60
Living_SDK/test/testcase/utility/cjson_test/cjson_test.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
|
||||
#include <aos/aos.h>
|
||||
#include <cJSON.h>
|
||||
|
||||
static void test_simple_case(void)
|
||||
{
|
||||
cJSON *obj = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(obj, "a", "b");
|
||||
char *p = cJSON_PrintUnformatted(obj);
|
||||
YUNIT_ASSERT(strcmp(p, "{\"a\":\"b\"}") == 0);
|
||||
cJSON_free(p);
|
||||
|
||||
cJSON_Delete(obj);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_cjson_testcases[] = {
|
||||
{ "simple", test_simple_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "cjson", init, cleanup, setup, teardown, aos_cjson_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_cjson(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_cjson);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := cjson_test
|
||||
|
||||
$(NAME)_COMPONENTS += cjson
|
||||
|
||||
$(NAME)_SOURCES += cjson_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
10
Living_SDK/test/testcase/utility/cjson_test/ucube.py
Normal file
10
Living_SDK/test/testcase/utility/cjson_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
cjson_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('cjson_test', src)
|
||||
|
||||
component.add_comp_deps('utility/cjson')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <aos/types.h>
|
||||
#include "digest_algorithm.h"
|
||||
#include "crc.h"
|
||||
|
||||
static void test_md5(void)
|
||||
{
|
||||
void *md5 = NULL;
|
||||
char *buf_md5 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
int ret = 0;
|
||||
|
||||
md5 = digest_md5_init();
|
||||
YUNIT_ASSERT(NULL != md5);
|
||||
|
||||
ret = digest_md5_update(md5,buf_md5,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_md5(buf_md5,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
#ifdef CONFIG_AOS_YTS_ALL
|
||||
ret = digest_md5_file("/etc/bash.bashrc",buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
#endif
|
||||
|
||||
ret = digest_md5_final(md5,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_sha256(void)
|
||||
{
|
||||
char *buf_sha256 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
void *sha256 = NULL;
|
||||
int ret = 0;
|
||||
|
||||
sha256 = digest_sha256_init();
|
||||
YUNIT_ASSERT(NULL != sha256);
|
||||
|
||||
ret = digest_sha256_update(sha256,buf_sha256,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha256(buf_sha256,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha256_final(sha256,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_sha384(void)
|
||||
{
|
||||
char *buf_sha384 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
void *sha384 = NULL;
|
||||
int ret = 0;
|
||||
|
||||
sha384 = digest_sha384_init();
|
||||
YUNIT_ASSERT(NULL != sha384);
|
||||
|
||||
ret = digest_sha384_update(sha384,buf_sha384,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha384(buf_sha384,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha384_final(sha384,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_sha512(void)
|
||||
{
|
||||
char *buf_sha512 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
void *sha512 = NULL;
|
||||
int ret = 0;
|
||||
|
||||
sha512 = digest_sha512_init();
|
||||
YUNIT_ASSERT(NULL != sha512);
|
||||
|
||||
ret = digest_sha512_update(sha512,buf_sha512 ,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha512(buf_sha512,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha512_final(sha512,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_crc(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char *buf_md5 = "asf";
|
||||
int len = 3;
|
||||
|
||||
ret = utils_crc16((unsigned char *)buf_md5,len);
|
||||
YUNIT_ASSERT(0 != ret);
|
||||
|
||||
ret = utils_crc32((unsigned char *)buf_md5,len);
|
||||
YUNIT_ASSERT(0 != ret);
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_digest_algorithm_testcases[] = {
|
||||
{ "test_md5", test_md5},
|
||||
{ "test_sha256", test_sha256},
|
||||
{ "test_sha384 ", test_sha384 },
|
||||
{ "test_sha512 ", test_sha512 },
|
||||
{ "test_crc", test_crc},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "digest", init, cleanup, setup, teardown, aos_digest_algorithm_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_digest_algorithm(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_digest_algorithm);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := digest_algorithm_test
|
||||
|
||||
$(NAME)_COMPONENTS += digest_algorithm
|
||||
|
||||
$(NAME)_SOURCES += digest_algorithm_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
digest_algorithm_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('digest_algorithm_test', src)
|
||||
|
||||
component.add_comp_deps('utility/digest_algorithm')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
179
Living_SDK/test/testcase/utility/hashtable_test/hashtable_test.c
Normal file
179
Living_SDK/test/testcase/utility/hashtable_test/hashtable_test.c
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include "hashtable.h"
|
||||
|
||||
typedef struct {
|
||||
char name[10];
|
||||
char addr[20];
|
||||
char phone[20];
|
||||
} stu_user_info;
|
||||
|
||||
static void *g_ht = NULL;
|
||||
static int g_ht_size = 5;
|
||||
|
||||
static int key_integer = 5;
|
||||
static int val_integer = 10;
|
||||
static const char *key_str = "user_name";
|
||||
static const char *val_str = "tiger";
|
||||
static const char *key_str_2 = "user_info";
|
||||
static stu_user_info val_stu = {"xxxxx", "yyyyyyyy", "zzzzzzzzzzz"};
|
||||
|
||||
static void test_ht_add(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
for (i=0;i<g_ht_size*2;i++) {
|
||||
ret = ht_add(g_ht, &i, sizeof(int *), &i, sizeof(int));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
for (i=0;i<g_ht_size*2;i++) {
|
||||
int tmp, len;
|
||||
len = sizeof(int);
|
||||
ht_find(g_ht, &i, sizeof(int *), &tmp, &len);
|
||||
YUNIT_ASSERT(i == tmp && len == sizeof(i));
|
||||
ret = ht_del(g_ht, &i, sizeof(i));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
ret = ht_add(g_ht, &key_integer, sizeof(key_integer), &val_integer, sizeof(int));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add(g_ht, &key_integer, sizeof(key_integer), &val_integer, sizeof(int));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add(g_ht, key_str, strlen(key_str) + 1, val_str, strlen(val_str) + 1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add(g_ht, key_str_2, strlen(key_str_2) + 1, &val_stu, sizeof(val_stu));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_ht_find(void)
|
||||
{
|
||||
int tmp = 0;
|
||||
int len = 0;
|
||||
len = sizeof(tmp);
|
||||
ht_find(g_ht, &key_integer, sizeof(&key_integer), &tmp, &len);
|
||||
|
||||
YUNIT_ASSERT(tmp == val_integer);
|
||||
|
||||
char tmp_buff[20] = {0};
|
||||
len = sizeof(tmp_buff);
|
||||
ht_find(g_ht, key_str, strlen(key_str) + 1, tmp_buff, &len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp_buff, val_str));
|
||||
YUNIT_ASSERT(len == strlen(val_str)+1);
|
||||
|
||||
stu_user_info tmp_user ;
|
||||
len = sizeof(tmp_user);
|
||||
ht_find(g_ht, key_str_2, strlen(key_str_2) + 1, &tmp_user, &len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp_user.name, val_stu.name) || strcmp(tmp_user.phone, val_stu.phone));
|
||||
}
|
||||
|
||||
static void test_ht_del(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char tmp_buff[20] = {0};
|
||||
int len = 0;
|
||||
|
||||
len = sizeof(tmp_buff);
|
||||
ht_find(g_ht, key_str, strlen(key_str) + 1, tmp_buff, &len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp_buff, val_str));
|
||||
|
||||
ret = ht_del(g_ht, key_str, strlen(key_str) + 1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
len = sizeof(tmp_buff);
|
||||
memset(tmp_buff,0,len);
|
||||
ht_find(g_ht, key_str, strlen(key_str) + 1, tmp_buff, &len);
|
||||
YUNIT_ASSERT(0 != strcmp(tmp_buff, val_str));
|
||||
}
|
||||
|
||||
static void test_ht_lockless(void)
|
||||
{
|
||||
int key_int_1 = 1;
|
||||
int key_int_2 = 2;
|
||||
int key_int_3 = 3;
|
||||
|
||||
char *val_str_1 = "1";
|
||||
char *val_str_2 = "2";
|
||||
char *val_str_3 = "3";
|
||||
|
||||
int ret = 0;
|
||||
char tmp[5] = {0};
|
||||
int len = sizeof(tmp);
|
||||
|
||||
ht_lock(g_ht);
|
||||
ret = ht_add_lockless(g_ht,&key_int_1,sizeof(int *),val_str_1,strlen(val_str_1)+1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add_lockless(g_ht,&key_int_2,sizeof(int *),val_str_2,strlen(val_str_2)+1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add_lockless(g_ht,&key_int_3,sizeof(int *),val_str_3,strlen(val_str_3)+1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
ht_unlock(g_ht);
|
||||
|
||||
char *x = NULL;
|
||||
x = ht_find(g_ht,&key_int_1,sizeof(int *),tmp,&len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp,val_str_1));
|
||||
YUNIT_ASSERT(0 == strcmp(x,val_str_1));
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
g_ht = ht_init(g_ht_size);
|
||||
YUNIT_ASSERT(NULL != g_ht);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = ht_clear(g_ht);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
ret = ht_destroy(g_ht);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_hashtable_testcases[] = {
|
||||
{ "ht_add", test_ht_add },
|
||||
{ "ht_find", test_ht_find },
|
||||
{ "ht_del", test_ht_del },
|
||||
{ "ht_lockless", test_ht_lockless },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "hashtable", init, cleanup, setup, teardown, aos_hashtable_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_hashtable(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_hashtable);
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
NAME := hashtable_test
|
||||
|
||||
$(NAME)_COMPONENTS += hashtable
|
||||
|
||||
$(NAME)_SOURCES += hashtable_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
10
Living_SDK/test/testcase/utility/hashtable_test/ucube.py
Normal file
10
Living_SDK/test/testcase/utility/hashtable_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
hashtable_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('hashtable_test', src)
|
||||
|
||||
component.add_comp_deps('utility/hashtable')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
135
Living_SDK/test/testcase/yts_main.c
Normal file
135
Living_SDK/test/testcase/yts_main.c
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(__GNUC__)
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#include <aos/kernel.h>
|
||||
|
||||
#include "yunit.h"
|
||||
#include "yts.h"
|
||||
|
||||
static int yts_argc;
|
||||
static char **yts_argv;
|
||||
|
||||
extern void add_test(void);
|
||||
|
||||
int yts_get_args(const char ***argv)
|
||||
{
|
||||
*argv = (const char **)yts_argv;
|
||||
return yts_argc;
|
||||
}
|
||||
|
||||
void yts_run(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
yts_argc = argc;
|
||||
yts_argv = argv;
|
||||
|
||||
aos_msleep(2 * 1000);
|
||||
|
||||
yunit_test_init();
|
||||
|
||||
add_test();
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
yunit_test_suite_t *test_suite = yunit_get_test_suite(argv[i]);
|
||||
if (test_suite != NULL)
|
||||
{
|
||||
ret = yunit_run_test_suite(test_suite, 1);
|
||||
printf("suite:%s completed with %d\n", argv[i], ret);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *suite_case = argv[i];
|
||||
char *test = strrchr(suite_case, ':');
|
||||
if (test != NULL)
|
||||
{
|
||||
*test++ = '\0';
|
||||
|
||||
test_suite = yunit_get_test_suite(suite_case);
|
||||
yunit_test_case_t *test_case = yunit_get_test_case(test_suite, test);
|
||||
if (test_case != NULL)
|
||||
{
|
||||
ret = yunit_run_test_case(test_suite, test_case);
|
||||
printf("suite:%s completed with %d\n", argv[i], ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("suite:%s not found\n", argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = yunit_test_run();
|
||||
printf("\nTests completed with return value %d\n", ret);
|
||||
}
|
||||
|
||||
yunit_test_print_result();
|
||||
|
||||
yunit_test_deinit();
|
||||
}
|
||||
|
||||
int yts_run_suite_by_name(const char *suite_name, int test_case_times)
|
||||
{
|
||||
int ret = -1;
|
||||
yunit_test_suite_t *test_suite = NULL;
|
||||
|
||||
yunit_test_init();
|
||||
|
||||
if (!strcmp(suite_name, "basic"))
|
||||
{
|
||||
test_basic();
|
||||
}
|
||||
else
|
||||
{
|
||||
add_test();
|
||||
|
||||
test_suite = yunit_get_test_suite(suite_name);
|
||||
if (test_suite != NULL)
|
||||
{
|
||||
ret = yunit_run_test_suite(test_suite, test_case_times);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_Printf("Test suite:%s not found\r\n", suite_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
yunit_test_print_result();
|
||||
}
|
||||
|
||||
yunit_test_deinit();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ct_yts_run_all(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
yunit_test_init();
|
||||
|
||||
test_basic(); //Run basic
|
||||
|
||||
add_test();
|
||||
|
||||
ret = yunit_test_run(); //Run case which beyond of basic
|
||||
printf("\nTests completed with return value %d\n", ret);
|
||||
|
||||
yunit_test_print_result();
|
||||
|
||||
yunit_test_deinit();
|
||||
}
|
||||
196
Living_SDK/test/yunit/include/yunit.h
Normal file
196
Living_SDK/test/yunit/include/yunit.h
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef AOS_UNIT_TEST_H
|
||||
#define AOS_UNIT_TEST_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void (*yunit_test_case_proc)(void);
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
yunit_test_case_proc test_proc;
|
||||
} yunit_test_case_t;
|
||||
|
||||
#define YUNIT_TEST_CASE_NULL { 0 }
|
||||
|
||||
typedef int (*yunit_test_suit_init)(void);
|
||||
typedef int (*yunit_test_suit_deinit)(void);
|
||||
typedef void (*yunit_test_case_setup)(void);
|
||||
typedef void (*yunit_test_case_teardown)(void);
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
yunit_test_suit_init init;
|
||||
yunit_test_suit_deinit deinit;
|
||||
yunit_test_case_setup setup;
|
||||
yunit_test_case_teardown teardown;
|
||||
yunit_test_case_t *test_case_array;
|
||||
} yunit_test_suite_t;
|
||||
|
||||
#define YUNIT_TEST_SUITE_NULL { 0 }
|
||||
|
||||
void *yunit_add_test_suite(
|
||||
const char *name,
|
||||
yunit_test_suit_init init,
|
||||
yunit_test_suit_deinit deinit,
|
||||
yunit_test_case_setup setup,
|
||||
yunit_test_case_teardown teardown);
|
||||
|
||||
int yunit_add_test_case(
|
||||
void *test_suite,
|
||||
const char *name, yunit_test_case_proc proc);
|
||||
int yunit_add_test_suites(yunit_test_suite_t *test_suite_array);
|
||||
|
||||
void *yunit_get_test_suite(const char *name);
|
||||
void *yunit_get_test_case(void *test_suite, const char *name);
|
||||
|
||||
void yunit_test_init(void);
|
||||
void yunit_test_deinit(void);
|
||||
int yunit_test_run(void);
|
||||
int yunit_run_test_suite(void *test_suite, int test_times);
|
||||
int yunit_run_test_case(void *test_suite, void *test_case);
|
||||
void yunit_test_print_result(void);
|
||||
|
||||
enum {
|
||||
TEST_RESULT_SUCCESS = 0,
|
||||
TEST_RESULT_FAILURE,
|
||||
TEST_RESULT_FATAL
|
||||
};
|
||||
void yunit_add_test_case_result(
|
||||
int result_type,
|
||||
const char *file, size_t line, const char *fmt, ...);
|
||||
|
||||
#define YUNIT_FAIL(msg) \
|
||||
yunit_add_test_case_result( \
|
||||
TEST_RESULT_FAILURE, __FILE__, __LINE__, "%s", msg);
|
||||
|
||||
#define YUNIT_FAIL_FATAL(msg) \
|
||||
yunit_add_test_case_result( \
|
||||
TEST_RESULT_FATAL, __FILE__, __LINE__, "%s", msg);
|
||||
|
||||
#define YUNIT_ASSERT(expr) \
|
||||
do { \
|
||||
yunit_add_test_case_result( \
|
||||
(expr) ? TEST_RESULT_SUCCESS : TEST_RESULT_FAILURE, \
|
||||
__FILE__, __LINE__, "%s", #expr); \
|
||||
} while (0);
|
||||
|
||||
/* print msg if failure, else nothing */
|
||||
#define YUNIT_ASSERT_MSG(expr, fmt, args...) \
|
||||
do { \
|
||||
yunit_add_test_case_result( \
|
||||
(expr) ? TEST_RESULT_SUCCESS : TEST_RESULT_FAILURE, \
|
||||
__FILE__, __LINE__, "expect (%s) but actual ("fmt")", #expr, ##args); \
|
||||
} while (0);
|
||||
|
||||
#define YUNIT_ASSERT_FETAL(expr) \
|
||||
do { \
|
||||
yunit_add_test_case_result( \
|
||||
(expr) ? TEST_RESULT_SUCCESS : TEST_RESULT_FATAL, \
|
||||
__FILE__, __LINE__, "%s", #expr); \
|
||||
} while (0);
|
||||
|
||||
#define YUNIT_ASSERT_TRUE(expr) YUNIT_ASSERT(expr)
|
||||
|
||||
#define YUNIT_ASSERT_FALSE(expr) YUNIT_ASSERT(!(expr))
|
||||
|
||||
#define YUNIT_ASSERT_TRUE_FATAL(expr) YUNIT_ASSERT_FETAL(expr)
|
||||
|
||||
#define YUNIT_ASSERT_EQUAL(expect, actual) \
|
||||
do { \
|
||||
int result = (expect == actual); \
|
||||
yunit_add_test_case_result( \
|
||||
result ? TEST_RESULT_SUCCESS : TEST_RESULT_FAILURE, \
|
||||
__FILE__, __LINE__, \
|
||||
"%s==%s", #expect, #actual); \
|
||||
} while (0);
|
||||
|
||||
#define YUNIT_ASSERT_EQUAL_FATAL(expect, actual) \
|
||||
do { \
|
||||
yunit_add_test_case_result( \
|
||||
(expect == actual) ? TEST_RESULT_SUCCESS : TEST_RESULT_FATAL, \
|
||||
__FILE__, __LINE__, "%s==%s", #expect, #actual); \
|
||||
} while (0);
|
||||
|
||||
#define YUNIT_ASSERT_STR_EQUAL(expect, actual) \
|
||||
do { \
|
||||
int result = strcmp((const char *)expect, (const char *)actual) == 0; \
|
||||
yunit_add_test_case_result( \
|
||||
result ? TEST_RESULT_SUCCESS : TEST_RESULT_FAILURE, \
|
||||
__FILE__, __LINE__, \
|
||||
result ? "%s(%s)==%s(%s)" : "expect %s(%s) but actual is %s(%s)", \
|
||||
#expect, (const char *)expect, #actual, (const char *)actual); \
|
||||
} while (0);
|
||||
|
||||
#define YUNIT_ASSERT_STR_N_EQUAL(expect, actual, len) \
|
||||
do { \
|
||||
int result = strncmp((const char *)expect, (const char *)actual, len) == 0; \
|
||||
yunit_add_test_case_result( \
|
||||
result ? TEST_RESULT_SUCCESS : TEST_RESULT_FAILURE, \
|
||||
__FILE__, __LINE__, \
|
||||
result ? "%s(%s)==%s(%s) len=%d" \
|
||||
: "expect %s(%s) but actual is %s(%s) len=%d", \
|
||||
#expect, (const char *)expect, #actual, (const char *)actual, len); \
|
||||
} while (0);
|
||||
|
||||
#define YUNIT_ASSERT_PTR_NULL(p) YUNIT_ASSERT_PTR_EQUAL(p, NULL)
|
||||
|
||||
#define YUNIT_ASSERT_PTR_NOT_NULL(p) YUNIT_ASSERT_PTR_NOT_EQUAL(p, NULL)
|
||||
|
||||
#define YUNIT_ASSERT_PTR_EQUAL(expect, actual) \
|
||||
do { \
|
||||
int result = (expect == actual); \
|
||||
yunit_add_test_case_result( \
|
||||
result ? TEST_RESULT_SUCCESS : TEST_RESULT_FAILURE, \
|
||||
__FILE__, __LINE__, \
|
||||
result ? "%s(%p)==%s(%p)" : "expect %s(%p) but actual is %s(%p)", \
|
||||
#expect, expect, #actual, actual); \
|
||||
} while (0);
|
||||
|
||||
#define YUNIT_ASSERT_PTR_NOT_EQUAL(expect, actual) \
|
||||
do { \
|
||||
int result = (expect != actual); \
|
||||
yunit_add_test_case_result( \
|
||||
result ? TEST_RESULT_SUCCESS : TEST_RESULT_FAILURE, \
|
||||
__FILE__, __LINE__, \
|
||||
result ? "%s(%p)!=%s(%p)" : "expect %s(%p) but actual is %s(%p)", \
|
||||
#expect, expect, #actual, actual); \
|
||||
} while (0);
|
||||
|
||||
|
||||
#define PRINT_TASK_INFO(task) \
|
||||
printf("\t%-40s%-10d%-20d\n",\
|
||||
task->task_name, \
|
||||
(int)task->task_state, \
|
||||
(int)task->stack_size*sizeof(cpu_stack_t))
|
||||
|
||||
#define PRINT_ALL_TASK_INFO() do { \
|
||||
klist_t *taskhead = &g_kobj_list.task_head; \
|
||||
klist_t *taskend = taskhead;\
|
||||
klist_t *tmp;\
|
||||
ktask_t *task; \
|
||||
printf("\t--------------------------------------------------------------\n");\
|
||||
printf("\t%-40s%-10s%-20s\n", "Name","State", "StackSize");\
|
||||
printf("\t--------------------------------------------------------------\n");\
|
||||
for (tmp = taskhead->next; tmp != taskend; tmp = tmp->next) { \
|
||||
task = krhino_list_entry(tmp, ktask_t, task_stats_item);\
|
||||
PRINT_TASK_INFO(task);\
|
||||
}\
|
||||
printf("\t--------------------------------------------------------------\n");\
|
||||
}while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AOS_UNIT_TEST_H */
|
||||
|
||||
7
Living_SDK/test/yunit/ucube.py
Normal file
7
Living_SDK/test/yunit/ucube.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
src = Split('''
|
||||
yunit.c
|
||||
''')
|
||||
|
||||
component = aos_component('yunit', src)
|
||||
component.add_global_includes('include')
|
||||
|
||||
444
Living_SDK/test/yunit/yunit.c
Normal file
444
Living_SDK/test/yunit/yunit.c
Normal file
|
|
@ -0,0 +1,444 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/aos.h>
|
||||
|
||||
#include <k_api.h>
|
||||
#include "yunit.h"
|
||||
|
||||
#define TAG "yunit"
|
||||
|
||||
extern k_mm_head *g_kmm_head;
|
||||
|
||||
typedef struct yunit_test_case_node_s
|
||||
{
|
||||
struct yunit_test_case_node_s *next;
|
||||
const char *name;
|
||||
yunit_test_case_proc test_proc;
|
||||
} yunit_test_case_node_t;
|
||||
|
||||
typedef struct yunit_test_suite_node_s
|
||||
{
|
||||
struct yunit_test_suite_node_s *next;
|
||||
const char *name;
|
||||
yunit_test_suit_init init;
|
||||
yunit_test_suit_deinit deinit;
|
||||
yunit_test_case_setup setup;
|
||||
yunit_test_case_teardown teardown;
|
||||
yunit_test_case_node_t test_case_list_header;
|
||||
} yunit_test_suite_node_t;
|
||||
|
||||
#define TEST_RESULT_MESSAGE_LENGTH 64
|
||||
typedef struct yunit_test_case_result_s
|
||||
{
|
||||
struct yunit_test_case_result_s *next;
|
||||
const char *file;
|
||||
size_t line;
|
||||
char msg[TEST_RESULT_MESSAGE_LENGTH];
|
||||
} yunit_test_case_result_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
yunit_test_suite_node_t test_suite_list_header;
|
||||
int all_test_cases_count;
|
||||
int failed_test_cases_count;
|
||||
int fatal_test_cases_count;
|
||||
yunit_test_case_result_t failed_test_case_result;
|
||||
} yunit_test_context_t;
|
||||
|
||||
static int yunit_run_test_case_list(
|
||||
yunit_test_suite_node_t *suite,
|
||||
yunit_test_case_node_t *test_case_list_header);
|
||||
|
||||
yunit_test_context_t g_test_context;
|
||||
|
||||
void yunit_test_init(void)
|
||||
{
|
||||
memset(&g_test_context, 0, sizeof(yunit_test_context_t));
|
||||
}
|
||||
|
||||
void yunit_test_deinit(void)
|
||||
{
|
||||
yunit_test_suite_node_t *test_suite_node = g_test_context.test_suite_list_header.next;
|
||||
while (test_suite_node != NULL)
|
||||
{
|
||||
yunit_test_case_node_t *test_case_node = test_suite_node->test_case_list_header.next;
|
||||
while (test_case_node != NULL)
|
||||
{
|
||||
yunit_test_case_node_t *test_case_node_next = test_case_node->next;
|
||||
aos_free(test_case_node);
|
||||
test_case_node = test_case_node_next;
|
||||
}
|
||||
|
||||
yunit_test_suite_node_t *test_suite_node_next = test_suite_node->next;
|
||||
aos_free(test_suite_node);
|
||||
test_suite_node = test_suite_node_next;
|
||||
}
|
||||
|
||||
yunit_test_case_result_t *test_case_result = g_test_context.failed_test_case_result.next;
|
||||
while (test_case_result != NULL)
|
||||
{
|
||||
yunit_test_case_result_t *test_case_result_next = test_case_result->next;
|
||||
aos_free(test_case_result);
|
||||
test_case_result = test_case_result_next;
|
||||
}
|
||||
}
|
||||
|
||||
void *yunit_add_test_suite(
|
||||
const char *name,
|
||||
yunit_test_suit_init init,
|
||||
yunit_test_suit_deinit deinit,
|
||||
yunit_test_case_setup setup,
|
||||
yunit_test_case_teardown teardown)
|
||||
{
|
||||
yunit_test_suite_node_t *node = aos_malloc(sizeof(yunit_test_suite_node_t));
|
||||
if (node == NULL)
|
||||
{
|
||||
printf("%s\n", "out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset(node, 0, sizeof(yunit_test_suite_node_t));
|
||||
|
||||
node->next = NULL;
|
||||
node->name = name;
|
||||
node->init = init;
|
||||
node->deinit = deinit;
|
||||
node->setup = setup;
|
||||
node->teardown = teardown;
|
||||
|
||||
yunit_test_suite_node_t *prev = &g_test_context.test_suite_list_header;
|
||||
while (prev->next != NULL)
|
||||
{
|
||||
prev = prev->next;
|
||||
}
|
||||
|
||||
prev->next = node;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
int yunit_add_test_case(void *test_suite, const char *name, yunit_test_case_proc proc)
|
||||
{
|
||||
yunit_test_suite_node_t *test_suite_node = test_suite;
|
||||
|
||||
yunit_test_case_node_t *prev = &test_suite_node->test_case_list_header;
|
||||
while (prev->next != NULL)
|
||||
{
|
||||
prev = prev->next;
|
||||
}
|
||||
|
||||
yunit_test_case_node_t *node = aos_malloc(sizeof(yunit_test_case_node_t));
|
||||
memset(node, 0, sizeof(yunit_test_case_node_t));
|
||||
|
||||
if (node == NULL)
|
||||
{
|
||||
printf("%s\n", "out of memory");
|
||||
return -1;
|
||||
}
|
||||
node->name = name;
|
||||
node->test_proc = proc;
|
||||
|
||||
prev->next = node;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int yunit_add_test_suites(yunit_test_suite_t *test_suit_array)
|
||||
{
|
||||
int i = 0;
|
||||
while (test_suit_array[i].name != NULL)
|
||||
{
|
||||
yunit_test_suite_t *test_suite = &test_suit_array[i++];
|
||||
void *test_suite_node = yunit_add_test_suite(
|
||||
test_suite->name,
|
||||
test_suite->init, test_suite->deinit,
|
||||
test_suite->setup, test_suite->teardown);
|
||||
|
||||
if (test_suite_node == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
yunit_test_case_t *test_case_array = test_suite->test_case_array;
|
||||
while (test_case_array[j].name != NULL)
|
||||
{
|
||||
yunit_test_case_t *test_case = &test_case_array[j++];
|
||||
int ret = yunit_add_test_case(
|
||||
test_suite_node,
|
||||
test_case->name, test_case->test_proc);
|
||||
if (ret == -1)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *yunit_get_test_suite(const char *name)
|
||||
{
|
||||
yunit_test_suite_node_t *node = g_test_context.test_suite_list_header.next;
|
||||
while (node != NULL)
|
||||
{
|
||||
if (strcmp(node->name, name) == 0)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *yunit_get_test_case(void *test_suite, const char *name)
|
||||
{
|
||||
yunit_test_suite_node_t *test_suite_node = test_suite;
|
||||
|
||||
yunit_test_case_node_t *node = test_suite_node->test_case_list_header.next;
|
||||
while (node != NULL)
|
||||
{
|
||||
if (strcmp(node->name, name) == 0)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int yunit_test_run(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
yunit_test_suite_node_t *test_suite = g_test_context.test_suite_list_header.next;
|
||||
while (test_suite != NULL)
|
||||
{
|
||||
ret = yunit_run_test_suite(test_suite, 1);
|
||||
if (ret != 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
test_suite = test_suite->next;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int yunit_run_test_suite(void *test_suite, int test_times)
|
||||
{
|
||||
int ret = 0;
|
||||
int index = 0;
|
||||
|
||||
yunit_test_suite_node_t *node = NULL;
|
||||
|
||||
if (NULL == test_suite || test_times < 1)
|
||||
{
|
||||
printf("param error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
node = test_suite;
|
||||
|
||||
printf("Run test suite:%s\n", node->name);
|
||||
|
||||
for (index = 0; index < test_times; index++)
|
||||
{
|
||||
if (node->init != NULL)
|
||||
{
|
||||
node->init();
|
||||
}
|
||||
|
||||
ret = yunit_run_test_case_list(node, &node->test_case_list_header);
|
||||
|
||||
if (node->deinit != NULL)
|
||||
{
|
||||
node->deinit();
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("Run test suite %s index:%d failed ret:%d\n", node->name, index + 1, ret);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _run_test_case(void *test_suite, void *test_case)
|
||||
{
|
||||
yunit_test_suite_node_t *test_suite_node = test_suite;
|
||||
yunit_test_case_node_t *test_case_node = test_case;
|
||||
int cnt1 = g_test_context.failed_test_cases_count + g_test_context.fatal_test_cases_count;
|
||||
int cnt2;
|
||||
long long now = aos_now_ms();
|
||||
int delta;
|
||||
|
||||
if (test_suite_node->setup != NULL)
|
||||
{
|
||||
test_suite_node->setup();
|
||||
}
|
||||
|
||||
fprintf(stderr, "Run test case:%s start ... free heap = %d\n", test_case_node->name, g_kmm_head->free_size);
|
||||
|
||||
if (test_case_node->test_proc != NULL)
|
||||
{
|
||||
test_case_node->test_proc();
|
||||
}
|
||||
|
||||
if (test_suite_node->teardown != NULL)
|
||||
{
|
||||
test_suite_node->teardown();
|
||||
}
|
||||
|
||||
cnt2 = g_test_context.failed_test_cases_count + g_test_context.fatal_test_cases_count;
|
||||
delta = aos_now_ms() - now;
|
||||
|
||||
if ((cnt2 - cnt1) > 0) //There are some failed
|
||||
{
|
||||
fprintf(stderr, "Run test case:%s finished elapsed time:%d ms failed:%d\n", test_case_node->name, delta, cnt2 - cnt1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Run test case:%s finished elapsed time:%d ms\n", test_case_node->name, delta);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int yunit_run_test_case(void *test_suite, void *test_case)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
yunit_test_suite_node_t *tnode = test_suite;
|
||||
yunit_test_case_node_t *tcase = test_case;
|
||||
|
||||
printf("Run test suites %s\n", tnode->name);
|
||||
|
||||
if (tnode->init != NULL)
|
||||
{
|
||||
tnode->init();
|
||||
}
|
||||
|
||||
ret = _run_test_case(tnode, tcase);
|
||||
|
||||
if (tnode->deinit != NULL)
|
||||
{
|
||||
tnode->deinit();
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
LOGE(TAG, "Suite:%s fail ret = %d", tnode->name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int yunit_run_test_case_list(yunit_test_suite_node_t *test_suite,
|
||||
yunit_test_case_node_t *test_case_list_header)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
yunit_test_case_node_t *node = test_case_list_header->next;
|
||||
|
||||
while (node != NULL)
|
||||
{
|
||||
ret = _run_test_case(test_suite, node);
|
||||
if (ret != 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void yunit_add_test_case_result(int type, const char *file, size_t line, const char *fmt, ...)
|
||||
{
|
||||
g_test_context.all_test_cases_count++;
|
||||
|
||||
if (type == TEST_RESULT_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == TEST_RESULT_FAILURE)
|
||||
{
|
||||
g_test_context.failed_test_cases_count++;
|
||||
}
|
||||
else if (type == TEST_RESULT_FATAL)
|
||||
{
|
||||
g_test_context.fatal_test_cases_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
yunit_test_case_result_t *result = aos_malloc(sizeof(yunit_test_case_result_t));
|
||||
if (result == NULL)
|
||||
{
|
||||
printf("%s\n", "out of memory");
|
||||
return;
|
||||
}
|
||||
memset(result, 0, sizeof(yunit_test_case_result_t));
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(result->msg, TEST_RESULT_MESSAGE_LENGTH, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
result->file = file;
|
||||
result->line = line;
|
||||
|
||||
yunit_test_case_result_t *prev = &g_test_context.failed_test_case_result;
|
||||
while (prev != NULL && prev->next != NULL)
|
||||
{
|
||||
prev = prev->next;
|
||||
}
|
||||
|
||||
prev->next = result;
|
||||
}
|
||||
|
||||
void yunit_test_print_result(void)
|
||||
{
|
||||
int failed_times = 0;
|
||||
int passed_times = 0;
|
||||
|
||||
printf("\n--------------------------------\n");
|
||||
|
||||
failed_times = g_test_context.failed_test_cases_count + g_test_context.fatal_test_cases_count;
|
||||
passed_times = g_test_context.all_test_cases_count - failed_times;
|
||||
|
||||
if (failed_times > 0)
|
||||
{
|
||||
printf("total:%d test cases, passed:%d failed:%d\n\n",
|
||||
g_test_context.all_test_cases_count, passed_times, failed_times);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("total:%d test cases, passed:%d\n\n",
|
||||
g_test_context.all_test_cases_count, passed_times);
|
||||
|
||||
}
|
||||
|
||||
yunit_test_case_result_t *result = g_test_context.failed_test_case_result.next;
|
||||
while (result != NULL)
|
||||
{
|
||||
printf("failed at %s(#%d) %s\n", result->file, result->line, result->msg);
|
||||
result = result->next;
|
||||
}
|
||||
|
||||
printf("\n--------------------------------\n");
|
||||
}
|
||||
5
Living_SDK/test/yunit/yunit.mk
Normal file
5
Living_SDK/test/yunit/yunit.mk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
NAME := yunit
|
||||
|
||||
$(NAME)_SOURCES := yunit.c
|
||||
|
||||
GLOBAL_INCLUDES += include
|
||||
Loading…
Add table
Add a link
Reference in a new issue