ipc tests by GQ
This commit is contained in:
31
test/ipc/msgctl/Makefile
Normal file
31
test/ipc/msgctl/Makefile
Normal file
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
|
||||
CFLAGS += -I../lib -I../../../../../include -Wall
|
||||
LDLIBS += -L../../../../../lib -lltp -L.. -lipc
|
||||
|
||||
SRCS = $(wildcard *.c)
|
||||
TARGETS = $(patsubst %.c,%,$(SRCS))
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
install:
|
||||
@set -e; for i in $(TARGETS); do ln -f $$i ../../../../bin/$$i ; done
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
179
test/ipc/msgctl/msgctl01.c
Normal file
179
test/ipc/msgctl/msgctl01.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
*
|
||||
* 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
|
||||
* msgctl01.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* msgctl01 - create a message queue, then issue the IPC_STAT command
|
||||
* and RMID commands to test the functionality
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a message queue
|
||||
* loop if that option was specified
|
||||
* call msgctl() with the IPC_STAT command
|
||||
* check the return code
|
||||
* if failure, issue a FAIL message and break remaining tests
|
||||
* otherwise,
|
||||
* if doing functionality testing
|
||||
* if the max number of bytes on the queue is > 0,
|
||||
* issue a PASS message
|
||||
* otherwise
|
||||
* issue a FAIL message
|
||||
* else issue a PASS message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* msgctl01 [-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
|
||||
*
|
||||
* RESTRICTIONS
|
||||
* none
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
#include "ipcmsg.h"
|
||||
|
||||
char *TCID = "msgctl01";
|
||||
int TST_TOTAL = 1;
|
||||
extern int Tst_count;
|
||||
|
||||
int msg_q_1 = -1; /* to hold the message queue id */
|
||||
|
||||
struct msqid_ds qs_buf;
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int lc; /* loop counter */
|
||||
char *msg; /* message returned from parse_opts */
|
||||
|
||||
/* 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;
|
||||
|
||||
/*
|
||||
* Get the msqid_ds structure values for the queue
|
||||
*/
|
||||
|
||||
TEST(msgctl(msg_q_1, IPC_STAT, &qs_buf));
|
||||
|
||||
if (TEST_RETURN == -1) {
|
||||
tst_resm(TFAIL, "%s call failed - errno = %d"
|
||||
" : %s", TCID, TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
} else {
|
||||
if (STD_FUNCTIONAL_TEST) {
|
||||
if (qs_buf.msg_qbytes > 0) {
|
||||
tst_resm(TPASS, "qs_buf.msg_qbytes is"
|
||||
" a positive value");
|
||||
} else {
|
||||
tst_resm(TFAIL, "qs_buf.msg_qbytes did"
|
||||
" not change");
|
||||
}
|
||||
} else {
|
||||
tst_resm(TPASS, "msgctl() call succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* clean up things in case we are looping
|
||||
*/
|
||||
qs_buf.msg_qbytes = 0x0000;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* 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 a message key */
|
||||
msgkey = getipckey();
|
||||
|
||||
/* make sure the initial # of bytes is 0 in our buffer */
|
||||
qs_buf.msg_qbytes = 0x0000;
|
||||
|
||||
/* now we have a key, so let's create a message queue */
|
||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if it exists, remove the message queue */
|
||||
rm_queue(msg_q_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();
|
||||
}
|
||||
|
||||
202
test/ipc/msgctl/msgctl02.c
Normal file
202
test/ipc/msgctl/msgctl02.c
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
*
|
||||
* 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
|
||||
* msgctl02.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* msgctl02 - create a message queue, then issue the IPC_SET command
|
||||
* to lower the msg_qbytes value.
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a message queue
|
||||
* loop if that option was specified
|
||||
* call msgctl() with the IPC_SET command with a new msg_qbytes value
|
||||
* check the return code
|
||||
* if failure, issue a FAIL message and break remaining tests
|
||||
* otherwise,
|
||||
* if doing functionality testing
|
||||
* if the msg_qbytes value is the new value
|
||||
* issue a PASS message
|
||||
* otherwise
|
||||
* issue a FAIL message
|
||||
* else issue a PASS message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* msgctl02 [-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
|
||||
*
|
||||
* RESTRICTIONS
|
||||
* none
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
#include "ipcmsg.h"
|
||||
|
||||
char *TCID = "msgctl02";
|
||||
int TST_TOTAL = 1;
|
||||
extern int Tst_count;
|
||||
|
||||
int msg_q_1 = -1; /* to hold the message queue id */
|
||||
|
||||
struct msqid_ds qs_buf;
|
||||
|
||||
unsigned short new_bytes;
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int lc; /* loop counter */
|
||||
char *msg; /* message returned from parse_opts */
|
||||
|
||||
/* 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;
|
||||
|
||||
/*
|
||||
* Set the msqid_ds structure values for the queue
|
||||
*/
|
||||
|
||||
TEST(msgctl(msg_q_1, IPC_SET, &qs_buf));
|
||||
|
||||
if (TEST_RETURN == -1) {
|
||||
tst_resm(TFAIL, "%s call failed - errno = %d"
|
||||
" : %s", TCID, TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
} else {
|
||||
if (STD_FUNCTIONAL_TEST) {
|
||||
|
||||
/* do a stat to get current queue values */
|
||||
if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)){
|
||||
tst_resm(TBROK, "stat on queue failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (qs_buf.msg_qbytes == new_bytes) {
|
||||
tst_resm(TPASS, "qs_buf.msg_qbytes is"
|
||||
" the new value - %d",
|
||||
qs_buf.msg_qbytes);
|
||||
} else {
|
||||
tst_resm(TFAIL, "qs_buf.msg_qbytes "
|
||||
"value is not expected");
|
||||
tst_resm(TINFO, "expected - %d, "
|
||||
"received - %d", new_bytes,
|
||||
qs_buf.msg_qbytes);
|
||||
}
|
||||
} else {
|
||||
tst_resm(TPASS, "msgctl() call succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* decrement by one the msq_qbytes value
|
||||
*/
|
||||
qs_buf.msg_qbytes -= 1;
|
||||
new_bytes = qs_buf.msg_qbytes;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* 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 a message key */
|
||||
msgkey = getipckey();
|
||||
|
||||
/* make sure the initial # of bytes is 0 in our buffer */
|
||||
qs_buf.msg_qbytes = 0x3000;
|
||||
|
||||
/* now we have a key, so let's create a message queue */
|
||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
||||
}
|
||||
|
||||
/* now stat the queue to get the default msg_qbytes value */
|
||||
if ((msgctl(msg_q_1, IPC_STAT, &qs_buf)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "Can't stat the message queue");
|
||||
}
|
||||
|
||||
/* decrement msg_qbytes and copy its value */
|
||||
qs_buf.msg_qbytes -= 1;
|
||||
new_bytes = qs_buf.msg_qbytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if it exists, remove the message queue */
|
||||
rm_queue(msg_q_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();
|
||||
}
|
||||
|
||||
169
test/ipc/msgctl/msgctl03.c
Normal file
169
test/ipc/msgctl/msgctl03.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
*
|
||||
* 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
|
||||
* msgctl03.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* msgctl03 - create a message queue, then issue the IPC_RMID command
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a message queue
|
||||
* loop if that option was specified
|
||||
* call msgctl() with the IPC_RMID command
|
||||
* check the return code
|
||||
* if failure, issue a FAIL message and break remaining tests
|
||||
* otherwise,
|
||||
* if doing functionality testing
|
||||
* issue an IPC_STAT on the queue that was just removed
|
||||
* if the call fails
|
||||
* issue a PASS message
|
||||
* otherwise
|
||||
* issue a FAIL message
|
||||
* else issue a PASS message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* msgctl03 [-c n] [-f] [-I x] [-P x] [-t]
|
||||
* where, -c n : Run n copies concurrently.
|
||||
* -f : Turn off functionality Testing.
|
||||
* -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
|
||||
* This test does not support looping.
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
#include "ipcmsg.h"
|
||||
|
||||
char *TCID = "msgctl03";
|
||||
int TST_TOTAL = 1;
|
||||
extern int Tst_count;
|
||||
|
||||
int msg_q_1 = -1; /* to hold the message queue id */
|
||||
|
||||
struct msqid_ds qs_buf;
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
char *msg; /* message returned from parse_opts */
|
||||
|
||||
/* 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 */
|
||||
|
||||
/*
|
||||
* Remove the queue that was created in setup()
|
||||
*/
|
||||
|
||||
TEST(msgctl(msg_q_1, IPC_RMID, NULL));
|
||||
|
||||
if (TEST_RETURN == -1) {
|
||||
tst_brkm(TFAIL, cleanup, "%s call failed - errno = %d"
|
||||
" : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO));
|
||||
} else {
|
||||
if (STD_FUNCTIONAL_TEST) {
|
||||
/*
|
||||
* if the queue is gone, then an IPC_STAT msgctl()
|
||||
* call should generate an EINVAL error.
|
||||
*/
|
||||
if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)){
|
||||
if (errno == EINVAL) {
|
||||
tst_resm(TPASS, "The queue is gone");
|
||||
} else {
|
||||
tst_resm(TFAIL, "IPC_RMID succeeded ,"
|
||||
" but functional test did not"
|
||||
" get expected EINVAL error");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tst_resm(TPASS, "msgctl() call succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
msg_q_1 = -1;
|
||||
|
||||
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);
|
||||
|
||||
/* 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 a message key */
|
||||
msgkey = getipckey();
|
||||
|
||||
/* now we have a key, so let's create a message queue */
|
||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/* if it exists, remove the message queue */
|
||||
rm_queue(msg_q_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();
|
||||
}
|
||||
|
||||
229
test/ipc/msgctl/msgctl04.c
Normal file
229
test/ipc/msgctl/msgctl04.c
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
*
|
||||
* 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
|
||||
* msgctl04.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* msgctl04 - test for EACCES, EFAULT and EINVAL errors using
|
||||
* a variety of incorrect calls.
|
||||
*
|
||||
* ALGORITHM
|
||||
* create two message queues
|
||||
* loop if that option was specified
|
||||
* try to access a queue with some invalid argument
|
||||
* check the errno value
|
||||
* issue a PASS message if we get EACCES, EFAULT or EINVAL
|
||||
* depending on the test case
|
||||
* otherwise, the tests fails
|
||||
* issue a FAIL message
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* msgctl04 [-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 "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
#include "ipcmsg.h"
|
||||
|
||||
char *TCID = "msgctl04";
|
||||
int TST_TOTAL = 6;
|
||||
extern int Tst_count;
|
||||
|
||||
char nobody_uid[] = "nobody";
|
||||
struct passwd *ltpuser;
|
||||
|
||||
int exp_enos[] = {EACCES, EFAULT, EINVAL, 0};
|
||||
|
||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
||||
int msg_q_2 = -1; /* Another queue id created in setup */
|
||||
int bad_q = -1; /* a value to use as a bad queue id */
|
||||
|
||||
struct msqid_ds q_buf;
|
||||
|
||||
struct test_case_t { /* This allows testing of many negative */
|
||||
int *queue_id; /* test cases that can all use the same */
|
||||
int ipc_cmd; /* basic test setup. */
|
||||
struct msqid_ds *buf;
|
||||
int error;
|
||||
} TC[] = {
|
||||
/* EACCES - there is no read permission for the queue */
|
||||
{&msg_q_1, IPC_STAT, &q_buf, EACCES},
|
||||
|
||||
/* EFAULT - the structure address is invalid - IPC_STAT */
|
||||
{&msg_q_2, IPC_STAT, (struct msqid_ds *)-1, EFAULT},
|
||||
|
||||
/* EFAULT - the structure address is invalid - IPC_SET */
|
||||
{&msg_q_2, IPC_SET, (struct msqid_ds *)-1, EFAULT},
|
||||
|
||||
/* EINVAL - the command (-1) is invalid */
|
||||
{&msg_q_2, -1, &q_buf, EINVAL},
|
||||
|
||||
/* EINVAL - the queue id is invalid - IPC_STAT */
|
||||
{&bad_q, IPC_STAT, &q_buf, EINVAL},
|
||||
|
||||
/* EINVAL - the queue id is invalid - IPC_SET */
|
||||
{&bad_q, IPC_SET, &q_buf, 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;
|
||||
|
||||
/* loop through the test cases */
|
||||
|
||||
for (i=0; i<TST_TOTAL; i++) {
|
||||
|
||||
TEST(msgctl(*(TC[i].queue_id), TC[i].ipc_cmd,
|
||||
TC[i].buf));
|
||||
|
||||
if (TEST_RETURN != -1) {
|
||||
tst_resm(TFAIL, "msgctl() call succeeded "
|
||||
"on expected fail");
|
||||
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));
|
||||
tst_resm(TINFO, "expected error is - %d : %s",
|
||||
TC[i].error, strerror(TC[i].error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* Switch to nobody user for correct error code collection */
|
||||
if (geteuid() != 0) {
|
||||
tst_brkm(TBROK, tst_exit, "Test must be run as root");
|
||||
}
|
||||
ltpuser = getpwnam(nobody_uid);
|
||||
if (setuid(ltpuser->pw_uid) == -1) {
|
||||
tst_resm(TINFO, "setuid failed to "
|
||||
"to set the effective uid to %d",
|
||||
ltpuser->pw_uid);
|
||||
perror("setuid");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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();
|
||||
|
||||
msgkey = getipckey();
|
||||
|
||||
/* now we have a key, so let's create a message queue */
|
||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "Can't create message queue #1" );
|
||||
}
|
||||
|
||||
/* now let's create another message queue with read & write access */
|
||||
if ((msg_q_2 =
|
||||
msgget(msgkey + 1, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "Can't create message queue #2" );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/*
|
||||
* remove the message queues that were created.
|
||||
*/
|
||||
rm_queue(msg_q_1);
|
||||
|
||||
rm_queue(msg_q_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();
|
||||
}
|
||||
|
||||
217
test/ipc/msgctl/msgctl05.c
Normal file
217
test/ipc/msgctl/msgctl05.c
Normal file
@@ -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
|
||||
* msgctl05.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* msgctl05 - test for EPERM error
|
||||
*
|
||||
* ALGORITHM
|
||||
* create a message queue as root
|
||||
* fork a child process and change its ID to nobody
|
||||
* loop if that option was specified
|
||||
* try to remove the queue in the child process with msgctl()
|
||||
* check the errno value
|
||||
* issue a PASS message if we get EPERM
|
||||
* otherwise, the tests fails
|
||||
* issue a FAIL message
|
||||
* break any remaining tests
|
||||
* call cleanup
|
||||
*
|
||||
* USAGE: <for command-line>
|
||||
* msgctl05 [-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
|
||||
* The test must be run as root.
|
||||
* There must be a nobody ID installed on the system.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
|
||||
#include "ipcmsg.h"
|
||||
|
||||
char *TCID = "msgctl05";
|
||||
int TST_TOTAL = 1;
|
||||
extern int Tst_count;
|
||||
|
||||
int exp_enos[] = {EPERM, 0}; /* 0 terminated list of expected errnos */
|
||||
|
||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
||||
uid_t ltp_uid; /* The user ID for a non root user */
|
||||
char *ltp_user = "nobody"; /* A non root user */
|
||||
|
||||
struct msqid_ds q_buf;
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
char *msg; /* message returned from parse_opts */
|
||||
pid_t pid;
|
||||
void do_child(void);
|
||||
|
||||
/* 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 */
|
||||
|
||||
if ((pid = FORK_OR_VFORK()) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "could not fork");
|
||||
}
|
||||
|
||||
if (pid == 0) { /* child */
|
||||
/* set the user ID of the child to nobody */
|
||||
if (setuid(ltp_uid) == -1) {
|
||||
tst_resm(TBROK, "setuid() failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
do_child();
|
||||
} else { /* parent */
|
||||
if (waitpid(pid, NULL, 0) == -1) {
|
||||
tst_resm(TBROK, "waitpid() failed");
|
||||
tst_resm(TINFO, "waitpid() error = %d : %s", errno,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
/* if it exists, remove the message queue */
|
||||
rm_queue(msg_q_1);
|
||||
|
||||
/* Remove the temporary directory */
|
||||
tst_rmdir();
|
||||
}
|
||||
|
||||
cleanup ();
|
||||
/**NOT REACHED**/
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* do_child - make the TEST call as the child process
|
||||
*/
|
||||
void
|
||||
do_child()
|
||||
{
|
||||
int lc; /* loop counter */
|
||||
int i;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* loop through the test cases */
|
||||
|
||||
for (i=0; i<TST_TOTAL; i++) {
|
||||
TEST(msgctl(msg_q_1, IPC_RMID, NULL));
|
||||
|
||||
if (TEST_RETURN != -1) {
|
||||
tst_resm(TFAIL, "msgget() call succeeded "
|
||||
"on expected fail");
|
||||
continue;
|
||||
}
|
||||
|
||||
TEST_ERROR_LOG(TEST_ERRNO);
|
||||
|
||||
switch(TEST_ERRNO) {
|
||||
case EPERM:
|
||||
tst_resm(TPASS, "expected error = %d : %s",
|
||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
||||
break;
|
||||
default:
|
||||
tst_resm(TFAIL, "call failed with unexpected "
|
||||
"error - %d : %s", TEST_ERRNO,
|
||||
strerror(TEST_ERRNO));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* setup() - performs all the ONE TIME setup for this test.
|
||||
*/
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
/* check for root as user id of process */
|
||||
check_root();
|
||||
|
||||
/* capture signals */
|
||||
tst_sig(FORK, 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();
|
||||
|
||||
msgkey = getipckey();
|
||||
|
||||
/* now we have a key, so let's create a message queue */
|
||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
||||
tst_brkm(TBROK, cleanup, "Can't create message queue #1" );
|
||||
}
|
||||
|
||||
/* get the user ID for a non root user */
|
||||
ltp_uid = getuserid(ltp_user);
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
||||
* or premature exit.
|
||||
*/
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
197
test/ipc/msgctl/msgctl06.c
Normal file
197
test/ipc/msgctl/msgctl06.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2002
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
|
||||
/* 11/06/2002 Port to LTP dbarrera@us.ibm.com */
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* msgctl06
|
||||
*
|
||||
* CALLS
|
||||
* msgget(2) msgctl(2)
|
||||
*
|
||||
* ALGORITHM
|
||||
* Get and manipulate a message queue.
|
||||
*
|
||||
* RESTRICTIONS
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <sys/types.h> /* needed for test */
|
||||
#include <sys/ipc.h> /* needed for test */
|
||||
#include <sys/msg.h> /* needed for test */
|
||||
#include <stdio.h> /* needed by testhead.h */
|
||||
#include <errno.h> /* definitions needed for errno */
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
void setup();
|
||||
void cleanup();
|
||||
/*
|
||||
* * * These globals must be defined in the test.
|
||||
* * */
|
||||
|
||||
|
||||
char *TCID="msgctl06"; /* Test program identifier. */
|
||||
int TST_TOTAL=1; /* Total number of test cases. */
|
||||
extern int Tst_count; /* Test Case counter for tst_* routines */
|
||||
|
||||
int exp_enos[]={0}; /* List must end with 0 */
|
||||
|
||||
|
||||
/*
|
||||
* msgctl3_t -- union of msgctl(2)'s possible argument # 3 types.
|
||||
*/
|
||||
typedef union msgctl3_u {
|
||||
struct msqid_ds *msq_ds; /* pointer to msqid_ds struct */
|
||||
struct ipc_acl *msq_acl; /* pointer ACL buff and size */
|
||||
} msgctl3_t;
|
||||
|
||||
extern int local_flag;
|
||||
|
||||
int msqid, status;
|
||||
struct msqid_ds buf;
|
||||
|
||||
|
||||
#define K 1024
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
key_t key;
|
||||
setup();
|
||||
|
||||
key = 2 * K;
|
||||
TEST(msgget(key, IPC_CREAT));
|
||||
msqid = TEST_RETURN;
|
||||
if (TEST_RETURN == -1)
|
||||
{
|
||||
tst_resm(TFAIL, "msgget() failed errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
TEST(msgctl(msqid, IPC_STAT, &buf));
|
||||
status = TEST_RETURN;
|
||||
if (TEST_RETURN == -1)
|
||||
{
|
||||
(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgctl(msqid, IPC_STAT, &buf) failed errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
/*
|
||||
* Check contents of msqid_ds structure.
|
||||
*/
|
||||
|
||||
if (buf.msg_qnum != 0)
|
||||
{
|
||||
tst_resm(TFAIL, "error: unexpected nbr of messages %d", buf.msg_qnum);
|
||||
tst_exit();
|
||||
}
|
||||
if (buf.msg_perm.uid != getuid())
|
||||
{
|
||||
tst_resm(TFAIL, "error: unexpected uid %d", buf.msg_perm.uid);
|
||||
tst_exit();
|
||||
}
|
||||
if (buf.msg_perm.gid != getgid())
|
||||
{
|
||||
tst_resm(TFAIL, "error: unexpected gid %d", buf.msg_perm.gid);
|
||||
tst_exit();
|
||||
}
|
||||
if (buf.msg_perm.cuid != getuid())
|
||||
{
|
||||
tst_resm(TFAIL, "error: unexpected cuid %d", buf.msg_perm.cuid);
|
||||
tst_exit();
|
||||
}
|
||||
if (buf.msg_perm.cgid != getgid())
|
||||
{
|
||||
tst_resm(TFAIL, "error: unexpected cgid %d", buf.msg_perm.cgid);
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
|
||||
tst_resm(TPASS,"msgctl06 ran successfully!");
|
||||
/***************************************************************
|
||||
* cleanup and exit
|
||||
***************************************************************/
|
||||
cleanup();
|
||||
|
||||
return 0;
|
||||
} /* End main */
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* * setup() - performs all ONE TIME setup for this test.
|
||||
* ****************************************************************/
|
||||
void
|
||||
setup()
|
||||
{
|
||||
/* You will want to enable some signal handling so you can capture
|
||||
* unexpected signals like SIGSEGV.
|
||||
*/
|
||||
tst_sig(NOFORK, DEF_HANDLER, cleanup);
|
||||
|
||||
/* Pause if that option was specified */
|
||||
/* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
|
||||
* fork the test with the -c option. You want to make sure you do this
|
||||
* before you create your temporary directory.
|
||||
*/
|
||||
TEST_PAUSE;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* * * cleanup() - performs all ONE TIME cleanup for this test at
|
||||
* * * completion or premature exit.
|
||||
* * ***************************************************************/
|
||||
void
|
||||
cleanup()
|
||||
{
|
||||
int status;
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
|
||||
/*
|
||||
* Remove the message queue from the system
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
tst_resm(TINFO,"Remove the message queue");
|
||||
#endif
|
||||
fflush (stdout);
|
||||
(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
if ((status = msgctl(msqid, IPC_STAT, &buf)) != -1)
|
||||
{
|
||||
(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgctl(msqid, IPC_RMID) failed");
|
||||
tst_exit();
|
||||
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
/* exit with return code appropriate for results */
|
||||
tst_exit();
|
||||
}
|
||||
371
test/ipc/msgctl/msgctl07.c
Normal file
371
test/ipc/msgctl/msgctl07.c
Normal file
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2002
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
|
||||
/* 11/06/2002 Port to LTP dbarrera@us.ibm.com */
|
||||
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* msgctl07
|
||||
*
|
||||
* CALLS
|
||||
* msgget(2) msgctl(2) msgop(2)
|
||||
*
|
||||
* ALGORITHM
|
||||
* Get and manipulate a message queue.
|
||||
*
|
||||
* RESTRICTIONS
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h> /* needed for test */
|
||||
#include <sys/ipc.h> /* needed for test */
|
||||
#include <sys/msg.h> /* needed for test */
|
||||
#include <signal.h> /* needed for test */
|
||||
#include <wait.h> /* needed for test */
|
||||
#include <stdio.h> /* needed by testhead.h */
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
typedef void (*sighandler_t)(int);
|
||||
volatile int ready;
|
||||
|
||||
#define K 1024
|
||||
#define BYTES 100
|
||||
#define SECS 10
|
||||
|
||||
void setup();
|
||||
void cleanup();
|
||||
void do_child_1();
|
||||
void do_child_2();
|
||||
|
||||
/*
|
||||
* * * * These globals must be defined in the test.
|
||||
* * * */
|
||||
|
||||
char *TCID="msgctl07"; /* Test program identifier. */
|
||||
int TST_TOTAL=1; /* Total number of test cases. */
|
||||
extern int Tst_count; /* Test Case counter for tst_* routines */
|
||||
|
||||
/* Used by main() and do_child_1(): */
|
||||
static int msqid;
|
||||
struct my_msgbuf {
|
||||
long type;
|
||||
char text[BYTES];
|
||||
} p1_msgp, p2_msgp, p3_msgp, c1_msgp, c2_msgp, c3_msgp;
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
key_t key;
|
||||
int pid, status;
|
||||
int i, j, k;
|
||||
sighandler_t alrm();
|
||||
|
||||
#ifdef UCLINUX
|
||||
char *msg;
|
||||
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(argc, argv, (option_t *)NULL, NULL)) !=
|
||||
(char *)NULL){
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
maybe_run_child(&do_child_1, "ndd", 1, &msqid, &c1_msgp.type);
|
||||
maybe_run_child(&do_child_2, "ndddd", 2, &msqid, &c1_msgp.type,
|
||||
&c2_msgp.type, &c3_msgp.type);
|
||||
#endif
|
||||
|
||||
key = 2 * K;
|
||||
if ((msqid = msgget(key, IPC_CREAT)) == -1)
|
||||
{
|
||||
tst_resm(TFAIL, "msgget() failed errno = %d", errno);
|
||||
tst_exit();
|
||||
|
||||
}
|
||||
|
||||
pid = FORK_OR_VFORK();
|
||||
if (pid < 0) {
|
||||
(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "\tFork failed (may be OK if under stress)");
|
||||
tst_exit();
|
||||
}
|
||||
else if (pid == 0) {
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(argv[0], "ndd", 1, msqid, c1_msgp.type) < 0) {
|
||||
tst_resm(TFAIL, "\tself_exec failed");
|
||||
tst_exit();
|
||||
}
|
||||
#else
|
||||
do_child_1();
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
struct sigaction act;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = (sighandler_t) alrm;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGALRM);
|
||||
if ((sigaction(SIGALRM, &act, NULL)) < 0) {
|
||||
kill(pid, SIGKILL);
|
||||
(void)msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "signal failed. errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
ready = 0;
|
||||
alarm(SECS);
|
||||
while (!ready) /* make the child wait */
|
||||
;
|
||||
for (i=0; i<BYTES; i++)
|
||||
p1_msgp.text[i] = 'i';
|
||||
p1_msgp.type = 1;
|
||||
if (msgsnd(msqid, &p1_msgp, BYTES, 0) == -1) {
|
||||
kill(pid, SIGKILL);
|
||||
(void)msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgsnd() failed. errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
wait(&status);
|
||||
}
|
||||
if ((status >> 8) == 1)
|
||||
{
|
||||
tst_resm(TFAIL, "test failed. status = %d", (status >> 8));
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
pid = FORK_OR_VFORK();
|
||||
if (pid < 0) {
|
||||
(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "\tFork failed (may be OK if under stress)");
|
||||
tst_exit();
|
||||
}
|
||||
else if (pid == 0) {
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(argv[0], "ndddd", 1, msqid, c1_msgp.type,
|
||||
c2_msgp.type, c3_msgp.type) < 0) {
|
||||
tst_resm(TFAIL, "\tself_exec failed");
|
||||
tst_exit();
|
||||
}
|
||||
#else
|
||||
do_child_2();
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
struct sigaction act;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = (sighandler_t) alrm;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGALRM);
|
||||
if ((sigaction(SIGALRM, &act, NULL)) < 0) {
|
||||
kill(pid, SIGKILL);
|
||||
(void)msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "signal failed. errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
ready = 0;
|
||||
alarm(SECS);
|
||||
while (!ready) /* make the child wait */
|
||||
;
|
||||
for (i=0; i<BYTES; i++)
|
||||
p1_msgp.text[i] = 'i';
|
||||
p1_msgp.type = 1;
|
||||
if (msgsnd(msqid, &p1_msgp, BYTES, 0) == -1) {
|
||||
kill(pid, SIGKILL);
|
||||
(void)msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgsnd() failed. errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
for (j=0; j<BYTES; j++)
|
||||
p2_msgp.text[j] = 'j';
|
||||
p2_msgp.type = 2;
|
||||
if (msgsnd(msqid, &p2_msgp, BYTES, 0) == -1) {
|
||||
kill(pid, SIGKILL);
|
||||
(void)msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgsnd() failed. errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
for (k=0; k<BYTES; k++)
|
||||
p3_msgp.text[k] = 'k';
|
||||
p3_msgp.type = 3;
|
||||
if (msgsnd(msqid, &p3_msgp, BYTES, 0) == -1) {
|
||||
kill(pid, SIGKILL);
|
||||
(void)msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgsnd() failed. errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
wait(&status);
|
||||
}
|
||||
if ((status >> 8) == 1)
|
||||
{
|
||||
tst_resm(TFAIL, "test failed. status = %d", (status >> 8));
|
||||
tst_exit();
|
||||
}
|
||||
/*
|
||||
* Remove the message queue from the system
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
tst_resm(TINFO,"Removing the message queue");
|
||||
#endif
|
||||
fflush (stdout);
|
||||
(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
if ((status = msgctl(msqid, IPC_STAT, (struct msqid_ds *)NULL)) != -1)
|
||||
{
|
||||
(void) msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgctl(msqid, IPC_RMID) failed");
|
||||
tst_exit();
|
||||
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
tst_resm(TPASS,"msgctl07 ran successfully!");
|
||||
return (0);
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
sighandler_t alrm(sig)
|
||||
int sig;
|
||||
{
|
||||
ready++;
|
||||
return(0);
|
||||
}
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
do_child_1()
|
||||
{
|
||||
int i;
|
||||
int size;
|
||||
|
||||
if ((size = msgrcv(msqid, &c1_msgp, BYTES, 0, 0)) == -1)
|
||||
{
|
||||
tst_resm(TFAIL, "msgrcv() failed errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (size != BYTES)
|
||||
{
|
||||
tst_resm(TFAIL, "error: received %d bytes expected %d", size, BYTES);
|
||||
tst_exit();
|
||||
}
|
||||
for (i=0; i<BYTES; i++)
|
||||
if (c1_msgp.text[i] != 'i')
|
||||
{
|
||||
tst_resm(TFAIL, "error: corrup message");
|
||||
tst_exit();
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
do_child_2()
|
||||
{
|
||||
int i, j, k;
|
||||
int size;
|
||||
|
||||
if ((size = msgrcv(msqid, &c3_msgp, BYTES, 3, 0)) == -1) {
|
||||
tst_resm(TFAIL, "msgrcv() failed errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (size != BYTES) {
|
||||
tst_resm(TFAIL, "error: received %d bytes expected %d", size, BYTES);
|
||||
tst_exit();
|
||||
}
|
||||
for (k=0; k<BYTES; k++)
|
||||
if (c3_msgp.text[k] != 'k') {
|
||||
tst_resm(TFAIL, "error: corrupt message");
|
||||
tst_exit();
|
||||
}
|
||||
if ((size = msgrcv(msqid, &c2_msgp, BYTES, 2, 0)) == -1) {
|
||||
tst_resm(TFAIL, "msgrcv() failed errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (size != BYTES) {
|
||||
tst_resm(TFAIL, "error: received %d bytes expected %d", size, BYTES);
|
||||
tst_exit();
|
||||
}
|
||||
for (j=0; j<BYTES; j++)
|
||||
if (c2_msgp.text[j] != 'j') {
|
||||
tst_resm(TFAIL, "error: corrupt message");
|
||||
tst_exit();
|
||||
}
|
||||
if ((size = msgrcv(msqid, &c1_msgp, BYTES, 1, 0)) == -1) {
|
||||
tst_resm(TFAIL, "msgrcv() failed errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (size != BYTES) {
|
||||
tst_resm(TFAIL, "error: received %d bytes expected %d", size, BYTES);
|
||||
tst_exit();
|
||||
}
|
||||
for (i=0; i<BYTES; i++)
|
||||
if (c1_msgp.text[i] != 'i') {
|
||||
tst_resm(TFAIL, "error: corrupt message");
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* setup() - performs all ONE TIME setup for this test.
|
||||
****************************************************************/
|
||||
void
|
||||
setup()
|
||||
{
|
||||
/* You will want to enable some signal handling so you can capture
|
||||
* unexpected signals like SIGSEGV.
|
||||
*/
|
||||
tst_sig(FORK, DEF_HANDLER, cleanup);
|
||||
|
||||
/* Pause if that option was specified */
|
||||
/* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
|
||||
* fork the test with the -c option. You want to make sure you do this
|
||||
* before you create your temporary directory.
|
||||
*/
|
||||
TEST_PAUSE;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* * cleanup() - performs all ONE TIME cleanup for this test at
|
||||
* * completion or premature exit.
|
||||
* ***************************************************************/
|
||||
void
|
||||
cleanup()
|
||||
{
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
564
test/ipc/msgctl/msgctl08.c
Normal file
564
test/ipc/msgctl/msgctl08.c
Normal file
@@ -0,0 +1,564 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2002
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
|
||||
/* 11/06/2002 Port to LTP dbarrera@us.ibm.com */
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* msgctl08
|
||||
*
|
||||
* CALLS
|
||||
* msgget(2) msgctl(2)
|
||||
*
|
||||
* ALGORITHM
|
||||
* Get and manipulate a message queue.
|
||||
*
|
||||
* RESTRICTIONS
|
||||
*
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <values.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
void setup();
|
||||
void cleanup();
|
||||
/*
|
||||
* * * * These globals must be defined in the test.
|
||||
* * * */
|
||||
|
||||
|
||||
char *TCID="msgctl08"; /* Test program identifier. */
|
||||
int TST_TOTAL=1; /* Total number of test cases. */
|
||||
extern int Tst_count; /* Test Case counter for tst_* routines */
|
||||
|
||||
int exp_enos[]={0}; /* List must end with 0 */
|
||||
|
||||
#ifndef CONFIG_COLDFIRE
|
||||
#define MAXNPROCS 1000000 /* This value is set to an arbitrary high limit. */
|
||||
#else
|
||||
#define MAXNPROCS 100000 /* Coldfire can't deal with 1000000 */
|
||||
#endif
|
||||
#define MAXNREPS 100000
|
||||
#define FAIL 1
|
||||
#define PASS 0
|
||||
|
||||
key_t keyarray[MAXNPROCS];
|
||||
|
||||
struct {
|
||||
long type;
|
||||
struct {
|
||||
char len;
|
||||
char pbytes[99];
|
||||
} data;
|
||||
} buffer;
|
||||
|
||||
int pidarray[MAXNPROCS];
|
||||
int tid;
|
||||
int MSGMNI,nprocs, nreps;
|
||||
int procstat;
|
||||
int dotest(key_t key, int child_process);
|
||||
int doreader(int id, long key, int child);
|
||||
int dowriter(int id,long key, int child);
|
||||
int fill_buffer(register char *buf, char val, register int size);
|
||||
int verify(register char *buf,char val, register int size,int child);
|
||||
void sig_handler(); /* signal catching function */
|
||||
int mykid;
|
||||
#ifdef UCLINUX
|
||||
static char *argv0;
|
||||
|
||||
void do_child_1_uclinux();
|
||||
static key_t key_uclinux;
|
||||
static int i_uclinux;
|
||||
|
||||
void do_child_2_uclinux();
|
||||
static int id_uclinux;
|
||||
static int child_process_uclinux;
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int i, j, ok, pid;
|
||||
int count, status;
|
||||
struct sigaction act;
|
||||
|
||||
#ifdef UCLINUX
|
||||
char *msg; /* message returned from parse_opts */
|
||||
|
||||
argv0 = argv[0];
|
||||
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(argc, argv, (option_t *)NULL, NULL)) != (char *)NULL)
|
||||
{
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
maybe_run_child(&do_child_1_uclinux, "ndd", 1, &key_uclinux, &i_uclinux);
|
||||
maybe_run_child(&do_child_2_uclinux, "nddd", 2, &id_uclinux, &key_uclinux,
|
||||
&child_process_uclinux);
|
||||
#endif
|
||||
|
||||
setup();
|
||||
|
||||
if (argc == 1 )
|
||||
{
|
||||
/* Set default parameters */
|
||||
nreps = MAXNREPS;
|
||||
nprocs = MSGMNI;
|
||||
}
|
||||
else if (argc == 3 )
|
||||
{
|
||||
if ( atoi(argv[1]) > MAXNREPS )
|
||||
{
|
||||
tst_resm(TCONF,"Requested number of iterations too large, setting to Max. of %d", MAXNREPS);
|
||||
nreps = MAXNREPS;
|
||||
}
|
||||
else
|
||||
{
|
||||
nreps = atoi(argv[1]);
|
||||
}
|
||||
if (atoi(argv[2]) > MSGMNI )
|
||||
{
|
||||
tst_resm(TCONF,"Requested number of processes too large, setting to Max. of %d", MSGMNI);
|
||||
nprocs = MSGMNI;
|
||||
}
|
||||
else
|
||||
{
|
||||
nprocs = atoi(argv[2]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tst_resm(TCONF," Usage: %s [ number of iterations number of processes ]", argv[0]);
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
srand(getpid());
|
||||
tid = -1;
|
||||
|
||||
/* Setup signal handleing routine */
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = sig_handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGTERM);
|
||||
if (sigaction(SIGTERM, &act, NULL) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Sigset SIGTERM failed");
|
||||
tst_exit();
|
||||
}
|
||||
/* Set up array of unique keys for use in allocating message
|
||||
* queues
|
||||
*/
|
||||
for (i = 0; i < nprocs; i++)
|
||||
{
|
||||
ok = 1;
|
||||
do
|
||||
{
|
||||
/* Get random key */
|
||||
keyarray[i] = (key_t)rand();
|
||||
/* Make sure key is unique and not private */
|
||||
if (keyarray[i] == IPC_PRIVATE)
|
||||
{
|
||||
ok = 0;
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
if (keyarray[j] == keyarray[i])
|
||||
{
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
ok = 1;
|
||||
}
|
||||
} while (ok == 0);
|
||||
}
|
||||
|
||||
/* Fork a number of processes, each of which will
|
||||
* create a message queue with one reader/writer
|
||||
* pair which will read and write a number (iterations)
|
||||
* of random length messages with specific values.
|
||||
*/
|
||||
|
||||
for (i = 0; i < nprocs; i++)
|
||||
{
|
||||
fflush(stdout);
|
||||
if ((pid = FORK_OR_VFORK()) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "\tFork failed (may be OK if under stress)");
|
||||
tst_exit();
|
||||
}
|
||||
/* Child does this */
|
||||
if (pid == 0)
|
||||
{
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(argv[0], "ndd", 1, keyarray[i], i) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "\tself_exec failed");
|
||||
tst_exit();
|
||||
}
|
||||
#else
|
||||
procstat = 1;
|
||||
exit( dotest(keyarray[i], i) );
|
||||
#endif
|
||||
}
|
||||
pidarray[i] = pid;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
while(1)
|
||||
{
|
||||
if (( wait(&status)) > 0)
|
||||
{
|
||||
if (status>>8 != 0 )
|
||||
{
|
||||
tst_resm(TFAIL, "Child exit status = %d", status>>8);
|
||||
tst_exit();
|
||||
}
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (errno != EINTR)
|
||||
{
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
tst_resm(TINFO,"Signal detected during wait");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* Make sure proper number of children exited */
|
||||
if (count != nprocs)
|
||||
{
|
||||
tst_resm(TFAIL, "Wrong number of children exited, Saw %d, Expected %d", count, nprocs);
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
tst_resm(TPASS,"msgctl08 ran successfully!");
|
||||
|
||||
cleanup();
|
||||
return (0);
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
|
||||
#ifdef UCLINUX
|
||||
void
|
||||
do_child_1_uclinux()
|
||||
{
|
||||
procstat = 1;
|
||||
exit(dotest(key_uclinux, i_uclinux));
|
||||
}
|
||||
|
||||
void
|
||||
do_child_2_uclinux()
|
||||
{
|
||||
exit(doreader(id_uclinux, key_uclinux % 255, child_process_uclinux));
|
||||
}
|
||||
#endif
|
||||
|
||||
int dotest(key, child_process)
|
||||
key_t key;
|
||||
int child_process;
|
||||
{
|
||||
int id, pid;
|
||||
|
||||
sighold(SIGTERM);
|
||||
TEST(msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR));
|
||||
if (TEST_RETURN < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgget error in child %d, errno = %d", child_process, TEST_ERRNO);
|
||||
tst_exit();
|
||||
}
|
||||
tid = id = TEST_RETURN;
|
||||
sigrelse(SIGTERM);
|
||||
|
||||
fflush(stdout);
|
||||
if ((pid = FORK_OR_VFORK()) < 0)
|
||||
{
|
||||
tst_resm(TWARN, "\tFork failed (may be OK if under stress)");
|
||||
TEST(msgctl(tid, IPC_RMID, 0));
|
||||
if (TEST_RETURN < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgctl error in cleanup, errno = %d", errno);
|
||||
}
|
||||
tst_exit();
|
||||
}
|
||||
/* Child does this */
|
||||
if (pid == 0)
|
||||
{
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(argv0, "nddd", 2, id, key, child_process) < 0) {
|
||||
tst_resm(TWARN, "self_exec failed");
|
||||
TEST(msgctl(tid, IPC_RMID, 0));
|
||||
if (TEST_RETURN < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "\tMsgctl error in cleanup, "
|
||||
"errno = %d\n", errno);
|
||||
}
|
||||
tst_exit();
|
||||
}
|
||||
#else
|
||||
exit( doreader(id, key % 255, child_process) );
|
||||
#endif
|
||||
}
|
||||
/* Parent does this */
|
||||
mykid = pid;
|
||||
procstat = 2;
|
||||
dowriter(id, key % 255, child_process);
|
||||
wait(0);
|
||||
TEST(msgctl(id, IPC_RMID, 0));
|
||||
if (TEST_RETURN < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "msgctl errno %d", TEST_ERRNO);
|
||||
tst_exit();
|
||||
}
|
||||
exit(PASS);
|
||||
}
|
||||
|
||||
int doreader(id, key, child)
|
||||
int id, child;
|
||||
long key;
|
||||
{
|
||||
int i, size;
|
||||
|
||||
for (i = 0; i < nreps; i++)
|
||||
{
|
||||
if ((size = msgrcv(id, &buffer, 100, 0, 0)) < 0)
|
||||
{
|
||||
tst_brkm(TBROK, cleanup, "Msgrcv error in child %d, read # = %d, errno = %d", (i + 1), child, errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (buffer.data.len + 1 != size)
|
||||
{
|
||||
tst_resm(TFAIL, "Size mismatch in child %d, read # = %d", child, (i + 1));
|
||||
tst_resm(TFAIL, "for message size got %d expected %d %s",size ,buffer.data.len);
|
||||
tst_exit();
|
||||
}
|
||||
if ( verify(buffer.data.pbytes, key, size - 1, child) )
|
||||
{
|
||||
tst_resm(TFAIL, "in read # = %d,key = %x", (i + 1), child, key);
|
||||
tst_exit();
|
||||
}
|
||||
key++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int dowriter(id, key, child)
|
||||
int id,child;
|
||||
long key;
|
||||
{
|
||||
int i, size;
|
||||
|
||||
for (i = 0; i < nreps; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
size = (rand() % 99);
|
||||
} while (size == 0);
|
||||
fill_buffer(buffer.data.pbytes, key, size);
|
||||
buffer.data.len = size;
|
||||
buffer.type = 1;
|
||||
TEST(msgsnd(id, &buffer, size + 1, 0));
|
||||
if (TEST_RETURN < 0)
|
||||
{
|
||||
tst_brkm(TBROK, cleanup, "Msgsnd error in child %d, key = %x errno = %d", child, key, TEST_ERRNO);
|
||||
}
|
||||
key++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int fill_buffer(buf, val, size)
|
||||
register char *buf;
|
||||
char val;
|
||||
register int size;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for(i = 0; i < size; i++)
|
||||
{
|
||||
buf[i] = val;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* verify()
|
||||
* Check a buffer for correct values.
|
||||
*/
|
||||
|
||||
int verify(buf, val, size, child)
|
||||
register char *buf;
|
||||
char val;
|
||||
register int size;
|
||||
int child;
|
||||
{
|
||||
while(size-- > 0)
|
||||
{
|
||||
if (*buf++ != val)
|
||||
{
|
||||
tst_resm(TWARN, "Verify error in child %d, *buf = %x, val = %x, size = %d", child, *buf, val, size);
|
||||
return(FAIL);
|
||||
}
|
||||
}
|
||||
return(PASS);
|
||||
}
|
||||
|
||||
/*
|
||||
* * void
|
||||
* * sig_handler() - signal catching function for 'SIGUSR1' signal.
|
||||
* *
|
||||
* * This is a null function and used only to catch the above signal
|
||||
* * generated in parent process.
|
||||
* */
|
||||
void
|
||||
sig_handler()
|
||||
{
|
||||
}
|
||||
|
||||
#define BUFSIZE 512
|
||||
|
||||
/** Get the number of message queues already in use */
|
||||
static int get_used_msgqueues()
|
||||
{
|
||||
FILE *f;
|
||||
int used_queues;
|
||||
char buff[BUFSIZE];
|
||||
|
||||
f = popen("ipcs -q", "r");
|
||||
if (!f) {
|
||||
tst_resm(TBROK,"Could not run 'ipcs' to calculate used message queues");
|
||||
tst_exit();
|
||||
}
|
||||
/* FIXME: Start at -4 because ipcs prints four lines of header */
|
||||
for (used_queues = -4; fgets(buff, BUFSIZE, f); used_queues++)
|
||||
;
|
||||
pclose(f);
|
||||
if (used_queues < 0) {
|
||||
tst_resm(TBROK,"Could not read output of 'ipcs' to calculate used message queues");
|
||||
tst_exit();
|
||||
}
|
||||
return used_queues;
|
||||
}
|
||||
|
||||
/** Get the max number of message queues allowed on system */
|
||||
static int get_max_msgqueues()
|
||||
{
|
||||
FILE *f;
|
||||
char buff[BUFSIZE];
|
||||
|
||||
/* Get the max number of message queues allowed on system */
|
||||
f = fopen("/proc/sys/kernel/msgmni", "r");
|
||||
if (!f){
|
||||
tst_resm(TBROK,"Could not open /proc/sys/kernel/msgmni");
|
||||
tst_exit();
|
||||
}
|
||||
if (!fgets(buff, BUFSIZE, f)) {
|
||||
tst_resm(TBROK,"Could not read /proc/sys/kernel/msgmni");
|
||||
tst_exit();
|
||||
}
|
||||
fclose(f);
|
||||
return atoi(buff);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* setup() - performs all ONE TIME setup for this test.
|
||||
*****************************************************************/
|
||||
void
|
||||
setup()
|
||||
{
|
||||
tst_tmpdir();
|
||||
|
||||
/* You will want to enable some signal handling so you can capture
|
||||
* unexpected signals like SIGSEGV.
|
||||
*/
|
||||
tst_sig(FORK, DEF_HANDLER, cleanup);
|
||||
|
||||
|
||||
/* Pause if that option was specified */
|
||||
/* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
|
||||
* fork the test with the -c option. You want to make sure you do this
|
||||
* before you create your temporary directory.
|
||||
*/
|
||||
TEST_PAUSE;
|
||||
|
||||
MSGMNI = get_max_msgqueues() - get_used_msgqueues();
|
||||
if (MSGMNI <= 0){
|
||||
tst_resm(TBROK,"Max number of message queues already used, cannot create more.");
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* cleanup() - performs all ONE TIME cleanup for this test at
|
||||
* completion or premature exit.
|
||||
****************************************************************/
|
||||
void
|
||||
cleanup()
|
||||
{
|
||||
int status;
|
||||
/*
|
||||
* Remove the message queue from the system
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
tst_resm(TINFO,"Removing the message queue");
|
||||
#endif
|
||||
fflush (stdout);
|
||||
(void) msgctl(tid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
if ((status = msgctl(tid, IPC_STAT, (struct msqid_ds *)NULL)) != -1)
|
||||
{
|
||||
(void) msgctl(tid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgctl(tid, IPC_RMID) failed");
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
tst_rmdir();
|
||||
/* exit with return code appropriate for results */
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
735
test/ipc/msgctl/msgctl09.c
Normal file
735
test/ipc/msgctl/msgctl09.c
Normal file
@@ -0,0 +1,735 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) International Business Machines Corp., 2002
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
|
||||
/* 11/11/2002 Port to LTP dbarrera@us.ibm.com */
|
||||
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* msgctl09
|
||||
*
|
||||
* CALLS
|
||||
* msgget(2) msgctl(2) msgop(2)
|
||||
*
|
||||
* ALGORITHM
|
||||
* Get and manipulate a message queue.
|
||||
*
|
||||
* RESTRICTIONS
|
||||
*
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "test.h"
|
||||
#include "usctest.h"
|
||||
|
||||
#define MAXNREPS 1000
|
||||
#ifndef CONFIG_COLDFIRE
|
||||
#define MAXNPROCS 1000000 /* This value is set to an arbitrary high limit. */
|
||||
#else
|
||||
#define MAXNPROCS 100000 /* Coldfire can't deal with 1000000 */
|
||||
#endif
|
||||
#define MAXNKIDS 10
|
||||
#define FAIL 1
|
||||
#define PASS 0
|
||||
|
||||
int dotest(key_t,int);
|
||||
int doreader(long,int,int);
|
||||
int dowriter(long,int,int);
|
||||
int fill_buffer(char*,char,int);
|
||||
int verify(char*,char,int,int);
|
||||
void setup();
|
||||
void cleanup();
|
||||
|
||||
/*
|
||||
* These globals must be defined in the test.
|
||||
* */
|
||||
|
||||
|
||||
char *TCID="msgctl09"; /* Test program identifier. */
|
||||
int TST_TOTAL=1; /* Total number of test cases. */
|
||||
extern int Tst_count; /* Test Case counter for tst_* routines */
|
||||
|
||||
int exp_enos[]={0}; /* List must end with 0 */
|
||||
|
||||
|
||||
key_t keyarray[MAXNPROCS];
|
||||
|
||||
struct {
|
||||
long type;
|
||||
struct {
|
||||
char len;
|
||||
char pbytes[99];
|
||||
} data;
|
||||
} buffer;
|
||||
|
||||
int pidarray[MAXNPROCS];
|
||||
int rkidarray[MAXNKIDS];
|
||||
int wkidarray[MAXNKIDS];
|
||||
int tid;
|
||||
int nprocs, nreps, nkids, MSGMNI;
|
||||
int procstat;
|
||||
void term(int);
|
||||
#ifdef UCLINUX
|
||||
static char *argv0;
|
||||
|
||||
void do_child_1_uclinux();
|
||||
static key_t key_uclinux;
|
||||
static int i_uclinux;
|
||||
|
||||
void do_child_2_uclinux();
|
||||
static int pid_uclinux;
|
||||
static int child_process_uclinux;
|
||||
|
||||
void do_child_3_uclinux();
|
||||
static int rkid_uclinux;
|
||||
#endif
|
||||
void cleanup_msgqueue(int i, int tid);
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int i, j, ok, pid;
|
||||
int count, status;
|
||||
|
||||
#ifdef UCLINUX
|
||||
char *msg; /* message returned from parse_opts */
|
||||
|
||||
argv0 = argv[0];
|
||||
|
||||
/* parse standard options */
|
||||
if ((msg = parse_opts(argc, argv, (option_t *)NULL, NULL)) != (char *)NULL)
|
||||
{
|
||||
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
|
||||
}
|
||||
|
||||
maybe_run_child(&do_child_1_uclinux, "ndd", 1, &key_uclinux, &i_uclinux);
|
||||
maybe_run_child(&do_child_2_uclinux, "nddd", 2, &key_uclinux,
|
||||
&pid_uclinux, &child_process_uclinux);
|
||||
maybe_run_child(&do_child_3_uclinux, "nddd", 3, &key_uclinux,
|
||||
&rkid_uclinux, &child_process_uclinux);
|
||||
#endif
|
||||
|
||||
setup();
|
||||
|
||||
if (argc == 1 )
|
||||
{
|
||||
/* Set default parameters */
|
||||
nreps = MAXNREPS;
|
||||
nprocs = MSGMNI;
|
||||
nkids = MAXNKIDS;
|
||||
}
|
||||
else if (argc == 4 )
|
||||
{
|
||||
if ( atoi(argv[1]) > MAXNREPS )
|
||||
{
|
||||
tst_resm(TCONF,"Requested number of iterations too large, setting to Max. of %d", MAXNREPS);
|
||||
nreps = MAXNREPS;
|
||||
}
|
||||
else
|
||||
{
|
||||
nreps = atoi(argv[1]);
|
||||
}
|
||||
if (atoi(argv[2]) > MSGMNI )
|
||||
{
|
||||
tst_resm(TCONF,"Requested number of processes too large, setting to Max. of %d", MSGMNI);
|
||||
nprocs = MSGMNI;
|
||||
}
|
||||
else
|
||||
{
|
||||
nprocs = atoi(argv[2]);
|
||||
}
|
||||
if (atoi(argv[3]) > MAXNKIDS )
|
||||
{
|
||||
tst_resm(TCONF,"Requested number of read/write pairs too large; setting to Max. of %d", MAXNKIDS);
|
||||
nkids = MAXNKIDS;
|
||||
}
|
||||
else
|
||||
{
|
||||
nkids = atoi(argv[3]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tst_resm(TCONF," Usage: %s [ number of iterations number of processes number of read/write pairs ]", argv[0]);
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
procstat = 0;
|
||||
srand48((unsigned)getpid() + (unsigned)(getppid() << 16));
|
||||
tid = -1;
|
||||
|
||||
/* Setup signal handleing routine */
|
||||
if (sigset(SIGTERM, term) == SIG_ERR)
|
||||
{
|
||||
tst_resm(TFAIL, "Sigset SIGTERM failed");
|
||||
tst_exit();
|
||||
}
|
||||
/* Set up array of unique keys for use in allocating message
|
||||
* queues
|
||||
*/
|
||||
for (i = 0; i < nprocs; i++)
|
||||
{
|
||||
ok = 1;
|
||||
do
|
||||
{
|
||||
/* Get random key */
|
||||
keyarray[i] = (key_t)lrand48();
|
||||
/* Make sure key is unique and not private */
|
||||
if (keyarray[i] == IPC_PRIVATE)
|
||||
{
|
||||
ok = 0;
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
if (keyarray[j] == keyarray[i])
|
||||
{
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
ok = 1;
|
||||
}
|
||||
} while (ok == 0);
|
||||
}
|
||||
/*-----------------------------------------------------------------*/
|
||||
/* Fork a number of processes (nprocs), each of which will
|
||||
* create a message queue with several (nkids) reader/writer
|
||||
* pairs which will read and write a number (iterations)
|
||||
* of random length messages with specific values (keys).
|
||||
*/
|
||||
|
||||
for (i = 0; i < nprocs; i++)
|
||||
{
|
||||
fflush(stdout);
|
||||
if ((pid = FORK_OR_VFORK()) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "\tFork failed (may be OK if under stress)");
|
||||
tst_exit();
|
||||
}
|
||||
/* Child does this */
|
||||
if (pid == 0)
|
||||
{
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(argv[0], "ndd", 1, keyarray[i], i) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "\tself_exec failed");
|
||||
tst_exit();
|
||||
}
|
||||
#else
|
||||
procstat = 1;
|
||||
exit( dotest(keyarray[i], i) );
|
||||
#endif
|
||||
}
|
||||
pidarray[i] = pid;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
while(1)
|
||||
{
|
||||
if (( wait(&status)) > 0)
|
||||
{
|
||||
if (status>>8 != PASS )
|
||||
{
|
||||
tst_resm(TFAIL, "Child exit status = %d", status>>8);
|
||||
tst_exit();
|
||||
}
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (errno != EINTR)
|
||||
{
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
tst_resm(TINFO,"Signal detected during wait");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* Make sure proper number of children exited */
|
||||
if (count != nprocs)
|
||||
{
|
||||
tst_resm(TFAIL, "Wrong number of children exited, Saw %d, Expected %d", count, nprocs);
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
tst_resm(TPASS,"msgctl09 ran successfully!");
|
||||
|
||||
cleanup();
|
||||
|
||||
return (0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
|
||||
#ifdef UCLINUX
|
||||
void
|
||||
do_child_1_uclinux()
|
||||
{
|
||||
procstat = 1;
|
||||
exit(dotest(key_uclinux, i_uclinux));
|
||||
}
|
||||
|
||||
void
|
||||
do_child_2_uclinux()
|
||||
{
|
||||
procstat = 2;
|
||||
exit(doreader(key_uclinux, pid_uclinux, child_process_uclinux));
|
||||
}
|
||||
|
||||
void
|
||||
do_child_3_uclinux()
|
||||
{
|
||||
procstat = 2;
|
||||
exit(dowriter(key_uclinux, rkid_uclinux, child_process_uclinux));
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
cleanup_msgqueue(int i, int tid)
|
||||
{
|
||||
/*
|
||||
* Decrease the value of i by 1 because it
|
||||
* is getting incremented even if the fork
|
||||
* is failing.
|
||||
*/
|
||||
|
||||
i--;
|
||||
/*
|
||||
* Kill all children & free message queue.
|
||||
*/
|
||||
for (; i >= 0; i--) {
|
||||
(void)kill(rkidarray[i], SIGKILL);
|
||||
(void)kill(wkidarray[i], SIGKILL);
|
||||
}
|
||||
|
||||
if (msgctl(tid, IPC_RMID, 0) < 0) {
|
||||
tst_resm(TFAIL, "Msgctl error in cleanup, errno = %d", errno);
|
||||
tst_exit();
|
||||
}
|
||||
}
|
||||
|
||||
int dotest(key, child_process)
|
||||
key_t key;
|
||||
int child_process;
|
||||
{
|
||||
int id, pid;
|
||||
int i, count, status, exit_status;
|
||||
|
||||
sighold(SIGTERM);
|
||||
if ((id = msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR )) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgget error in child %d, errno = %d", child_process, errno);
|
||||
tst_exit();
|
||||
}
|
||||
tid = id;
|
||||
sigrelse(SIGTERM);
|
||||
|
||||
exit_status = PASS;
|
||||
|
||||
for (i=0; i < nkids; i++)
|
||||
{
|
||||
fflush(stdout);
|
||||
if ((pid = FORK_OR_VFORK()) < 0)
|
||||
{
|
||||
tst_resm(TWARN, "Fork failure in first child of child group %d", child_process);
|
||||
cleanup_msgqueue(i, tid);
|
||||
tst_exit();
|
||||
}
|
||||
/* First child does this */
|
||||
if (pid == 0)
|
||||
{
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(argv0, "nddd", 2, key, getpid(),
|
||||
child_process) < 0) {
|
||||
tst_resm(TWARN, "self_exec failed");
|
||||
cleanup_msgqueue(i, tid);
|
||||
tst_exit();
|
||||
}
|
||||
#else
|
||||
procstat = 2;
|
||||
exit( doreader( key, getpid(), child_process) );
|
||||
#endif
|
||||
}
|
||||
rkidarray[i] = pid;
|
||||
fflush(stdout);
|
||||
if ((pid = FORK_OR_VFORK()) < 0)
|
||||
{
|
||||
tst_resm(TWARN, "Fork failure in first child of child group %d", child_process);
|
||||
/*
|
||||
* Kill the reader child process
|
||||
*/
|
||||
(void)kill(rkidarray[i], SIGKILL);
|
||||
|
||||
cleanup_msgqueue(i, tid);
|
||||
tst_exit();
|
||||
}
|
||||
/* Second child does this */
|
||||
if (pid == 0)
|
||||
{
|
||||
#ifdef UCLINUX
|
||||
if (self_exec(argv0, "nddd", 3, key, rkidarray[i],
|
||||
child_process) < 0) {
|
||||
tst_resm(TWARN, "\tFork failure in first child "
|
||||
"of child group %d \n", child_process);
|
||||
/*
|
||||
* Kill the reader child process
|
||||
*/
|
||||
(void)kill(rkidarray[i], SIGKILL);
|
||||
|
||||
cleanup_msgqueue(i, tid);
|
||||
tst_exit();
|
||||
}
|
||||
#else
|
||||
procstat = 2;
|
||||
exit( dowriter( key, rkidarray[i], child_process) );
|
||||
#endif
|
||||
}
|
||||
wkidarray[i] = pid;
|
||||
}
|
||||
/* Parent does this */
|
||||
count = 0;
|
||||
while(1)
|
||||
{
|
||||
if (( wait(&status)) > 0)
|
||||
{
|
||||
if (status>>8 != PASS )
|
||||
{
|
||||
tst_resm(TFAIL, "Child exit status = %d from child group %d", status>>8, child_process);
|
||||
for (i = 0; i < nkids; i++)
|
||||
{
|
||||
kill(rkidarray[i], SIGTERM);
|
||||
kill(wkidarray[i], SIGTERM);
|
||||
}
|
||||
if (msgctl(tid, IPC_RMID, 0) < 0) {
|
||||
tst_resm(TFAIL, "Msgctl error, errno = %d", errno);
|
||||
}
|
||||
tst_exit();
|
||||
}
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (errno != EINTR)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Make sure proper number of children exited */
|
||||
if (count != (nkids * 2))
|
||||
{
|
||||
tst_resm(TFAIL, "Wrong number of children exited in child group %d, Saw %d Expected %d", child_process, count, (nkids * 2));
|
||||
if (msgctl(tid, IPC_RMID, 0) < 0) {
|
||||
tst_resm(TFAIL, "Msgctl error, errno = %d", errno);
|
||||
}
|
||||
tst_exit();
|
||||
}
|
||||
if (msgctl(id, IPC_RMID, 0) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgctl failure in child group %d, errno %d", child_process, errno);
|
||||
tst_exit();
|
||||
}
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
int doreader( key, type, child)
|
||||
int type, child;
|
||||
long key;
|
||||
{
|
||||
int i, size;
|
||||
int id;
|
||||
|
||||
if ((id = msgget(key, 0)) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgget error in reader of child group %d, errno = %d", child, errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (id != tid)
|
||||
{
|
||||
tst_resm(TFAIL, "Message queue mismatch in reader of child group %d for message queue id %d", child, id);
|
||||
tst_exit();
|
||||
}
|
||||
for (i = 0; i < nreps; i++)
|
||||
{
|
||||
if ((size = msgrcv(id, &buffer, 100, type, 0)) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgrcv error in child %d, read # = %d, errno = %d", (i + 1), child, errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (buffer.type != type)
|
||||
{
|
||||
tst_resm(TFAIL, "Size mismatch in child %d, read # = %d", child, (i + 1));
|
||||
tst_resm(TFAIL, "\tfor message size got %d expected %d %s",size ,buffer.data.len);
|
||||
tst_exit();
|
||||
}
|
||||
if (buffer.data.len + 1 != size)
|
||||
{
|
||||
tst_resm(TFAIL, "Size mismatch in child %d, read # = %d, size = %d, expected = %d", child, (i + 1), buffer.data.len, size);
|
||||
tst_exit();
|
||||
}
|
||||
if ( verify(buffer.data.pbytes, (key % 255), size - 1, child) )
|
||||
{
|
||||
tst_resm(TFAIL, "in read # = %d,key = %x", (i + 1), child, key);
|
||||
tst_exit();
|
||||
}
|
||||
key++;
|
||||
}
|
||||
exit(PASS);
|
||||
}
|
||||
|
||||
int dowriter( key, type, child)
|
||||
int type,child;
|
||||
long key;
|
||||
{
|
||||
int i, size;
|
||||
int id;
|
||||
|
||||
if ((id = msgget(key, 0)) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgget error in writer of child group %d, errno = %d", child, errno);
|
||||
tst_exit();
|
||||
}
|
||||
if (id != tid)
|
||||
{
|
||||
tst_resm(TFAIL, "Message queue mismatch in writer of child group %d", child);
|
||||
tst_resm(TFAIL, "\tfor message queue id %d expected %d",id, tid);
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
for (i = 0; i < nreps; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
size = (lrand48() % 99);
|
||||
} while (size == 0);
|
||||
fill_buffer(buffer.data.pbytes, (key % 255), size);
|
||||
buffer.data.len = size;
|
||||
buffer.type = type;
|
||||
if (msgsnd(id, &buffer, size + 1, 0) < 0)
|
||||
{
|
||||
tst_resm(TFAIL, "Msgsnd error in child %d, key = %x errno = %d", child, key, errno);
|
||||
tst_exit();
|
||||
}
|
||||
key++;
|
||||
}
|
||||
exit(PASS);
|
||||
}
|
||||
|
||||
int fill_buffer(buf, val, size)
|
||||
register char *buf;
|
||||
char val;
|
||||
register int size;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for(i = 0; i < size; i++)
|
||||
buf[i] = val;
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* verify()
|
||||
* Check a buffer for correct values.
|
||||
*/
|
||||
|
||||
int verify(buf, val, size, child)
|
||||
register char *buf;
|
||||
char val;
|
||||
register int size;
|
||||
int child;
|
||||
{
|
||||
while(size-- > 0)
|
||||
if (*buf++ != val)
|
||||
{
|
||||
tst_resm(TWARN, "Verify error in child %d, *buf = %x, val = %x, size = %d", child, *buf, val, size);
|
||||
return(FAIL);
|
||||
}
|
||||
return(PASS);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
term(int sig)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (procstat == 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
tst_resm(TINFO,"SIGTERM signal received, test killing kids");
|
||||
#endif
|
||||
for (i = 0; i < nprocs; i++)
|
||||
{
|
||||
if ( pidarray[i] > 0){
|
||||
if ( kill(pidarray[i], SIGTERM) < 0)
|
||||
{
|
||||
tst_resm(TBROK,"Kill failed to kill child %d", i);
|
||||
exit(FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (procstat == 2)
|
||||
{
|
||||
fflush(stdout);
|
||||
exit(PASS);
|
||||
}
|
||||
|
||||
if (tid == -1)
|
||||
{
|
||||
exit(FAIL);
|
||||
}
|
||||
for (i = 0; i < nkids; i++)
|
||||
{
|
||||
if (rkidarray[i] > 0)
|
||||
kill(rkidarray[i], SIGTERM);
|
||||
if (wkidarray[i] > 0)
|
||||
kill(wkidarray[i], SIGTERM);
|
||||
}
|
||||
}
|
||||
|
||||
#define BUFSIZE 512
|
||||
|
||||
/** Get the number of message queues already in use */
|
||||
static int get_used_msgqueues()
|
||||
{
|
||||
FILE *f;
|
||||
int used_queues;
|
||||
char buff[BUFSIZE];
|
||||
|
||||
f = popen("ipcs -q", "r");
|
||||
if (!f) {
|
||||
tst_resm(TBROK,"Could not run 'ipcs' to calculate used message queues");
|
||||
tst_exit();
|
||||
}
|
||||
/* FIXME: Start at -4 because ipcs prints four lines of header */
|
||||
for (used_queues = -4; fgets(buff, BUFSIZE, f); used_queues++)
|
||||
;
|
||||
pclose(f);
|
||||
if (used_queues < 0) {
|
||||
tst_resm(TBROK,"Could not read output of 'ipcs' to calculate used message queues");
|
||||
tst_exit();
|
||||
}
|
||||
return used_queues;
|
||||
}
|
||||
|
||||
/** Get the max number of message queues allowed on system */
|
||||
static int get_max_msgqueues()
|
||||
{
|
||||
FILE *f;
|
||||
char buff[BUFSIZE];
|
||||
|
||||
/* Get the max number of message queues allowed on system */
|
||||
f = fopen("/proc/sys/kernel/msgmni", "r");
|
||||
if (!f){
|
||||
tst_resm(TBROK,"Could not open /proc/sys/kernel/msgmni");
|
||||
tst_exit();
|
||||
}
|
||||
if (!fgets(buff, BUFSIZE, f)) {
|
||||
tst_resm(TBROK,"Could not read /proc/sys/kernel/msgmni");
|
||||
tst_exit();
|
||||
}
|
||||
fclose(f);
|
||||
return atoi(buff);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* setup() - performs all ONE TIME setup for this test.
|
||||
*****************************************************************/
|
||||
void
|
||||
setup()
|
||||
{
|
||||
tst_tmpdir();
|
||||
/* You will want to enable some signal handling so you can capture
|
||||
* unexpected signals like SIGSEGV.
|
||||
*/
|
||||
tst_sig(FORK, DEF_HANDLER, cleanup);
|
||||
|
||||
|
||||
/* Pause if that option was specified */
|
||||
/* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
|
||||
* fork the test with the -c option. You want to make sure you do this
|
||||
* before you create your temporary directory.
|
||||
*/
|
||||
TEST_PAUSE;
|
||||
|
||||
MSGMNI = get_max_msgqueues() - get_used_msgqueues();
|
||||
if (MSGMNI <= 0){
|
||||
tst_resm(TBROK,"Max number of message queues already used, cannot create more.");
|
||||
cleanup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* cleanup() - performs all ONE TIME cleanup for this test at
|
||||
* completion or premature exit.
|
||||
****************************************************************/
|
||||
void
|
||||
cleanup()
|
||||
{
|
||||
int status;
|
||||
/*
|
||||
* print timing stats if that option was specified.
|
||||
* print errno log if that option was specified.
|
||||
*/
|
||||
TEST_CLEANUP;
|
||||
|
||||
/*
|
||||
* Remove the message queue from the system
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
tst_resm(TINFO,"Removing the message queue");
|
||||
#endif
|
||||
fflush (stdout);
|
||||
(void) msgctl(tid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
if ((status = msgctl(tid, IPC_STAT, (struct msqid_ds *)NULL)) != -1)
|
||||
{
|
||||
(void) msgctl(tid, IPC_RMID, (struct msqid_ds *)NULL);
|
||||
tst_resm(TFAIL, "msgctl(tid, IPC_RMID) failed");
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
tst_rmdir();
|
||||
/* exit with return code appropriate for results */
|
||||
tst_exit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user