mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-13 05:25:38 +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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue