Re: [Xenomai-core] [Xenomai-git] Jan Kiszka : Add regression test for mprotect on pinned memory

2012-04-02 Thread Gilles Chanteperdrix
On 04/02/2012 04:09 PM, GIT version control wrote:
> Module: xenomai-jki
> Branch: for-upstream
> Commit: 410e90d085d21dc913f8724efafe6ae75bd3c952
> URL:
> http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=410e90d085d21dc913f8724efafe6ae75bd3c952
> 
> Author: Jan Kiszka 
> Date:   Fri Mar 30 18:06:27 2012 +0200
> 
> Add regression test for mprotect on pinned memory
> 
> This tests both the original issue of mprotect reintroducing COW pages
> to Xenomai processes as well as the recently fixed zero page corruption.
> 
> Signed-off-by: Jan Kiszka 
> +static void check_inner(const char *fn, int line, const char *msg,
> + int status, int expected)
> +{
> + if (status == expected)
> + return;
> +
> + rt_task_set_mode(T_WARNSW, 0, NULL);
> + rt_print_flush_buffers();
> (...)
> +static void check_value_inner(const char *fn, int line, const char *msg,
> +   int value, int expected)
> +{
> + if (value == expected)
> + return;
> +
> + rt_task_set_mode(T_WARNSW, 0, NULL);
> + rt_print_flush_buffers();
> (...)
> +void sigdebug_handler(int sig, siginfo_t *si, void *context)
> +{
> + unsigned int reason = si->si_value.sival_int;
> +
> + rt_print_flush_buffers();
> (...)
> +
> + rt_task_set_mode(T_WARNSW, 0, NULL);
> + rt_print_flush_buffers();

Maybe you could use posix skin's printf instead of putting calls to
rt_print_flush_buffers all over the place? I did not mean for this call
to be exported, I only added it for internal use by the posix skin.

-- 
Gilles.

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


[Xenomai-core] [PATCH 2.6] Add regression test for mprotect on pinned memory

2012-04-02 Thread Jan Kiszka
This tests both the original issue of mprotect reintroducing COW pages
to Xenomai processes as well as the recently fixed zero page corruption.

Signed-off-by: Jan Kiszka 
---
 src/testsuite/regression/native/Makefile.am |2 +-
 src/testsuite/regression/native/Makefile.in |   16 +++-
 src/testsuite/regression/native/mprotect.c  |  128 +++
 3 files changed, 142 insertions(+), 4 deletions(-)
 create mode 100644 src/testsuite/regression/native/mprotect.c

diff --git a/src/testsuite/regression/native/Makefile.am 
b/src/testsuite/regression/native/Makefile.am
index ce53834..afd2f43 100644
--- a/src/testsuite/regression/native/Makefile.am
+++ b/src/testsuite/regression/native/Makefile.am
@@ -2,7 +2,7 @@ tstdir = @XENO_TEST_DIR@/regression/native
 
 noinst_HEADERS = check.h
 
-tst_PROGRAMS = leaks tsc heap sigdebug
+tst_PROGRAMS = leaks tsc heap sigdebug mprotect
 
 CPPFLAGS = $(XENO_USER_CFLAGS) \
-I$(top_srcdir)/include
diff --git a/src/testsuite/regression/native/Makefile.in 
b/src/testsuite/regression/native/Makefile.in
index 3d5a0ce..b2ae93a 100644
--- a/src/testsuite/regression/native/Makefile.in
+++ b/src/testsuite/regression/native/Makefile.in
@@ -37,7 +37,7 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 tst_PROGRAMS = leaks$(EXEEXT) tsc$(EXEEXT) heap$(EXEEXT) \
-   sigdebug$(EXEEXT)
+   sigdebug$(EXEEXT) mprotect$(EXEEXT)
 subdir = src/testsuite/regression/native
 DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
@@ -70,6 +70,12 @@ leaks_LDADD = $(LDADD)
 leaks_DEPENDENCIES = ../../../skins/native/libnative.la \
../../../skins/rtdm/librtdm.la \
../../../skins/common/libxenomai.la
+mprotect_SOURCES = mprotect.c
+mprotect_OBJECTS = mprotect.$(OBJEXT)
+mprotect_LDADD = $(LDADD)
+mprotect_DEPENDENCIES = ../../../skins/native/libnative.la \
+   ../../../skins/rtdm/librtdm.la \
+   ../../../skins/common/libxenomai.la
 sigdebug_SOURCES = sigdebug.c
 sigdebug_OBJECTS = sigdebug.$(OBJEXT)
 sigdebug_LDADD = $(LDADD)
@@ -95,8 +101,8 @@ CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
-SOURCES = heap.c leaks.c sigdebug.c tsc.c
-DIST_SOURCES = heap.c leaks.c sigdebug.c tsc.c
+SOURCES = heap.c leaks.c mprotect.c sigdebug.c tsc.c
+DIST_SOURCES = heap.c leaks.c mprotect.c sigdebug.c tsc.c
 HEADERS = $(noinst_HEADERS)
 ETAGS = etags
 CTAGS = ctags
@@ -348,6 +354,9 @@ heap$(EXEEXT): $(heap_OBJECTS) $(heap_DEPENDENCIES)
 leaks$(EXEEXT): $(leaks_OBJECTS) $(leaks_DEPENDENCIES) 
@rm -f leaks$(EXEEXT)
$(LINK) $(leaks_OBJECTS) $(leaks_LDADD) $(LIBS)
+mprotect$(EXEEXT): $(mprotect_OBJECTS) $(mprotect_DEPENDENCIES) 
+   @rm -f mprotect$(EXEEXT)
+   $(LINK) $(mprotect_OBJECTS) $(mprotect_LDADD) $(LIBS)
 sigdebug$(EXEEXT): $(sigdebug_OBJECTS) $(sigdebug_DEPENDENCIES) 
@rm -f sigdebug$(EXEEXT)
$(LINK) $(sigdebug_OBJECTS) $(sigdebug_LDADD) $(LIBS)
@@ -363,6 +372,7 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/heap.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/leaks.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mprotect.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sigdebug.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsc.Po@am__quote@
 
diff --git a/src/testsuite/regression/native/mprotect.c 
b/src/testsuite/regression/native/mprotect.c
new file mode 100644
index 000..7d66e34
--- /dev/null
+++ b/src/testsuite/regression/native/mprotect.c
@@ -0,0 +1,128 @@
+/*
+ * Test if implicit pinning of memory via mprotect works.
+ *
+ * Copyright (C) Jan Kiszka  
+ *
+ * Released under the terms of GPLv2.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MEMSIZE 0x1
+
+static void check_inner(const char *fn, int line, const char *msg,
+   int status, int expected)
+{
+   if (status == expected)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flush_buffers();
+   fprintf(stderr, "FAILURE %s:%d: %s returned %d instead of %d - %s\n",
+   fn, line, msg, status, expected, strerror(-status));
+   exit(EXIT_FAILURE);
+}
+
+#define check_no_error(msg, status) ({ \
+   int __status = status;  \
+   check_inner(__FUNCTION__, __LINE__, msg,\
+   __status < 0 ? __status : 0, 0);\
+   __status;   \
+})
+
+static void check_value_inner(const char *fn, int line, const char *msg,
+ int value, int expected)
+{
+   if (value == expected)
+   return;
+
+   rt_task_set_mode(T_WARNSW, 0, NULL);
+   rt_print_flu