rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View 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);

View file

@ -0,0 +1,7 @@
NAME := deviceIO_test
$(NAME)_COMPONENTS += vfs
$(NAME)_SOURCES += deviceIO_test.c
$(NAME)_CFLAGS += -Wall -Werror

View 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')

View 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);

View file

@ -0,0 +1,8 @@
NAME := fatfs_test
$(NAME)_COMPONENTS += modules.fs.fatfs
$(NAME)_SOURCES += fatfs_test.c
$(NAME)_CFLAGS += -Wall -Werror

View 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')

View 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);

View file

@ -0,0 +1,8 @@
NAME := kv_test
$(NAME)_COMPONENTS += modules.fs.kv
$(NAME)_SOURCES += kv_test.c
$(NAME)_CFLAGS += -Wall -Werror

View 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')

View 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);
}

View 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);

View 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

View 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')

View 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')

View 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);

View file

@ -0,0 +1,8 @@
NAME := vcall_test
$(NAME)_COMPONENTS += vcall
$(NAME)_SOURCES += vcall_test.c
$(NAME)_CFLAGS += -Wall -Werror

View 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')

View 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);

View file

@ -0,0 +1,8 @@
NAME := vfs_test
$(NAME)_COMPONENTS += vfs
$(NAME)_SOURCES += vfs_test.c
$(NAME)_CFLAGS += -Wall -Werror

View 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')

View 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);

View file

@ -0,0 +1,8 @@
NAME := yloop_test
$(NAME)_COMPONENTS += yloop
$(NAME)_SOURCES += yloop_test.c
$(NAME)_CFLAGS += -Wall -Werror