robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /************************************************************************** |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 18 | * |
| 19 | * TEST IDENTIFIER : sysfs02 |
| 20 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 21 | * EXECUTED BY : anyone |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 22 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for sysfs(2) |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 24 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 1 |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 26 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 27 | * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com> |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 28 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 29 | * SIGNALS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 30 | * Uses SIGUSR1 to pause before test if option set. |
| 31 | * (See the parse_opts(3) man page). |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 32 | * |
| 33 | * DESCRIPTION |
| 34 | * This is a Phase I test for the sysfs(2) system call. |
| 35 | * It is intended to provide a limited exposure of the system call. |
| 36 | * This test is run for option 2 for sysfs(2) |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 37 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 38 | * Setup: |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 39 | * Setup signal handling. |
| 40 | * Pause for SIGUSR1 if option specified. |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 41 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 42 | * Test: |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 43 | * Loop if the proper options are given. |
| 44 | * Execute system call |
| 45 | * Check return code, if system call failed (return=-1) |
| 46 | * Log the errno and Issue a FAIL message. |
| 47 | * Otherwise, Issue a PASS message. |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 48 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 49 | * Cleanup: |
| 50 | * Print errno log and/or timing stats if options given |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 51 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 52 | * USAGE: <for command-line> |
| 53 | * sysfs02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-t] [-p] [-f] |
| 54 | * where: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 55 | * -c n : run n copies simultaneously |
| 56 | * -e : Turn on errno logging. |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 57 | * -i n : Execute test n times. |
| 58 | * -I x : Execute test for x seconds. |
| 59 | * -p : Pause for SIGUSR1 before starting |
| 60 | * -P x : Pause for x seconds between iterations. |
| 61 | * -t : Turn on syscall timing. |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 62 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 63 | *RESTRICTIONS: |
| 64 | *There is no glibc or libc support |
| 65 | *****************************************************************************/ |
| 66 | |
| 67 | #include "test.h" |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 68 | #include <errno.h> |
| 69 | #include <unistd.h> |
| 70 | #include <syscall.h> |
| 71 | |
| 72 | static void setup(); |
| 73 | static void cleanup(); |
| 74 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 75 | char *TCID = "sysfs02"; |
| 76 | int TST_TOTAL = 1; |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 77 | |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 78 | int main(int ac, char **av) |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 79 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 80 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 81 | const char *msg; |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 82 | char buf[40]; /* 40 bytes suffice to store fs name */ |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 83 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 84 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 85 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 86 | |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 87 | setup(); |
| 88 | |
subrata_modak | 5e27825 | 2008-04-23 07:21:00 +0000 | [diff] [blame] | 89 | #ifdef __NR_sysfs |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 90 | |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 91 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 92 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 93 | tst_count = 0; |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 94 | |
| 95 | /*option 2 buf holds fs name */ |
vapier | 83de327 | 2006-08-06 04:40:53 +0000 | [diff] [blame] | 96 | TEST(syscall(__NR_sysfs, 2, 0, buf)); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 97 | |
| 98 | /* check return code */ |
| 99 | if (TEST_RETURN == -1) { |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 100 | tst_resm(TFAIL, "sysfs(2) Failed for " |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 101 | "option 2 and returned" |
| 102 | " %d as error number", TEST_ERRNO); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 103 | } else { |
| 104 | tst_resm(TPASS, "sysfs(2) Passed for option 2"); |
| 105 | } |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 106 | } /*End of TEST_LOOPING */ |
subrata_modak | 5e27825 | 2008-04-23 07:21:00 +0000 | [diff] [blame] | 107 | #else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 108 | tst_resm(TWARN, |
| 109 | "This test can only run on kernels that support the sysfs system call"); |
subrata_modak | 5e27825 | 2008-04-23 07:21:00 +0000 | [diff] [blame] | 110 | #endif |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 111 | |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 112 | /*Clean up and exit */ |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 113 | cleanup(); |
| 114 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 115 | tst_exit(); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* setup() - performs all ONE TIME setup for this test */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 119 | void setup(void) |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 120 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 121 | |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 122 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 123 | |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 124 | TEST_PAUSE; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 125 | } |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * cleanup() - Performs one time cleanup for this test at |
| 129 | * completion or premature exit |
| 130 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 131 | void cleanup(void) |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 132 | { |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 133 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 134 | } |