blob: a9afd2f2a8c5f71649b649eca7f869c82c53ce93 [file] [log] [blame]
robbiew35c803d2002-12-31 22:53:23 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2002
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
robbiew35c803d2002-12-31 22:53:23 +000018 */
19
20/* 01/02/2003 Port to LTP avenkat@us.ibm.com*/
21/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
22
23/*
24 * NAME
25 * syscall1.c -- test syscall
26 *
27 * CALLS
28 * syscall
29 *
30 * ALGORITHM
31 * Use syscall to simulate some section 2 calls and make sure
32 * things work as expected. Pretty simple, but if it works
33 * for a few it should work for all.
34 *
35 * RESTRICTIONS
36 * The syscall numbers are system dependent!! They represent
37 * entries in a table and can be changed from kernel to kernel.
38 * They ARE differnet between vax 4.2BSD and our ported system.
39 */
40
subrata_modak56207ce2009-03-23 13:35:39 +000041#include <stdio.h> /* needed by testhead.h */
robbiew35c803d2002-12-31 22:53:23 +000042#include <syscall.h>
43#include <errno.h>
44
45/***** LTP Port *****/
46#include "test.h"
robbiew35c803d2002-12-31 22:53:23 +000047
48#define FAILED 0
49#define PASSED 1
50
51char *TCID = "syscall01";
52int local_flag = PASSED;
53int block_number;
robbiew35c803d2002-12-31 22:53:23 +000054FILE *temp;
55int TST_TOTAL = 1;
robbiew35c803d2002-12-31 22:53:23 +000056/***** ** ** *****/
57
58//char progname[]= "syscall1()";
59
60#define ITER 500
61
robbiew35c803d2002-12-31 22:53:23 +000062int t_flag;
robbiew35c803d2002-12-31 22:53:23 +000063
64/***** LTP Port *****/
65void setup();
66int blenter();
67int blexit();
68int anyfail();
69void cleanup();
70void do_setpg();
71void fail_exit();
72/***** ** ** *****/
73
74/*--------------------------------------------------------------*/
subrata_modak56207ce2009-03-23 13:35:39 +000075int main(int argc, char *argv[])
robbiew35c803d2002-12-31 22:53:23 +000076{
77 register int i;
78 int v1, v2;
79
subrata_modak56207ce2009-03-23 13:35:39 +000080 setup(); /* temp file is now open */
robbiew35c803d2002-12-31 22:53:23 +000081/*--------------------------------------------------------------*/
82 blenter();
83
robbiewd655d832004-05-20 22:03:41 +000084#if defined(SYS_getpid)
subrata_modak56207ce2009-03-23 13:35:39 +000085 for (i = 0; i < ITER; i++) {
robbiew35c803d2002-12-31 22:53:23 +000086 v1 = getpid();
87 v2 = syscall(SYS_getpid);
88 if (v1 != v2) {
89 fprintf(temp, "\tgetpid syscall failed.\n");
90 fprintf(temp, "\t iteration %d\n", i);
91 local_flag = FAILED;
92 break;
93 }
94 }
robbiewd655d832004-05-20 22:03:41 +000095#else
subrata_modak56207ce2009-03-23 13:35:39 +000096 fprintf(temp, "\tgetpid syscall failed.\n");
97 fprintf(temp, "\tSYS_getpid not defined\n");
robbiewd655d832004-05-20 22:03:41 +000098 local_flag = FAILED;
99#endif
robbiew35c803d2002-12-31 22:53:23 +0000100 blexit();
101/*--------------------------------------------------------------*/
102 blenter();
103
subrata_modak1522cca2008-07-11 10:26:24 +0000104#if defined(SYS_getuid) || defined(SYS_getuid32)
subrata_modak56207ce2009-03-23 13:35:39 +0000105 for (i = 0; i < ITER; i++) {
robbiew35c803d2002-12-31 22:53:23 +0000106 v1 = getuid();
subrata_modak1522cca2008-07-11 10:26:24 +0000107#if defined(SYS_getuid)
robbiew35c803d2002-12-31 22:53:23 +0000108 v2 = syscall(SYS_getuid);
subrata_modak1522cca2008-07-11 10:26:24 +0000109#else
110 v2 = syscall(SYS_getuid32);
111#endif
robbiew35c803d2002-12-31 22:53:23 +0000112 if (v1 != v2) {
113 fprintf(temp, "\tgetuid syscall failed.\n");
114 fprintf(temp, "\t iteration %d\n", i);
115 local_flag = FAILED;
116 break;
117 }
118 }
robbiewd655d832004-05-20 22:03:41 +0000119#else
subrata_modak56207ce2009-03-23 13:35:39 +0000120 fprintf(temp, "\tgetuid syscall failed.\n");
121 fprintf(temp, "\tSYS_getuid and SYS_getuid32 not defined\n");
122 local_flag = FAILED;
robbiewd655d832004-05-20 22:03:41 +0000123#endif
robbiew35c803d2002-12-31 22:53:23 +0000124 blexit();
125/*--------------------------------------------------------------*/
126 blenter();
127
subrata_modak1522cca2008-07-11 10:26:24 +0000128#if defined(SYS_getgid) || defined(SYS_getgid32)
subrata_modak56207ce2009-03-23 13:35:39 +0000129 for (i = 0; i < ITER; i++) {
robbiew35c803d2002-12-31 22:53:23 +0000130 v1 = getgid();
subrata_modak1522cca2008-07-11 10:26:24 +0000131#if defined(SYS_getgid)
robbiew35c803d2002-12-31 22:53:23 +0000132 v2 = syscall(SYS_getgid);
subrata_modak1522cca2008-07-11 10:26:24 +0000133#else
134 v2 = syscall(SYS_getgid32);
135#endif
robbiew35c803d2002-12-31 22:53:23 +0000136 if (v1 != v2) {
137 fprintf(temp, "\tgetgid syscall failed.\n");
138 fprintf(temp, "\t iteration %d\n", i);
139 local_flag = FAILED;
140 break;
141 }
142 }
robbiewd655d832004-05-20 22:03:41 +0000143#else
subrata_modak56207ce2009-03-23 13:35:39 +0000144 fprintf(temp, "\tgetgid syscall failed.\n");
145 fprintf(temp, "\tSYS_getgid and SYS_getgid32 not defined\n");
146 local_flag = FAILED;
robbiewd655d832004-05-20 22:03:41 +0000147#endif
robbiew35c803d2002-12-31 22:53:23 +0000148
149 blexit();
150/*--------------------------------------------------------------*/
151
152 /***************************************************************
153 * cleanup and exit
154 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000155 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800156 tst_exit();
robbiew35c803d2002-12-31 22:53:23 +0000157
subrata_modak56207ce2009-03-23 13:35:39 +0000158 anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */
Garrett Cooper2c282152010-12-16 00:55:50 -0800159
robbiew35c803d2002-12-31 22:53:23 +0000160}
subrata_modak56207ce2009-03-23 13:35:39 +0000161
robbiew35c803d2002-12-31 22:53:23 +0000162/*--------------------------------------------------------------*/
163
164/***** LTP Port *****/
165/* functions */
166
Mike Frysingerc57fba52014-04-09 18:56:30 -0400167void cleanup(void)
robbiew35c803d2002-12-31 22:53:23 +0000168{
robbiew35c803d2002-12-31 22:53:23 +0000169
Garrett Cooper2c282152010-12-16 00:55:50 -0800170}
robbiew35c803d2002-12-31 22:53:23 +0000171
Mike Frysingerc57fba52014-04-09 18:56:30 -0400172void setup(void)
robbiew35c803d2002-12-31 22:53:23 +0000173{
174
subrata_modak56207ce2009-03-23 13:35:39 +0000175 temp = stderr;
robbiew35c803d2002-12-31 22:53:23 +0000176
177}
178
Mike Frysingerc57fba52014-04-09 18:56:30 -0400179int blenter(void)
robbiew35c803d2002-12-31 22:53:23 +0000180{
subrata_modak56207ce2009-03-23 13:35:39 +0000181 local_flag = PASSED;
182 return 0;
robbiew35c803d2002-12-31 22:53:23 +0000183}
184
Mike Frysingerc57fba52014-04-09 18:56:30 -0400185int blexit(void)
robbiew35c803d2002-12-31 22:53:23 +0000186{
subrata_modak56207ce2009-03-23 13:35:39 +0000187 (local_flag == PASSED) ? tst_resm(TPASS, "Test passed")
188 : tst_resm(TFAIL, "Test failed");
189 return 0;
robbiew35c803d2002-12-31 22:53:23 +0000190}
191
Mike Frysingerc57fba52014-04-09 18:56:30 -0400192int anyfail(void)
robbiew35c803d2002-12-31 22:53:23 +0000193{
subrata_modak56207ce2009-03-23 13:35:39 +0000194 tst_exit();
robbiew35c803d2002-12-31 22:53:23 +0000195}
196
Mike Frysingerc57fba52014-04-09 18:56:30 -0400197void fail_exit(void)
robbiew35c803d2002-12-31 22:53:23 +0000198{
subrata_modak56207ce2009-03-23 13:35:39 +0000199 local_flag = FAILED;
200 blexit();
201 anyfail();
robbiew35c803d2002-12-31 22:53:23 +0000202}
203
Chris Dearmanec6edca2012-10-17 19:54:01 -0700204/***** ** ** *****/