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 : sysfs01 |
| 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 | * This test is carried out for option 1 for sysfs(2). |
| 36 | * It is intended to provide a limited exposure of the system call. |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 37 | * |
| 38 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 39 | * Setup: |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 40 | * Setup signal handling. |
| 41 | * Pause for SIGUSR1 if option specified. |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 42 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 43 | * Test: |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 44 | * Loop if the proper options are given. |
| 45 | * Execute system call |
| 46 | * Check return code, if system call failed (return=-1) |
| 47 | * Log the errno and Issue a FAIL message. |
| 48 | * Otherwise, Issue a PASS message. |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 49 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 50 | * Cleanup: |
| 51 | * Print errno log and/or timing stats if options given |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 52 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 53 | * USAGE: <for command-line> |
| 54 | * sysfs01 [-c n] [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p] |
| 55 | * where: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 56 | * -c n : run n copies simultaneously. |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 57 | * -e : Turn on errno logging. |
| 58 | * -i n : Execute test n times. |
| 59 | * -I x : Execute test for x seconds. |
| 60 | * -p : Pause for SIGUSR1 before starting |
| 61 | * -P x : Pause for x seconds between iterations. |
| 62 | * -t : Turn on syscall timing. |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 63 | * |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 64 | *RESTRICTIONS: |
| 65 | *There is no glibc or libc support |
subrata_modak | 79c1218 | 2007-04-28 11:30:51 +0000 | [diff] [blame] | 66 | *Kernel should be compiled with proc filesystem support |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 67 | ******************************************************************************/ |
| 68 | |
| 69 | #include "test.h" |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 70 | #include <errno.h> |
| 71 | #include <unistd.h> |
| 72 | #include <syscall.h> |
| 73 | |
| 74 | static void setup(); |
| 75 | static void cleanup(); |
| 76 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 77 | char *TCID = "sysfs01"; |
| 78 | int TST_TOTAL = 1; |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 79 | |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 80 | int main(int ac, char **av) |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 81 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 82 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 83 | const char *msg; |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 84 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 85 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 86 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 87 | |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 88 | setup(); |
| 89 | |
subrata_modak | 5e27825 | 2008-04-23 07:21:00 +0000 | [diff] [blame] | 90 | #ifdef __NR_sysfs |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 91 | |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 92 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 93 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 94 | tst_count = 0; |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 95 | |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 96 | /* option 1, buf holds fs name */ |
subrata_modak | 79c1218 | 2007-04-28 11:30:51 +0000 | [diff] [blame] | 97 | TEST(syscall(__NR_sysfs, 1, "proc")); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 98 | |
| 99 | /* check return code */ |
| 100 | if (TEST_RETURN == -1) { |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 101 | tst_resm(TFAIL, "sysfs(2) Failed for " |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 102 | "option 1 and set errno to %d", TEST_ERRNO); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 103 | } else { |
vapier | 238755b | 2007-03-22 06:50:54 +0000 | [diff] [blame] | 104 | tst_resm(TPASS, "sysfs(2) Passed for " "option 1"); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 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(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 114 | tst_exit(); |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 115 | |
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; |
| 125 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 126 | } |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * cleanup() - Performs one time cleanup for this test at |
| 130 | * completion or premature exit |
| 131 | */ |
| 132 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 133 | void cleanup(void) |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 134 | { |
robbiew | 9a55a78 | 2002-12-26 20:45:16 +0000 | [diff] [blame] | 135 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 136 | } |