• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""Simple script for xvfb_unittest to launch.
6
7This script outputs formatted data to stdout for the xvfb unit tests
8to read and compare with expected output.
9"""
10
11from __future__ import print_function
12
13import os
14import signal
15import sys
16import time
17
18
19def print_signal(sig, *_):
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))
26
27
28if __name__ == '__main__':
29  signal.signal(signal.SIGTERM, print_signal)
30  signal.signal(signal.SIGINT, print_signal)
31
32  # test the subprocess display number.
33  print('\nDisplay :{}'.format(os.environ.get('DISPLAY', 'None')))
34
35  if len(sys.argv) > 1 and sys.argv[1] == '--sleep':
36    time.sleep(2)  # gives process time to receive signal.
37