blob: f141e72d6fe0ba9d7ef04b23600ede666dc2520c [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 *
robbiew9a55a782002-12-26 20:45:16 +000019 * TEST IDENTIFIER : sysfs04
20 *
vapier238755b2007-03-22 06:50:54 +000021 *
robbiew9a55a782002-12-26 20:45:16 +000022 * EXECUTED BY : anyone
vapier238755b2007-03-22 06:50:54 +000023 *
robbiew9a55a782002-12-26 20:45:16 +000024 * TEST TITLE : Test checking for basic error conditions
subrata_modak56207ce2009-03-23 13:35:39 +000025 * for sysfs(2)
vapier238755b2007-03-22 06:50:54 +000026 *
27 * TEST CASE TOTAL : 1
28 *
robbiew9a55a782002-12-26 20:45:16 +000029 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
vapier238755b2007-03-22 06:50:54 +000030 *
robbiew9a55a782002-12-26 20:45:16 +000031 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000032 * Uses SIGUSR1 to pause before test if option set.
33 * (See the parse_opts(3) man page).
robbiew9a55a782002-12-26 20:45:16 +000034 *
35 * DESCRIPTION
vapier238755b2007-03-22 06:50:54 +000036 * This test case checks whether sysfs(2) system call returns
robbiew9a55a782002-12-26 20:45:16 +000037 * appropriate error number for invalid
38 * option.
vapier238755b2007-03-22 06:50:54 +000039 *
subrata_modak56207ce2009-03-23 13:35:39 +000040 * Setup:
robbiew9a55a782002-12-26 20:45:16 +000041 * Setup signal handling.
42 * Pause for SIGUSR1 if option specified.
vapier238755b2007-03-22 06:50:54 +000043 *
subrata_modak56207ce2009-03-23 13:35:39 +000044 * Test:
robbiew9a55a782002-12-26 20:45:16 +000045 * Loop if the proper options are given.
46 * Execute system call with invaid option parameter
vapier238755b2007-03-22 06:50:54 +000047 *
robbiew9a55a782002-12-26 20:45:16 +000048 * Check return code, if system call fails with errno == expected errno
49 * Issue syscall passed with expected errno
vapier238755b2007-03-22 06:50:54 +000050 * Otherwise,
robbiew9a55a782002-12-26 20:45:16 +000051 * Issue syscall failed to produce expected errno
vapier238755b2007-03-22 06:50:54 +000052 *
subrata_modak56207ce2009-03-23 13:35:39 +000053 * Cleanup:
54 * Do cleanup for the test.
vapier238755b2007-03-22 06:50:54 +000055 *
robbiew9a55a782002-12-26 20:45:16 +000056 * USAGE: <for command-line>
57 * sysfs04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
58 * where:
subrata_modak56207ce2009-03-23 13:35:39 +000059 * -c n : run n copies simultaneously
robbiew9a55a782002-12-26 20:45:16 +000060 * -e : Turn on errno logging.
61 * -i n : Execute test n times.
62 * -I x : Execute test for x seconds.
63 * -p : Pause for SIGUSR1 before starting
64 * -P x : Pause for x seconds between iterations.
65 * -t : Turn on syscall timing.
vapier238755b2007-03-22 06:50:54 +000066 *
robbiew9a55a782002-12-26 20:45:16 +000067 *RESTRICTIONS:
68 *No libc or glibc support
69 *****************************************************************************/
70
71#include <errno.h>
72#include <syscall.h>
73#include "test.h"
robbiew9a55a782002-12-26 20:45:16 +000074
75#define INVALID_OPTION 100
76static void setup();
77static void cleanup();
78
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020079char *TCID = "sysfs04";
80int TST_TOTAL = 1;
robbiew9a55a782002-12-26 20:45:16 +000081
vapier238755b2007-03-22 06:50:54 +000082int main(int ac, char **av)
robbiew9a55a782002-12-26 20:45:16 +000083{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020084 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020085 const char *msg;
robbiew9a55a782002-12-26 20:45:16 +000086
Garrett Cooper45e285d2010-11-22 12:19:25 -080087 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080088 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew9a55a782002-12-26 20:45:16 +000089
robbiew9a55a782002-12-26 20:45:16 +000090 setup();
91
subrata_modak5e278252008-04-23 07:21:00 +000092#ifdef __NR_sysfs
Garrett Cooper2c282152010-12-16 00:55:50 -080093
robbiew9a55a782002-12-26 20:45:16 +000094 for (lc = 0; TEST_LOOPING(lc); lc++) {
95
Caspar Zhangd59a6592013-03-07 14:59:12 +080096 tst_count = 0;
vapier83de3272006-08-06 04:40:53 +000097 TEST(syscall(__NR_sysfs, INVALID_OPTION));
robbiew9a55a782002-12-26 20:45:16 +000098
99 /* check return code */
100 if ((TEST_RETURN == -1) && (TEST_ERRNO == EINVAL)) {
vapier238755b2007-03-22 06:50:54 +0000101 tst_resm(TPASS, "sysfs(2) expected failure;"
102 " Got errno - EINVAL :" " Invalid option");
robbiew9a55a782002-12-26 20:45:16 +0000103 } else {
104 tst_resm(TFAIL, "sysfs(2) failed to produce"
vapier238755b2007-03-22 06:50:54 +0000105 " expected error; %d, errno"
106 " : EINVAL and got %d", EINVAL, TEST_ERRNO);
robbiew9a55a782002-12-26 20:45:16 +0000107 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800108 }
subrata_modak5e278252008-04-23 07:21:00 +0000109#else
subrata_modak56207ce2009-03-23 13:35:39 +0000110 tst_resm(TWARN,
111 "This test can only run on kernels that support the sysfs system call");
subrata_modak5e278252008-04-23 07:21:00 +0000112#endif
robbiew9a55a782002-12-26 20:45:16 +0000113
vapier238755b2007-03-22 06:50:54 +0000114 /*Clean up and exit */
robbiew9a55a782002-12-26 20:45:16 +0000115 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800116 tst_exit();
robbiew9a55a782002-12-26 20:45:16 +0000117
vapier238755b2007-03-22 06:50:54 +0000118} /*End of main */
robbiew9a55a782002-12-26 20:45:16 +0000119
120/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400121void setup(void)
robbiew9a55a782002-12-26 20:45:16 +0000122{
Garrett Cooper2c282152010-12-16 00:55:50 -0800123
robbiew9a55a782002-12-26 20:45:16 +0000124 tst_sig(NOFORK, DEF_HANDLER, cleanup);
125
robbiew9a55a782002-12-26 20:45:16 +0000126 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -0800127}
robbiew9a55a782002-12-26 20:45:16 +0000128
129/*
130* cleanup() - Performs one time cleanup for this test at
131* completion or premature exit
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}