RTEMS printk fails for large unsigned integers

Joel Sherrill joel.sherrill at OARcorp.com
Sat Nov 28 18:04:10 UTC 2009


On 11/28/2009 11:53 AM, Joris van Rantwijk wrote:
> On 27 nov 2009, at 20:32, Joel Sherrill wrote:
>    
>> On 11/27/2009 01:27 PM, Ingolf Steinbach wrote:
>>      
>>>>> Furthermore, printing variable greater LONG_MAX with "%u"
>>>>> formating is
>>>>> invalid/non-portable code.
>>>>>            
>>> I currently do not know the documentation of printk(). But if it is
>>> similar to printf(), you would probably have to use "%lu" rather than
>>> just "%u" if you output an (unsigned) *long* integer as in your case.
>>>        
> Ok, now I see the point that Ingolf and Ralf are making.
> However, in my case the value is "unsigned int", but larger than
> LONG_MAX.
>
>    
>> It should be a subset of printf.  An addition to the manual
>> to document it would be appreciated.  Please submit a patch
>> against spprintk which illustrates any behavior you think is
>> deficient.
>>      
> Very well. This patch adds some problem cases.
>    
Great!  I added this test to help in the coverage analysis
and it may or may not be all the cases. :)
> I believe Sebastian Huber already plans to fix the bug.
>
> Currently the test does not output anything on sparc/leon3. I added
> APPLICATION_NEEDS_CONSOLE_DRIVER to fix that.
FWIW I have seen this one myself.  It is a bug on the leon3
BSP in that the uart is not initialized enough to support printk
unless the console driver is initialized.  I looked at it and didn't
pursue it.  It appears that the amba scan needs to occur.
>   Output from the test
> looks garbled in my terminal because '\n' is not translated to '\r
> \n'. Some BSPs insert '\r' but sparc doesn't; should it do that?
>
>    
I will need to review all the BSPs to see what they do.
This is an area that needs to be (1) consistent and (2) not
result in copied code across BSPs.
> There is a file with the expected output of the test. Is there a way
> to automatically run tests and have output verified against that file?
>
>    
There is a script in testsuites/tools which should assist in this
(generic/difftest).  It is probably far from perfect but an aid.

FWIW this patch isn't applying cleanly.  Can you attach it rather
than cutting and pasting?

And please include a ChangeLog entry.

Thanks.
> Joris.
> --
>
> Index: rtems/testsuites/sptests/spprintk/init.c
> ===================================================================
> RCS file: /usr1/CVS/rtems/testsuites/sptests/spprintk/init.c,v
> retrieving revision 1.5
> diff -c -3 -p -r1.5 init.c
> *** rtems/testsuites/sptests/spprintk/init.c	24 Oct 2009 06:14:30
> -0000	1.5
> --- rtems/testsuites/sptests/spprintk/init.c	28 Nov 2009 17:38:22 -0000
> *************** rtems_task Init(
> *** 53,58 ****
> --- 53,62 ----
>       printk( "%%-4s of joel -- (%-4s)\n", "joel" );
>       printk( "%%c of X -- (%c)\n", 'X' );
>
> +   /* large unsigned numbers */
> +   printk( "%%u of 3000000000 -- %u\n", 3000000000U);
> +   printk( "%%x of 0x87654321 -- %x\n", 0x87654321);
> +   printk( "%%p of 0x87654321 -- %p\n", (void *)0x87654321);
>
>       printk( "*** END OF TEST PRINTK ***\n" );
>       rtems_test_exit( 0 );
> *************** rtems_task Init(
> *** 61,66 ****
> --- 65,71 ----
>     /* configuration information */
>
>     #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
> + #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
>
>     #define CONFIGURE_MAXIMUM_TASKS           1
>
> Index: rtems/testsuites/sptests/spprintk/spprintk.scn
> ===================================================================
> RCS file: /usr1/CVS/rtems/testsuites/sptests/spprintk/spprintk.scn,v
> retrieving revision 1.3
> diff -c -3 -p -r1.3 spprintk.scn
> *** rtems/testsuites/sptests/spprintk/spprintk.scn	9 Nov 2009
> 14:30:10 -0000	1.3
> --- rtems/testsuites/sptests/spprintk/spprintk.scn	28 Nov 2009
> 17:38:22 -0000
> *************** bad format -- %lq in parentheses (q)
> *** 28,31 ****
> --- 28,34 ----
>     %-12s of joel -- (joel                )
>     %-4s of joel -- (joel)
>     %c of X -- (X)
> + %u of 3000000000 -- 3000000000
> + %x of 0x87654321 -- 87654321
> + %p of 0x87654321 -- 0x87654321
>     *** END OF TEST PRINTK ***
>
>    




More information about the users mailing list