[Dev] Asserts? (was: RE: Keyboard issues with Weston and AGL application suite)

Derek Foreman derekf at osg.samsung.com
Thu Oct 15 17:21:47 GMT 2015


On 15/10/15 11:26 AM, Andersson, Gunnar wrote:
> This is not really on topic...
> 
> But seeing this issue just reminds me of a question that nags me. 
> 
> Why do people not use asserts in most projects?   Is it considered 
> to be ugly noise, is it not "cool" to use them, ... or what?
> 
> It's just that in a line like the original one (this is just an example)
>    
>    &context->input_method->seat->keyboard->input_method_grab;
> 
> at least my brain *cannot* avoid asking if every pointer is valid...
> 
> Is it just obviously assumed that of course no one has accidentally 
> left a null or uninitialized pointer there or is it that most programmers
> simply prefer to crash, debug, and then fix?   In other words assume
> everything is alright until crash?  Maybe that is a worthwhile trade-off
> I don't know - personally I prefer asserting.
> 
> Don't get me wrong, the bug fix you made is fine... but yet 
> use of asserts might have reported the exact location of a bug
> with what I would assume significantly reduced debugging time,
> and the person asking the question may even be able to find it
> himself?
> 
> So, opinion question... why do people not use asserts?   Is it not a 
> worthwhile trade-off?
> 

There are well over 1000 assert()s between weston and wayland, so we're
certainly not afraid of them.  (A quick grep shows 1400+ but some are in
test cases...)

For that pointer string you selected, input_method->seat is initialized
in text_backend_seat_creation() - if we have an input_method, it has a
valid seat.

seat->keyboard is only true if the seat has ever had a keyboard (it's
actually nasty, and the reason why the current code accesses the
keyboard through helper functions).  This was the source of the bug, and
it's really unassertable outside of this function.  We can get there
without a keyboard, and that's ok.  We just have to handle it when it
happens.

As to the rest, where would you put the asserts?  Just putting a stack
of asserts in that function seems pretty worthless since it's little
more informative than a segfault.

I fear the answer is frequently: The assert should go where you forgot
to set the pointer properly in the first place.  Well, just setting the
pointer there is really all that's required then.

For myself, I think I add more asserts for "boolean value isn't
appropriate here" and "integer value is out of range" than I do for
"pointer is NULL".

I just think it's harder to catch the "NULL pointer I'm not actually
using in this function is going to bite me much later" case?

All that said, if you want to add more asserts to weston and wayland,
I'll gladly review any submissions, feel free to CC me directly and
quote this e-mail. ;)

I wouldn't mind seeing more asserts in weston at all, I think it'd
improve at-a-glance readability in some cases, and it is supposed to be
"reference" code...

> Best Regards
> - Gunnar
> 
> -----Original Message-----
> From: genivi-projects-bounces at lists.genivi.org [mailto:genivi-projects-bounces at lists.genivi.org] On Behalf Of Derek Foreman
> Sent: den 14 oktober 2015 19:11
> To: Leon Anavi
> Cc: dev at lists.tizen.org; ivi at lists.tizen.org; genivi-projects at lists.genivi.org; automotive-discussions at lists.linuxfoundation.org
> Subject: Re: Keyboard issues with Weston and AGL application suite
> 
> On 14/10/15 05:31 AM, Leon Anavi wrote:
>> Hi Derek, All,
>>
>> Derek, I am experiencing similar issues with weston-keyboard as in your
>> article "When is a Keyboard Not a Keyboard?" which has been published at
>> Samsung OSG blog.
>>
>> Could you please provide me help how to get Weston 1.6 working with the
>> virtual weston-keyboard in the HTML5 apps from the AGL app suite when
>> hardware keyboard is not present?
> 
> Looks like a bug I fixed last December, actually:
> http://cgit.freedesktop.org/wayland/weston/commit/?id=f0aaa417
> 
> Fairly small so it might be an easy forward port...
> 
> Hope that helps a bit,
> Derek
> 
>> In my case Weston keeps crashing when I type in HTML5 input fields from
>> the AGL apps through the virtual weston-keyboard if no hardware keyboard
>> is attached. I am working on a Tizen image that contains Wayland and
>> Weston 1.6, Crosswalk 11.40.277.0 and libinput 0.6.0. Please have a look
>> at my test cases for more details:
>>
>> * Test case 1, weston.ini:
>>
>> [input-method]
>> path=/usr/libexec/weston-keyboard
>>
>> [keyboard]
>> keymap_layout=wkb
>>
>> Results:
>>
>> 1.1. No hardware keyboard: FAIL
>> Weston crashes when the user tries to launch Browser from the Homescreen
>> app:
>>
>> [00:00:32.676] caught signal: 11
>>
>> 1.2. With hardware keyboard: FAIL
>>
>> Weston detects the hardware keyboard:
>>
>> [00:00:07.480] input device 'SEM USB Keyboard', /dev/input/event0 is a
>> keyboard
>> [00:00:07.481] input device 'SEM USB Keyboard', /dev/input/event1 is a
>> keyboard
>>
>> Weston crashes when the user tries to launch Browser from the Homescreen
>> app:
>>
>> [00:00:49.925] caught signal: 11
>>
>>
>> * Test case 2, weston.ini:
>>
>> [input-method]
>> path=
>>
>> [keyboard]
>> keymap_layout=wkb
>>
>> Results:
>> 2.1. No hardware keyboard: OK with remark - there is no virtual keyboard
>> (as expected) so there is no way to type.
>>
>> 2.2. With hardware keyboard: FAIL
>>
>> Weston detects the hardware keyboard:
>>
>> [00:00:06.586] input device 'SEM USB Keyboard', /dev/input/event0 is a
>> keyboard
>> [00:00:06.587] input device 'SEM USB Keyboard', /dev/input/event1 is a
>> keyboard
>>
>> Weston fails as soon as the user starts to type in HTML5 input field for
>> URL at the Browser app through the hardware keyboard:
>>
>> [00:00:48.006] caught signal: 11
>>
>> * Test case 3, weston.ini:
>>
>> [input-method]
>> path=/usr/libexec/weston-keyboard
>>
>> [keyboard]
>> keymap_layout=us
>>
>> Results:
>> 3.1. No hardware keyboard: FAIL
>>
>> Weston crashes when the user tries to launch Browser from the Homescreen
>> app:
>>
>> [00:00:28.391] caught signal: 11
>>
>> 3.2. With hardware keyboard: OK
>>
>> Weston detects the hardware keyboard and both the hardware and virtual
>> weston-keyboard work fine:
>>
>> [00:00:06.767] input device 'SEM USB Keyboard', /dev/input/event0 is a
>> keyboard
>> [00:00:06.771] input device 'SEM USB Keyboard', /dev/input/event1 is a
>> keyboard
>>
>> I want to get weston-keyboard working fine in Weston even if there is no
>> hardware keyboard.
>>
>> Thanks,
>> Leon
>>
> 
> _______________________________________________
> genivi-projects mailing list
> genivi-projects at lists.genivi.org
> https://lists.genivi.org/mailman/listinfo/genivi-projects
> 



More information about the Dev mailing list