Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Fujitsu Ltd. |
| 3 | * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program. |
| 15 | */ |
| 16 | /* |
| 17 | * DESCRIPTION |
| 18 | * Basic test for modify_ldt(2) using func=0 argument. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | #include "test.h" |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 23 | |
| 24 | char *TCID = "modify_ldt03"; |
| 25 | int TST_TOTAL = 1; |
| 26 | |
| 27 | #if defined(__i386__) && defined(HAVE_MODIFY_LDT) |
| 28 | |
| 29 | #ifdef HAVE_ASM_LDT_H |
Cyril Hrubis | 24c3e60 | 2014-04-15 15:35:52 +0200 | [diff] [blame] | 30 | # include <asm/ldt.h> |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 31 | #endif |
| 32 | extern int modify_ldt(int, void *, unsigned long); |
| 33 | |
| 34 | #include <asm/unistd.h> |
| 35 | #include <string.h> |
| 36 | #include <sys/wait.h> |
| 37 | #include <errno.h> |
| 38 | #include "safe_macros.h" |
| 39 | |
Cyril Hrubis | 24c3e60 | 2014-04-15 15:35:52 +0200 | [diff] [blame] | 40 | #ifdef HAVE_STRUCT_USER_DESC |
| 41 | # define SIZE sizeof(struct user_desc) |
| 42 | #else |
| 43 | # define SIZE 16 |
| 44 | #endif |
| 45 | |
| 46 | static char buf[SIZE]; |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 47 | static void cleanup(void); |
| 48 | static void setup(void); |
| 49 | |
| 50 | int main(int ac, char **av) |
| 51 | { |
| 52 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 53 | const char *msg; |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 54 | |
| 55 | msg = parse_opts(ac, av, NULL, NULL); |
| 56 | if (msg != NULL) |
| 57 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 58 | |
| 59 | setup(); |
| 60 | |
| 61 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 62 | |
| 63 | tst_count = 0; |
| 64 | |
Cyril Hrubis | 24c3e60 | 2014-04-15 15:35:52 +0200 | [diff] [blame] | 65 | TEST(modify_ldt(0, buf, SIZE)); |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 66 | |
| 67 | if (TEST_RETURN < 0) { |
| 68 | tst_resm(TFAIL | TTERRNO, |
| 69 | "modify_ldt() failed with errno: %s", |
| 70 | strerror(TEST_ERRNO)); |
| 71 | } else { |
| 72 | tst_resm(TPASS, "modify_ldt() tested success"); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | cleanup(); |
| 77 | tst_exit(); |
| 78 | } |
| 79 | |
| 80 | static void setup(void) |
| 81 | { |
| 82 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 83 | |
| 84 | TEST_PAUSE; |
| 85 | } |
| 86 | |
| 87 | static void cleanup(void) |
| 88 | { |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | #elif HAVE_MODIFY_LDT |
| 92 | |
| 93 | int main(void) |
| 94 | { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 95 | tst_brkm(TCONF, |
| 96 | NULL, "modify_ldt is available but not tested on the platform than " |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 97 | "__i386__"); |
Zeng Linggang | ae090d4 | 2014-03-19 13:36:08 +0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | #else /* if defined(__i386__) */ |
| 101 | |
| 102 | int main(void) |
| 103 | { |
| 104 | tst_resm(TINFO, "modify_ldt03 test only for ix86"); |
| 105 | tst_exit(); |
| 106 | } |
| 107 | |
| 108 | #endif /* if defined(__i386__) */ |