blob: 9237aa2a1bed4dbe854c0b34c43a59929045cf18 [file] [log] [blame]
Ilia Samsonova00835302019-04-19 17:37:591#!/usr/bin/env python
Avi Drissmandfd880852022-09-15 20:11:092# Copyright 2019 The Chromium Authors
Ilia Samsonova00835302019-04-19 17:37:593# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
Ilia Samsonova00835302019-04-19 17:37:595"""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
Wenbin Zhangc56b1252021-10-05 02:49:0611from __future__ import print_function
12
Ilia Samsonova00835302019-04-19 17:37:5913import os
14import signal
15import sys
16import time
17
18
19def print_signal(sig, *_):
Matt Reichhoff36f6901c2021-11-09 18:40:1520 # 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 Samsonova00835302019-04-19 17:37:5926
27
28if __name__ == '__main__':
29 signal.signal(signal.SIGTERM, print_signal)
30 signal.signal(signal.SIGINT, print_signal)
31
Ilia Samsonova00835302019-04-19 17:37:5932 # test the subprocess display number.
Matt Reichhoff36f6901c2021-11-09 18:40:1533 print('\nDisplay :{}'.format(os.environ.get('DISPLAY', 'None')))
Ilia Samsonova00835302019-04-19 17:37:5934
35 if len(sys.argv) > 1 and sys.argv[1] == '--sleep':
36 time.sleep(2) # gives process time to receive signal.