Module: xenomai-3
Branch: next
Commit: 67a74febd420c1b88fd4712dee277a1d00d6c85f
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=67a74febd420c1b88fd4712dee277a1d00d6c85f

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Jun 20 11:58:00 2015 +0200

testsuite/smokey: add POSIX select testing code

---

 configure.ac                                       |    1 +
 include/smokey/smokey.h                            |   11 ++
 testsuite/regression/posix/Makefile.am             |    1 -
 testsuite/smokey/Makefile.am                       |    2 +
 testsuite/smokey/posix-select/Makefile.am          |   10 ++
 .../posix-select/posix-select.c}                   |  105 ++++++++++++--------
 6 files changed, 88 insertions(+), 42 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7abd18c..c9aed45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -931,6 +931,7 @@ AC_CONFIG_FILES([ \
        testsuite/smokey/posix-mutex/Makefile \
        testsuite/smokey/posix-clock/Makefile \
        testsuite/smokey/posix-fork/Makefile \
+       testsuite/smokey/posix-select/Makefile \
        testsuite/smokey/xddp/Makefile \
        testsuite/smokey/iddp/Makefile \
        testsuite/smokey/bufp/Makefile \
diff --git a/include/smokey/smokey.h b/include/smokey/smokey.h
index bf968f7..0a7b5e9 100644
--- a/include/smokey/smokey.h
+++ b/include/smokey/smokey.h
@@ -108,6 +108,17 @@ struct smokey_test {
                __ret;                                                  \
        })
 
+#define smokey_check_status(__expr)                                    \
+       ({                                                              \
+               int __ret = (__expr);                                   \
+               if (__ret) {                                            \
+                       smokey_warning(__FILE__, __LINE__, "%s: %s",    \
+                                      #__expr, strerror(__ret));       \
+                       __ret = -__ret;                                 \
+               }                                                       \
+               __ret;                                                  \
+       })
+
 #define smokey_assert(__expr)                                          \
        ({                                                              \
                int __ret = (__expr);                                   \
diff --git a/testsuite/regression/posix/Makefile.am 
b/testsuite/regression/posix/Makefile.am
index f78c244..c878630 100644
--- a/testsuite/regression/posix/Makefile.am
+++ b/testsuite/regression/posix/Makefile.am
@@ -6,7 +6,6 @@ noinst_HEADERS = check.h
 
 test_PROGRAMS = \
        leaks \
-       mq_select \
        timerfd
 
 CPPFLAGS = $(XENO_USER_CFLAGS)                 \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index 2229871..397872e 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -15,6 +15,7 @@ SUBDIRS =             \
        posix-cond      \
        posix-fork      \
        posix-mutex     \
+       posix-select    \
        rtdm            \
        sched-quota     \
        sched-tp        \
@@ -55,6 +56,7 @@ DIST_SUBDIRS =                \
        posix-cond      \
        posix-fork      \
        posix-mutex     \
+       posix-select    \
        rtdm            \
        sched-quota     \
        sched-tp        \
diff --git a/testsuite/smokey/posix-select/Makefile.am 
b/testsuite/smokey/posix-select/Makefile.am
new file mode 100644
index 0000000..40b8839
--- /dev/null
+++ b/testsuite/smokey/posix-select/Makefile.am
@@ -0,0 +1,10 @@
+
+noinst_LIBRARIES = libposix-select.a
+
+libposix_select_a_SOURCES = posix-select.c
+
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
+
+libposix_select_a_CPPFLAGS =   \
+       @XENO_USER_CFLAGS@      \
+       -I$(top_srcdir)/include
diff --git a/testsuite/regression/posix/mq_select.c 
b/testsuite/smokey/posix-select/posix-select.c
similarity index 55%
rename from testsuite/regression/posix/mq_select.c
rename to testsuite/smokey/posix-select/posix-select.c
index f0882bb..18a2b6b 100644
--- a/testsuite/regression/posix/mq_select.c
+++ b/testsuite/smokey/posix-select/posix-select.c
@@ -20,21 +20,21 @@
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
 #include <errno.h>
-
 #include <unistd.h>
-#include <signal.h>
 #include <mqueue.h>
 #include <pthread.h>
 #include <sys/select.h>
-#include <sys/mman.h>
+#include <smokey/smokey.h>
 
-#include "check.h"
+smokey_test_plugin(posix_select,
+                  SMOKEY_NOARGS,
+                  "Check POSIX select service"
+);
 
 static const char *tunes[] = {
     "Surfing With The Alien",
@@ -55,64 +55,87 @@ static const char *tunes[] = {
     "Engines Of Creation"
 };
 
-static void *task(void *cookie)
+static int test_status;
+
+static void *mq_thread(void *cookie)
 {
        mqd_t mqd = (mqd_t)(long)cookie;
-       fd_set inset;
-       unsigned i;
+       unsigned int i = 0, prio;
+       fd_set inset, tmp_inset;
+       char buf[128];
+       int ret;
 
        FD_ZERO(&inset);
        FD_SET(mqd, &inset);
 
-       for(i = 0; i < sizeof(tunes)/sizeof(tunes[0]); i++) {
-               fd_set tmp_inset = inset;
-               unsigned prio;
-               char buf[128];
+       for (;;) {
+               tmp_inset = inset;
 
-               check_unix(select(mqd + 1, &tmp_inset, NULL, NULL, NULL));
+               ret = smokey_check_errno(select(mqd + 1, &tmp_inset, NULL, 
NULL, NULL));
+               if (ret < 0) {
+                       test_status = ret;
+                       break;
+               }
 
-               check_unix(mq_receive(mqd, buf, sizeof(buf), &prio));
+               ret = smokey_check_errno(mq_receive(mqd, buf, sizeof(buf), 
&prio));
+               if (ret < 0) {
+                       test_status = ret;
+                       break;
+               }
 
-               if (strcmp(buf, tunes[i])) {
-                       fprintf(stderr, "Received %s instead of %s\n",
-                               buf, tunes[i]);
-                       exit(EXIT_FAILURE);
+               if (strcmp(buf, "/done") == 0)
+                       break;
+       
+               if (!smokey_assert(strcmp(buf, tunes[i]) == 0)) {
+                       test_status = -EINVAL;
+                       break;
                }
-               fprintf(stderr, "Received %s\n", buf);
+
+               smokey_note("received %s", buf);
+               i = (i + 1) % (sizeof(tunes) / sizeof(tunes[0]));
        }
 
        return NULL;
 }
 
-int main(void)
+static int run_posix_select(struct smokey_test *t, int argc, char *const 
argv[])
 {
        struct mq_attr qa;
        pthread_t tcb;
+       int i, j, ret;
        mqd_t mq;
-       int i;
-
-       fprintf(stderr, "Checking select service with posix message queues\n");
 
        mq_unlink("/select_test_mq");
-
        qa.mq_maxmsg = 128;
        qa.mq_msgsize = 128;
-       mq = mq_open("/select_test_mq", O_RDWR | O_CREAT | O_NONBLOCK, 0, &qa);
-       check_unix(mq == -1 ? -1 : 0);
-
-       check_pthread(pthread_create(&tcb, NULL, task, (void *)(long)mq));
-
-       alarm(30);
-
-       for(i = 0; i < sizeof(tunes) / sizeof(tunes[0]); i++) {
-               check_unix(mq_send(mq, tunes[i], strlen(tunes[i]) + 1, 0));
-
-               sleep(1);
+       mq = smokey_check_errno(mq_open("/select_test_mq", O_RDWR | O_CREAT | 
O_NONBLOCK, 0, &qa));
+       if (mq < 0)
+               return mq;
+
+       ret = smokey_check_status(pthread_create(&tcb, NULL, mq_thread, (void 
*)(long)mq));
+       if (ret)
+               return ret;
+
+       for (j = 0; j < 3; j++) {
+               for (i = 0; i < sizeof(tunes) / sizeof(tunes[0]); i++) {
+                       ret = smokey_check_errno(mq_send(mq, tunes[i], 
strlen(tunes[i]) + 1, 0));
+                       if (ret < 0) {
+                               smokey_check_status(pthread_cancel(tcb));
+                               goto out;
+                       }
+                       usleep(100000);
+               }
        }
-
-       check_pthread(pthread_join(tcb, NULL));
-
-       fprintf(stderr, "select service with posix message queues: success\n");
-
-       return EXIT_SUCCESS;
+       ret = smokey_check_errno(mq_send(mq, "/done", sizeof "/done", 0));
+       if (ret < 0) {
+               smokey_check_status(pthread_cancel(tcb));
+               goto out;
+       }
+       usleep(300000);
+       smp_rmb();
+       ret = test_status;
+out:
+       pthread_join(tcb, NULL);
+       
+       return ret;
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to