ipc test improvements
. rename testshm.sh to test.sh so all test scripts are called test.sh . delete msg* tests as msg* functionality isn't implemented . add ipc/test.sh that runs all test.sh scripts in the subdirs
This commit is contained in:
parent
78806e1b2e
commit
2fd5eb2569
31 changed files with 7 additions and 6448 deletions
|
@ -1,31 +0,0 @@
|
||||||
#
|
|
||||||
# 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)
|
|
|
@ -1,179 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,202 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,169 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,229 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,217 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,197 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
|
@ -1,371 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,564 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,735 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
#
|
|
||||||
# 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)
|
|
|
@ -1,211 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgget01.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgget01 - create a message queue, write a message to it and
|
|
||||||
* read it back.
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* loop if that option was specified
|
|
||||||
* create a message queue
|
|
||||||
* check the return code
|
|
||||||
* if failure, issue a FAIL message.
|
|
||||||
* otherwise,
|
|
||||||
* if doing functionality testing by writting a message to the queue,
|
|
||||||
* reading it back and comparing the two.
|
|
||||||
* if the messages are the same,
|
|
||||||
* issue a PASS message
|
|
||||||
* otherwise
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgget01 [-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 "ipcmsg.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char *TCID = "msgget01";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* to hold the message queue ID */
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
int lc; /* loop counter */
|
|
||||||
char *msg; /* message returned from parse_opts */
|
|
||||||
void check_functionality(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 */
|
|
||||||
|
|
||||||
/* 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 to create the message queue
|
|
||||||
*/
|
|
||||||
|
|
||||||
TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR));
|
|
||||||
|
|
||||||
if (TEST_RETURN == -1) {
|
|
||||||
tst_resm(TFAIL, "%s call failed - errno = %d : %s",
|
|
||||||
TCID, TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
} else {
|
|
||||||
msg_q_1 = TEST_RETURN;
|
|
||||||
if (STD_FUNCTIONAL_TEST) {
|
|
||||||
/*
|
|
||||||
* write a message to the queue.
|
|
||||||
* read back the message.
|
|
||||||
* PASS the test if they are the same.
|
|
||||||
*/
|
|
||||||
check_functionality();
|
|
||||||
} else {
|
|
||||||
tst_resm(TPASS, "message queue was created");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* remove the message queue that was created and mark the ID
|
|
||||||
* as invalid.
|
|
||||||
*/
|
|
||||||
if (msg_q_1 != -1) {
|
|
||||||
rm_queue(msg_q_1);
|
|
||||||
msg_q_1 = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
/*NOTREACHED*/
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check_functionality() - check the functionality of the tested system call.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
check_functionality()
|
|
||||||
{
|
|
||||||
int i=0;
|
|
||||||
MSGBUF snd_buf, rcv_buf;
|
|
||||||
|
|
||||||
/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */
|
|
||||||
char *queue_msg =
|
|
||||||
"Qston, check_functionality here. The message has queued!";
|
|
||||||
|
|
||||||
/*
|
|
||||||
* copy our message into the buffer and then set the type.
|
|
||||||
*/
|
|
||||||
do {
|
|
||||||
snd_buf.mtext[i++] = *queue_msg;
|
|
||||||
} while(*queue_msg++ != (char)NULL);
|
|
||||||
|
|
||||||
snd_buf.mtype = MSGTYPE;
|
|
||||||
|
|
||||||
/* send the message */
|
|
||||||
if(msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Could not send a message in the "
|
|
||||||
"check_functionality() routine.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* receive the message */
|
|
||||||
if(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Could not read a messages in the "
|
|
||||||
"check_functionality() routine.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(strcmp(snd_buf.mtext, rcv_buf.mtext) == 0) {
|
|
||||||
tst_resm(TPASS, "message received = message sent");
|
|
||||||
} else {
|
|
||||||
tst_resm(TFAIL, "message received != message sent");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,189 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgget02.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgget02 - test for EEXIST and ENOENT errors
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue
|
|
||||||
* loop if that option was specified
|
|
||||||
* try to recreate the same queue - test #1
|
|
||||||
* try to access a queue that doesn't exist - tests #2 & #3
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EEXIST or ENOENT depening on test
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* break any remaining tests
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgget02 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
char *TCID = "msgget02";
|
|
||||||
int TST_TOTAL = 3;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
struct test_case_t {
|
|
||||||
int error;
|
|
||||||
int msg_incr;
|
|
||||||
int flags;
|
|
||||||
} TC[] = {
|
|
||||||
{EEXIST, 0, IPC_CREAT | IPC_EXCL},
|
|
||||||
{ENOENT, 1, IPC_PRIVATE},
|
|
||||||
{ENOENT, 1, IPC_EXCL}
|
|
||||||
};
|
|
||||||
|
|
||||||
int exp_enos[] = {EEXIST, ENOENT, 0};
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
|
|
||||||
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(msgget(msgkey + TC[i].msg_incr, TC[i].flags));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
tst_resm(TFAIL, "msgget() call succeeded "
|
|
||||||
"on expected fail");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch(TEST_ERRNO) {
|
|
||||||
case ENOENT:
|
|
||||||
/*FALLTHROUGH*/
|
|
||||||
case EEXIST:
|
|
||||||
if (TEST_ERRNO == TC[i].error) {
|
|
||||||
tst_resm(TPASS, "expected failure - "
|
|
||||||
"errno = %d : %s", TEST_ERRNO,
|
|
||||||
strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*FALLTHROUGH*/
|
|
||||||
default:
|
|
||||||
tst_resm(TFAIL, "call failed with an "
|
|
||||||
"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();
|
|
||||||
|
|
||||||
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" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created. */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,233 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgget03.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgget03 - test for an ENOSPC error by using up all available
|
|
||||||
* message queues.
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* Get all the message queues that can be allocated
|
|
||||||
* loop if that option was specified
|
|
||||||
* Try to get one more message queue
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get ENOSPC
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* break any remaining tests
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgget03 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
char *TCID = "msgget03";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int maxmsgs = 0;
|
|
||||||
|
|
||||||
int exp_enos[] = {ENOSPC, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int *msg_q_arr = NULL; /* hold the id's that we create */
|
|
||||||
int num_queue = 0; /* count the queues created */
|
|
||||||
|
|
||||||
static int get_max_msgqueues();
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Try to create another message queue. This should
|
|
||||||
* give us an ENOSPC error.
|
|
||||||
*/
|
|
||||||
|
|
||||||
TEST(msgget(msgkey + num_queue + 1, IPC_CREAT|IPC_EXCL));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
tst_resm(TFAIL, "call succeeded when error expected");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch(TEST_ERRNO) {
|
|
||||||
case ENOSPC:
|
|
||||||
tst_resm(TPASS, "expected failure - errno = %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tst_resm(TFAIL, "call failed with an "
|
|
||||||
"unexpected error - %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
/*NOTREACHED*/
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get the max number of message queues allowed on system */
|
|
||||||
int get_max_msgqueues()
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
char buff[512];
|
|
||||||
|
|
||||||
/* Get the max number of message queues allowed on system */
|
|
||||||
f = fopen("/proc/sys/kernel/msgmni", "r");
|
|
||||||
if (!f){
|
|
||||||
tst_brkm(TBROK, cleanup, "Could not open /proc/sys/kernel/msgmni");
|
|
||||||
}
|
|
||||||
if (!fgets(buff, 512, f)) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Could not read /proc/sys/kernel/msgmni");
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
return atoi(buff);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* setup() - performs all the ONE TIME setup for this test.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
setup(void)
|
|
||||||
{
|
|
||||||
int msg_q;
|
|
||||||
|
|
||||||
/* 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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
maxmsgs = get_max_msgqueues();
|
|
||||||
|
|
||||||
msg_q_arr = (int *)calloc(maxmsgs, sizeof (int));
|
|
||||||
if (msg_q_arr == NULL) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
|
|
||||||
"for msg_q_arr: calloc() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Use a while loop to create the maximum number of queues.
|
|
||||||
* When we get an error, check for ENOSPC.
|
|
||||||
*/
|
|
||||||
while((msg_q = msgget(msgkey + num_queue, IPC_CREAT|IPC_EXCL)) != -1) {
|
|
||||||
msg_q_arr[num_queue] = msg_q;
|
|
||||||
if (num_queue == maxmsgs) {
|
|
||||||
tst_resm(TINFO, "The maximum number of message"
|
|
||||||
" queues (%d) has been reached", maxmsgs);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
num_queue++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if we have something other than ENOSPC, then something else is
|
|
||||||
* wrong.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (errno != ENOSPC) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup"
|
|
||||||
" - errno = %d : %s", errno, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
|
||||||
* or premature exit.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
cleanup(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* remove the message queues if they were created
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (msg_q_arr != NULL) {
|
|
||||||
for (i=0; i<num_queue; i++) {
|
|
||||||
rm_queue(msg_q_arr[i]);
|
|
||||||
}
|
|
||||||
(void) free(msg_q_arr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,201 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgget04.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgget04 - test for an EACCES error by creating a message queue
|
|
||||||
* with no read or write permission and then attempting
|
|
||||||
* to access it with various permissions.
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* Create a message queue with no read or write permission
|
|
||||||
* loop if that option was specified
|
|
||||||
* Try to access the message queue with various permissions
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EACCES
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* break any remaining tests
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgget04 [-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 = "msgget04";
|
|
||||||
int TST_TOTAL = 3;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
char nobody_uid[] = "nobody";
|
|
||||||
struct passwd *ltpuser;
|
|
||||||
|
|
||||||
|
|
||||||
int exp_enos[] = {EACCES, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* to hold the message queue id */
|
|
||||||
|
|
||||||
int test_flags[] = {MSG_RD, MSG_WR, MSG_RD | MSG_WR};
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
int lc; /* loop counter */
|
|
||||||
char *msg; /* message returned from parse_opts */
|
|
||||||
int i; /* a counter */
|
|
||||||
|
|
||||||
/* 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++) {
|
|
||||||
/*
|
|
||||||
* Try to access the message queue with specified
|
|
||||||
* permissions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
TEST(msgget(msgkey, test_flags[i]));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
tst_resm(TFAIL, "call succeeded "
|
|
||||||
"when EACCES error expected");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch(TEST_ERRNO) {
|
|
||||||
case EACCES:
|
|
||||||
tst_resm(TPASS, "expected failure - errno = "
|
|
||||||
"%d : %s", TEST_ERRNO,
|
|
||||||
strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tst_resm(TFAIL, "call failed with an "
|
|
||||||
"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;
|
|
||||||
|
|
||||||
/* 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();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create the message queue without specifying permissions.
|
|
||||||
*/
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT|IPC_EXCL)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Could not create message queue"
|
|
||||||
" - errno = %d : %s", errno, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
#
|
|
||||||
# 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)
|
|
|
@ -1,231 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgrcv01.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgrcv01 - test that msgrcv() receives the expected message
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue
|
|
||||||
* initialize a message buffer with a known message and type
|
|
||||||
* loop if that option was specified
|
|
||||||
* fork a child to receive the message
|
|
||||||
* parent enqueues the message then exits
|
|
||||||
* check the return code
|
|
||||||
* if failure, issue a FAIL message.
|
|
||||||
* otherwise,
|
|
||||||
* if doing functionality testing
|
|
||||||
* build a new message and compare it to the one received
|
|
||||||
* if they are the same,
|
|
||||||
* issue a PASS message
|
|
||||||
* otherwise
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgrcv01 [-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 <string.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
|
|
||||||
#include "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
void do_child(void);
|
|
||||||
|
|
||||||
char *TCID = "msgrcv01";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int msg_q_1;
|
|
||||||
MSGBUF snd_buf, rcv_buf, cmp_buf;
|
|
||||||
|
|
||||||
pid_t c_pid;
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
int lc; /* loop counter */
|
|
||||||
char *msg; /* message returned from parse_opts */
|
|
||||||
void check_functionality(void);
|
|
||||||
int status, e_code;
|
|
||||||
|
|
||||||
/* 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, "d", &msg_q_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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* fork a child to read from the queue while the parent
|
|
||||||
* enqueues the message to be read.
|
|
||||||
*/
|
|
||||||
if ((c_pid = FORK_OR_VFORK()) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not fork");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c_pid == 0) { /* child */
|
|
||||||
#ifdef UCLINUX
|
|
||||||
if (self_exec(av[0], "d", msg_q_1) < 0) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not self_exec");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
do_child();
|
|
||||||
#endif
|
|
||||||
} else { /* parent */
|
|
||||||
/* put the message on the queue */
|
|
||||||
if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Couldn't enqueue" " message");
|
|
||||||
}
|
|
||||||
/* wait for the child to finish */
|
|
||||||
wait(&status);
|
|
||||||
/* make sure the child returned a good exit status */
|
|
||||||
e_code = status >> 8;
|
|
||||||
if (e_code != 0) {
|
|
||||||
tst_resm(TFAIL, "Failures reported above");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
/** NOT REACHED **/
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child()
|
|
||||||
{
|
|
||||||
int retval = 0;
|
|
||||||
|
|
||||||
TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));
|
|
||||||
|
|
||||||
if (TEST_RETURN == -1) {
|
|
||||||
retval = 1;
|
|
||||||
tst_resm(TFAIL, "%s call failed - errno = %d : %s",
|
|
||||||
TCID, TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
} else {
|
|
||||||
if (STD_FUNCTIONAL_TEST) {
|
|
||||||
/*
|
|
||||||
* Build a new message and compare it
|
|
||||||
* with the one received.
|
|
||||||
*/
|
|
||||||
init_buf(&cmp_buf, MSGTYPE, MSGSIZE);
|
|
||||||
|
|
||||||
if (strcmp(rcv_buf.mtext, cmp_buf.mtext) == 0) {
|
|
||||||
tst_resm(TPASS,
|
|
||||||
"message received = " "message sent");
|
|
||||||
} else {
|
|
||||||
retval = 1;
|
|
||||||
tst_resm(TFAIL,
|
|
||||||
"message received != " "message sent");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tst_resm(TPASS, "call succeeded");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exit(retval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* setup() - performs all the ONE TIME setup for this test.
|
|
||||||
*/
|
|
||||||
void setup(void)
|
|
||||||
{
|
|
||||||
/* capture signals */
|
|
||||||
tst_sig(FORK, 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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the message buffer */
|
|
||||||
init_buf(&snd_buf, MSGTYPE, MSGSIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
|
@ -1,225 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgrcv02.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgrcv02 - test for EACCES and EFAULT errors
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* initialize a message buffer with a known message and type
|
|
||||||
* enqueue the message
|
|
||||||
* create another message queue without read/write permissions
|
|
||||||
* loop if that option was specified
|
|
||||||
* call msgrcv() using two different invalid cases
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EACCES or EFAULT
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgrcv02 [-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"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
|
|
||||||
char *TCID = "msgrcv02";
|
|
||||||
int TST_TOTAL = 2;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
char nobody_uid[] = "nobody";
|
|
||||||
struct passwd *ltpuser;
|
|
||||||
|
|
||||||
int exp_enos[] = {EACCES, EFAULT, 0};
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue ID created in setup */
|
|
||||||
int msg_q_2 = -1; /* Another message queue ID created in setup */
|
|
||||||
MSGBUF snd_buf, rcv_buf;
|
|
||||||
|
|
||||||
struct test_case_t {
|
|
||||||
int *queue_id;
|
|
||||||
MSGBUF *mbuf;
|
|
||||||
int error;
|
|
||||||
} TC[] = {
|
|
||||||
/* EACCES - the queue has no read access */
|
|
||||||
{&msg_q_2, &rcv_buf, EACCES},
|
|
||||||
|
|
||||||
/* EFAULT - the message buffer address is invalid */
|
|
||||||
{&msg_q_1, (MSGBUF *)-1, EFAULT}
|
|
||||||
};
|
|
||||||
|
|
||||||
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(msgrcv(*(TC[i].queue_id), TC[i].mbuf, MSGSIZE,
|
|
||||||
1, IPC_NOWAIT));
|
|
||||||
|
|
||||||
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, "call failed with an "
|
|
||||||
"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;
|
|
||||||
|
|
||||||
/* 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();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue #1");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize a message buffer */
|
|
||||||
init_buf(&snd_buf, MSGTYPE, MSGSIZE);
|
|
||||||
|
|
||||||
/* put it on msq_q_1 */
|
|
||||||
if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, IPC_NOWAIT) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Couldn't put message on queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create a message queue without read/write permission */
|
|
||||||
if ((msg_q_2 = msgget(msgkey + 1, IPC_CREAT | IPC_EXCL)) == -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)
|
|
||||||
{
|
|
||||||
/* if it exists, remove the message queue #1 */
|
|
||||||
rm_queue(msg_q_1);
|
|
||||||
|
|
||||||
/* if it exists, remove the message queue #2 */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,188 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgrcv03.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgrcv03 - test for EINVAL error
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* loop if that option was specified
|
|
||||||
* call msgrcv() using two different invalid cases
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EINVAL
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgrcv03 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
|
|
||||||
char *TCID = "msgrcv03";
|
|
||||||
int TST_TOTAL = 2;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int exp_enos[] = {EINVAL, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
int bad_q = -1; /* a value to use as a bad queue ID */
|
|
||||||
MSGBUF rcv_buf;
|
|
||||||
|
|
||||||
struct test_case_t {
|
|
||||||
int *queue_id;
|
|
||||||
int msize;
|
|
||||||
int error;
|
|
||||||
} TC[] = {
|
|
||||||
/* EINVAL - the queue ID is invalid */
|
|
||||||
{&bad_q, MSGSIZE, EINVAL},
|
|
||||||
|
|
||||||
/* EINVAL - the message size is less than 0 */
|
|
||||||
{&msg_q_1, -1, 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(msgrcv(*(TC[i].queue_id), &rcv_buf, TC[i].msize,
|
|
||||||
1, 0));
|
|
||||||
|
|
||||||
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, "call failed with an "
|
|
||||||
"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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,207 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgrcv04.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgrcv04 - test for E2BIG and ENOMSG errors
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* initialize a message buffer with a known message and type
|
|
||||||
* enqueue the message
|
|
||||||
* loop if that option was specified
|
|
||||||
* call msgrcv() using two different invalid cases
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get E2BIG or ENOMSG
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgrcv04 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
|
|
||||||
char *TCID = "msgrcv04";
|
|
||||||
int TST_TOTAL = 2;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int exp_enos[] = {E2BIG, ENOMSG, 0};
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
|
|
||||||
#define SMSIZE 512
|
|
||||||
|
|
||||||
MSGBUF snd_buf, rcv_buf;
|
|
||||||
|
|
||||||
struct test_case_t {
|
|
||||||
int size;
|
|
||||||
int type;
|
|
||||||
int flags;
|
|
||||||
int error;
|
|
||||||
} TC[] = {
|
|
||||||
/*
|
|
||||||
* E2BIG - The receive buffer is too small for the message and
|
|
||||||
* MSG_NOERROR isn't asserted in the flags.
|
|
||||||
*/
|
|
||||||
{SMSIZE, 1, 0, E2BIG},
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ENOMSG - There is no message with the requested type and
|
|
||||||
* IPC_NOWAIT is asserted in the flags.
|
|
||||||
*/
|
|
||||||
{MSGSIZE, 2, IPC_NOWAIT, ENOMSG}
|
|
||||||
};
|
|
||||||
|
|
||||||
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(msgrcv(msg_q_1, &rcv_buf, TC[i].size, TC[i].type,
|
|
||||||
TC[i].flags));
|
|
||||||
|
|
||||||
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, "call failed with an "
|
|
||||||
"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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize a buffer */
|
|
||||||
init_buf(&snd_buf, MSGTYPE, MSGSIZE);
|
|
||||||
|
|
||||||
/* put the message on the queue */
|
|
||||||
if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't enqueue message");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,243 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgrcv05.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgrcv05 - test for EINTR error
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* loop if that option was specified
|
|
||||||
* fork a child who attempts to read a non-existent message with msgrcv()
|
|
||||||
* parent sends a SIGHUP to the child, then waits for the child to complete
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EINTR
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* child exits, parent calls cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgrcv05 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
|
|
||||||
void do_child(void);
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
void sighandler(int);
|
|
||||||
#ifdef UCLINUX
|
|
||||||
void do_child_uclinux(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *TCID = "msgrcv05";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int exp_enos[] = {EINTR, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
|
|
||||||
MSGBUF rcv_buf;
|
|
||||||
pid_t c_pid;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef UCLINUX
|
|
||||||
maybe_run_child(&do_child_uclinux, "d", &msg_q_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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* fork a child that will attempt to read a non-existent
|
|
||||||
* message from the queue
|
|
||||||
*/
|
|
||||||
if ((c_pid = FORK_OR_VFORK()) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not fork");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c_pid == 0) { /* child */
|
|
||||||
/*
|
|
||||||
* Attempt to read a message without IPC_NOWAIT.
|
|
||||||
* With no message to read, the child sleeps.
|
|
||||||
*/
|
|
||||||
#ifdef UCLINUX
|
|
||||||
if (self_exec(av[0], "d", msg_q_1) < 0) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not self_exec");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
do_child();
|
|
||||||
#endif
|
|
||||||
} else { /* parent */
|
|
||||||
usleep(250000);
|
|
||||||
|
|
||||||
/* send a signal that must be caught to the child */
|
|
||||||
if (kill(c_pid, SIGHUP) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "kill failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
waitpid(c_pid, NULL, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
/*NOTREACHED*/
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child()
|
|
||||||
{
|
|
||||||
TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
tst_resm(TFAIL, "call succeeded when error expected");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch(TEST_ERRNO) {
|
|
||||||
case EINTR:
|
|
||||||
tst_resm(TPASS, "expected failure - errno = %d : %s", TEST_ERRNO,
|
|
||||||
strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tst_resm(TFAIL, "call failed with an unexpected error - %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef UCLINUX
|
|
||||||
/*
|
|
||||||
* do_child_uclinux() - capture signals again, then run do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child_uclinux()
|
|
||||||
{
|
|
||||||
tst_sig(FORK, sighandler, cleanup);
|
|
||||||
|
|
||||||
do_child();
|
|
||||||
}
|
|
||||||
#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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
|
@ -1,248 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgrcv06.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgrcv06 - test for EIDRM error
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* loop if that option was specified
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* fork a child who sleeps on an attempted read with msgrcv()
|
|
||||||
* parent removes the queue then waits for child to complete
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EIDRM
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* child removes message queue if required
|
|
||||||
* parent callc cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgrcv06 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
|
|
||||||
void do_child(void);
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
void sighandler(int);
|
|
||||||
#ifdef UCLINUX
|
|
||||||
void do_child_uclinux(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *TCID = "msgrcv06";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int exp_enos[] = {EIDRM, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
|
|
||||||
MSGBUF rcv_buf;
|
|
||||||
pid_t c_pid;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef UCLINUX
|
|
||||||
maybe_run_child(&do_child_uclinux, "d", &msg_q_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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* set up the queue here so that multiple test iterations
|
|
||||||
* will work.
|
|
||||||
*/
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW))
|
|
||||||
== -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* fork a child that will attempt to read a non-existent
|
|
||||||
* message from the queue
|
|
||||||
*/
|
|
||||||
if ((c_pid = FORK_OR_VFORK()) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not fork");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c_pid == 0) { /* child */
|
|
||||||
/*
|
|
||||||
* Attempt to read a message without IPC_NOWAIT.
|
|
||||||
* With no message to read, the child sleeps.
|
|
||||||
*/
|
|
||||||
#ifdef UCLINUX
|
|
||||||
if (self_exec(av[0], "d", msg_q_1) < 0) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not self_exec");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
do_child();
|
|
||||||
#endif
|
|
||||||
} else { /* parent */
|
|
||||||
usleep(250000);
|
|
||||||
|
|
||||||
/* remove the queue */
|
|
||||||
rm_queue(msg_q_1);
|
|
||||||
|
|
||||||
waitpid(c_pid, NULL, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*NOTREACHED*/
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child()
|
|
||||||
{
|
|
||||||
TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
tst_resm(TFAIL, "call succeeded when error expected");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch(TEST_ERRNO) {
|
|
||||||
case EIDRM:
|
|
||||||
tst_resm(TPASS, "expected failure - errno = %d : %s", TEST_ERRNO,
|
|
||||||
strerror(TEST_ERRNO));
|
|
||||||
|
|
||||||
/* mark the queue as invalid as it was removed */
|
|
||||||
msg_q_1 = -1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tst_resm(TFAIL, "call failed with an unexpected error - %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if it exists, remove the message queue that was created */
|
|
||||||
rm_queue(msg_q_1);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef UCLINUX
|
|
||||||
/*
|
|
||||||
* do_child_uclinux() - capture signals again, then run do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child_uclinux()
|
|
||||||
{
|
|
||||||
tst_sig(FORK, sighandler, cleanup);
|
|
||||||
|
|
||||||
do_child();
|
|
||||||
}
|
|
||||||
#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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
|
||||||
* or premature exit.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
cleanup(void)
|
|
||||||
{
|
|
||||||
/* 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();
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
#
|
|
||||||
# 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)
|
|
|
@ -1,195 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgsnd01.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgsnd01 - test that msgsnd() enqueues a message correctly
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue
|
|
||||||
* initialize a message buffer with a known message and type
|
|
||||||
* loop if that option was specified
|
|
||||||
* enqueue the message
|
|
||||||
* check the return code
|
|
||||||
* if failure, issue a FAIL message.
|
|
||||||
* otherwise,
|
|
||||||
* if doing functionality testing
|
|
||||||
* stat the message queue
|
|
||||||
* check for # of bytes = MSGSIZE and # of messages = 1
|
|
||||||
* if correct,
|
|
||||||
* issue a PASS message
|
|
||||||
* otherwise
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgsnd01 [-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"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
|
|
||||||
char *TCID = "msgsnd01";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int msg_q_1;
|
|
||||||
MSGBUF msg_buf, rd_buf;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Use TEST macro to make the call
|
|
||||||
*/
|
|
||||||
|
|
||||||
TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
|
|
||||||
|
|
||||||
if (TEST_RETURN == -1) {
|
|
||||||
tst_resm(TFAIL, "%s call failed - errno = %d : %s",
|
|
||||||
TCID, TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (STD_FUNCTIONAL_TEST) {
|
|
||||||
|
|
||||||
/* get the queue status */
|
|
||||||
if (msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Could not "
|
|
||||||
"get queue status");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qs_buf.msg_cbytes != MSGSIZE) {
|
|
||||||
tst_resm(TFAIL, "queue bytes != MSGSIZE");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qs_buf.msg_qnum != 1) {
|
|
||||||
tst_resm(TFAIL, "queue message != 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
tst_resm(TPASS, "queue bytes = MSGSIZE and "
|
|
||||||
"queue messages = 1");
|
|
||||||
} else {
|
|
||||||
tst_resm(TPASS, "call succeeded");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* remove the message by reading from the queue
|
|
||||||
*/
|
|
||||||
if (msgrcv(msg_q_1, &rd_buf, MSGSIZE, 1, 0) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Could not read from queue");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permissions */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the message buffer */
|
|
||||||
init_buf(&msg_buf, MSGTYPE, MSGSIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 if it exists */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,206 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgsnd02.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgsnd02 - test for EACCES and EFAULT errors
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue without write permission
|
|
||||||
* create a trivial message buffer
|
|
||||||
* loop if that option was specified
|
|
||||||
* call msgsnd() using two different invalid cases
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EACCES or EFAULT
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgsnd02 [-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"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
|
|
||||||
char *TCID = "msgsnd02";
|
|
||||||
int TST_TOTAL = 2;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
char nobody_uid[] = "nobody";
|
|
||||||
struct passwd *ltpuser;
|
|
||||||
|
|
||||||
int exp_enos[] = {EACCES, EFAULT, 0};
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
MSGBUF msg_buf; /* a buffer for the message to queue */
|
|
||||||
int bad_q = -1; /* a value to use as a bad queue ID */
|
|
||||||
|
|
||||||
struct test_case_t {
|
|
||||||
int *queue_id;
|
|
||||||
MSGBUF *buffer;
|
|
||||||
int error;
|
|
||||||
} TC[] = {
|
|
||||||
/* EACCES - there is no write permission for the queue */
|
|
||||||
{&msg_q_1, &msg_buf, EACCES},
|
|
||||||
|
|
||||||
/* EFAULT - the message buffer address is invalid */
|
|
||||||
{&msg_q_1, NULL, EFAULT},
|
|
||||||
};
|
|
||||||
|
|
||||||
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(msgsnd(*(TC[i].queue_id), TC[i].buffer, 1, 0));
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/* 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();
|
|
||||||
|
|
||||||
/* create a message queue without write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the message buffer with something trivial */
|
|
||||||
msg_buf.mtype = MSGTYPE;
|
|
||||||
msg_buf.mtext[0] = 'a';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,205 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgsnd03.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgsnd03 - test for EINVAL error
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* create a trivial message buffer
|
|
||||||
* loop if that option was specified
|
|
||||||
* call msgsnd() using four different invalid cases
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EINVAL
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgsnd03 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
|
|
||||||
char *TCID = "msgsnd03";
|
|
||||||
int TST_TOTAL = 4;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
|
|
||||||
int exp_enos[] = {EINVAL, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
MSGBUF msg_buf; /* a buffer for the message to queue */
|
|
||||||
int bad_q = -1; /* a value to use as a bad queue ID */
|
|
||||||
|
|
||||||
struct test_case_t {
|
|
||||||
int *queue_id;
|
|
||||||
MSGBUF *buffer;
|
|
||||||
long mtype;
|
|
||||||
int msg_size;
|
|
||||||
int error;
|
|
||||||
} TC[] = {
|
|
||||||
/* EINVAL - the queue ID is invalid */
|
|
||||||
{&bad_q, &msg_buf, 1, 1, EINVAL},
|
|
||||||
|
|
||||||
/* EINVAL - the message type is not positive (0) */
|
|
||||||
{&msg_q_1, &msg_buf, 0, 1, EINVAL},
|
|
||||||
|
|
||||||
/* EINVAL - the message type is not positive (>0) */
|
|
||||||
{&msg_q_1, &msg_buf, -1, 1, EINVAL},
|
|
||||||
|
|
||||||
/* EINVAL - the message size is less than zero */
|
|
||||||
{&msg_q_1, &msg_buf, 1, -1, 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++) {
|
|
||||||
|
|
||||||
/* set the message type */
|
|
||||||
msg_buf.mtype = TC[i].mtype;
|
|
||||||
|
|
||||||
/* make the call with the TEST macro */
|
|
||||||
TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer,
|
|
||||||
TC[i].msg_size, 0));
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the message buffer with something trivial */
|
|
||||||
msg_buf.mtype = MSGTYPE;
|
|
||||||
msg_buf.mtext[0] = 'a';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,182 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgsnd04.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgsnd04 - test for EAGAIN error
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* initialize a message buffer with a known message and type
|
|
||||||
* enqueue the message in a loop until the queue is full
|
|
||||||
* loop if that option was specified
|
|
||||||
* attempt to enqueue another message - msgsnd()
|
|
||||||
* 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>
|
|
||||||
* msgsnd04 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
|
|
||||||
char *TCID = "msgsnd04";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int exp_enos[] = {EAGAIN, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
MSGBUF msg_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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Attempt to write another message to the full queue.
|
|
||||||
*/
|
|
||||||
|
|
||||||
TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
tst_resm(TFAIL, "call succeeded when error expected");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch(TEST_ERRNO) {
|
|
||||||
case EAGAIN:
|
|
||||||
tst_resm(TPASS, "expected failure - errno = %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tst_resm(TFAIL, "call failed with an "
|
|
||||||
"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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the message buffer */
|
|
||||||
init_buf(&msg_buf, MSGTYPE, MSGSIZE);
|
|
||||||
|
|
||||||
/* write messages to the queue until it is full */
|
|
||||||
while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
|
|
||||||
msg_buf.mtype += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,258 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgsnd05.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgsnd05 - test for EINTR error
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* initialize a message buffer with a known message and type
|
|
||||||
* enqueue the message in a loop until the queue is full
|
|
||||||
* loop if that option was specified
|
|
||||||
* fork a child process
|
|
||||||
* child attempts to enqueue a message to the full queue and sleeps
|
|
||||||
* parent sends a SIGHUP to the child then waits for the child to complete
|
|
||||||
* child get a return from msgsnd()
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EINTR
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* child exits, parent calls cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgsnd05 [-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 "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
|
|
||||||
void do_child(void);
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
void sighandler(int);
|
|
||||||
#ifdef UCLINUX
|
|
||||||
void do_child_uclinux(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *TCID = "msgsnd05";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int exp_enos[] = {EINTR, 0}; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
MSGBUF msg_buf;
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
int lc; /* loop counter */
|
|
||||||
char *msg; /* message returned from parse_opts */
|
|
||||||
pid_t c_pid;
|
|
||||||
|
|
||||||
/* 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, "d", &msg_q_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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* fork a child that will attempt to write a message
|
|
||||||
* to the queue without IPC_NOWAIT
|
|
||||||
*/
|
|
||||||
if ((c_pid = FORK_OR_VFORK()) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not fork");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c_pid == 0) { /* child */
|
|
||||||
/*
|
|
||||||
* Attempt to write another message to the full queue.
|
|
||||||
* Without the IPC_NOWAIT flag, the child sleeps
|
|
||||||
*/
|
|
||||||
#ifdef UCLINUX
|
|
||||||
if (self_exec(av[0], "d", msg_q_1) < 0) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not self_exec");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
do_child();
|
|
||||||
#endif
|
|
||||||
} else { /* parent */
|
|
||||||
usleep(250000);
|
|
||||||
|
|
||||||
/* send a signal that must be caught to the child */
|
|
||||||
if (kill(c_pid, SIGHUP) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "kill failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
waitpid(c_pid, NULL, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
/*NOTREACHED*/
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child()
|
|
||||||
{
|
|
||||||
TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
tst_resm(TFAIL, "call succeeded when error expected");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch(TEST_ERRNO) {
|
|
||||||
case EINTR:
|
|
||||||
tst_resm(TPASS, "expected failure - errno = %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tst_resm(TFAIL, "call failed with an unexpected error - %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef UCLINUX
|
|
||||||
/*
|
|
||||||
* do_child_uclinux() - capture signals, initialize buffer, then run do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child_uclinux()
|
|
||||||
{
|
|
||||||
/* initialize the message buffer */
|
|
||||||
init_buf(&msg_buf, MSGTYPE, MSGSIZE);
|
|
||||||
|
|
||||||
tst_sig(FORK, sighandler, cleanup);
|
|
||||||
|
|
||||||
do_child();
|
|
||||||
}
|
|
||||||
#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 in our own handler */
|
|
||||||
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();
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the message buffer */
|
|
||||||
init_buf(&msg_buf, MSGTYPE, MSGSIZE);
|
|
||||||
|
|
||||||
/* write messages to the queue until it is full */
|
|
||||||
while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
|
|
||||||
msg_buf.mtype += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 that was created */
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,239 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* msgsnd06.c
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
* msgsnd06 - test for EIDRM error
|
|
||||||
*
|
|
||||||
* ALGORITHM
|
|
||||||
* loop if that option was specified
|
|
||||||
* create a message queue with read/write permissions
|
|
||||||
* initialize a message buffer with a known message and type
|
|
||||||
* enqueue messages in a loop until the queue is full
|
|
||||||
* fork a child process
|
|
||||||
* child attempts to enqueue a message to the full queue and sleeps
|
|
||||||
* parent removes the queue and then exits
|
|
||||||
* child get a return from msgsnd()
|
|
||||||
* check the errno value
|
|
||||||
* issue a PASS message if we get EIDRM
|
|
||||||
* otherwise, the tests fails
|
|
||||||
* issue a FAIL message
|
|
||||||
* call cleanup
|
|
||||||
*
|
|
||||||
* USAGE: <for command-line>
|
|
||||||
* msgsnd06 [-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 <sys/wait.h>
|
|
||||||
#include "test.h"
|
|
||||||
#include "usctest.h"
|
|
||||||
|
|
||||||
#include "ipcmsg.h"
|
|
||||||
|
|
||||||
void cleanup(void);
|
|
||||||
void setup(void);
|
|
||||||
void do_child(void);
|
|
||||||
|
|
||||||
char *TCID = "msgsnd06";
|
|
||||||
int TST_TOTAL = 1;
|
|
||||||
extern int Tst_count;
|
|
||||||
|
|
||||||
int exp_enos[] = { EIDRM, 0 }; /* 0 terminated list of expected errnos */
|
|
||||||
|
|
||||||
int msg_q_1 = -1; /* The message queue id created in setup */
|
|
||||||
MSGBUF msg_buf;
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
int lc; /* loop counter */
|
|
||||||
char *msg; /* message returned from parse_opts */
|
|
||||||
pid_t c_pid;
|
|
||||||
int status, e_code;
|
|
||||||
|
|
||||||
/* 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, "d", &msg_q_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;
|
|
||||||
|
|
||||||
msgkey = getipckey();
|
|
||||||
|
|
||||||
/* create a message queue with read/write permission */
|
|
||||||
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW))
|
|
||||||
== -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the message buffer */
|
|
||||||
init_buf(&msg_buf, MSGTYPE, MSGSIZE);
|
|
||||||
|
|
||||||
/* write messages to the queue until it is full */
|
|
||||||
while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
|
|
||||||
msg_buf.mtype += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* fork a child that will attempt to write a message
|
|
||||||
* to the queue without IPC_NOWAIT
|
|
||||||
*/
|
|
||||||
if ((c_pid = FORK_OR_VFORK()) == -1) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not fork");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c_pid == 0) { /* child */
|
|
||||||
#ifdef UCLINUX
|
|
||||||
if (self_exec(av[0], "d", msg_q_1) < 0) {
|
|
||||||
tst_brkm(TBROK, cleanup, "could not self_exec");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
do_child();
|
|
||||||
#endif
|
|
||||||
} else { /* parent */
|
|
||||||
sleep(1);
|
|
||||||
/* remove the queue */
|
|
||||||
rm_queue(msg_q_1);
|
|
||||||
|
|
||||||
/* wait for the child to finish */
|
|
||||||
wait(&status);
|
|
||||||
/* make sure the child returned a good exit status */
|
|
||||||
e_code = status >> 8;
|
|
||||||
if (e_code != 0) {
|
|
||||||
tst_resm(TFAIL, "Failures reported above");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
/*NOTREACHED*/
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* do_child()
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
do_child()
|
|
||||||
{
|
|
||||||
int retval = 0;
|
|
||||||
|
|
||||||
#ifdef UCLINUX
|
|
||||||
/* initialize the message buffer */
|
|
||||||
init_buf(&msg_buf, MSGTYPE, MSGSIZE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Attempt to write another message to the full queue.
|
|
||||||
* Without the IPC_NOWAIT flag, the child sleeps
|
|
||||||
*/
|
|
||||||
TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
|
|
||||||
|
|
||||||
if (TEST_RETURN != -1) {
|
|
||||||
retval = 1;
|
|
||||||
tst_resm(TFAIL, "call succeeded when error expected");
|
|
||||||
exit(retval);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ERROR_LOG(TEST_ERRNO);
|
|
||||||
|
|
||||||
switch (TEST_ERRNO) {
|
|
||||||
case EIDRM:
|
|
||||||
tst_resm(TPASS, "expected failure - errno = %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
|
|
||||||
/* mark the queue as invalid as it was removed */
|
|
||||||
msg_q_1 = -1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
retval = 1;
|
|
||||||
tst_resm(TFAIL, "call failed with an unexpected error - %d : %s",
|
|
||||||
TEST_ERRNO, strerror(TEST_ERRNO));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
exit(retval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* setup() - performs all the ONE TIME setup for this test.
|
|
||||||
*/
|
|
||||||
void setup(void)
|
|
||||||
{
|
|
||||||
/* 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
|
||||||
* or premature exit.
|
|
||||||
*/
|
|
||||||
void cleanup(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* 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();
|
|
||||||
}
|
|
7
test/ipc/test.sh
Normal file
7
test/ipc/test.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
for d in semctl semget semop shmat shmctl shmdt shmget shmt
|
||||||
|
do echo $d
|
||||||
|
( cd $d
|
||||||
|
sh test.sh
|
||||||
|
)
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in a new issue