syscalls/pselect_02: Convert to new API
PATCH 1/1 syscalls/pselect_02: Convert to new API
Signed-off-by tangmeng <[email protected]>
--- testcases/kernel/syscalls/pselect/pselect02.c | 95 ++++--------------- 1 file changed, 20 insertions(+), 75 deletions(-)
testcases/kernel/syscalls/pselect/pselect02.c +20 -75
@@ -1,24 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2014 Fujitsu Ltd. * Author: Zeng Linggang <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Library General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* */ -/* -* Test Description: + +/*\ +* [Description] +* * Verify that, * 1. pselect() fails with -1 return value and sets errno to EBADF * if a file descriptor that was already closed.
@@ -28,91 +16,48 @@* if the value contained within timeout was invalid. */ -#include <errno.h> -#include "test.h" -#include "safe_macros.h" - -TCID_DEFINE (pselect02); +#include "tst_test.h" static fd_set read_fds;static struct timespec time_buf; -static struct test_case_t { +static struct tcase {int nfds;fd_set *readfds;struct timespec *timeout;int exp_errno; -} test_cases[] = { +} tcases[] = { {128 , &read_fds,NULL ,EBADF }, {-1 ,NULL ,NULL ,EINVAL }, {128 ,NULL , &time_buf,EINVAL }, }; -int TST_TOTAL =ARRAY_SIZE (test_cases); - -static void setup (void ); -static void cleanup (void ); -static void pselect_verify (const struct test_case_t *); - -int main (int argc,char **argv) -{ -int lc, i; - -tst_parse_opts (argc, argv,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -for (i =0 ; i <TST_TOTAL ; i++) -pselect_verify (&test_cases[i]); - } - -cleanup (); -tst_exit (); -} -static void setup (void ) {int fd; -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - - fd =SAFE_OPEN (cleanup,"test_file" ,O_RDWR |O_CREAT ,0777 ); + fd =SAFE_OPEN ("test_file" ,O_RDWR |O_CREAT ,0777 );FD_ZERO (&read_fds);FD_SET (fd, &read_fds); -SAFE_CLOSE (cleanup, fd); +SAFE_CLOSE (fd); time_buf.tv_sec =-1 ; time_buf.tv_nsec =0 ; } -static void pselect_verify (const struct test_case_t *test) +static void pselect_verify (unsigned int i) { -TEST (pselect (test->nfds, test->readfds,NULL ,NULL , test->timeout, -NULL )); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"pselect() succeeded unexpectedly" ); -return ; - } +struct tcase *tc = &tcases[i]; -if (TEST_ERRNO == test->exp_errno) { -tst_resm (TPASS |TTERRNO ,"pselect() failed as expected" ); - }else { -tst_resm (TFAIL |TTERRNO , -"pselect() failed unexpectedly; expected: %d - %s" , - test->exp_errno,strerror (test->exp_errno)); - } +TST_EXP_FAIL (pselect (tc->nfds, tc->readfds,NULL ,NULL , tc->timeout, +NULL ), tc->exp_errno); } -static void cleanup (void ) -{ -tst_rmdir (); -} +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .test = pselect_verify, + .setup = setup, + .needs_tmpdir =1 , +};
--
2.20.1
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Pushed with minor changes, thanks.
- Fixed some whitespaces
(please remmeber to run make check-testXX when you are rewriting test)
- Changed the messages written by the test to be nicer
- Rewritten the description a bit
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp