Last active
September 6, 2021 07:49
-
-
Save joycemaferko/1b31470accb43d4397ba454b9b7665eb to your computer and use it in GitHub Desktop.
RTEMS Test for sig2str.c (psxsignal09)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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. | |
*/ | |
#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" | |
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]; | |
char test_str5[SIG2STR_MAX]; | |
int res1; | |
int res2; | |
int retval; | |
int min = SIGRTMIN; | |
int max = SIGRTMAX; | |
printf( "\n" ); | |
printf( "SIG2STR_MAX is %d\n", SIG2STR_MAX ); | |
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( SIGRTMAX-1 == 30 ); | |
rtems_test_assert( retval == 0 ); | |
rtems_test_assert( strcmp( test_str4, "RTMAX-1" ) == 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 pass */ | |
retval = sig2str( 0, test_str4 ); | |
rtems_test_assert( retval == 0 ); | |
rtems_test_assert( strcmp( test_str4, "EXIT" ) == 0); | |
printf( "The string for test8 is: %s\n", test_str4 ); | |
/* Expected fail, invalid signal number */ | |
retval = sig2str( 201, test_str5 ); | |
rtems_test_assert( retval == -1); | |
rtems_test_assert( strcmp( test_str5, "" ) == 0); | |
printf( "The string for test9 is: %s\n", test_str5 ); | |
/* Expected fail, max signal number + 1 */ | |
retval = sig2str( 32, test_str5 ); | |
rtems_test_assert( retval == -1 ); | |
rtems_test_assert( strcmp( test_str5, "" ) == 0); | |
printf( "The string for test10 is: %s\n", test_str5 ); | |
/* Expected fail, invalid signal number */ | |
retval = sig2str( 2147483647, test_str5 ); | |
rtems_test_assert( retval == -1 ); | |
rtems_test_assert( strcmp( test_str5, "" ) == 0); | |
printf( "The string for test11 is: %s\n", test_str5 ); | |
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 valid 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 ); | |
/* Expected fail, invalid signal name */ | |
retval = str2sig( "12xyz", &res2 ); | |
rtems_test_assert( retval == -1); | |
printf( "Result 10 is: %d\n", res2 ); | |
/* Expected fail, invalid signal name */ | |
retval = str2sig( "xyz12", &res2 ); | |
rtems_test_assert( retval == -1); | |
printf( "Result 11 is: %d\n", res2 ); | |
/* Expected fail, invalid signal name */ | |
retval = str2sig( "xyz12xyz", &res2 ); | |
rtems_test_assert( retval == -1); | |
printf( "Result 12 is: %d\n", res2 ); | |
/* Expected pass, string representation of valid integer */ | |
retval = str2sig( "15", &res1 ); | |
rtems_test_assert( retval == 0); | |
rtems_test_assert( res1 == 15 ); | |
printf( "Result 13 is: %d\n", res1 ); | |
/* Expected fail, string representation of invalid integer */ | |
retval = str2sig( "40", &res2 ); | |
rtems_test_assert( retval == -1); | |
printf( "Result 14 is: %d\n", res2 ); | |
/* Expected pass */ | |
retval = str2sig( "EXIT", &res1 ); | |
rtems_test_assert( retval == 0); | |
rtems_test_assert( res1 == 0 ); | |
printf( "Result 15 is: %d\n", res1 ); | |
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_str5, &res2 ); | |
rtems_test_assert( retval == -1 ); | |
printf( "Result 4 is: %d\n", res2 ); | |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test for newly implemented sig2str and str2sig methods in the RTEMS real-time operating system (RTOS).