blob: ab7972b87c86fb5961b5e9876e8590d7c3557502 [file] [log] [blame]
subrata_modak1382fd12008-08-11 10:35:31 +00001/*
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 Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
subrata_modak1382fd12008-08-11 10:35:31 +000018 */
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 Cooper66776cc2010-12-19 02:18:12 -080045#include <sys/types.h>
46#include <sys/syscall.h>
47
48#include <errno.h>
49#include <stdint.h>
subrata_modak1382fd12008-08-11 10:35:31 +000050#include <stdio.h>
51#include <stdlib.h>
subrata_modak5ec2c492008-10-23 14:06:23 +000052
subrata_modak65be6ce2008-11-07 10:15:22 +000053#include "test.h"
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080054#include "linux_syscall_numbers.h"
subrata_modak65be6ce2008-11-07 10:15:22 +000055
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020056char *TCID = "get_robust_list01";
57int TST_TOTAL = 5;
subrata_modak65be6ce2008-11-07 10:15:22 +000058
subrata_modak5ec2c492008-10-23 14:06:23 +000059struct robust_list {
subrata_modak56207ce2009-03-23 13:35:39 +000060 struct robust_list *next;
subrata_modak5ec2c492008-10-23 14:06:23 +000061};
62
63struct robust_list_head {
subrata_modak56207ce2009-03-23 13:35:39 +000064 struct robust_list list;
65 long futex_offset;
66 struct robust_list *list_op_pending;
subrata_modak5ec2c492008-10-23 14:06:23 +000067};
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040068static pid_t unused_pid;
subrata_modak1382fd12008-08-11 10:35:31 +000069
70void setup(void);
71void cleanup(void);
72
subrata_modak56207ce2009-03-23 13:35:39 +000073int main(int argc, char **argv)
subrata_modak1382fd12008-08-11 10:35:31 +000074{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020075 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020076 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000077 struct robust_list_head head;
78 size_t len_ptr; /* size of structure struct robust_list_head */
subrata_modak1382fd12008-08-11 10:35:31 +000079
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080080 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
subrata_modak1382fd12008-08-11 10:35:31 +000081 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080082
subrata_modak1382fd12008-08-11 10:35:31 +000083 setup();
84
subrata_modak56207ce2009-03-23 13:35:39 +000085 len_ptr = sizeof(struct robust_list_head);
subrata_modak1382fd12008-08-11 10:35:31 +000086
87 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080088 tst_count = 0;
subrata_modak1382fd12008-08-11 10:35:31 +000089
subrata_modak56207ce2009-03-23 13:35:39 +000090 /*
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_modak1382fd12008-08-11 10:35:31 +000097
Jan Stancek359980f2013-02-15 10:16:05 +010098 TEST(ltp_syscall(__NR_get_robust_list, 0,
subrata_modak56207ce2009-03-23 13:35:39 +000099 (struct robust_list_head *)&head,
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200100 NULL));
subrata_modak1382fd12008-08-11 10:35:31 +0000101
Garrett Cooper66776cc2010-12-19 02:18:12 -0800102 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000103 if (TEST_ERRNO == EFAULT)
104 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800105 "get_robust_list failed as expected with "
106 "EFAULT");
subrata_modak56207ce2009-03-23 13:35:39 +0000107 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800108 tst_resm(TFAIL | TTERRNO,
109 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800110 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000111 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000113
Jan Stancek359980f2013-02-15 10:16:05 +0100114 TEST(ltp_syscall(__NR_get_robust_list, 0,
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200115 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000116 &len_ptr));
subrata_modak1382fd12008-08-11 10:35:31 +0000117
subrata_modak56207ce2009-03-23 13:35:39 +0000118 if (TEST_RETURN) {
119 if (TEST_ERRNO == EFAULT)
120 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 "get_robust_list failed as expected with "
122 "EFAULT");
subrata_modak56207ce2009-03-23 13:35:39 +0000123 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124 tst_resm(TFAIL | TTERRNO,
125 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800126 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000127 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800128 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000129
subrata_modak56207ce2009-03-23 13:35:39 +0000130 /*
Garrett Cooper66776cc2010-12-19 02:18:12 -0800131 * The get_robust_list function fails with ESRCH if it can't
132 * find the task specified by the pid argument.
subrata_modak56207ce2009-03-23 13:35:39 +0000133 */
subrata_modak1382fd12008-08-11 10:35:31 +0000134
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400135 TEST(ltp_syscall(__NR_get_robust_list, unused_pid,
subrata_modak56207ce2009-03-23 13:35:39 +0000136 (struct robust_list_head *)&head,
137 &len_ptr));
subrata_modak1382fd12008-08-11 10:35:31 +0000138
Garrett Cooper66776cc2010-12-19 02:18:12 -0800139 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000140 if (TEST_ERRNO == ESRCH)
141 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800142 "get_robust_list failed as expected with "
143 "ESRCH");
subrata_modak56207ce2009-03-23 13:35:39 +0000144 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800145 tst_resm(TFAIL | TTERRNO,
146 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800147 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000148 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800149 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000150
Jan Stancek359980f2013-02-15 10:16:05 +0100151 TEST(ltp_syscall(__NR_get_robust_list, 0,
Wanlong Gaod28ecfa2012-06-20 15:58:13 +0800152 (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 Gao354ebb42012-12-07 10:10:04 +0800158 tst_resm(TFAIL | TTERRNO,
Wanlong Gaod28ecfa2012-06-20 15:58:13 +0800159 "get_robust_list failed unexpectedly");
160
161 if (setuid(1) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800162 tst_brkm(TBROK | TERRNO, cleanup, "setuid(1) failed");
subrata_modak1382fd12008-08-11 10:35:31 +0000163
Jan Stancek359980f2013-02-15 10:16:05 +0100164 TEST(ltp_syscall(__NR_get_robust_list, 1,
subrata_modak56207ce2009-03-23 13:35:39 +0000165 (struct robust_list_head *)&head,
166 &len_ptr));
subrata_modak1382fd12008-08-11 10:35:31 +0000167
Garrett Cooper66776cc2010-12-19 02:18:12 -0800168 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000169 if (TEST_ERRNO == EPERM)
170 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800171 "get_robust_list failed as expected with "
172 "EPERM");
subrata_modak56207ce2009-03-23 13:35:39 +0000173 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800174 tst_resm(TFAIL | TERRNO,
175 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800176 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000177 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800178 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000179 }
180
subrata_modak1382fd12008-08-11 10:35:31 +0000181 cleanup();
182
Garrett Cooper66776cc2010-12-19 02:18:12 -0800183 tst_exit();
subrata_modak1382fd12008-08-11 10:35:31 +0000184}
185
subrata_modak56207ce2009-03-23 13:35:39 +0000186void setup(void)
subrata_modak1382fd12008-08-11 10:35:31 +0000187{
Garrett Cooper66776cc2010-12-19 02:18:12 -0800188 tst_require_root(NULL);
189
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400190 unused_pid = tst_get_unused_pid(cleanup);
subrata_modak1382fd12008-08-11 10:35:31 +0000191
subrata_modak56207ce2009-03-23 13:35:39 +0000192 TEST_PAUSE;
subrata_modak1382fd12008-08-11 10:35:31 +0000193}
194
subrata_modak56207ce2009-03-23 13:35:39 +0000195void cleanup(void)
subrata_modak1382fd12008-08-11 10:35:31 +0000196{
Wanlong Gaod28ecfa2012-06-20 15:58:13 +0800197}