blob: d3ab244cf5ad5224519f3979001e2411b0fe980f [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"
54#include "usctest.h"
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080055#include "linux_syscall_numbers.h"
subrata_modak65be6ce2008-11-07 10:15:22 +000056
subrata_modak56207ce2009-03-23 13:35:39 +000057char *TCID = "get_robust_list01"; /* test program identifier. */
58int TST_TOTAL = 5; /* total number of tests in this file. */
subrata_modak65be6ce2008-11-07 10:15:22 +000059
subrata_modak5ec2c492008-10-23 14:06:23 +000060struct robust_list {
subrata_modak56207ce2009-03-23 13:35:39 +000061 struct robust_list *next;
subrata_modak5ec2c492008-10-23 14:06:23 +000062};
63
64struct robust_list_head {
subrata_modak56207ce2009-03-23 13:35:39 +000065 struct robust_list list;
66 long futex_offset;
67 struct robust_list *list_op_pending;
subrata_modak5ec2c492008-10-23 14:06:23 +000068};
subrata_modak1382fd12008-08-11 10:35:31 +000069
subrata_modak56207ce2009-03-23 13:35:39 +000070int exp_enos[] = { ESRCH, EPERM, EFAULT, 0 };
subrata_modak1382fd12008-08-11 10:35:31 +000071
72void setup(void);
73void cleanup(void);
74
subrata_modak56207ce2009-03-23 13:35:39 +000075int main(int argc, char **argv)
subrata_modak1382fd12008-08-11 10:35:31 +000076{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020077 int lc;
78 char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000079 struct robust_list_head head;
80 size_t len_ptr; /* size of structure struct robust_list_head */
subrata_modak1382fd12008-08-11 10:35:31 +000081
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080082 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
subrata_modak1382fd12008-08-11 10:35:31 +000083 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080084
subrata_modak1382fd12008-08-11 10:35:31 +000085 setup();
86
subrata_modak56207ce2009-03-23 13:35:39 +000087 len_ptr = sizeof(struct robust_list_head);
subrata_modak1382fd12008-08-11 10:35:31 +000088
89 for (lc = 0; TEST_LOOPING(lc); ++lc) {
90 Tst_count = 0;
91
subrata_modak56207ce2009-03-23 13:35:39 +000092 /*
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_modak1382fd12008-08-11 10:35:31 +000099
Jan Stancek359980f2013-02-15 10:16:05 +0100100 TEST(ltp_syscall(__NR_get_robust_list, 0,
subrata_modak56207ce2009-03-23 13:35:39 +0000101 (struct robust_list_head *)&head,
102 (size_t *) NULL));
subrata_modak1382fd12008-08-11 10:35:31 +0000103
Garrett Cooper66776cc2010-12-19 02:18:12 -0800104 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000105 if (TEST_ERRNO == EFAULT)
106 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107 "get_robust_list failed as expected with "
108 "EFAULT");
subrata_modak56207ce2009-03-23 13:35:39 +0000109 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800110 tst_resm(TFAIL | TTERRNO,
111 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800112 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000113 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000115
Jan Stancek359980f2013-02-15 10:16:05 +0100116 TEST(ltp_syscall(__NR_get_robust_list, 0,
subrata_modak56207ce2009-03-23 13:35:39 +0000117 (struct robust_list_head **)NULL,
118 &len_ptr));
subrata_modak1382fd12008-08-11 10:35:31 +0000119
subrata_modak56207ce2009-03-23 13:35:39 +0000120 if (TEST_RETURN) {
121 if (TEST_ERRNO == EFAULT)
122 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800123 "get_robust_list failed as expected with "
124 "EFAULT");
subrata_modak56207ce2009-03-23 13:35:39 +0000125 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800126 tst_resm(TFAIL | TTERRNO,
127 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800128 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000129 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800130 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000131
subrata_modak56207ce2009-03-23 13:35:39 +0000132 /*
Garrett Cooper66776cc2010-12-19 02:18:12 -0800133 * The get_robust_list function fails with ESRCH if it can't
134 * find the task specified by the pid argument.
subrata_modak56207ce2009-03-23 13:35:39 +0000135 */
subrata_modak1382fd12008-08-11 10:35:31 +0000136
Jan Stancek359980f2013-02-15 10:16:05 +0100137 TEST(ltp_syscall(__NR_get_robust_list, UINT16_MAX,
subrata_modak56207ce2009-03-23 13:35:39 +0000138 (struct robust_list_head *)&head,
139 &len_ptr));
subrata_modak1382fd12008-08-11 10:35:31 +0000140
Garrett Cooper66776cc2010-12-19 02:18:12 -0800141 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000142 if (TEST_ERRNO == ESRCH)
143 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800144 "get_robust_list failed as expected with "
145 "ESRCH");
subrata_modak56207ce2009-03-23 13:35:39 +0000146 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800147 tst_resm(TFAIL | TTERRNO,
148 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800149 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000150 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800151 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000152
Jan Stancek359980f2013-02-15 10:16:05 +0100153 TEST(ltp_syscall(__NR_get_robust_list, 0,
Wanlong Gaod28ecfa2012-06-20 15:58:13 +0800154 (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 Gao354ebb42012-12-07 10:10:04 +0800160 tst_resm(TFAIL | TTERRNO,
Wanlong Gaod28ecfa2012-06-20 15:58:13 +0800161 "get_robust_list failed unexpectedly");
162
163 if (setuid(1) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800164 tst_brkm(TBROK | TERRNO, cleanup, "setuid(1) failed");
subrata_modak1382fd12008-08-11 10:35:31 +0000165
Jan Stancek359980f2013-02-15 10:16:05 +0100166 TEST(ltp_syscall(__NR_get_robust_list, 1,
subrata_modak56207ce2009-03-23 13:35:39 +0000167 (struct robust_list_head *)&head,
168 &len_ptr));
subrata_modak1382fd12008-08-11 10:35:31 +0000169
Garrett Cooper66776cc2010-12-19 02:18:12 -0800170 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000171 if (TEST_ERRNO == EPERM)
172 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800173 "get_robust_list failed as expected with "
174 "EPERM");
subrata_modak56207ce2009-03-23 13:35:39 +0000175 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800176 tst_resm(TFAIL | TERRNO,
177 "get_robust_list failed unexpectedly");
Garrett Cooper66776cc2010-12-19 02:18:12 -0800178 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000179 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800180 "get_robust_list succeeded unexpectedly");
subrata_modak1382fd12008-08-11 10:35:31 +0000181 }
182
subrata_modak1382fd12008-08-11 10:35:31 +0000183 cleanup();
184
Garrett Cooper66776cc2010-12-19 02:18:12 -0800185 tst_exit();
subrata_modak1382fd12008-08-11 10:35:31 +0000186}
187
subrata_modak56207ce2009-03-23 13:35:39 +0000188void setup(void)
subrata_modak1382fd12008-08-11 10:35:31 +0000189{
Garrett Cooper66776cc2010-12-19 02:18:12 -0800190 tst_require_root(NULL);
191
subrata_modak1382fd12008-08-11 10:35:31 +0000192 TEST_EXP_ENOS(exp_enos);
193
subrata_modak56207ce2009-03-23 13:35:39 +0000194 TEST_PAUSE;
subrata_modak1382fd12008-08-11 10:35:31 +0000195}
196
subrata_modak56207ce2009-03-23 13:35:39 +0000197void cleanup(void)
subrata_modak1382fd12008-08-11 10:35:31 +0000198{
subrata_modak56207ce2009-03-23 13:35:39 +0000199 TEST_CLEANUP;
Wanlong Gaod28ecfa2012-06-20 15:58:13 +0800200}