xref: /aosp_15_r20/external/cronet/testing/xvfb_test_script.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1#!/usr/bin/env python
2# Copyright 2019 The Chromium Authors
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
8This script outputs formatted data to stdout for the xvfb unit tests
9to read and compare with expected output.
10"""
11
12from __future__ import print_function
13
14import os
15import signal
16import sys
17import time
18
19
20def print_signal(sig, *_):
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))
27
28
29if __name__ == '__main__':
30  signal.signal(signal.SIGTERM, print_signal)
31  signal.signal(signal.SIGINT, print_signal)
32
33  # test the subprocess display number.
34  print('\nDisplay :{}'.format(os.environ.get('DISPLAY', 'None')))
35
36  if len(sys.argv) > 1 and sys.argv[1] == '--sleep':
37    time.sleep(2)  # gives process time to receive signal.
38