diff --git a/README1.md b/README1.md deleted file mode 100644 index 9c62098d3ae5eb51641cfcc07250ce7d3cbd7d64..0000000000000000000000000000000000000000 --- a/README1.md +++ /dev/null @@ -1,61 +0,0 @@ -# 总体介绍: - -`oebuild`作为openEuler Embedded项目的开发工具,一直以来承担着openEuler Embedded入门的导引角色,目前oebuild已经集成了相当多的功能,例如OS构建,交叉编译链构建,oebuild插件管理,软件包在线部署等等功能,然后对于一个嵌入式系统的发布,测试这一环节必不可少,openEuler Embedded对于系统版本的发布有着严格测试要求,因此对于OS系统开发者来说,本地化测试就显得尤为重要,而对于openEuler生态的系统来说,mugen是openEuler社区开放的测试框架,提供公共配置和方法以便社区开发者进行测试代码的编写和执行,其中就包括了openEuler Embedded,此次设计的插件可以使oebuild能够通过mugen来实现嵌入式OS的本地化测试。 - -## 功能概述 - -该插件主要用于通过`oebuild`工具实现以下功能: - -- 自动化本地化Mugen测试集成。 -- 支持`qemu`与BSP等嵌入式环境的选择。 -- 配置远程环境以便使用`qemu`进行测试。 -- 提供多种测试套件选择,包括: - 1. Tiny镜像测试 - 2. OS基础测试 - 3. 嵌入式安全配置测试 - 4. 嵌入式基础开发测试 - -## 使用方法 - -该插件提供了通过`oebuild`命令行工具来运行`mugen`测试的能力。以下是一个典型的使用示例: - -### 1. 运行测试 - -```bash -bash oebuild mugen-test --env bsp --mugen-path /path/to/mugen -``` - ---env 参数用于指定测试环境,可以是qemu或者bsp。 ---mugen-path 指定mugen工具的安装路径。 - -### 2. 选择测试套件 - -执行上述命令后,您将能够选择需要运行的测试套件: - -- Tiny镜像测试 -- OS基础测试 -- 嵌入式安全配置测试 -- 嵌入式基础开发测试 - -根据测试需求,选择对应的测试套件。 - -### 3. QEMU远程测试配置 - -如果选择了`qemu`环境,则需要提供远程测试的详细信息,例如IP地址、用户名、密码等: - -```bash -bash oebuild mugen-test --env qemu --mugen-path /path/to/mugen --ip 192.168.0.100 --user root --password your_password --port 22 -``` ---ip 指定远程测试机器的IP地址 ---user 指定远程测试机器的用户名 ---password 指定远程测试机器的密码 - - -停止QEMU -在OS基础测试、嵌入式安全配置测试或嵌入式基础开发测试完成后,可以使用以下命令停止QEMU: - -```bash -bash bash qemu_ctl.sh stop -``` - - diff --git a/src/oebuild/app/plugins/mugentest/mugentest.py b/src/oebuild/app/plugins/mugentest/mugentest.py index c57c1fbde44db54c7ebc9b562f3e6142e219352a..3743320e3b96eda4c849f6320db8504ae6f80809 100644 --- a/src/oebuild/app/plugins/mugentest/mugentest.py +++ b/src/oebuild/app/plugins/mugentest/mugentest.py @@ -1,6 +1,6 @@ """ MugenTest module to run Mugen test cases for openEuler Embedded OS. -Supports running tests in qemu and BSP environments. +Supports running tests in remote environments. """ import argparse @@ -18,13 +18,13 @@ logger = logging.getLogger() class MugenTest(OebuildCommand): """ MugenTest class allows running Mugen test cases for openEuler Embedded OS. - It supports both qemu and BSP environments. + It supports remote environments. """ name = 'mugentest' help_msg = 'This command allows you to run Mugen test cases for openEuler Embedded OS.' description = textwrap.dedent('''\ Run Mugen test cases for openEuler Embedded systems. - Select the environment (qemu or BSP) and specify the test case from a predefined list. + Configure remote testing and specify the test case from a predefined list. ''') def __init__(self): @@ -39,12 +39,13 @@ class MugenTest(OebuildCommand): def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: """ - Adds arguments to the parser for environment, Mugen path, and remote testing. + Adds arguments to the parser for Mugen path and remote testing. """ parser = self._parser( parser_adder, usage=textwrap.dedent('''\ - %(prog)s --env --mugen-path [other options] + %(prog)s --mugen-path --ip + --user --password [other options] Then select the test suite from the following options: 1 -- Tiny Image Test 2 -- OS Basic Test @@ -53,22 +54,23 @@ class MugenTest(OebuildCommand): ''') ) - parser.add_argument('--env', choices=['qemu', 'bsp'], required=True, - help='Specify the test environment: qemu or bsp') - parser.add_argument('--mugen-path', required=False, + parser.add_argument('--mugen-path', required=True, help='Specify the path to the Mugen installation') - parser.add_argument('--kernal_img_path', required=False, - help='Path to the QEMU kernel image') - parser.add_argument('--initrd_path', required=False, - help='Path to the QEMU initrd image') - parser.add_argument('--ip', required=False, - help='IP address for remote testing (required for qemu)') - parser.add_argument('--user', required=False, - help='Username for remote login (required for qemu)') - parser.add_argument('--password', required=False, - help='Password for remote login (required for qemu)') + parser.add_argument('--ip', required=True, + help='IP address for remote testing') + parser.add_argument('--user', required=True, + help='Username for remote login') + parser.add_argument('--password', required=True, + help='Password for remote login') parser.add_argument('--port', required=False, default=22, - help='SSH port (default is 22, required for qemu)') + help='SSH port (default is 22)') + # 注释掉的参数 + # parser.add_argument('--env', choices=['qemu', 'bsp'], required=True, + # help='Specify the test environment: qemu or bsp') + # parser.add_argument('--kernal_img_path', required=False, + # help='Path to the QEMU kernel image') + # parser.add_argument('--initrd_path', required=False, + # help='Path to the QEMU initrd image') return parser def do_run(self, args: argparse.Namespace, unknown=None): @@ -82,17 +84,45 @@ class MugenTest(OebuildCommand): args = args.parse_args(unknown) mugen_path = self.get_mugen_path(args.mugen_path) + self.check_and_install_lshw() + + self.setup_mugen_environment(mugen_path) + if not self.is_mugen_installed(mugen_path): print(f"Mugen not found at {mugen_path}. Please install Mugen first " f"or specify the correct path.") sys.exit(1) - if args.env == "qemu" and (not args.ip or not args.user or not args.password): - logger.error("For qemu environment, --ip, --user, and --password are required.") + if not args.ip or not args.user or not args.password: + logger.error("For remote testing, --ip, --user, and --password are required.") return self.select_test_suite(mugen_path, args) + def check_and_install_lshw(self): + """ + Check if lshw is installed, if not, install it. + """ + try: + subprocess.run(['lshw', '-version'], check=True) + print("lshw is already installed.") + except subprocess.CalledProcessError: + print("lshw is not installed. Installing lshw...") + sys.exit(0) + + def setup_mugen_environment(self, mugen_path): + """ + Sets up the Mugen environment by switching to the correct directory + and cleaning up old configurations. + """ + os.chdir(mugen_path) + env_file = os.path.join(mugen_path, 'conf', 'env.json') + if os.path.exists(env_file): + print(f"Removing existing {env_file}") + os.remove(env_file) + else: + print(f"No env.json found in {mugen_path}/conf.") + def get_mugen_path(self, custom_path=None): """ Returns the Mugen installation path, either custom or default. @@ -134,50 +164,70 @@ class MugenTest(OebuildCommand): def run_mugen_test(self, mugen_path, suite, args): """ - Runs the selected Mugen test suite based on the environment and user input. + Runs the selected Mugen test suite based on the user input. """ cmd = None try: print(f"Running {suite} with Mugen...") - if args.env == "qemu": - if suite == "embedded_tiny_image_test": - cmd = ( - f"bash {mugen_path}/mugen.sh -c --ip {args.ip} --password {args.password} " - f"--user {args.user} --port {args.port} --put_all --run_remote" - ) - else: - if not args.kernal_img_path or not args.initrd_path: - logger.error( - "For this test, --kernal_img_path and --initrd_path are required." - ) - return - qemu_start_cmd = ( - f"sh qemu_ctl.sh start --put_all --kernal_img_path {args.kernal_img_path} " - f"--initrd_path {args.initrd_path}" - ) - if suite in { - "embedded_os_basic_test", "embedded_security_config_test", - "embedded_application_develop_tests" - }: - qemu_start_cmd += " --qemu_type arm" - subprocess.run(qemu_start_cmd, shell=True, check=True) - - if suite == "embedded_application_develop_tests": - compile_cmd = f"bash {mugen_path}/mugen.sh -b {suite}" - subprocess.run(compile_cmd, shell=True, check=True) - - cmd = f"bash {mugen_path}/mugen.sh -f {suite} -s" - - elif args.env == "bsp": - cmd = f"bash {mugen_path}/mugen.sh -f {suite} -s" - - if cmd: - subprocess.run(cmd, shell=True, check=True) +# if args.env == "qemu": +# if suite == "embedded_tiny_image_test": +# cmd = ( +# f"bash {mugen_path}/mugen.sh -c --ip {args.ip} --password {args.password} " +# f"--user {args.user} --port {args.port} --put_all --run_remote" +# ) +# else: +# if not args.kernal_img_path or not args.initrd_path: +# logger.error( +# "For this test, --kernal_img_path and --initrd_path are required." +# ) +# return +# qemu_start_cmd = ( +# f"sh qemu_ctl.sh start --put_all --kernal_img_path {args.kernal_img_path} " +# f"--initrd_path {args.initrd_path}" +# ) +# if suite in { +# "embedded_os_basic_test", "embedded_security_config_test", +# "embedded_application_develop_tests" +# }: +# qemu_start_cmd += " --qemu_type arm" +# subprocess.run(qemu_start_cmd, shell=True, check=True) +# +# if suite == "embedded_application_develop_tests": +# compile_cmd = f"bash {mugen_path}/mugen.sh -b {suite}" +# subprocess.run(compile_cmd, shell=True, check=True) +# +# cmd = f"bash {mugen_path}/mugen.sh -f {suite} -s" +# +# elif args.env == "bsp": +# cmd = f"bash {mugen_path}/mugen.sh -f {suite} -s" +# +# if cmd: +# subprocess.run(cmd, shell=True, check=True) + + os.chdir(mugen_path) + + # Constructing the remote environment setup command + cmd = ( + f"bash mugen.sh -c --ip {args.ip} --password {args.password} " + f"--user {args.user} --port {args.port}" + ) + result = subprocess.run(cmd, shell=True, check=True) + + if result.returncode == 0: + print("Successfully configured and connected to the remote environment.") + else: + print(f"Failed to configure the remote environment." + f"Return code: {result.returncode}.") + sys.exit(result.returncode) + + # Running the selected test suite + cmd = f"bash mugen.sh -f {suite} -s" + result = subprocess.run(cmd, shell=True, check=True) + if result.returncode == 0: print(f"Test suite {suite} completed successfully.") - - if args.env == "qemu" and suite != "embedded_tiny_image_test": - subprocess.run("sh qemu_ctl.sh stop", shell=True, check=True) + else: + print(f"Test suite {suite} failed with return code {result.returncode}.") except subprocess.CalledProcessError as e: logger.error("Failed to run test suite %s: %s", suite, e)