/* * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc. * */ /********************************************************** * * TEST IDENTIFIER : read03 * * TEST TITLE : Basic tests for read(2) * * TEST CASE TOTAL : 1 * * AUTHOR : jitwxs * <jitwxs@foxmail.com> * * DESCRIPTION * Testcase to check that read() sets errno to EAGAIN. * * ALGORITHM * Create a named pipe (fifo), open it in O_NONBLOCK mode, and * attempt to read from it, without writing to it. read() should fail * with EAGAIN. * **********************************************************/
#include<errno.h> #include"tst_test.h"
#define FIFONAME "tmpFIFO"
int rfd, wfd;
staticvoidmy_test(void) { int c;
TEST(read(rfd, &c, 1));
if (TEST_RETURN != -1) tst_res(TFAIL, "read() failed");
if (TEST_ERRNO != EAGAIN) tst_res(TFAIL, "read set bad errno, expected EAGAIN, got %d", TEST_ERRNO); else tst_res(TPASS, "read() succeded in setting errno to EAGAIN"); }
wxs@ubuntu:~/ltp$ git add testcases/kernel/syscalls/read/read03_new.c wxs@ubuntu:~/ltp$ git commit -s -m "Convert read03 to new API" [master 2f7fb39] Convert read03 to new API 1 file changed, 75 insertions(+) create mode 100644 testcases/kernel/syscalls/read/read03_new.c
5.1.3 patch 校验
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
wxs@ubuntu:~/ltp$ git format-patch -1 0001-Convert-read03-to-new-API.patch wxs@ubuntu:~/ltp$ ../linux/scripts/checkpatch.pl 0001-Convert-read03-to-new-API.patch WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13: new file mode 100644
total: 0 errors, 1 warnings, 75 lines checked
NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
0001-Convert-read03-to-new-API.patch has style problems, please review.
NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5.2 Convert read04
5.2.1 重写代码
1 2
wxs@ubuntu:~/ltp/testcases/kernel/syscalls/read$ rm read04.c wxs@ubuntu:~/ltp/testcases/kernel/syscalls/read$ vim read04.c
/* * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc. * */ /********************************************************** * * TEST IDENTIFIER : read04 * * TEST TITLE : Basic tests for read(2) * * TEST CASE TOTAL : 1 * * AUTHOR : jitwxs * <jitwxs@foxmail.com> * * DESCRIPTION * Testcase to check if read returns the number of bytes read correctly. * * ALGORITHM * Create a file and write some bytes out to it. * Attempt to read more than written. * Check the return count, and the read buffer. The read buffer should be * same as the write buffer. * **********************************************************/
wxs@ubuntu:~/ltp$ git add testcases/kernel/syscalls/read/read04_new.c wxs@ubuntu:~/ltp$ git commit -s -m "Convert read04 to new API" [master b5ef790] Convert read04 to new API 1 file changed, 88 insertions(+) create mode 100644 testcases/kernel/syscalls/read/read04_new.c
5.2.3 patch 校验
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
wxs@ubuntu:~/ltp$ git format-patch -2 0001-Convert-read03-to-new-API.patch 0002-Convert-read04-to-new-API.patch wxs@ubuntu:~/ltp$ ../linux/scripts/checkpatch.pl 0002-Convert-read04-to-new-API.patch WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13: new file mode 100644
total: 0 errors, 1 warnings, 88 lines checked
NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
0002-Convert-read04-to-new-API.patch has style problems, please review.
NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5.3 Convert close02
5.3.1 重写代码
1
wxs@ubuntu:~/ltp/testcases/kernel/syscalls/close$ vim close02_new.c
/* * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc. * */ /********************************************************** * * TEST IDENTIFIER : close02 * * TEST TITLE : Basic tests for close(2) * * TEST CASE TOTAL : 1 * * AUTHOR : jitwxs * <jitwxs@foxmail.com> * * DESCRIPTION * Check that an invalid file descriptor returns EBADF * **********************************************************/
#include<errno.h> #include"tst_test.h"
staticvoidmy_test(void) { TEST(close(-1));
if (TEST_RETURN != -1) tst_res(TFAIL, "Closed a non existent fildes"); else { if (TEST_ERRNO != EBADF) tst_res(TFAIL, "close() FAILED dis EBADF, got %d", errno); else tst_res(TPASS, "call returned EBADF"); } }
wxs@ubuntu:~/ltp$ git add testcases/kernel/syscalls/close/close02_new.c wxs@ubuntu:~/ltp$ git commit -s -m "Convert close02 to new API" [master 68c6b1f] Convert close02 to new API 1 file changed, 51 insertions(+) create mode 100644 testcases/kernel/syscalls/close/close02_new.c
5.3.3 patch 校验
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
wxs@ubuntu:~/ltp$ git format-patch -3 0001-Convert-read03-to-new-API.patch 0002-Convert-read04-to-new-API.patch 0003-Convert-close02-to-new-API.patch wxs@ubuntu:~/ltp$ ../linux/scripts/checkpatch.pl 0003-Convert-close02-to-new-API.patch WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13: new file mode 100644
total: 0 errors, 1 warnings, 51 lines checked
NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
0003-Convert-close02-to-new-API.patch has style problems, please review.
NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5.4 Convert close08
5.4.1 重写代码
1 2
wxs@ubuntu:~/ltp/testcases/kernel/syscalls/close$ vim close08.c wxs@ubuntu:~/ltp/testcases/kernel/syscalls/close$ rm close08.c
/* * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc. * */ /********************************************************** * * TEST IDENTIFIER : close08 * * TEST TITLE : Basic tests for close(2) * * TEST CASE TOTAL : 1 * * AUTHOR : jitwxs * <jitwxs@foxmail.com> * * DESCRIPTION * It should/will be extended when full functional tests are written * for close(2). * **********************************************************/
#include<errno.h> #include"tst_test.h"
#define FILENAME "tmpFile"
int fd;
staticvoidmy_test(void) { TEST(close(fd));
if (TEST_RETURN == -1) tst_res(TFAIL | TTERRNO, "close(%s) failed", FILENAME); else tst_res(TPASS, "close(%s) returned %ld", FILENAME, TEST_RETURN); }
/* * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc. * */ /********************************************************** * * TEST IDENTIFIER : open04 * * TEST TITLE : Basic tests for open(2) * * TEST CASE TOTAL : 1 * * AUTHOR : jitwxs * <jitwxs@foxmail.com> * * DESCRIPTION * Testcase to check that open(2) sets EMFILE if a process opens files * more than its descriptor size * * ALGORITHM * First get the file descriptor table size which is set for a process. * Use open(2) for creating files till the descriptor table becomes full. * These open(2)s should succeed. Finally use open(2) to open another * file. This attempt should fail with EMFILE. * **********************************************************/