1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import os 6 import logging 7 8 from autotest_lib.client.bin import test, utils 9 from autotest_lib.client.cros import service_stopper 10 from autotest_lib.client.cros.graphics import graphics_utils 11 12 # to run this test manually on a test target 13 # ssh root@machine 14 # cd /usr/local/autotest/deps/glbench 15 # stop ui 16 # ./windowmanagertest --screenshot1_sec 2 --screenshot2_sec 1 --cooldown_sec 1 \ 17 # --screenshot1_cmd \ 18 # "/usr/local/autotest/bin/screenshot.py screenshot1_generated.png" \ 19 # --screenshot2_cmd \ 20 # "/usr/local/autotest/bin/screenshot.py screenshot2_generated.png" 21 # start ui 22 23 class graphics_Sanity(test.test): 24 """ 25 This test is meant to be used as a quick sanity check for GL/GLES. 26 """ 27 version = 1 28 29 # None-init vars used by cleanup() here, in case setup() fails 30 _services = None 31 32 33 def setup(self): 34 self.job.setup_dep(['glbench']) 35 36 37 def initialize(self): 38 # If UI is running, we must stop it and restore later. 39 self._services = service_stopper.ServiceStopper(['ui']) 40 self._services.stop_services() 41 42 43 def cleanup(self): 44 if self._services: 45 self._services.restore_services() 46 47 48 def run_once(self): 49 """ 50 Draws a texture with a soft ellipse twice and captures each image. 51 Compares the output fuzzily against reference images. 52 """ 53 if utils.is_freon() and graphics_utils.get_display_resolution() is None: 54 logging.warning('Skipping test because there is no screen') 55 return 56 57 dep = 'glbench' 58 dep_dir = os.path.join(self.autodir, 'deps', dep) 59 self.job.install_pkg(dep, 'dep', dep_dir) 60 61 screenshot1_reference = os.path.join(self.bindir, 62 "screenshot1_reference.png") 63 screenshot1_generated = os.path.join(self.resultsdir, 64 "screenshot1_generated.png") 65 screenshot1_resized = os.path.join(self.resultsdir, 66 "screenshot1_generated_resized.png") 67 screenshot2_reference = os.path.join(self.bindir, 68 "screenshot2_reference.png") 69 screenshot2_generated = os.path.join(self.resultsdir, 70 "screenshot2_generated.png") 71 screenshot2_resized = os.path.join(self.resultsdir, 72 "screenshot2_generated_resized.png") 73 74 exefile = os.path.join(self.autodir, 'deps/glbench/windowmanagertest') 75 76 # Delay before screenshot: 1 second has caused failures. 77 options = ' --screenshot1_sec 2' 78 options += ' --screenshot2_sec 1' 79 options += ' --cooldown_sec 1' 80 # perceptualdiff can handle only 8 bit images. 81 if not utils.is_freon(): 82 screenshot_cmd = ' "DISPLAY=:1 import -window root %s"' 83 else: 84 screenshot_cmd = ' "/usr/local/autotest/bin/screenshot.py %s"' 85 options += ' --screenshot1_cmd' + screenshot_cmd % screenshot1_generated 86 options += ' --screenshot2_cmd' + screenshot_cmd % screenshot2_generated 87 88 cmd = exefile + ' ' + options 89 if not utils.is_freon(): 90 cmd = 'X :1 vt1 & sleep 1; chvt 1 && DISPLAY=:1 ' + cmd 91 try: 92 utils.run(cmd, 93 stdout_tee=utils.TEE_TO_LOGS, 94 stderr_tee=utils.TEE_TO_LOGS) 95 finally: 96 if not utils.is_freon(): 97 # Just sending SIGTERM to X is not enough; we must wait for it to 98 # really die before we start a new X server (ie start ui). 99 utils.ensure_processes_are_dead_by_name('^X$') 100 101 convert_cmd = ("convert -channel RGB -colorspace RGB -depth 8" 102 " -resize '100x100!' %s %s") 103 utils.system(convert_cmd % (screenshot1_generated, screenshot1_resized)) 104 utils.system(convert_cmd % (screenshot2_generated, screenshot2_resized)) 105 os.remove(screenshot1_generated) 106 os.remove(screenshot2_generated) 107 108 diff_cmd = 'perceptualdiff -verbose %s %s' 109 utils.system(diff_cmd % (screenshot1_reference, screenshot1_resized)) 110 utils.system(diff_cmd % (screenshot2_reference, screenshot2_resized)) 111