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

Matt Joyce mfjoyce2004 at gmail.com
Fri Jul 9 08:49:28 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 |  20 ++
 testsuites/psxtests/Makefile.am               |  11 +
 testsuites/psxtests/configure.ac              |   1 +
 testsuites/psxtests/psxhdrs/signal/sig2str.c  |  57 ++++
 testsuites/psxtests/psxsignal09/init.c        | 249 ++++++++++++++++++
 .../psxtests/psxsignal09/psxsignal09.doc      |  35 +++
 .../psxtests/psxsignal09/psxsignal09.scn      |  32 +++
 9 files changed, 408 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..5c9a16a7fc
--- /dev/null
+++ b/spec/build/testsuites/psxtests/psxsignal09.yml
@@ -0,0 +1,20 @@
+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: []
\ No newline at end of file
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..520a0db740
--- /dev/null
+++ b/testsuites/psxtests/psxhdrs/signal/sig2str.c
@@ -0,0 +1,57 @@
+/* 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+
+#define BUFLEN 10
+
+int test( void );
+
+int test( void )
+{
+  int result;
+  int signal_number; 
+  char signal_name[BUFLEN]; 
+
+  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..3684484723
--- /dev/null
+++ b/testsuites/psxtests/psxsignal09/init.c
@@ -0,0 +1,249 @@
+/* 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 test1[SIG2STR_MAX];
+  char test2[SIG2STR_MAX];
+  char test3[SIG2STR_MAX];
+  char test4[SIG2STR_MAX];
+  char test5[SIG2STR_MAX];
+  char test6[SIG2STR_MAX];
+  char test7[SIG2STR_MAX];
+  char test8[SIG2STR_MAX];
+  char test9[SIG2STR_MAX];
+  int res1;
+  int res2; 
+  int res3;
+  int res4; 
+  int res5;
+  int res6; 
+  int res7;
+  int res8;
+  int res9;
+  int retval1;
+  int retval2;
+  int retval3;
+  int retval4;
+  int retval5;
+  int retval6;
+  int retval7;
+  int retval8;
+  int retval9;
+  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 */
+  retval1 = sig2str( 1, test1 );
+  rtems_test_assert( retval1 == 0 );
+  rtems_test_assert( strcmp( test1, "HUP" )==0 );
+  printf( "The string test1 is: %s\n", test1 ); 
+
+  /* Expected pass */
+  retval2 = sig2str( 3, test2 );
+  rtems_test_assert( retval2 == 0 );
+  rtems_test_assert( strcmp( test2, "QUIT" )==0);
+  printf( "The string test2 is: %s\n", test2 ); 
+
+  /* Expected pass */
+  retval3 = sig2str( 27, test3 );
+  rtems_test_assert( retval3 == 0 );
+  rtems_test_assert( strcmp( test3, "RTMIN" )==0 );
+  printf( "The string test3 is: %s\n", test3 ); 
+
+  /* Expected pass */
+  retval4 = sig2str( 29, test4 );
+  rtems_test_assert( retval4 == 0 );
+  rtems_test_assert( strcmp( test4, "RTMIN+2" )==0 );
+  printf( "The string test4 is: %s\n", test4 ); 
+
+  /* Expected pass */
+  retval5 = sig2str( 31, test5 );
+  rtems_test_assert( retval5 == 0 );
+  rtems_test_assert( strcmp( test5, "RTMAX" )==0);
+  printf( "The string test5 is: %s\n", test5 ); 
+
+  /* Expected pass */
+  retval6 = sig2str( 30, test6 );
+  rtems_test_assert( retval6 == 0 );
+  rtems_test_assert( strcmp( test6, "RTMIN+3" )==0);
+  printf( "The string test6 is: %s\n", test6 );
+
+  /* Expected pass */
+  retval7 = sig2str( 9, test7 );
+  rtems_test_assert( retval7 == 0 );
+  rtems_test_assert(strcmp( test7, "KILL" )==0);
+  printf( "The string test7 is: %s\n", test7 );
+
+  /* Expected fail, invalid signal number */
+  retval8 = sig2str( 201, test8 );
+  rtems_test_assert( retval8 == -1);
+  rtems_test_assert( strcmp( test8, "Unknown signal 201" )==0);
+  printf( "The string test8 is: %s\n", test8 );
+
+  /* Expected fail, if signum is 0 the output is unspecified */
+  retval9 = sig2str( 0, test9 );
+  rtems_test_assert( retval9 == -1 );
+  printf( "The string test9 is: %s\n", test9 );
+
+
+  printf( "\n" ); 
+  printf( "Calling str2sig: \n" );
+
+  /* Expected pass */
+  retval1 = str2sig( "PIPE", &res1 );
+  rtems_test_assert( retval1 == 0); 
+  rtems_test_assert( res1 == 13 ); 
+  printf( "Result 1 is: %d\n", res1 );
+
+  /* Expected pass */
+  retval2 = str2sig( "TSTP", &res2 );
+  rtems_test_assert( retval2 == 0); 
+  rtems_test_assert( res2 == 18 ); 
+  printf( "Result 2 is: %d\n", res2 );
+
+  /* Expected pass */
+  retval3 = str2sig( "KILL", &res3 );
+  rtems_test_assert( retval3 == 0); 
+  rtems_test_assert( res3 == 9 ); 
+  printf( "Result 3 is: %d\n", res3 );
+
+  /* Expected pass, String representation of integer */
+  retval4 = str2sig( "10", &res4 );
+  rtems_test_assert( retval4 == 0); 
+  rtems_test_assert( res4 == 10 ); 
+  printf( "Result 4 is: %d\n", res4 );
+
+  /* Expected pass */
+  retval5 = str2sig( "RTMIN", &res5 );
+  rtems_test_assert( retval5 == 0); 
+  rtems_test_assert( res5 == 27 ); 
+  printf( "Result 5 is: %d\n", res5 );
+
+  /* Expected pass */
+  retval6 = str2sig( "RTMIN+1", &res6 );
+  rtems_test_assert( retval6 == 0); 
+  rtems_test_assert( res6 == 28 ); 
+  printf( "Result 6 is: %d\n", res6 );
+
+  /* Expected pass */
+  retval7 = str2sig( "RTMAX-2", &res7 );
+  rtems_test_assert( retval7 == 0); 
+  rtems_test_assert( res7 == 29 ); 
+  printf( "Result 7 is: %d\n", res7 );
+
+  /* Expected fail, invalid signal name */
+  retval8 = str2sig( "BOSS", &res8 );
+  rtems_test_assert( retval8 == -1); 
+  printf( "Result 8 is: %d\n", res8 );
+
+  /* Expected fail, invalid signal name */
+  retval9 = str2sig( "RTMIN+1000", &res9 );
+  rtems_test_assert( retval9 == -1); 
+  printf( "Result 9 is: %d\n", res9 );
+
+  printf( "\n" );
+  printf( "Calling str2sig using the result from previous call to sig2str\n" );
+  
+  /* Expected pass */
+  retval1 = str2sig( test1, &res1 );
+  rtems_test_assert( retval1 == 0 ); 
+  rtems_test_assert( res1 == 1 ); 
+  printf( "Result 1 is: %d\n", res1 ); 
+
+  /* Expected pass */
+  retval2 = str2sig( test2, &res2 );
+  rtems_test_assert( retval2 == 0 ); 
+  rtems_test_assert( res2 == 3 ); 
+  printf( "Result 2 is: %d\n", res2 ); 
+
+  /* Expected pass */
+  retval3 = str2sig( test3, &res3 );
+  rtems_test_assert( retval3 == 0 ); 
+  rtems_test_assert( res3 == 27 ); 
+  printf( "Result 3 is: %d\n", res3 ); 
+
+  /* Expected fail, calling using string from invalid sig2str call */
+  retval4 = str2sig( test8, &res4 );
+  rtems_test_assert( retval4 == -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..37c9b5b1fc
--- /dev/null
+++ b/testsuites/psxtests/psxsignal09/psxsignal09.scn
@@ -0,0 +1,32 @@
+*** BEGIN OF TEST SIG2STR AND STR2SIG ***
+SIGRTMIN is 27 and SIGRTMAX is 31
+
+Calling sig2str: 
+The string test1 is: HUP
+The string test2 is: QUIT
+The string test3 is: RTMIN
+The string test4 is: RTMIN+2
+The string test5 is: RTMAX
+The string test6 is: RTMIN+3
+The string test7 is: KILL
+The string test8 is: Unknown signal 201
+The string test9 is: Unknown signal 0
+
+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