All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH 1/2] x86: Build ISO images from x86/*.elf
@ 2021-06-04  2:34 Yi Sun
  2021-06-04  2:34 ` [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg Yi Sun
  0 siblings, 1 reply; 6+ messages in thread
From: Yi Sun @ 2021-06-04  2:34 UTC (permalink / raw)
  To: yi.sun, kvm

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 <yi.sun@intel.com>

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 \
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg
  2021-06-04  2:34 [kvm-unit-tests PATCH 1/2] x86: Build ISO images from x86/*.elf Yi Sun
@ 2021-06-04  2:34 ` Yi Sun
  2021-06-04  3:06   ` Nadav Amit
  0 siblings, 1 reply; 6+ messages in thread
From: Yi Sun @ 2021-06-04  2:34 UTC (permalink / raw)
  To: yi.sun, kvm

Create ISO image according to the configure file unittests.cfg,
where describes the parameters of each test case.

Signed-off-by: Yi Sun <yi.sun@intel.com>

diff --git a/x86/create_iso.sh b/x86/create_iso.sh
new file mode 100755
index 0000000..8486be7
--- /dev/null
+++ b/x86/create_iso.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+set -e
+config_file=$1
+
+opts=
+extra_params=
+kernel=
+smp=
+testname=
+
+
+grub_cfg() {
+
+	kernel_elf=$1
+	kernel_para=$2
+
+	cat << EOF
+set timeout=0
+set default=0
+
+
+menuentry "${kernel_elf}" {
+    multiboot /boot/${kernel_elf} ${kernel_para}
+    boot
+}
+EOF
+
+}
+
+create_iso() {
+	case_name=$1
+	kernel_elf=$2
+	kernel_params=$3
+	if [ -f $kernel_elf ]; then
+		rm -rf build/isofiles
+		mkdir -p build/isofiles/boot/grub
+
+		cp $kernel_elf build/isofiles/boot/
+		grub_cfg ${kernel_elf##*/} $kernel_params> build/isofiles/boot/grub/grub.cfg
+
+		rm -rf ${testname}.iso
+		grub-mkrescue -o ${case_name}.iso build/isofiles 2> /dev/null
+		[ $? == 0 ] && echo "Creating ISO for case: ${case_name}"
+	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 ${kernel}.elf $extra_params
+		fi
+		testname=$rematch
+
+	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]}
+		fi
+	elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
+		groups=${BASH_REMATCH[1]}
+	fi
+	(( nline -= 1))
+
+done < $config_file
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg
  2021-06-04  2:34 ` [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg Yi Sun
@ 2021-06-04  3:06   ` Nadav Amit
  2021-06-04 12:32     ` Sun, Yi
  0 siblings, 1 reply; 6+ messages in thread
From: Nadav Amit @ 2021-06-04  3:06 UTC (permalink / raw)
  To: Yi Sun; +Cc: kvm



> On Jun 3, 2021, at 7:34 PM, Yi Sun <yi.sun@intel.com> wrote:
> 
> Create ISO image according to the configure file unittests.cfg,
> where describes the parameters of each test case.
> 

Looks cool!

> diff --git a/x86/create_iso.sh b/x86/create_iso.sh
> new file mode 100755
> index 0000000..8486be7
> --- /dev/null
> +++ b/x86/create_iso.sh
> @@ -0,0 +1,71 @@
> +#!/bin/bash
> +set -e
> +config_file=$1
> +
> +opts=
> +extra_params=
> +kernel=
> +smp=
> +testname=
> +
> +
> +grub_cfg() {
> +
> +	kernel_elf=$1
> +	kernel_para=$2
> +
> +	cat << EOF
> +set timeout=0
> +set default=0
> +
> +
> +menuentry "${kernel_elf}" {
> +    multiboot /boot/${kernel_elf} ${kernel_para}

Any chance you can add an optional “module” command here, that
would be configurable as a parameter to create_iso.sh?

I use such a command to provide parameters that kvm-unit-tests
usually gets from the “firmware" (and therefore are not available
in certain environments). 

The “module” can look something like:
	NR_CPUS=56
	MEMSIZE=4096
	TEST_DEVICE=0
	BOOTLOADER=1 

(kvm-unit-tests already knows to use these values)

This “module" would need to be copied into build/isofiles/boot as
well.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg
  2021-06-04  3:06   ` Nadav Amit
@ 2021-06-04 12:32     ` Sun, Yi
  2021-06-04 17:08       ` Nadav Amit
  0 siblings, 1 reply; 6+ messages in thread
From: Sun, Yi @ 2021-06-04 12:32 UTC (permalink / raw)
  To: Nadav Amit; +Cc: kvm

Hi Nadav,

Let me confirm if  I got what you meant. Do you want the grub entry look like following? 
Take case memory as an example:
Add module command line taking '/boot/module' as its parameter, meanwhile package the file 'module' in the folder?

menuentry "memory.elf" {
    multiboot /boot/memory.elf  tscdeadline_immed
    module   /boot/module    # Add one line like this ?
}

Thanks
    --Sun, Yi

> -----Original Message-----
> From: Nadav Amit <nadav.amit@gmail.com>
> Sent: Friday, June 4, 2021 11:06
> To: Sun, Yi <yi.sun@intel.com>
> Cc: kvm@vger.kernel.org
> Subject: Re: [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to
> unittests.cfg
> 
> 
> 
> > On Jun 3, 2021, at 7:34 PM, Yi Sun <yi.sun@intel.com> wrote:
> >
> > Create ISO image according to the configure file unittests.cfg, where
> > describes the parameters of each test case.
> >
> 
> Looks cool!
> 
> > diff --git a/x86/create_iso.sh b/x86/create_iso.sh new file mode
> > 100755 index 0000000..8486be7
> > --- /dev/null
> > +++ b/x86/create_iso.sh
> > @@ -0,0 +1,71 @@
> > +#!/bin/bash
> > +set -e
> > +config_file=$1
> > +
> > +opts=
> > +extra_params=
> > +kernel=
> > +smp=
> > +testname=
> > +
> > +
> > +grub_cfg() {
> > +
> > +	kernel_elf=$1
> > +	kernel_para=$2
> > +
> > +	cat << EOF
> > +set timeout=0
> > +set default=0
> > +
> > +
> > +menuentry "${kernel_elf}" {
> > +    multiboot /boot/${kernel_elf} ${kernel_para}
> 
> Any chance you can add an optional “module” command here, that would be
> configurable as a parameter to create_iso.sh?
> 
> I use such a command to provide parameters that kvm-unit-tests usually gets
> from the “firmware" (and therefore are not available in certain
> environments).
> 
> The “module” can look something like:
> 	NR_CPUS=56
> 	MEMSIZE=4096
> 	TEST_DEVICE=0
> 	BOOTLOADER=1
> 
> (kvm-unit-tests already knows to use these values)
> 
> This “module" would need to be copied into build/isofiles/boot as well.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg
  2021-06-04 12:32     ` Sun, Yi
@ 2021-06-04 17:08       ` Nadav Amit
  2021-06-04 17:13         ` Sun, Yi
  0 siblings, 1 reply; 6+ messages in thread
From: Nadav Amit @ 2021-06-04 17:08 UTC (permalink / raw)
  To: Sun, Yi; +Cc: kvm



> On Jun 4, 2021, at 5:32 AM, Sun, Yi <yi.sun@intel.com> wrote:
> 
> Hi Nadav,
> 
> Let me confirm if  I got what you meant. Do you want the grub entry look like following? 
> Take case memory as an example:
> Add module command line taking '/boot/module' as its parameter, meanwhile package the file 'module' in the folder?
> 
> menuentry "memory.elf" {
>    multiboot /boot/memory.elf  tscdeadline_immed
>    module   /boot/module    # Add one line like this ?
> }

Yes. The entry should look exactly like that.

Just to make sure we are on the same page, the “module” should be provided as a second parameter for the script. The additional “module” entry should only be added if a second parameter is provided.

Thanks,
Nadav

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg
  2021-06-04 17:08       ` Nadav Amit
@ 2021-06-04 17:13         ` Sun, Yi
  0 siblings, 0 replies; 6+ messages in thread
From: Sun, Yi @ 2021-06-04 17:13 UTC (permalink / raw)
  To: Nadav Amit; +Cc: kvm

Ok, get it now. Send you the second version soon.

Thanks
    --Sun, Yi

> -----Original Message-----
> From: Nadav Amit <nadav.amit@gmail.com>
> Sent: Saturday, June 5, 2021 01:09
> To: Sun, Yi <yi.sun@intel.com>
> Cc: kvm@vger.kernel.org
> Subject: Re: [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to
> unittests.cfg
> 
> 
> 
> > On Jun 4, 2021, at 5:32 AM, Sun, Yi <yi.sun@intel.com> wrote:
> >
> > Hi Nadav,
> >
> > Let me confirm if  I got what you meant. Do you want the grub entry look
> like following?
> > Take case memory as an example:
> > Add module command line taking '/boot/module' as its parameter,
> meanwhile package the file 'module' in the folder?
> >
> > menuentry "memory.elf" {
> >    multiboot /boot/memory.elf  tscdeadline_immed
> >    module   /boot/module    # Add one line like this ?
> > }
> 
> Yes. The entry should look exactly like that.
> 
> Just to make sure we are on the same page, the “module” should be
> provided as a second parameter for the script. The additional “module” entry
> should only be added if a second parameter is provided.
> 
> Thanks,
> Nadav

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-04 17:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04  2:34 [kvm-unit-tests PATCH 1/2] x86: Build ISO images from x86/*.elf Yi Sun
2021-06-04  2:34 ` [kvm-unit-tests PATCH 2/2] x86: Create ISO images according to unittests.cfg Yi Sun
2021-06-04  3:06   ` Nadav Amit
2021-06-04 12:32     ` Sun, Yi
2021-06-04 17:08       ` Nadav Amit
2021-06-04 17:13         ` Sun, Yi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.