1#!/usr/bin/env python3
2#
3# Functional test that boots known good tuxboot images the same way
4# that tuxrun (www.tuxrun.org) does. This tool is used by things like
5# the LKFT project to run regression tests on kernels.
6#
7# Copyright (c) 2023 Linaro Ltd.
8#
9# Author:
10#  Alex Bennée <alex.bennee@linaro.org>
11#
12# SPDX-License-Identifier: GPL-2.0-or-later
13
14import os
15import time
16
17from unittest import skipUnless
18from qemu_test import Asset, exec_command_and_wait_for_pattern
19from qemu_test.tuxruntest import TuxRunBaselineTest
20
21class TuxRunSh4Test(TuxRunBaselineTest):
22
23    ASSET_SH4_KERNEL = Asset(
24        'https://storage.tuxboot.com/20230331/sh4/zImage',
25        '29d9b2aba604a0f53a5dc3b5d0f2b8e35d497de1129f8ee5139eb6fdf0db692f')
26    ASSET_SH4_ROOTFS = Asset(
27        'https://storage.tuxboot.com/20230331/sh4/rootfs.ext4.zst',
28        '3592a7a3d5a641e8b9821449e77bc43c9904a56c30d45da0694349cfd86743fd')
29
30    def test_sh4(self):
31        self.set_machine('r2d')
32        self.cpu='sh7785'
33        self.root='sda'
34        self.console='ttySC1'
35
36        # The test is currently too unstable to do much in userspace
37        # so we skip common_tuxrun and do a minimal boot and shutdown.
38        (kernel, disk, dtb) = self.fetch_tuxrun_assets(self.ASSET_SH4_KERNEL,
39                                                       self.ASSET_SH4_ROOTFS)
40
41        # the console comes on the second serial port
42        self.prepare_run(kernel, disk,
43                         "driver=ide-hd,bus=ide.0,unit=0",
44                         console_index=1)
45        self.vm.launch()
46
47        self.wait_for_console_pattern("tuxtest login:")
48        exec_command_and_wait_for_pattern(self, 'root', 'root@tuxtest:~#')
49        exec_command_and_wait_for_pattern(self, 'halt',
50                                          "reboot: System halted")
51
52if __name__ == '__main__':
53    TuxRunBaselineTest.main()
54