xvfb_test_script.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. """Simple script for xvfb_unittest to launch.
  6. This script outputs formatted data to stdout for the xvfb unit tests
  7. to read and compare with expected output.
  8. """
  9. from __future__ import print_function
  10. import os
  11. import signal
  12. import sys
  13. import time
  14. def print_signal(sig, *_):
  15. # print_function does not guarantee its output won't be interleaved
  16. # with other logging elsewhere, but it does guarantee its output
  17. # will appear intact. Because the tests parse via starts_with, prefix
  18. # with a newline. These tests were previously flaky due to output like
  19. # > Signal: 1 <other messages>.
  20. print('\nSignal :{}'.format(sig))
  21. if __name__ == '__main__':
  22. signal.signal(signal.SIGTERM, print_signal)
  23. signal.signal(signal.SIGINT, print_signal)
  24. # test the subprocess display number.
  25. print('\nDisplay :{}'.format(os.environ.get('DISPLAY', 'None')))
  26. if len(sys.argv) > 1 and sys.argv[1] == '--sleep':
  27. time.sleep(2) # gives process time to receive signal.