import RT-Thread@9217865c without bsp, libcpu and components/net
This commit is contained in:
commit
e2376a3709
1414 changed files with 390370 additions and 0 deletions
|
@ -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);
|
||||
|
66
examples/utest/testcases/posix/unistd_h/functions/chdir_tc.c
Normal file
66
examples/utest/testcases/posix/unistd_h/functions/chdir_tc.c
Normal 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);
|
||||
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
|
32
examples/utest/testcases/posix/unistd_h/functions/rmdir_tc.c
Normal file
32
examples/utest/testcases/posix/unistd_h/functions/rmdir_tc.c
Normal 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);
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue