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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Mar 26 16:27:35 2015 +0100

testsuite/smokey: adapt/fix sigdebug for Cobalt

---

 testsuite/smokey/sigdebug/sigdebug.c |   89 +++++++++++++++-------------------
 1 file changed, 38 insertions(+), 51 deletions(-)

diff --git a/testsuite/smokey/sigdebug/sigdebug.c 
b/testsuite/smokey/sigdebug/sigdebug.c
index 27c3263..aa04301 100644
--- a/testsuite/smokey/sigdebug/sigdebug.c
+++ b/testsuite/smokey/sigdebug/sigdebug.c
@@ -20,10 +20,13 @@
 #include <pthread.h>
 #include <semaphore.h>
 #include <asm/unistd.h>
+#include <sys/cobalt.h>
 #include <smokey/smokey.h>
 
 smokey_test_plugin(sigdebug,
-                  SMOKEY_NOARGS,
+                  SMOKEY_ARGLIST(
+                          SMOKEY_BOOL(no_watchdog),
+                  ),
                   "Check SIGDEBUG reporting."
 );
 
@@ -88,15 +91,17 @@ static void *rt_thread_body(void *cookie)
        unsigned long long end;
        int err;
 
+       err = pthread_setname_np(pthread_self(), "test");
+       check_no_error("pthread_setname_np", err);
        err = pthread_setmode_np(0, PTHREAD_WARNSW, NULL);
        check_no_error("pthread_setmode_np", err);
 
-       printf("syscall\n");
+       smokey_note("syscall\n");
        setup_checkdebug(SIGDEBUG_MIGRATE_SYSCALL);
        syscall(__NR_gettid);
        check_sigdebug_received("SIGDEBUG_MIGRATE_SYSCALL");
 
-       printf("signal\n");
+       smokey_note("signal\n");
        setup_checkdebug(SIGDEBUG_MIGRATE_SIGNAL);
        err = sem_post(&send_signal);
        check_no_error("sem_post", err);
@@ -104,13 +109,13 @@ static void *rt_thread_body(void *cookie)
        check_no_error("clock_nanosleep", err);
        check_sigdebug_received("SIGDEBUG_MIGRATE_SIGNAL");
 
-       printf("relaxed mutex owner\n");
+       smokey_note("relaxed mutex owner\n");
        setup_checkdebug(SIGDEBUG_MIGRATE_PRIOINV);
        err = pthread_mutex_lock(&prio_invert);
        check_no_error("pthread_mutex_lock", err);
        check_sigdebug_received("SIGDEBUG_MIGRATE_PRIOINV");
 
-       printf("page fault\n");
+       smokey_note("page fault\n");
        setup_checkdebug(SIGDEBUG_MIGRATE_FAULT);
        delay.tv_nsec = 0;
        err = clock_nanosleep(CLOCK_MONOTONIC, 0, &delay, NULL);
@@ -119,7 +124,7 @@ static void *rt_thread_body(void *cookie)
        check_sigdebug_received("SIGDEBUG_MIGRATE_FAULT");
 
        if (wd) {
-               printf("watchdog\n");
+               smokey_note("watchdog\n");
                rt_print_flush_buffers();
                setup_checkdebug(SIGDEBUG_WATCHDOG);
                clock_gettime(CLOCK_MONOTONIC, &now);
@@ -131,9 +136,10 @@ static void *rt_thread_body(void *cookie)
                while (now.tv_sec * 1000000000ULL + now.tv_nsec < end &&
                         !sigdebug_received);
                check_sigdebug_received("SIGDEBUG_WATCHDOG");
-       }
+       } else
+               smokey_note("watchdog not tested\n");
 
-       printf("lock break\n");
+       smokey_note("lock break\n");
        setup_checkdebug(SIGDEBUG_LOCK_BREAK);
        err = pthread_setmode_np(0, PTHREAD_LOCK_SCHED |
                                    PTHREAD_DISABLE_LOCKBREAK, NULL);
@@ -163,62 +169,40 @@ static void dummy_handler(int sig, siginfo_t *si, void 
*context)
 {
 }
 
+static void fault_handler(int sig)
+{
+       mprotect(mem, 1, PROT_WRITE);
+}
+
 static int run_sigdebug(struct smokey_test *t, int argc, char *const argv[])
 {
        char tempname[] = "/tmp/sigdebug-XXXXXX";
-       char buf[BUFSIZ], dev[BUFSIZ];
        struct sched_param params = {.sched_priority = 1};
        pthread_t rt_thread;
        pthread_attr_t attr;
        pthread_mutexattr_t mutex_attr;
        struct timespec delay = {.tv_sec = 0, .tv_nsec = 20000000ULL};
-       long int start, trash, end;
-       unsigned char *mayday, *p;
+       int err, debug, tmp_fd;
        struct sigaction sa;
        int old_wd_value;
-       char r, w, x, s;
-       int tmp_fd, d;
-       FILE *maps;
-       int err;
 
-       rt_print_auto_init(1);
+       err = cobalt_corectl(_CC_COBALT_GET_DEBUG, &debug, sizeof(debug));
+       if (err || (debug & _CC_COBALT_DEBUG_USER) == 0)
+               return -ENOSYS;
 
-       if (argc < 2 || strcmp(argv[1], "--skip-watchdog") != 0) {
+       smokey_parse_args(t, argc, argv);
+       if (!SMOKEY_ARG_ISSET(sigdebug, no_watchdog) ||
+           !SMOKEY_ARG_BOOL(sigdebug, no_watchdog)) {
                wd = fopen("/sys/module/xenomai/parameters/watchdog_timeout",
                           "w+");
-               if (!wd) {
-                       fprintf(stderr, "FAILURE: no watchdog available and "
-                                       "--skip-watchdog not specified\n");
-                       exit(EXIT_FAILURE);
-               }
-               err = fscanf(wd, "%d", &old_wd_value);
-               check("get watchdog", err, 1);
-               err = fprintf(wd, "2");
-               check("set watchdog", err, 1);
-               fflush(wd);
-       }
-
-       maps = fopen("/proc/self/maps", "r");
-       if (maps == NULL) {
-               perror("open /proc/self/maps");
-               exit(EXIT_FAILURE);
-       }
-
-       while (fgets(buf, sizeof(buf), maps)) {
-               if (sscanf(buf, "%lx-%lx %c%c%c%c %lx %x:%x %d%s\n",
-                          &start, &end, &r, &w, &x, &s, &trash,
-                          &d, &d, &d, dev) == 11
-                   && r == 'r' && x == 'x'
-                   && !strcmp(dev, "/dev/rtheap") && end - start == 4096) {
-                       printf("mayday page starting at 0x%lx [%s]\n"
-                              "mayday code:", start, dev);
-                       mayday = (unsigned char *)start;
-                       for (p = mayday; p < mayday + 32; p++)
-                               printf(" %.2x", *p);
-                       printf("\n");
+               if (wd) {
+                       err = fscanf(wd, "%d", &old_wd_value);
+                       check("get watchdog", err, 1);
+                       err = fprintf(wd, "2");
+                       check("set watchdog", err, 1);
+                       fflush(wd);
                }
        }
-       fclose(maps);
 
        sigemptyset(&sa.sa_mask);
        sa.sa_sigaction = sigdebug_handler;
@@ -228,12 +212,15 @@ static int run_sigdebug(struct smokey_test *t, int argc, 
char *const argv[])
        sa.sa_sigaction = dummy_handler;
        sigaction(SIGUSR1, &sa, NULL);
 
+       sa.sa_handler = fault_handler;
+       sigaction(SIGSEGV, &sa, NULL);
+
        errno = 0;
        tmp_fd = mkstemp(tempname);
        check_no_error("mkstemp", -errno);
        unlink(tempname);
        check_no_error("unlink", -errno);
-       mem = mmap(NULL, 1, PROT_READ | PROT_WRITE, MAP_SHARED, tmp_fd, 0);
+       mem = mmap(NULL, 1, PROT_READ, MAP_SHARED, tmp_fd, 0);
        check_no_error("mmap", -errno);
        err = write(tmp_fd, "X", 1);
        check("write", err, 1);
@@ -264,7 +251,7 @@ static int run_sigdebug(struct smokey_test *t, int argc, 
char *const argv[])
        err = pthread_attr_setschedparam(&attr, &params);
        check_no_error("pthread_attr_setschedparam", err);
 
-       printf("mlockall\n");
+       smokey_note("mlockall\n");
        munlockall();
        setup_checkdebug(SIGDEBUG_NOMLOCK);
        err = pthread_create(&rt_thread, &attr, rt_thread_body, NULL);
@@ -277,7 +264,7 @@ static int run_sigdebug(struct smokey_test *t, int argc, 
char *const argv[])
 
        err = sem_wait(&send_signal);
        check_no_error("sem_wait", err);
-       err = __real_pthread_kill(rt_thread, SIGUSR1);
+       err = __STD(pthread_kill(rt_thread, SIGUSR1));
        check_no_error("pthread_kill", err);
 
        __STD(nanosleep(&delay, NULL));


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

Reply via email to