From patchwork Sun Jun 13 12:47:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 12317567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49469C48BDF for ; Sun, 13 Jun 2021 12:47:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15C8D61057 for ; Sun, 13 Jun 2021 12:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231779AbhFMMtk (ORCPT ); Sun, 13 Jun 2021 08:49:40 -0400 Received: from mga01.intel.com ([192.55.52.88]:40833 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbhFMMtk (ORCPT ); Sun, 13 Jun 2021 08:49:40 -0400 IronPort-SDR: Xnh/JsDakQSzb3sNRQzTbDhDiyymf0G2zKqFXGfKFfuuOiBWnUJcvR/KQSmmRsE2eL4w2dF+ui pNQhpfkpaHfQ== X-IronPort-AV: E=McAfee;i="6200,9189,10013"; a="227158359" X-IronPort-AV: E=Sophos;i="5.83,271,1616482800"; d="scan'208";a="227158359" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2021 05:47:39 -0700 IronPort-SDR: pByYOUl8OyeCceHPExXLVBDmFh9lLxMTjm8C0sO+2FeR7EB267B8K1fA6F2EqTn+thyS3EJ9vL 9rlvIEWrBSGA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,271,1616482800"; d="scan'208";a="487109870" Received: from sunyi-u2010.sh.intel.com ([10.239.48.3]) by fmsmga002.fm.intel.com with ESMTP; 13 Jun 2021 05:47:38 -0700 From: Yi Sun To: nadav.amit@gmail.com, yi.sun@intel.com, kvm@vger.kernel.org Cc: gordon.jin@intel.com Subject: [PATCH v3 1/2] x86: Build ISO images from x86/*.elf Date: Sun, 13 Jun 2021 20:47:23 +0800 Message-Id: <20210613124724.1850051-2-yi.sun@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210613124724.1850051-1-yi.sun@intel.com> References: <20210613124724.1850051-1-yi.sun@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make use of tool grub-mkresure to wrap x86/*.elf in ISO images. VMM could load test cases just like a CD-ROM, which could extend usage of those cases. Refine Makefile to clean *.iso when running 'make clean'. Signed-off-by: Yi Sun diff --git a/lib/grub/grub.cfg b/lib/grub/grub.cfg new file mode 100644 index 0000000..b287cf4 --- /dev/null +++ b/lib/grub/grub.cfg @@ -0,0 +1,7 @@ +set timeout=0 +set default=0 + +menuentry "my os" { + multiboot /boot/kernel.bin + boot +} diff --git a/x86/Makefile.common b/x86/Makefile.common index 52bb7aa..62eea51 100644 --- a/x86/Makefile.common +++ b/x86/Makefile.common @@ -50,6 +50,22 @@ FLATLIBS = lib/libcflat.a $(OBJCOPY) -O elf32-i386 $^ $@ @chmod a-x $@ +grub_cfg := lib/grub/grub.cfg + +elf_files := $(wildcard ./x86/*.elf) +iso_files := $(patsubst %.elf,%.iso,$(elf_files)) + +%.iso: %.elf + @echo "Creating ISO for case: $(notdir $<)" + @rm -rf build/isofiles + @mkdir -p build/isofiles/boot/grub + @cp $< build/isofiles/boot/kernel.bin + @cp $(grub_cfg) build/isofiles/boot/grub + @grub-mkrescue -o $@ build/isofiles 2> /dev/null + +iso: $(iso_files) + echo "All ISO created successfully!" + tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/smptest.flat \ $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \ @@ -81,5 +97,5 @@ $(TEST_DIR)/hyperv_stimer.elf: $(TEST_DIR)/hyperv.o $(TEST_DIR)/hyperv_connections.elf: $(TEST_DIR)/hyperv.o arch_clean: - $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ + $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf $(TEST_DIR)/*.iso \ $(TEST_DIR)/.*.d lib/x86/.*.d \ From patchwork Sun Jun 13 12:47:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 12317569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AF67C48BE8 for ; Sun, 13 Jun 2021 12:47:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2C2861057 for ; Sun, 13 Jun 2021 12:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231785AbhFMMtm (ORCPT ); Sun, 13 Jun 2021 08:49:42 -0400 Received: from mga01.intel.com ([192.55.52.88]:40833 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231782AbhFMMtl (ORCPT ); Sun, 13 Jun 2021 08:49:41 -0400 IronPort-SDR: Lp+97yMOId7BxGJplxcGP2llZBXfeWOjOIFR6yo/duC1kBYuH6Y+ANKm8wtUqs3ViOsffnrr+0 riuO8AUOMNCQ== X-IronPort-AV: E=McAfee;i="6200,9189,10013"; a="227158361" X-IronPort-AV: E=Sophos;i="5.83,271,1616482800"; d="scan'208";a="227158361" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2021 05:47:40 -0700 IronPort-SDR: 46cT6pQRJTQBbh0hHqnSkC3AdkJWO5uJvgb+9wiE8VKpL6JRqFtmQFzcqP3JA1EKpSLvBkZxHl Mz3FdpM1Z1sw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,271,1616482800"; d="scan'208";a="487109875" Received: from sunyi-u2010.sh.intel.com ([10.239.48.3]) by fmsmga002.fm.intel.com with ESMTP; 13 Jun 2021 05:47:39 -0700 From: Yi Sun To: nadav.amit@gmail.com, yi.sun@intel.com, kvm@vger.kernel.org Cc: gordon.jin@intel.com Subject: [PATCH v3 2/2] x86: Create ISO images according to unittests.cfg Date: Sun, 13 Jun 2021 20:47:24 +0800 Message-Id: <20210613124724.1850051-3-yi.sun@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210613124724.1850051-1-yi.sun@intel.com> References: <20210613124724.1850051-1-yi.sun@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Create ISO image according to the configure file unittests.cfg, where describes the parameters of each test case. The grub.cfg in ios/boot/grub/ looks as following, taking case 'vmx_apicv_test' as an example: set timeout=0 set default=0 menuentry "vmx.elf" { multiboot /boot/vmx.elf apic_reg_virt_test virt_x2apic_mode_test module /boot/module boot } [1] All parameters are from '-append xxx' in the unittests.cfg. [2] The file 'module' is a fixed file that can be passed by paramters of script ./create_iso.sh. Signed-off-by: Yi Sun diff --git a/x86/create_iso.sh b/x86/create_iso.sh new file mode 100755 index 0000000..4fe8e5b --- /dev/null +++ b/x86/create_iso.sh @@ -0,0 +1,112 @@ +#!/bin/bash +config_file=$1 +module_file=$2 + +opts= +extra_params=" " +kernel= +smp= +testname= + +dir_x86=`dirname $0` +[[ ${dir_x86:0:1} != "/" ]] && dir_x86=`pwd`/$dir_x86 + +usage() { + cat << EOF +Usage: create_iso.sh [module_file] + configure: + Usually just pass unittests.cfg to the create_iso.sh. + + module_file: + This is optional. You can pass some environment to the kernels + The module.file looks as following: + NR_CPUS=56 + MEMSIZE=4096 + TEST_DEVICE=0 + BOOTLOADER=1 +EOF +} + +grub_cfg() { + local kernel_elf=$1 + local kernel_para=$2 + local module_file=$3 + + if [[ "${module_file}" != "" ]]; then + module_cmd="module /boot/${module_file}" + fi + + cat << EOF +set timeout=0 +set default=0 + +menuentry "${kernel_elf}" { + multiboot /boot/${kernel_elf} ${kernel_para} + ${module_cmd} + boot +} +EOF +} + +create_iso() { + local case_name=$1 + local kernel_elf=$2 + local kernel_params=$3 + local module_file=$4 + + if [ -f $kernel_elf ]; then + rm -rf build/isofiles + mkdir -p build/isofiles/boot/grub + + cp $kernel_elf build/isofiles/boot/ + [[ -f $module_file ]] && cp $module_file build/isofiles/boot/ + + grub_cfg ${kernel_elf##*/} "${kernel_params}" ${module_file##*/} > build/isofiles/boot/grub/grub.cfg + + rm -rf ${testname}.iso + grub-mkrescue -o ${dir_x86}/${case_name}.iso build/isofiles >& /dev/null + if [ $? == 0 ]; then + echo "Creating ISO for case: ${case_name}" + else + echo "[FAIL] grub-mkrescue: Please install grub-mkrescue and xorriso correctly." + exit 1 + fi + fi +} + +if [[ "$config_file" == "" || ! -f $config_file ]]; then + echo "[FAIL] A configure file is required, usually pass unittests.cfg as the first parameter" + usage + exit 1 +fi + +nline=`wc $config_file | cut -d' ' -f 2` + +while read -r line; do + if [[ "$line" =~ ^\[(.*)\]$ || $nline == 1 ]]; then + rematch=${BASH_REMATCH[1]} + if [[ "${testname}" != "" ]]; then + create_iso $testname ${dir_x86}/${kernel}.elf "${extra_params}" $module_file + fi + testname=$rematch + extra_params=" " + smp=1 + kernel="" + opts="" + groups="" + elif [[ $line =~ ^file\ *=\ *(.*)\.flat$ ]]; then + kernel=${BASH_REMATCH[1]} + elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then + smp=${BASH_REMATCH[1]} + elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then + opts=${BASH_REMATCH[1]} + if [[ "$opts" =~ .*append\ (.*)$ ]]; then + extra_params=${BASH_REMATCH[1]} + extra_params=`echo $extra_params | sed 's/\"//g'` + fi + elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then + groups=${BASH_REMATCH[1]} + fi + (( nline -= 1)) + +done < $config_file