Skip to content

Commit

Permalink
[guest-test] Test Enhance: tab format unified across all source code
Browse files Browse the repository at this point in the history
all tab format unified to 2 spaces across all source code

[Test Components] tdx
[Test Types] func
[Supported Devices] spr,emr,gnr.srf

Signed-off-by: Hongyu Ning <[email protected]>
  • Loading branch information
hongyuni committed Oct 23, 2023
1 parent 5a9b9e3 commit 1ffd1d9
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 169 deletions.
88 changes: 44 additions & 44 deletions guest-test/qemu.config.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"common": {
"kernel_img": "/boot/vmlinuz-xxx-yyy",
"initrd_img": "/boot/initramfs-xxx-yyy",
"bios_img": "/path/to/EDKII/OVMF.fd or other virtual BIOS",
"qemu_img": "/path/to/qemu-kvm with proper capabilty of VM test",
"guest_img": "/path/to/prepared/guest_os_image, in qcow2 or raw image format",
"guest_img_format": "raw",
"boot_pattern": "*Kernel*on*an*x86_64*",
"guest_root_passwd": "123456",
"vm_type": "tdx",
"pmu": "off",
"cpus": "4",
"sockets": "1",
"mem": "16",
"cmdline": "accept_memory=lazy",
"debug": "on"
},
"common": {
"kernel_img": "/boot/vmlinuz-xxx-yyy",
"initrd_img": "/boot/initramfs-xxx-yyy",
"bios_img": "/path/to/EDKII/OVMF.fd or other virtual BIOS",
"qemu_img": "/path/to/qemu-kvm with proper capabilty of VM test",
"guest_img": "/path/to/prepared/guest_os_image, in qcow2 or raw image format",
"guest_img_format": "raw",
"boot_pattern": "*Kernel*on*an*x86_64*",
"guest_root_passwd": "123456",
"vm_type": "tdx",
"pmu": "off",
"cpus": "4",
"sockets": "1",
"mem": "16",
"cmdline": "accept_memory=lazy",
"debug": "on"
},

"vm": {
"cfg_1": "-accel kvm -no-reboot -nographic -vga none -device virtio-net-pci,netdev=mynet0,mac=DE:AD:BE:EF:AB:CD,romfile= ",
"cfg_2": "-chardev stdio,id=mux,mux=on,signal=off -device virtio-serial,romfile= -device virtconsole,chardev=mux ",
"cfg_3": "-serial chardev:mux -monitor chardev:mux -monitor pty -no-hpet -nodefaults ",
"cfg_var_1": "-name process=$VM_TYPEVM_$PORT,debug-threads=on ",
"cfg_var_2": "-cpu host,host-phys-bits,pmu=$PMU ",
"cfg_var_3": "-smp cpus=$VCPU,sockets=$SOCKETS ",
"cfg_var_4": "-m $MEMG ",
"cfg_var_5": "-kernel $KERNEL_IMG ",
"cfg_var_6": "-initrd $INITRD_IMG",
"cfg_var_7": "-netdev user,id=mynet0,hostfwd=tcp::$PORT-:22 ",
"cfg_var_8": "-drive file=$GUEST_IMG,if=virtio,format=$IMG_FORMAT ",
"cfg_var_9": "-append \"root=/dev/vda3 ro console=hvc0 earlyprintk=ttyS0 ignore_loglevel debug earlyprintk l1tf=off initcall_debug log_buf_len=200M nokaslr tsc=reliable efi=debug mce=off efi=debug $CMDLINE\" ",
"cfg_var_10": "-bios $BIOS_IMG "
},
"vm": {
"cfg_1": "-accel kvm -no-reboot -nographic -vga none -device virtio-net-pci,netdev=mynet0,mac=DE:AD:BE:EF:AB:CD,romfile= ",
"cfg_2": "-chardev stdio,id=mux,mux=on,signal=off -device virtio-serial,romfile= -device virtconsole,chardev=mux ",
"cfg_3": "-serial chardev:mux -monitor chardev:mux -monitor pty -no-hpet -nodefaults ",
"cfg_var_1": "-name process=$VM_TYPEVM_$PORT,debug-threads=on ",
"cfg_var_2": "-cpu host,host-phys-bits,pmu=$PMU ",
"cfg_var_3": "-smp cpus=$VCPU,sockets=$SOCKETS ",
"cfg_var_4": "-m $MEMG ",
"cfg_var_5": "-kernel $KERNEL_IMG ",
"cfg_var_6": "-initrd $INITRD_IMG",
"cfg_var_7": "-netdev user,id=mynet0,hostfwd=tcp::$PORT-:22 ",
"cfg_var_8": "-drive file=$GUEST_IMG,if=virtio,format=$IMG_FORMAT ",
"cfg_var_9": "-append \"root=/dev/vda3 ro console=hvc0 earlyprintk=ttyS0 ignore_loglevel debug earlyprintk l1tf=off initcall_debug log_buf_len=200M nokaslr tsc=reliable efi=debug mce=off efi=debug $CMDLINE\" ",
"cfg_var_10": "-bios $BIOS_IMG "
},

"tdx": {
"cfg_1": "-machine q35,kernel_irqchip=split,confidential-guest-support=tdx,memory-backend=ram1 ",
"cfg_var_1": "-object tdx-guest,id=tdx,debug=$DEBUG,sept-ve-disable=on,quote-generation-service=vsock:2:4050 ",
"cfg_var_2": "-object memory-backend-memfd-private,id=ram1,size=$MEMG "
},
"tdx": {
"cfg_1": "-machine q35,kernel_irqchip=split,confidential-guest-support=tdx,memory-backend=ram1 ",
"cfg_var_1": "-object tdx-guest,id=tdx,debug=$DEBUG,sept-ve-disable=on,quote-generation-service=vsock:2:4050 ",
"cfg_var_2": "-object memory-backend-memfd-private,id=ram1,size=$MEMG "
},

"tdxio": {
"cfg_1": "-object iommufd,id=iommufd0 ",
"cfg_2": "-device vfio-pci,host=tee_bdf1,id=hostdev2,addr=0x3,x-secure-mode=on ",
"cfg_3": "-device vfio-pci,host=tee_bdf2,id=hostdev3,addr=0x4,x-secure-mode=on ",
"cfg_4": "-device vfio-pci,host=tee_bdf3,id=hostdev4,addr=0x5,x-secure-mode=on ",
"cfg_5": "-device vfio-pci,host=tee_bdf4,id=hostdev5,addr=0x6,x-secure-mode=on "
}
"tdxio": {
"cfg_1": "-object iommufd,id=iommufd0 ",
"cfg_2": "-device vfio-pci,host=tee_bdf1,id=hostdev2,addr=0x3,x-secure-mode=on ",
"cfg_3": "-device vfio-pci,host=tee_bdf2,id=hostdev3,addr=0x4,x-secure-mode=on ",
"cfg_4": "-device vfio-pci,host=tee_bdf3,id=hostdev4,addr=0x5,x-secure-mode=on ",
"cfg_5": "-device vfio-pci,host=tee_bdf4,id=hostdev5,addr=0x6,x-secure-mode=on "
}
}
142 changes: 71 additions & 71 deletions guest-test/qemu_get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
# read from qemu.config.json format for all raw qemu vm config
cwd = Path(os.getcwd())
if cwd.stem == "guest-test":
raw_config = Path(f"{os.getcwd()}/qemu.config.json").read_text()
raw_config = Path(f"{os.getcwd()}/qemu.config.json").read_text()
else:
exit(1)
exit(1)

qemu_config = json.loads(raw_config)

Expand All @@ -54,40 +54,40 @@
# O-list variables default value from qemu.config.json
vm_type = qemu_config["common"]["vm_type"]
if 'PMU' in dir():
pmu = PMU
pmu = PMU
else:
pmu = qemu_config["common"]["pmu"]
pmu = qemu_config["common"]["pmu"]

if 'VCPU' in dir():
cpus = VCPU
cpus = VCPU
else:
cpus = qemu_config["common"]["cpus"]
cpus = qemu_config["common"]["cpus"]

if 'SOCKETS' in dir():
sockets = SOCKETS
sockets = SOCKETS
else:
sockets = qemu_config["common"]["sockets"]
sockets = qemu_config["common"]["sockets"]

if 'MEM' in dir():
mem = MEM
mem = MEM
else:
mem = qemu_config["common"]["mem"]
mem = qemu_config["common"]["mem"]

if 'CMDLINE' in dir():
cmdline = CMDLINE
cmdline = CMDLINE
else:
cmdline = qemu_config["common"]["cmdline"]
cmdline = qemu_config["common"]["cmdline"]

if 'DEBUG' in dir():
debug = DEBUG
debug = DEBUG
else:
debug = qemu_config["common"]["debug"]
debug = qemu_config["common"]["debug"]

if 'TESTCASE' in dir():
testcase = TESTCASE
testcase = TESTCASE
else:
print("No TESTCASE info found, can't run any test!")
exit(1)
print("No TESTCASE info found, can't run any test!")
exit(1)

# O-list variables override value handling with args passed options, not used in framework, keep it for customization
params_o_list = argparse.ArgumentParser()
Expand All @@ -111,21 +111,21 @@

# NOTICE!! O-list veriables' value will be override if passed through above args option
if args.vmtype is not None:
vm_type = args.vmtype
vm_type = args.vmtype
if args.pmu is not None:
pmu = args.pmu
pmu = args.pmu
if args.cpus is not None:
cpus = args.cpus
cpus = args.cpus
if args.sockets is not None:
sockets = args.sockets
sockets = args.sockets
if args.mem is not None:
mem = args.mem
mem = args.mem
if args.cmdline is not None:
cmdline = args.cmdline
cmdline = args.cmdline
if args.debug is not None:
debug = args.debug
debug = args.debug
if args.testcase is not None:
testcase = args.testcase
testcase = args.testcase

# end of O-list variables handling

Expand All @@ -138,18 +138,18 @@
qemu_config["vm"]["cfg_var_5"] = qemu_config["vm"]["cfg_var_5"].replace("$KERNEL_IMG", kernel_img)
# bypass -initrd config option in case it's not provided
if os.path.isfile(initrd_img):
qemu_config["vm"]["cfg_var_6"] = qemu_config["vm"]["cfg_var_6"].replace("$INITRD_IMG", initrd_img)
qemu_config["vm"]["cfg_var_6"] = qemu_config["vm"]["cfg_var_6"].replace("$INITRD_IMG", initrd_img)
else:
qemu_config["vm"]["cfg_var_6"] = ""
qemu_config["vm"]["cfg_var_6"] = ""

qemu_config["vm"]["cfg_var_7"] = qemu_config["vm"]["cfg_var_7"].replace("$PORT", str(port))
qemu_config["vm"]["cfg_var_8"] = qemu_config["vm"]["cfg_var_8"].replace("$GUEST_IMG", guest_img).replace("$IMG_FORMAT", guest_img_format)
qemu_config["vm"]["cfg_var_9"] = qemu_config["vm"]["cfg_var_9"].replace("$CMDLINE", cmdline)
# bypass -bios config option in case it's not provided, default seabios to use
if os.path.isfile(bios_img):
qemu_config["vm"]["cfg_var_10"] = qemu_config["vm"]["cfg_var_10"].replace("$BIOS_IMG", bios_img)
qemu_config["vm"]["cfg_var_10"] = qemu_config["vm"]["cfg_var_10"].replace("$BIOS_IMG", bios_img)
else:
qemu_config["vm"]["cfg_var_10"] = ""
qemu_config["vm"]["cfg_var_10"] = ""

qemu_config["tdx"]["cfg_var_1"] = qemu_config["tdx"]["cfg_var_1"].replace("$DEBUG", debug)
qemu_config["tdx"]["cfg_var_2"] = qemu_config["tdx"]["cfg_var_2"].replace("$MEM", str(mem))
Expand All @@ -158,31 +158,31 @@

###################### Functions ######################
def get_sub_keys(d, key):
"""
Recursively get all 2nd-level keys in a dictionary.
"""
if isinstance(d, dict):
for k, v in d.items():
if isinstance(v, dict):
if k == key:
for k2 in v.keys():
yield k2
"""
Recursively get all 2nd-level keys in a dictionary.
"""
if isinstance(d, dict):
for k, v in d.items():
if isinstance(v, dict):
if k == key:
for k2 in v.keys():
yield k2

def print_sub_keys(l, key):
"""
Recursively get each 2nd-level key.
"""
print("Key %s has sub-keys:" %(key))
for i in l:
print(i)
"""
Recursively get each 2nd-level key.
"""
print("Key %s has sub-keys:" %(key))
for i in l:
print(i)

def get_sub_cfgs(l, key, result=""):
"""
Recursively collect all 2nd-level key cfg string.
"""
for i in l:
result += qemu_config[key][i]
return result
"""
Recursively collect all 2nd-level key cfg string.
"""
for i in l:
result += qemu_config[key][i]
return result

###################### Do Works ######################
#common_keys = list(get_sub_keys(qemu_config, "common"))
Expand All @@ -192,30 +192,30 @@ def get_sub_cfgs(l, key, result=""):

#print_sub_keys(vm_keys, "vm")
if vm_type == "legacy":
vm_cfg = get_sub_cfgs(vm_keys, "vm")
print("HERE're all the vm configs to launch legacy vm:")
print("#### qemu config option, part 1 ####")
print(vm_cfg)
vm_cfg = get_sub_cfgs(vm_keys, "vm")
print("HERE're all the vm configs to launch legacy vm:")
print("#### qemu config option, part 1 ####")
print(vm_cfg)

#print_sub_keys(tdx_keys, "tdx")
if vm_type == "tdx":
vm_cfg = get_sub_cfgs(vm_keys, "vm")
tdx_cfg = get_sub_cfgs(tdx_keys, "tdx")
print("HERE're all the tdx configs to launch tdx vm:")
print("#### qemu config option, part 1 ####")
print(vm_cfg)
print("#### qemu config option, part 2 ####")
print(tdx_cfg)
vm_cfg = get_sub_cfgs(vm_keys, "vm")
tdx_cfg = get_sub_cfgs(tdx_keys, "tdx")
print("HERE're all the tdx configs to launch tdx vm:")
print("#### qemu config option, part 1 ####")
print(vm_cfg)
print("#### qemu config option, part 2 ####")
print(tdx_cfg)

#print_sub_keys(tdxio_keys, "tdxio")
if vm_type == "tdxio":
vm_cfg = get_sub_cfgs(vm_keys, "vm")
tdx_cfg = get_sub_cfgs(tdx_keys, "tdx")
tdxio_cfg = get_sub_cfgs(tdxio_keys, "tdxio")
print("HERE're all the tdx configs to launch tdxio vm:")
print("#### qemu config option, part 1 ####")
print(vm_cfg)
print("#### qemu config option, part 2 ####")
print(tdx_cfg)
print("#### qemu config option, part 3 ####")
print(tdxio_cfg)
vm_cfg = get_sub_cfgs(vm_keys, "vm")
tdx_cfg = get_sub_cfgs(tdx_keys, "tdx")
tdxio_cfg = get_sub_cfgs(tdxio_keys, "tdxio")
print("HERE're all the tdx configs to launch tdxio vm:")
print("#### qemu config option, part 1 ####")
print(vm_cfg)
print("#### qemu config option, part 2 ####")
print(tdx_cfg)
print("#### qemu config option, part 3 ####")
print(tdxio_cfg)
12 changes: 6 additions & 6 deletions guest-test/qemu_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
###################### Do Works ######################
# launch legacy common vm based on vm_type config
if vm_type == "legacy":
command = '{} {}'.format(qemu_img, vm_cfg)
sp.run(command, shell=True)
command = '{} {}'.format(qemu_img, vm_cfg)
sp.run(command, shell=True)

# launch tdx vm based on vm_type config
if vm_type == "tdx":
command = '{} {} {}'.format(qemu_img, vm_cfg, tdx_cfg)
sp.run(command, shell=True)
command = '{} {} {}'.format(qemu_img, vm_cfg, tdx_cfg)
sp.run(command, shell=True)

# launch tdxio vm based on vm_type config
if vm_type == "tdxio":
command = '{} {} {} {}'.format(qemu_img, vm_cfg, tdx_cfg, tdxio_cfg)
sp.run(command, shell=True)
command = '{} {} {} {}'.format(qemu_img, vm_cfg, tdx_cfg, tdxio_cfg)
sp.run(command, shell=True)
Loading

0 comments on commit 1ffd1d9

Please sign in to comment.