#!/usr/bin/env python3

import common
import lkmc.import_path
from shell_helpers import LF

class Main(common.TestCliFunction):
    def __init__(self):
        super().__init__(
            description='''\
https://cirosantilli.com/linux-kernel-module-cheat#automated-tests
'''
        )
        self.add_argument(
            '--size',
            default=1,
            type=int,
            help='''\
Size of the tests to run. Scale:

* 1: a few seconds and important
* 2: < 5 minutes and important or a few seconds and not too important
* 3: all
'''
        )

    def timed_main(self):
        run_args = self.get_common_args()
        test_boot_args = run_args.copy()
        test_boot_args['size'] = self.env['size']
        self.run_test(lkmc.import_path.import_path_main('test-boot'), test_boot_args, 'test-boot')
        self.run_test(lkmc.import_path.import_path_main('test-userland-full-system'), run_args, 'test-userland')
        self.run_test(lkmc.import_path.import_path_main('test-executables'), {**run_args, **{'mode': 'baremetal'}}, 'test-executables-baremetal')
        self.run_test(lkmc.import_path.import_path_main('test-executables'), run_args, 'test-executables-userland')
        self.run_test(lkmc.import_path.import_path_main('test-gdb'), run_args, 'test-gdb')
        if self.env['emulator'] == 'gem5':
            gem5_unit_test_args = run_args.copy()
            gem5_unit_test_args['unit_tests'] = True
            self.run_test(lkmc.import_path.import_path_main('build-gem5'), gem5_unit_test_args, 'gem5-unit-tests')

if __name__ == '__main__':
    Main().cli()

