subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2001 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Test Name: get_robust_list01 |
| 22 | * |
| 23 | * Test Description: |
| 24 | * Verify that get_robust_list() returns the proper errno for various failure |
| 25 | * cases |
| 26 | * |
| 27 | * Usage: <for command-line> |
| 28 | * get_robust_list01 [-c n] [-e][-i n] [-I x] [-p x] [-t] |
| 29 | * where, -c n : Run n copies concurrently. |
| 30 | * -e : Turn on errno logging. |
| 31 | * -i n : Execute test n times. |
| 32 | * -I x : Execute test for x seconds. |
| 33 | * -P x : Pause for x seconds between iterations. |
| 34 | * -t : Turn on syscall timing. |
| 35 | * |
| 36 | * History |
| 37 | * 07/2008 Ramon de Carvalho Valle <rcvalle@br.ibm.com> |
| 38 | * -Created |
| 39 | * |
| 40 | * Restrictions: |
| 41 | * None. |
| 42 | * |
| 43 | */ |
| 44 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 45 | #include <sys/types.h> |
| 46 | #include <sys/syscall.h> |
| 47 | |
| 48 | #include <errno.h> |
| 49 | #include <stdint.h> |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 50 | #include <stdio.h> |
| 51 | #include <stdlib.h> |
subrata_modak | 5ec2c49 | 2008-10-23 14:06:23 +0000 | [diff] [blame] | 52 | |
subrata_modak | 65be6ce | 2008-11-07 10:15:22 +0000 | [diff] [blame] | 53 | #include "test.h" |
| 54 | #include "usctest.h" |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 55 | #include "linux_syscall_numbers.h" |
subrata_modak | 65be6ce | 2008-11-07 10:15:22 +0000 | [diff] [blame] | 56 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 57 | char *TCID = "get_robust_list01"; /* test program identifier. */ |
| 58 | int TST_TOTAL = 5; /* total number of tests in this file. */ |
subrata_modak | 65be6ce | 2008-11-07 10:15:22 +0000 | [diff] [blame] | 59 | |
subrata_modak | 5ec2c49 | 2008-10-23 14:06:23 +0000 | [diff] [blame] | 60 | struct robust_list { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 61 | struct robust_list *next; |
subrata_modak | 5ec2c49 | 2008-10-23 14:06:23 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct robust_list_head { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 65 | struct robust_list list; |
| 66 | long futex_offset; |
| 67 | struct robust_list *list_op_pending; |
subrata_modak | 5ec2c49 | 2008-10-23 14:06:23 +0000 | [diff] [blame] | 68 | }; |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 69 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | int exp_enos[] = { ESRCH, EPERM, EFAULT, 0 }; |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 71 | |
| 72 | void setup(void); |
| 73 | void cleanup(void); |
| 74 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 75 | int main(int argc, char **argv) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 76 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 77 | int lc; |
| 78 | char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | struct robust_list_head head; |
| 80 | size_t len_ptr; /* size of structure struct robust_list_head */ |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 81 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 82 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 83 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 84 | |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 85 | setup(); |
| 86 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | len_ptr = sizeof(struct robust_list_head); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 88 | |
| 89 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 90 | Tst_count = 0; |
| 91 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | /* |
| 93 | * The get_robust_list function fails with EFAULT if the size of the |
| 94 | * struct robust_list_head can't be stored in the memory address space |
| 95 | * specified by len_ptr argument, or the head of the robust list can't |
| 96 | * be stored in the memory address space specified by the head_ptr |
| 97 | * argument. |
| 98 | */ |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 99 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 100 | TEST(ltp_syscall(__NR_get_robust_list, 0, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | (struct robust_list_head *)&head, |
| 102 | (size_t *) NULL)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 103 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 104 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | if (TEST_ERRNO == EFAULT) |
| 106 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 107 | "get_robust_list failed as expected with " |
| 108 | "EFAULT"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 110 | tst_resm(TFAIL | TTERRNO, |
| 111 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 112 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 114 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 115 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 116 | TEST(ltp_syscall(__NR_get_robust_list, 0, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 117 | (struct robust_list_head **)NULL, |
| 118 | &len_ptr)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 119 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | if (TEST_RETURN) { |
| 121 | if (TEST_ERRNO == EFAULT) |
| 122 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | "get_robust_list failed as expected with " |
| 124 | "EFAULT"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 125 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 126 | tst_resm(TFAIL | TTERRNO, |
| 127 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 128 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 130 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 131 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | /* |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 133 | * The get_robust_list function fails with ESRCH if it can't |
| 134 | * find the task specified by the pid argument. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 135 | */ |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 136 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 137 | TEST(ltp_syscall(__NR_get_robust_list, UINT16_MAX, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | (struct robust_list_head *)&head, |
| 139 | &len_ptr)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 140 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 141 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 142 | if (TEST_ERRNO == ESRCH) |
| 143 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | "get_robust_list failed as expected with " |
| 145 | "ESRCH"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 146 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 147 | tst_resm(TFAIL | TTERRNO, |
| 148 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 149 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 150 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 151 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 152 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 153 | TEST(ltp_syscall(__NR_get_robust_list, 0, |
Wanlong Gao | d28ecfa | 2012-06-20 15:58:13 +0800 | [diff] [blame] | 154 | (struct robust_list_head **)&head, |
| 155 | &len_ptr)); |
| 156 | |
| 157 | if (TEST_RETURN == 0) |
| 158 | tst_resm(TPASS, "get_robust_list succeeded"); |
| 159 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 160 | tst_resm(TFAIL | TTERRNO, |
Wanlong Gao | d28ecfa | 2012-06-20 15:58:13 +0800 | [diff] [blame] | 161 | "get_robust_list failed unexpectedly"); |
| 162 | |
| 163 | if (setuid(1) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 164 | tst_brkm(TBROK | TERRNO, cleanup, "setuid(1) failed"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 165 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 166 | TEST(ltp_syscall(__NR_get_robust_list, 1, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 167 | (struct robust_list_head *)&head, |
| 168 | &len_ptr)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 169 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 170 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | if (TEST_ERRNO == EPERM) |
| 172 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 173 | "get_robust_list failed as expected with " |
| 174 | "EPERM"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 175 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 176 | tst_resm(TFAIL | TERRNO, |
| 177 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 178 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 179 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 180 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 181 | } |
| 182 | |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 183 | cleanup(); |
| 184 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 185 | tst_exit(); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 186 | } |
| 187 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 188 | void setup(void) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 189 | { |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 190 | tst_require_root(NULL); |
| 191 | |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 192 | TEST_EXP_ENOS(exp_enos); |
| 193 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 194 | TEST_PAUSE; |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 195 | } |
| 196 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 197 | void cleanup(void) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 198 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 199 | TEST_CLEANUP; |
Wanlong Gao | d28ecfa | 2012-06-20 15:58:13 +0800 | [diff] [blame] | 200 | } |