ipc tests by GQ
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# Makefile for the tests
|
||||
|
||||
CC = exec cc
|
||||
CFLAGS = -Wall -D_MINIX -D_POSIX_SOURCE -I../lib/
|
||||
|
||||
PROG = semop01 semop02 semop03 semop04 semop05
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
$(PROG): tst_res.o libipc.o tst_sig.o parse_opts.o tst_tmpdir.o rmobj.o
|
||||
$(CC) $(CFLAGS) -o $@ $@.c tst_res.o libipc.o tst_sig.o parse_opts.o tst_tmpdir.o rmobj.o
|
||||
|
||||
rmobj.o: ../lib/rmobj.c
|
||||
$(CC) $(CFLAGS) -c -o rmobj.o ../lib/rmobj.c
|
||||
|
||||
tst_res.o: ../lib/tst_res.c
|
||||
$(CC) $(CFLAGS) -c -o tst_res.o ../lib/tst_res.c
|
||||
|
||||
tst_sig.o: ../lib/tst_sig.c
|
||||
$(CC) $(CFLAGS) -c -o tst_sig.o ../lib/tst_sig.c
|
||||
|
||||
tst_tmpdir.o: ../lib/tst_tmpdir.c
|
||||
$(CC) $(CFLAGS) -c -o tst_tmpdir.o ../lib/tst_tmpdir.c
|
||||
|
||||
parse_opts.o: ../lib/parse_opts.c
|
||||
$(CC) $(CFLAGS) -c -o parse_opts.o ../lib/parse_opts.c
|
||||
|
||||
libipc.o: ../lib/libipc.c
|
||||
$(CC) $(CFLAGS) -c -o libipc.o ../lib/libipc.c
|
||||
|
||||
clean:
|
||||
/usr/bin/rm -f *.o $(PROG)
|
||||
|
||||
test:
|
||||
sh ./test.sh
|
||||
|
||||
semop01: semop01.c
|
||||
semop02: semop02.c
|
||||
semop03: semop03.c
|
||||
semop04: semop04.c
|
||||
semop05: semop05.c
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
* the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* semop01.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* semop01 - test that semop() basic functionality is correct
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a semaphore set and initialize some values
|
||||
* loop if that option was specified
|
||||
* call semop() to set values for the primitive semaphores
|
||||
* check the return code
|
||||
* if failure, issue a FAIL message.
|
||||
* otherwise,
|
||||
* if doing functionality testing
|
||||
* get the semaphore values and compare with expected values
|
||||
* if correct,
|
||||
* issue a PASS message
|
||||
* otherwise
|
||||
* issue a FAIL message
|
||||
* else issue a PASS message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* semop01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
|
||||
* where, -c n : Run n copies concurrently.
|
||||
* -f : Turn off functionality Testing.
|
||||
* -i n : Execute test n times.
|
||||
* -I x : Execute test for x seconds.
|
||||
* -P x : Pause for x seconds between iterations.
|
||||
* -t : Turn on syscall timing.
|
||||
*
|
||||
* HISTORY
|
||||
* 03/2001 - Written by Wayne Boyer
|
||||
* 17/01/02 - Modified. Manoj Iyer, IBM Austin. TX. manjo@austin.ibm.com
|
||||
* 4th argument to semctl() system call was modified according
|
||||
* to man pages.
|
||||
* In my opinion The test should not even have compiled but
|
||||
* it was working due to some mysterious reason.
|
||||
*
|
||||
* RESTRICTIONS
|
||||
* none
|
||||
*/
|
||||
|
||||
#include "ipcsem.h"
|
||||
|
||||
#define NSEMS 4 /* the number of primitive semaphores to test */
|
||||
|
||||
char *TCID = "semop01";
|
||||
int TST_TOTAL = 1;
|
||||
extern int Tst_count;
|
||||
|
||||
int sem_id_1 = -1; /* a semaphore set with read & alter permissions */
|
||||
|
||||
|
||||
struct sembuf sops[PSEMS]; /* an array of sembuf structures */
|
||||
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
union semun get_arr;
|
||||
int lc; /* loop counter */
|
||||
char *msg; /* message returned from parse_opts */
|
||||
int i;
|
||||
int fail = 0;
|
||||
|
||||
get_arr.array = malloc(sizeof(unsigned short int) * PSEMS);
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
setup(); /* global setup */
|
||||
|
||||
/* The following loop checks looping state if -i option given */
|
||||
|
||||
for (lc = 0; TEST_LOOPING(lc); lc++) {
|
||||
/* reset Tst_count in case we are looping */
|
||||
Tst_count = 0;
|
||||
|
||||
/*
|
||||
* Use TEST macro to make the call
|
||||
*/
|
||||
|
||||
TEST(semop(sem_id_1, sops, NSEMS));
|
||||
|
||||
if (TEST_RETURN == -1) {
|
||||
tst_resm(TFAIL, "%s call failed - errno = %d "
|
||||
": %s", TCID, TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
} else {
|
||||
if (STD_FUNCTIONAL_TEST) {
|
||||
|
||||
/* get the values and make sure they */
|
||||
/* are the same as what was set */
|
||||
if (semctl(sem_id_1, 0, GETALL, get_arr) ==
|
||||
-1) {
|
||||
tst_brkm(TBROK, cleanup, "semctl() "
|
||||
"failed in functional test");
|
||||
}
|
||||
|
||||
for (i=0; i<NSEMS; i++) {
|
||||
if (get_arr.array[i] != i*i) {
|
||||
fail = 1;
|
||||
}
|
||||
}
|
||||
if (fail) {
|
||||
tst_resm(TFAIL, "semaphore values"
|
||||
" are not expected");
|
||||
} else {
|
||||
tst_resm(TPASS, "semaphore values"
|
||||
" are correct");
|
||||
}
|
||||
|
||||
} else {
|
||||
tst_resm(TPASS, "call succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* clean up things in case we are looping
|
||||
*/
|
||||
get_arr.val = 0;
|
||||
for (i=0; i<NSEMS; i++) {
|
||||
if(semctl(sem_id_1, i, SETVAL, get_arr) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "semctl failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
/*NOTREACHED*/
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* setup() - performs all the ONE TIME setup for this test.
|
||||
*/
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* capture signals */
|
||||
tst_sig(NOFORK, DEF_HANDLER, cleanup);
|
||||
|
||||
/* Pause if that option was specified */
|
||||
TEST_PAUSE;
|
||||
|
||||
/*
|
||||
* Create a temporary directory and cd into it.
|
||||
* This helps to ensure that a unique msgkey is created.
|
||||
* See ../lib/libipc.c for more information.
|
||||
*/
|
||||
tst_tmpdir();
|
||||
|
||||
/* get an IPC resource key */
|
||||
semkey = getipckey();
|
||||
|
||||
/* create a semaphore set with read and alter permissions */
|
||||
if ((sem_id_1 =
|
||||
semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
|
||||
}
|
||||
|
||||
/* set up some values for the first four primitive semaphores */
|
||||
for (i=0; i<NSEMS; i++){
|
||||
sops[i].sem_num = i;
|
||||
sops[i].sem_op = i*i; /* 0, 1, 4, 9, */
|
||||
sops[i].sem_flg = SEM_UNDO;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if it exists, remove the semaphore resouce */
|
||||
rm_sema(sem_id_1);
|
||||
|
||||
/* Remove the temporary directory */
|
||||
tst_rmdir();
|
||||
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
|
||||
/* exit with return code appropriate for results */
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
* the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* semop02.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* semop02 - test for E2BIG, EACCES, EFAULT and EINVAL errors
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a semaphore set with read and alter permissions
|
||||
* create a semaphore set without read and alter permissions
|
||||
* loop if that option was specified
|
||||
* call semop with five different invalid cases
|
||||
* check the errno value
|
||||
* issue a PASS message if we get E2BIG, EACCES, EFAULT or EINVAL
|
||||
* otherwise, the tests fails
|
||||
* issue a FAIL message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* semop02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
|
||||
* where, -c n : Run n copies concurrently.
|
||||
* -e : Turn on errno logging.
|
||||
* -i n : Execute test n times.
|
||||
* -I x : Execute test for x seconds.
|
||||
* -P x : Pause for x seconds between iterations.
|
||||
* -t : Turn on syscall timing.
|
||||
*
|
||||
* HISTORY
|
||||
* 03/2001 - Written by Wayne Boyer
|
||||
*
|
||||
* RESTRICTIONS
|
||||
* none
|
||||
*/
|
||||
#include <pwd.h>
|
||||
|
||||
#include "ipcsem.h"
|
||||
|
||||
char *TCID = "semop02";
|
||||
int TST_TOTAL = 4;
|
||||
extern int Tst_count;
|
||||
|
||||
int exp_enos[] = {E2BIG, EACCES, EFAULT, EINVAL, 0};
|
||||
|
||||
int sem_id_1 = -1; /* a semaphore set with read & alter permissions */
|
||||
int sem_id_2 = -1; /* a semaphore set without read & alter permissions */
|
||||
int bad_id = -1;
|
||||
char nobody_uid[] = "nobody";
|
||||
struct passwd *ltpuser;
|
||||
|
||||
struct sembuf s_buf[PSEMS];
|
||||
|
||||
int badbuf = -1;
|
||||
|
||||
#define NSOPS 5 /* a resonable number of operations */
|
||||
#define BIGOPS 1024 /* a value that is too large for the number */
|
||||
/* of semop operations that are permitted */
|
||||
|
||||
struct test_case_t {
|
||||
int *semid; /* the semaphore id */
|
||||
struct sembuf *t_sbuf; /* the first in an array of sembuf structures */
|
||||
unsigned t_ops; /* the number of elements in the above array */
|
||||
int error; /* the expected error number */
|
||||
} TC[] = {
|
||||
/* E2BIG - the number of operations is too big */
|
||||
{&sem_id_1, (struct sembuf *)&s_buf, BIGOPS, E2BIG},
|
||||
|
||||
/* EACCES - the semaphore set has no access permission */
|
||||
{&sem_id_2, (struct sembuf *)&s_buf, NSOPS, EACCES},
|
||||
|
||||
/* EINVAL - the number of elments (t_ops) is 0 */
|
||||
{&sem_id_1, (struct sembuf *)&s_buf, 0, EINVAL},
|
||||
|
||||
/* EINVAL - the semaphore set doesn't exist */
|
||||
{&bad_id, (struct sembuf *)&s_buf, NSOPS, EINVAL}
|
||||
};
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int lc; /* loop counter */
|
||||
char *msg; /* message returned from parse_opts */
|
||||
int i;
|
||||
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
setup(); /* global setup */
|
||||
|
||||
/* The following loop checks looping state if -i option given */
|
||||
|
||||
for (lc = 0; TEST_LOOPING(lc); lc++) {
|
||||
/* reset Tst_count in case we are looping */
|
||||
Tst_count = 0;
|
||||
|
||||
for (i=0; i<TST_TOTAL; i++) {
|
||||
/*
|
||||
* use the TEST macro to make the call
|
||||
*/
|
||||
|
||||
TEST(semop(*(TC[i].semid), TC[i].t_sbuf, TC[i].t_ops));
|
||||
|
||||
if (TEST_RETURN != -1) {
|
||||
tst_resm(TFAIL, "call succeeded unexpectedly");
|
||||
continue;
|
||||
}
|
||||
|
||||
TEST_ERROR_LOG(TEST_ERRNO);
|
||||
|
||||
if (TEST_ERRNO == TC[i].error) {
|
||||
tst_resm(TPASS, "expected failure - errno = "
|
||||
"%d : %s", TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
} else {
|
||||
tst_resm(TFAIL, "unexpected error - "
|
||||
"%d : %s", TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
/*NOTREACHED*/
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* setup() - performs all the ONE TIME setup for this test.
|
||||
*/
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
/* Switch to nobody user for correct error code collection */
|
||||
if (geteuid() != 0) {
|
||||
tst_brkm(TBROK, tst_exit, "Test must be run as root");
|
||||
}
|
||||
|
||||
/* capture signals */
|
||||
tst_sig(NOFORK, DEF_HANDLER, cleanup);
|
||||
|
||||
/* Set up the expected error numbers for -e option */
|
||||
TEST_EXP_ENOS(exp_enos);
|
||||
|
||||
/* Pause if that option was specified */
|
||||
TEST_PAUSE;
|
||||
|
||||
/*
|
||||
* Create a temporary directory and cd into it.
|
||||
* This helps to ensure that a unique msgkey is created.
|
||||
* See ../lib/libipc.c for more information.
|
||||
*/
|
||||
tst_tmpdir();
|
||||
|
||||
ltpuser = getpwnam(nobody_uid);
|
||||
if (seteuid(ltpuser->pw_uid) == -1) {
|
||||
tst_resm(TINFO, "setreuid failed to "
|
||||
"to set the effective uid to %d",
|
||||
ltpuser->pw_uid);
|
||||
perror("setreuid");
|
||||
}
|
||||
|
||||
/* get an IPC resource key */
|
||||
semkey = getipckey();
|
||||
|
||||
/* create a semaphore set with read and alter permissions */
|
||||
if ((sem_id_1 =
|
||||
semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
|
||||
}
|
||||
|
||||
/* increment the semkey */
|
||||
semkey += 1;
|
||||
|
||||
/* create a semaphore set without read and alter permissions */
|
||||
if ((sem_id_2 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if they exist, remove the semaphore resources */
|
||||
rm_sema(sem_id_1);
|
||||
rm_sema(sem_id_2);
|
||||
|
||||
/* Remove the temporary directory */
|
||||
tst_rmdir();
|
||||
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
|
||||
/* exit with return code appropriate for results */
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
* the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* semop03.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* semop03 - test for EFBIG error
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a semaphore set with read and alter permissions
|
||||
* loop if that option was specified
|
||||
* call semop() using two different invalid cases
|
||||
* check the errno value
|
||||
* issue a PASS message if we get EFBIG
|
||||
* otherwise, the tests fails
|
||||
* issue a FAIL message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* semop03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
|
||||
* where, -c n : Run n copies concurrently.
|
||||
* -e : Turn on errno logging.
|
||||
* -i n : Execute test n times.
|
||||
* -I x : Execute test for x seconds.
|
||||
* -P x : Pause for x seconds between iterations.
|
||||
* -t : Turn on syscall timing.
|
||||
*
|
||||
* HISTORY
|
||||
* 03/2001 - Written by Wayne Boyer
|
||||
*
|
||||
* RESTRICTIONS
|
||||
* none
|
||||
*/
|
||||
|
||||
#include "ipcsem.h"
|
||||
|
||||
char *TCID = "semop03";
|
||||
int TST_TOTAL = 2;
|
||||
extern int Tst_count;
|
||||
|
||||
int exp_enos[] = {EFBIG, 0}; /* 0 terminated list of expected errnos */
|
||||
|
||||
int sem_id_1 = -1;
|
||||
|
||||
struct sembuf s_buf;
|
||||
|
||||
int TC[] = {-1, PSEMS + 1}; /* negative and too many "primitive" semas */
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int lc; /* loop counter */
|
||||
char *msg; /* message returned from parse_opts */
|
||||
int i;
|
||||
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) !=(char *)NULL){
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
setup(); /* global setup */
|
||||
|
||||
/* initialize two fields in the sembuf structure here */
|
||||
s_buf.sem_op = 1; /* add this value to struct sem.semval */
|
||||
s_buf.sem_flg = SEM_UNDO; /* undo when process exits */
|
||||
|
||||
/* The following loop checks looping state if -i option given */
|
||||
|
||||
for (lc = 0; TEST_LOOPING(lc); lc++) {
|
||||
/* reset Tst_count in case we are looping */
|
||||
Tst_count = 0;
|
||||
|
||||
for (i=0; i<TST_TOTAL; i++) {
|
||||
|
||||
/* initialize the last field in the sembuf */
|
||||
/* structure to the test dependent value */
|
||||
s_buf.sem_num = TC[i];
|
||||
|
||||
/*
|
||||
* use the TEST macro to make the call
|
||||
*/
|
||||
|
||||
TEST(semop(sem_id_1, &s_buf, 1));
|
||||
|
||||
if (TEST_RETURN != -1) {
|
||||
tst_resm(TFAIL, "call succeeded unexpectedly");
|
||||
continue;
|
||||
}
|
||||
|
||||
TEST_ERROR_LOG(TEST_ERRNO);
|
||||
|
||||
switch(TEST_ERRNO) {
|
||||
case EFBIG:
|
||||
tst_resm(TPASS, "expected failure - errno = "
|
||||
"%d : %s", TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
break;
|
||||
default:
|
||||
tst_resm(TFAIL, "unexpected error - "
|
||||
"%d : %s", TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
/*NOTREACHED*/
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* setup() - performs all the ONE TIME setup for this test.
|
||||
*/
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
/* capture signals */
|
||||
tst_sig(NOFORK, DEF_HANDLER, cleanup);
|
||||
|
||||
/* Set up the expected error numbers for -e option */
|
||||
TEST_EXP_ENOS(exp_enos);
|
||||
|
||||
/* Pause if that option was specified */
|
||||
TEST_PAUSE;
|
||||
|
||||
/*
|
||||
* Create a temporary directory and cd into it.
|
||||
* This helps to ensure that a unique msgkey is created.
|
||||
* See ../lib/libipc.c for more information.
|
||||
*/
|
||||
tst_tmpdir();
|
||||
|
||||
/* get an IPC resource key */
|
||||
semkey = getipckey();
|
||||
|
||||
/* create a semaphore with read and alter permissions */
|
||||
if ((sem_id_1 =
|
||||
semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if it exists, remove the semaphore resource */
|
||||
rm_sema(sem_id_1);
|
||||
|
||||
/* Remove the temporary directory */
|
||||
tst_rmdir();
|
||||
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
|
||||
/* exit with return code appropriate for results */
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
* the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* semop04.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* semop04 - test for EAGAIN error
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a semaphore set with read and alter permissions
|
||||
* loop if that option was specified
|
||||
* call semop() with two different invalid cases
|
||||
* check the errno value
|
||||
* issue a PASS message if we get EAGAIN
|
||||
* otherwise, the tests fails
|
||||
* issue a FAIL message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* semop04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
|
||||
* where, -c n : Run n copies concurrently.
|
||||
* -e : Turn on errno logging.
|
||||
* -i n : Execute test n times.
|
||||
* -I x : Execute test for x seconds.
|
||||
* -P x : Pause for x seconds between iterations.
|
||||
* -t : Turn on syscall timing.
|
||||
*
|
||||
* HISTORY
|
||||
* 03/2001 - Written by Wayne Boyer
|
||||
*
|
||||
* RESTRICTIONS
|
||||
* none
|
||||
*/
|
||||
|
||||
#include "ipcsem.h"
|
||||
|
||||
char *TCID = "semop04";
|
||||
int TST_TOTAL = 2;
|
||||
extern int Tst_count;
|
||||
|
||||
int exp_enos[] = {EAGAIN, 0}; /* 0 terminated list of expected errnos */
|
||||
|
||||
int sem_id_1 = -1;
|
||||
|
||||
struct sembuf s_buf;
|
||||
|
||||
struct test_case_t {
|
||||
union semun get_arr;
|
||||
short op;
|
||||
short flg;
|
||||
short num;
|
||||
int error;
|
||||
} TC[] = {
|
||||
/* EAGAIN sem_op = 0 */
|
||||
{{1}, 0, IPC_NOWAIT, 2, EAGAIN},
|
||||
|
||||
/* EAGAIN sem_op = -1 */
|
||||
{{0}, -1, IPC_NOWAIT, 2, EAGAIN}
|
||||
};
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int lc; /* loop counter */
|
||||
char *msg; /* message returned from parse_opts */
|
||||
int val = 1; /* value for SETVAL */
|
||||
|
||||
int i;
|
||||
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
setup(); /* global setup */
|
||||
|
||||
/* The following loop checks looping state if -i option given */
|
||||
|
||||
for (lc = 0; TEST_LOOPING(lc); lc++) {
|
||||
/* reset Tst_count in case we are looping */
|
||||
Tst_count = 0;
|
||||
|
||||
for (i=0; i<TST_TOTAL; i++) {
|
||||
|
||||
/* initialize the s_buf buffer */
|
||||
s_buf.sem_op = TC[i].op;
|
||||
s_buf.sem_flg = TC[i].flg;
|
||||
s_buf.sem_num = TC[i].num;
|
||||
|
||||
/* initialize all the primitive semaphores */
|
||||
TC[i].get_arr.val = val--;
|
||||
if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].get_arr)
|
||||
== -1) {
|
||||
tst_brkm(TBROK, cleanup, "semctl() failed");
|
||||
}
|
||||
|
||||
/*
|
||||
* make the call with the TEST macro
|
||||
*/
|
||||
|
||||
TEST(semop(sem_id_1, &s_buf, 1));
|
||||
|
||||
if (TEST_RETURN != -1) {
|
||||
tst_resm(TFAIL, "call succeeded unexpectedly");
|
||||
continue;
|
||||
}
|
||||
|
||||
TEST_ERROR_LOG(TEST_ERRNO);
|
||||
|
||||
if (TEST_ERRNO == TC[i].error) {
|
||||
tst_resm(TPASS, "expected failure - errno = %d" " : %s", TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
} else {
|
||||
tst_resm(TFAIL, "unexpected error - "
|
||||
"%d : %s", TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
/*NOTREACHED*/
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* setup() - performs all the ONE TIME setup for this test.
|
||||
*/
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
/* capture signals */
|
||||
tst_sig(NOFORK, DEF_HANDLER, cleanup);
|
||||
|
||||
/* Set up the expected error numbers for -e option */
|
||||
TEST_EXP_ENOS(exp_enos);
|
||||
|
||||
/* Pause if that option was specified */
|
||||
TEST_PAUSE;
|
||||
|
||||
/*
|
||||
* Create a temporary directory and cd into it.
|
||||
* This helps to ensure that a unique msgkey is created.
|
||||
* See ../lib/libipc.c for more information.
|
||||
*/
|
||||
tst_tmpdir();
|
||||
|
||||
/* get an IPC resource key */
|
||||
semkey = getipckey();
|
||||
|
||||
/* create a semaphore set with read and alter permissions */
|
||||
/* and PSEMS "primitive" semaphores */
|
||||
if ((sem_id_1 =
|
||||
semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if it exists, remove the semaphore resource */
|
||||
rm_sema(sem_id_1);
|
||||
|
||||
/* Remove the temporary directory */
|
||||
tst_rmdir();
|
||||
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
|
||||
/* exit with return code appropriate for results */
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
* the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* semop05.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* semop05 - test for EINTR and EIDRM errors
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a semaphore set with read and alter permissions
|
||||
* loop if that option was specified
|
||||
* set up the s_buf buffer
|
||||
* initialize the primitive semaphores
|
||||
* fork a child process
|
||||
* child calls semop() and sleeps
|
||||
* parent either removes the semaphore set or sends a signal to the child
|
||||
* parent then exits
|
||||
* child gets a return from the semop() call
|
||||
* check the errno value
|
||||
* issue a PASS message if we get EINTR or EIDRM
|
||||
* otherwise, the tests fails
|
||||
* issue a FAIL message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* semop05 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
|
||||
* where, -c n : Run n copies concurrently.
|
||||
* -e : Turn on errno logging.
|
||||
* -i n : Execute test n times.
|
||||
* -I x : Execute test for x seconds.
|
||||
* -P x : Pause for x seconds between iterations.
|
||||
* -t : Turn on syscall timing.
|
||||
*
|
||||
* HISTORY
|
||||
* 03/2001 - Written by Wayne Boyer
|
||||
*
|
||||
* RESTRICTIONS
|
||||
* none
|
||||
*/
|
||||
|
||||
#include "ipcsem.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
void sighandler(int);
|
||||
|
||||
char *TCID = "semop05";
|
||||
int TST_TOTAL = 4;
|
||||
extern int Tst_count;
|
||||
|
||||
int exp_enos[] = {EINTR, EIDRM, 0}; /* 0 terminated list of expected errnos */
|
||||
|
||||
int sem_id_1 = -1;
|
||||
|
||||
struct sembuf s_buf;
|
||||
|
||||
struct test_case_t {
|
||||
union semun semunptr;
|
||||
short op;
|
||||
short flg;
|
||||
short num;
|
||||
int error;
|
||||
} TC[] = {
|
||||
/* EIRDM sem_op = 0 */
|
||||
{{1}, 0, 0, 2, EIDRM},
|
||||
|
||||
/* EIRDM sem_op = -1 */
|
||||
{{0}, -1, 0, 3, EIDRM},
|
||||
|
||||
/* EINTR sem_op = 0 */
|
||||
{{1}, 0, 0, 4, EINTR},
|
||||
|
||||
/* EINTR sem_op = -1 */
|
||||
{{0}, -1, 0, 5, EINTR}
|
||||
};
|
||||
|
||||
#ifdef UCLINUX
|
||||
void do_child_uclinux();
|
||||
static int i_uclinux;
|
||||
#endif
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int lc; /* loop counter */
|
||||
char *msg; /* message returned from parse_opts */
|
||||
int i;
|
||||
pid_t pid;
|
||||
void do_child(int);
|
||||
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
#ifdef UCLINUX
|
||||
maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id_1);
|
||||
#endif
|
||||
|
||||
setup(); /* global setup */
|
||||
|
||||
/* The following loop checks looping state if -i option given */
|
||||
|
||||
for (lc = 0; TEST_LOOPING(lc); lc++) {
|
||||
/* reset Tst_count in case we are looping */
|
||||
Tst_count = 0;
|
||||
|
||||
for (i=0; i<TST_TOTAL; i++) {
|
||||
|
||||
/* initialize the s_buf buffer */
|
||||
s_buf.sem_op = TC[i].op;
|
||||
s_buf.sem_flg = TC[i].flg;
|
||||
s_buf.sem_num = TC[i].num;
|
||||
|
||||
/* initialize all of the primitive semaphores */
|
||||
if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr)
|
||||
== -1) {
|
||||
tst_brkm(TBROK, cleanup, "semctl() failed");
|
||||
}
|
||||
|
||||
if ((pid = fork()) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "could not fork");
|
||||
}
|
||||
|
||||
if (pid == 0) { /* child */
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(av[0], "dd", i, sem_id_1) < 0) {
|
||||
tst_brkm(TBROK, cleanup,
|
||||
"could not self_exec");
|
||||
}
|
||||
#else
|
||||
do_child(i);
|
||||
#endif
|
||||
} else { /* parent */
|
||||
usleep(250000);
|
||||
|
||||
/*
|
||||
* If we are testing for EIDRM then remove
|
||||
* the semaphore, else send a signal that
|
||||
* must be caught as we are testing for
|
||||
* EINTR.
|
||||
*/
|
||||
if (TC[i].error == EIDRM) {
|
||||
/* remove the semaphore resource */
|
||||
rm_sema(sem_id_1);
|
||||
} else {
|
||||
if (kill(pid, SIGHUP) == -1) {
|
||||
tst_brkm(TBROK, cleanup,
|
||||
"kill failed");
|
||||
}
|
||||
}
|
||||
|
||||
/* let the child carry on */
|
||||
waitpid(pid,NULL,0);
|
||||
}
|
||||
|
||||
/*
|
||||
* recreate the semaphore resource if needed
|
||||
*/
|
||||
if (TC[i].error == EINTR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT |
|
||||
IPC_EXCL | SEM_RA)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "couldn't recreate "
|
||||
"semaphore");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
/*NOTREACHED*/
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* do_child()
|
||||
*/
|
||||
void
|
||||
do_child(int i)
|
||||
{
|
||||
/*
|
||||
* make the call with the TEST macro
|
||||
*/
|
||||
|
||||
TEST(semop(sem_id_1, &s_buf, 1));
|
||||
|
||||
if (TEST_RETURN != -1) {
|
||||
tst_resm(TFAIL, "call succeeded when error expected");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
TEST_ERROR_LOG(TEST_ERRNO);
|
||||
|
||||
if (TEST_ERRNO == TC[i].error) {
|
||||
tst_resm(TPASS, "expected failure - errno = %d"
|
||||
" : %s", TEST_ERRNO, strerror(TEST_ERRNO));
|
||||
} else {
|
||||
tst_resm(TFAIL, "unexpected error - "
|
||||
"%d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#ifdef UCLINUX
|
||||
/*
|
||||
* do_child_uclinux() - capture signals, re-initialize s_buf then call do_child
|
||||
* with the appropriate argument
|
||||
*/
|
||||
void
|
||||
do_child_uclinux()
|
||||
{
|
||||
int i = i_uclinux;
|
||||
|
||||
/* capture signals */
|
||||
tst_sig(FORK, sighandler, cleanup);
|
||||
|
||||
/* initialize the s_buf buffer */
|
||||
s_buf.sem_op = TC[i].op;
|
||||
s_buf.sem_flg = TC[i].flg;
|
||||
s_buf.sem_num = TC[i].num;
|
||||
|
||||
do_child(i);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* sighandler() - handle signals
|
||||
*/
|
||||
void
|
||||
sighandler(int sig)
|
||||
{
|
||||
/* we don't need to do anything here */
|
||||
}
|
||||
|
||||
/*
|
||||
* setup() - performs all the ONE TIME setup for this test.
|
||||
*/
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
/* capture signals */
|
||||
tst_sig(FORK, sighandler, cleanup);
|
||||
|
||||
/* Set up the expected error numbers for -e option */
|
||||
TEST_EXP_ENOS(exp_enos);
|
||||
|
||||
/* Pause if that option was specified */
|
||||
TEST_PAUSE;
|
||||
|
||||
/*
|
||||
* Create a temporary directory and cd into it.
|
||||
* This helps to ensure that a unique msgkey is created.
|
||||
* See ../lib/libipc.c for more information.
|
||||
*/
|
||||
tst_tmpdir();
|
||||
|
||||
/* get an IPC resource key */
|
||||
semkey = getipckey();
|
||||
|
||||
/* create a semaphore set with read and alter permissions */
|
||||
/* and PSEMS "primitive" semaphores */
|
||||
if ((sem_id_1 =
|
||||
semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if it exists, remove the semaphore resource */
|
||||
rm_sema(sem_id_1);
|
||||
|
||||
/* Remove the temporary directory */
|
||||
tst_rmdir();
|
||||
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
|
||||
/* exit with return code appropriate for results */
|
||||
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
./semop01
|
||||
./semop02
|
||||
./semop03
|
||||
./semop04
|
||||
./semop05
|
||||
Reference in New Issue
Block a user