blob: 3121fe5b9ed29eea13eaa0388b9a13107c4ad3a1 [file] [log] [blame]
robbiew9a55a782002-12-26 20:45:16 +00001/*
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 Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiew9a55a782002-12-26 20:45:16 +000015 *
16 */
17/**************************************************************************
vapier238755b2007-03-22 06:50:54 +000018 *
19 * TEST IDENTIFIER : sysfs01
20 *
robbiew9a55a782002-12-26 20:45:16 +000021 * EXECUTED BY : anyone
vapier238755b2007-03-22 06:50:54 +000022 *
robbiew9a55a782002-12-26 20:45:16 +000023 * TEST TITLE : Basic test for sysfs(2)
vapier238755b2007-03-22 06:50:54 +000024 *
robbiew9a55a782002-12-26 20:45:16 +000025 * TEST CASE TOTAL : 1
vapier238755b2007-03-22 06:50:54 +000026 *
robbiew9a55a782002-12-26 20:45:16 +000027 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
vapier238755b2007-03-22 06:50:54 +000028 *
robbiew9a55a782002-12-26 20:45:16 +000029 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000030 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
robbiew9a55a782002-12-26 20:45:16 +000032 *
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.
vapier238755b2007-03-22 06:50:54 +000037 *
38 *
subrata_modak56207ce2009-03-23 13:35:39 +000039 * Setup:
robbiew9a55a782002-12-26 20:45:16 +000040 * Setup signal handling.
41 * Pause for SIGUSR1 if option specified.
vapier238755b2007-03-22 06:50:54 +000042 *
subrata_modak56207ce2009-03-23 13:35:39 +000043 * Test:
robbiew9a55a782002-12-26 20:45:16 +000044 * 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.
vapier238755b2007-03-22 06:50:54 +000049 *
subrata_modak56207ce2009-03-23 13:35:39 +000050 * Cleanup:
51 * Print errno log and/or timing stats if options given
vapier238755b2007-03-22 06:50:54 +000052 *
robbiew9a55a782002-12-26 20:45:16 +000053 * USAGE: <for command-line>
54 * sysfs01 [-c n] [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p]
55 * where:
subrata_modak56207ce2009-03-23 13:35:39 +000056 * -c n : run n copies simultaneously.
robbiew9a55a782002-12-26 20:45:16 +000057 * -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.
vapier238755b2007-03-22 06:50:54 +000063 *
robbiew9a55a782002-12-26 20:45:16 +000064 *RESTRICTIONS:
65 *There is no glibc or libc support
subrata_modak79c12182007-04-28 11:30:51 +000066 *Kernel should be compiled with proc filesystem support
robbiew9a55a782002-12-26 20:45:16 +000067 ******************************************************************************/
68
69#include "test.h"
robbiew9a55a782002-12-26 20:45:16 +000070#include <errno.h>
71#include <unistd.h>
72#include <syscall.h>
73
74static void setup();
75static void cleanup();
76
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020077char *TCID = "sysfs01";
78int TST_TOTAL = 1;
robbiew9a55a782002-12-26 20:45:16 +000079
vapier238755b2007-03-22 06:50:54 +000080int main(int ac, char **av)
robbiew9a55a782002-12-26 20:45:16 +000081{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020082 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020083 const char *msg;
robbiew9a55a782002-12-26 20:45:16 +000084
Garrett Cooper45e285d2010-11-22 12:19:25 -080085 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080086 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew9a55a782002-12-26 20:45:16 +000087
robbiew9a55a782002-12-26 20:45:16 +000088 setup();
89
subrata_modak5e278252008-04-23 07:21:00 +000090#ifdef __NR_sysfs
Garrett Cooper2c282152010-12-16 00:55:50 -080091
robbiew9a55a782002-12-26 20:45:16 +000092 for (lc = 0; TEST_LOOPING(lc); lc++) {
93
Caspar Zhangd59a6592013-03-07 14:59:12 +080094 tst_count = 0;
robbiew9a55a782002-12-26 20:45:16 +000095
vapier238755b2007-03-22 06:50:54 +000096 /* option 1, buf holds fs name */
subrata_modak79c12182007-04-28 11:30:51 +000097 TEST(syscall(__NR_sysfs, 1, "proc"));
robbiew9a55a782002-12-26 20:45:16 +000098
99 /* check return code */
100 if (TEST_RETURN == -1) {
robbiew9a55a782002-12-26 20:45:16 +0000101 tst_resm(TFAIL, "sysfs(2) Failed for "
vapier238755b2007-03-22 06:50:54 +0000102 "option 1 and set errno to %d", TEST_ERRNO);
robbiew9a55a782002-12-26 20:45:16 +0000103 } else {
vapier238755b2007-03-22 06:50:54 +0000104 tst_resm(TPASS, "sysfs(2) Passed for " "option 1");
robbiew9a55a782002-12-26 20:45:16 +0000105 }
vapier238755b2007-03-22 06:50:54 +0000106 } /*End of TEST_LOOPING */
subrata_modak5e278252008-04-23 07:21:00 +0000107#else
subrata_modak56207ce2009-03-23 13:35:39 +0000108 tst_resm(TWARN,
109 "This test can only run on kernels that support the sysfs system call");
subrata_modak5e278252008-04-23 07:21:00 +0000110#endif
robbiew9a55a782002-12-26 20:45:16 +0000111
vapier238755b2007-03-22 06:50:54 +0000112 /*Clean up and exit */
robbiew9a55a782002-12-26 20:45:16 +0000113 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800114 tst_exit();
robbiew9a55a782002-12-26 20:45:16 +0000115
robbiew9a55a782002-12-26 20:45:16 +0000116}
117
118/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400119void setup(void)
robbiew9a55a782002-12-26 20:45:16 +0000120{
Garrett Cooper2c282152010-12-16 00:55:50 -0800121
robbiew9a55a782002-12-26 20:45:16 +0000122 tst_sig(NOFORK, DEF_HANDLER, cleanup);
123
robbiew9a55a782002-12-26 20:45:16 +0000124 TEST_PAUSE;
125
Garrett Cooper2c282152010-12-16 00:55:50 -0800126}
robbiew9a55a782002-12-26 20:45:16 +0000127
128/*
129 * cleanup() - Performs one time cleanup for this test at
130 * completion or premature exit
131 */
132
Mike Frysingerc57fba52014-04-09 18:56:30 -0400133void cleanup(void)
robbiew9a55a782002-12-26 20:45:16 +0000134{
robbiew9a55a782002-12-26 20:45:16 +0000135
Chris Dearmanec6edca2012-10-17 19:54:01 -0700136}