Ilia Samsonov | a0083530 | 2019-04-19 17:37:59 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2019 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Simple script for xvfb_unittest to launch. |
| 7 | |
| 8 | This script outputs formatted data to stdout for the xvfb unit tests |
| 9 | to read and compare with expected output. |
| 10 | """ |
| 11 | |
Wenbin Zhang | c56b125 | 2021-10-05 02:49:06 | [diff] [blame] | 12 | from __future__ import print_function |
| 13 | |
Ilia Samsonov | a0083530 | 2019-04-19 17:37:59 | [diff] [blame] | 14 | import os |
| 15 | import signal |
| 16 | import sys |
| 17 | import time |
| 18 | |
| 19 | |
| 20 | def print_signal(sig, *_): |
Matt Reichhoff | 36f6901c | 2021-11-09 18:40:15 | [diff] [blame] | 21 | # print_function does not guarantee its output won't be interleaved |
| 22 | # with other logging elsewhere, but it does guarantee its output |
| 23 | # will appear intact. Because the tests parse via starts_with, prefix |
| 24 | # with a newline. These tests were previously flaky due to output like |
| 25 | # > Signal: 1 <other messages>. |
| 26 | print('\nSignal :{}'.format(sig)) |
Ilia Samsonov | a0083530 | 2019-04-19 17:37:59 | [diff] [blame] | 27 | |
| 28 | |
| 29 | if __name__ == '__main__': |
| 30 | signal.signal(signal.SIGTERM, print_signal) |
| 31 | signal.signal(signal.SIGINT, print_signal) |
| 32 | |
Ilia Samsonov | a0083530 | 2019-04-19 17:37:59 | [diff] [blame] | 33 | # test the subprocess display number. |
Matt Reichhoff | 36f6901c | 2021-11-09 18:40:15 | [diff] [blame] | 34 | print('\nDisplay :{}'.format(os.environ.get('DISPLAY', 'None'))) |
Ilia Samsonov | a0083530 | 2019-04-19 17:37:59 | [diff] [blame] | 35 | |
| 36 | if len(sys.argv) > 1 and sys.argv[1] == '--sleep': |
| 37 | time.sleep(2) # gives process time to receive signal. |