robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 1 | /* |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 18 | */ |
| 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 41 | #include <stdio.h> /* needed by testhead.h */ |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 42 | #include <syscall.h> |
| 43 | #include <errno.h> |
| 44 | |
| 45 | /***** LTP Port *****/ |
| 46 | #include "test.h" |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 47 | |
| 48 | #define FAILED 0 |
| 49 | #define PASSED 1 |
| 50 | |
| 51 | char *TCID = "syscall01"; |
| 52 | int local_flag = PASSED; |
| 53 | int block_number; |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 54 | FILE *temp; |
| 55 | int TST_TOTAL = 1; |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 56 | /***** ** ** *****/ |
| 57 | |
| 58 | //char progname[]= "syscall1()"; |
| 59 | |
| 60 | #define ITER 500 |
| 61 | |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 62 | int t_flag; |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 63 | |
| 64 | /***** LTP Port *****/ |
| 65 | void setup(); |
| 66 | int blenter(); |
| 67 | int blexit(); |
| 68 | int anyfail(); |
| 69 | void cleanup(); |
| 70 | void do_setpg(); |
| 71 | void fail_exit(); |
| 72 | /***** ** ** *****/ |
| 73 | |
| 74 | /*--------------------------------------------------------------*/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 75 | int main(int argc, char *argv[]) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 76 | { |
| 77 | register int i; |
| 78 | int v1, v2; |
| 79 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 80 | setup(); /* temp file is now open */ |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 81 | /*--------------------------------------------------------------*/ |
| 82 | blenter(); |
| 83 | |
robbiew | d655d83 | 2004-05-20 22:03:41 +0000 | [diff] [blame] | 84 | #if defined(SYS_getpid) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | for (i = 0; i < ITER; i++) { |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 86 | 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 | } |
robbiew | d655d83 | 2004-05-20 22:03:41 +0000 | [diff] [blame] | 95 | #else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 96 | fprintf(temp, "\tgetpid syscall failed.\n"); |
| 97 | fprintf(temp, "\tSYS_getpid not defined\n"); |
robbiew | d655d83 | 2004-05-20 22:03:41 +0000 | [diff] [blame] | 98 | local_flag = FAILED; |
| 99 | #endif |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 100 | blexit(); |
| 101 | /*--------------------------------------------------------------*/ |
| 102 | blenter(); |
| 103 | |
subrata_modak | 1522cca | 2008-07-11 10:26:24 +0000 | [diff] [blame] | 104 | #if defined(SYS_getuid) || defined(SYS_getuid32) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | for (i = 0; i < ITER; i++) { |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 106 | v1 = getuid(); |
subrata_modak | 1522cca | 2008-07-11 10:26:24 +0000 | [diff] [blame] | 107 | #if defined(SYS_getuid) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 108 | v2 = syscall(SYS_getuid); |
subrata_modak | 1522cca | 2008-07-11 10:26:24 +0000 | [diff] [blame] | 109 | #else |
| 110 | v2 = syscall(SYS_getuid32); |
| 111 | #endif |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 112 | 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 | } |
robbiew | d655d83 | 2004-05-20 22:03:41 +0000 | [diff] [blame] | 119 | #else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | fprintf(temp, "\tgetuid syscall failed.\n"); |
| 121 | fprintf(temp, "\tSYS_getuid and SYS_getuid32 not defined\n"); |
| 122 | local_flag = FAILED; |
robbiew | d655d83 | 2004-05-20 22:03:41 +0000 | [diff] [blame] | 123 | #endif |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 124 | blexit(); |
| 125 | /*--------------------------------------------------------------*/ |
| 126 | blenter(); |
| 127 | |
subrata_modak | 1522cca | 2008-07-11 10:26:24 +0000 | [diff] [blame] | 128 | #if defined(SYS_getgid) || defined(SYS_getgid32) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | for (i = 0; i < ITER; i++) { |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 130 | v1 = getgid(); |
subrata_modak | 1522cca | 2008-07-11 10:26:24 +0000 | [diff] [blame] | 131 | #if defined(SYS_getgid) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 132 | v2 = syscall(SYS_getgid); |
subrata_modak | 1522cca | 2008-07-11 10:26:24 +0000 | [diff] [blame] | 133 | #else |
| 134 | v2 = syscall(SYS_getgid32); |
| 135 | #endif |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 136 | 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 | } |
robbiew | d655d83 | 2004-05-20 22:03:41 +0000 | [diff] [blame] | 143 | #else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 144 | fprintf(temp, "\tgetgid syscall failed.\n"); |
| 145 | fprintf(temp, "\tSYS_getgid and SYS_getgid32 not defined\n"); |
| 146 | local_flag = FAILED; |
robbiew | d655d83 | 2004-05-20 22:03:41 +0000 | [diff] [blame] | 147 | #endif |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 148 | |
| 149 | blexit(); |
| 150 | /*--------------------------------------------------------------*/ |
| 151 | |
| 152 | /*************************************************************** |
| 153 | * cleanup and exit |
| 154 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 155 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 156 | tst_exit(); |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 157 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 159 | |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 160 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 162 | /*--------------------------------------------------------------*/ |
| 163 | |
| 164 | /***** LTP Port *****/ |
| 165 | /* functions */ |
| 166 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 167 | void cleanup(void) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 168 | { |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 169 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 170 | } |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 171 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 172 | void setup(void) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 173 | { |
| 174 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 175 | temp = stderr; |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 176 | |
| 177 | } |
| 178 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 179 | int blenter(void) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 180 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 181 | local_flag = PASSED; |
| 182 | return 0; |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 185 | int blexit(void) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 186 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 187 | (local_flag == PASSED) ? tst_resm(TPASS, "Test passed") |
| 188 | : tst_resm(TFAIL, "Test failed"); |
| 189 | return 0; |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 192 | int anyfail(void) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 193 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 194 | tst_exit(); |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 197 | void fail_exit(void) |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 198 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 199 | local_flag = FAILED; |
| 200 | blexit(); |
| 201 | anyfail(); |
robbiew | 35c803d | 2002-12-31 22:53:23 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 204 | /***** ** ** *****/ |