From e73923cd630abe13a9c87da41f5b5a3c1ce51fb2 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 01:20:35 +0000 Subject: [PATCH 01/11] =?UTF-8?q?=E6=94=B9=E5=8F=98=E4=BA=86gjb=E7=9A=84?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wujun <1405961592@qq.com> --- file_system/gjb_S0101601GN_1 | Bin 0 -> 17152 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 file_system/gjb_S0101601GN_1 diff --git a/file_system/gjb_S0101601GN_1 b/file_system/gjb_S0101601GN_1 new file mode 100644 index 0000000000000000000000000000000000000000..3b36b81547bb752dac23319f5fe2cf5f2b41d7f8 GIT binary patch literal 17152 zcmeHPe{dAl9e+s(1c6IHs1a07iZck!kw8d;HsvnA*w_RRlB%t^UhX#BNpctO_9RiE zIH`_TNQ-~eGOe9K$F@#?4efLsYZ(ngwb-!^OdZFL(-u2LlS(N@?O+wIpYPlE-Ry4e zYR743+L?QJ`M&Sx`|IuZy?yuI?LNQM*4bWKQX;sNiO&k+4$Zfapb`YHR~3+;XcY7C zcd58a%mhC}VwOB;5lF4_YN?x6D7*}m?5e4fhhAa9f+@Fr0Pza_hx8wQA7{xFD+VmVLpfGjXQEp;2QY>OkZu*4E%V9;?j##oAQg%bijw#1s z%K4<6(5F%5(@Xu3QSr;aLU`?NR(4+6s`Qys3@Y1Bo6(OGZ;P^f+%Me-FXcE)Io^%1 zqrCjPg}ZsHidU!~4yyb!Roy98_s4r1>R0ziYx?7f%uvlxV?#|teIT6-tdUKic2Nu( zHXAqf2)G#|Or=rw#X`lCd_(iu?ayw%@Q&F$v9jy3d#;?Zr1g6CK`}{(3fc3JAfDZ0zi4Zqe5S>h0Q^z&fFKba&}dBW3J}r%fZ(-PO{c zOc>qa-hT45V<4GOo^(q!uOf|08kwaSuT-=CS*V4V04sq8--iq1@p&}5?@?H0aeOxE z-w&P&&yPGW?NyyMsOCS$g9@(*N;7*NWB%0*7EbpH-;0Eta^RO(D)R5R1E+g}%Q**L z$sp)?2hP_<;=Kx=g*sg~mj@j*#pC?=2DrEb?-yfi>nc{bQ_>6}i@bHF*-|pdiJbagjZ}ad?9)6vZ zuls99_T+6^_D|Z#pU-XS?i?+@3mMf$=jD)SZM5kqE;qMm0ZiUK0Cqhp+GzP2BJ0na zi_o=aYfwkm&d!~xT)G$P;+Ue)pDp#*l@hu3qLw|U9X-22J9@rMD|uc!dC^=52hS-7 z6}eM=GH+~8{lB+~#3Hk*M;mE+jH+7pv^iJX*YsU5H}SlsUu%mtK(w#zc=lK0J*YkXB;?P~ScUz0EP5^bJ1o!8d)g;u z>&oB&Hm_fxkS~txeo+k9!Q=zm*hM_M+mqVNk)x5ATOZM5wKU(Z^IHFy-z zz@P}A!4ccp65Cmwp3H+S<8tG??Y%eGt5WVHA}2bLghd z(WY-<7H9^V$nE$BkEh09QvZl$lHGUQ^@0GdtOt zJ=>anGn8BSM{VR-iMIatnZMBd_r>j@TSMDJw}td$eSLw-rC+9I%Xl<1(r}gYraePxF$2X66f;oFKrsXV(;1-WG=bH9aXkHz&zby2DwRyBI>G*QCK55y z>8phqi>LkgFYGssv}rwL@=F!VMm}}20A(YeVmVbJF(b0m0wT$TX(UWnymWZLu%r}$ zBFn%fOUkYfB8&7hz`cLVJ5 zS8P~(-O9Dgmk~^UDegh&IiCj+ZsKzQ_+d~k6l*^|^U=<=wD)ZDRXtGJGH+(t%2G5* z;3o<3Lwr`elgk;PqTN^ZwbBk>^;gTo7e61gmvVg`yCC}yCTfno-V87O9;n1NyjiW&It zW`N&kTn?``5qRVzOXDJoUaok4Pi~3g=}{<^#TF6#z8vi{sIdIKi@7B6 zhv-=>3hxPSR~3Gz?6{KiJ94jB>H?2rWT{qEHA`_*@7l%GdttP-p;DnPkoH4V_#L&& zELLa=VEjSV5N`LF(&Km4IQ~@%XFWXGk=KWC62e0~$=|H};UN;sr6sm|l5bG*_Z6=$ zUwQw}5q^K$>#UK@=l3T!wzOR5U(wT> zNthY``apf4wx%v4xw<`TY6G?Pfi>4!_(yr9F;QZ_-|y6>cSiaBbT?im`2BM?K11A_ zr(?=6ig`S{^=Aqm$8LO<;PLLpD+G@NH$GeN_;KTx2p*?ye2zVy-8k;E)?dE{ULvOV*Kd_Re-CkpH)Lh{_<3LYnclw}@dZ&Trr#HpxUdDt zPp$fb;qR%X66a`BbZr4#1MZ(vvum>u*Dt1zt7ri~yMR|g-#gweC;igt_t%~Re!f`% z|8W8QXaW4?0{9yR@N!%)wcmRmEs%Mz(_&Yy20p*^a>3sREC>*eo)LZvnV|$tz^T8+ z)EB&=@aI6Qa9>mh6`;r*rO)TfRx7*42ei`V6fjXjcA~;wxKS+5}ovj>)})?Jgnmv^VG2DOW}udJ(?L97>0?1)1hg) zRCnCbt8c5VtF3FOt=qUsuS4^6y?tw_t4(j))T-l1~?wptWul`o_-9&7n?xb9?)?wr;&U)ZE!dUgepTNID~1ua39`gM221PNJyuFmCW) z9Z!)D7(D7mG;D?u&V8h2N~vBQsF^}2v^-ejhUEDgH$-P}+{m<}HeNBc#yUTPHn|Ve z=+SgikA)LaI%w0e8CubJLeHcPqi}o$M)RUi(LZQBK%DzQnDf zsCPx~?f*wS_I_o@bWFKp;&Cs&=dnMf6qvGpA^XD~d){9$CAqV(Kc=*Pc3wZPYnXmr z-B0X;?U;YoW6%3Fru;h)>wEJ@>nw`T{V)7VQ_;s2%fxH{8wi~CkF%Ykt!${M*Zwu& zPJ7-bGUf5ZZg~7Ke;O6qb8(t@U%}_Kz52{EeH*rw4txInYp@0&3hPE@1*wFbLa*+zDnGckl}!V-F}{bX9MH5 nJIsYf8*3E)|3_Gyl`F0jrR{q@d;fKo)?#j`#mZc(swDpe!)R?T literal 0 HcmV?d00001 -- Gitee From b3e38812146960e16f80a6a0cb74cd2570719757 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 01:25:44 +0000 Subject: [PATCH 02/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20fi?= =?UTF-8?q?le=5Fsystem/gjb=5FS0101601GN=5F1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file_system/gjb_S0101601GN_1 | Bin 17152 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 file_system/gjb_S0101601GN_1 diff --git a/file_system/gjb_S0101601GN_1 b/file_system/gjb_S0101601GN_1 deleted file mode 100644 index 3b36b81547bb752dac23319f5fe2cf5f2b41d7f8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17152 zcmeHPe{dAl9e+s(1c6IHs1a07iZck!kw8d;HsvnA*w_RRlB%t^UhX#BNpctO_9RiE zIH`_TNQ-~eGOe9K$F@#?4efLsYZ(ngwb-!^OdZFL(-u2LlS(N@?O+wIpYPlE-Ry4e zYR743+L?QJ`M&Sx`|IuZy?yuI?LNQM*4bWKQX;sNiO&k+4$Zfapb`YHR~3+;XcY7C zcd58a%mhC}VwOB;5lF4_YN?x6D7*}m?5e4fhhAa9f+@Fr0Pza_hx8wQA7{xFD+VmVLpfGjXQEp;2QY>OkZu*4E%V9;?j##oAQg%bijw#1s z%K4<6(5F%5(@Xu3QSr;aLU`?NR(4+6s`Qys3@Y1Bo6(OGZ;P^f+%Me-FXcE)Io^%1 zqrCjPg}ZsHidU!~4yyb!Roy98_s4r1>R0ziYx?7f%uvlxV?#|teIT6-tdUKic2Nu( zHXAqf2)G#|Or=rw#X`lCd_(iu?ayw%@Q&F$v9jy3d#;?Zr1g6CK`}{(3fc3JAfDZ0zi4Zqe5S>h0Q^z&fFKba&}dBW3J}r%fZ(-PO{c zOc>qa-hT45V<4GOo^(q!uOf|08kwaSuT-=CS*V4V04sq8--iq1@p&}5?@?H0aeOxE z-w&P&&yPGW?NyyMsOCS$g9@(*N;7*NWB%0*7EbpH-;0Eta^RO(D)R5R1E+g}%Q**L z$sp)?2hP_<;=Kx=g*sg~mj@j*#pC?=2DrEb?-yfi>nc{bQ_>6}i@bHF*-|pdiJbagjZ}ad?9)6vZ zuls99_T+6^_D|Z#pU-XS?i?+@3mMf$=jD)SZM5kqE;qMm0ZiUK0Cqhp+GzP2BJ0na zi_o=aYfwkm&d!~xT)G$P;+Ue)pDp#*l@hu3qLw|U9X-22J9@rMD|uc!dC^=52hS-7 z6}eM=GH+~8{lB+~#3Hk*M;mE+jH+7pv^iJX*YsU5H}SlsUu%mtK(w#zc=lK0J*YkXB;?P~ScUz0EP5^bJ1o!8d)g;u z>&oB&Hm_fxkS~txeo+k9!Q=zm*hM_M+mqVNk)x5ATOZM5wKU(Z^IHFy-z zz@P}A!4ccp65Cmwp3H+S<8tG??Y%eGt5WVHA}2bLghd z(WY-<7H9^V$nE$BkEh09QvZl$lHGUQ^@0GdtOt zJ=>anGn8BSM{VR-iMIatnZMBd_r>j@TSMDJw}td$eSLw-rC+9I%Xl<1(r}gYraePxF$2X66f;oFKrsXV(;1-WG=bH9aXkHz&zby2DwRyBI>G*QCK55y z>8phqi>LkgFYGssv}rwL@=F!VMm}}20A(YeVmVbJF(b0m0wT$TX(UWnymWZLu%r}$ zBFn%fOUkYfB8&7hz`cLVJ5 zS8P~(-O9Dgmk~^UDegh&IiCj+ZsKzQ_+d~k6l*^|^U=<=wD)ZDRXtGJGH+(t%2G5* z;3o<3Lwr`elgk;PqTN^ZwbBk>^;gTo7e61gmvVg`yCC}yCTfno-V87O9;n1NyjiW&It zW`N&kTn?``5qRVzOXDJoUaok4Pi~3g=}{<^#TF6#z8vi{sIdIKi@7B6 zhv-=>3hxPSR~3Gz?6{KiJ94jB>H?2rWT{qEHA`_*@7l%GdttP-p;DnPkoH4V_#L&& zELLa=VEjSV5N`LF(&Km4IQ~@%XFWXGk=KWC62e0~$=|H};UN;sr6sm|l5bG*_Z6=$ zUwQw}5q^K$>#UK@=l3T!wzOR5U(wT> zNthY``apf4wx%v4xw<`TY6G?Pfi>4!_(yr9F;QZ_-|y6>cSiaBbT?im`2BM?K11A_ zr(?=6ig`S{^=Aqm$8LO<;PLLpD+G@NH$GeN_;KTx2p*?ye2zVy-8k;E)?dE{ULvOV*Kd_Re-CkpH)Lh{_<3LYnclw}@dZ&Trr#HpxUdDt zPp$fb;qR%X66a`BbZr4#1MZ(vvum>u*Dt1zt7ri~yMR|g-#gweC;igt_t%~Re!f`% z|8W8QXaW4?0{9yR@N!%)wcmRmEs%Mz(_&Yy20p*^a>3sREC>*eo)LZvnV|$tz^T8+ z)EB&=@aI6Qa9>mh6`;r*rO)TfRx7*42ei`V6fjXjcA~;wxKS+5}ovj>)})?Jgnmv^VG2DOW}udJ(?L97>0?1)1hg) zRCnCbt8c5VtF3FOt=qUsuS4^6y?tw_t4(j))T-l1~?wptWul`o_-9&7n?xb9?)?wr;&U)ZE!dUgepTNID~1ua39`gM221PNJyuFmCW) z9Z!)D7(D7mG;D?u&V8h2N~vBQsF^}2v^-ejhUEDgH$-P}+{m<}HeNBc#yUTPHn|Ve z=+SgikA)LaI%w0e8CubJLeHcPqi}o$M)RUi(LZQBK%DzQnDf zsCPx~?f*wS_I_o@bWFKp;&Cs&=dnMf6qvGpA^XD~d){9$CAqV(Kc=*Pc3wZPYnXmr z-B0X;?U;YoW6%3Fru;h)>wEJ@>nw`T{V)7VQ_;s2%fxH{8wi~CkF%Ykt!${M*Zwu& zPJ7-bGUf5ZZg~7Ke;O6qb8(t@U%}_Kz52{EeH*rw4txInYp@0&3hPE@1*wFbLa*+zDnGckl}!V-F}{bX9MH5 nJIsYf8*3E)|3_Gyl`F0jrR{q@d;fKo)?#j`#mZc(swDpe!)R?T -- Gitee From 3e6d0b1eae2d40bd4dd5f1c9a1d16419529d2962 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 01:26:27 +0000 Subject: [PATCH 03/11] changed the gjb Signed-off-by: wujun <1405961592@qq.com> --- file_system/gjb_S0101601GN_1.c | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 file_system/gjb_S0101601GN_1.c diff --git a/file_system/gjb_S0101601GN_1.c b/file_system/gjb_S0101601GN_1.c new file mode 100644 index 0000000..8b64f15 --- /dev/null +++ b/file_system/gjb_S0101601GN_1.c @@ -0,0 +1,102 @@ +/********************************************************************************************************* +** +** 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!"); + 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"); + } + + /* + * ?????????????????? + */ + 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"); + close(fd); + unlink("./file"); + return -1; + } + } + + close(fd); + + /* + * ?????????????, ?????????????-1 + */ + fd = creat("./file", 0777); + if (fd >= 0) { + printf( "creat same file test sucess!"); + } else { + printf("creat error"); + close(fd); + unlink("./file"); + return -1; + } + + unlink("./file"); + + return 0; +} -- Gitee From 0ee38c30df23be712059f7fb0baa3d1d1c7860a5 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 02:53:19 +0000 Subject: [PATCH 04/11] a Signed-off-by: wujun <1405961592@qq.com> --- file_system/gjb_S0101603GN_2.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 file_system/gjb_S0101603GN_2.c diff --git a/file_system/gjb_S0101603GN_2.c b/file_system/gjb_S0101603GN_2.c new file mode 100644 index 0000000..724c2bc --- /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; +} + -- Gitee From 00bf5fb5cdd74a8b992a98c2a9ee641c3ed365ea Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 02:53:29 +0000 Subject: [PATCH 05/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20fi?= =?UTF-8?q?le=5Fsystem/gjb=5FS0101603GN=5F2.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file_system/gjb_S0101603GN_2.c | 54 ---------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 file_system/gjb_S0101603GN_2.c diff --git a/file_system/gjb_S0101603GN_2.c b/file_system/gjb_S0101603GN_2.c deleted file mode 100644 index 724c2bc..0000000 --- a/file_system/gjb_S0101603GN_2.c +++ /dev/null @@ -1,54 +0,0 @@ -/********************************************************************************************************* -** -** 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; -} - -- Gitee From 79260110ac795de5562f973bb49a58f8a28ca334 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 02:53:46 +0000 Subject: [PATCH 06/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20fi?= =?UTF-8?q?le=5Fsystem/gjb=5FS0101601GN=5F1.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file_system/gjb_S0101601GN_1.c | 102 --------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 file_system/gjb_S0101601GN_1.c diff --git a/file_system/gjb_S0101601GN_1.c b/file_system/gjb_S0101601GN_1.c deleted file mode 100644 index 8b64f15..0000000 --- a/file_system/gjb_S0101601GN_1.c +++ /dev/null @@ -1,102 +0,0 @@ -/********************************************************************************************************* -** -** 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!"); - 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"); - } - - /* - * ?????????????????? - */ - 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"); - close(fd); - unlink("./file"); - return -1; - } - } - - close(fd); - - /* - * ?????????????, ?????????????-1 - */ - fd = creat("./file", 0777); - if (fd >= 0) { - printf( "creat same file test sucess!"); - } else { - printf("creat error"); - close(fd); - unlink("./file"); - return -1; - } - - unlink("./file"); - - return 0; -} -- Gitee From 275260884fb5a72dbc66fac70aeffe4b55680994 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 02:54:38 +0000 Subject: [PATCH 07/11] filesystem Signed-off-by: wujun <1405961592@qq.com> --- file_system/gjb_S0101601GN_1.c | 101 ++++++++++++++++++++ file_system/gjb_S0101602GN_2.c | 92 ++++++++++++++++++ file_system/gjb_S0101603GN_1.c | 51 ++++++++++ file_system/gjb_S0101603GN_2.c | 54 +++++++++++ file_system/gjb_S0101604GN_1.c | 115 ++++++++++++++++++++++ file_system/gjb_S0101604GN_3.c | 58 +++++++++++ file_system/gjb_S0101605GN_1.c | 103 ++++++++++++++++++++ file_system/gjb_S0101605GN_3.c | 97 +++++++++++++++++++ file_system/gjb_S0101605GN_4.c | 112 ++++++++++++++++++++++ file_system/gjb_S0101605GN_5.c | 137 ++++++++++++++++++++++++++ file_system/gjb_S0101605GN_6.c | 167 ++++++++++++++++++++++++++++++++ file_system/gjb_S0101606GN.c | 80 ++++++++++++++++ file_system/gjb_S0101607GN_1.c | 72 ++++++++++++++ file_system/gjb_S0101607GN_2.c | 50 ++++++++++ file_system/gjb_S0101607GN_3.c | 54 +++++++++++ file_system/gjb_S0101607GN_4.c | 75 +++++++++++++++ file_system/gjb_S0101607GN_5.c | 78 +++++++++++++++ file_system/gjb_S0101607GN_6.c | 65 +++++++++++++ file_system/gjb_S0101607GN_7.c | 67 +++++++++++++ file_system/gjb_S0101608GN.c | 170 +++++++++++++++++++++++++++++++++ 20 files changed, 1798 insertions(+) create mode 100644 file_system/gjb_S0101601GN_1.c create mode 100644 file_system/gjb_S0101602GN_2.c create mode 100644 file_system/gjb_S0101603GN_1.c create mode 100644 file_system/gjb_S0101603GN_2.c create mode 100644 file_system/gjb_S0101604GN_1.c create mode 100644 file_system/gjb_S0101604GN_3.c create mode 100644 file_system/gjb_S0101605GN_1.c create mode 100644 file_system/gjb_S0101605GN_3.c create mode 100644 file_system/gjb_S0101605GN_4.c create mode 100644 file_system/gjb_S0101605GN_5.c create mode 100644 file_system/gjb_S0101605GN_6.c create mode 100644 file_system/gjb_S0101606GN.c create mode 100644 file_system/gjb_S0101607GN_1.c create mode 100644 file_system/gjb_S0101607GN_2.c create mode 100644 file_system/gjb_S0101607GN_3.c create mode 100644 file_system/gjb_S0101607GN_4.c create mode 100644 file_system/gjb_S0101607GN_5.c create mode 100644 file_system/gjb_S0101607GN_6.c create mode 100644 file_system/gjb_S0101607GN_7.c create mode 100644 file_system/gjb_S0101608GN.c diff --git a/file_system/gjb_S0101601GN_1.c b/file_system/gjb_S0101601GN_1.c new file mode 100644 index 0000000..ed1e321 --- /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_S0101602GN_2.c b/file_system/gjb_S0101602GN_2.c new file mode 100644 index 0000000..fb82faa --- /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 0000000..7996ec3 --- /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 0000000..724c2bc --- /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 0000000..746e163 --- /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_3.c b/file_system/gjb_S0101604GN_3.c new file mode 100644 index 0000000..2b5a12b --- /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 0000000..ea42eb9 --- /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 0000000..60d3b07 --- /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 0000000..a3676de --- /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 0000000..dbe45d9 --- /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 0000000..dbff891 --- /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 0000000..115a756 --- /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 0000000..915604b --- /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 0000000..14b317f --- /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 0000000..3f9efca --- /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 0000000..a05329d --- /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 0000000..2598302 --- /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 0000000..89c24b8 --- /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 0000000..f91a914 --- /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 0000000..6c7cf20 --- /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; +} -- Gitee From 2123d228ca3e3d178e75677aa12b96d9df1adc2d Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 03:00:03 +0000 Subject: [PATCH 08/11] filesystem Signed-off-by: wujun <1405961592@qq.com> --- file_system/gjb_S0101601GN_2.c | 77 ++++++++++ file_system/gjb_S0101609GN.c | 202 +++++++++++++++++++++++++ file_system/gjb_S0101610GN.c | 266 +++++++++++++++++++++++++++++++++ 3 files changed, 545 insertions(+) create mode 100644 file_system/gjb_S0101601GN_2.c create mode 100644 file_system/gjb_S0101609GN.c create mode 100644 file_system/gjb_S0101610GN.c diff --git a/file_system/gjb_S0101601GN_2.c b/file_system/gjb_S0101601GN_2.c new file mode 100644 index 0000000..eb0452d --- /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_S0101609GN.c b/file_system/gjb_S0101609GN.c new file mode 100644 index 0000000..f3b78ce --- /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 0000000..598f3db --- /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; +} -- Gitee From df28a34b6b6b927894dfa7d28df78fca656ecb02 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 03:00:43 +0000 Subject: [PATCH 09/11] filesystem Signed-off-by: wujun <1405961592@qq.com> --- file_system/gjb_S0101602GN_1.c | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 file_system/gjb_S0101602GN_1.c diff --git a/file_system/gjb_S0101602GN_1.c b/file_system/gjb_S0101602GN_1.c new file mode 100644 index 0000000..5d146ff --- /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; +} + -- Gitee From 48267ccc81a43743d4803f17a1a6fcafcd01cae1 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 07:02:54 +0000 Subject: [PATCH 10/11] filesystem Signed-off-by: wujun <1405961592@qq.com> --- file_system/gjb_S0101604GN_2.c | 99 ++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 file_system/gjb_S0101604GN_2.c diff --git a/file_system/gjb_S0101604GN_2.c b/file_system/gjb_S0101604GN_2.c new file mode 100644 index 0000000..0b95fcf --- /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; +} -- Gitee From 2a2ca40123f2b890bbd8c849b22558ef3599ad99 Mon Sep 17 00:00:00 2001 From: wujun <1405961592@qq.com> Date: Thu, 2 Nov 2023 07:07:04 +0000 Subject: [PATCH 11/11] device management Signed-off-by: wujun <1405961592@qq.com> --- device_management/gjb_S0101701GN_1.c | 96 ++++++++++ device_management/gjb_S0101701GN_2.c | 107 +++++++++++ device_management/gjb_S0101701GN_3.c | 128 +++++++++++++ device_management/gjb_S0101701GN_4.c | 121 ++++++++++++ device_management/gjb_S0101701GN_5.c | 116 ++++++++++++ device_management/gjb_S0101702GN_1.c | 97 ++++++++++ device_management/gjb_S0101702GN_2.c | 109 +++++++++++ device_management/gjb_S0101702GN_3.c | 125 ++++++++++++ device_management/gjb_S0101702GN_4.c | 127 +++++++++++++ device_management/gjb_S0101702GN_5.c | 119 ++++++++++++ device_management/gjb_S0101703GN_1.c | 213 +++++++++++++++++++++ device_management/gjb_S0101703GN_2.c | 241 +++++++++++++++++++++++ device_management/gjb_S0101703GN_3.c | 213 +++++++++++++++++++++ device_management/gjb_S0101703GN_4.c | 232 +++++++++++++++++++++++ device_management/gjb_S0101704GN_1.c | 132 +++++++++++++ device_management/gjb_S0101705GN.c | 273 +++++++++++++++++++++++++++ device_management/gjb_S0101706GN_1.c | 113 +++++++++++ device_management/gjb_S0101706GN_2.c | 153 +++++++++++++++ device_management/gjb_S0101706GN_3.c | 122 ++++++++++++ 19 files changed, 2837 insertions(+) create mode 100644 device_management/gjb_S0101701GN_1.c create mode 100644 device_management/gjb_S0101701GN_2.c create mode 100644 device_management/gjb_S0101701GN_3.c create mode 100644 device_management/gjb_S0101701GN_4.c create mode 100644 device_management/gjb_S0101701GN_5.c create mode 100644 device_management/gjb_S0101702GN_1.c create mode 100644 device_management/gjb_S0101702GN_2.c create mode 100644 device_management/gjb_S0101702GN_3.c create mode 100644 device_management/gjb_S0101702GN_4.c create mode 100644 device_management/gjb_S0101702GN_5.c create mode 100644 device_management/gjb_S0101703GN_1.c create mode 100644 device_management/gjb_S0101703GN_2.c create mode 100644 device_management/gjb_S0101703GN_3.c create mode 100644 device_management/gjb_S0101703GN_4.c create mode 100644 device_management/gjb_S0101704GN_1.c create mode 100644 device_management/gjb_S0101705GN.c create mode 100644 device_management/gjb_S0101706GN_1.c create mode 100644 device_management/gjb_S0101706GN_2.c create mode 100644 device_management/gjb_S0101706GN_3.c diff --git a/device_management/gjb_S0101701GN_1.c b/device_management/gjb_S0101701GN_1.c new file mode 100644 index 0000000..6988c6f --- /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 0000000..2f14bf9 --- /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 0000000..8039352 --- /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 0000000..565dfb3 --- /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 0000000..0ee994d --- /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 0000000..22f1f89 --- /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 0000000..52badd8 --- /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 0000000..ad6a749 --- /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 0000000..215ba06 --- /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 0000000..228d044 --- /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 0000000..73d5873 --- /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 0000000..ecaa5cb --- /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 0000000..64c9957 --- /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 0000000..c1e8458 --- /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 0000000..875e431 --- /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 0000000..a277836 --- /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 0000000..e4145e0 --- /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 0000000..a9d4d84 --- /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 0000000..2ad2446 --- /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; +} -- Gitee