summaryrefslogtreecommitdiff
path: root/tests/kms-test-modes.py
blob: c47848904ec464779a5b67e892598461216a3535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2017-2019 Renesas Electronics Corporation

import kmstest
import pykms

class ModesTest(kmstest.KMSTest):
    """Test all available modes on all available connectors."""

    def handle_page_flip(self, frame, time):
        self.logger.log('Page flip complete')

    def test_mode(self, connector, crtc, mode):
        self.logger.log(f'Testing connector {connector.fullname} '
                        f'on CRTC {crtc.id} with mode {mode.name}')

        # Create a frame buffer
        fb = pykms.DumbFramebuffer(self.card, mode.hdisplay, mode.vdisplay, 'XR24')
        pykms.draw_test_pattern(fb)

        # Perform the mode set
        ret = self.atomic_crtc_mode_set(crtc, connector, mode, fb)
        if ret < 0:
            raise RuntimeError(f'atomic mode set failed with {ret}')

        self.logger.log('Atomic mode set complete')
        self.run(4)
        self.atomic_crtc_disable(crtc)

        if self.flips == 0:
            raise RuntimeError('Page flip not registered')

    def main(self):
        for connector in self.output_connectors():
            self.start(f'modes on connector {connector.fullname}')

            # Skip disconnected connectors
            if not connector.connected():
                self.skip('unconnected connector')
                continue

            # Find a CRTC suitable for the connector
            crtc = connector.get_current_crtc()
            if not crtc:
                crtcs = connector.get_possible_crtcs()
                if len(crtcs) == 0:
                    pass

                crtc = crtcs[0]

            # Test all available modes
            modes = connector.get_modes()
            if len(modes) == 0:
                self.skip('no mode available')
                continue

            for i in range(len(modes)):
                try:
                    self.progress(i+1, len(modes))
                    self.test_mode(connector, crtc, modes[i])
                except RuntimeError as e:
                    self.fail(e.message)
                    break
            else:
                self.success()

ModesTest().execute()