Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:32

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <tmacros.h>
0034 #include <rtems/bspcmdline.h>
0035 
0036 const char rtems_test_name[] = "BSPCMDLINE 1";
0037 
0038 /* forward declarations to avoid warnings */
0039 rtems_task Init(rtems_task_argument argument);
0040 void test_errors(void);
0041 void test_search(bool null_expected, const char *cmdline, const char *param);
0042 
0043 extern const char *bsp_boot_cmdline;
0044 
0045 void test_errors(void)
0046 {
0047   const char *p;
0048   char        result[32];
0049 
0050   bsp_boot_cmdline = NULL;
0051 
0052   puts( "rtems_bsp_cmdline_get_param - name=NULL - returns NULL" );
0053   p = rtems_bsp_cmdline_get_param( NULL, result, 32 );
0054   rtems_test_assert( p == NULL );
0055 
0056   puts( "rtems_bsp_cmdline_get_param - result=NULL - returns NULL" );
0057   p = rtems_bsp_cmdline_get_param( "name", NULL, 32 );
0058   rtems_test_assert( p == NULL );
0059 
0060   puts( "rtems_bsp_cmdline_get_param - length=0 - returns NULL" );
0061   p = rtems_bsp_cmdline_get_param( "name", result, 0 );
0062   rtems_test_assert( p == NULL );
0063 
0064   puts( "rtems_bsp_cmdline_get_param_raw - name=NULL - returns NULL" );
0065   p = rtems_bsp_cmdline_get_param_raw( NULL );
0066   rtems_test_assert( p == NULL );
0067 
0068   bsp_boot_cmdline = NULL;
0069 
0070   puts( "rtems_bsp_cmdline_get_param - bsp_boot_cmdline=NULL - returns NULL" );
0071   p = rtems_bsp_cmdline_get_param( "name", result, 5 );
0072   rtems_test_assert( p == NULL );
0073 
0074   puts(
0075     "rtems_bsp_cmdline_get_param_raw - bsp_boot_cmdline=NULL - returns NULL" );
0076   p = rtems_bsp_cmdline_get_param_raw( "name" );
0077   rtems_test_assert( p == NULL );
0078   
0079   bsp_boot_cmdline = "edit";
0080   puts (
0081     "rtems_bsp_cmdline_get_param - bsp_boot_cmdline = edit name = "
0082       "edit -no error" );
0083   p = rtems_bsp_cmdline_get_param("edit", result, 5);
0084   rtems_test_assert( p != NULL );
0085 
0086   bsp_boot_cmdline = "joel=123456789";
0087   puts( "rtems_bsp_cmdline_get_param - too short buffer" );
0088   p = rtems_bsp_cmdline_get_param("joel", result, 5);
0089   rtems_test_assert( p != NULL );
0090 
0091   bsp_boot_cmdline = "--arg1=X`";
0092   puts( "rtems_bsp_cmdline_get_param_rhs - short match" );
0093   p = rtems_bsp_cmdline_get_param_rhs("arg", result, 10);
0094   rtems_test_assert( p == NULL );
0095 }
0096 
0097 void test_search(
0098   bool        null_expected,
0099   const char *cmdline,
0100   const char *param
0101 )
0102 {
0103   const char *p;
0104   char        value[80];
0105   size_t      length;
0106 
0107   bsp_boot_cmdline = cmdline;
0108 
0109   printf(
0110     "\n"
0111     "Testing for param=(%s)%s\n"
0112     "  Command Line : (%s)\n",
0113     param,
0114     ((null_expected) ? " - Expect NULL" : ""),
0115     cmdline
0116   );
0117 
0118   printf( "rtems_bsp_cmdline_get_param_raw(%s)\n", param );
0119   p = rtems_bsp_cmdline_get_param_raw( param );
0120   if ( null_expected ) {
0121     if ( p )
0122       puts( "ERROR - rtems_bsp_cmdline_get_param_raw did not return NULL" );
0123     else
0124       printf( "rtems_bsp_cmdline_get_param_raw(%s) returned NULL\n", param );
0125     rtems_test_assert( !p );
0126   } else {
0127     if ( p )
0128       printf( "rtems_bsp_cmdline_get_param_raw(%s) returned (%s)\n", param, p );
0129     else
0130       printf( "rtems_bsp_cmdline_get_param_raw(%s) returned NULL\n", param );
0131 
0132     rtems_test_assert( p );
0133   }
0134 
0135   printf( "rtems_bsp_cmdline_get_param_rhs(%s)\n", param );
0136   length = sizeof(value);
0137   p = rtems_bsp_cmdline_get_param_rhs( param, value, length );
0138   if ( null_expected ) {
0139     if ( p )
0140       puts( "ERROR - rtems_bsp_cmdline_get_param_rhs did not return NULL" );
0141     else
0142       printf( "rtems_bsp_cmdline_get_param_rhs(%s) returned NULL\n", param );
0143     rtems_test_assert( !p );
0144   } else {
0145     if ( !p )
0146       puts( "ERROR - rtems_bsp_cmdline_get_param_rhs returned NULL" );
0147     rtems_test_assert( p );
0148     printf(
0149       "rtems_bsp_cmdline_get_param_rhs(%s) returned (%s) value=(%s)\n",
0150       param,
0151       ((*p == '\0') ? "ZERO_LENGTH_STRING" : p ),
0152       ((*value == '\0') ? "ZERO_LENGTH_STRING" : value )
0153     );
0154   }
0155 
0156 }
0157 
0158 rtems_task Init(
0159   rtems_task_argument ignored
0160 )
0161 {
0162   const char *bspcmdline;
0163 
0164   TEST_BEGIN();
0165 
0166   bspcmdline = rtems_bsp_cmdline_get();
0167   if ( bspcmdline ) {
0168     printf(
0169       "BSP has a boot command line:\n"
0170       "%s\n",
0171       bspcmdline
0172     );
0173   } else {
0174     puts( "BSP does not have a boot command line" );
0175   }
0176 
0177   puts( "\nTest Parameter Error Conditions" );
0178   test_errors();
0179 
0180   test_search( false, "--arg=", "--arg" );
0181   test_search( true, "--arg=", "-g" );
0182   test_search( false, "--ip=192.168.1.151 --name=fred", "-name" );
0183   test_search( false, "--ip=192.168.1.151 --name=fred", "-ip" );
0184   test_search(
0185     false,
0186     "--ip=192.168.1.151 --name=\"joel and michele\" --cpu=fast",
0187     "-name"
0188     );
0189 
0190   TEST_END();
0191   rtems_test_exit(0);
0192 }
0193 
0194 /* configuration information */
0195 
0196 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0197 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0198 
0199 #define CONFIGURE_MAXIMUM_TASKS         1
0200 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0201 
0202 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0203 
0204 #define CONFIGURE_INIT
0205 #include <rtems/confdefs.h>
0206 
0207 /* global variables */