diff --git a/device_management/gjb_S0101701GN_1.c b/device_management/gjb_S0101701GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..6988c6f4345ddb450a4e5b901eb7f45011665a02 --- /dev/null +++ b/device_management/gjb_S0101701GN_1.c @@ -0,0 +1,96 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101701GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 终端设备管理功能测试。当系统提供终端设备管理功能时, +** 测试对终端设备打开 +*********************************************************************************************************/ +#include +#include +#include +#define PATH_MAX 4096 +#define F_OK 0 +#define O_RDWR 02 + + +int open (const char *__path, int __oflag, ...); +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} + + +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + +int main(int argc, char **argv) +{ + int fd = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + + } + + /* + * 打开终端设备,参数flags为可读写权限 + */ + fd = open(pathname, O_RDWR); + if (fd == -1) { + printf("open error!\n"); + return -1; + } else { + printf( "open success!\n"); + } + + close(fd); + return 0; +} diff --git a/device_management/gjb_S0101701GN_2.c b/device_management/gjb_S0101701GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..2f14bf9b7b9308f19bf85f1bbc23811838b60071 --- /dev/null +++ b/device_management/gjb_S0101701GN_2.c @@ -0,0 +1,107 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101701GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 终端设备管理功能测试。当系统提供终端设备管理功能时, +** 测试对终端设备关闭 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +#define PATH_MAX 4096 +#include +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + int status = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开终端设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf( "open success!\n"); + } + + /* + * 关闭终端设备 + */ + status = close(fd); + if (status == -1) { + printf("close error! \n"); + return -1; + } else { + printf( "close success!\n"); + } + return 0; +} diff --git a/device_management/gjb_S0101701GN_3.c b/device_management/gjb_S0101701GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..80393526f20fe56b6ba11ab412a27ee56fd83899 --- /dev/null +++ b/device_management/gjb_S0101701GN_3.c @@ -0,0 +1,128 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101701GN_3.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 终端设备管理功能测试。当系统提供终端设备管理功能时, +** 测试对终端设备读 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +#define PATH_MAX 4096 +#include +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + int count = -2; /* 实际读出的字节数 */ + char buffer[32] = "hello world test\n"; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开终端设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error!\n"); + return -1; + } else { + printf( "open success!\n"); + } + + printf("please terminal exec \' echo 123 >/dev/ttyS100\'\n"); + + system("echo 123 >/dev/ttyS100"); + + /* + * 对终端设备进行读操作 + */ + count = read(fd, buffer, strlen(buffer)); + if(count == -1) { + printf("read error!\n"); + close(fd); + return -1; + } else { + printf("read success\n"); + } + + buffer[strlen(buffer) - 1] = '\0'; + if (0 >= count) { + printf("[ERROR] read serial(%s)\n", "/dev/console"); + close(fd); + return 0; + } else { + printf("[OK] read serial(%s), readed(%d), content(%s)\n", + "/dev/console", count, buffer); + } + + /* + * 关闭终端设备 + */ + close(fd); + return 0; +} diff --git a/device_management/gjb_S0101701GN_4.c b/device_management/gjb_S0101701GN_4.c new file mode 100644 index 0000000000000000000000000000000000000000..565dfb34dd5306406ded946e20df64fafe0149b1 --- /dev/null +++ b/device_management/gjb_S0101701GN_4.c @@ -0,0 +1,121 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101701GN_4.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 终端设备管理功能测试。当系统提供终端设备管理功能时, +** 测试对终端设备写 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find);} + + + +int main(int argc, char **argv) +{ + int fd = -2; + int count = -2; + char buffer[] = "hello world test \n"; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开终端设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } + + /* + * 对终端设备进行读操作 + */ + count = write(fd, buffer, strlen(buffer)); + if(count == -1) { + printf("write error! \n"); + close(fd); + return -1; + } else { + printf( "write success\n"); + } + + /* + * 关闭终端设备 + */ + close(fd); + if ((strlen(buffer))!= count) { + printf("[ERROR] write serial(%s), SIMPLE_MSG=%d\n", + "/dev/console", (int)strlen(buffer)); + close(fd); + return -1; + } else { + printf("[OK] write serial(%s), written(%d)\n", + "/dev/console", count); + } + return 0; +} + diff --git a/device_management/gjb_S0101701GN_5.c b/device_management/gjb_S0101701GN_5.c new file mode 100644 index 0000000000000000000000000000000000000000..0ee994d35cbe79fd7549a4ad9f93373c3f5c26af --- /dev/null +++ b/device_management/gjb_S0101701GN_5.c @@ -0,0 +1,116 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101701GN_5.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 终端设备管理功能测试。当系统提供终端设备管理功能时, +** 测试对终端设备控制操作 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ioccom.h" +#include +//#include "gjb.h" + +#include +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + + +int main(int argc, char **argv) +{ + unsigned int baudrate; + int ret; + int fd = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开终端设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf( "open success!\n"); + } + + /* + * 对终端设备进行控制操作 + */ + ret = ioctl(fd, FIONREAD, (void *) &baudrate); + if(ret == -1) { + printf("ioctl error! \n"); + close(fd); + return -1; + } else { + printf( "ioctl success\n"); + } + + close(fd); + return 0; +} diff --git a/device_management/gjb_S0101702GN_1.c b/device_management/gjb_S0101702GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..22f1f890fd3899f0183bdf428dd74a75eb7d0acf --- /dev/null +++ b/device_management/gjb_S0101702GN_1.c @@ -0,0 +1,97 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101702GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 字符设备管理功能测试。当系统提供字符设备管理功能时, +** 测试对字符设备打开。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +#include +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} + +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开字符设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + + if (fd == -1) { + printf("open error!\n"); + return -1; + } else { + printf( "open success!\n"); + close(fd); + return 0; + } +} diff --git a/device_management/gjb_S0101702GN_2.c b/device_management/gjb_S0101702GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..52badd8d24c5955b1303852fb9f37e2484cf92a0 --- /dev/null +++ b/device_management/gjb_S0101702GN_2.c @@ -0,0 +1,109 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101702GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 字符设备管理功能测试。当系统提供字符设备管理功能时, +** 测试对字符设备关闭。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} + +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + + +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + int status = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开字符设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 关闭字符设备,参数flags为0x2即可读写 + */ + status = close(fd); + if (status == -1) { + printf("close error! \n"); + return -1; + } else { + printf("close success! \n"); + } + + return 0; +} + diff --git a/device_management/gjb_S0101702GN_3.c b/device_management/gjb_S0101702GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..ad6a749b92ecfe90c1335d803d3cc06724edf11f --- /dev/null +++ b/device_management/gjb_S0101702GN_3.c @@ -0,0 +1,125 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101702GN_3.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 字符设备管理功能测试。当系统提供字符设备管理功能时, +** 测试对字符设备读。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +#define PATH_MAX 4096 +#include +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} + +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + int count = -2; /* 实际读出的字节数 */ + char buffer[] = "hello world test \n"; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开字符设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 对字符设备进行读操作 + */ + count = read(fd, buffer, strlen(buffer)); + if(count == -1) { + printf("open error! \n"); + close(fd); + return -1; + + } else { + printf( "read success\n"); + } + + buffer[strlen(buffer) - 1] = '\0'; + if (0 >= count) { + printf("[ERROR] read serial(%s)\n", "/dev/console"); + close(fd); + return -1; + + } else { + printf("[OK] read serial(%s), readed(%d), content(%s)\n", + "/dev/ttyS100", count, buffer); + } + + close(fd); + + return 0; +} diff --git a/device_management/gjb_S0101702GN_4.c b/device_management/gjb_S0101702GN_4.c new file mode 100644 index 0000000000000000000000000000000000000000..215ba069da63695cba1f228a4afb743a887c96ae --- /dev/null +++ b/device_management/gjb_S0101702GN_4.c @@ -0,0 +1,127 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101702GN_4.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 字符设备管理功能测试。当系统提供字符设备管理功能时, +** 测试对字符设备写。 +*********************************************************************************************************/ +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#define PATH_MAX 4096 + +//#include "gjb.h" + +#include +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + + +int main(int argc, char **argv) +{ + int fd = -2; + int count = -2; + char buffer[] = "hello world test \n"; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开字符设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 对字符设备进行写操作 + */ + count = write(fd, buffer, strlen(buffer)); + + if(count == -1) { + printf("write error! \n"); + close(fd); + return -1; + } else { + printf( "write success\n"); + } + + /* + * 关闭字符设备 + */ + close(fd); + if ((strlen(buffer))!= count) { + printf("[ERROR] write serial(%s),SIMPLE_MSG=%d\n", + "/dev/console", (int)strlen(buffer)); + return -1; + } else { + printf("[OK] write serial(%s), written(%d)\n", + "/dev/console", count); + } + + return 0; +} + diff --git a/device_management/gjb_S0101702GN_5.c b/device_management/gjb_S0101702GN_5.c new file mode 100644 index 0000000000000000000000000000000000000000..228d044387473c0cb9dc3d544ad4945bb6416c0b --- /dev/null +++ b/device_management/gjb_S0101702GN_5.c @@ -0,0 +1,119 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101702GN_5.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 字符设备管理功能测试。当系统提供字符设备管理功能时, +** 测试对字符设备控制操作。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ioccom.h" +#include +#include + +//#include "gjb.h" + +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + + + +int main(int argc, char **argv) +{ + unsigned int nread; + int ret; + int fd = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 对字符设备进行控制操作 + */ + ret = ioctl(fd, FIONREAD, (void *) &nread); + if (ret == -1) { + printf("ioctl error! \n"); + close(fd); + return -1; + + } else { + printf( "ioctl success\n"); + } + + close(fd); + return 0; +} diff --git a/device_management/gjb_S0101703GN_1.c b/device_management/gjb_S0101703GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..73d5873ff22b055c6149ef851c1aa4e4f450d06d --- /dev/null +++ b/device_management/gjb_S0101703GN_1.c @@ -0,0 +1,213 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101703GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 块设备管理功能测试。当系统提供块设备管理功能时,测试 +** 对块设备打开和关闭。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +//#include"gjbext.h" +#define TEST_MOUNT_DEV "/dev/sda4" +#define TEST_MOUNT_PATH "/home/wujun/media" +#define TEST_MOUNT_FS "vfat" + + +int fs_init; +#define PATH_MAX 4096 +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int umount (char* src) +{ + char cmd[1204]; + int ret = 0; + sprintf(cmd, "umount %s\n", src); + // printf("get in user unmount\n"); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int mount(char *type, char *src, char *dest) +{ + char cmd[PATH_MAX]; + int ret = 0; + if (src == NULL) + { + errno = ENOENT; + return -1; + } + if (type == NULL) + { + errno = EINVAL; + return -1; + } + if (dest == NULL) + { + errno = ENOENT; + return -1; + } + if (strlen(src) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(type) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(dest) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (access(dest, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENOENT; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (dest == NULL || (access(src, F_OK) != 0)) + { + errno = ENOENT; + return -1; + } + if (fs_init == 0) + init_filesystem(); + sprintf(cmd, "mount %s %s\n", src, dest); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} +int format(const char *fsname,const char *devname) +{ + if ((fsname == NULL) ||(devname == NULL)) + { + return -1; + } + // printf("get in user mount\n"); + char cmd[1204]; + sprintf(cmd, "rm %s/* -rf\n", devname); + system(cmd); + return 0; +} + +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + int err = 0; + + /* + * 如果这个目录已经存在, 先卸载 + */ + if (access(TEST_MOUNT_PATH, R_OK) == 0) { + umount(TEST_MOUNT_PATH); + } + /* + * 挂载文件系统到 TEST_MOUNT_PATH 路径 + */ + int ret = mount(TEST_MOUNT_FS, TEST_MOUNT_DEV, TEST_MOUNT_PATH); + if (ret < 0) { + printf("mount failed. errno = %d\n", errno); + return -1; + + } else { + printf("mount sucess\n"); + } + + /* + * 格式化块设备 + */ + ret = format(TEST_MOUNT_FS, TEST_MOUNT_PATH); + if (ret == 0) { + printf("format success\n"); + + } else { + printf("format failed. errno = %d\n", errno); + return -1; + } + + /* + * 打开文件 + */ + fd = open(TEST_MOUNT_PATH"/1.txt", 0x2 | O_CREAT, 0666); + if (fd == -1) { + printf("open error!\n"); + return -1; + + } else { + printf("open success!\n"); + } + + /* + * 关闭文件 + */ + ret = close(fd); + if (ret == -1) { + printf("close error!\n"); + err++; + + } else { + printf( "close success!\n"); + } + + /* + * 删除1.txt文件 + */ + unlink(TEST_MOUNT_PATH "/1.txt"); + + /* + * 卸载文件系统 + */ + ret = umount(TEST_MOUNT_PATH); + if(ret < 0) { + printf("umount failed. errno = %d\n", errno); + err++; + + } else { + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("umount success\n"); + + } else { + printf("umount failed. errno = %d\n", errno); + err++; + } + } + + if (err == 0) { + return 0; + } + + return -1; +} diff --git a/device_management/gjb_S0101703GN_2.c b/device_management/gjb_S0101703GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..ecaa5cb03dd62c6e8f5683c13d810f1cbd7bb2dd --- /dev/null +++ b/device_management/gjb_S0101703GN_2.c @@ -0,0 +1,241 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101703GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 块设备管理功能测试。当系统提供块设备管理功能时,测试 +** 对块设备读操作。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +int fs_init; +#define PATH_MAX 4096 +#define TEST_MOUNT_DEV "/dev/sda4" +#define TEST_MOUNT_PATH "/home/wujun/media" +#define TEST_MOUNT_FS "vfat" + +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int umount (char* src) +{ + char cmd[1204]; + int ret = 0; + sprintf(cmd, "umount %s\n", src); + // printf("get in user unmount\n"); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + + +int mount(char *type, char *src, char *dest) +{ + char cmd[PATH_MAX]; + int ret = 0; + if (src == NULL) + { + errno = ENOENT; + return -1; + } + if (type == NULL) + { + errno = EINVAL; + return -1; + } + if (dest == NULL) + { + errno = ENOENT; + return -1; + } + if (strlen(src) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(type) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(dest) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (access(dest, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENOENT; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (dest == NULL || (access(src, F_OK) != 0)) + { + errno = ENOENT; + return -1; + } + if (fs_init == 0) + init_filesystem(); + sprintf(cmd, "mount %s %s\n", src, dest); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int format(const char *fsname,const char *devname) +{ + if ((fsname == NULL) ||(devname == NULL)) + { + return -1; + } + // printf("get in user mount\n"); + char cmd[1204]; + sprintf(cmd, "rm %s/* -rf\n", devname); + system(cmd); + return 0; +} + + +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + int count = -2; /* 实际读出的字节数 */ + int err = 0; + char buffer[] = "hello world test \n"; + + /* + * 如果这个目录已经存在, 先卸载 + */ + if (access(TEST_MOUNT_PATH, R_OK) == 0) { + umount(TEST_MOUNT_PATH); + } + /* + * 挂载文件系统到 TEST_MOUNT_PATH 路径 + */ + int ret = mount(TEST_MOUNT_FS, TEST_MOUNT_DEV, TEST_MOUNT_PATH); + if(ret < 0) { + printf("mount failed. errno = %d\n", errno); + err++; + } else { + printf("mount sucess\n"); + } + + /* + * 格式化块设备 + */ + ret = format(TEST_MOUNT_FS, TEST_MOUNT_PATH); + if(ret == 0) { + printf("format success\n"); + } else { + printf("format failed. errno = %d\n", errno); + err++; + } + + /* + * 打开文件 + */ + fd = open("/home/wujun/media/1.txt", O_RDWR | O_CREAT, 0333); + if (fd == -1) { + printf("open error! \n"); + err++; + } else { + printf("open success! \n"); + } + + /* + * 写数据 + */ + count = write(fd, buffer, strlen(buffer)); + if (count == -1) { + printf("write error! \n"); + err++; + } else { + printf("write success! \n"); + } + + lseek(fd, 0, 0); + + /* + * 读数据 + */ + count = read(fd, buffer, strlen(buffer)); + if(count == -1) { + printf("read error\n"); + err++; + } else { + printf( "read success\n"); + } + + buffer[strlen(buffer) - 1] = '\0'; + if (0 >= count) { + printf("[ERROR] read serial(%s)\n","/media/vdd0/1.txt"); + err++; + } else { + printf("[OK] read serial(%s), readed(%d), content(%s)\n", + "/media/vdd0/1.txt", count, buffer); + } + + /* + * 关闭文件 + */ + ret = close(fd); + if (ret == -1) { + printf("close error!\n"); + err++; + } else { + printf( "close success!\n"); + } + + /* + * 删除1.txt文件 + */ + unlink("/media/vdd0/1.txt"); + + /* + * 卸载文件系统 + */ + ret = umount(TEST_MOUNT_PATH); + if(ret < 0) { + printf("umount failed. errno = %d\n", errno); + err++; + } else { + ret = umount(TEST_MOUNT_PATH); + if(ret < 0) { + printf("umount success\n"); + } else { + printf("umount failed. errno = %d\n", errno); + err++; + } + } + + if (err == 0) { + return 0; + } + return -1; +} diff --git a/device_management/gjb_S0101703GN_3.c b/device_management/gjb_S0101703GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..64c99576eff5f53dac88351f3ea04e42c3049e5a --- /dev/null +++ b/device_management/gjb_S0101703GN_3.c @@ -0,0 +1,213 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101703GN_4.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 块设备管理功能测试。当系统提供块设备管理功能时,测试 +** 对块设备控制操作。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +int fs_init; +#define PATH_MAX 4096 + + +//#include "gjbext.h" +#define TEST_MOUNT_DEV "/dev/sda4" +#define TEST_MOUNT_PATH "/home/wujun/media" +#define TEST_MOUNT_FS "vfat" + +int format(const char *fsname,const char *devname) +{ + if ((fsname == NULL) ||(devname == NULL)) + { + return -1; + } + // printf("get in user mount\n"); + char cmd[1204]; + sprintf(cmd, "rm %s/* -rf\n", devname); + system(cmd); + return 0; +} + +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int mount(char *type, char *src, char *dest) +{ + char cmd[PATH_MAX]; + int ret = 0; + if (src == NULL) + { + errno = ENOENT; + return -1; + } + if (type == NULL) + { + errno = EINVAL; + return -1; + } + if (dest == NULL) + { + errno = ENOENT; + return -1; + } + if (strlen(src) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + + } + if (strlen(type) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(dest) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (access(dest, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENOENT; + return -1; + } + + if (fs_init == 0) + init_filesystem(); + sprintf(cmd, "mount %s %s\n", src, dest); + // printf("%s\n", cmd); + ret = system(cmd); + } + +int umount (char* src) +{ + char cmd[1204]; + int ret = 0; + sprintf(cmd, "umount %s\n", src); + // printf("get in user unmount\n"); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int main(int argc, char **argv) +{ + unsigned int nread; /* 缓冲区返回的字节数*/ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + + int err = 0; + + /* + * 如果这个目录已经存在, 先卸载 + */ + if (access(TEST_MOUNT_PATH, R_OK) == 0) { + umount(TEST_MOUNT_PATH); + } + /* + * 挂载文件系统到 TEST_MOUNT_PATH 路径 + */ + int ret = mount(TEST_MOUNT_FS, TEST_MOUNT_DEV, TEST_MOUNT_PATH); + if(ret < 0) { + printf("mount failed. errno = %d\n", errno); + err++; + } else { + printf("mount sucess\n"); + } + + /* + * 格式化块设备 + */ + ret = format(TEST_MOUNT_FS, TEST_MOUNT_PATH); + if(ret == 0) { + printf("format success\n"); + } else { + printf("format failed. errno = %d\n", errno); + err++; + } + + /* + * 打开文件 + */ + fd = open("/home/wujun/media/1.txt", 0x2 | O_CREAT, 0666); + if (fd == -1) { + printf("open error!\n"); + err++; + } else { + printf("open success!\n"); + } + + /* + * 文件里面有多少字节要被读取。值放在nread裡面了 + */ + ret = ioctl(fd, FIONREAD, (void *) &nread); + if (ret == -1) { + printf("ioctl error! \n"); + err++; + } else { + printf("ioctl success! \n"); + } + + /* + * 关闭文件 + */ + ret = close(fd); + if (ret == -1) { + printf("close error! \n"); + err++; + } else { + printf( "close success!\n"); + } + + /* + * 删除文件 + */ + unlink("/media/vdd0/1.txt"); + + /* + * 卸载文件系统 + */ + ret = umount(TEST_MOUNT_PATH); + if(ret < 0) { + printf("umount failed. errno = %d\n", errno); + err++; + } else { + ret = umount(TEST_MOUNT_PATH); + if(ret < 0) { + printf("umount success\n"); + } else { + printf("umount failed. errno = %d\n", errno); + err++; + } + } + + if (err == 0) { + return 0; + } + return -1; +} + diff --git a/device_management/gjb_S0101703GN_4.c b/device_management/gjb_S0101703GN_4.c new file mode 100644 index 0000000000000000000000000000000000000000..c1e8458ae549b48da93ca0ca67982453f9840ed7 --- /dev/null +++ b/device_management/gjb_S0101703GN_4.c @@ -0,0 +1,232 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101703GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 块设备管理功能测试。当系统提供块设备管理功能时,测试 +** 对块设备写操作。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +int fs_init; +#define PATH_MAX 4096 +#define TEST_MOUNT_DEV "/dev/sda4" +#define TEST_MOUNT_PATH "/home/wujun/media" +#define TEST_MOUNT_FS "vfat" + +int format(const char *fsname,const char *devname) +{ + if ((fsname == NULL) ||(devname == NULL)) + { + return -1; + } + // printf("get in user mount\n"); + char cmd[1204]; + sprintf(cmd, "rm %s/* -rf\n", devname); + system(cmd); + return 0; +} + +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int mount(char *type, char *src, char *dest) +{ + char cmd[PATH_MAX]; + int ret = 0; + if (src == NULL) + { + errno = ENOENT; + return -1; + } + if (type == NULL) + { + errno = EINVAL; + return -1; + } + if (dest == NULL) + { + errno = ENOENT; + return -1; + } + if (strlen(src) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + + } + if (strlen(type) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(dest) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (access(dest, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENOENT; + return -1; + } + + if (fs_init == 0) + init_filesystem(); + sprintf(cmd, "mount %s %s\n", src, dest); + // printf("%s\n", cmd); + ret = system(cmd); + } + +int umount (char* src) +{ + char cmd[1204]; + int ret = 0; + sprintf(cmd, "umount %s\n", src); + // printf("get in user unmount\n"); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + + +int main(int argc, char **argv) +{ + int fd = -2; /* 设置为OS_OK和OS_ERROR以外的值 */ + int count = -2; /* 实际读出的字节数 */ + int err = 0; + char buffer[] = "hello world test \n"; + + /* + * 如果这个目录已经存在, 先卸载 + */ + if (access(TEST_MOUNT_PATH, R_OK) == 0) { + umount(TEST_MOUNT_PATH); + } + + /* + * 挂载文件系统到 TEST_MOUNT_PATH 路径 + */ + int ret = mount(TEST_MOUNT_FS, TEST_MOUNT_DEV, TEST_MOUNT_PATH); + if(ret < 0) { + printf("mount failed. errno = %d\n", errno); + err++; + } else { + printf("mount sucess\n"); + } + + /* + * 格式化块设备 + */ + ret = format(TEST_MOUNT_FS, TEST_MOUNT_PATH); + if(ret == 0) { + printf("format success\n"); + } else { + printf("format failed. errno = %d\n", errno); + err++; + } + + /* + * 打开文件 + */ + fd = open("/home/wujun/media/1.txt", O_RDWR | O_CREAT, 0333); + if (fd == -1) { + printf("open error! \n"); + err++; + } else { + printf("open success! \n"); + } + + /* + * 写数据 + */ + count = write(fd, buffer, strlen(buffer)); + if (count == -1) { + printf("write error! \n"); + err++; + } else { + printf("write success! \n"); + } + + lseek(fd, 0, 0); + + /* + * 读数据 + */ + count = read(fd, buffer, strlen(buffer)); + if(count == -1) { + printf("read error\n"); + err++; + } else { + printf( "read success\n"); + } + + buffer[strlen(buffer) - 1] = '\0'; + if (0 >= count) { + printf("[ERROR] read serial(%s)\n","/media/vdd0/1.txt"); + err++; + } else { + printf("[OK] read serial(%s), readed(%d), content(%s)\n", + "/media/vdd0/1.txt", count, buffer); + } + + /* + * 关闭文件 + */ + ret = close(fd); + if (ret == -1) { + printf("close error!\n"); + err++; + } else { + printf( "close success!\n"); + } + + /* + * 删除1.txt文件 + */ + unlink("/media/vdd0/1.txt"); + + /* + * 卸载文件系统 + */ + ret = umount(TEST_MOUNT_PATH); + if(ret < 0) { + printf("umount failed. errno = %d\n", errno); + err++; + } else { + ret = umount(TEST_MOUNT_PATH); + if(ret < 0) { + printf("umount success\n"); + } else { + printf("umount failed. errno = %d\n", errno); + err++; + } + } + + if (err == 0) { + return 0; + } + return -1; +} diff --git a/device_management/gjb_S0101704GN_1.c b/device_management/gjb_S0101704GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..875e431c61abfc103f47887455cd07696e7dcf0b --- /dev/null +++ b/device_management/gjb_S0101704GN_1.c @@ -0,0 +1,132 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101704GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 设备信息查看能力测试。查看指定设备信息,比对查看 +** 结果与设备实际信息是否相符,验证操作系统设备信息 +** 查看功能的正确性。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +int fs_init; +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + + +int main(int argc, char **argv) +{ + struct stat buf = {0}; + int fd = -2; + int ret = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 获取设备文件信息 + */ + ret = stat(pathname, &buf); + if (ret == -1) { + printf("gain device message fail \n"); + close(fd); + return -1; + + } else { + printf("gain device message success!\n"); + } + + /* + * 成功获取了stat结构体,从中可以得到各种属性信息了 + */ + printf("inode = %ld.\n", buf.st_ino); + printf("size = %ld bytes.\n", buf.st_size); + printf("st_blksize = %ld.\n", buf.st_blksize); + + if (buf.st_uid != 0 || buf.st_rdev != 1) { + printf("gain device message fail \n"); + close(fd); + return -1; + } + /* + * 关闭设备,参数flags为0x2即可读写 + */ + close(fd); + return 0; +} diff --git a/device_management/gjb_S0101705GN.c b/device_management/gjb_S0101705GN.c new file mode 100644 index 0000000000000000000000000000000000000000..a277836d0192caf193b551d978d7ceb1f92d8e5d --- /dev/null +++ b/device_management/gjb_S0101705GN.c @@ -0,0 +1,273 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101706GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 设备异步访问功能测试。编制测试用例代码,测试设备 +** 异步访问能力。 +*********************************************************************************************************/ + +#ifdef SYLIXOS + +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +//#include "gjbext.h" +#include +#define F_OK 0 +ssize_t write (int __fd, const void *__buf, size_t __n) __wur; +//int pthread_getname(pthread_t thread,char *thread_name); +int pthread_getname_np (pthread_t __target_thread, char *__buf, + size_t __buflen); +int pthread_setname_np (pthread_t __target_thread, const char *__name); + +#define PATH_MAX 4096 +/********************************************************************************************************* + 宏定义 +*********************************************************************************************************/ +#define TEST_THREAD_NAME "t_openclose" + +/********************************************************************************************************* + 全局变量定义 +*********************************************************************************************************/ +static int err_count_dm_705 = 0; +/********************************************************************************************************* +** 函数名称: t1 +** 功能描述: 线程函数 +** 输 入 : arg : 线程参数 +** 输 出 : ERROR +** 全局变量: +** 调用模块: +*********************************************************************************************************/ +int pthread_getname(pthread_t thread, char *thread_name) +{ + if (thread <= 0) + { + errno = ESRCH; + return ESRCH; + } + if (thread_name == NULL) + { + errno =EINVAL; + return EINVAL; + } + + return pthread_getname_np(thread, thread_name, 64); +} + +void *t1_dm_705 (void *arg) +{ + int fd = (int)(long)arg; + char *str = "test select function."; + ssize_t ret; + int i; + + for (i = 0; i < 10; ++i) { + ret = write(fd, str, strlen(str) + 1); + printf("write data: %s\n", str); + printf("write data len: %ld\n", ret); + + sleep(1); + } + + return (NULL); +} +/***************************pthread_setname_np +** 功能描述: 线程函数 +** 输 入 : arg : 线程参数 +** 输 出 : ERROR +** 全局变量: +** 调用模块: +*********************************************************************************************************/ +void *t2_dm_705 (void *arg) +{ + int ret; + int fd = (int)(long)arg; + fd_set set; + char buf[64] = {0}; + struct timeval time; + ssize_t stlen; + + while (1) + { + FD_ZERO(&set); + FD_SET(fd, &set); + + time.tv_sec = 1; + time.tv_usec = 0; + + /* + * select函数可以实现非阻塞 + */ + ret = select(fd + 1, &set, NULL, NULL, &time); + if (ret < 0) { + printf("select error return value: %d\n", ret); + } else if (ret == 0) { + printf("select timeout return value: %d\n", ret); + break; + } else { + printf( "select number of files changed: %d\n", ret); + } + + stlen = read(fd, buf, 64); + if (stlen <= 0) { + printf("read error return: %ld\n", stlen); + } else { + printf("read file content: %s\n", buf); + } + } + + return (NULL); +} + +#include +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + + + +/********************************************************************************************************* +** 函数名称: main +** 功能描述: 主函数 +** 输 入 : argc, argv[] +** 输 出 : ERROR +** 全局变量: +** 调用模块: +*********************************************************************************************************/ + + +int main(int argc, char **argv) +{ + pthread_t tid, tid1; + int ret; + void *status; + int fd; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开设备,参数flags为0x2即可读写 + */ + fd = open(pathname, O_RDWR); + if (fd < 0) { + err_count_dm_705++; + printf("open error! \n"); + return-1; + } else { + printf("open dev file /dev/testdev success fd: %d.\n", fd); + } + + /* + * 线程创建 + */ + ret = pthread_create(&tid, NULL, t1_dm_705, (void *)(long)fd); + if (ret < 0) { + printf("pthread_create fail!\n"); + close(fd); + return-1; + } else { + printf( "pthread_create success!\n"); + } + + /* + * 修改线程名字 + */ + ret = pthread_setname_np(tid, TEST_THREAD_NAME); + if (ret != 0) { + printf("pthread_setname_np"); + close(fd); + return-1; + } + + /* + * 线程创建 + */ + ret = pthread_create(&tid1, NULL, t2_dm_705, (void *)(long)fd); + if (ret < 0) { + printf("pthread_create failed"); + close(fd); + return-1; + } + + /* + * 线程合并 + */ + pthread_join(tid, NULL); + pthread_join(tid1, &status); + + /* + * 关闭设备 + */ + close(fd); + + if (err_count_dm_705) { + fprintf(stderr, "test error [%d].\n", err_count_dm_705); + return-1; + } + + return 0; +} +/********************************************************************************************************* + END +*********************************************************************************************************/ diff --git a/device_management/gjb_S0101706GN_1.c b/device_management/gjb_S0101706GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..e4145e0eaa9aff862df2f7c91ea3a590fc98c715 --- /dev/null +++ b/device_management/gjb_S0101706GN_1.c @@ -0,0 +1,113 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101706GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 设备访问接口测试。编制测试用例代码,验证系统提供的 +** 设备访问统一接口打开。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +int fs_init; +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + +int main(int argc, char **argv) +{ + int fd = -2; + int status = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 关闭设备 + */ + status = close(fd); + if (status == -1) { + printf("gain device message fail \n"); + close(fd); + return -1; + } else { + printf("gain device message success!\n"); + } + + return 0; +} diff --git a/device_management/gjb_S0101706GN_2.c b/device_management/gjb_S0101706GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..a9d4d84277a5f6737eae348091091e5a646c9522 --- /dev/null +++ b/device_management/gjb_S0101706GN_2.c @@ -0,0 +1,153 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101706GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 设备访问接口测试。编制测试用例代码,验证系统提供的 +** 设备访问统一接口写测试。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +int fs_init; +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + + + + + +int main(int argc, char **argv) +{ + int fd = -2; + int count1 = -2; + int count2 = -2; + char buffer[] = "hello world test \n"; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 对设备进行写测试 + */ + count1 = write(fd, buffer, strlen(buffer)); + if (fd == -1) { + printf("write error! \n"); + return -1; + } else { + printf("write success! \n"); + } + + if ((strlen(buffer))!= count1) { + printf("[ERROR] write serial(%s), SIMPLE_MSG=%zd\n", + "/dev/console", strlen(buffer)); + close(fd); + return -1; + } else { + printf("[OK] write serial(%s), written(%d)\n", + "/dev/console", count1); + } + + /* + * 对设备进行读测试 + */ + count2 = read(fd, buffer, strlen(buffer)); + if (fd == -1) { + printf("read error! \n"); + close(fd); + return -1; + + } else { + printf("read success! \n"); + } + + buffer[strlen(buffer) - 1] = '\0'; + if (0 >= count2) { + printf("[ERROR] read serial(%s)\n", "/dev/console"); + close(fd); + return -1; + + } else { + printf("[OK] read serial(%s), readed(%d), content(%s)\n", + "/dev/console", count2, buffer); + } + + close(fd); + return 0; +} diff --git a/device_management/gjb_S0101706GN_3.c b/device_management/gjb_S0101706GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..2ad2446af71972ccf7306f10efc8c1527fcf7517 --- /dev/null +++ b/device_management/gjb_S0101706GN_3.c @@ -0,0 +1,122 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101706GN_3.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 设备访问接口测试。编制测试用例代码,验证系统提供的 +** 设备访问统一接口,至少包括设备控制操作接口。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ioccom.h" +#include +//#include "gjb.h" + +//#include "gjb.h" +//#include "gjbext.h" +int fs_init; +#define PATH_MAX 4096 +size_t strlcpy(char *dest, const char *src, size_t size) +{ + return (size_t)strcpy(dest, src); +} +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int get_device (char *pathname) +{ + int tty_i = 0; + char ttypath[PATH_MAX]; + int find = 0; + + for (tty_i = 0; tty_i < 20; tty_i++) { + sprintf(ttypath, "/dev/ttyS%d", tty_i); + /* + * 首先查看 /dev/ttySx 是否存在 + */ + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 再次查看 /dev/ttyUSBx 是否存在 + */ + sprintf(ttypath, "/dev/ttyUSB%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + + /* + * 最后查看 /dev/ttyPCIx 是否存在 + */ + sprintf(ttypath, "/dev/ttyPCI%d", tty_i); + if (access(ttypath, F_OK) == 0) { + strlcpy(pathname, ttypath, PATH_MAX); + find = 1; + break; + } + } + + return (find); +} + +int main(int argc, char **argv) +{ + unsigned int nread; + int fd = -2; + int ret = -2; + char pathname[PATH_MAX]; + + if (get_device(pathname) == 0) { + printf("get device error!\n"); + return -1; + } + + /* + * 打开设备,参数flags为0x2即可读写 + */ + fd = open(pathname, 0x2, 0644); + if (fd == -1) { + printf("open error! \n"); + return -1; + } else { + printf("open success! \n"); + } + + /* + * 对设备进行控制操作 + */ + ret = ioctl(fd, FIONREAD, (void *) &nread); + if (ret == -1) { + printf("ioctl error! \n"); + close(fd); + return -1; + } else { + printf("ioctl success! \n"); + } + + close(fd); + return 0; +} diff --git a/file_system/gjb_S0101601GN_1.c b/file_system/gjb_S0101601GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..ed1e321511d3766f94bd644902dbac7a5a420096 --- /dev/null +++ b/file_system/gjb_S0101601GN_1.c @@ -0,0 +1,101 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101601GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件动态创建功能测试。按照操作系统提供的文件系统类 +** 型要求,调用文件创建接口,测试不同条件下文件创建功 +** 能;文件创建成功,并且可以被打开和查询。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int fd; + char buf[32]; + int ret; + + /* + * 创建文件 + */ + fd = creat("./file", 0777); + if(fd < 0) { + printf("creat error"); + return -1; + + } else { + printf( "creat file success!\n"); + close(fd); + } + + fd = open("./file", O_RDWR, 0666); + + ret = write(fd, "this is a test", strlen("this is a test")); + if (ret < 0) { + printf("write file error"); + close(fd); + unlink("./file"); + return -1; + } else { + printf("write file success\n"); + } + + /* + * 将文件内容同步到磁盘 + */ + fsync(fd); + lseek(fd, SEEK_SET, 0); + + /* + * 查询文件内容是否与写入的一致 + */ + ret = read(fd, buf, 32); + if (ret < 0) { + printf("read file error"); + close(fd); + unlink("./file"); + return -1; + + } else { + if (strncmp(buf, "this is a test", 14)) { + printf("check file content error\n"); + close(fd); + unlink("./file"); + return -1; + } + } + + close(fd); + + /* + * 创建一个同名文件, 这里应该失败返回-1 + */ + fd = creat("./file", 0777); + if (fd >= 0) { + printf( "creat same file test sucess!\n"); + } else { + printf("creat error\n"); + close(fd); + unlink("./file"); + return -1; + } + + unlink("./file"); + + return 0; +} diff --git a/file_system/gjb_S0101601GN_2.c b/file_system/gjb_S0101601GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..eb0452d76a558966bbf671fc5ed504bd446b88eb --- /dev/null +++ b/file_system/gjb_S0101601GN_2.c @@ -0,0 +1,77 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101601GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 目录动态创建功能测试。按照操作系统提供的文件系统类 +** 型要求,调用目录创建接口,测试不同条件下目录创建功 +** 能;目录创建成功,并且可以被打开和查询。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int ret1; + int ret2; + int fd; + + /* + * 创建目录 + */ + ret1 = mkdir("./mkdirdir",0777); + if(ret1 != 0) { + printf("mkdir error"); + return -1; + } else { + printf( "creat directory success!\n"); + } + + /* + * 在目录下面创建一个文件 + */ + mkdir("./mkdirdir1",0777); + + fd = creat("./mkdirdir1/file", 0777); + if (fd < 0) { + printf("creat file failure in dir.\n"); + rmdir("./mkdirdir"); + return -1; + } else { + printf( "creat file success in mkdirdir1!\n"); + } + + /* + * 删除目录 + */ + ret2 = rmdir("./mkdirdir"); + if(ret2 != 0) { + printf("rmdir error"); + unlink("./mkdirdir1/file"); + rmdir("./mkdirdir1"); + return -1; + + } else { + printf( "delete directory success!\n"); + } + + /* + * 删除测试完成的文件 + */ + unlink("./mkdirdir1/file"); + rmdir("./mkdirdir1"); + + return 0; +} diff --git a/file_system/gjb_S0101602GN_1.c b/file_system/gjb_S0101602GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..5d146ff42bc1aa9748643c18d87dc1a9a4a912c9 --- /dev/null +++ b/file_system/gjb_S0101602GN_1.c @@ -0,0 +1,102 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101602GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件打开和关闭功能测试。根据文件系统规范要求,在已经挂 +** 载的文件系统上打开已经存在的文件或目录,测试不同类型的 +** 打开模式,然后关闭文件或目录;在符合文件系统规范时,文 +** 件或目录打开成功,并且返回文件或目录描述符。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + + + +#define FILE_PATH "./test.txt" + +int main(int argc, char **argv) +{ + int ret; + int fd; + + /* + * 打开文件 + */ + fd = open(FILE_PATH, O_RDWR | O_CREAT | O_EXCL, 0666); + if (fd < 0) { + printf("open error\n"); + return -1; + + } else { + printf("open RDWR success\n"); + } + + /* + * 关闭文件 + */ + ret = close(fd); + unlink(FILE_PATH); + if(ret != 0) { + printf("close error\n"); + return -1; + } else { + printf( "close RDWR success\n"); + } + + /* + * 只读方式打开文件 + */ + fd = open(FILE_PATH, O_RDONLY | O_CREAT | O_EXCL, 0666); + if (fd < 0) { + printf("open error"); + return -1; + + } else { + printf("open RDONLY success\n"); + } + + ret = close(fd); + unlink(FILE_PATH); + if(ret != 0) { + printf("close error"); + return -1; + } else { + printf( "close RDONLY success\n"); + } + + /* + * 只写方式打开文件 + */ + fd = open(FILE_PATH, O_WRONLY | O_CREAT | O_EXCL, 0666); + if (fd < 0) { + printf("open error\n"); + return -1; + } else { + printf("open WRONLY success\n"); + } + + ret = close(fd); + unlink(FILE_PATH); + if(ret != 0) { + printf("close error"); + return -1; + } else { + printf( "close WRONLY success\n"); + } + + return 0; +} + diff --git a/file_system/gjb_S0101602GN_2.c b/file_system/gjb_S0101602GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..fb82faa507a1800e8ad5f014cf08610939092d6e --- /dev/null +++ b/file_system/gjb_S0101602GN_2.c @@ -0,0 +1,92 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101602GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 目录打开和关闭功能测试。根据文件系统规范要求,在已经挂 +** 载的文件系统上打开已经存在的文件或目录,测试不同类型的 +** 打开模式,然后关闭文件或目录;在符合文件系统规范时,文 +** 件或目录打开成功,并且返回文件或目录描述符。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +int mkdir (const char *__path, __mode_t __mode); +int main(int argc, char **argv) +{ + int status = 0; + int fd; + DIR *dirptr; + char buf[128] = "./mkdir"; + + /* + * 创建目录 + */ + status = mkdir(buf, 0777); + if (status == -1) { + printf("mkdir error"); + return -1; + } + + /* + * 打开目录下的文件 + */ + fd = open("./mkdir/test3.txt", O_RDWR | O_CREAT | O_EXCL, 0666); + if (fd < 0) { + printf("open error\n"); + rmdir(buf); + return -1; + } + + /* + * opendir打开该目录流 + */ + dirptr = opendir(buf); + if (dirptr == NULL) { + printf("Test1:[ERROR]opendir error\n"); + close(fd); + unlink("./mkdir/test3.txt\n"); + rmdir(buf); + return -1; + + } else { + printf("opendir success!\n"); + } + + /* + * closedir关闭该目录流 + */ + status = closedir(dirptr); + if (status == -1) { + printf("Test1:[ERROR]closedir error,status[%d] \n",status); + close(fd); + unlink("./mkdir/test3.txt\n"); + rmdir(buf); + return -1; + + } else { + printf("closedir success!\n"); + } + + close(fd); + unlink("./mkdir/test3.txt\n"); + rmdir(buf); + + return 0; +} diff --git a/file_system/gjb_S0101603GN_1.c b/file_system/gjb_S0101603GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..7996ec311ec6cf7a41a578e59037a5cb47ce9830 --- /dev/null +++ b/file_system/gjb_S0101603GN_1.c @@ -0,0 +1,51 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101603GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 删除文件或目录测试。调用按照文件名删除文件接口函数, +** 文件应被正确删除。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int fd; + int ret; + + /* + * 创建文件 + */ + fd = creat("./file", 0777); + if(fd < 0) { + printf("creat error\n"); + return -1; + } + + /* + * 删除文件 + */ + ret = remove("./file"); + if(ret != 0) { + printf("remove error\n"); + return -1; + } else { + printf( "remove file success!\n"); + } + + return 0; +} diff --git a/file_system/gjb_S0101603GN_2.c b/file_system/gjb_S0101603GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..724c2bc23a468aa2da7446ca0f883b09588f750f --- /dev/null +++ b/file_system/gjb_S0101603GN_2.c @@ -0,0 +1,54 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101603GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 删除文件或目录测试。调用按照目录名删除目录接口函数,目 +** 录应被正确删除。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +int mkdir (const char *__path, __mode_t __mode); +int main(int argc, char **argv) +{ + char buf[128] = "./mkdir"; + int status = 0; + int ret; + + /* + * 创建目录 + */ + status = mkdir(buf, 0777); + if(status == -1) { + printf("mkdir error!"); + return -1; + } + + /* + * 删除目录 + */ + ret = rmdir(buf); + if(ret != 0) { + printf("rmdir error!"); + return -1; + } + + return 0; +} + diff --git a/file_system/gjb_S0101604GN_1.c b/file_system/gjb_S0101604GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..746e1630ecb0a4b3e1189588a63875429ca5579f --- /dev/null +++ b/file_system/gjb_S0101604GN_1.c @@ -0,0 +1,115 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101604GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: stat记录文件或目录属性功能测试。创建文件,并进行 +** 读写编辑,查看操作系统是否正确记录文件或目录属性( +** 如大小、时间),并能够对文件或目录属性进行查询操作。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +//#include"gjb.h" +//#include"gjbext.h" +int open (const char *__path, int __oflag, ...); + + +int stat (const char *__restrict __file, + struct stat *__restrict __buf) __THROW __nonnull ((1, 2)); + +#define NAME "./file" + +#define O_RDWR 02 +# define O_CREAT 0100 /* Not fcntl. */ +int main(int argc, char **argv) +{ + int fd, ret; + struct stat buf = {0}; + struct stat buf1 = {0}; + char str[] = "hello world test \n"; + char content_buf[32]; + + fd = open(NAME, O_RDWR | O_CREAT, 0644); + if (fd < 0) { + printf("open file error"); + return -1; + } + + ret = stat(NAME, &buf); + if (ret == -1) { + printf("gain file message fail"); + goto done; + } + + /* + * 查看写之前的文件状态信息 + */ + + printf("inode = %lu.\n", buf.st_ino); + printf("size = %ld bytes.\n", buf.st_size); + printf("st_blksize = %ld.\n", buf.st_blksize); + printf("st_blksize = %ld.\n", buf.st_mtime); + + ret = write(fd, str, strlen(str)); + if (ret == -1) { + printf("write fail"); + goto done; + } + + fsync(fd); + lseek(fd, SEEK_SET, 0); + + ret = read(fd, content_buf, 32); + if (ret == -1) { + printf("read fail"); + goto done; + } + + if (strncmp(content_buf, str, strlen(str))) { + printf("read file content error"); + goto done; + } + + /* + * 获取文件信息 + */ + ret = stat(NAME, &buf1); + if (ret == -1) { + printf("gain file message fail"); + goto done; + } + + close(fd); + + printf("inode = %lu.\n", buf1.st_ino); + printf("size = %ld bytes.\n", buf1.st_size); + printf("st_blksize = %ld.\n", buf1.st_blksize); + printf("st_blksize = %ld.\n", buf1.st_mtime); + + if (buf.st_size >= buf1.st_size && S_ISREG(buf1.st_mode)) { + printf("file size errno."); + remove(NAME); + return -1; + } + + remove(NAME); + return 0; + +done: + close(fd); + remove(NAME); + return -1; +} diff --git a/file_system/gjb_S0101604GN_2.c b/file_system/gjb_S0101604GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..0b95fcf7bb24c2a239e255a11b616f5f70a08f73 --- /dev/null +++ b/file_system/gjb_S0101604GN_2.c @@ -0,0 +1,99 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101604GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: stat记录文件或目录属性功能测试。创建目录,并进行 +** 读写编辑,查看操作系统是否正确记录文件或目录属性( +** 如大小、时间),并能够对文件或目录属性进行查询操作。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define O_RDWR 02 +# define O_CREAT 0100 /* Not fcntl. */ +# define O_EXCL 0200 + int open (const char *__path, int __oflag, ...); +int main(int argc, char **argv) +{ + int fd, ret; + int status; + struct stat buf = {0}; + struct stat buf1 = {0}; + char dir[128] = "./mkdir"; + DIR *dirptr; + + status = mkdir(dir, 0777); + if (status == -1) { + printf("mkdir error!"); + return -1; + } + + ret = stat(dir, &buf); + if (ret == -1) { + printf("gain file message fail"); + rmdir(dir); + return -1; + } + + fd = open("./mkdir/test3.txt", O_RDWR | O_CREAT | O_EXCL, 0666); + if (fd < 0) { + printf("open file error"); + rmdir(dir); + return -1; + } + + dirptr = opendir(dir); + if (dirptr == NULL) { + printf("Test1:[ERROR]opendir error"); + goto done; + } + + status = closedir(dirptr); + if (status == -1) { + printf("Test1:[ERROR]closedir error"); + goto done; + } + + ret = stat(dir, &buf); + if (ret == -1) { + printf("gain file message fail"); + goto done; + } + + close(fd); + remove("./mkdir/test3.txt"); + rmdir(dir); + + printf("inode = %lu.\n", buf1.st_ino); + printf("size = %ld bytes.\n", buf1.st_size); + printf("st_blksize = %ld.\n", buf1.st_blksize); + printf("st_blksize = %ld.\n", buf1.st_mtime); + + if (buf.st_size >= buf1.st_size && S_ISDIR(buf1.st_mode)) { + printf("file size errno."); + return -1; + } + + return 0; + +done: + close(fd); + remove("./mkdir/test3.txt"); + rmdir(dir); + return -1; +} diff --git a/file_system/gjb_S0101604GN_3.c b/file_system/gjb_S0101604GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..2b5a12b41f1c7811a64453c5c33e4ea6e5958dd2 --- /dev/null +++ b/file_system/gjb_S0101604GN_3.c @@ -0,0 +1,58 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101604GN_3.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: fstat记录文件或目录属性功能测试。创建文件或目录, +** 并进行读写编辑,查看操作系统是否正确记录文件或目录 +** 属性(如大小、时间),并能够对文件或目录属性进行查 +** 询操作。 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int status; + int fd; + struct stat buf; + + char *filename = "fstattest1.c"; + fd = open(filename, O_RDWR | O_CREAT ,0777); + if (fd == -1) { + printf("[ERROR]Can not open output file"); + return -1; + } + + status = fstat(fd,&buf); + if (status == 0) { + printf("fstat success\n"); + + } else { + printf( "fstat fail!\n"); + close(fd); + remove(filename); + return -1; + } + + close(fd); + + printf("size is [%ld], atime is [%ld],mtime is [%ld],\n", + buf.st_size, buf.st_atime, buf.st_mtime); + + remove(filename); + + return 0; +} diff --git a/file_system/gjb_S0101605GN_1.c b/file_system/gjb_S0101605GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..ea42eb9ffbf5f2a10819d0600fa0dff8ccbc726b --- /dev/null +++ b/file_system/gjb_S0101605GN_1.c @@ -0,0 +1,103 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101605GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件写入和读取功能测试。编制测试用例代码,调用写入接 +** 口,将数据内容写入到文件当前位置或指定位置,然后将写入 +** 内容读取出来,可按照指定方式、指定长度进行数据读取。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int fd, n, ret; + char buf[] = "hello test \n"; + char buf1[] = "world"; + char buf2[32]; + + fd = open("./test.txt", O_RDWR | O_CREAT, 0644); + if (fd < 0) { + printf("open test.txt error\n"); + return -1; + } + + /* + * 使用fd对打开的文件进行写操作,写完后文件指针位置位于文件结尾处 + */ + ret = write(fd, buf, strlen(buf)); + if (ret == -1) { + printf("write fail\n"); + goto done; + } + + /* + * 像指定位置写数据,文件中内容为 “hello world \n” + */ + n = lseek(fd, strlen("hello "), SEEK_SET); + if (n == -1) { + printf("write fail"); + goto done; + } else { + printf("set file read-write location success!\n"); + } + + ret = write(fd, buf1, strlen(buf1)); + if (ret == -1) { + printf("write fail\n"); + goto done; + } + + /* + * 注意:读和写操作使用同一偏移位置,由于文件指针位于末尾,因此后面的read就会读不到数据了 + * 这一行的目的是把文件指针移动到文件头位置,这样下面的代码就能读到数据了 + */ + n = lseek(fd, 0, SEEK_SET); + if (n == -1) { + printf("write fail"); + goto done; + } else { + printf("set file read-write location success!\n"); + } + + /* + * lseek移到文件开头,read就能读取到数据了 + */ + n = read(fd, buf2, sizeof(buf2)); + if (n == -1) { + printf("read file fail!"); + goto done; + } else { + if (!strncmp(buf2, "hello world\n", strlen("hello world\n"))) { + printf("read data success!\n"); + } else { + printf("read data fail!\n"); + goto done; + } + } + + close(fd); + remove("./test.txt"); + return 0; +done: + close(fd); + remove("./test.txt"); + return -1; +} + + diff --git a/file_system/gjb_S0101605GN_3.c b/file_system/gjb_S0101605GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..60d3b076e5ccb20c483f589a4c0d6faab291c754 --- /dev/null +++ b/file_system/gjb_S0101605GN_3.c @@ -0,0 +1,97 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101605GN_3.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件/目录写入和读取功能测试。编制测试用例代码,写入 +** 内容读取出来,可按照指定方式、指定长度进行数据读取; +** 文件/目录写入和读取操作接口调用成功,并且按照规范返 +** 回正确返回值;读取和写入的数据相同。(truncate) +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int filesize; + int i; + int fd; + struct stat buffer; + int status; + char data[1024]; + ssize_t rtread; + mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + char *filename = "file_truncate"; + + fd = open(filename, O_RDWR | O_CREAT ,mode); + if (fd == -1) { + printf("[ERROR]Can not open output file"); + return -1; + } + + for(i = 0; i<1024; i++) { + write(fd, "a", 1); + } + + if(stat(filename, &buffer) == -1) { + printf("[ERROR]stat error--1!"); + goto done; + } + + filesize = buffer.st_size; + printf("filesize = %d\n", filesize); + + status = truncate(filename, filesize - 20 ); + if (status == -1) { + printf("[ERROR]truncate error"); + goto done; + } else { + if(stat(filename, &buffer) == -1) { + printf("[ERROR]stat error!"); + goto done; + } + + printf("buffer.st_size = %ld\n", buffer.st_size); + + if(buffer.st_size == (filesize - 20)) { + printf("The truncated file length is correct!"); + } else { + printf("[ERROR]The truncated file length is error!"); + goto done; + } + } + + lseek(fd, 0, SEEK_SET); + + rtread = read(fd, data, sizeof(data)); + if (rtread != buffer.st_size) { + printf("[ERROR]The truncated file length is error!"); + goto done; + } + + for (i = 0; i < rtread; ++i) { + if (data[i] != 'a') { + printf("file content read != write"); + goto done; + } + } + close(fd); + remove(filename); + return 0; +done: + close(fd); + remove(filename); + return -1; +} diff --git a/file_system/gjb_S0101605GN_4.c b/file_system/gjb_S0101605GN_4.c new file mode 100644 index 0000000000000000000000000000000000000000..a3676de8a5cc70577b460aeec06a31844b0a0944 --- /dev/null +++ b/file_system/gjb_S0101605GN_4.c @@ -0,0 +1,112 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101605GN_4.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件/目录写入和读取功能测试。编制测试用例代码,写入 +** 内容读取出来,可按照指定方式、指定长度进行数据读取; +** 文件/目录写入和读取操作接口调用成功,并且按照规范返 +** 回正确返回值;读取和写入的数据相同。(ftruncate) +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int filesize; + int i; + int fd; + char data[1024]; + ssize_t rtread; + struct stat buffer; + + char *filename = "file_ftruncate_1_1.c"; + + /* + * 创建并打开文件filename + */ + fd = open(filename, O_RDWR | O_CREAT, 0777); + if (fd == -1) { + printf("[ERROR]Can not open output file"); + return -1; + } + + /* + * 向文件filename写入数据 + */ + for(i = 0; i<1024; i++) { + write(fd,"a", 1); + } + + /* + * 获取文件filename大小 + */ + if(stat(filename, &buffer) == -1) { + printf("[ERROR]stat error "); + goto done; + } + + filesize = buffer.st_size; + printf("filesize = %d\n", filesize); + + /* + * 将一个已存在文件截短,应该成功 + */ + if ( ftruncate(fd, filesize - 20) == -1 ) { + printf("[ERROR]ftruncate error "); + goto done; + } else { + printf("ftruncate success\n"); + if(stat(filename, &buffer) == -1) { + printf("[ERROR]stat error "); + goto done; + } + + printf("buffer.st_size = %ld\n", buffer.st_size); + + if(buffer.st_size == (filesize - 20)) { + printf("The ftruncated file length is correct!"); + } else { + printf("[ERROR]The ftruncated file length is error!"); + goto done; + } + } + + lseek(fd, 0, SEEK_SET); + + rtread = read(fd, data, sizeof(data)); + if (rtread != buffer.st_size) { + printf("[ERROR]The truncated file length is error!"); + goto done; + } + + for (i = 0; i < rtread; ++i) { + if (data[i] != 'a') { + printf("file content read != write"); + goto done; + } + } + + close(fd); + remove(filename); + return 0; +done: + close(fd); + remove(filename); + return -1; +} + + diff --git a/file_system/gjb_S0101605GN_5.c b/file_system/gjb_S0101605GN_5.c new file mode 100644 index 0000000000000000000000000000000000000000..dbe45d9af00fe6e749c464496dda1254c915b081 --- /dev/null +++ b/file_system/gjb_S0101605GN_5.c @@ -0,0 +1,137 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101605GN_5.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 目录写入和读取功能测试。编制测试用例代码,调用 +** 写入接口,将数据内容写入到文件/目录当前位置或指定位 +** 置;然后将写入内容读取出来,可按照指定方式、指定长度 +** 进行数据读取;需要测试不同类型的读、写操作模式:随机 +** 写、插入、随机读;文件/目录写入和读取操作接口调用成 +** 功,并且按照规范返回正确返回值;读取和写入的数据相同。(readdir) +*********************************************************************************************************/ +#define __SYLIXOS_KERNEL +#include +//#include"gjbext.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +int main(int argc, char **argv) +{ + int ret1 = -2, status, fd, fd2; + char buf[30] = "./mkdirdir"; + DIR *dirptr; + struct dirent *mydirent; + char *data = "hello sylixos test."; + ssize_t rtwrite, rtread; + char read_buf[32]; + + ret1 = mkdir(buf, 0777); + if(ret1 != 0) { + printf("mkdir error"); + return -1; + } + + fd = open("./mkdirdir/test.txt1", O_RDWR | O_CREAT | O_EXCL, 0666); + + if (fd < 0) { + printf("open error\n"); + rmdir(buf); + return -1; + } + + fd2 = open("./mkdirdir/test.txt2", O_RDWR | O_CREAT | O_EXCL, 0666); + if (fd2 < 0) { + printf("open error\n"); + close(fd); + remove("./mkdirdir/test.txt1\n"); + rmdir(buf); + return -1; + } + + dirptr = opendir(buf); + if(dirptr == NULL) { + printf("opendir error\n"); + goto done; + } + + mydirent = readdir(dirptr); + if(mydirent == NULL) { + printf("readdir error! errno = %d\n ", errno); + goto done; + } else { + printf("readdir success!\n"); + } + + /* + * 关闭该目录流 + */ + status = closedir(dirptr); + if( status == -1) { + printf("Test1:[ERROR]closedir error,status = %d\n", + status); + goto done; + } + + rtwrite = write(fd, data, strlen(data)); + if (rtwrite < 0) { + printf("write error! errno = %d\n ", errno); + goto done; + } else { + printf("write file success!\n"); + } + + /* + * 将文件写到磁盘 + */ + fsync(fd); + + /* + * 将文件指针移动到文件开头 + */ + lseek(fd, 0, SEEK_SET); + + rtread = read(fd, read_buf, sizeof(read_buf)); + if (rtread < 0) { + printf("read error! errno = %d\n ", errno); + goto done; + } else { + printf("read file success!\n"); + } + + if (strncmp(read_buf, data, strlen(data))) { + printf("write content != read content\n "); + goto done; + } else { + printf("read content == write content!\n"); + } + + close(fd); + close(fd2); + remove("./mkdirdir/test.txt1"); + remove("./mkdirdir/test.txt2"); + rmdir(buf); + + return 0; + +done: + close(fd); + close(fd2); + remove("./mkdirdir/test.txt1"); + remove("./mkdirdir/test.txt2"); + rmdir(buf); + return -1; +} diff --git a/file_system/gjb_S0101605GN_6.c b/file_system/gjb_S0101605GN_6.c new file mode 100644 index 0000000000000000000000000000000000000000..dbff891ba22240ea01b94aea643e2c63e1462451 --- /dev/null +++ b/file_system/gjb_S0101605GN_6.c @@ -0,0 +1,167 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101605GN_6.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 目录写入和读取功能测试。编制测试用例代码,调用写入 +** 接口,将数据内容写入到目录当前位置或指定位置,并且按 +** 照规范返回正确返回值;读取和写入的数据相同。(目录回读) +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +int main(int argc, char **argv) +{ + int ret1 = -2, status, fd, fd1, fd2; + int iErrno1 = 0; + int iErrno2 = 0; + char buf[30] = "./mkdir2"; + DIR *dirptr; + struct dirent *mydirent; + struct dirent *mydirent1; + char *data = "hello sylixos test test test."; + ssize_t rtwrite, rtread; + char read_buf[32]; + + ret1 = mkdir(buf, 0777); + if(ret1 != 0) { + printf("mkdir error"); + return -1; + } + + dirptr = opendir(buf); + if(dirptr == NULL) { + printf("opendir error"); + rmdir(buf); + return -1; + } + + fd = open("./mkdir2/test.txt1", O_RDWR | O_CREAT | O_EXCL, 0666); + if (fd < 0) { + printf("open test.txt1 error!\n"); + rmdir(buf); + return -1; + } + + fd1 = open("./mkdir2/test.txt2", O_RDWR | O_CREAT | O_EXCL, 0666); + if(fd1 < 0) { + printf("open test.txt2 error! \n"); + close(fd); + remove("./mkdir2/test.txt1"); + rmdir(buf); + return -1; + } + + fd2 = open("./mkdir2/test.txt3", O_RDWR | O_CREAT | O_EXCL, 0666); + if(fd2 < 0) { + printf("open test.txt3 error! \n"); + close(fd); + remove("./mkdir2/test.txt1"); + close(fd1); + remove("./mkdir2/test.txt2"); + rmdir(buf); + return -1; + } + + iErrno1 = errno; + + mydirent = readdir(dirptr); + mydirent = readdir(dirptr); + mydirent = readdir(dirptr); + + iErrno2 = errno; + + mydirent = readdir(dirptr); + if(mydirent == NULL) { + printf("errno = %d : %d : %d\n", errno, iErrno1, iErrno2); + goto done; + } + + rewinddir(dirptr); + mydirent1 = readdir(dirptr); + if(mydirent1 == NULL) { + printf("readdir error= %d \n", errno); + goto done; + } + + /* + * 关闭该目录流 + */ + status = closedir(dirptr); + if( status == -1) { + printf("Test1:[ERROR]closedir error, " + "status = %d \n", status); + goto done; + } + + rtwrite = write(fd, data, strlen(data)); + if (rtwrite < 0) { + printf("write error! errno = %d\n ", errno); + goto done; + } else { + printf("write file success!\n"); + } + + /* + * 将文件写到磁盘 + */ + fsync(fd); + + /* + * 将文件指针移动到文件开头 + */ + lseek(fd, 0, SEEK_SET); + + rtread = read(fd, read_buf, sizeof(read_buf)); + if (rtread < 0) { + printf("read error! errno = %d\n ", errno); + goto done; + } else { + printf("read file success!\n"); + } + + if (strncmp(read_buf, data, strlen(data))) { + printf("write content != read content\n "); + goto done; + } else { + printf("read content == write content!\n"); + } + + + close(fd); + remove("./mkdir2/test.txt1"); + close(fd1); + remove("./mkdir2/test.txt2"); + close(fd2); + remove("./mkdir2/test.txt3"); + rmdir(buf); + return 0; +done: + close(fd); + remove("./mkdir2/test.txt1"); + close(fd1); + remove("./mkdir2/test.txt2"); + close(fd2); + remove("./mkdir2/test.txt3"); + rmdir(buf); + return -1; +} + diff --git a/file_system/gjb_S0101606GN.c b/file_system/gjb_S0101606GN.c new file mode 100644 index 0000000000000000000000000000000000000000..115a75616ee29c502eb0e1679a173e7ab6503293 --- /dev/null +++ b/file_system/gjb_S0101606GN.c @@ -0,0 +1,80 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101606GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件操作位置调整功能测试。根据文件位置操作规范, +** 通过获取文件 操作当前位置接口和调整文件位置接口 +** 函数,测试各种类型的文件位置调整模式;文件位置调 +** 整结果与文件系统规范一致。 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int fd, n; + char buf[] = "hello world test \n"; + char ch; + + fd = open("test.txt", O_RDWR|O_CREAT, 0644); + if(fd < 0) { + printf("open test.txt error\n"); + return -1; + } + + /* + * 使用fd对打开的文件进行写操作,写完后文件指针位置位于文件结尾处 + */ + write(fd, buf, strlen(buf)); + + /* + * 注意:读和写操作使用同一偏移位置,由于文件指针位于末尾,因此后面的read就会读不到数据了 + * 这一行的目的是把文件指针移动到文件头位置,这样下面的代码就能读到数据了 + */ + n = lseek(fd , 0 , SEEK_SET); + if(n == -1) { + printf("lseek fail"); + goto done; + } else { + printf("set file read-write location success!\n"); + } + + /* + * lseek移到文件开头,read就能读取到数据了 + */ + while((n = read(fd, &ch, 1))) { + if(n < 0) { + printf("read error"); + goto done; + } + + /* + * 将文件内容按字节读出,写到屏幕 + */ + write(STDOUT_FILENO, &ch, n); + } + + close(fd); + remove("test.txt"); + return 0; +done: + close(fd); + remove("test.txt"); + return -1; +} diff --git a/file_system/gjb_S0101607GN_1.c b/file_system/gjb_S0101607GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..915604b4bc2e1a8fa0f18cf45aab9d7e6df826fe --- /dev/null +++ b/file_system/gjb_S0101607GN_1.c @@ -0,0 +1,72 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101607GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件cat控制功能测试。根据文件系统提供的文件控制命令 +** 规范,测试各文件控制命令有效性;文件控制操作与文件系 +** 统规范一致。 +** +*********************************************************************************************************/ +#include +#include"gjbext.h" +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +int cat(char* pathname) +{ + return 0; +} + +int main(int argc, char **argv) +{ + int fd; + int nbytes; + int bytes_written; + char *buf = "this is file write test"; + + char *filename = "cat_test"; + + nbytes = strlen(buf); + fd = open(filename, O_RDWR|O_CREAT ,0644); + if (fd == -1) { + printf("[ERROR]Can not open output file!\n"); + return -1; + } + + if ((bytes_written = write(fd, buf, nbytes)) > 0) { + printf("[SUCESS] write %s to %s sucess!\n", buf, filename); + } else { + printf("[ERROR] Error write!\n"); + goto done; + } + + close(fd); + + if (cat(filename) != 0) { + printf("cat %s did not return 0!\n", filename); + goto done; + } else { + printf("cat success!\n"); + } + + remove(filename); + return 0; +done: + close(fd); + remove(filename); + return -1; +} + + diff --git a/file_system/gjb_S0101607GN_2.c b/file_system/gjb_S0101607GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..14b317ff2c09ec788cbe7c857fe403e514f05e2e --- /dev/null +++ b/file_system/gjb_S0101607GN_2.c @@ -0,0 +1,50 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101607GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件rename控制功能测试。根据文件系统提供的文件控制命令 +** 规范,测试各文件控制命令有效性;文件控制操作与文件系 +** 统规范一致。 +** +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int fd; + int ret; + + fd = creat("./file", 0777); + if(fd < 0) { + printf("creat error"); + return -1; + } + + ret = rename("./file", "test.txt10"); + if(ret != 0) { + printf("rename error %d\n", errno); + remove("test.txt10"); + return -1; + } else { + printf( "rename success\n"); + remove("test.txt10"); + return 0; + } +} + diff --git a/file_system/gjb_S0101607GN_3.c b/file_system/gjb_S0101607GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..3f9efcaf432f29b0b64d000298d0ad4c89cc9c30 --- /dev/null +++ b/file_system/gjb_S0101607GN_3.c @@ -0,0 +1,54 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101607GN_3.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件ioctl控制功能测试。根据文件系统提供的文件控制命令 +** 规范,测试各文件控制命令有效性;文件控制操作与文件系 +** 统规范一致。 +** +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ioccom.h" +#include +//#include "gjb.h" + +int main(int argc, char **argv) +{ + int status,fd; + + char *oldname = "ioctl_old.c"; + + fd = open(oldname, O_RDWR | O_CREAT, 0644); + if(fd == -1) { + printf("[ERROR]Fail to open file!"); + return -1; + } + + int size; + status = ioctl(fd, FIONREAD, &size); + if (status == -1) { + printf("[ioctl error\n"); + remove("ioctl_old.c"); + return -1; + } else { + printf("ioctl success\n"); + remove("ioctl_old.c"); + return 0; + } +} diff --git a/file_system/gjb_S0101607GN_4.c b/file_system/gjb_S0101607GN_4.c new file mode 100644 index 0000000000000000000000000000000000000000..a05329da1a9b412947b860643854fd486253f734 --- /dev/null +++ b/file_system/gjb_S0101607GN_4.c @@ -0,0 +1,75 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101607GN_4.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件mkdir控制功能测试。根据文件系统提供的文件控制命令 +** 规范,测试各文件控制命令有效性;文件控制操作与文件系 +** 统规范一致。 +** +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include "gjb.h" +int mkdir (const char *__path, __mode_t __mode); +int main(int argc, char **argv) +{ + int status = 0; + DIR * dirptr; + int fd; + char buf[128] = "./mkdir"; + + status = mkdir(buf, 0777); + if(status == -1) { + printf("mkdir error!\n"); + return -1; + } + + fd = open("./mkdir/test3.txt", O_RDWR | O_CREAT | O_EXCL, 0666); + if (fd < 0) { + printf("open error\n"); + rmdir(buf); + return -1; + } + + dirptr = opendir(buf); + if( dirptr == NULL) { + printf("Test1:[ERROR]opendir error\n"); + goto done; + } + + status = closedir(dirptr); + if( status == -1) { + printf("Test1:[ERROR]closedir error, status = %d", status); + goto done; + } else { + printf("closedir success!\n"); + } + + close(fd); + remove("./mkdir/test3.txt"); + rmdir(buf); + return 0; +done: + close(fd); + remove("./mkdir/test3.txt"); + rmdir(buf); + return -1; +} + diff --git a/file_system/gjb_S0101607GN_5.c b/file_system/gjb_S0101607GN_5.c new file mode 100644 index 0000000000000000000000000000000000000000..259830255df9157f4ba2487e12b11a3fcdd26564 --- /dev/null +++ b/file_system/gjb_S0101607GN_5.c @@ -0,0 +1,78 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101607GN_5.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件chdir控制功能测试。根据文件系统提供的文件控制命令 +** 规范,测试各文件控制命令有效性;文件控制操作与文件系 +** 统规范一致。 +** +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include "gjb.h" +int mkdir (const char *__path, __mode_t __mode); +int main(int argc, char **argv) +{ + int status; + char *buf; + int ret1; + + rmdir("./mkdirdir2"); + + ret1 = mkdir("./mkdirdir2", 0777); + if(ret1 != 0) { + printf("mkdir error!"); + return -1; + } + + status = chdir("./mkdirdir2"); + if(status != 0) { + printf("[ERROR]chdir error,status[%d]\n",status); + goto done; + } + + buf = (char *) malloc (64); + if(buf == NULL) { + printf("buf is null malloc failed\n"); + chdir(".."); + goto done; + } + + if (getcwd (buf, 64) == NULL) { + printf("[ERROR]getcwd error! \n"); + chdir(".."); + goto done; + } + + if (strstr(buf, "mkdirdir2") == NULL) { + printf("[ERROR]Error in strcmp, buf = %s, pathname = %s!\n", buf, "/mkdirdir" ); + chdir(".."); + goto done; + } + chdir(".."); + rmdir("./mkdirdir2"); + printf("[success]getcwd success! \n"); + return 0; +done: + rmdir("./mkdirdir2"); + return -1; +} + diff --git a/file_system/gjb_S0101607GN_6.c b/file_system/gjb_S0101607GN_6.c new file mode 100644 index 0000000000000000000000000000000000000000..89c24b8a1e478da658e51656199fb89991ef280a --- /dev/null +++ b/file_system/gjb_S0101607GN_6.c @@ -0,0 +1,65 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101607GN_6.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件fsync控制功能测试。根据文件系统提供的文件控制命令 +** 规范,测试各文件控制命令有效性;文件控制操作与文件系 +** 统规范一致。 +** +*********************************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" + +int main(int argc, char **argv) +{ + int status; + int fd; + char *filename = "fsync_file.c"; + ssize_t bytes_written; + char * buf = "errno is not a global variable, because that would make using it"; + + fd = open(filename, O_RDWR | O_CREAT, 0777); + if(fd < 0) { + printf("[ERROR]open error!"); + return -1; + } + + bytes_written = write(fd, buf, strlen(buf)); + if (bytes_written == -1) { + printf("[ERROR]write error\n"); + goto done; + } + + status = fsync(fd); + if(status != 0) { + printf("[ERROR]fsync error\n"); + goto done; + } + + close(fd); + remove(filename); + printf("[SUCCESSS]fsync success\n"); + return 0; +done: + close(fd); + remove(filename); + return -1; + +} + diff --git a/file_system/gjb_S0101607GN_7.c b/file_system/gjb_S0101607GN_7.c new file mode 100644 index 0000000000000000000000000000000000000000..f91a914e7c404379e9b52670aba8e0d2071e9f43 --- /dev/null +++ b/file_system/gjb_S0101607GN_7.c @@ -0,0 +1,67 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101607GN_7.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件fcntl控制功能测试。根据文件系统提供的文件控制命令 +** 规范,测试各文件控制命令有效性;文件控制操作与文件系 +** 统规范一致。 +** +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +//#include "gjb.h" +#define PATH_MAX 4096 +typedef unsigned int u32; +int main(int argc, char **argv) +{ + int fd = -1; + u32 flags = 0; + + fd = open("fcntl_test.txt", O_RDWR| O_CREAT, 0644); + + + if (fd == -1) { + printf("open file fcntl_test.txt failed!"); + return -1; + } + + flags = fcntl(fd, F_GETFL,NULL); + + if(flags == -1) { + printf("[ERROR]fcntl error\n"); + goto done; + } +printf("fd=%hx\n",fd); +printf("flags=%hx\n",flags); +printf("O_RDWR=%hx\n",O_RDWR); +printf("O_CREAT=%hx\n",O_CREAT); + if((flags & O_RDWR) && (flags & O_CREAT)) { + printf("fcntl:F_GETFL PASS!\n"); + } else { + printf("fcntl:F_GETFL FAIL!\n"); + goto done; + } + + close(fd); + remove("fcntl_test.txt"); + return 0; +done: + close(fd); + remove("fcntl_test.txt"); + return -1; +} + + diff --git a/file_system/gjb_S0101608GN.c b/file_system/gjb_S0101608GN.c new file mode 100644 index 0000000000000000000000000000000000000000..6c7cf20ff4af9fcdd8d2007143488625527c8cb4 --- /dev/null +++ b/file_system/gjb_S0101608GN.c @@ -0,0 +1,170 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101608GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件系统格式化测试。根据操作系统提供文件系统类型, +** 以及提供的文件系统操作工具、函数,在给定的外部存储 +** 设备上创建文件系统,并且进行格式化;文件系统创建成功。 +** +** 测试之前需要通过操作系统分区工具对磁盘进行分区, 例如: SylixOS 可以试用 fdisk 工具 +** 对 /dev/blk/vdd-0 设备进行分区 +*********************************************************************************************************/ +#include +//#include "gjbext.h" +//#include "gjb.h" +#include +#include +#include +#include + +#define PATH_MAX 4096 +#define TEST_MOUNT_DEV "/dev/sda4" +#define TEST_MOUNT_PATH "/home/wujun/media" +#define TEST_MOUNT_FS "vfat" +#define F_OK 0 + +int fs_init; +int format(const char *fsname,const char *devname) +{ + if ((fsname == NULL) ||(devname == NULL)) + { + return -1; + } + // printf("get in user mount\n"); + char cmd[1204]; + sprintf(cmd, "rm %s/* -rf\n", devname); + system(cmd); + return 0; +} + +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int mount(char *type, char *src, char *dest) +{ + char cmd[PATH_MAX]; + int ret = 0; + if (src == NULL) + { + errno = ENOENT; + return -1; + } + if (type == NULL) + { + errno = EINVAL; + return -1; + } + if (dest == NULL) + { + errno = ENOENT; + return -1; + } + if (strlen(src) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + + } + if (strlen(type) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(dest) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (access(dest, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENOENT; + return -1; + } + + if (fs_init == 0) + init_filesystem(); + sprintf(cmd, "mount %s %s\n", src, dest); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int umount (char* src) +{ + char cmd[1204]; + int ret = 0; + sprintf(cmd, "umount %s\n", src); + // printf("get in user unmount\n"); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int main(int argc, char **argv) +{ + int err = 0; + + /* + * 挂载文件系统到TEST_MOUNT_PATH路径 + */ + int ret = mount(TEST_MOUNT_FS, TEST_MOUNT_DEV, TEST_MOUNT_PATH); + if (ret < 0) { + printf("mount failed. errno = %d\n", errno); + return -1; + + } else { + printf("mount sucess"); + } + + /* + * 格式化外部设备 + */ + ret = format(TEST_MOUNT_FS, TEST_MOUNT_PATH); + if (ret == 0) { + printf("format success"); + + } else { + printf("format failed. errno = %d\n", errno); + err++; + } + + /* + * 卸载文件系统 + */ + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("umount failed. errno = %d\n", errno); + err++; + + } else { + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("repeat umount test success"); + + } else { + printf("umount failed. errno = %d\n", errno); + err++; + } + } + + if (err == 0) { + return 0; + } + + return -1; +} diff --git a/file_system/gjb_S0101609GN.c b/file_system/gjb_S0101609GN.c new file mode 100644 index 0000000000000000000000000000000000000000..f3b78ced68ebeb01b2a723960ed4451238fe9fab --- /dev/null +++ b/file_system/gjb_S0101609GN.c @@ -0,0 +1,202 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101609GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件系统挂载和卸载功能测试。在操作系统启动阶段或者 +** 运行过程中,挂载文件系统,并且进行基本文件操作,然 +** 后卸载文件系统;文件系统挂载成功,并且文件操作无异 +** 常。 +** +** 测试之前需要通过操作系统分区工具对磁盘进行分区, 例如: SylixOS 可以试用 fdisk 工具 +** 对 /dev/blk/vdd-0 设备进行分区 +*********************************************************************************************************/ +#include +//#include "gjbext.h" +//#include "gjb.h" +#include +#include +#include +#include +int fs_init; +#define PATH_MAX 4096 +# define O_CREAT 0100 /* Not fcntl. */ +#define O_RDWR 02 +#define TEST_MOUNT_DEV "/dev/sda4" +#define TEST_MOUNT_PATH "/home/wujun/media" +#define TEST_MOUNT_FS "vfat" + +#define TEST_FILE "/home/wujun/media/test_file13" + +int open (const char *__path, int __oflag, ...); +int format(const char *fsname,const char *devname) +{ + if ((fsname == NULL) ||(devname == NULL)) + { + return -1; + } + // printf("get in user mount\n"); + char cmd[1204]; + sprintf(cmd, "rm %s/* -rf\n", devname); + system(cmd); + return 0; +} + +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + int fs_init = 1; +} +int mount(char *type, char *src, char *dest) +{ + char cmd[PATH_MAX]; + int ret = 0; + if (src == NULL) + { + errno = ENOENT; + return -1; + } + if (type == NULL) + { + errno = EINVAL; + return -1; + } + if (dest == NULL) + { + errno = ENOENT; + return -1; + } + if (strlen(src) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + + } + if (strlen(type) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(dest) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (access(dest, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENOENT; + return -1; + } + + if (fs_init == 0) + init_filesystem(); + sprintf(cmd, "mount %s %s\n", src, dest); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int umount (char* src) +{ + char cmd[1204]; + int ret = 0; + sprintf(cmd, "umount %s\n", src); + // printf("get in user unmount\n"); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + + + +static int file_operate_fs_609(void) +{ + int fd; + int ret; + char buf[32]; + + fd = open(TEST_FILE, O_CREAT | O_RDWR, 0666); + if (fd < 0) { + printf("at /media/vdd0 create file fail."); + return (-1); + } + + ret = write(fd, "test", 4); + if (ret < 0) { + printf("write file fail."); + return (-1); + } + + fsync(fd); + lseek(fd, SEEK_SET, 0); + + ret = read(fd, buf, 32); + if (ret < 0) { + printf("read file fail."); + return (-1); + } + + if (strncmp(buf, "test", 4)) { + printf("read file content error."); + return (-1); + } + + close(fd); + unlink(TEST_FILE); + + return (0); +} + +int main(int argc, char **argv) +{ + /* + * 挂载文件系统 + */ + int ret = mount(TEST_MOUNT_FS, TEST_MOUNT_DEV, TEST_MOUNT_PATH); + if (ret < 0) { + printf("mount failed. errno = %d\n", errno); + return -1; + } else { + printf("mount sucess"); + } + + format(TEST_MOUNT_FS, TEST_MOUNT_PATH); + + ret = file_operate_fs_609(); + if (ret < 0) { + return -1; + } + + /* + * 卸载文件系统 + */ + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("umount failed. errno = %d\n", errno); + return -1; + + } else { + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("umount success"); + + } else { + printf("umount failed. errno = %d\n", errno); + return -1; + } + } + + return 0; +} diff --git a/file_system/gjb_S0101610GN.c b/file_system/gjb_S0101610GN.c new file mode 100644 index 0000000000000000000000000000000000000000..598f3db20a915201e77401ac36b8c920407b8ab4 --- /dev/null +++ b/file_system/gjb_S0101610GN.c @@ -0,0 +1,266 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101608GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 文件系统格式化测试。根据操作系统提供文件系统类型, +** 以及提供的文件系统操作工具、函数,在给定的外部存储 +** 设备上创建文件系统,并且进行格式化;文件系统创建成功。 +** +** 测试之前需要通过操作系统分区工具对磁盘进行分区, 例如: SylixOS 可以试用 fdisk 工具 +** 对 /dev/blk/vdd-0 设备进行分区 +*********************************************************************************************************/ +#include +//#include "gjbext.h" +//#include "gjb.h" +#include +#include +#include +#include +int fs_init; +#define PATH_MAX 4096 +# define O_CREAT 0100 /* Not fcntl. */ +#define O_RDWR 02 +#define TEST_MOUNT_DEV "/dev/sda4" +#define TEST_MOUNT_PATH "/home/wujun/media" +#define TEST_MOUNT_FS "vfat" +int open (const char *__path, int __oflag, ...); +int format(const char *fsname,const char *devname) +{ + if ((fsname == NULL) ||(devname == NULL)) + { + return -1; + } + // printf("get in user mount\n"); + char cmd[1204]; + sprintf(cmd, "rm %s/* -rf\n", devname); + system(cmd); + return 0; +} + +void init_filesystem(void) +{ + // system("losetup -f /work/vdd.img"); + fs_init = 1; +} +int mount(char *type, char *src, char *dest) +{ + char cmd[PATH_MAX]; + int ret = 0; + if (src == NULL) + { + errno = ENOENT; + return -1; + } + if (type == NULL) + { + errno = EINVAL; + return -1; + } + if (dest == NULL) + { + errno = ENOENT; + return -1; + } + if (strlen(src) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + + } + if (strlen(type) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (strlen(dest) > PATH_MAX) + { + errno = ENAMETOOLONG; + return -1; + } + if (access(dest, F_OK) != 0) + { + errno = ENODEV; + return -1; + } + if (access(src, F_OK) != 0) + { + errno = ENOENT; + return -1; + } + + if (fs_init == 0) + init_filesystem(); + sprintf(cmd, "mount %s %s\n", src, dest); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int umount (char* src) +{ + char cmd[1204]; + int ret = 0; + sprintf(cmd, "umount %s\n", src); + // printf("get in user unmount\n"); + // printf("%s\n", cmd); + ret = system(cmd); + return ret; +} + +int main(int argc, char **argv) +{ + int err = 0; + int fd; + char buf[32]; + + /* + * 挂载文件系统到TEST_MOUNT_PATH路径 + */ + int ret = mount(TEST_MOUNT_FS, TEST_MOUNT_DEV, TEST_MOUNT_PATH); + if (ret < 0) { + printf("mount failed. errno = %d\n", errno); + return -1; + + } else { + printf("mount sucess\n"); + } + + + /* + *格式化外部设备 + */ + ret = format(TEST_MOUNT_FS, TEST_MOUNT_PATH); + if (ret == 0) { + printf("format success"); + + } else { + printf("format failed. errno = %d\n", errno); + err++; + } + + + /* + *打开文件 + */ + + fd = open(TEST_MOUNT_PATH "/test_file13", O_CREAT | O_RDWR, 0666); + if (fd < 0) { + printf("at /media/vdd0 create file fail."); + return (-1); + } else { + printf("open file success\n"); + } + + /* + * 写文件 + */ + ret = write(fd, "test", 4); + if (ret < 0) { + printf("write file fail."); + return (-1); + } else { + printf("write file success\n"); + } + + lseek(fd, 0, SEEK_SET); + + /* + * 读文件 + */ + ret = read(fd, buf, 32); + if (ret < 0) { + printf("read file fail."); + return (-1); + } else { + printf("read file success"); + } + + if (strncmp(buf, "test", 4)) { + printf("read file content error.\n"); + return (-1); + } + + /* + * 关文件 + */ + ret = close(fd); + if (ret < 0) { + printf("close file fail."); + return (-1); + } else { + printf("close file success\n"); + } + + /* + * 删除文件 + */ + ret = remove(TEST_MOUNT_PATH "/test_file13"); + if (ret < 0) { + printf("remove file fail."); + return (-1); + } else { + printf("remove file success\n"); + } + + /* + * 卸载文件系统 + */ + + /* while(1){ + ret = umount(TEST_MOUNT_PATH); + if(ret==0) + + { + printf("umount successful\n"); + break; + + } + else if (ret < 0) { + printf("umount failed. errno 1= %d\n", errno); + err++; + + } else { + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("repeat umount test success"); + + } else { + printf("umount failed. errno2 = %d,%d\n", errno,ret); + err++; + } + } + }*/ + + + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("umount failed. errno = %d\n", errno); + err++; + + } else { + ret = umount(TEST_MOUNT_PATH); + if (ret < 0) { + printf("repeat umount test success"); + + } else { + printf("umount failed. errno = %d,%d\n", errno,ret); + err++; + } + } + + + + if (err == 0) { + return 0; + } + + return -1; +}