[PATCH 1/1] testsuites: Added tests for sig2str/str2sig methods

Matt Joyce mfjoyce2004 at gmail.com
Sun Jul 18 11:15:58 UTC 2021


Added psxsignal09 in psxtests and compile only test in psxhdrs in order to evaluate
newly added POSIX standard methods in Newlib.
---
 spec/build/testsuites/psxtests/grp.yml        |   2 +
 spec/build/testsuites/psxtests/libpsxhdrs.yml |   1 +
 .../build/testsuites/psxtests/psxsignal09.yml |  21 ++
 testsuites/psxtests/Makefile.am               |  11 +
 testsuites/psxtests/configure.ac              |   1 +
 testsuites/psxtests/psxhdrs/signal/sig2str.c  |  58 ++++
 testsuites/psxtests/psxsignal09/init.c        | 251 ++++++++++++++++++
 .../psxtests/psxsignal09/psxsignal09.doc      |  35 +++
 .../psxtests/psxsignal09/psxsignal09.scn      |  33 +++
 9 files changed, 413 insertions(+)
 create mode 100644 spec/build/testsuites/psxtests/psxsignal09.yml
 create mode 100644 testsuites/psxtests/psxhdrs/signal/sig2str.c
 create mode 100644 testsuites/psxtests/psxsignal09/init.c
 create mode 100644 testsuites/psxtests/psxsignal09/psxsignal09.doc
 create mode 100644 testsuites/psxtests/psxsignal09/psxsignal09.scn

diff --git a/spec/build/testsuites/psxtests/grp.yml b/spec/build/testsuites/psxtests/grp.yml
index fb7ce465ae..f61f45dbe9 100644
--- a/spec/build/testsuites/psxtests/grp.yml
+++ b/spec/build/testsuites/psxtests/grp.yml
@@ -205,6 +205,8 @@ links:
   uid: psxsignal07
 - role: build-dependency
   uid: psxsignal08
+- role: build-dependency
+  uid: psxsignal09
 - role: build-dependency
   uid: psxspin01
 - role: build-dependency
diff --git a/spec/build/testsuites/psxtests/libpsxhdrs.yml b/spec/build/testsuites/psxtests/libpsxhdrs.yml
index 6a0ab6d4f7..5767bcdacd 100644
--- a/spec/build/testsuites/psxtests/libpsxhdrs.yml
+++ b/spec/build/testsuites/psxtests/libpsxhdrs.yml
@@ -513,6 +513,7 @@ source:
 - testsuites/psxtests/psxhdrs/signal/sigtimedwait.c
 - testsuites/psxtests/psxhdrs/signal/sigwait.c
 - testsuites/psxtests/psxhdrs/signal/sigwaitinfo.c
+- testsuites/psxtests/psxhdrs/signal/sig2str.c
 - testsuites/psxtests/psxhdrs/stddef/offsetof.c
 - testsuites/psxtests/psxhdrs/stdio/clearerr.c
 - testsuites/psxtests/psxhdrs/stdio/ctermid.c
diff --git a/spec/build/testsuites/psxtests/psxsignal09.yml b/spec/build/testsuites/psxtests/psxsignal09.yml
new file mode 100644
index 0000000000..08a29c7c5b
--- /dev/null
+++ b/spec/build/testsuites/psxtests/psxsignal09.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+cppflags: []
+cxxflags: []
+enabled-by:
+- RTEMS_POSIX_API
+features: c cprogram
+includes: []
+ldflags: []
+links: []
+source:
+- testsuites/psxtests/psxsignal09/init.c
+stlib: []
+target: testsuites/psxtests/psxsignal09.exe
+type: build
+use-after: []
+use-before: []
+
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index a35f00b665..b62d5cab59 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -924,6 +924,17 @@ psxsignal08_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxsignal08) \
 endif
 endif
 
+if HAS_POSIX
+if TEST_psxsignal09
+psx_tests += psxsignal09
+psx_screens += psxsignal09/psxsignal09.scn
+psx_docs += psxsignal09/psxsignal09.doc
+psxsignal09_SOURCES = psxsignal09/init.c 
+psxsignal09_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxsignal09) \
+	$(support_includes) -I$(top_srcdir)/include
+endif
+endif
+
 if TEST_psxspin01
 psx_tests += psxspin01
 psx_screens += psxspin01/psxspin01.scn
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index 3f95010cd3..7b9a1027ca 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -138,6 +138,7 @@ RTEMS_TEST_CHECK([psxsignal05])
 RTEMS_TEST_CHECK([psxsignal06])
 RTEMS_TEST_CHECK([psxsignal07])
 RTEMS_TEST_CHECK([psxsignal08])
+RTEMS_TEST_CHECK([psxsignal09])
 RTEMS_TEST_CHECK([psxspin01])
 RTEMS_TEST_CHECK([psxstack01])
 RTEMS_TEST_CHECK([psxstack02])
diff --git a/testsuites/psxtests/psxhdrs/signal/sig2str.c b/testsuites/psxtests/psxhdrs/signal/sig2str.c
new file mode 100644
index 0000000000..d4932c1961
--- /dev/null
+++ b/testsuites/psxtests/psxhdrs/signal/sig2str.c
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ * @brief Header File Conformance Test
+ *
+ * This test file is used to verify that the header files associated with
+ * invoking this function are correct.
+ */
+
+/*
+ * Copyright (C) 2021 Matthew Joyce
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
+/* Defined to have access to SIG2STR_MAX and function prototypes in signal.h*/
+#define _GNU_SOURCE
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+
+int test( void );
+
+int test( void )
+{
+  int result;
+  int signal_number; 
+  char signal_name[SIG2STR_MAX]; 
+
+  signal_number = SIGALRM;
+
+  result = sig2str(signal_number, signal_name);
+
+  return result;
+}
diff --git a/testsuites/psxtests/psxsignal09/init.c b/testsuites/psxtests/psxsignal09/init.c
new file mode 100644
index 0000000000..21746aeb0c
--- /dev/null
+++ b/testsuites/psxtests/psxsignal09/init.c
@@ -0,0 +1,251 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ * @brief Test of sig2str and str2sig methods
+ *
+ * This test file is used to verify that the methods sig2str and str2sig
+ * are functioning as expected
+ */
+
+/*
+ * Copyright (C) 2021 Matthew Joyce
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
+/* Defined to have access to SIG2STR_MAX and function prototypes in signal.h*/
+#define _GNU_SOURCE
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <tmacros.h>
+#include <signal.h>
+#include <rtems/test.h>
+#include "test_support.h"
+
+//#include <sys/signal.h>
+
+const char rtems_test_name[] = "SIG2STR AND STR2SIG";
+
+static rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  rtems_print_printer_fprintf_putc(&rtems_test_printer);
+  TEST_BEGIN();
+  
+  char test_str1[SIG2STR_MAX];
+  char test_str2[SIG2STR_MAX];
+  char test_str3[SIG2STR_MAX];
+  char test_str4[SIG2STR_MAX];
+  int res1;
+  int res2; 
+  int retval;
+  int min = SIGRTMIN;
+  int max = SIGRTMAX;
+  
+  printf( "\n" );
+  printf( "SIGRTMIN is %d and SIGRTMAX is %d\n", min, max );
+  printf( "\n" );
+
+  printf( "Calling sig2str: \n" );
+
+  /* Expected pass */
+  retval = sig2str( 1, test_str1 );
+  rtems_test_assert( SIGHUP == 1 );
+  rtems_test_assert( retval == 0 );
+  rtems_test_assert( strcmp( test_str1, "HUP" ) == 0 );
+  printf( "The string for test1 is: %s\n", test_str1 ); 
+
+  /* Expected pass */
+  retval = sig2str( 3, test_str2 );
+  rtems_test_assert( SIGQUIT == 3 ); 
+  rtems_test_assert( retval == 0 );
+  rtems_test_assert( strcmp( test_str2, "QUIT" ) == 0 );
+  printf( "The string for test2 is: %s\n", test_str2 ); 
+
+  /* Expected pass */
+  retval = sig2str( 27, test_str3 );
+  rtems_test_assert( SIGRTMIN == 27 );
+  rtems_test_assert( retval == 0 );
+  rtems_test_assert( strcmp( test_str3, "RTMIN" ) == 0 );
+  printf( "The string for test3 is: %s\n", test_str3 ); 
+
+  /* Expected pass */
+  retval = sig2str( 29, test_str4 );
+  rtems_test_assert( SIGRTMIN+2 == 29 );
+  rtems_test_assert( retval == 0 );
+  rtems_test_assert( strcmp( test_str4, "RTMIN+2" ) == 0 );
+  printf( "The string for test4 is: %s\n", test_str4 ); 
+
+  /* Expected pass */
+  retval = sig2str( 31, test_str4 );
+  rtems_test_assert( SIGRTMAX == 31 );
+  rtems_test_assert( retval == 0 );
+  rtems_test_assert( strcmp( test_str4, "RTMAX" ) == 0);
+  printf( "The string for test5 is: %s\n", test_str4 ); 
+
+  /* Expected pass */
+  retval = sig2str( 30, test_str4 );
+  rtems_test_assert( SIGRTMIN+3 == 30 );
+  rtems_test_assert( retval == 0 );
+  rtems_test_assert( strcmp( test_str4, "RTMIN+3" ) == 0);
+  printf( "The string for test6 is: %s\n", test_str4 );
+
+  /* Expected pass */
+  retval = sig2str( 9, test_str4 );
+  rtems_test_assert( SIGKILL == 9 );
+  rtems_test_assert( retval == 0 );
+  rtems_test_assert(strcmp( test_str4, "KILL" ) == 0 );
+  printf( "The string for test7 is: %s\n", test_str4 );
+
+  /* Expected fail, invalid signal number */
+  retval = sig2str( 201, test_str4 );
+  rtems_test_assert( retval == -1);
+  rtems_test_assert( strcmp( test_str4, "Unknown signal 201" ) == 0);
+  printf( "The string for test8 is: %s\n", test_str4 );
+
+  /* Expected fail, if signum is 0 the output is unspecified */
+  retval = sig2str( 0, test_str4 );
+  rtems_test_assert( retval == -1 );
+  printf( "The string for test9 is: %s\n", test_str4 );
+
+  /* Expected fail, max signal number + 1 */
+  retval = sig2str( 32, test_str4 );
+  rtems_test_assert( retval == -1 );
+  printf( "The string for test10 is: %s\n", test_str4 );
+
+  /* Expected fail, SIG2STR_MAX overflowed by one digit */
+  retval = sig2str( 2147483648, test_str4 );
+  rtems_test_assert( retval == -1 );
+  printf( "The string for test11 is: %s\n", test_str4 );
+
+  printf( "\n" ); 
+  printf( "Calling str2sig: \n" );
+
+  /* Expected pass */
+  retval = str2sig( "PIPE", &res1 );
+  rtems_test_assert( SIGPIPE == 13 );
+  rtems_test_assert( retval == 0); 
+  rtems_test_assert( res1 == 13 ); 
+  printf( "Result 1 is: %d\n", res1 );
+
+  /* Expected pass */
+  retval = str2sig( "TSTP", &res1 );
+  rtems_test_assert( SIGTSTP == 18 );
+  rtems_test_assert( retval == 0); 
+  rtems_test_assert( res1 == 18 ); 
+  printf( "Result 2 is: %d\n", res1 );
+
+  /* Expected pass */
+  retval = str2sig( "KILL", &res1 );
+  rtems_test_assert( SIGKILL == 9 );
+  rtems_test_assert( retval == 0); 
+  rtems_test_assert( res1 == 9 ); 
+  printf( "Result 3 is: %d\n", res1 );
+
+  /* Expected pass, String representation of integer */
+  retval = str2sig( "10", &res1 );
+  rtems_test_assert( retval == 0); 
+  rtems_test_assert( res1 == 10 ); 
+  printf( "Result 4 is: %d\n", res1 );
+
+  /* Expected pass */
+  retval = str2sig( "RTMIN", &res1 );
+  rtems_test_assert( SIGRTMIN == 27 );
+  rtems_test_assert( retval == 0); 
+  rtems_test_assert( res1 == 27 ); 
+  printf( "Result 5 is: %d\n", res1 );
+
+  /* Expected pass */
+  retval = str2sig( "RTMIN+1", &res1 );
+  rtems_test_assert( SIGRTMIN+1 == 28 );
+  rtems_test_assert( retval == 0); 
+  rtems_test_assert( res1 == 28 ); 
+  printf( "Result 6 is: %d\n", res1 );
+
+  /* Expected pass */
+  retval = str2sig( "RTMAX-2", &res1 );
+  rtems_test_assert( SIGRTMAX-2 == 29 );
+  rtems_test_assert( retval == 0); 
+  rtems_test_assert( res1 == 29 ); 
+  printf( "Result 7 is: %d\n", res1 );
+
+  /* Expected fail, invalid signal name */
+  retval = str2sig( "BOSS", &res2 );
+  rtems_test_assert( retval == -1); 
+  printf( "Result 8 is: %d\n", res2 );
+
+  /* Expected fail, invalid signal name */
+  retval = str2sig( "RTMIN+1000", &res2 );
+  rtems_test_assert( retval == -1); 
+  printf( "Result 9 is: %d\n", res2 );
+
+  printf( "\n" );
+  printf( "Calling str2sig using the result from previous call to sig2str\n" );
+  
+  /* Expected pass */
+  retval = str2sig( test_str1, &res1 );
+  rtems_test_assert( retval == 0 ); 
+  rtems_test_assert( res1 == 1 ); 
+  printf( "Result 1 is: %d\n", res1 ); 
+
+  /* Expected pass */
+  retval = str2sig( test_str2, &res1 );
+  rtems_test_assert( retval == 0 ); 
+  rtems_test_assert( res1 == 3 ); 
+  printf( "Result 2 is: %d\n", res1 ); 
+
+  /* Expected pass */
+  retval = str2sig( test_str3, &res1 );
+  rtems_test_assert( retval == 0 ); 
+  rtems_test_assert( res1 == 27 ); 
+  printf( "Result 3 is: %d\n", res1 ); 
+
+  /* Expected fail, calling using string from invalid sig2str call */
+  retval = str2sig( test_str4, &res1 );
+  rtems_test_assert( retval == -1 ); 
+  
+  TEST_END();
+  rtems_test_exit( 0 );
+}
+
+
+/* NOTICE: the clock driver is explicitly disabled */
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS            1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
diff --git a/testsuites/psxtests/psxsignal09/psxsignal09.doc b/testsuites/psxtests/psxsignal09/psxsignal09.doc
new file mode 100644
index 0000000000..c90ee805f0
--- /dev/null
+++ b/testsuites/psxtests/psxsignal09/psxsignal09.doc
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ * @brief Test of sig2str and str2sig methods
+ *
+ * This test file is used to verify that the methods sig2str and str2sig
+ * are functioning as expected
+ */
+
+/*
+ * Copyright (C) 2021 Matthew Joyce
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
diff --git a/testsuites/psxtests/psxsignal09/psxsignal09.scn b/testsuites/psxtests/psxsignal09/psxsignal09.scn
new file mode 100644
index 0000000000..78f8bde324
--- /dev/null
+++ b/testsuites/psxtests/psxsignal09/psxsignal09.scn
@@ -0,0 +1,33 @@
+*** BEGIN OF TEST SIG2STR AND STR2SIG ***
+SIGRTMIN is 27 and SIGRTMAX is 31
+
+Calling sig2str: 
+The string for test1 is: HUP
+The string for test2 is: QUIT
+The string for test3 is: RTMIN
+The string for test4 is: RTMIN+2
+The string for test5 is: RTMAX
+The string for test6 is: RTMIN+3
+The string for test7 is: KILL
+The string for test8 is: Unknown signal 201
+The string for test9 is: Unknown signal 0
+The string for test10 is: Unknown signal 32
+The string for test11 is: Unknown signal -2147483648
+
+Calling str2sig: 
+Result 1 is: 13
+Result 2 is: 18
+Result 3 is: 9
+Result 4 is: 10
+Result 5 is: 27
+Result 6 is: 28
+Result 7 is: 29
+Result 8 is: 0
+Result 9 is: 0
+
+Calling str2sig using the result from previous call to sig2str
+Result 1 is: 1
+Result 2 is: 3
+Result 3 is: 27
+
+*** END OF TEST SIG2STR AND STR2SIG ***
-- 
2.31.1



More information about the devel mailing list