sort: add -x hex sort feature back
[minix.git] / test / ipc / semctl / semctl07.c
blobb93bf920989c692c534c0d0a3baa389ccf61ee6e
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 /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
21 /* 10/30/2002 Port to LTP dbarrera@us.ibm.com */
24 * NAME
25 * semctl07
27 * CALLS
28 * semctl(2) semget(2)
30 * ALGORITHM
31 * Get and manipulate a set of semaphores.
33 * RESTRICTIONS
38 #include <sys/types.h> /* needed for test */
39 #include <sys/ipc.h> /* needed for test */
40 #include <sys/sem.h> /* needed for test */
41 #include <signal.h> /* needed for test */
42 #include <errno.h> /* needed for test */
43 #include <stdio.h> /* needed by testhead.h */
44 #include <sys/wait.h> /* needed by testhead.h */
45 #include "ipcsem.h"
46 #include "test.h"
47 #include "usctest.h"
50 void setup(void);
51 void cleanup(void);
55 *These globals must be defined in the test.
59 char *TCID="semctl07"; /* Test program identifier. */
60 int TST_TOTAL=1; /* Total number of test cases. */
61 extern int Tst_count; /* Test Case counter for tst_* routines */
63 int exp_enos[]={0}; /* List must end with 0 */
67 /*--------------------------------------------------------------*/
69 int main(int argc, char *argv[])
71 key_t key;
72 int semid, nsems, status;
73 struct semid_ds buf_ds;
75 union semun {
76 int val;
77 struct semid_ds *buf;
78 short *array;
81 union semun arg;
83 setup(); /* temp file is now open */
84 /*--------------------------------------------------------------*/
85 key = nsems = 1;
86 if ((semid = semget(key, nsems, SEM_RA|IPC_CREAT)) == -1) {
87 tst_resm(TFAIL, "semget() failed errno = %d", errno);
88 tst_exit();
90 arg.buf = &buf_ds;
91 if ((status = semctl(semid, 0, IPC_STAT, arg)) == -1) {
92 tst_resm(TFAIL, "semctl() failed errno = %d", errno);
93 semctl(semid, 1, IPC_RMID, arg);
94 tst_exit();
98 * Check contents of semid_ds structure.
101 if (arg.buf->sem_nsems != nsems) {
102 tst_resm(TFAIL, "error: unexpected number of sems %d", arg.buf->sem_nsems);
103 tst_exit();
105 if (arg.buf->sem_perm.uid != getuid()) {
106 tst_resm(TFAIL, "error: unexpected uid %d", arg.buf->sem_perm.uid);
107 tst_exit();
109 if (arg.buf->sem_perm.gid != getgid()) {
110 tst_resm(TFAIL, "error: unexpected gid %d", arg.buf->sem_perm.gid);
111 tst_exit();
113 if (arg.buf->sem_perm.cuid != getuid()) {
114 tst_resm(TFAIL, "error: unexpected cuid %d", arg.buf->sem_perm.cuid);
115 tst_exit();
117 if (arg.buf->sem_perm.cgid != getgid()) {
118 tst_resm(TFAIL, "error: unexpected cgid %d", arg.buf->sem_perm.cgid);
119 tst_exit();
121 if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
122 tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
123 tst_exit();
125 arg.val = 1;
126 if ((status = semctl(semid, 0, SETVAL, arg)) == -1) {
127 tst_resm(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno);
128 tst_exit();
130 if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
131 tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
132 tst_exit();
134 if (status != arg.val) {
135 tst_resm(TFAIL, "error: unexpected value %d", status);
136 tst_exit();
138 if ((status = semctl(semid, 0, GETPID, arg)) == -1) {
139 tst_resm(TFAIL, "semctl(GETPID) failed errno = %d", errno);
140 tst_exit();
142 status = getpid();
143 if (status == 0)
145 tst_resm(TFAIL, "error: unexpected pid %d", status);
146 tst_exit();
148 if ((status = semctl(semid, 0, GETNCNT, arg)) == -1) {
149 tst_resm(TFAIL, "semctl(GETNCNT) failed errno = %d", errno);
150 tst_exit();
152 if (status != 0) {
153 tst_resm(TFAIL, "error: unexpected semncnt %d", status);
154 tst_exit();
156 if ((status = semctl(semid, 0, GETZCNT, arg)) == -1) {
157 tst_resm(TFAIL, "semctl(GETZCNT) failed errno = %d", errno);
158 tst_exit();
160 if (status != 0) {
161 tst_resm(TFAIL, "error: unexpected semzcnt %d", status);
162 tst_exit();
165 semctl(semid, 0, IPC_RMID, arg);
166 if ((status = semctl(semid, 0, GETPID, arg)) != -1) {
167 tst_resm(TFAIL, "semctl(IPC_RMID) failed");
168 tst_exit();
171 tst_resm(TPASS, "semctl07 ran successfully!");
172 /*--------------------------------------------------------------*/
173 /* Clean up any files created by test before exit. */
174 /*--------------------------------------------------------------*/
176 cleanup();
177 return (0);
179 /*--------------------------------------------------------------*/
181 /***************************************************************
182 * setup() - performs all ONE TIME setup for this test.
183 *****************************************************************/
184 void
185 setup()
187 /* You will want to enable some signal handling so you can capture
188 * unexpected signals like SIGSEGV.
189 * */
190 tst_sig(NOFORK, DEF_HANDLER, cleanup);
193 /* Pause if that option was specified */
194 /* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
195 * fork the test with the -c option. You want to make sure you do this
196 * before you create your temporary directory.
198 TEST_PAUSE;
202 /***************************************************************
203 * cleanup() - performs all ONE TIME cleanup for this test at
204 * completion or premature exit.
205 ****************************************************************/
206 void
207 cleanup()
210 * print timing stats if that option was specified.
211 * print errno log if that option was specified.
213 TEST_CLEANUP;
215 /* exit with return code appropriate for results */
216 tst_exit();