blob: 8f5fb4cb711df3999158f7bd809bd729defc5f96 [file] [log] [blame]
Cyril Hrubisbde87cb2011-08-25 16:12:50 +02001/*************************************************************************
yaberauneya335f6502009-10-22 09:25:19 +00002 * Copyright (c) Crackerjack Project., 2007
Cyril Hrubisbde87cb2011-08-25 16:12:50 +02003 * Copyright (c) Manas Kumar Nayak <maknayak@in.ibm.com>
4 * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 2011
yaberauneya335f6502009-10-22 09:25:19 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yaberauneya335f6502009-10-22 09:25:19 +000019 *
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020020 ************************************************************************/
yaberauneya335f6502009-10-22 09:25:19 +000021
subrata_modake03fa312009-08-26 06:44:25 +000022#include "set_thread_area.h"
subrata_modaka535e982009-05-21 18:30:28 +000023
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020024char *TCID = "set_thread_area_01";
Wanlong Gao354ebb42012-12-07 10:10:04 +080025int TST_TOTAL = 6;
subrata_modaka535e982009-05-21 18:30:28 +000026
yaberauneya335f6502009-10-22 09:25:19 +000027#if defined(HAVE_ASM_LDT_H) && defined(HAVE_STRUCT_USER_DESC)
subrata_modak566e9a22009-06-25 08:01:27 +000028
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020029static void cleanup(void)
30{
yaberauneya335f6502009-10-22 09:25:19 +000031 TEST_CLEANUP;
subrata_modaka535e982009-05-21 18:30:28 +000032}
33
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020034static void setup(void)
35{
yaberauneya335f6502009-10-22 09:25:19 +000036 TEST_PAUSE;
subrata_modaka535e982009-05-21 18:30:28 +000037}
38
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020039struct test {
40 int syscall;
41 thread_area_s *u_info;
42 int exp_ret;
43 int exp_errno;
44};
yaberauneya335f6502009-10-22 09:25:19 +000045
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020046/*
47 * The set_thread_area uses a free entry_number if entry number is set to -1
48 * and upon the syscall exit the entry number is set to entry which was used.
49 * So when we call get_thread_area on u_info1, the entry number is initalized
50 * corectly by the previous set_thread_area.
51 */
Wanlong Gao354ebb42012-12-07 10:10:04 +080052static struct user_desc u_info1 = {.entry_number = -1 };
53static struct user_desc u_info2 = {.entry_number = -2 };
Garrett Cooper2c282152010-12-16 00:55:50 -080054
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020055static struct test tests[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080056 {__NR_set_thread_area, &u_info1, 0, 0},
57 {__NR_get_thread_area, &u_info1, 0, 0},
58 {__NR_set_thread_area, &u_info2, -1, EINVAL},
59 {__NR_get_thread_area, &u_info2, -1, EINVAL},
60 {__NR_set_thread_area, (void *)-9, -1, EFAULT},
61 {__NR_get_thread_area, (void *)-9, -1, EFAULT},
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020062};
63
64static const char *get_name(int syscall)
65{
66 switch (syscall) {
67 case __NR_set_thread_area:
68 return "set_thread_area()";
Wanlong Gao354ebb42012-12-07 10:10:04 +080069 break;
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020070 case __NR_get_thread_area:
71 return "get_thread_area()";
Wanlong Gao354ebb42012-12-07 10:10:04 +080072 break;
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020073 default:
74 return "invalid syscall";
yaberauneya335f6502009-10-22 09:25:19 +000075 }
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020076}
77
78int main(int argc, char *argv[])
79{
80 int lc, i;
81 char *msg;
82
83 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modaka535e982009-05-21 18:30:28 +000085
yaberauneya335f6502009-10-22 09:25:19 +000086 setup();
subrata_modaka535e982009-05-21 18:30:28 +000087
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020088 for (lc = 0; TEST_LOOPING(lc); lc++) {
89 for (i = 0; i < sizeof(tests) / sizeof(struct test); i++) {
Jan Stancek359980f2013-02-15 10:16:05 +010090 TEST(ltp_syscall(tests[i].syscall, tests[i].u_info));
Chris Dearman37550cf2012-10-17 19:54:01 -070091
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020092 if (TEST_RETURN != tests[i].exp_ret) {
93 tst_resm(TFAIL, "%s returned %li expected %i",
Wanlong Gao354ebb42012-12-07 10:10:04 +080094 get_name(tests[i].syscall),
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020095 TEST_RETURN, tests[i].exp_ret);
96 continue;
yaberauneya335f6502009-10-22 09:25:19 +000097 }
Garrett Cooper2c282152010-12-16 00:55:50 -080098
Cyril Hrubisbde87cb2011-08-25 16:12:50 +020099 if (TEST_ERRNO != tests[i].exp_errno) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100 tst_resm(TFAIL,
101 "%s failed with %i (%s) expected %i (%s)",
102 get_name(tests[i].syscall), TEST_ERRNO,
103 strerror(TEST_ERRNO),
104 tests[i].exp_errno,
Cyril Hrubisbde87cb2011-08-25 16:12:50 +0200105 strerror(tests[i].exp_errno));
106 continue;
yaberauneya335f6502009-10-22 09:25:19 +0000107 }
Chris Dearman37550cf2012-10-17 19:54:01 -0700108
Cyril Hrubisbde87cb2011-08-25 16:12:50 +0200109 tst_resm(TPASS, "%s returned %li errno %i (%s)",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800110 get_name(tests[i].syscall), TEST_RETURN,
Cyril Hrubisbde87cb2011-08-25 16:12:50 +0200111 TEST_ERRNO, strerror(TEST_ERRNO));
yaberauneya335f6502009-10-22 09:25:19 +0000112 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800113 }
yaberauneya335f6502009-10-22 09:25:19 +0000114
subrata_modaka535e982009-05-21 18:30:28 +0000115 cleanup();
yaberauneya335f6502009-10-22 09:25:19 +0000116 tst_exit();
subrata_modaka535e982009-05-21 18:30:28 +0000117}
subrata_modak566e9a22009-06-25 08:01:27 +0000118#else
Cyril Hrubisbde87cb2011-08-25 16:12:50 +0200119int main(void)
120{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 tst_brkm(TCONF, NULL,
122 "set_thread_area isn't available for this architecture");
yaberauneya335f6502009-10-22 09:25:19 +0000123 tst_exit();
subrata_modak566e9a22009-06-25 08:01:27 +0000124}
Cyril Hrubisbde87cb2011-08-25 16:12:50 +0200125#endif