Add support for arm32/integratorcp
[ci.git] / vm-test.py
blob68855785d598e1ed8d4bf8fc9ec1da84743137a5
1 #!/usr/bin/env python3
4 # Copyright (c) 2018 Vojtech Horky
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 import argparse
33 import yaml
34 import logging
35 import sys
37 from htest.vm.controller import VMManager
38 from htest.vm.qemu import QemuVMController
39 from htest.tasks import *
41 args = argparse.ArgumentParser(description='HelenOS VM tests')
42 args.add_argument('--scenario',
43 metavar='FILENAME.yml',
44 dest='scenario',
45 default='scenarios/base/pcut.yml',
46 help='Scenario file'
48 args.add_argument('--arch',
49 metavar='ARCHITECTURE',
50 dest='architecture',
51 required=True,
52 help='Emulated architecture identification.'
54 args.add_argument('--image',
55 metavar='FILENAME',
56 dest='boot_image',
57 required=True,
58 help='HelenOS boot image (e.g. ISO file).'
60 args.add_argument('--vterm-dump',
61 metavar='FILENAME.txt',
62 dest='vterm_dump',
63 default=None,
64 help='Where to store full vterm dump.'
66 args.add_argument('--debug',
67 dest='debug',
68 default=False,
69 action='store_true',
70 help='Print debugging messages'
73 config = args.parse_args()
75 if config.debug:
76 config.logging_level = logging.DEBUG
77 else:
78 config.logging_level = logging.INFO
80 logging.basicConfig(
81 format='[%(asctime)s %(name)-16s %(levelname)7s] %(message)s',
82 level=config.logging_level
85 logger = logging.getLogger('main')
87 with open(config.scenario, 'r') as f:
88 try:
89 scenario = yaml.load(f)
90 except yaml.YAMLError as ex:
91 logger.error(ex)
92 sys.exit(1)
94 controller = None
95 for ctl in [ QemuVMController ]:
96 if ctl.is_supported(config.architecture):
97 controller = ctl
99 if controller is None:
100 logger.error("Unsupported architecture {}.".format(config.architecture))
101 sys.exit(1)
103 vmm = VMManager(controller, config.architecture, config.boot_image)
105 scenario_tasks = []
106 for t in scenario['tasks']:
107 task_name = None
108 if type(t) is dict:
109 k = list(set(t.keys()) - set(['name', 'machine']))
110 if len(k) != 1:
111 raise Exception("Unknown task ({})!".format(k))
112 task_name = k[0]
113 elif type(t) is str:
114 task_name = t
115 t = {
116 task_name: {}
118 else:
119 raise Exception("Unknown task!")
120 task_classname = 'ScenarioTask' + task_name.title().replace('-', '_')
121 task_class = globals()[task_classname]
122 task_inst = task_class(t[task_name])
123 if not ('machine' in t):
124 t['machine'] = None
125 machine = vmm.get(t['machine'])
126 if machine is None:
127 if t['machine'] is None:
128 t['machine'] = 'default'
129 logger.debug("Creating new machine {}.".format(t['machine']))
130 machine = vmm.create(t['machine'])
131 task_inst.set_machine(machine)
132 scenario_tasks.append(task_inst)
134 try:
135 for t in scenario_tasks:
136 t.run()
137 except Exception as ex:
138 print(ex)
140 vmm.terminate(config.vterm_dump)