* [LTP] [PATCH v2 1/2] iopl: convert to new API @ 2020-07-16 6:10 Li Wang 2020-07-16 6:10 ` [LTP] [PATCH v2 2/2] ioperm: Convert " Li Wang 2020-07-16 8:53 ` [LTP] [PATCH v2 1/2] iopl: convert " Petr Vorel 0 siblings, 2 replies; 6+ messages in thread From: Li Wang @ 2020-07-16 6:10 UTC (permalink / raw) To: ltp Signed-off-by: Li Wang <liwang@redhat.com> Cc: Erico Nunes <ernunes@redhat.com> --- testcases/kernel/syscalls/iopl/iopl01.c | 172 ++++------------- testcases/kernel/syscalls/iopl/iopl02.c | 247 +++++------------------- 2 files changed, 86 insertions(+), 333 deletions(-) diff --git a/testcases/kernel/syscalls/iopl/iopl01.c b/testcases/kernel/syscalls/iopl/iopl01.c index 0b1952668..e0f9d7b5f 100644 --- a/testcases/kernel/syscalls/iopl/iopl01.c +++ b/testcases/kernel/syscalls/iopl/iopl01.c @@ -1,162 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * + * Copyright (c) Linux Test Project, 2020 + * Copyright (c) Wipro Technologies Ltd, 2002 */ -/********************************************************** - * - * TEST IDENTIFIER : iopl01 - * - * EXECUTED BY : superuser - * - * TEST TITLE : Basic test for iopl(2) - * - * TEST CASE TOTAL : 4 - * - * AUTHOR : Subhab Biswas <subhabrata.biswas@wipro.com> - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * DESCRIPTION - * This is a Phase I test for the iopl(2) system call. - * It is intended to provide a limited exposure of the system call. - * - * Setup: - * Setup signal handling. - * Test caller is superuser - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Issue FAIL message with errno. - * Otherwise, Issue PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given + +/* + * This is a basic test for iopl(2) system call. * - * USAGE: <for command-line> - * iopl01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -h : Show help screen - * -f : Turn off functional testing - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -p : Pause for SIGUSR1 before starting - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Test the system call for possible privelege levels. + * As the privelge level for a normal process is 0, start by + * setting/changing the level to 0. * - ****************************************************************/ - -char *TCID = "iopl01"; - -#if defined __i386__ || defined(__x86_64__) + * Author: Subhab Biswas <subhabrata.biswas@wipro.com> + */ #include <errno.h> #include <unistd.h> #include <sys/io.h> -#include "test.h" - -static void setup(); -static void cleanup(); +#include "tst_test.h" -int TST_TOTAL = 4; - -int level; /* I/O privilege level of the process */ +#if defined __i386__ || defined(__x86_64__) -int main(int ac, char **av) +static void verify_iopl(void) { + int total_level = 4; + int level; - int lc; + for (level = 0; level < total_level; ++level) { - tst_parse_opts(ac, av, NULL, NULL); + TEST(iopl(level)); - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Test the system call for possible privelege levels. - * As the privelge level for a normal process is 0, - * start by setting/changing the level to 0. - */ - for (level = 0; level < TST_TOTAL; ++level) { - - TEST(iopl(level)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "iopl() failed for level %d, " - "errno=%d : %s", level, - TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - tst_resm(TPASS, "iopl() passed for level %d, " - "returned %ld", level, TEST_RETURN); - } + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "iopl() failed for level %d, " + "errno=%d : %s", level, + TST_ERR, tst_strerrno(TST_ERR)); + } else { + tst_res(TPASS, "iopl() passed for level %d, " + "returned %ld", level, TST_RET); } } - - /* cleanup and exit */ - cleanup(); - tst_exit(); - } -/* setup() - performs all ONE TIME setup for this test */ -void setup(void) +static void cleanup(void) { - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - -} - -/* - *cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - /* * back to I/O privilege for normal process. */ - if (iopl(0) == -1) { - tst_resm(TWARN, "iopl() cleanup failed"); - } - + if (iopl(0) == -1) + tst_res(TWARN, "iopl() cleanup failed"); } -#else /* __i386__ */ - -#include "test.h" - -int TST_TOTAL = 0; - -int main(void) -{ - tst_resm(TPASS, - "LSB v1.3 does not specify iopl() for this architecture."); - tst_exit(); -} +static struct tst_test test = { + .test_all = verify_iopl, + .needs_root = 1, + .cleanup = cleanup, +}; -#endif /* __i386__ */ +#else +TST_TEST_TCONF("LSB v1.3 does not specify iopl() for this architecture. (only for i386 or x86_64)"); +#endif /* __i386_, __x86_64__*/ diff --git a/testcases/kernel/syscalls/iopl/iopl02.c b/testcases/kernel/syscalls/iopl/iopl02.c index 35d239268..dab6881f4 100644 --- a/testcases/kernel/syscalls/iopl/iopl02.c +++ b/testcases/kernel/syscalls/iopl/iopl02.c @@ -1,221 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * + * Copyright (c) Linux Test Project, 2020 + * Copyright (c) Wipro Technologies Ltd, 2002 */ -/********************************************************** - * - * TEST IDENTIFIER : iopl02 - * - * EXECUTED BY : superuser - * - * TEST TITLE : Tests for error conditions - * - * TEST CASE TOTAL : 2 - * - * AUTHOR : Subhab Biwas <subhabrata.biswas@wipro.com> - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * DESCRIPTION - * Verify that - * 1) iopl(2) returns -1 and sets errno to EINVAL for privilege - * level greater than 3. - * 2) iopl(2) returns -1 and sets errno to EPERM if the current - * user is not the super-user. - * - * Setup: - * Setup signal handling. - * Test caller is superuser - * Set expected errnos for logging - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code and error number, if matching, - * Issue PASS message - * Otherwise, - * Issue FAIL message - * Perform testcase specific cleanup (if needed) - * - * Cleanup: - * Print errno log and/or timing stats if options given + +/* + * This is an error test for iopl(2) system call. * - * USAGE: <for command-line> - * iopl02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -h : Show help screen - * -f : Turn off functional testing - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -p : Pause for SIGUSR1 before starting - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Verify that + * 1) iopl(2) returns -1 and sets errno to EINVAL for privilege + * level greater than 3. + * 2) iopl(2) returns -1 and sets errno to EPERM if the current + * user is not the super-user. * - ****************************************************************/ - -char *TCID = "iopl02"; - -#if defined __i386__ || defined(__x86_64__) + * Author: Subhab Biswas <subhabrata.biswas@wipro.com> + */ #include <errno.h> #include <unistd.h> #include <sys/io.h> #include <pwd.h> -#include "test.h" -#include "safe_macros.h" - -#define INVALID_LEVEL 4 /* Invalid privilege level */ -#define EXP_RET_VAL -1 +#include "tst_test.h" +#include "tst_safe_macros.h" -static void setup(); -static int setup1(void); -static void cleanup1(); -static void cleanup(); - -static char nobody_uid[] = "nobody"; -struct passwd *ltpuser; +#if defined __i386__ || defined(__x86_64__) -struct test_cases_t { - int level; /* I/O privilege level */ - char *desc; /* test case description */ - int exp_errno; /* expected error number */ -} test_cases[] = { - { - INVALID_LEVEL, "Invalid privilege level", EINVAL}, { - 1, "Non super-user", EPERM} +static struct tcase { + int level; + char *desc; + int exp_errno; +} tcases[] = { + {4, "Invalid privilege level", EINVAL}, + {1, "Non super-user", EPERM} }; -int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); - -int main(int ac, char **av) +static void verify_iopl(unsigned int i) { - - int lc, i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (i = 0; i < TST_TOTAL; ++i) { - - if (i == 1) { - /* setup Non super-user for second test */ - if (setup1()) { - /* setup1() failed, skip this test */ - continue; - } - } - - /* - * Call iopl(2) - */ - TEST(iopl(test_cases[i].level)); - - if ((TEST_RETURN == EXP_RET_VAL) && - (TEST_ERRNO == test_cases[i].exp_errno)) { - tst_resm(TPASS, "Expected failure for %s, " - "errno: %d", test_cases[i].desc, - TEST_ERRNO); - } else { - tst_resm(TFAIL, "Unexpected results for %s ; " - "returned %ld (expected %d), errno %d " - "(expected errno %d)", - test_cases[i].desc, - TEST_RETURN, EXP_RET_VAL, - TEST_ERRNO, test_cases[i].exp_errno); - } - - if (i == 1) { - /* revert back to super user */ - cleanup1(); - } - - } + TEST(iopl(tcases[i].level)); + + if ((TST_RET == -1) && (TST_ERR == tcases[i].exp_errno)) { + tst_res(TPASS | TTERRNO, + "Expected failure for %s, errno: %d", + tcases[i].desc, TST_ERR); + } else { + tst_res(TFAIL | TTERRNO, + "%s returned %ld expected -1, expected %s got ", + tcases[i].desc, TST_RET, tst_strerrno(tcases[i].exp_errno)); } - - /* cleanup and exit */ - cleanup(); - - tst_exit(); - } -/* setup1() - set up non-super user for second test case */ -int setup1(void) +static void setup(void) { - /* switch to "nobody" user */ - if (seteuid(ltpuser->pw_uid) == -1) { - tst_resm(TWARN, "Failed to set effective" - "uid to %d", ltpuser->pw_uid); - return 1; - } - return 0; + struct passwd *pw; + pw = SAFE_GETPWNAM("nobody"); + SAFE_SETEUID(pw->pw_uid); } -/* cleanup1() - reset to super user for first test case */ -void cleanup1(void) +static void cleanup(void) { - /* reset user as root */ - SAFE_SETEUID(NULL, 0); + SAFE_SETEUID(0); } -/* setup() - performs all ONE TIME setup for this test */ -void setup(void) -{ - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - /* Check if "nobody" user id exists */ - if ((ltpuser = getpwnam(nobody_uid)) == NULL) { - tst_brkm(TBROK, NULL, "\"nobody\" user id doesn't exist"); - } - - TEST_PAUSE; - -} - -/* - *cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - -} - -#else /* __i386__ */ - -#include "test.h" -#include "safe_macros.h" - -int TST_TOTAL = 0; - -int main(void) -{ - tst_resm(TPASS, - "LSB v1.3 does not specify iopl() for this architecture."); - tst_exit(); -} +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = verify_iopl, + .needs_root = 1, + .setup = setup, + .cleanup = cleanup, +}; -#endif /* __i386__ */ +#else +TST_TEST_TCONF("LSB v1.3 does not specify iopl() for this architecture. (only for i386 or x86_64)"); +#endif /* __i386_, __x86_64__*/ -- 2.21.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 2/2] ioperm: Convert to new API 2020-07-16 6:10 [LTP] [PATCH v2 1/2] iopl: convert to new API Li Wang @ 2020-07-16 6:10 ` Li Wang 2020-07-16 8:53 ` Petr Vorel 2020-07-16 9:15 ` [LTP] [v2,2/2] " Petr Vorel 2020-07-16 8:53 ` [LTP] [PATCH v2 1/2] iopl: convert " Petr Vorel 1 sibling, 2 replies; 6+ messages in thread From: Li Wang @ 2020-07-16 6:10 UTC (permalink / raw) To: ltp Signed-off-by: Li Wang <liwang@redhat.com> Cc: Erico Nunes <ernunes@redhat.com> --- testcases/kernel/syscalls/ioperm/ioperm01.c | 181 +++---------- testcases/kernel/syscalls/ioperm/ioperm02.c | 273 +++++--------------- 2 files changed, 99 insertions(+), 355 deletions(-) diff --git a/testcases/kernel/syscalls/ioperm/ioperm01.c b/testcases/kernel/syscalls/ioperm/ioperm01.c index e8bd18dd7..9802d91ed 100644 --- a/testcases/kernel/syscalls/ioperm/ioperm01.c +++ b/testcases/kernel/syscalls/ioperm/ioperm01.c @@ -1,178 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * + * Copyright (c) Linux Test Project, 2020 + * Copyright (c) Wipro Technologies Ltd, 2002 */ -/********************************************************** - * - * TEST IDENTIFIER : ioperm01 - * - * EXECUTED BY : superuser - * - * TEST TITLE : Basic test for ioperm(2) - * - * TEST CASE TOTAL : 1 - * - * AUTHOR : Subhab Biswas <subhabrata.biswas@wipro.com> - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * DESCRIPTION - * This is a Phase I test for the ioperm(2) system call. - * It is intended to provide a limited exposure of the system call. - * - * Setup: - * Setup signal handling. - * Test caller is superuser - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Issue FAIL message with errno. - * Otherwise, Issue PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * USAGE: <for command-line> - * ioperm01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -h : Show help screen - * -f : Turn off functional testing - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -p : Pause for SIGUSR1 before starting - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - ****************************************************************/ -char *TCID = "ioperm01"; - -#if defined __i386__ || defined(__x86_64__) +/* + * This is a basic test for ioperm(2) system call. + * It is intended to provide a limited exposure of the system call. + * + * Author: Subhab Biswas <subhabrata.biswas@wipro.com> + */ #include <errno.h> #include <unistd.h> #include <sys/io.h> -#include "test.h" +#include "tst_test.h" + +#if defined __i386__ || defined(__x86_64__) -unsigned long io_addr; /*kernel version dependant io start address */ -#define NUM_BYTES 3 /* number of bytes from start address */ -#define TURN_ON 1 -#define TURN_OFF 0 +unsigned long io_addr; +#define NUM_BYTES 3 #ifndef IO_BITMAP_BITS #define IO_BITMAP_BITS 1024 #endif -static void setup(); -static void cleanup(); - -int TST_TOTAL = 1; - -int main(int ac, char **av) +static void verify_ioperm(void) { + TEST(ioperm(io_addr, NUM_BYTES, 1)); - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Test the system call. - */ - TEST(ioperm(io_addr, NUM_BYTES, TURN_ON)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "ioperm() failed for port address " - "%lu, errno=%d : %s", io_addr, - TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - tst_resm(TPASS, "ioperm() passed for port " - "address %lu, returned %lu", - io_addr, TEST_RETURN); - } + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "ioperm() failed for port address " + "%lu, errno=%d : %s", io_addr, + TST_ERR, tst_strerrno(TST_ERR)); + } else { + tst_res(TPASS, "ioperm() passed for port " + "address %lu, returned %lu", + io_addr, TST_RET); } - - /* cleanup and exit */ - cleanup(); - tst_exit(); - } -/* setup() - performs all ONE TIME setup for this test */ -void setup(void) +static void setup(void) { - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - /* * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed * from kernel 2.6.8 to permit 16-bits ioperm * * Ricky Ng-Adam, rngadam@yahoo.com * */ - if (tst_kvercmp(2, 6, 8) < 0) { - /*get ioperm on 1021, 1022, 1023 */ + if (tst_kvercmp(2, 6, 8) < 0) io_addr = IO_BITMAP_BITS - NUM_BYTES; - } else { - /*get ioperm on 65533, 65534, 65535 */ + else io_addr = IO_BITMAP_BITS - NUM_BYTES; - } - - TEST_PAUSE; - } -/* - *cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* * Reset I/O privileges for the specified port. */ - if ((ioperm(io_addr, NUM_BYTES, TURN_OFF)) == -1) { - tst_brkm(TBROK, NULL, "ioperm() cleanup failed"); - } - + if ((ioperm(io_addr, NUM_BYTES, 0)) == -1) + tst_brk(TBROK | TTERRNO, "ioperm() cleanup failed"); } -#else /* __i386__ */ - -#include "test.h" - -int TST_TOTAL = 0; - -int main(void) -{ - tst_resm(TPASS, - "LSB v1.3 does not specify ioperm() for this architecture."); - tst_exit(); -} +static struct tst_test test = { + .test_all = verify_ioperm, + .needs_root = 1, + .setup = setup, + .cleanup = cleanup, +}; -#endif /* __i386__ */ +#else +TST_TEST_TCONF("LSB v1.3 does not specify ioperm() for this architecture. (only for i386 or x86_64)"); +#endif /* __i386_, __x86_64__*/ diff --git a/testcases/kernel/syscalls/ioperm/ioperm02.c b/testcases/kernel/syscalls/ioperm/ioperm02.c index 3d9b1445f..c9c6d48b6 100644 --- a/testcases/kernel/syscalls/ioperm/ioperm02.c +++ b/testcases/kernel/syscalls/ioperm/ioperm02.c @@ -1,250 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * + * Copyright (c) Linux Test Project, 2020 + * Copyright (c) Wipro Technologies Ltd, 2002 */ -/********************************************************** - * - * TEST IDENTIFIER : ioperm02 - * - * EXECUTED BY : superuser - * - * TEST TITLE : Tests for error conditions - * - * TEST CASE TOTAL : 2 - * - * AUTHOR : Subhab Biwas <subhabrata.biswas@wipro.com> - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * DESCRIPTION - * Verify that - * 1) ioperm(2) returns -1 and sets errno to EINVAL for I/O port - * address greater than 0x3ff. - * 2) ioperm(2) returns -1 and sets errno to EPERM if the current - * user is not the super-user. - * - * Setup: - * Setup signal handling. - * Set expected errnos for logging - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code and error number, if matching, - * Issue PASS message - * Otherwise, - * Issue FAIL message - * Perform testcase specific cleanup (if needed) - * - * Cleanup: - * Print errno log and/or timing stats if options given + +/* + * This is an error test for ioperm(2) system call. * - * USAGE: <for command-line> - * ioperm02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -h : Show help screen - * -f : Turn off functional testing - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -p : Pause for SIGUSR1 before starting - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Verify that + * 1) ioperm(2) returns -1 and sets errno to EINVAL for I/O port + * address greater than 0x3ff. + * 2) ioperm(2) returns -1 and sets errno to EPERM if the current + * user is not the super-user. * - ****************************************************************/ - -char *TCID = "ioperm02"; - -#if defined __i386__ || defined(__x86_64__) + * Author: Subhab Biswas <subhabrata.biswas@wipro.com> + */ +#include <stdlib.h> #include <errno.h> #include <unistd.h> #include <sys/io.h> #include <pwd.h> -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" +#include "tst_safe_macros.h" + +#if defined __i386__ || defined(__x86_64__) #define NUM_BYTES 3 -#define TURN_ON 1 -#define TURN_OFF 0 -#define EXP_RET_VAL -1 #ifndef IO_BITMAP_BITS #define IO_BITMAP_BITS 1024 /* set to default value since some H/W may not support 0x10000 even with a 2.6.8 kernel */ #define IO_BITMAP_BITS_16 65536 #endif -static void setup(); -static int setup1(void); -static void cleanup1(); -static void cleanup(); - -static char nobody_uid[] = "nobody"; -struct passwd *ltpuser; - -struct test_cases_t { - long from; /* starting port address */ - long num; /* no. of bytes from starting address */ +static struct tcase_t { + long from; + long num; int turn_on; - char *desc; /* test case description */ - int exp_errno; /* expected error number */ + char *desc; + int exp_errno; +} tcases[] = { + {0, NUM_BYTES, 1, "Invalid I/O address", EINVAL}, + {0, NUM_BYTES, 1, "Non super-user", EPERM}, }; -int TST_TOTAL = 2; -struct test_cases_t *test_cases; - -int main(int ac, char **av) -{ - int lc, i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (i = 0; i < TST_TOTAL; ++i) { - - if (i == 1) { - /* setup Non super-user for second test */ - if (setup1()) { - /* setup1() failed, skip this test */ - continue; - } - } - - /* Test the system call */ - - TEST(ioperm(test_cases[i].from, - test_cases[i].num, test_cases[i].turn_on)); - - if ((TEST_RETURN == EXP_RET_VAL) && - (TEST_ERRNO == test_cases[i].exp_errno)) { - tst_resm(TPASS, "Expected failure for %s, " - "errno: %d", test_cases[i].desc, - TEST_ERRNO); - } else { - tst_resm(TFAIL, "Unexpected results for %s ; " - "returned %ld (expected %d), errno %d " - "(expected errno %d)", - test_cases[i].desc, - TEST_RETURN, EXP_RET_VAL, - TEST_ERRNO, test_cases[i].exp_errno); - } - - if (i == 1) { - /* revert back to super user */ - cleanup1(); - } else { - } - } - - } - - /* cleanup and exit */ - cleanup(); - - tst_exit(); - -} - -/* setup1() - set up non-super user for second test case */ -int setup1(void) -{ - /* switch to "nobody" user */ - if (seteuid(ltpuser->pw_uid) == -1) { - tst_resm(TWARN, "Failed to set effective" - "uid to %d", ltpuser->pw_uid); - return 1; - } - return 0; -} - -/* cleanup1() - reset to super user for second test case */ -void cleanup1(void) -{ - /* reset user as root */ - SAFE_SETEUID(NULL, 0); -} - -/* setup() - performs all ONE TIME setup for this test */ -void setup(void) +static void setup(void) { - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - /* Check if "nobody" user id exists */ - if ((ltpuser = getpwnam(nobody_uid)) == NULL) { - tst_brkm(TBROK, NULL, "\"nobody\" user id doesn't exist"); - } - /* * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed * from kernel 2.6.8 to permit 16-bits (65536) ioperm * * Ricky Ng-Adam, rngadam@yahoo.com - * */ - test_cases = malloc(sizeof(struct test_cases_t) * 2); - test_cases[0].num = NUM_BYTES; - test_cases[0].turn_on = TURN_ON; - test_cases[0].desc = "Invalid I/O address"; - test_cases[0].exp_errno = EINVAL; - test_cases[1].num = NUM_BYTES; - test_cases[1].turn_on = TURN_ON; - test_cases[1].desc = "Non super-user"; - test_cases[1].exp_errno = EPERM; + */ if ((tst_kvercmp(2, 6, 8) < 0) || (tst_kvercmp(2, 6, 9) == 0)) { - /*try invalid ioperm on 1022, 1023, 1024 */ - test_cases[0].from = (IO_BITMAP_BITS - NUM_BYTES) + 1; - - /*try get valid ioperm on 1021, 1022, 1023 */ - test_cases[1].from = IO_BITMAP_BITS - NUM_BYTES; + tcases[0].from = (IO_BITMAP_BITS - NUM_BYTES) + 1; + tcases[1].from = IO_BITMAP_BITS - NUM_BYTES; } else { - /*try invalid ioperm on 65534, 65535, 65536 */ - test_cases[0].from = (IO_BITMAP_BITS_16 - NUM_BYTES) + 1; - - /*try valid ioperm on 65533, 65534, 65535 */ - test_cases[1].from = IO_BITMAP_BITS_16 - NUM_BYTES; + tcases[0].from = (IO_BITMAP_BITS_16 - NUM_BYTES) + 1; + tcases[1].from = IO_BITMAP_BITS_16 - NUM_BYTES; } - TEST_PAUSE; - + struct passwd *pw; + pw = SAFE_GETPWNAM("nobody"); + SAFE_SETEUID(pw->pw_uid); } -void cleanup(void) +static void cleanup(void) { - + SAFE_SETEUID(0); } -#else /* __i386__ */ - -#include "test.h" -#include "safe_macros.h" - -int TST_TOTAL = 0; - -int main(void) +static void verify_ioperm(unsigned int i) { - tst_resm(TPASS, - "LSB v1.3 does not specify ioperm() for this architecture."); - tst_exit(); + TEST(ioperm(tcases[i].from, tcases[i].num, tcases[i].turn_on)); + + if ((TST_RET == -1) && (TST_ERR == tcases[i].exp_errno)) { + tst_res(TPASS | TTERRNO, "Expected failure for %s, " + "errno: %d", tcases[i].desc, TST_ERR); + } else { + tst_res(TFAIL | TTERRNO, "Unexpected results for %s ; " + "returned %ld (expected -1), errno %d " + "(expected errno %d)", tcases[i].desc, + TST_RET, TST_ERR, tcases[i].exp_errno); + } } -#endif /* __i386__ */ +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = verify_ioperm, + .needs_root = 1, + .setup = setup, + .cleanup = cleanup, +}; + +#else +TST_TEST_TCONF("LSB v1.3 does not specify ioperm() for this architecture. (only for i386 or x86_64)"); +#endif /* __i386_, __x86_64__*/ -- 2.21.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 2/2] ioperm: Convert to new API 2020-07-16 6:10 ` [LTP] [PATCH v2 2/2] ioperm: Convert " Li Wang @ 2020-07-16 8:53 ` Petr Vorel 2020-07-16 9:15 ` [LTP] [v2,2/2] " Petr Vorel 1 sibling, 0 replies; 6+ messages in thread From: Petr Vorel @ 2020-07-16 8:53 UTC (permalink / raw) To: ltp Hi Li, Reviewed-by: Petr Vorel <pvorel@suse.cz> Thanks! Kind regards, Petr ^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [v2,2/2] ioperm: Convert to new API 2020-07-16 6:10 ` [LTP] [PATCH v2 2/2] ioperm: Convert " Li Wang 2020-07-16 8:53 ` Petr Vorel @ 2020-07-16 9:15 ` Petr Vorel 2020-07-16 11:40 ` Li Wang 1 sibling, 1 reply; 6+ messages in thread From: Petr Vorel @ 2020-07-16 9:15 UTC (permalink / raw) To: ltp Hi Li, Actually it fails to build on non-intel. https://travis-ci.org/github/pevik/ltp/jobs/708655670 /usr/src/ltp/testcases/kernel/syscalls/iopl/iopl02.c:21:10: fatal error: sys/io.h: No such file or directory 9793 #include <sys/io.h> https://travis-ci.org/github/pevik/ltp/builds/708655668 <sys/io.h> needs to be included behind #if defined __i386__ || defined(__x86_64__) guarder. Please fix it before merge. Kind regards, Petr ^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [v2,2/2] ioperm: Convert to new API 2020-07-16 9:15 ` [LTP] [v2,2/2] " Petr Vorel @ 2020-07-16 11:40 ` Li Wang 0 siblings, 0 replies; 6+ messages in thread From: Li Wang @ 2020-07-16 11:40 UTC (permalink / raw) To: ltp Hi Petr, On Thu, Jul 16, 2020 at 5:15 PM Petr Vorel <pvorel@suse.com> wrote: > Hi Li, > > Actually it fails to build on non-intel. > https://travis-ci.org/github/pevik/ltp/jobs/708655670 > /usr/src/ltp/testcases/kernel/syscalls/iopl/iopl02.c:21:10: fatal error: > sys/io.h: No such file or directory > 9793 #include <sys/io.h> > > https://travis-ci.org/github/pevik/ltp/builds/708655668 > > <sys/io.h> needs to be included behind #if defined __i386__ || > defined(__x86_64__) guarder. > Thanks for catching this, I have fixed it and pushed. -- Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200716/a795b7e5/attachment.htm> ^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 1/2] iopl: convert to new API 2020-07-16 6:10 [LTP] [PATCH v2 1/2] iopl: convert to new API Li Wang 2020-07-16 6:10 ` [LTP] [PATCH v2 2/2] ioperm: Convert " Li Wang @ 2020-07-16 8:53 ` Petr Vorel 1 sibling, 0 replies; 6+ messages in thread From: Petr Vorel @ 2020-07-16 8:53 UTC (permalink / raw) To: ltp Hi Li, Reviewed-by: Petr Vorel <pvorel@suse.cz> Thanks! Kind regards, Petr ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-16 11:40 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-07-16 6:10 [LTP] [PATCH v2 1/2] iopl: convert to new API Li Wang 2020-07-16 6:10 ` [LTP] [PATCH v2 2/2] ioperm: Convert " Li Wang 2020-07-16 8:53 ` Petr Vorel 2020-07-16 9:15 ` [LTP] [v2,2/2] " Petr Vorel 2020-07-16 11:40 ` Li Wang 2020-07-16 8:53 ` [LTP] [PATCH v2 1/2] iopl: convert " Petr Vorel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox