import RT-Thread@9217865c without bsp, libcpu and components/net

This commit is contained in:
Zihao Yu 2023-05-20 16:23:33 +08:00
commit e2376a3709
1414 changed files with 390370 additions and 0 deletions

View file

@ -0,0 +1,27 @@
menuconfig RTT_POSIX_TESTCASE_UNISTD_H
bool "<unistd.h>"
default n
if RTT_POSIX_TESTCASE_UNISTD_H
config UNISTD_H_ACCESS
bool "<unistd.h> -> access"
default n
config UNISTD_H_CHDIR
bool "<unistd.h> -> chdir"
default n
config UNISTD_H_FTRUNCATE
bool "<unistd.h> -> ftruncate"
default n
config UNISTD_H_ISATTY
bool "<unistd.h> -> isatty"
default n
config UNISTD_H_FSYNC
bool "<unistd.h> -> fsync"
default n
config UNISTD_H_RMDIR
bool "<unistd.h> -> rmdir"
default n
endif

View file

@ -0,0 +1,33 @@
import rtconfig
Import('RTT_ROOT')
from building import *
# get current directory
cwd = GetCurrentDir()
path = [cwd]
src = []
if GetDepend('RTT_POSIX_TESTCASE_UNISTD_H'):
src += Glob('./definitions/*.c')
if GetDepend('UNISTD_H_ACCESS'):
src += Glob('./functions/access_tc.c')
if GetDepend('UNISTD_H_CHDIR'):
src += Glob('./functions/chdir_tc.c')
if GetDepend('UNISTD_H_FTRUNCATE'):
src += Glob('./functions/ftruncate_tc.c')
if GetDepend('UNISTD_H_ISATTY'):
src += Glob('./functions/isatty_tc.c')
if GetDepend('UNISTD_H_FSYNC'):
src += Glob('./functions/open_read_write_fsync_close_tc.c')
if GetDepend('UNISTD_H_RMDIR'):
src += Glob('./functions/rmdir_tc.c')
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_UNISTD_H'], CPPPATH = path)
Return('group')

View file

@ -0,0 +1,44 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#define ACCESS_DIR "./access_dir"
#include <utest.h>
static int access_entry(void)
{
int i = 0;
/* file/dir that not exist*/
char *files[] =
{
"/usr/local/nginx/conf/nginx.conf",
"./a.out",
"/usr/include/libgen.h",
"/ff/last",
NULL
};
for (i = 0; files[i] != NULL; i++)
{
/* mode=0: file/dir exist or not */
uassert_int_not_equal(access(files[i], 0), 0);
}
mkdir(ACCESS_DIR, 0x777);
uassert_int_equal(access(ACCESS_DIR, 0), 0);
return 0;
}
static void test_access(void)
{
uassert_int_equal(access_entry(), 0);
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_access);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.access_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,66 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#define NEW_CURR_DIR "./chdir_test"
static int chdir_entry(void)
{
__attribute__((unused)) long path_max;
size_t size;
char *buf;
char *ptr;
__attribute__((unused)) char *old_dir;
size = 1024;
for (buf = ptr = NULL; ptr == NULL; size *= 2)
{
if ((buf = realloc(buf, size)) == NULL)
{
printf("error\n");
}
ptr = getcwd(buf, size);
if (ptr == NULL)
{
printf("error\n");
}
else
{
printf("ptr %s\n",ptr);
printf("old curr dir is %s\n", ptr);
}
mkdir(NEW_CURR_DIR, 0x777);
chdir(NEW_CURR_DIR);
ptr = getcwd(buf, size);
if (ptr == NULL)
{
printf("error\n");
}
else
{
printf("new curr dir is %s\n", ptr);
}
}
free(buf);
return 0;
}
#include <utest.h>
static void test_chdir(void)
{
uassert_int_equal(chdir_entry(), 0);
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_chdir);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.chdir_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,36 @@
#include <unistd.h>
#include <fcntl.h>
#define TRUN_SIZE 3
#define TRUNCATE_TEST_NAME "./ftruncate_to3"
static int ftruncate_entry(void)
{
int res = 0;
int fd = 0;
fd = open(TRUNCATE_TEST_NAME, O_RDWR | O_CREAT | O_APPEND);
if (fd < 0)
{
return -1;
}
write(fd, "hello", 6);
/* TODO */
res = ftruncate(fd, TRUN_SIZE);
close(fd);
return res;
}
#include <utest.h>
static void test_ftruncate(void)
{
uassert_int_equal(ftruncate_entry(), 0);
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_ftruncate);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.ftruncate_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,22 @@
#include <unistd.h>
#include <utest.h>
static void test_isatty(void)
{
int i = 0;
for (i = 0; i < 3; i++) /* 3: Number of terminals */
{
uassert_int_equal(isatty(i), 1);
}
for (i = 3; i < 32; i++) /* 32: DFS_FD_MAX */
{
uassert_int_equal(isatty(i), 0);
}
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_isatty);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.isatty_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,67 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#define FILE_TEST_NAME "./rw_file_test.txt"
#define FILE_TEST_LENGTH(x) sizeof(x)
/* close read write fsync*/
static int open_read_write_fsync_close_entry(void)
{
__attribute__((unused)) int res = 0;
int size = 0;
int fd = 0;
char s[] = "RT-Thread Programmer!";
char buffer[30];
printf("the data is: %s\n", s);
fd = open(FILE_TEST_NAME, O_RDWR | O_CREAT | O_APPEND);
if (fd < 0)
{
printf("rw_entry open error\n");
return -1;
}
write(fd, s, FILE_TEST_LENGTH(s));
/* write -> read */
read(fd,buffer,FILE_TEST_LENGTH(s));
printf("the read content is %s\n ",buffer);
/* write -> fsync -> read */
if(fsync(fd)!=0)
{
printf("fync failed\n ");
return -1;
}
read(fd,buffer,FILE_TEST_LENGTH(s));
printf("the fync read content is %s\n ",buffer);
close(fd);
/* close -> open -> read */
fd = open(FILE_TEST_NAME, O_RDONLY);
if (fd>= 0)
{
size = read(fd, buffer, sizeof(buffer));
close(fd);
printf("Read from file test.txt : %s \n", buffer);
if (size < 0)
return -1;
}
return 0;
}
#include <utest.h>
static void test_open_read_write_fsync_close(void)
{
uassert_int_equal(open_read_write_fsync_close_entry(), 0);
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_open_read_write_fsync_close);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.open_read_write_fsync_close_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,32 @@
#include <unistd.h>
#include <sys/stat.h>
#define RM_DIR "./rmdir"
static int rmdir_entry(void)
{
int res = 0;
res = mkdir(RM_DIR, 0x777);
if(res != 0)
{
return -1;
}
res = rmdir(RM_DIR);
if(res != 0)
{
return -1;
}
return res;
}
#include <utest.h>
static void test_rmdir(void)
{
uassert_int_equal(rmdir_entry(), 0);
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_rmdir);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.rmdir_tc.c", RT_NULL, RT_NULL, 10);