VM: simplify slab allocator
[minix.git] / test / ipc / shmt / shmt05.c
blob10086930d9a2816ad20f7aa1d50582d0984eda90
1 /*
3 * Copyright (c) International Business Machines Corp., 2002
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.
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.
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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /* 12/20/2002 Port to LTP robbiew@us.ibm.com */
21 /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
24 * NAME
25 * shmt05
27 * CALLS
28 * shmctl(2) shmget(2) shmat(2)
30 * ALGORITHM
31 * Create two shared memory segments and attach them to the same process
32 * at two different addresses. The addresses DO BUMP into each other.
33 * The second attach should Fail.
38 #include <stdio.h>
39 #include <sys/types.h>
40 #include <sys/ipc.h>
41 #include <sys/shm.h>
42 #include <sys/utsname.h>
43 #include <errno.h>
44 #include <time.h>
46 /** LTP Port **/
47 #include "test.h"
48 #include "usctest.h"
51 char *TCID="shmt05"; /* Test program identifier. */
52 int TST_TOTAL=2; /* Total number of test cases. */
53 extern int Tst_count; /* Test Case counter for tst_* routines */
54 /**************/
56 key_t key[2];
58 #define ADDR (void *)0x80000
59 #define ADDR1 (void *)0x81000
60 #define ADDR_IA (void *)0x40000000
61 #define ADDR1_IA (void *)0x40000010
63 #define SIZE 16*1024
65 #define srand48 srand
66 #define lrand48 rand
68 int rm_shm(int);
70 int main(void)
72 int shmid, shmid1;
73 char *cp, *cp1;
75 srand48((getpid() << 16) + (unsigned)time((time_t *)NULL));
77 key[0] = (key_t) lrand48();
78 key[1] = (key_t) lrand48();
80 /*--------------------------------------------------------*/
83 if ((shmid = shmget(key[0], SIZE, IPC_CREAT|0666)) < 0) {
84 perror("shmget");
85 tst_resm(TFAIL,
86 "Error: shmget: shmid = %d, errno = %d\n",
87 shmid, errno) ;
88 } else {
89 #ifdef __ia64__
90 cp = (char *) shmat(shmid, ADDR_IA, 0);
91 #elif defined(__ARM_ARCH_4T__) || defined(__minix)
92 cp = (char *) shmat(shmid, (void *)NULL, 0);
93 #else
94 cp = (char *) shmat(shmid, ADDR, 0);
95 #endif
96 if (cp == (char *)-1) {
97 tst_resm(TFAIL,"shmat");
98 rm_shm(shmid) ;
102 tst_resm(TPASS,"shmget & shmat");
104 /*--------------------------------------------------------*/
107 if ((shmid1 = shmget(key[1], SIZE, IPC_CREAT|0666)) < 0) {
108 perror("shmget2");
109 tst_resm(TFAIL,
110 "Error: shmget: shmid1 = %d, errno = %d\n",
111 shmid1, errno) ;
112 } else {
113 #ifdef __ia64__
114 cp1 = (char *) shmat(shmid1, ADDR1_IA, 0);
115 #elif defined(__ARM_ARCH_4T__)
116 cp1 = (char *) shmat(shmid1, (void *)NULL, 0);
117 #else
118 cp1 = (char *) shmat(shmid1, ADDR1, 0);
119 #endif
120 if (cp1 != (char *)-1) {
121 perror("shmat");
122 tst_resm(TFAIL,
123 "Error: shmat: shmid1 = %d, addr= %#x, errno = %d\n",
124 shmid1, cp1, errno);
128 tst_resm(TPASS,"2nd shmget & shmat");
130 /*------------------------------------------------------*/
132 rm_shm(shmid) ;
133 rm_shm(shmid1) ;
135 tst_exit() ;
137 /*-------------------------------------------------------*/
138 return(0);
141 int rm_shm(shmid)
142 int shmid ;
144 if (shmctl(shmid, IPC_RMID, NULL) == -1) {
145 perror("shmctl");
146 tst_resm(TFAIL,
147 "shmctl Failed to remove: shmid = %d, errno = %d\n",
148 shmid, errno) ;
149 tst_exit();
151 return(0);