blob: 5660cba1bb991eca909ce07695533ebaf2c9b6ff [file] [log] [blame]
robbiewd771da72002-12-27 18:41:54 +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.
robbiewd771da72002-12-27 18:41:54 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiewd771da72002-12-27 18:41:54 +000019 * TEST IDENTIFIER : capget01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
robbiewd771da72002-12-27 18:41:54 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiewd771da72002-12-27 18:41:54 +000023 * TEST TITLE : Basic test for capget(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiewd771da72002-12-27 18:41:54 +000025 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiewd771da72002-12-27 18:41:54 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiewd771da72002-12-27 18:41:54 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * This is a Phase I test for the capget(2) system call.
35 * It is intended to provide a limited exposure of the system call.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
robbiewd771da72002-12-27 18:41:54 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
robbiewd771da72002-12-27 18:41:54 +000041 * Test:
42 * Loop if the proper options are given.
43 * call capget()
44 * if return value == 0
45 * Test passed
46 * Otherwise
47 * Test failed
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
robbiewd771da72002-12-27 18:41:54 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
robbiewd771da72002-12-27 18:41:54 +000052 * USAGE: <for command-line>
53 * capget01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
54 * where, -c n : Run n copies concurrently.
55 * -e : Turn on errno logging.
56 * -h : Show help screen
57 * -f : Turn off functional testing
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.
63 ****************************************************************/
robbiewd771da72002-12-27 18:41:54 +000064
65#include <errno.h>
robbiewb204c202003-03-25 17:10:15 +000066#include <unistd.h>
robbiewd771da72002-12-27 18:41:54 +000067#include "test.h"
Garrett Cooper17b121b2010-12-17 11:05:05 -080068#include "linux_syscall_numbers.h"
robbiew04a8ba52003-10-02 17:38:04 +000069
70#include <linux/capability.h>
71
robbiewd771da72002-12-27 18:41:54 +000072static void setup();
73static void cleanup();
74
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020075char *TCID = "capget01";
76int TST_TOTAL = 1;
robbiewd771da72002-12-27 18:41:54 +000077
subrata_modak56207ce2009-03-23 13:35:39 +000078static struct __user_cap_header_struct header; /* cap_user_header_t is a pointer
79 to __user_cap_header_struct */
robbiewd771da72002-12-27 18:41:54 +000080
subrata_modak56207ce2009-03-23 13:35:39 +000081static struct __user_cap_data_struct data; /* cap_user_data_t is a pointer to
82 __user_cap_data_struct */
robbiewd771da72002-12-27 18:41:54 +000083
subrata_modak56207ce2009-03-23 13:35:39 +000084int main(int ac, char **av)
robbiewd771da72002-12-27 18:41:54 +000085{
86
Garrett Cooper17b121b2010-12-17 11:05:05 -080087 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020088 const char *msg;
robbiewd771da72002-12-27 18:41:54 +000089
Garrett Cooper1acf4712010-12-16 14:53:32 -080090 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080091 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewd771da72002-12-27 18:41:54 +000092
robbiewd771da72002-12-27 18:41:54 +000093 setup();
94
Garrett Cooper17b121b2010-12-17 11:05:05 -080095 /* header.version must be _LINUX_CAPABILITY_VERSION */
96 header.version = _LINUX_CAPABILITY_VERSION;
97
robbiewd771da72002-12-27 18:41:54 +000098 for (lc = 0; TEST_LOOPING(lc); lc++) {
99
Caspar Zhangd59a6592013-03-07 14:59:12 +0800100 tst_count = 0;
robbiewd771da72002-12-27 18:41:54 +0000101
Jan Stancek359980f2013-02-15 10:16:05 +0100102 TEST(ltp_syscall(__NR_capget, &header, &data));
robbiewd771da72002-12-27 18:41:54 +0000103
104 if (TEST_RETURN == 0) {
vapier72d58562009-08-28 11:24:25 +0000105 tst_resm(TPASS, "capget() returned %ld", TEST_RETURN);
robbiewd771da72002-12-27 18:41:54 +0000106 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107 tst_resm(TFAIL | TTERRNO,
108 "Test Failed, capget() returned %ld",
vapier72d58562009-08-28 11:24:25 +0000109 TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000110 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800111 }
robbiewd771da72002-12-27 18:41:54 +0000112
robbiewd771da72002-12-27 18:41:54 +0000113 cleanup();
114
Garrett Cooper17b121b2010-12-17 11:05:05 -0800115 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800116}
robbiewd771da72002-12-27 18:41:54 +0000117
Mike Frysingerc57fba52014-04-09 18:56:30 -0400118void setup(void)
robbiewd771da72002-12-27 18:41:54 +0000119{
Garrett Cooper2c282152010-12-16 00:55:50 -0800120
robbiewd771da72002-12-27 18:41:54 +0000121 tst_sig(NOFORK, DEF_HANDLER, cleanup);
122
robbiewd771da72002-12-27 18:41:54 +0000123 TEST_PAUSE;
124
Garrett Cooper2c282152010-12-16 00:55:50 -0800125}
robbiewd771da72002-12-27 18:41:54 +0000126
Mike Frysingerc57fba52014-04-09 18:56:30 -0400127void cleanup(void)
robbiewd771da72002-12-27 18:41:54 +0000128{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700129}