blob: 8100a9199f456d26532c70bebf98e39b5d208588 [file] [log] [blame]
Zach Reizner52bb0652016-09-15 15:07:54 -07001# Copyright 2016 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
Gurchetan Singhb1144312017-02-22 14:31:26 -08005import logging
Gurchetan Singh193a0f02017-06-09 16:02:27 -07006import os
Gurchetan Singha1f606b2017-11-17 16:43:23 -08007from autotest_lib.client.bin import utils
Ilja H. Friedel2f7624c2016-11-08 16:28:40 -08008from autotest_lib.client.common_lib import error
Zach Reizner52bb0652016-09-15 15:07:54 -07009from autotest_lib.client.cros import service_stopper
10from autotest_lib.client.cros.graphics import graphics_utils
11
12
Po-Hsien Wangb3708862017-05-11 16:33:16 -070013class DrmTest(object):
Zach Reizner52bb0652016-09-15 15:07:54 -070014
Chad Versace034373c2017-07-20 21:02:57 -070015 def __init__(self, name, command=None, **kargs):
16 """
17 @param name(str)
18 @param command(str): The shell command to run. If None, then reuse 'name'.
19 @param kargs: Test options
20 """
21
Po-Hsien Wangb3708862017-05-11 16:33:16 -070022 self._opts = {
23 'timeout': 20,
Po-Hsien Wang04d72022017-04-25 11:55:06 -070024 'display_required': True,
25 'vulkan_required': False,
26 'min_kernel_version': None
27 }
Po-Hsien Wangb3708862017-05-11 16:33:16 -070028 self._opts.update(kargs)
Chad Versace034373c2017-07-20 21:02:57 -070029 self.name = name
Po-Hsien Wangb3708862017-05-11 16:33:16 -070030 self._command = command
Chad Versace034373c2017-07-20 21:02:57 -070031 if self._command is None:
32 self._command = name
Po-Hsien Wang04d72022017-04-25 11:55:06 -070033
Po-Hsien Wangb3708862017-05-11 16:33:16 -070034 def can_run(self):
35 """Indicate if the test can be run on the configuration."""
Gurchetan Singhb1144312017-02-22 14:31:26 -080036 num_displays = graphics_utils.get_num_outputs_on()
Gurchetan Singhb1144312017-02-22 14:31:26 -080037 if num_displays == 0 and utils.get_device_type() == 'CHROMEBOOK':
Po-Hsien Wangb3708862017-05-11 16:33:16 -070038 # Sanity check to guard against incorrect silent passes.
39 logging.error('Error: found Chromebook without display.')
40 return False
41 return True
42
43 def should_run(self):
44 """Indicate if the test should be run on current configuration."""
45 supported_apis = graphics_utils.GraphicsApiHelper().get_supported_apis()
46 num_displays = graphics_utils.get_num_outputs_on()
Gurchetan Singh906a9072017-11-17 15:32:03 -080047 gpu_type = utils.get_gpu_family()
Gurchetan Singhee5c0c62017-11-17 15:52:38 -080048 soc = utils.get_cpu_soc_family()
49 kernel_version = os.uname()[2]
Po-Hsien Wangb3708862017-05-11 16:33:16 -070050 if num_displays == 0 and self._opts['display_required']:
Gurchetan Singhb1144312017-02-22 14:31:26 -080051 # If a test needs a display and we don't have a display,
52 # consider it a pass.
53 logging.warning('No display connected, skipping test.')
Po-Hsien Wangb3708862017-05-11 16:33:16 -070054 return False
55 if self._opts['vulkan_required'] and 'vk' not in supported_apis:
Po-Hsien Wang04d72022017-04-25 11:55:06 -070056 # If a test needs vulkan to run and we don't have it,
57 # consider it a pass
Po-Hsien Wangb3708862017-05-11 16:33:16 -070058 logging.warning('Vulkan is required by test but is not '
59 'available on system. Skipping test.')
60 return False
Gurchetan Singh193a0f02017-06-09 16:02:27 -070061 if self._opts['min_kernel_version']:
Gurchetan Singh193a0f02017-06-09 16:02:27 -070062 min_kernel_version = self._opts['min_kernel_version']
63 if utils.compare_versions(kernel_version, min_kernel_version) < 0:
64 logging.warning('Test requires kernel version >= %s,'
65 'have version %s. Skipping test.'
66 % (min_kernel_version, kernel_version))
67 return False
Gurchetan Singh906a9072017-11-17 15:32:03 -080068 if self.name == 'atomictest' and gpu_type == 'baytrail':
69 logging.warning('Baytrail is on kernel v4.4, but there is no '
70 'intention to enable atomic.')
71 return False
Po-Hsien Wangb3708862017-05-11 16:33:16 -070072 return True
Po-Hsien Wang04d72022017-04-25 11:55:06 -070073
Po-Hsien Wangb3708862017-05-11 16:33:16 -070074 def run(self):
Ilja H. Friedel2f7624c2016-11-08 16:28:40 -080075 try:
Po-Hsien Wangb3708862017-05-11 16:33:16 -070076 # TODO(pwang): consider TEE to another file if drmtests keep
77 # spewing so much output.
Chad Versace018e1742017-07-20 21:02:56 -070078 cmd_result = utils.run(
Po-Hsien Wangb3708862017-05-11 16:33:16 -070079 self._command,
80 timeout=self._opts['timeout'],
81 stderr_is_expected=True,
82 verbose=True,
83 stdout_tee=utils.TEE_TO_LOGS,
84 stderr_tee=utils.TEE_TO_LOGS
85 )
Chad Versace018e1742017-07-20 21:02:56 -070086 logging.info('Passed: %s', self._command)
87 logging.debug('Duration: %s: (%0.2fs)'
88 % (self._command, cmd_result.duration))
89 return True
Po-Hsien Wangb3708862017-05-11 16:33:16 -070090 except error.CmdTimeoutError as e:
Chad Versacef412ac42017-07-20 21:02:56 -070091 logging.error('Failed: Timeout while running %s (timeout=%0.2fs)'
92 % (self._command, self._opts['timeout']))
Po-Hsien Wangb3708862017-05-11 16:33:16 -070093 logging.debug(e)
94 return False
95 except error.CmdError as e:
96 logging.error('Failed: %s (exit=%d)' % (self._command,
97 e.result_obj.exit_status))
98 logging.debug(e)
99 return False
100 except Exception as e:
101 logging.error('Failed: Unexpected exception while running %s'
102 % self._command)
103 logging.debug(e)
104 return False
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700105
106drm_tests = {
Chad Versace034373c2017-07-20 21:02:57 -0700107 test.name: test
108 for test in (
Ilja H. Friedel2bdd37f2018-04-19 20:38:26 -0700109 DrmTest('atomictest', 'atomictest -a -t all', min_kernel_version='4.4',
110 timeout=120),
Chad Versace034373c2017-07-20 21:02:57 -0700111 DrmTest('drm_cursor_test'),
Chad Versace034373c2017-07-20 21:02:57 -0700112 DrmTest('linear_bo_test'),
Chad Versacee9407f12017-07-20 21:02:58 -0700113 DrmTest('mmap_test', timeout=300),
Chad Versace034373c2017-07-20 21:02:57 -0700114 DrmTest('null_platform_test'),
115 DrmTest('swrast_test', display_required=False),
Gurchetan Singh77365cc2018-04-02 09:18:58 -0700116 DrmTest('vgem_test'),
Chad Versace034373c2017-07-20 21:02:57 -0700117 DrmTest('vk_glow', vulkan_required=True),
118 )
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700119}
120
Po-Hsien Wanga9788692017-05-30 11:11:26 -0700121class graphics_Drm(graphics_utils.GraphicsTest):
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700122 """Runs one, several or all of the drm-tests."""
123 version = 1
124 _services = None
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700125
126 def initialize(self):
Po-Hsien Wanga9788692017-05-30 11:11:26 -0700127 super(graphics_Drm, self).initialize()
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700128 self._services = service_stopper.ServiceStopper(['ui'])
129 self._services.stop_services()
130
131 def cleanup(self):
132 if self._services:
133 self._services.restore_services()
Po-Hsien Wanga9788692017-05-30 11:11:26 -0700134 super(graphics_Drm, self).cleanup()
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700135
136 # graphics_Drm runs all available tests if tests = None.
Po-Hsien Wanga9788692017-05-30 11:11:26 -0700137 def run_once(self, tests=None, perf_report=False):
138 self._test_failure_report_enable = perf_report
Po-Hsien Wange83f6ea2017-12-08 18:58:19 -0800139 self._test_failure_report_subtest = perf_report
Chad Versacedaff3df2017-07-20 21:02:57 -0700140 for test in drm_tests.itervalues():
141 if tests and test.name not in tests:
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700142 continue
143
Chad Versacedaff3df2017-07-20 21:02:57 -0700144 logging.info('-----------------[%s]-----------------' % test.name)
Po-Hsien Wange83f6ea2017-12-08 18:58:19 -0800145 self.add_failures(test.name, subtest=test.name)
146 passed = False
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700147 if test.should_run():
148 if test.can_run():
Chad Versacedaff3df2017-07-20 21:02:57 -0700149 logging.debug('Running test %s.', test.name)
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700150 passed = test.run()
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700151 else:
Po-Hsien Wange83f6ea2017-12-08 18:58:19 -0800152 logging.info('Failed: test %s can not be run on current'
153 ' configurations.' % test.name)
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700154 else:
Po-Hsien Wange83f6ea2017-12-08 18:58:19 -0800155 passed = True
Chad Versacedaff3df2017-07-20 21:02:57 -0700156 logging.info('Skipping test: %s.' % test.name)
Po-Hsien Wangb3708862017-05-11 16:33:16 -0700157
Po-Hsien Wange83f6ea2017-12-08 18:58:19 -0800158 if passed:
159 self.remove_failures(test.name, subtest=test.name)
160
Po-Hsien Wanga9788692017-05-30 11:11:26 -0700161 if self.get_failures():
162 raise error.TestFail('Failed: %s' % self.get_failures())