Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel Convert to ATF format the old src/regress/ styl...



details:   https://anonhg.NetBSD.org/src/rev/d5f678d988dc
branches:  trunk
changeset: 782528:d5f678d988dc
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Nov 05 04:09:14 2012 +0000

description:
Convert to ATF format the old src/regress/ style tests for Sys V IPC

diffstat:

 tests/kernel/Makefile |    3 +-
 tests/kernel/t_sysv.c |  841 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 843 insertions(+), 1 deletions(-)

diffs (truncated from 862 to 300 lines):

diff -r 7c8e1bd61f12 -r d5f678d988dc tests/kernel/Makefile
--- a/tests/kernel/Makefile     Mon Nov 05 01:25:25 2012 +0000
+++ b/tests/kernel/Makefile     Mon Nov 05 04:09:14 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.27 2012/11/03 05:19:33 pgoyette Exp $
+# $NetBSD: Makefile,v 1.28 2012/11/05 04:09:14 pgoyette Exp $
 
 NOMAN=         # defined
 
@@ -10,6 +10,7 @@
 TESTS_C=       t_lock
 TESTS_C+=      t_pty
 TESTS_C+=      t_mqueue
+TESTS_C+=      t_sysv
 TESTS_C+=      t_subr_prf
 
 TESTS_SH=      t_umount
diff -r 7c8e1bd61f12 -r d5f678d988dc tests/kernel/t_sysv.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/kernel/t_sysv.c     Mon Nov 05 04:09:14 2012 +0000
@@ -0,0 +1,841 @@
+/*     $NetBSD: t_sysv.c,v 1.1 2012/11/05 04:09:14 pgoyette Exp $      */
+
+/*-
+ * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center, and by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Test the SVID-compatible Message Queue facility.
+ */
+
+#include <atf-c.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/param.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
+#include <sys/wait.h>
+
+volatile int did_sigsys, did_sigchild;
+volatile int child_status, child_count;
+
+void   sigsys_handler(int);
+void   sigchld_handler(int);
+
+void   print_msqid_ds(struct msqid_ds *, mode_t);
+void   cleanup_msg(void);
+void   receiver(void);
+
+void   print_semid_ds(struct semid_ds *, mode_t);
+void   cleanup_sem(void);
+void   waiter(void);
+
+void   print_shmid_ds(struct shmid_ds *, mode_t);
+void   cleanup_shm(void);
+void   sharer(void);
+
+#define        MESSAGE_TEXT_LEN        256
+
+struct mymsg {
+       long    mtype;
+       char    mtext[MESSAGE_TEXT_LEN];
+};
+
+const char *m1_str = "California is overrated.";
+const char *m2_str = "The quick brown fox jumped over the lazy dog.";
+
+size_t pgsize;
+
+#define        MTYPE_1         1
+#define        MTYPE_1_ACK     2
+
+#define        MTYPE_2         3
+#define        MTYPE_2_ACK     4
+
+int    sender_msqid = -1;
+int    sender_semid = -1;
+int    sender_shmid = -1;
+pid_t  child_pid;
+
+char   token_key[64];
+
+key_t  msgkey, semkey, shmkey;
+
+int    maxloop = 1;
+
+union semun {
+       int     val;            /* value for SETVAL */
+       struct  semid_ds *buf;  /* buffer for IPC_{STAT,SET} */
+       u_short *array;         /* array for GETALL & SETALL */
+};
+
+
+void
+sigsys_handler(int signo)
+{
+
+       did_sigsys = 1;
+}
+
+void
+sigchld_handler(int signo)
+{
+       int c_status;
+
+       did_sigchild = 1;
+       /*
+        * Reap the child and return its status
+        */
+       if (wait(&c_status) == -1)
+               child_status = -errno;
+       else
+               child_status = c_status;
+
+       child_count--;
+}
+
+ATF_TC(msg);
+ATF_TC_HEAD(msg, tc)
+{  
+
+       atf_tc_set_md_var(tc, "timeout", "3");
+       atf_tc_set_md_var(tc, "descr", "Checks sysvmsg passing");
+}
+
+ATF_TC_BODY(msg, tc)
+{
+       struct sigaction sa;
+       struct msqid_ds m_ds;
+       struct mymsg m;
+       sigset_t sigmask;
+       int loop;
+       int c_status;
+
+       /*
+        * Install a SIGSYS handler so that we can exit gracefully if
+        * System V Message Queue support isn't in the kernel.
+        */
+       did_sigsys = 0;
+       sa.sa_handler = sigsys_handler;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = 0;
+       ATF_REQUIRE_MSG(sigaction(SIGSYS, &sa, NULL) != -1,
+           "sigaction SIGSYS: %d", errno);
+
+       /*
+        * Install a SIGCHLD handler to deal with all possible exit
+        * conditions of the receiver.
+        */
+       did_sigchild = 0;
+       child_count = 0;
+       sa.sa_handler = sigchld_handler;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = 0;
+       ATF_REQUIRE_MSG(sigaction(SIGCHLD, &sa, NULL) != -1,
+           "sigaction SIGCHLD: %d", errno);
+
+       msgkey = ftok(token_key, 4160);
+       ATF_REQUIRE_MSG(msgkey != (key_t)-1, "ftok failed");
+
+       /*
+        * Initialize child_pid to ourselves so that the cleanup function
+        * works before we create the receiver.
+        */
+       child_pid = getpid();
+
+       /*
+        * Make sure that when the sender exits, the message queue is
+        * removed.
+        */
+       ATF_REQUIRE_MSG(atexit(cleanup_msg) != -1, "atexit:%d", errno);
+
+       sender_msqid = msgget(msgkey, IPC_CREAT | 0640);
+       ATF_REQUIRE_MSG(sender_msqid != -1, "msgget: %d", errno);
+
+       if (did_sigsys) {
+               atf_tc_skip("SYSV Message Queue not supported");
+               return;
+       }
+
+       ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, &m_ds) != -1,
+       "msgctl IPC_STAT 1: %d", errno);
+
+       print_msqid_ds(&m_ds, 0640);
+
+       m_ds.msg_perm.mode = (m_ds.msg_perm.mode & ~0777) | 0600;
+
+       ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_SET, &m_ds) != -1,
+           "msgctl IPC_SET: %d", errno);
+
+       memset(&m_ds, 0, sizeof(m_ds));
+
+       ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, &m_ds) != -1,
+           "msgctl IPC_STAT 2: %d", errno);
+
+       ATF_REQUIRE_MSG((m_ds.msg_perm.mode & 0777) == 0600,
+           "IPC_SET of mode didn't hold");
+
+       print_msqid_ds(&m_ds, 0600);
+
+       switch ((child_pid = fork())) {
+       case -1:
+               atf_tc_fail("fork: %d", errno);
+               return;
+
+       case 0:
+               child_count++;
+               receiver();
+               break;
+
+       default:
+               break;
+       }
+
+       for (loop = 0; loop < maxloop; loop++) {
+               /*
+                * Send the first message to the receiver and wait for the ACK.
+                */
+               m.mtype = MTYPE_1;
+               strcpy(m.mtext, m1_str);
+               ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, sizeof(m), 0) != -1,
+                   "sender: msgsnd 1: %d", errno);
+
+               ATF_REQUIRE_MSG(msgrcv(sender_msqid, &m, sizeof(m),
+                                      MTYPE_1_ACK, 0) == sizeof(m),
+                   "sender: msgrcv 1 ack: %d", errno);
+
+               print_msqid_ds(&m_ds, 0600);
+
+               /*
+                * Send the second message to the receiver and wait for the ACK.
+                */
+               m.mtype = MTYPE_2;
+               strcpy(m.mtext, m2_str);
+               ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, sizeof(m), 0) != -1,
+                   "sender: msgsnd 2: %d", errno);
+
+               ATF_REQUIRE_MSG(msgrcv(sender_msqid, &m, sizeof(m),
+                                      MTYPE_2_ACK, 0) == sizeof(m),
+                   "sender: msgrcv 2 ack: %d", errno);
+       }
+
+       /*
+        * Wait for child to finish
+        */
+       sigemptyset(&sigmask);
+       (void) sigsuspend(&sigmask);
+
+       /*
+        * ...and any other signal is an unexpected error.
+        */
+       if (did_sigchild) {
+               c_status = child_status;
+               if (c_status < 0)
+                       atf_tc_fail("waitpid: %d", -c_status);
+               else if (WIFEXITED(c_status) == 0)
+                       atf_tc_fail("child abnormal exit: %d", c_status);
+               else if (WEXITSTATUS(c_status) != 0)
+                       atf_tc_fail("c status: %d", WEXITSTATUS(c_status));
+               else {
+                       ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, &m_ds)
+                           != -1, "msgctl IPC_STAT: %d", errno);
+



Home | Main Index | Thread Index | Old Index