msgrcv/msgrcv07.c: add MSG_EXCEPT, MSG_NOERROR flag test

create a new case to test MSG_EXCEPT, MSG_NOERROR flag for msgrcv(2)

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
diff --git a/runtest/ltplite b/runtest/ltplite
index c34c589..bed8e10 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -490,6 +490,7 @@
 msgrcv04 msgrcv04
 msgrcv05 msgrcv05
 msgrcv06 msgrcv06
+msgrcv07 msgrcv07
 
 msgsnd01 msgsnd01
 msgsnd02 msgsnd02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 27667d2..9046c9b 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -413,6 +413,7 @@
 msgrcv04 msgrcv04
 msgrcv05 msgrcv05
 msgrcv06 msgrcv06
+msgrcv07 msgrcv07
 
 msgsnd01 msgsnd01
 msgsnd02 msgsnd02
diff --git a/runtest/syscalls b/runtest/syscalls
index aec49ad..2d51fb6 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -644,6 +644,7 @@
 msgrcv04 msgrcv04
 msgrcv05 msgrcv05
 msgrcv06 msgrcv06
+msgrcv07 msgrcv07
 
 msgsnd01 msgsnd01
 msgsnd02 msgsnd02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 02b6e45..bd9bf30 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -23,6 +23,7 @@
 msgrcv04 msgrcv04
 msgrcv05 msgrcv05
 msgrcv06 msgrcv06
+msgrcv07 msgrcv07
 
 msgsnd01 msgsnd01
 msgsnd02 msgsnd02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d461569..42b0eed 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -390,6 +390,7 @@
 /ipc/msgrcv/msgrcv04
 /ipc/msgrcv/msgrcv05
 /ipc/msgrcv/msgrcv06
+/ipc/msgrcv/msgrcv07
 /ipc/msgsnd/msgsnd01
 /ipc/msgsnd/msgsnd02
 /ipc/msgsnd/msgsnd03
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
new file mode 100644
index 0000000..aac0b44
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * Description:
+ *     Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR
+ */
+
+#define  _GNU_SOURCE
+#include <sys/wait.h>
+#include "test.h"
+#include "usctest.h"
+#include "ipcmsg.h"
+
+
+#define MSGTYPE1	1
+#define MSGTYPE2	2
+#define MSG1	"message type1"
+#define MSG2	"message type2"
+
+static void wait4child(pid_t child, char *tst_flag);
+
+static void test_msg_except(void);
+static void test_msg_noerror(void);
+
+static void (*testfunc[])(void) = { test_msg_except, test_msg_noerror };
+
+char *TCID = "msgrcv07";
+int TST_TOTAL = ARRAY_SIZE(testfunc);
+
+int main(int ac, char **av)
+{
+	int lc;
+	char *msg;
+	int i;
+
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; i++)
+			(*testfunc[i])();
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+void setup(void)
+{
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+}
+
+static void test_msg_except(void)
+{
+	pid_t child_pid;
+	int msgq_id;
+	MSGBUF snd_buf1 = {.mtype = MSGTYPE1, .mtext = MSG1};
+	MSGBUF snd_buf2 = {.mtype = MSGTYPE2, .mtext = MSG2};
+	MSGBUF rcv_buf;
+
+	msgq_id = msgget(IPC_PRIVATE, MSG_RW);
+	if (msgq_id == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Can't create message queue");
+
+	if (msgsnd(msgq_id, &snd_buf1, MSGSIZE, 0) == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Can't enqueue message");
+
+	if (msgsnd(msgq_id, &snd_buf2, MSGSIZE, 0) == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Can't enqueue message");
+
+	child_pid = tst_fork();
+	if (child_pid == -1) {
+		tst_brkm(TBROK, cleanup, "fork failed");
+	} else if (child_pid > 0) {
+		wait4child(child_pid, "MSG_EXCEPT");
+	} else {
+		memset(&rcv_buf, 0, sizeof(rcv_buf));
+		TEST(msgrcv(msgq_id, &rcv_buf, MSGSIZE, MSGTYPE2, MSG_EXCEPT));
+		if (TEST_RETURN == -1) {
+			fprintf(stderr, "msgrcv(MSG_EXCEPT) failed\n");
+			exit(TBROK);
+		}
+		/* check the received message */
+		if (strcmp(rcv_buf.mtext, MSG1) == 0 &&
+		    rcv_buf.mtype == MSGTYPE1)
+			exit(TPASS);
+		else
+			exit(TFAIL);
+	}
+
+	rm_queue(msgq_id);
+}
+
+
+static void test_msg_noerror(void)
+{
+	pid_t child_pid;
+	int msg_len, msgq_id;
+	MSGBUF snd_buf1 = {.mtype = MSGTYPE1, .mtext = MSG1};
+	MSGBUF rcv_buf;
+
+	msgq_id = msgget(IPC_PRIVATE, MSG_RW);
+	if (msgq_id == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Can't create message queue");
+
+	if (msgsnd(msgq_id, &snd_buf1, MSGSIZE, 0) == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Can't enqueue message");
+
+	child_pid = tst_fork();
+	if (child_pid == -1) {
+		tst_brkm(TBROK, cleanup, "fork failed");
+	} else if (child_pid > 0) {
+		wait4child(child_pid, "MSG_NOERROR");
+	} else {
+		msg_len = sizeof(MSG1) / 2;
+		memset(&rcv_buf, 0, sizeof(rcv_buf));
+
+		TEST(msgrcv(msgq_id, &rcv_buf, msg_len, MSGTYPE1, MSG_NOERROR));
+		if (TEST_RETURN == -1)
+			exit(TFAIL);
+
+		if (strncmp(rcv_buf.mtext, MSG1, msg_len) == 0 &&
+		    rcv_buf.mtype == MSGTYPE1)
+			exit(TPASS);
+		exit(TFAIL);
+	}
+
+	rm_queue(msgq_id);
+}
+
+static void wait4child(pid_t child, char *tst_flag)
+{
+	int status;
+	int ret;
+
+	if (waitpid(child, &status, 0) == -1)
+		tst_resm(TBROK | TERRNO, "waitpid");
+	if (WIFEXITED(status)) {
+		ret = WEXITSTATUS(status);
+		if (ret == 0)
+			tst_resm(TPASS, "test %s success", tst_flag);
+		else if (ret == 1)
+			tst_resm(TFAIL, "test %s failed", tst_flag);
+		else
+			tst_brkm(TBROK, cleanup, "msgrcv failed unexpectedly");
+	} else {
+		tst_brkm(TBROK, cleanup, "child process terminated "
+			 "abnormally. status: %d", status);
+	}
+}
+
+void cleanup(void)
+{
+	TEST_CLEANUP;
+}