[PATCH 2/2] testsuites: Edited tests for sig2str/str2sig methods
Matt Joyce
mfjoyce2004 at gmail.com
Wed Jul 7 10:55:59 UTC 2021
Added additional tests to init.c and added psxsignal09.scn and
psxsignal09.doc to conform to RTEMS standards.
---
testsuites/psxtests/Makefile.am | 2 +
testsuites/psxtests/psxsignal09/init.c | 207 +++++++++++++-----
.../psxtests/psxsignal09/psxsignal09.doc | 34 +++
.../psxtests/psxsignal09/psxsignal09.scn | 31 +++
4 files changed, 223 insertions(+), 51 deletions(-)
create mode 100644 testsuites/psxtests/psxsignal09/psxsignal09.doc
create mode 100644 testsuites/psxtests/psxsignal09/psxsignal09.scn
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index b50c9b97cb..b62d5cab59 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -927,6 +927,8 @@ 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
diff --git a/testsuites/psxtests/psxsignal09/init.c b/testsuites/psxtests/psxsignal09/init.c
index 02ad8a9e45..7025b471aa 100644
--- a/testsuites/psxtests/psxsignal09/init.c
+++ b/testsuites/psxtests/psxsignal09/init.c
@@ -48,7 +48,7 @@
//#include <sys/signal.h>
-const char rtems_test_name[] = "SIG2STR AND STR2SIG TEST";
+const char rtems_test_name[] = "SIG2STR AND STR2SIG";
static rtems_task Init(
rtems_task_argument ignored
@@ -56,72 +56,177 @@ static rtems_task Init(
{
rtems_print_printer_fprintf_putc(&rtems_test_printer);
TEST_BEGIN();
- printf( "SIG2STR AND STR2SIG TEST\n" );
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( "sigrtmin is %d and sigrtmax is %d\n", min, max );
-
- printf("Calling sig2str: \n");
- sig2str(31, test1);
- sig2str(9, test2);
- sig2str(29, test3);
- sig2str(2147483647, test4);
- printf("test1 is now: %s\n", test1);
- printf("test2 is now: %s\n", test2);
- printf("test3 is now: %s\n", test3);
- printf("test4 is now: %s\n", test4);
-
- printf("Calling str2sig: \n");
- retval1 = str2sig("19", &res1);
- retval2 = str2sig("TSTP", &res2);
- retval3 = str2sig("RTMIN+12", &res3);
- retval4 = str2sig("RTMAX-2", &res4);
- printf("The result of the first call is: %d\n", res1);
- printf("The second result of the second call is: %d\n", res2);
- printf("The second result of the third call is: %d\n", res3);
- printf("The second result of the fourth call is: %d\n", res4);
-
- // T_TEST_CASE(a_test_case)
- // {
- // T_eq_int(res1, 19);
- // }
-
- printf("retval1 is %d\n", retval1);
- printf("retval2 is %d\n", retval2);
- printf("retval3 is %d\n", retval3);
- printf("retval4 is %d\n", retval4);
-
- /* Testing a call to str2sig using a previously successful call to sig2str.
- * value in pnum should equal signum*/
- printf("\n");
- str2sig(test1, &res1);
- str2sig(test2, &res2);
- str2sig(test3, &res3);
- rtems_test_assert(res1 == 31);
- printf("res1 should equal 31. It is: %d\n", res1);
- rtems_test_assert(res2 == 9);
- printf("res2 should equal 9. It is: %d\n", res2);
- rtems_test_assert(res3 == 29);
- printf("res3 should equal 29. It is: %d\n", res3);
-
-
+ 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, "RTMAX-1" )==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( 200, test8 );
+ rtems_test_assert( retval8 == -1);
+ rtems_test_assert( strcmp( test8, "Unknown signal 200" )==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 );
}
diff --git a/testsuites/psxtests/psxsignal09/psxsignal09.doc b/testsuites/psxtests/psxsignal09/psxsignal09.doc
new file mode 100644
index 0000000000..0f11061c4d
--- /dev/null
+++ b/testsuites/psxtests/psxsignal09/psxsignal09.doc
@@ -0,0 +1,34 @@
+/* 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.
+ */
\ No newline at end of file
diff --git a/testsuites/psxtests/psxsignal09/psxsignal09.scn b/testsuites/psxtests/psxsignal09/psxsignal09.scn
new file mode 100644
index 0000000000..632e152e9b
--- /dev/null
+++ b/testsuites/psxtests/psxsignal09/psxsignal09.scn
@@ -0,0 +1,31 @@
+*** 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: RTMAX-1
+The string test7 is: KILL
+The string test8 is: Unknown signal 200
+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 ***
\ No newline at end of file
--
2.31.1
More information about the devel
mailing list