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" |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 54 | #include "linux_syscall_numbers.h" |
subrata_modak | 65be6ce | 2008-11-07 10:15:22 +0000 | [diff] [blame] | 55 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 56 | char *TCID = "get_robust_list01"; |
| 57 | int TST_TOTAL = 5; |
subrata_modak | 65be6ce | 2008-11-07 10:15:22 +0000 | [diff] [blame] | 58 | |
subrata_modak | 5ec2c49 | 2008-10-23 14:06:23 +0000 | [diff] [blame] | 59 | struct robust_list { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 60 | struct robust_list *next; |
subrata_modak | 5ec2c49 | 2008-10-23 14:06:23 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | struct robust_list_head { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 64 | struct robust_list list; |
| 65 | long futex_offset; |
| 66 | struct robust_list *list_op_pending; |
subrata_modak | 5ec2c49 | 2008-10-23 14:06:23 +0000 | [diff] [blame] | 67 | }; |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 68 | static pid_t unused_pid; |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 69 | |
| 70 | void setup(void); |
| 71 | void cleanup(void); |
| 72 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | int main(int argc, char **argv) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 74 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 75 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 76 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | struct robust_list_head head; |
| 78 | size_t len_ptr; /* size of structure struct robust_list_head */ |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 79 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 80 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 81 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 82 | |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 83 | setup(); |
| 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | len_ptr = sizeof(struct robust_list_head); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 86 | |
| 87 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 88 | tst_count = 0; |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 89 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | /* |
| 91 | * The get_robust_list function fails with EFAULT if the size of the |
| 92 | * struct robust_list_head can't be stored in the memory address space |
| 93 | * specified by len_ptr argument, or the head of the robust list can't |
| 94 | * be stored in the memory address space specified by the head_ptr |
| 95 | * argument. |
| 96 | */ |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 97 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 98 | TEST(ltp_syscall(__NR_get_robust_list, 0, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 99 | (struct robust_list_head *)&head, |
Cyril Hrubis | cf0d626 | 2014-09-23 14:03:31 +0200 | [diff] [blame] | 100 | NULL)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 101 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 102 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 103 | if (TEST_ERRNO == EFAULT) |
| 104 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 105 | "get_robust_list failed as expected with " |
| 106 | "EFAULT"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 108 | tst_resm(TFAIL | TTERRNO, |
| 109 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 110 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 113 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 114 | TEST(ltp_syscall(__NR_get_robust_list, 0, |
Cyril Hrubis | cf0d626 | 2014-09-23 14:03:31 +0200 | [diff] [blame] | 115 | NULL, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 116 | &len_ptr)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 117 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | if (TEST_RETURN) { |
| 119 | if (TEST_ERRNO == EFAULT) |
| 120 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | "get_robust_list failed as expected with " |
| 122 | "EFAULT"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 123 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 124 | tst_resm(TFAIL | TTERRNO, |
| 125 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 126 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 128 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 129 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | /* |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 131 | * The get_robust_list function fails with ESRCH if it can't |
| 132 | * find the task specified by the pid argument. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 133 | */ |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 134 | |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 135 | TEST(ltp_syscall(__NR_get_robust_list, unused_pid, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | (struct robust_list_head *)&head, |
| 137 | &len_ptr)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 138 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 139 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 140 | if (TEST_ERRNO == ESRCH) |
| 141 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 142 | "get_robust_list failed as expected with " |
| 143 | "ESRCH"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 144 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | tst_resm(TFAIL | TTERRNO, |
| 146 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 147 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 150 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 151 | TEST(ltp_syscall(__NR_get_robust_list, 0, |
Wanlong Gao | d28ecfa | 2012-06-20 15:58:13 +0800 | [diff] [blame] | 152 | (struct robust_list_head **)&head, |
| 153 | &len_ptr)); |
| 154 | |
| 155 | if (TEST_RETURN == 0) |
| 156 | tst_resm(TPASS, "get_robust_list succeeded"); |
| 157 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 158 | tst_resm(TFAIL | TTERRNO, |
Wanlong Gao | d28ecfa | 2012-06-20 15:58:13 +0800 | [diff] [blame] | 159 | "get_robust_list failed unexpectedly"); |
| 160 | |
| 161 | if (setuid(1) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 162 | tst_brkm(TBROK | TERRNO, cleanup, "setuid(1) failed"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 163 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 164 | TEST(ltp_syscall(__NR_get_robust_list, 1, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 165 | (struct robust_list_head *)&head, |
| 166 | &len_ptr)); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 167 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 168 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 169 | if (TEST_ERRNO == EPERM) |
| 170 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 171 | "get_robust_list failed as expected with " |
| 172 | "EPERM"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 173 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 174 | tst_resm(TFAIL | TERRNO, |
| 175 | "get_robust_list failed unexpectedly"); |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 176 | } else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 177 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 178 | "get_robust_list succeeded unexpectedly"); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 179 | } |
| 180 | |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 181 | cleanup(); |
| 182 | |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 183 | tst_exit(); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 184 | } |
| 185 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 186 | void setup(void) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 187 | { |
Garrett Cooper | 66776cc | 2010-12-19 02:18:12 -0800 | [diff] [blame] | 188 | tst_require_root(NULL); |
| 189 | |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 190 | unused_pid = tst_get_unused_pid(cleanup); |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 191 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 192 | TEST_PAUSE; |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 193 | } |
| 194 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 195 | void cleanup(void) |
subrata_modak | 1382fd1 | 2008-08-11 10:35:31 +0000 | [diff] [blame] | 196 | { |
Wanlong Gao | d28ecfa | 2012-06-20 15:58:13 +0800 | [diff] [blame] | 197 | } |