Skip to contentSkip to conversation

Add rt signal newlib support + convert rt_sigsuspend01

PATCH New Cyril Hrubis 2 participants 6 messages Nov 13, 2018 – Nov 19, 2018

lore
Share & tools
lore
#0 lore raw

cover Add rt signal newlib support + convert rt_sigsuspend01

This set lays out interface for converting rt signal tests to new library and also converts the rt_sigsuspend01 test.

Cyril Hrubis (3):
lapi/rt_sigaction.h: Make it usable for newlib tests lapi/safe_rt_signal.h: Add. syscalls/rt_sigsuspend01: Cleanup && convert to newlib

 include/lapi/rt_sigaction.h                        |  10 +-
 include/lapi/safe_rt_signal.h                      |  50 ++++++++
 .../syscalls/rt_sigsuspend/rt_sigsuspend01.c       | 135 +++++++--------------
 3 files changed, 101 insertions(+), 94 deletions(-)
 create mode 100644 include/lapi/safe_rt_signal.h
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/3 lapi/rt_sigaction.h: Make it usable for newlib tests

We only need to switch between ltp_syscall() and tst_syscall().

---
 include/lapi/rt_sigaction.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
include/lapi/rt_sigaction.h +8 -2
index 18236db62..2dbbc7672 100644
@@ -177,6 +177,12 @@ __attribute__ ((optimize("Os"))) __attribute__((used)) restore_rt(void)
 }
 #endif
 
+#ifdef TST_TEST_H__
+# define TST_SYSCALL tst_syscall
+#else
+# define TST_SYSCALL ltp_syscall
+#endif
+
 /* This is a wrapper for __NR_rt_sigaction syscall.
  * act/oact values of INVAL_SA_PTR is used to pass
  * an invalid pointer to syscall(__NR_rt_sigaction)
@@ -232,11 +238,11 @@ static int ltp_rt_sigaction(int signum, const struct sigaction *act,
 
 
 #ifdef __sparc__
-	ret = ltp_syscall(__NR_rt_sigaction, signum,
+	ret = TST_SYSCALL(__NR_rt_sigaction, signum,
 			kact_p, koact_p,
 			stub, sigsetsize);
 #else
-	ret = ltp_syscall(__NR_rt_sigaction, signum,
+	ret = TST_SYSCALL(__NR_rt_sigaction, signum,
 			kact_p, koact_p,
 			sigsetsize);
 #endif
Signature · 1 line
2.16.4
#2 lore raw

PATCH 2/3 lapi/safe_rt_signal.h: Add.

In reply to Cyril Hrubis

This commits adds SAFE_RT_* calls, the file is created in lapi/ because these are wrappers around low level kernel syscalls rather than around the libc interfaces.

---
 include/lapi/safe_rt_signal.h | 50 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 include/lapi/safe_rt_signal.h
include/lapi/safe_rt_signal.h new file +50 -0
new file mode 100644
index 000000000..67fa44417
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018 Cyril Hrubis <[email protected]>
+ */
+
+#ifndef SAFE_RT_SIGNAL_H__
+#define SAFE_RT_SIGNAL_H__
+
+#include <signal.h>
+#include "lapi/rt_sigaction.h"
+
+static inline int safe_rt_sigaction(const char *file, const int lineno,
+                                    int signum, const struct sigaction *act,
+                                    struct sigaction *oact, size_t sigsetsize)
+{
+	int ret;
+
+	ret = ltp_rt_sigaction(signum, act, oact, sigsetsize);
+	if (ret < 0) {
+		tst_brk(TBROK | TERRNO,
+			"%s:%d: ltp_rt_sigaction(%i, %p, %p, %zu) failed",
+			file, lineno, signum, act, oact, sigsetsize);
+	}
+
+	return ret;
+}
+
+#define SAFE_RT_SIGACTION(signum, act, oldact, sigsetsize) \
+	safe_rt_sigaction(__FILE__, __LINE__, signum, act, oldact, sigsetsize)
+
+
+static inline int safe_rt_sigprocmask(const char *file, const int lineno,
+                                      int how, const sigset_t *set,
+                                      sigset_t *oldset, size_t sigsetsize)
+{
+	int ret;
+
+	ret = tst_syscall(__NR_rt_sigprocmask, how, set, oldset, sigsetsize);
+	if (ret < 0) {
+		tst_brk(TBROK | TERRNO,
+		        "%s:%d: rt_sigprocmask(%i, %p, %p, %zu) failed",
+			file, lineno, how, set, oldset, sigsetsize);
+	}
+
+	return ret;
+}
+
+#define SAFE_RT_SIGPROCMASK(how, set, oldset, sigsetsize) \
+	safe_rt_sigprocmask(__FILE__, __LINE__, how, set, oldset, sigsetsize)
+
+#endif /* SAFE_RT_SIGNAL_H__ */
Signature · 1 line
2.16.4
#3 lore raw

PATCH 3/3 syscalls/rt_sigsuspend01: Cleanup && convert to newlib

In reply to Cyril Hrubis

Also there is no need to sleep for 5 seconds so we only sleep for 1 now.

---
 .../syscalls/rt_sigsuspend/rt_sigsuspend01.c       | 135 +++++++--------------
 1 file changed, 43 insertions(+), 92 deletions(-)
testcases/kernel/syscalls/rt_sigsuspend/rt_sigsuspend01.c +43 -92
index c8c228a47..14b6bb332 100644
@@ -1,112 +1,63 @@
 /******************************************************************************/
 /* Copyright (c) Crackerjack Project., 2007                                   */
 /*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software Foundation,   */
-/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
-/*                                                                            */
 /* History:     Porting from Crackerjack to LTP is done by                    */
 /*              Manas Kumar Nayak [email protected]>                        */
 /******************************************************************************/
 
-/******************************************************************************/
-/* Description: This tests the rt_sigsuspend() syscall.                       */
-/******************************************************************************/
+/*
+ * Description: This tests the rt_sigsuspend() syscall.
+ *
+ * Waits for SIGALRM in rt_sigsuspend() then checks that process mask wasn't
+ * modified.
+ */
 
-#include <stdio.h>
 #include <signal.h>
 #include <errno.h>
-#include <string.h>
 
-#include "test.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
-#include "lapi/rt_sigaction.h"
-
-char *TCID = "rt_sigsuspend01";
-int TST_TOTAL = 1;
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-	tst_tmpdir();
-}
+#include "lapi/safe_rt_signal.h"
 
 static void sig_handler(int sig)
 {
+	(void) sig;
 }
 
-int main(int ac, char **av)
+static void verify_rt_sigsuspend(void)
 {
 	sigset_t set, set1, set2;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-
-		tst_count = 0;
-
-		if (sigemptyset(&set) < 0)
-			tst_brkm(TFAIL | TERRNO, cleanup, "sigemptyset failed");
-		struct sigaction act, oact;
-		memset(&act, 0, sizeof(act));
-		memset(&oact, 0, sizeof(oact));
-		act.sa_handler = sig_handler;
-
-		TEST(ltp_rt_sigaction(SIGALRM, &act, &oact, SIGSETSIZE));
-		if (TEST_RETURN == -1)
-			tst_brkm(TFAIL | TTERRNO, cleanup,
-				 "rt_sigaction failed");
-
-		TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
-			     &set1, SIGSETSIZE));
-		if (TEST_RETURN == -1)
-			tst_brkm(TFAIL | TTERRNO, cleanup,
-				 "rt_sigprocmask failed");
-
-		TEST(alarm(5));
-		int result;
-		TEST(result = ltp_syscall(__NR_rt_sigsuspend, &set,
-			SIGSETSIZE));
-		TEST(alarm(0));
-		if (result == -1 && TEST_ERRNO != EINTR) {
-			TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
-				&set2, SIGSETSIZE));
-			if (TEST_RETURN == -1) {
-				tst_brkm(TFAIL | TTERRNO, cleanup,
-					 "rt_sigprocmask failed");
-			} else if (memcmp(&set1, &set2,
-				   sizeof(unsigned long))) {
-				tst_brkm(TFAIL | TTERRNO, cleanup,
-					 "rt_sigsuspend failed to "
-					 "preserve signal mask");
-			} else {
-				tst_resm(TPASS, "rt_sigsuspend PASSED");
-			}
-		} else {
-			tst_resm(TFAIL | TTERRNO, "rt_sigsuspend failed");
-		}
-
-	}
-
-	cleanup();
-
-	tst_exit();
+	struct sigaction act = {.sa_handler = sig_handler};
+
+	if (sigemptyset(&set) < 0)
+		tst_brk(TFAIL | TERRNO, "sigemptyset failed");
+
+	SAFE_RT_SIGACTION(SIGALRM, &act, NULL, SIGSETSIZE);
+
+	SAFE_RT_SIGPROCMASK(0, NULL, &set1, SIGSETSIZE);
+
+	alarm(1);
+
+	TEST(tst_syscall(__NR_rt_sigsuspend, &set, SIGSETSIZE));
+
+	alarm(0);
+
+	if (TST_RET != -1)
+		tst_brk(TFAIL, "rt_sigsuspend returned %ld", TST_RET);
+
+	if (TST_ERR != EINTR)
+		tst_brk(TFAIL | TTERRNO, "rt_sigsuspend() failed unexpectedly");
+
+	tst_res(TPASS, "rt_sigsuspend() returned with -1 and EINTR");
+
+	SAFE_RT_SIGPROCMASK(0, NULL, &set2, SIGSETSIZE);
+
+	if (memcmp(&set1, &set2, sizeof(unsigned long)))
+		tst_res(TFAIL, "signal mask not preserved");
+	else
+		tst_res(TPASS, "signal mask preserved");
 }
+
+static struct tst_test test = {
+	.test_all = verify_rt_sigsuspend,
+};
Signature · 1 line
2.16.4
#4 lore raw

PATCH 3/3 syscalls/rt_sigsuspend01: Cleanup && convert to newlib

LGTM

Quoted 169 lines · Cyril Hrubis

Also there is no need to sleep for 5 seconds so we only sleep for 1 now.

---
  .../syscalls/rt_sigsuspend/rt_sigsuspend01.c       | 135 +++++++--------------
  1 file changed, 43 insertions(+), 92 deletions(-)
testcases/kernel/syscalls/rt_sigsuspend/rt_sigsuspend01.c +43 -92
index c8c228a47..14b6bb332 100644
@@ -1,112 +1,63 @@
  /******************************************************************************/
  /* Copyright (c) Crackerjack Project., 2007                                   */
  /*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software Foundation,   */
-/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
-/*                                                                            */
  /* History:     Porting from Crackerjack to LTP is done by                    */
  /*              Manas Kumar Nayak [email protected]>                        */
  /******************************************************************************/
 
-/******************************************************************************/
-/* Description: This tests the rt_sigsuspend() syscall.                       */
-/******************************************************************************/
+/*
+ * Description: This tests the rt_sigsuspend() syscall.
+ *
+ * Waits for SIGALRM in rt_sigsuspend() then checks that process mask wasn't
+ * modified.
+ */
 
-#include <stdio.h>
  #include <signal.h>
  #include <errno.h>
-#include <string.h>
 
-#include "test.h"
+#include "tst_test.h"
  #include "lapi/syscalls.h"
-#include "lapi/rt_sigaction.h"
-
-char *TCID = "rt_sigsuspend01";
-int TST_TOTAL = 1;
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-	tst_tmpdir();
-}
+#include "lapi/safe_rt_signal.h"
 
  static void sig_handler(int sig)
  {
+	(void) sig;
  }
 
-int main(int ac, char **av)
+static void verify_rt_sigsuspend(void)
  {
  	sigset_t set, set1, set2;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-
-		tst_count = 0;
-
-		if (sigemptyset(&set) < 0)
-			tst_brkm(TFAIL | TERRNO, cleanup, "sigemptyset failed");
-		struct sigaction act, oact;
-		memset(&act, 0, sizeof(act));
-		memset(&oact, 0, sizeof(oact));
-		act.sa_handler = sig_handler;
-
-		TEST(ltp_rt_sigaction(SIGALRM, &act, &oact, SIGSETSIZE));
-		if (TEST_RETURN == -1)
-			tst_brkm(TFAIL | TTERRNO, cleanup,
-				 "rt_sigaction failed");
-
-		TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
-			     &set1, SIGSETSIZE));
-		if (TEST_RETURN == -1)
-			tst_brkm(TFAIL | TTERRNO, cleanup,
-				 "rt_sigprocmask failed");
-
-		TEST(alarm(5));
-		int result;
-		TEST(result = ltp_syscall(__NR_rt_sigsuspend, &set,
-			SIGSETSIZE));
-		TEST(alarm(0));
-		if (result == -1 && TEST_ERRNO != EINTR) {
-			TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
-				&set2, SIGSETSIZE));
-			if (TEST_RETURN == -1) {
-				tst_brkm(TFAIL | TTERRNO, cleanup,
-					 "rt_sigprocmask failed");
-			} else if (memcmp(&set1, &set2,
-				   sizeof(unsigned long))) {
-				tst_brkm(TFAIL | TTERRNO, cleanup,
-					 "rt_sigsuspend failed to "
-					 "preserve signal mask");
-			} else {
-				tst_resm(TPASS, "rt_sigsuspend PASSED");
-			}
-		} else {
-			tst_resm(TFAIL | TTERRNO, "rt_sigsuspend failed");
-		}
-
-	}
-
-	cleanup();
-
-	tst_exit();
+	struct sigaction act = {.sa_handler = sig_handler};
+
+	if (sigemptyset(&set) < 0)
+		tst_brk(TFAIL | TERRNO, "sigemptyset failed");
+
+	SAFE_RT_SIGACTION(SIGALRM, &act, NULL, SIGSETSIZE);
+
+	SAFE_RT_SIGPROCMASK(0, NULL, &set1, SIGSETSIZE);
+
+	alarm(1);
+
+	TEST(tst_syscall(__NR_rt_sigsuspend, &set, SIGSETSIZE));
+
+	alarm(0);
+
+	if (TST_RET != -1)
+		tst_brk(TFAIL, "rt_sigsuspend returned %ld", TST_RET);
+
+	if (TST_ERR != EINTR)
+		tst_brk(TFAIL | TTERRNO, "rt_sigsuspend() failed unexpectedly");
+
+	tst_res(TPASS, "rt_sigsuspend() returned with -1 and EINTR");
+
+	SAFE_RT_SIGPROCMASK(0, NULL, &set2, SIGSETSIZE);
+
+	if (memcmp(&set1, &set2, sizeof(unsigned long)))
+		tst_res(TFAIL, "signal mask not preserved");
+	else
+		tst_res(TPASS, "signal mask preserved");
  }
+
+static struct tst_test test = {
+	.test_all = verify_rt_sigsuspend,
+};