xref: /aosp_15_r20/external/autotest/client/site_tests/graphics_LibDRM/graphics_LibDRM.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright (c) 2012 The Chromium OS 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.
5import logging
6
7from autotest_lib.client.bin import test, utils
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.cros import service_stopper
10from autotest_lib.client.cros.graphics import graphics_utils
11
12class graphics_LibDRM(graphics_utils.GraphicsTest):
13    version = 1
14    _services = None
15
16    def initialize(self):
17        super(graphics_LibDRM, self).initialize()
18        self._services = service_stopper.ServiceStopper(['ui'])
19
20    def cleanup(self):
21        super(graphics_LibDRM, self).cleanup()
22        if self._services:
23            self._services.restore_services()
24
25    def run_once(self):
26        keyvals = {}
27
28        # These are tests to run for all platforms.
29        tests_common = ['modetest']
30
31        # Determine which tests to run based on the architecture type.
32        tests_exynos5 = ['kmstest']
33        tests_mediatek = ['kmstest']
34        tests_qualcomm = ['kmstest']
35        tests_rockchip = ['kmstest']
36        arch_tests = {
37            'amd': [],
38            'arm': [],
39            'exynos5': tests_exynos5,
40            'i386': [],
41            'mediatek': tests_mediatek,
42            'qualcomm': tests_qualcomm,
43            'rockchip': tests_rockchip,
44            'tegra': [],
45            'x86_64': []
46        }
47        soc = utils.get_cpu_soc_family()
48        if not soc in arch_tests:
49            raise error.TestFail('Error: Architecture "%s" not supported.',
50                                 soc)
51        elif soc == 'tegra':
52            logging.warning('Tegra does not support DRM.')
53            return
54        tests = tests_common + arch_tests[soc]
55
56        # If UI is running, we must stop it and restore later.
57        self._services.stop_services()
58
59        for test in tests:
60            self.add_failures(test)
61            # Make sure the test exists on this system.  Not all tests may be
62            # present on a given system.
63            if utils.system('which %s' % test):
64                logging.error('Could not find test %s.', test)
65                keyvals[test] = 'NOT FOUND'
66                continue
67
68            # Run the test and check for success based on return value.
69            return_value = utils.system(test)
70            if return_value:
71                logging.error('%s returned %d', test, return_value)
72                keyvals[test] = 'FAILED'
73            else:
74                keyvals[test] = 'PASSED'
75                self.remove_failures(test)
76
77        self.write_perf_keyval(keyvals)
78        if self.get_failures():
79            raise error.TestFail('Failed: %d libdrm tests failed.'
80                                 % len(self.get_failures()))
81