Typo in assert error message causing confusion?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Typo in assert error message causing confusion?

Daniel Zebralla
From /host/infra/cyg_ass.h as well as /host/infra/cyg/infra/cyg_ass.h:

# define CYG_CHECK_DATA_PTRC( _ptr_ )                   \
         CYG_MACRO_START                                \
         if ( !cyg_check_data_ptr((void *)(_ptr_)))     \
             CYG_ASSERT_DOCALL("data pointer (" #_ptr_ ") is valid");\
         CYG_MACRO_END

# define CYG_CHECK_FUNC_PTRC( _ptr_ )                       \
         CYG_MACRO_START                                    \
         if ( !cyg_check_func_ptr((void (*)(void))(_ptr_))) \
             CYG_ASSERT_DOCALL("function pointer (" #_ptr_ ") is valid"); \
         CYG_MACRO_END

As I understand, CYG_ASSERT_DOCALL is triggered when the checked data or function pointer is invalid. The printed message however indicates that the checked pointer is valid. Is this an error or am I misunderstanding the usage of CYG_ASSERT_DOCALL here?

Thanks for clarification!
Reply | Threaded
Open this post in threaded view
|

Re: Typo in assert error message causing confusion?

Michael Jones
Daniel,

I think it is printing the assertion, not the failure.

It would be clearer if it printed:

Assertion "data pointer NNN is valid" failed

But it might be consistent with standard practice. I am not sure.

Mike



On Oct 1, 2013, at 3:01 AM, Daniel Zebralla <[hidden email]> wrote:

>> From /host/infra/cyg_ass.h as well as /host/infra/cyg/infra/cyg_ass.h:
>
> # define CYG_CHECK_DATA_PTRC( _ptr_ )                   \
>         CYG_MACRO_START                                \
>         if ( !cyg_check_data_ptr((void *)(_ptr_)))     \
>             CYG_ASSERT_DOCALL("data pointer (" #_ptr_ ") is valid");\
>         CYG_MACRO_END
>
> # define CYG_CHECK_FUNC_PTRC( _ptr_ )                       \
>         CYG_MACRO_START                                    \
>         if ( !cyg_check_func_ptr((void (*)(void))(_ptr_))) \
>             CYG_ASSERT_DOCALL("function pointer (" #_ptr_ ") is valid"); \
>         CYG_MACRO_END
>
> As I understand, CYG_ASSERT_DOCALL is triggered when the checked data or
> function pointer is invalid. The printed message however indicates that the
> checked pointer is valid. Is this an error or am I misunderstanding the
> usage of CYG_ASSERT_DOCALL here?
>
> Thanks for clarification!
>
>
>
> --
> View this message in context: http://sourceware-org.1504.n7.nabble.com/Typo-in-assert-error-message-causing-confusion-tp245807.html
> Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.
>
> --
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
>


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: Typo in assert error message causing confusion?

Daniel Zebralla
I get your point of view. However, I assume that someone would like to know what's broken instead of what would be the case if the message would have not been displayed. If my system stops with a kernel panic and tells me "Pointer is valid" I would be like -> oO.

As I can see inside eCos source, I'm not the only one understanding those assertion messages this way, some examples:
CYG_ASSERT( freeret , "Couldn't free!" );
CYG_ASSERT( interr == 0, "internal lock failed!" );
CYG_ASSERT( usertmp->next != NULL, "Couldn't find message queue user" );
CYG_ASSERT( stacksize >= PTHREAD_STACK_MIN, "Inadequate stack size supplied");
CYG_ASSERT( ticks != 0, "Zero tick count");

To sum it up:
- Some eCos developers use assertion messages to say what failed
- Some eCos developers use assertion messages to say what would have passed
This inconsistency confuses people like me, new to eCos and debugging something which I don't fully understand yet.

Any further comments/opinions?
- Daniel
Reply | Threaded
Open this post in threaded view
|

Re: Typo in assert error message causing confusion?

Stanislav Meduna
On 02.10.2013 13:26, Daniel Zebralla wrote:

> I get your point of view. However, I assume that someone would like to know
> what's broken instead of what would be the case if the message would have
> not been displayed.

The original assert macro that is in use for decades does _not_
contain an explanatory text and outputs the expression itself.
See e.g. http://www.manpagez.com/man/3/assert/

I.e. if the programmer says "I am asserting that ptr != 0" and it
is not true, it writes that the assertion "ptr != 0" failed.

If the CYG_ASSERT follows this schema, it should definitely
print what was expected.

> If my system stops with a kernel panic and tells me
> "Pointer is valid" I would be like -> oO.

As Michael says, it should tell you something along the lines
  Assertion "Pointer is valid" failed
which makes perfect sense.

See comments at the top of host/infra/cyg_ass.h - it indeed defines
it this way.
  CYG_ASSERT( pcount > 0, "Number of probes should be > 0!" );
Unfortunaly the very same file then spoils it with
  CYG_ASSERTCLASS( p, "Object at p is broken!" );
;)

Anyway, an assertion is a developer tool catching situations
the developer thinks can never happen. As such they are not
expected to be interpreted by anyone not able to look up the
source code and investigate what exactly went wrong.

--
                                      Stano


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss