robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 1 | /* |
| 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 Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : capget01 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 21 | * EXECUTED BY : anyone |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for capget(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 27 | * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 29 | * 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 36 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 37 | * Setup: |
| 38 | * Setup signal handling. |
| 39 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 40 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 41 | * 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 48 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 49 | * Cleanup: |
| 50 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 51 | * |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 52 | * 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 | ****************************************************************/ |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 64 | |
| 65 | #include <errno.h> |
robbiew | b204c20 | 2003-03-25 17:10:15 +0000 | [diff] [blame] | 66 | #include <unistd.h> |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 67 | #include "test.h" |
| 68 | #include "usctest.h" |
Garrett Cooper | 17b121b | 2010-12-17 11:05:05 -0800 | [diff] [blame] | 69 | #include "linux_syscall_numbers.h" |
robbiew | 04a8ba5 | 2003-10-02 17:38:04 +0000 | [diff] [blame] | 70 | |
| 71 | #include <linux/capability.h> |
| 72 | |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 73 | static void setup(); |
| 74 | static void cleanup(); |
| 75 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 76 | char *TCID = "capget01"; |
| 77 | int TST_TOTAL = 1; |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 78 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | static struct __user_cap_header_struct header; /* cap_user_header_t is a pointer |
| 80 | to __user_cap_header_struct */ |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 81 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | static struct __user_cap_data_struct data; /* cap_user_data_t is a pointer to |
| 83 | __user_cap_data_struct */ |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | int main(int ac, char **av) |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 86 | { |
| 87 | |
Garrett Cooper | 17b121b | 2010-12-17 11:05:05 -0800 | [diff] [blame] | 88 | int lc; |
| 89 | char *msg; |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 90 | |
Garrett Cooper | 1acf471 | 2010-12-16 14:53:32 -0800 | [diff] [blame] | 91 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 92 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 93 | |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 94 | setup(); |
| 95 | |
Garrett Cooper | 17b121b | 2010-12-17 11:05:05 -0800 | [diff] [blame] | 96 | /* header.version must be _LINUX_CAPABILITY_VERSION */ |
| 97 | header.version = _LINUX_CAPABILITY_VERSION; |
| 98 | |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 99 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 100 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 101 | tst_count = 0; |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 102 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 103 | TEST(ltp_syscall(__NR_capget, &header, &data)); |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 104 | |
| 105 | if (TEST_RETURN == 0) { |
vapier | 72d5856 | 2009-08-28 11:24:25 +0000 | [diff] [blame] | 106 | tst_resm(TPASS, "capget() returned %ld", TEST_RETURN); |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 107 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 108 | tst_resm(TFAIL | TTERRNO, |
| 109 | "Test Failed, capget() returned %ld", |
vapier | 72d5856 | 2009-08-28 11:24:25 +0000 | [diff] [blame] | 110 | TEST_RETURN); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 111 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 112 | } |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 113 | |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 114 | cleanup(); |
| 115 | |
Garrett Cooper | 17b121b | 2010-12-17 11:05:05 -0800 | [diff] [blame] | 116 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 117 | } |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 118 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame^] | 119 | void setup(void) |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 120 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 121 | |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 122 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 123 | |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 124 | TEST_PAUSE; |
| 125 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 126 | } |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 127 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame^] | 128 | void cleanup(void) |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 129 | { |
robbiew | d771da7 | 2002-12-27 18:41:54 +0000 | [diff] [blame] | 130 | TEST_CLEANUP; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 131 | } |