1 /* 2 * Copyright (c) International Business Machines Corp., 2002 3 * 01/02/2003 Port to LTP avenkat@us.ibm.com 4 * 06/30/2001 Port to Linux nsharoff@us.ibm.com 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 Foundation, 18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 /* 22 * Basic test for syscall(). 23 */ 24 25 #define _GNU_SOURCE 26 #include <unistd.h> 27 #include <sys/syscall.h> 28 #include <sys/types.h> 29 30 #include "tst_test.h" 31 #include "lapi/syscalls.h" 32 33 static void verify_getpid(void) 34 { 35 pid_t p1, p2; 36 37 p1 = getpid(); 38 p2 = syscall(SYS_getpid); 39 40 if (p1 == p2) { 41 tst_res(TPASS, "getpid() == syscall(SYS_getpid)"); 42 } else { 43 tst_res(TFAIL, "getpid() = %i, syscall(SYS_getpid) = %i", 44 p1, p2); 45 } 46 } 47 48 static void verify_getuid(void) 49 { 50 uid_t u1, u2; 51 52 u1 = getuid(); 53 u2 = syscall(SYS_getuid); 54 55 if (u1 == u2) { 56 tst_res(TPASS, "getuid() == syscall(SYS_getuid)"); 57 } else { 58 tst_res(TFAIL, "getuid() = %i, syscall(SYS_getuid) = %i", 59 u1, u2); 60 } 61 } 62 63 static void verify_getgid(void) 64 { 65 gid_t g1, g2; 66 67 g1 = getgid(); 68 g2 = syscall(SYS_getgid); 69 70 if (g1 == g2) { 71 tst_res(TPASS, "getgid() == syscall(SYS_getgid)"); 72 } else { 73 tst_res(TFAIL, "getgid() = %i, syscall(SYS_getgid) = %i", 74 g1, g2); 75 } 76 } 77 78 79 static void (*tcases[])(void) = { 80 verify_getpid, 81 verify_getuid, 82 verify_getgid, 83 }; 84 85 static void verify_syscall(unsigned int n) 86 { 87 tcases[n](); 88 } 89 90 static struct tst_test test = { 91 .test = verify_syscall, 92 .tcnt = ARRAY_SIZE(tcases), 93 }; 94 95