From 0bfe14eeafed2cddff89e9607c55cc61fbe61cc7 Mon Sep 17 00:00:00 2001 From: Vojtech Horky Date: Mon, 27 Aug 2018 20:58:02 +0200 Subject: [PATCH] Add --memory switch --- htest/vm/controller.py | 6 +++++- htest/vm/qemu.py | 10 ++++++---- vm-test.py | 14 +++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/htest/vm/controller.py b/htest/vm/controller.py index 3d02e0b..d98fd6d 100755 --- a/htest/vm/controller.py +++ b/htest/vm/controller.py @@ -36,10 +36,11 @@ class VMManager: Keeps track of running virtual machines. """ - def __init__(self, controller, architecture, boot_image): + def __init__(self, controller, architecture, boot_image, memory_amount): self.controller_class = controller self.architecture = architecture self.boot_image = boot_image + self.memory_amount = memory_amount self.instances = {} self.last = None @@ -47,6 +48,7 @@ class VMManager: if name in self.instances: raise Exception("Duplicate machine name {}.".format(name)) self.instances[name] = self.controller_class(self.architecture, name, self.boot_image) + self.instances[name].memory = self.memory_amount self.last = name return self.instances[name] @@ -93,6 +95,8 @@ class VMController: self.full_vterm = [] # Used to keep track of new-lines self.vterm = [] + # Amount of memory (MB) (patched by VMM manager) + self.memory = 0 pass def is_supported(self, arch): diff --git a/htest/vm/qemu.py b/htest/vm/qemu.py index dbbe15c..3b7dad7 100755 --- a/htest/vm/qemu.py +++ b/htest/vm/qemu.py @@ -46,7 +46,7 @@ class QemuVMController(VMController): 'amd64': [ 'qemu-system-x86_64', '-cdrom', '{BOOT}', - '-m', '256', + '-m', '{MEMORY}', '-usb', ], 'arm32/integratorcp': [ @@ -54,12 +54,12 @@ class QemuVMController(VMController): '-M', 'integratorcp', '-usb', '-kernel', '{BOOT}', - '-m', '256', + '-m', '{MEMORY}', ], 'ia32': [ 'qemu-system-i386', '-cdrom', '{BOOT}', - '-m', '256', + '-m', '{MEMORY}', '-usb', ], 'ppc32': [ @@ -67,7 +67,7 @@ class QemuVMController(VMController): '-usb', '-boot', 'd', '-cdrom', '{BOOT}', - '-m', '256', + '-m', '{MEMORY}', ], } @@ -122,6 +122,8 @@ class QemuVMController(VMController): for opt in QemuVMController.config[self.arch]: if opt == '{BOOT}': opt = self.boot_image + elif opt == '{MEMORY}': + opt = '{}'.format(self.memory) cmd.append(opt) cmd.append('-monitor') cmd.append('unix:{},server,nowait'.format(self.monitor_file)) diff --git a/vm-test.py b/vm-test.py index 905520c..75ff806 100755 --- a/vm-test.py +++ b/vm-test.py @@ -51,6 +51,14 @@ args.add_argument('--arch', required=True, help='Emulated architecture identification.' ) +args.add_argument('--memory', + metavar='MB', + dest='memory', + type=int, + required=False, + default=256, + help='Amount of memory for the virtual machine.' +) args.add_argument('--image', metavar='FILENAME', dest='boot_image', @@ -97,6 +105,10 @@ with open(config.scenario, 'r') as f: logger.error(ex) sys.exit(1) +if config.memory < 8: + logger.error("Specify at least 8MB of memory.") + sys.exit(1) + controller = None for ctl in [ QemuVMController ]: if ctl.is_supported(config.architecture): @@ -106,7 +118,7 @@ if controller is None: logger.error("Unsupported architecture {}.".format(config.architecture)) sys.exit(1) -vmm = VMManager(controller, config.architecture, config.boot_image) +vmm = VMManager(controller, config.architecture, config.boot_image, config.memory) scenario_tasks = [] for t in scenario['tasks']: -- 2.11.4.GIT