4 # Copyright (c) 2018 Vojtech Horky
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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',
45 default
='scenarios/base/pcut.yml',
48 args
.add_argument('--arch',
49 metavar
='ARCHITECTURE',
52 help='Emulated architecture identification.'
54 args
.add_argument('--image',
58 help='HelenOS boot image (e.g. ISO file).'
60 args
.add_argument('--vterm-dump',
61 metavar
='FILENAME.txt',
64 help='Where to store full vterm dump.'
66 args
.add_argument('--last-screenshot',
67 metavar
='FILENAME.png',
68 dest
='last_screenshot',
70 help='Where to store last screenshot.'
72 args
.add_argument('--debug',
76 help='Print debugging messages'
79 config
= args
.parse_args()
82 config
.logging_level
= logging
.DEBUG
84 config
.logging_level
= logging
.INFO
87 format
='[%(asctime)s %(name)-16s %(levelname)7s] %(message)s',
88 level
=config
.logging_level
91 logger
= logging
.getLogger('main')
93 with
open(config
.scenario
, 'r') as f
:
95 scenario
= yaml
.load(f
)
96 except yaml
.YAMLError
as ex
:
101 for ctl
in [ QemuVMController
]:
102 if ctl
.is_supported(config
.architecture
):
105 if controller
is None:
106 logger
.error("Unsupported architecture {}.".format(config
.architecture
))
109 vmm
= VMManager(controller
, config
.architecture
, config
.boot_image
)
112 for t
in scenario
['tasks']:
115 k
= list(set(t
.keys()) - set(['name', 'machine']))
117 raise Exception("Unknown task ({})!".format(k
))
125 raise Exception("Unknown task!")
126 task_classname
= 'ScenarioTask' + task_name
.title().replace('-', '_')
127 task_class
= globals()[task_classname
]
128 task_inst
= task_class(t
[task_name
])
129 if not ('machine' in t
):
131 machine
= vmm
.get(t
['machine'])
133 if t
['machine'] is None:
134 t
['machine'] = 'default'
135 logger
.debug("Creating new machine {}.".format(t
['machine']))
136 machine
= vmm
.create(t
['machine'])
137 task_inst
.set_machine(machine
)
138 scenario_tasks
.append(task_inst
)
141 for t
in scenario_tasks
:
143 except Exception as ex
:
146 vmm
.terminate(config
.vterm_dump
, config
.last_screenshot
)