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 one shared memory segment and attach it twice to the same process,
32 * at an address that is chosen by the system. After the first attach has
33 * completed, write to it and then do the second attach.
34 * Verify that the doubly attached segment contains the same data.
40 #include <sys/types.h>
49 char *TCID
="shmt03"; /* Test program identifier. */
50 int TST_TOTAL
=4; /* Total number of test cases. */
51 extern int Tst_count
; /* Test Case counter for tst_* routines */
68 key
= (key_t
) getpid() ;
71 /*------------------------------------------------------------*/
74 if ((shmid
= shmget(key
, 16*K_1
, IPC_CREAT
|0666)) < 0) {
76 tst_resm(TFAIL
, "shmget Failed: shmid = %d, errno = %d\n",
81 tst_resm(TPASS
,"shmget");
83 /*------------------------------------------------------------*/
86 if ((cp1
= (char *)shmat(shmid
, (void *)0, 0)) == (char *)-1) {
88 tst_resm(TFAIL
, "shmat Failed: shmid = %d, errno = %d\n",
93 first_attach
= SUCCESSFUL
;
96 tst_resm(TPASS
,"1st shmat");
98 /*------------------------------------------------------------*/
101 if ((cp2
= (char *)shmat(shmid
, (void *)0, 0)) == (char *)-1) {
103 tst_resm(TFAIL
, "shmat Failed: shmid = %d, errno = %d\n",
107 second_attach
= SUCCESSFUL
;
108 if ( (*cp2
!= '1' || *(cp2
+5*K_1
) != '2') &&
109 first_attach
== SUCCESSFUL
) {
111 "Error: Shared memory contents\n") ;
115 tst_resm(TPASS
,"2nd shmat");
117 /*---------------------------------------------------------------*/
122 if ( first_attach
&& second_attach
) {
123 if ( *cp2
!= '1' || *(cp2
+5*K_1
) != '2' ||
124 *cp1
!= '1' || *(cp1
+5*K_1
) != '2' ) {
125 tst_resm(TFAIL
, "Error: Shared memory contents\n") ;
129 tst_resm(TPASS
, "Correct shared memory contents");
130 /*-----------------------------------------------------------------*/
133 /*----------------------------------------------------------------*/
140 if (shmctl(shmid
, IPC_RMID
, NULL
) == -1) {
143 "shmctl Failed to remove: shmid = %d, errno = %d\n",