blob: ae3f533eb51cc714d753e5e69d0113ebc5887104 [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 : sysfs02
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 * It is intended to provide a limited exposure of the system call.
36 * This test is run for option 2 for sysfs(2)
vapier238755b2007-03-22 06:50:54 +000037 *
subrata_modak56207ce2009-03-23 13:35:39 +000038 * Setup:
robbiew9a55a782002-12-26 20:45:16 +000039 * Setup signal handling.
40 * Pause for SIGUSR1 if option specified.
vapier238755b2007-03-22 06:50:54 +000041 *
subrata_modak56207ce2009-03-23 13:35:39 +000042 * Test:
robbiew9a55a782002-12-26 20:45:16 +000043 * 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.
vapier238755b2007-03-22 06:50:54 +000048 *
subrata_modak56207ce2009-03-23 13:35:39 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
vapier238755b2007-03-22 06:50:54 +000051 *
robbiew9a55a782002-12-26 20:45:16 +000052 * USAGE: <for command-line>
53 * sysfs02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-t] [-p] [-f]
54 * where:
subrata_modak56207ce2009-03-23 13:35:39 +000055 * -c n : run n copies simultaneously
56 * -e : Turn on errno logging.
robbiew9a55a782002-12-26 20:45:16 +000057 * -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.
vapier238755b2007-03-22 06:50:54 +000062 *
robbiew9a55a782002-12-26 20:45:16 +000063 *RESTRICTIONS:
64 *There is no glibc or libc support
65 *****************************************************************************/
66
67#include "test.h"
robbiew9a55a782002-12-26 20:45:16 +000068#include <errno.h>
69#include <unistd.h>
70#include <syscall.h>
71
72static void setup();
73static void cleanup();
74
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020075char *TCID = "sysfs02";
76int TST_TOTAL = 1;
robbiew9a55a782002-12-26 20:45:16 +000077
vapier238755b2007-03-22 06:50:54 +000078int main(int ac, char **av)
robbiew9a55a782002-12-26 20:45:16 +000079{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020080 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020081 const char *msg;
vapier238755b2007-03-22 06:50:54 +000082 char buf[40]; /* 40 bytes suffice to store fs name */
robbiew9a55a782002-12-26 20:45:16 +000083
Garrett Cooper45e285d2010-11-22 12:19:25 -080084 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080085 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew9a55a782002-12-26 20:45:16 +000086
robbiew9a55a782002-12-26 20:45:16 +000087 setup();
88
subrata_modak5e278252008-04-23 07:21:00 +000089#ifdef __NR_sysfs
Garrett Cooper2c282152010-12-16 00:55:50 -080090
robbiew9a55a782002-12-26 20:45:16 +000091 for (lc = 0; TEST_LOOPING(lc); lc++) {
92
Caspar Zhangd59a6592013-03-07 14:59:12 +080093 tst_count = 0;
robbiew9a55a782002-12-26 20:45:16 +000094
95 /*option 2 buf holds fs name */
vapier83de3272006-08-06 04:40:53 +000096 TEST(syscall(__NR_sysfs, 2, 0, buf));
robbiew9a55a782002-12-26 20:45:16 +000097
98 /* check return code */
99 if (TEST_RETURN == -1) {
robbiew9a55a782002-12-26 20:45:16 +0000100 tst_resm(TFAIL, "sysfs(2) Failed for "
vapier238755b2007-03-22 06:50:54 +0000101 "option 2 and returned"
102 " %d as error number", TEST_ERRNO);
robbiew9a55a782002-12-26 20:45:16 +0000103 } else {
104 tst_resm(TPASS, "sysfs(2) Passed for option 2");
105 }
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();
114
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800115 tst_exit();
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;
Garrett Cooper2c282152010-12-16 00:55:50 -0800125}
robbiew9a55a782002-12-26 20:45:16 +0000126
127/*
128 * cleanup() - Performs one time cleanup for this test at
129 * completion or premature exit
130 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400131void cleanup(void)
robbiew9a55a782002-12-26 20:45:16 +0000132{
robbiew9a55a782002-12-26 20:45:16 +0000133
Chris Dearmanec6edca2012-10-17 19:54:01 -0700134}