blob: 5d6c3ea065f4fe0f5753a0fc74b3aa8cca3aa663 [file] [log] [blame]
Zeng Linggangae090d42014-03-19 13:36:08 +08001/*
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 Linggangae090d42014-03-19 13:36:08 +080023
24char *TCID = "modify_ldt03";
25int TST_TOTAL = 1;
26
27#if defined(__i386__) && defined(HAVE_MODIFY_LDT)
28
29#ifdef HAVE_ASM_LDT_H
Cyril Hrubis24c3e602014-04-15 15:35:52 +020030# include <asm/ldt.h>
Zeng Linggangae090d42014-03-19 13:36:08 +080031#endif
32extern 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 Hrubis24c3e602014-04-15 15:35:52 +020040#ifdef HAVE_STRUCT_USER_DESC
41# define SIZE sizeof(struct user_desc)
42#else
43# define SIZE 16
44#endif
45
46static char buf[SIZE];
Zeng Linggangae090d42014-03-19 13:36:08 +080047static void cleanup(void);
48static void setup(void);
49
50int main(int ac, char **av)
51{
52 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020053 const char *msg;
Zeng Linggangae090d42014-03-19 13:36:08 +080054
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 Hrubis24c3e602014-04-15 15:35:52 +020065 TEST(modify_ldt(0, buf, SIZE));
Zeng Linggangae090d42014-03-19 13:36:08 +080066
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
80static void setup(void)
81{
82 tst_sig(NOFORK, DEF_HANDLER, cleanup);
83
84 TEST_PAUSE;
85}
86
87static void cleanup(void)
88{
Zeng Linggangae090d42014-03-19 13:36:08 +080089}
90
91#elif HAVE_MODIFY_LDT
92
93int main(void)
94{
Cyril Hrubis526fdf82014-12-04 14:35:01 +010095 tst_brkm(TCONF,
96 NULL, "modify_ldt is available but not tested on the platform than "
Zeng Linggangae090d42014-03-19 13:36:08 +080097 "__i386__");
Zeng Linggangae090d42014-03-19 13:36:08 +080098}
99
100#else /* if defined(__i386__) */
101
102int main(void)
103{
104 tst_resm(TINFO, "modify_ldt03 test only for ix86");
105 tst_exit();
106}
107
108#endif /* if defined(__i386__) */