Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 1 | /************************************************************************* |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 2 | * Copyright (c) Crackerjack Project., 2007 |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 3 | * Copyright (c) Manas Kumar Nayak <maknayak@in.ibm.com> |
| 4 | * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 2011 |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 5 | * |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 19 | * |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 20 | ************************************************************************/ |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 21 | |
subrata_modak | e03fa31 | 2009-08-26 06:44:25 +0000 | [diff] [blame] | 22 | #include "set_thread_area.h" |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 23 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 24 | char *TCID = "set_thread_area_01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 25 | int TST_TOTAL = 6; |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 26 | |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 27 | #if defined(HAVE_ASM_LDT_H) && defined(HAVE_STRUCT_USER_DESC) |
subrata_modak | 566e9a2 | 2009-06-25 08:01:27 +0000 | [diff] [blame] | 28 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 29 | static void cleanup(void) |
| 30 | { |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 31 | TEST_CLEANUP; |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 34 | static void setup(void) |
| 35 | { |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 36 | TEST_PAUSE; |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 39 | struct test { |
| 40 | int syscall; |
| 41 | thread_area_s *u_info; |
| 42 | int exp_ret; |
| 43 | int exp_errno; |
| 44 | }; |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 45 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 46 | /* |
| 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 52 | static struct user_desc u_info1 = {.entry_number = -1 }; |
| 53 | static struct user_desc u_info2 = {.entry_number = -2 }; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 54 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 55 | static struct test tests[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 56 | {__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 Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | static const char *get_name(int syscall) |
| 65 | { |
| 66 | switch (syscall) { |
| 67 | case __NR_set_thread_area: |
| 68 | return "set_thread_area()"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 69 | break; |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 70 | case __NR_get_thread_area: |
| 71 | return "get_thread_area()"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 72 | break; |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 73 | default: |
| 74 | return "invalid syscall"; |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 75 | } |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | int 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 84 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 85 | |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 86 | setup(); |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 87 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 88 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 89 | for (i = 0; i < sizeof(tests) / sizeof(struct test); i++) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 90 | TEST(ltp_syscall(tests[i].syscall, tests[i].u_info)); |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 91 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 92 | if (TEST_RETURN != tests[i].exp_ret) { |
| 93 | tst_resm(TFAIL, "%s returned %li expected %i", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 94 | get_name(tests[i].syscall), |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 95 | TEST_RETURN, tests[i].exp_ret); |
| 96 | continue; |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 97 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 98 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 99 | if (TEST_ERRNO != tests[i].exp_errno) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 100 | 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 Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 105 | strerror(tests[i].exp_errno)); |
| 106 | continue; |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 107 | } |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 108 | |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 109 | tst_resm(TPASS, "%s returned %li errno %i (%s)", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 110 | get_name(tests[i].syscall), TEST_RETURN, |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 111 | TEST_ERRNO, strerror(TEST_ERRNO)); |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 112 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 113 | } |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 114 | |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 115 | cleanup(); |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 116 | tst_exit(); |
subrata_modak | a535e98 | 2009-05-21 18:30:28 +0000 | [diff] [blame] | 117 | } |
subrata_modak | 566e9a2 | 2009-06-25 08:01:27 +0000 | [diff] [blame] | 118 | #else |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 119 | int main(void) |
| 120 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | tst_brkm(TCONF, NULL, |
| 122 | "set_thread_area isn't available for this architecture"); |
yaberauneya | 335f650 | 2009-10-22 09:25:19 +0000 | [diff] [blame] | 123 | tst_exit(); |
subrata_modak | 566e9a2 | 2009-06-25 08:01:27 +0000 | [diff] [blame] | 124 | } |
Cyril Hrubis | bde87cb | 2011-08-25 16:12:50 +0200 | [diff] [blame] | 125 | #endif |