~compiz-team/compiz/compiz.fix_1130160

« back to all changes in this revision

Viewing changes to tests/xorg-gtest/src/compiz-xorg-gtest.cpp

  • Committer: Tarmac
  • Author(s): Sam Spilsbury
  • Date: 2013-02-19 14:44:27 UTC
  • mfrom: (3554.6.19 compiz.fix_1120009)
  • Revision ID: tarmac-20130219144427-2xzi2f9b4ap9b2r0
Enable xorg-gtest tests by default and build in CI.

This change also refactors a number of parts of the code to find and build the tests. It puts the logic to find Google Test and Xorg GTest in their own cmake files, and also splits the find logic with the build logic. Finally, it makes the xorg-gtest variables available to all subdirectories and not just the ones under tests/.

This change also refreshes some distro patches. A new option was added to not auto-load the ccp plugin, and also modifies one of the tests depending on a modified setting value.

(LP: #1120009). Fixes: https://bugs.launchpad.net/bugs/1120009.

Approved by Sam Spilsbury, Andrea Azzarone.

Show diffs side-by-side

added added

removed removed

Lines of Context:
504
504
void
505
505
ct::CompizXorgSystemTest::SetUp ()
506
506
{
507
 
    xorg::testing::Test::SetUp ();
 
507
    const unsigned int MAX_CONNECTION_ATTEMPTS = 10;
 
508
    const unsigned int USEC_TO_MSEC = 1000;
 
509
    const unsigned int SLEEP_TIME = 50 * USEC_TO_MSEC;
 
510
 
 
511
    unsigned int connectionAttemptsRemaining = MAX_CONNECTION_ATTEMPTS;
 
512
 
 
513
    /* Work around an inherent race condition in XOpenDisplay
 
514
     *
 
515
     * All xorg::testing::Test::SetUp does is call XOpenDisplay
 
516
     * and assign a display string, the former before the latter.
 
517
     * The current X Error handler will throw an exception if
 
518
     * an X error occurrs.
 
519
     *
 
520
     * Unfortunately there's an inherent race condition in spawning
 
521
     * a new server and using XOpenDisplay to connect to it - we
 
522
     * simply don't know when the new server will be ready, and even
 
523
     * watching its socket with inotify will be racey too. The only
 
524
     * solution would be a handshake process where we pass the server
 
525
     * a socket or pipe and it writes to it indicating that it is ready
 
526
     * to accept connections. There isn't such a thing. As such, we need
 
527
     * to work around that by simply re-trying our connection to the server
 
528
     * once every 50ms or so, and we're trying about 10 times before giving up
 
529
     * and assuming there is a problem with the server.
 
530
     */
 
531
    while (connectionAttemptsRemaining--)
 
532
    {
 
533
        try
 
534
        {
 
535
            xorg::testing::Test::SetUp ();
 
536
            break;
 
537
        }
 
538
        catch (std::runtime_error &exception)
 
539
        {
 
540
            usleep (SLEEP_TIME);
 
541
        }
 
542
    }
 
543
 
 
544
    if (!connectionAttemptsRemaining)
 
545
    {
 
546
        throw std::runtime_error ("Failed to connect to X Server. "\
 
547
                                  "Check the logs by setting "\
 
548
                                  "XORG_GTEST_CHILD_STDOUT=1 to see if "\
 
549
                                  "there are any startup errors. Otherwise "\
 
550
                                  "if you suspect the server is running "\
 
551
                                  "particularly slowly, try bumping up the "\
 
552
                                  "maximum number of connection attempts in "\
 
553
                                  "compiz-xorg-gtest.cpp");
 
554
    }
508
555
}
509
556
 
510
557
void