Unit tests crashing on GTK2

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
vid512
Experienced Solver
Experienced Solver
Posts: 55
Joined: Mon Feb 08, 2010 10:16 am

Unit tests crashing on GTK2

Post by vid512 »

What is the current state of WxWidgets unit tests with GTK2? Are they supposed to be working?

I have tried running tests/test_gui from master branch (on linux, with GTK2) and very often I get undeterministic crash with this error message:

Code: Select all

Test program for wxWidgets GUI features
build: 3.1.6 (wchar_t,compiler with C++ ABI compatible with gcc 4,wx containers,compatible with 3.0)
compiled using gcc 10.2
running under Linux 5.10.0-9-amd64 x86_64 as vid
The program 'test_gui' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
  (Details: serial 12 error_code 8 request_code 42 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
As was said, the crash is non-determinstic. For example "test_gui wxTextCtrl*" passes about 50% of times.

All samples and wxWidgets apps work OK, so this seems to be something related to the testing framework. Any idea how to go on analyzing and solving this?
vid512
Experienced Solver
Experienced Solver
Posts: 55
Joined: Mon Feb 08, 2010 10:16 am

Re: Unit tests crashing on GTK2

Post by vid512 »

After some experiments, I am fairly certain that this is a race condition, caused by wxYield() not really doing what it is expected to (eg. to ensure that all controls are fully realized before going on with tests). I just have easier time hitting this race condition, becuase I am running tests on a old computer, where the creation of GTK window takes longer time.

This is especially apparent when running test_gui with GTK3, where window takes about 1.5 second to appear. I can see simulated input from wxUIActionSimulator being entered into console from which I started the test_gui, before the window has even appeared. Obviously, affected tests then failed afterwars.

This explanation is also supported by number of embarassing hacks infound the TextCtrl test code, by people who encountered this problem and tried to workaround it in creative ways:

Code: Select all

// textentrytest.cpp:280
#ifdef __WXGTK__
    // For some reason, wxBitmapComboBox doesn't appear on the screen without
    // this (due to wxTLW size hacks perhaps?). It would be nice to avoid doing
    // this, but without this hack the test often (although not always) fails.
    wxMilliSleep(50);
#endif // __WGTK__

// textctrltest.cpp:450
    // For some reason, this test sporadically fails when run in AppVeyor or
    // GitHub Actions CI environments, even though it passes locally.
    if ( IsAutomaticTest() )
        return;

// textctrltest.cpp:757
    // wxGTK needs to yield here to update the text control.
#ifdef __WXGTK__
    wxStopWatch sw;
    while ( m_text->PositionToCoords(0).y == 0 ||
                m_text->PositionToCoords(pos).y > TEXT_HEIGHT )
    {
        if ( sw.Time() > 1000 )
        {
            FAIL("Timed out waiting for wxTextCtrl update.");
            break;
        }

        wxYield();
    }
#endif // __WXGTK__

//textctrltest.cpp:397
    #ifdef __WXGTK__
        // wxGTK must be given an opportunity to lay the text out.
        for ( wxStopWatch sw; sw.Time() < 50; )
            wxYield();
    #endif
Simply adding few hundred millisecond wait at the beginning of every "wxTextCtrl*" test solved all issues for me, both on GTK2 and GTK3. I think the wxYield clearly needs an overhaul, or to be replaced by something else for tests on GTK platform. That is, unfortunately, something I don't know how to do.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Unit tests crashing on GTK2

Post by ONEEYEMAN »

Hi,
Could you please post to wx-dev mailing list with you findings?

This forum is for the users by the users of the library.

Thank you.
vid512
Experienced Solver
Experienced Solver
Posts: 55
Joined: Mon Feb 08, 2010 10:16 am

Re: Unit tests crashing on GTK2

Post by vid512 »

Will do. Thanks for explanation, I wasn't clear where to reach devs.
Post Reply