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 */
28 * shmctl(2) shmget(2) shmat(2)
31 * Create and attach a shared memory segment, write to it
32 * and then fork a child. The child Verifies that the shared memory segment
33 * that it inherited from the parent conatins the same data that was originally
34 * written to it by the parent.
40 #include <sys/types.h>
44 #include <sys/utsname.h>
49 #define ADDR (void *)0x80000
50 #define ADDR_IA (void *)0x40000000
58 char *TCID
="shmt07"; /* Test program identifier. */
59 int TST_TOTAL
=2; /* Total number of test cases. */
60 extern int Tst_count
; /* Test Case counter for tst_* routines */
69 int shmid
, pid
, status
;
72 key
= (key_t
) getpid() ;
74 /*---------------------------------------------------------*/
78 if ((shmid
= shmget(key
, SIZE
, IPC_CREAT
|0666)) < 0) {
80 tst_resm(TFAIL
,"Error: shmget: shmid = %d, errno = %d\n",
86 cp
= (char *) shmat(shmid
, ADDR_IA
, 0);
87 #elif defined(__ARM_ARCH_4T__) || defined(__minix)
88 cp
= (char *) shmat(shmid
, (void *) NULL
, 0);
90 cp
= (char *) shmat(shmid
, ADDR
, 0);
92 if (cp
== (char *)-1) {
95 "Error: shmat: shmid = %d, errno = %d\n",
104 tst_resm(TPASS
,"shmget,shmat");
106 /*-------------------------------------------------------*/
112 tst_resm(TBROK
,"fork failed");
117 tst_resm(TFAIL
, "Error: not 1\n");
119 if (*(cp
+1) != '2') {
120 tst_resm(TFAIL
, "Error: not 2\n");
126 while( wait(&status
) < 0 && errno
== EINTR
) ;
128 tst_resm(TPASS
,"cp & cp+1 correct") ;
130 /*-----------------------------------------------------------*/
133 /*-----------------------------------------------------------*/
140 if (shmctl(shmid
, IPC_RMID
, NULL
) == -1) {
143 "shmctl Failed to remove: shmid = %d, errno = %d\n",