VM: simplify slab allocator
[minix.git] / test / ipc / shmt / shmt08.c
blob36c406255a4ea1e02da21fb821d2586bd9503f74
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 * shmt08
27 * CALLS
28 * shmctl(2) shmget(2) shmat(2) shmdt(2)
30 * ALGORITHM
31 * Create a shared memory segment. Attach it twice at an address
32 * that is provided by the system. Detach the previously attached
33 * segments from the process.
38 #include <stdio.h>
39 #include <sys/types.h>
40 #include <sys/ipc.h>
41 #include <sys/shm.h>
42 #include <errno.h>
44 #define K_1 1024
46 /** LTP Port **/
47 #include "test.h"
48 #include "usctest.h"
50 char *TCID="shmt08"; /* Test program identifier. */
51 int TST_TOTAL=2; /* Total number of test cases. */
52 extern int Tst_count; /* Test Case counter for tst_* routines */
53 /**************/
55 key_t key;
57 int rm_shm(int);
59 int main(void)
61 char *cp=NULL, *cp1=NULL;
62 int shmid;
64 key = (key_t) getpid() ;
65 errno = 0 ;
66 /*-------------------------------------------------------*/
69 if ((shmid = shmget(key, 24*K_1, IPC_CREAT|0666)) < 0) {
70 perror("shmget");
71 tst_resm(TFAIL,"Error: shmget: shmid = %d, errno = %d\n",
72 shmid, errno) ;
73 tst_exit() ;
76 cp = (char *) shmat(shmid, (void *)0, 0);
77 if (cp == (char *)-1) {
78 tst_resm(TFAIL,"shmat1 Failed");
79 rm_shm(shmid) ;
80 tst_exit() ;
83 cp1 = (char *) shmat(shmid, (void *)0, 0);
84 if (cp1 == (char *)-1) {
85 perror("shmat2");
86 rm_shm(shmid) ;
87 tst_exit() ;
90 tst_resm(TPASS,"shmget,shmat");
92 /*--------------------------------------------------------*/
95 if (shmdt(cp) < 0) {
96 perror("shmdt2");
97 tst_resm(TFAIL,"shmdt:cp") ;
100 if (shmdt(cp1) < 0 ) {
101 perror("shmdt1");
102 tst_resm(TFAIL,"shmdt:cp1") ;
105 tst_resm(TPASS,"shmdt");
107 /*---------------------------------------------------------*/
108 rm_shm(shmid) ;
109 tst_exit() ;
111 /*---------------------------------------------------------*/
112 return(0);
115 int rm_shm(shmid)
116 int shmid ;
118 if (shmctl(shmid, IPC_RMID, NULL) == -1) {
119 perror("shmctl");
120 tst_resm(TFAIL,
121 "shmctl Failed to remove: shmid = %d, errno = %d\n",
122 shmid, errno) ;
123 tst_exit();
125 return(0);