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