1#!/usr/bin/env python3
2#
3# Functional tests for the Lemote Fuloong-2E machine.
4#
5# Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
6#
7# This work is licensed under the terms of the GNU GPL, version 2 or later.
8# See the COPYING file in the top-level directory.
9#
10# SPDX-License-Identifier: GPL-2.0-or-later
11
12import os
13import subprocess
14
15from qemu_test import QemuSystemTest
16from qemu_test import wait_for_console_pattern
17from unittest import skipUnless
18
19class MipsFuloong2e(QemuSystemTest):
20
21    timeout = 60
22
23    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
24    @skipUnless(os.getenv('RESCUE_YL_PATH'), 'RESCUE_YL_PATH not available')
25    def test_linux_kernel_2_6_27_isa_serial(self):
26        # Recovery system for the Yeeloong laptop
27        # (enough to test the fuloong2e southbridge, accessing its ISA bus)
28        # http://dev.lemote.com/files/resource/download/rescue/rescue-yl
29        sha = 'ab588d3316777c62cc81baa20ac92e98b01955c244dff3794b711bc34e26e51d'
30        kernel_path = os.getenv('RESCUE_YL_PATH')
31        output = subprocess.check_output(['sha256sum', kernel_path])
32        checksum = output.split()[0]
33        assert checksum.decode("utf-8") == sha
34
35        self.set_machine('fuloong2e')
36        self.vm.set_console()
37        self.vm.add_args('-kernel', kernel_path)
38        self.vm.launch()
39        wait_for_console_pattern(self, 'Linux version 2.6.27.7lemote')
40        cpu_revision = 'CPU revision is: 00006302 (ICT Loongson-2)'
41        wait_for_console_pattern(self, cpu_revision)
42
43
44if __name__ == '__main__':
45    QemuSystemTest.main()
46