blob: 0229bd5d5ad26b5d9180fd85bae855f742fc2972 [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"
68#include "usctest.h"
Garrett Cooper17b121b2010-12-17 11:05:05 -080069#include "linux_syscall_numbers.h"
robbiew04a8ba52003-10-02 17:38:04 +000070
71#include <linux/capability.h>
72
robbiewd771da72002-12-27 18:41:54 +000073static void setup();
74static void cleanup();
75
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020076char *TCID = "capget01";
77int TST_TOTAL = 1;
robbiewd771da72002-12-27 18:41:54 +000078
subrata_modak56207ce2009-03-23 13:35:39 +000079static struct __user_cap_header_struct header; /* cap_user_header_t is a pointer
80 to __user_cap_header_struct */
robbiewd771da72002-12-27 18:41:54 +000081
subrata_modak56207ce2009-03-23 13:35:39 +000082static struct __user_cap_data_struct data; /* cap_user_data_t is a pointer to
83 __user_cap_data_struct */
robbiewd771da72002-12-27 18:41:54 +000084
subrata_modak56207ce2009-03-23 13:35:39 +000085int main(int ac, char **av)
robbiewd771da72002-12-27 18:41:54 +000086{
87
Garrett Cooper17b121b2010-12-17 11:05:05 -080088 int lc;
89 char *msg;
robbiewd771da72002-12-27 18:41:54 +000090
Garrett Cooper1acf4712010-12-16 14:53:32 -080091 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080092 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewd771da72002-12-27 18:41:54 +000093
robbiewd771da72002-12-27 18:41:54 +000094 setup();
95
Garrett Cooper17b121b2010-12-17 11:05:05 -080096 /* header.version must be _LINUX_CAPABILITY_VERSION */
97 header.version = _LINUX_CAPABILITY_VERSION;
98
robbiewd771da72002-12-27 18:41:54 +000099 for (lc = 0; TEST_LOOPING(lc); lc++) {
100
Caspar Zhangd59a6592013-03-07 14:59:12 +0800101 tst_count = 0;
robbiewd771da72002-12-27 18:41:54 +0000102
Jan Stancek359980f2013-02-15 10:16:05 +0100103 TEST(ltp_syscall(__NR_capget, &header, &data));
robbiewd771da72002-12-27 18:41:54 +0000104
105 if (TEST_RETURN == 0) {
vapier72d58562009-08-28 11:24:25 +0000106 tst_resm(TPASS, "capget() returned %ld", TEST_RETURN);
robbiewd771da72002-12-27 18:41:54 +0000107 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800108 tst_resm(TFAIL | TTERRNO,
109 "Test Failed, capget() returned %ld",
vapier72d58562009-08-28 11:24:25 +0000110 TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000111 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800112 }
robbiewd771da72002-12-27 18:41:54 +0000113
robbiewd771da72002-12-27 18:41:54 +0000114 cleanup();
115
Garrett Cooper17b121b2010-12-17 11:05:05 -0800116 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800117}
robbiewd771da72002-12-27 18:41:54 +0000118
Mike Frysingerc57fba52014-04-09 18:56:30 -0400119void setup(void)
robbiewd771da72002-12-27 18:41:54 +0000120{
Garrett Cooper2c282152010-12-16 00:55:50 -0800121
robbiewd771da72002-12-27 18:41:54 +0000122 tst_sig(NOFORK, DEF_HANDLER, cleanup);
123
robbiewd771da72002-12-27 18:41:54 +0000124 TEST_PAUSE;
125
Garrett Cooper2c282152010-12-16 00:55:50 -0800126}
robbiewd771da72002-12-27 18:41:54 +0000127
Mike Frysingerc57fba52014-04-09 18:56:30 -0400128void cleanup(void)
robbiewd771da72002-12-27 18:41:54 +0000129{
robbiewd771da72002-12-27 18:41:54 +0000130 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700131}